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

    var cookie = " " + document.cookie;
    var search = " " + name + "=";
    var setStr = null;
    var offset = 0;
    var end = 0;

    if (cookie.length > 0) {
        offset = cookie.indexOf(search);
        if (offset != -1) {
            offset += search.length;
            end = cookie.indexOf(";", offset)
            if (end == -1) {
                end = cookie.length;
            }
            setStr = unescape(cookie.substring(offset, end));
        }
    }
    return(setStr);
}

function winopen(game_code, encodeURL) {
    ctxmGameOpen(game_code, encodeURL);
}



function ctxmGameOpen(game_code, encodeURL) {
        
    var game_mode;
    game_mode = "fun";
      
    if ( document.forms["game_mode_form"].game_mode.length == 2 )
        if ( document.forms["game_mode_form"].game_mode[1].checked == true )
            game_mode = "real";
        
    var width,height;
            
    width = 700; height = 400;
            
    if ( game_code == "WOF" ) { 
        width = 750; height = 520;
    }
    if ( game_code == "HOR" ) { 
        width = 750; height = 475;
    }
    if ( game_code == "VGR" ) { 
        width = 750; height = 430;
    }
    if ( game_code == "SHILO" ) { 
        width = 700; height = 440;
    }
    if ( game_code == "PSHOT" ) { 
        width = 700; height = 535;
    }
    if ( game_code == "PNLT" ) { 
        width = 700; height = 430;
    }
    if ( game_code == "ROLLUP" ) { 
        width = 700; height = 535;
    }
    if ( game_code == "ALEX" ) { 
        width = 755; height = 601;
    }
    if ( game_code == "LOTTO7" ) { 
        width = 750; height = 550;
    }
    if ( game_code == "PBPOKER" ) { 
        width = 713; height = 590;
    }
    if ( game_code == "XG_BNW" ) { 
        width = 750; height = 520;
    }
    
    windop = window.open(encodeURL+"?game_code="+game_code+"&game_mode="+game_mode, game_code,"height="+height+",width="+width+",left=100,top=30, Resizable=yes");

    windop.focus();
}

function rulesopen(game_code, lang_path) {   
    var URL;
    URL = "/"+lang_path+"/rules_"+game_code+".htm";
    window.open(URL,"casino_rules","directories=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no,width=750,height=500");  
}     
        
      
// сохраняем в кукисах информацию о вборе режима игры
function saveGameMode( game_mode ) {
    setCookie("game_mode", game_mode);
//alert('saveGameMode');
}
        
function init_lobby_page() {
    if ( getCookie("game_mode") == "real" ) {
        document.forms["game_mode_form"].game_mode[1].checked = true;
    //alert('init_lobby_page');
    }
}


function init_login_page() {
    // устанавливаем выбор режима игры на демо-игру
    setCookie("game_mode", "fun");
//alert('init_login_page');
}


function init_page() 
{    
    if(document.forms["jsp_name"]){
        if ( document.forms["jsp_name"].name.value == "lobby" ) {
            init_lobby_page();
        }
        if ( document.forms["jsp_name"].name.value == "login" ) {
            init_login_page();
        }
    }
}


function openGame(game_code, encodeURL, game_type, window_name, fullscreen) {
        
    var game_mode;
    game_mode = "fun";
       
    if ( document.forms["game_mode_form"].game_mode.length == 2 )
        if ( document.forms["game_mode_form"].game_mode[1].checked == true )
            game_mode = "real";

    var width,height;
            

    if ( fullscreen == "fullscreen" ) {
        var params = 'width=' + screen.width;
        params += ', height=' + screen.height;
        params += ', top=0, left=0'
        params += ', fullscreen=yes, resizable=yes';

        windop = window.open(encodeURL+"?fullscreen=true&game_type="+game_type+"&game_code="+game_code+"&game_mode="+game_mode, window_name, params); //height="+height+",width="+width+",left=100,top=30,
    } else if (game_code == "tribble") {

        width = 450; height = 750;

        windop = window.open(encodeURL+"?fullscreen=true&game_type="+game_type+"&game_code="+game_code+"&game_mode="+game_mode, window_name,"height="+height+",width="+width+",left=100,top=30, Resizable=yes");
    } else if (game_code == "zodiac") {

        width = 400; height = 500;

        windop = window.open(encodeURL+"?fullscreen=true&game_type="+game_type+"&game_code="+game_code+"&game_mode="+game_mode, window_name,"height="+height+",width="+width+",left=100,top=30, Resizable=yes");
    }  else {

        width = 640; height = 480;

        windop = window.open(encodeURL+"?fullscreen=true&game_type="+game_type+"&game_code="+game_code+"&game_mode="+game_mode, window_name,"height="+height+",width="+width+",left=100,top=30, Resizable=yes");
    }
            
    windop.focus();
}


// проверка данных формы вывода денег из ne-казино
function checkMoneyOutForm ( form, confirmString ) {
    
    if (  validateMoneyOutForm(form)  ) { 
        if(  confirm(confirmString)){
            return true;
        }
    }
    return false;
}

// открывает окно истории 
function openNEHistory( ) {

    windop = window.open("/entertainment/casino/history.do", "history","toolbar=no, scrollbars=yes, height=650, width=600, left=100, top=30, Resizable=yes");
            
    windop.focus();
}

function disableButton() {

    var buttons = new Array(
        "moneyInButton",
        "moneyOutButton",
        "moneyOutAllButton",
        "moneyInAllButton",
        "loginButton",
        "loginButton2",
        "logoutButton",
        "netellerInitialFormSubmit",
        "netellerConfirmFormSubmit",
        "depositFonbetPointsButton",
        "webmoneyPurseBinding"
        );

    var i;
    var button;

    for (i = 0; i < buttons.length; i++) {
        button = document.getElementById(buttons[i]);

        if (button != null) {
            button.disabled = true;
        }
    }
}

function time() {
    var obj = document.getElementById('timer');
    
    if (obj != null) {
        var till = new Date(2009, 5, 1, 10, 0, 0, 0);
        var currentTime = new Date();
        var millisecondsTill = till.getTime() - currentTime.getTime();
        var seconds = div(millisecondsTill, 1000);
        var hours = div(seconds, 3600);
        var minutes = div(mod(seconds, 3600), 60);
        seconds = seconds - (hours * 3600 + minutes * 60);

        if (hours < 10) {
            hours = "0" + hours;
        }
        if (minutes < 10) {
            minutes = "0" + minutes;
        }
        if (seconds < 10) {
            seconds = "0" + seconds;
        }

        obj.innerHTML = hours + ":" + minutes + ":" + seconds;
        
        return true;
    }

    return false;
}

function timer() {
    if (time()) {
        setInterval('time()', 1000);
    }
}

function mod(a, b) {
    return a % b;
}

function div(a, b) {
    return (a - mod(a ,b))/b;
}

function showSubLinks() {
    var handRaceLinkObj = document.getElementById("handRaceLink");
    var rakeRaceLinkObj = document.getElementById("rakeRaceLink");

    if (handRaceLinkObj && rakeRaceLinkObj) {
        handRaceLinkObj.style.display = "list-item";
        rakeRaceLinkObj.style.display = "list-item";
    }
}