function changeLang(lang)
{
    window.location.href =  "/default.htm?lang=" + lang + "&" + sCutLang;
}

function Terminology(strTerm)
{
    window.document.location.href="poker-terminology.htm?" + sCut + "#"+strTerm;
}

function OpenCasinoDownload()
{  
    document.location.href = "/" + sLang + "/download.htm?" + sCut  + "&dl=" + casinoDl;    
    if(sGID != '0')
    {
         window.open("/CasinoInstaller?" + sCut + "&dl=" + casinoDl ,"popDown","width=1,height=1,top=0,left=0");
    }
    else
    {    
        window.open( casinoRealInstallerPath + "/CasinoInstaller?mode=1&" + sCut + "&dl=" + casinoDl,"popDown","width=1,height=1,top=0,left=0");
    }
}

function OpenPokerDownload()
{
    document.location.href = "/" + sLang + "/download_poker.htm?" + sCut + "&dl=" + pokerDl;
    if(sGID != '0')
    {
        window.open("/PokerInstaller?" + sCut + "&dl=" + pokerDl,"popDown","width=1,height=1,top=0,left=0");
    }
    else
        window.open( pokerRealInstallerPath + "/PokerInstaller?Real=1&" + sCut + "&dl=" + pokerDl,"popDown","width=1,height=1,top=0,left=0");
}
function OpenITCasinoDownload()
{  
    document.location.href = "/" + sLang + "/download.htm?" + sCut  + "&dl=" + casinoDl;     
    if(sGID != '0')
    {
         window.open("/CasinoInstaller?" + sCut + "&dl=" + casinoDl,"popDown","width=1,height=1,top=0,left=0");
    }
    else
    {    
        window.open(casinoITRealInstallerPath + "CasinoInstaller?mode=1&" + sCut + "&dl=" + casinoDl,"popDown","width=1,height=1,top=0,left=0");
    }
}

function OpenITPokerDownload()
{
    document.location.href = "/" + sLang + "/download_poker.htm?" + sCut + "&dl=" + pokerDl;
    if(sGID != '0')
    {
        window.open("/PokerInstaller?" + sCut + "&dl=" + pokerDl,"popDown","width=1,height=1,top=0,left=0");
    }
    else
        window.open( pokerITRealInstallerPath + "/PokerInstaller?Real=1&" + sCut + "&dl="+pokerDl,"popDown","width=1,height=1,top=0,left=0");
}


/*this part hadels the registration*/

function getCookieRegistration(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) 
                        return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

 function setRegistrationCookie(name)
{
    var d = new Date();
    d.setTime(d.getTime() + (1000*60*60*24*60));
    document.cookie= name + "=1;expires=" + d.toGMTString() + ";path=/";                   
}

function isRegistered()
{
    if( getCookieRegistration("registration") )
        return true;
    return false;
}

function OpenRegistration(brand)
{
    if (sRg == '0')
    {
        if (isRegistered())      
        {
            if (brand == 'casino')
            {
                if (sLang == 'it')
                     OpenITCasinoDownload();
                else
                     OpenCasinoDownload();
            }
            else if (brand == 'poker')
            {
                 if (sLang =='it')
                     OpenITPokerDownload();
                 else
                    OpenPokerDownload();
            }
        }
        else
        {
            document.location.href = "/" + sLang + "/registration.htm?brand=" + brand  + "&" + sCut;     
        }
    }
    else
    {
        if (brand == 'casino')
        {
            if (sLang == 'it')
                 OpenITCasinoDownload();
            else
                 OpenCasinoDownload();
        }
        else if (brand == 'poker')
        {
             if (sLang =='it')
                 OpenITPokerDownload();
             else
                OpenPokerDownload();
        }
    }
}

function submitForm(brand)
{
     if (validateForm())    
    {      
        setRegistrationCookie('registration');       
        document.regForm.myAction.value="ok";
        document.regForm.action="/registration_submit.htm?"+sCut;
        document.regForm.submit();        
        if (brand == 'casino')
        {
                    //document.location.href = "/" + sLang + "/download.htm?" + sCut + "&dl=644";
            if (sLang == 'it')
                OpenITCasinoDownload();
            else    
                OpenCasinoDownload();
        }
        else if (brand == 'poker')
        {
                    //document.location.href = "/" + sLang + "/download_poker.htm?" + sCut + "&dl=645";
            if (sLang == 'it')
                OpenITPokerDownload();
            else
                OpenPokerDownload();
        }
     }    
 }

