window.defaultStatus="Bob4Men";

function openPopup( strURL, intWidth, intHeight, intLeft, intTop, wParams ) {
    var intScreenHeight = 0;
    var intScreenWidth = 0;
    //  get screen size
    if( parseInt( navigator.appVersion ) > 3 ) {
        intScreenHeight = screen.availHeight;
        intScreenWidth = screen.availWidth;
        if( !intScreenHeight ) {
            intScreenHeight = screen.height;
            intScreenWidth = screen.width;
        }
    } else if(
        navigator.appName == "Netscape" &&
        parseInt( navigator.appVersion ) == 3 &&
        navigator.javaEnabled()
    ) {
        var jToolkit = java.awt.Toolkit.getDefaultToolkit();
        var jScreenSize = jToolkit.getScreenSize();
        intScreenHeight = jScreenSize.height;
        intScreenWidth = jScreenSize.width;
    } else {
    }
    //  adjust dimensions if necessary
    if( intHeight > intScreenHeight ) {
        intHeight = intScreenHeight - 10;
    }
    if( intWidth > intScreenWidth ) {
        intWidth = intScreenWidth - 10;
    }
    // center window if position is not specified
    if(undefined == intLeft){
        intLeft = (intScreenWidth - intWidth) / 2;
    }
    if(undefined == intTop){
        intTop = (intScreenHeight - intHeight) / 2;
    }

    if(undefined == wParams){
        wParams = "";
    }
    if(wParams.length > 0) wParams = "," + wParams;

    var wnd = window.open( strURL,'_blank','status=1,toolbar=0,scrollbars=0,location=0,menubar=0,resizable=1,width=' + intWidth + ',height=' + intHeight + ',left=' + intLeft + ',top=' + intTop + wParams);
    wnd.focus();

    return;
}

function resizeWindow(wwidth, wheight)
{
    wwidth += 14;
    wheight += 86;
    var swidth = screen.availWidth;
    var sheight = screen.availHeight;

    if(swidth < wwidth) wwidth=swidth;
    if(sheight < wheight) wheight=sheight;

    var x = (swidth - wwidth) / 2;
    var y = (sheight - wheight) / 2;

    window.moveTo(x,y);
    window.resizeTo(wwidth, wheight);
}

function checkLang(lang)
{
    var re, result;

    if(lang == '') return true;

    re = new RegExp("/" + lang + "/");
    str = document.location.href;
    result = re.test(str);

    return result;
}

function getScrollX()
{
    return (document.documentElement.scrollLeft || document.body.scrollLeft);
}

function getScrollY()
{
    return (document.documentElement.scrollTop || document.body.scrollTop);
}

function addScrollListener(func) {
    var oldonscroll = window.onscroll;
    if (typeof window.onscroll != 'function') {
        window.onscroll = func;
    } else {
        window.onscroll = function() {
            if (oldonscroll) {
                oldonscroll();
            }
            func();
        }
    }
}

function getViewportWidth()
{
    return window.innerWidth || (document.documentElement.clientWidth || document.body.clientWidth);
}

function getViewportHeight()
{
    return window.innerHeight || (document.documentElement.clientHeight || document.body.clientHeight);
}

function woopen(href)
{
    if(window.opener) { window.opener.open(href, '_self'); window.close(); } else window.open(href, '_self');
    return false;
}

function oI(href)
{
    openPopup(href, 840, 700, undefined, undefined, 'scrollbars=1');
    return false;
}

function addOnLoadListener(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            if (oldonload) {
                oldonload();
            }
            func();
        }
    }
}

/* Disclaimer functions */

function fixDisclaimerHeight()
{
    var disclaimer = document.getElementById("disclaimer");
    if(disclaimer){
        var newHeight = window.innerHeight > document.body.clientHeight ? window.innerHeight : document.body.clientHeight;
        disclaimer.style.height = newHeight + "px";
    }
}

