function gid(id) {
    return document.getElementById(id);
}

function checkAllCheckboxes(form, namePrefix, checkAll) {
    if(typeof checkAll == "undefined") checkAll = true;

    for (i = 0; i < form.elements.length; i++) {
        e = form.elements[i];

        if(e.name.slice(0, namePrefix.length) == namePrefix) {
            e.checked = checkAll;
        }
    }
}

function popup_photo(url) {
    w = window.open("", "photo", "top=100,left=150,width=750,height=550,location=no,resizable=no,directories=no,menubar=no,scrollbars=yes,status=yes,titlebar=no,toolbar=no");
    w.document.write("<body style='margin:0;'><table height=100% align=center><tr><td>");
    w.document.write("<img src='"+url+"' border=0>");
    w.document.write("</td></tr></table></body>");
}

function popup(url, _width, _height) {
    if (window.innerWidth == null) {
        _openerWidth = document.body.clientWidth;
        _openerHeight=document.body.clientHeight;
    }
    else {
        _openerWidth = window.innerWidth;
        _openerHeight = window.innerHeight;
    }
    _left = (_openerWidth - _width) / 2;
    _top = (_openerHeight - _height) / 2;

    w = window.open(url, null, "top="+_top+",left="+_left+",width="+_width+",height="+_height+",location=no,resizable=yes,directories=no,menubar=no,scrollbars=yes,status=yes,titlebar=no,toolbar=no");
}
//popup window with scroll bars and with ability of resize window
function popup2(url, _width, _height) {
    if (window.innerWidth == null) {
        _openerWidth = document.body.clientWidth;
        _openerHeight=document.body.clientHeight;
    }
    else {
        _openerWidth = window.innerWidth;
        _openerHeight = window.innerHeight;
    }
    _left = (_openerWidth - _width) / 2;
    _top = (_openerHeight - _height) / 2;

    w = window.open(url, null, "top="+_top+",left="+_left+",width="+_width+",height="+_height+",location=no,resizable=yes,directories=no,menubar=no,scrollbars=yes,status=yes,titlebar=no,toolbar=yes");
}
function emptyPopup(name, _width, _height){
    if (window.innerWidth == null) {
        _openerWidth = document.body.clientWidth;
        _openerHeight=document.body.clientHeight;
    }
    else {
        _openerWidth = window.innerWidth;
        _openerHeight = window.innerHeight;
    }
    _left = (_openerWidth - _width) / 2;
    _top = (_openerHeight - _height) / 2;
    w = window.open("", name, "top="+_top+",left="+_left+",width="+_width+",height="+_height+",location=no,resizable=no,directories=no,menubar=no,scrollbars=no,status=yes,titlebar=no,toolbar=no");
}
function popupForPrint(url, _width, _height) {
    if (window.innerWidth == null) {
        _openerWidth = document.body.clientWidth;
        _openerHeight=document.body.clientHeight;
    }
    else {
        _openerWidth = window.innerWidth;
        _openerHeight = window.innerHeight;
    }
    _left = (_openerWidth - _width) / 2;
    _top = (_openerHeight - _height) / 2;
    w = window.open(url, null, "top="+_top+",left="+_left+",width="+_width+",height="+_height+",location=no,resizable=no,directories=no,menubar=no,scrollbars=yes,status=yes,titlebar=no,toolbar=yes");
}

var swapImageObject;
var swapImageOldSrc = "";

function swapImage(img, new_src) {
    swapImageObject = img;
    swapImageOldSrc = img.src;
    img.src = new_src;
    img.onmouseout = swapImgRestore;
}

function swapImgRestore() {
    swapImageObject.src = swapImageOldSrc;
}

function setCookie(name, value, days) {
    var today = new Date();
    var expDate = new Date(today.getTime() + days*24*60*60*1000);
    var path='/';

    expires = expDate.toGMTString();
    __rnd = Math.random();

    document.cookie = name+"="+value+"; expires=" + expires+"; path=" + path;
    document.cookie = "__rnd="+__rnd+"; expires=" + expires+"; path=" + path;
}

function setLanguage(id) {
    buf = document.cookie;

    setCookie("lang", id, 30);
    if (buf == document.cookie) return true; else{
        document.location.reload(); false;
    }
}