function openErrorMsg(msg)
{
    var p=document.getElementById("errordiv");
    p.style.visibility = "visible";
    var m=document.getElementById("msg");
    m.innerHTML=msg;
}

function closeErrorMsg()
{
    var p=document.getElementById("errordiv");
    p.style.visibility = "hidden";
}

function check_mail(str)
{
            var myRegExp = /^([a-zA-Z0-9_\-])+([a-zA-Z0-9_\.\-])*\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})$/
            if( ! str.match( myRegExp ) )
            {
                    return false
            }
            return true
    }

function check_str(str)
{
       var myRegExp = /^[^;~\^&\*!<>"\/|%\?@$\+=\{\}\(\)\[\]\\]*$/
        if( ! str.match( myRegExp ) )
                return false

        return true
}

function check_name(str)
{
        var myRegExp = /^[^;~\^&\*!<>"\/|%\?@$0-9\+=\{\}\(\)\[\]\\]*$/ 
        if( ! str.match( myRegExp ) )
                return false

        return true
}

function check_num(str)
{
        var myRegExp = /^[0-9]{1,3}$/
        if( ! str.match( myRegExp ) )
                return false

        return true
}

function check_phonenum(str)
{
    if(str ==  "")
        return  true
     else
     {
        var myRegExp = /^[0-9\-]{1,20}$/
        if( ! str.match( myRegExp ) )
                return false
     }
    return true
}
function trimString(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}

function verifydata()
{
   /* if (sLang == 'de')
    {
        var selectObj = document.regForm.Country;
        var index1 = selectObj.selectedIndex;
        var objForm = document.regForm;

        if (selectObj.options[index1].value != "United States")
        {
            objForm.State.disabled = true
        }
        else
            objForm.State.disabled = false
     }*/

}

function validateForm()
{    
    //first name validation 
    tmpObj =document.getElementById("FirstName");
    tmpStr = trimString(tmpObj.value);
     if (tmpStr == "")
    {
        openErrorMsg(error_firstname_empty);
        return false;
    }
     if (!check_name(tmpStr))    
    {
        openErrorMsg(error_firstname_valied);
        return false;
    } 
    //last neme validation 
    tmpObj =document.getElementById("LastName");
    tmpStr = trimString(tmpObj.value);
     if (tmpStr == "")
    {
        openErrorMsg(error_lastname_empty);
        return false;
    }
    if (!check_name(tmpStr))    
    {
        openErrorMsg(error_lastname_valied);
        return false;
    } 
    //email validation 
    tmpObj =document.getElementById("Email");
    tmpStr = trimString(tmpObj.value);
    if (tmpStr == "")
    {
        openErrorMsg(error_email_empty);
        return false;
    }
    if (!check_mail(tmpStr))    
    {
        openErrorMsg(error_email_valied);
        return false;
    }    
   
    //country validation 
    tmpObj =document.getElementById("Country");
    tmpStr = trimString(tmpObj.value);
    if (tmpStr == "none")
    {
        openErrorMsg(error_country_empty);
        return false;
    }
  
    //phone validation 
    tmpObj =document.getElementById("Phone");
    tmpStr =tmpObj.value;
    if (tmpStr == "")
    {
        openErrorMsg(error_phonenumber_empty);
        return false;
    }
    if (!check_phonenum(tmpStr))    
    {
        openErrorMsg(error_phonenumber_valied);
        return false;
    }
    
   
    return true;
    
}

function setFocus()
{
    var tmpObj =document.getElementById("FirstName");
    tmpObj.focus();
}

function openBJScholl()
{
    var w = 794;
    var h = 517;
    var l = 1; 
    var t = 1; 
    var LocationString ="http://standalone.888.com/bjschool/Free/bjschool.htm?" + sCut;
    var x = window.open(LocationString,"BJScholl","status=no,toolbar=no,menubar=no,location=no,left=" + l + ",top=" + t + ",width=" + w + ",height=" + h)   
}