function closeDisclaimer()
{
    if(!document.getElementById('cbConfirm').checked) {
        var disclaimerAlert = document.getElementById("disclaimer-alert");
        if(disclaimerAlert) 
            alert(disclaimerAlert.innerHTML);
        else
            alert('Error: Localization not found');
        return;
    }
    
    document.getElementById("disclaimer").style.display = "none";
    if(d=document.getElementById("disclaimer-container")) d.style.display = "none";
    var http_request = createHttpRequest();
    http_request.open('GET', '/set_disclaimer.php?rnd=' + Math.random(), true);
    http_request.send(null);
}

var disclaimer_scroll_value;
function disclaimerOnScroll()
{
    disclaimer_scroll_value = getScrollY();
    window.setTimeout("disclaimerApplyScroll()", 150);
}

function disclaimerApplyScroll()
{
    default_margin = 80;
    sheet_height = 572;
    viewport_height = getViewportHeight();
    margin = default_margin;
    if(viewport_height > sheet_height + default_margin){
        margin = default_margin + disclaimer_scroll_value;
    } else if (viewport_height > sheet_height ){
        margin = (viewport_height-sheet_height)/2 + disclaimer_scroll_value;
    }
    document.getElementById("disclaimer_sheet").style.marginTop = margin + "px";
}

function setDisclaimer()
{
	var disclaimer = document.getElementById("disclaimer");
    if(!disclaimer) return false;
    if(inCookieArray("VISITED", "/disclaimer/")){
    	disclaimer.style.display = "none";
        return false;
    }
    fixDisclaimerHeight();
    disclaimerOnScroll();
    addScrollListener(disclaimerOnScroll);
}

/* End Disclaimer */

/* Cookie handling functions */

function getCookieVal(offset) {
    var endstr = document.cookie.indexOf (";", offset);
    if (endstr == -1) {
        endstr = document.cookie.length;
    }
    return unescape(document.cookie.substring(offset, endstr));
}

function getCookie(name) {
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen) {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg) {
            return getCookieVal(j);
        }
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0) break;
    }
    return "";
}

function setCookie(name, value, expires, path, domain, secure) {
    document.cookie = name + "=" + escape (value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

// handling comma separated arrays in cookie value

function getarraysource(arr)
{
     var str = "";
     for (var i=0; i<arr.length; i++)
     {
          if (i==arr.length-1)
               str += "\"" + arr[i] + "\"" ;
          else
               str += "\"" + arr[i] + "\"" + ", ";
     }
     return str+"";
}

function getarrayvalue(str)
{
    var arr = str.split(",");
    var result = [];
    var j = 0;
    for (var i=0; i<arr.length; i++)
    {
        entry = unescape(arr[i]);
        re = new RegExp("\"(.*)\"","gi");
        if(matches = re.exec(entry)){
            result[j++] = matches[1];
        }
    }
    return result;
}

function inCookieArray(name, value)
{
	var n = getCookie(name);
    var arr = getarrayvalue(n ? n : '');
    
    result = false;
    for(var i in arr){
        if(arr[i] == value) {
            result = true;
            break;
        }
    }
    return result;
}

/* End Cookie handling functions */


/* Pop-up layers functions */

var image_menu_first_load = false;
function show_image_menu(id)
{
    if (image_menu_first_load==false && (image_menu = document.getElementById('imenu_'+id)))
        image_menu.style.display ="block";
}

function hide_image_menu(id)
{
    if (image_menu_first_load==false && (image_menu = document.getElementById('imenu_'+id)))
        image_menu.style.display ="none";
}

function over_image_menu(id)
{
    image_menu_first_load = true;
    if(image_menu = document.getElementById('imenu_'+id))
        image_menu.style.display ="block" ;
}

function out_image_menu(id)
{
    image_menu_first_load = false;
    if(image_menu = document.getElementById('imenu_'+id))
        image_menu.style.display ="none" ;
}

/* End Pop-up layers functions */

/* Top menu counters load */

function getCounters()
{
    $.getJSON(
        '/get_counters.php?t=' + getTimeSeed(),
        function(counters) {
            for(var name in counters)
                $("#"+name).html('('+counters[name]+')');
        }
    );
}

function setCounters()
{
    getCounters();
    window.setInterval('getCounters()', 180000);
}

/* End Top menu counters load */

