function OpenPoker(loc) {
    var w = 820;
    var h = 565;
    var l = (window.screen.width-w)/2;
    var t = (window.screen.height-h)/2; 
    
    //if NOT from landing page (out of the frame)
    if (window.name != "") {                 
        setDownloadStatus();
    }
    
    var filename = "http://ndl.888.com/poker/flashpoker_real/application/RLFLashPoker.html?langid=" + sLang + "&brand=1&skin=0&" + sCutLang + "&dl=" + loc; 
 
    if (sLang == "es" || sLang == "de" || sLang == "fr" || sLang == "en" || sLang == "ru" || sLang == 'mx'  || sLang == 'la' || sLang == 'br')
        filename = "http://ndl.888.com/poker/flashpoker_real/application/RLFLashPoker.html?langid=" + sLang + "&brand=1&skin=4&" + sCutLang + "&dl=" + loc; 
    else
        filename = "http://ndl.888.com/poker/flashpoker_real/application/RLFLashPoker.html?langid=" + sLang + "&brand=1&skin=0&" + sCutLang + "&dl=" + loc;
        
    window.open(filename ,null, "height=" + h + ",width=" + w + ",status=no,toolbar=no,menubar=no,location=no,resize=no,left="+l+",top="+t);
}

function setDownloadStatus() {   
    parent.isDownload = true;
}

function OpenDownPoker(loc) {     
    try {
        ntptAddPair("dl",loc);
        ntptEventTag("ev=download_poker_from_"+sLang);
    }catch(err){}
    
    if (sLang == 'en') {    
        var url="http://www.pacificpoker.com/PokerInstaller?" +sCut + "&dl="+loc;
        var origcid = getCookieValue(origCoockieName);
        var username = getCookieValue(userCoockieName);
        if (origcid != null)
            url = url + "&originalcid=" + origcid;
        if (username != null)
            url = url + "&username=" + username;
    }   
    else if (sLang == 'it') 
        url="http://" + ItalyDomainPoker + "/PokerInstaller?" +sCut + "&dl="+loc;
    else if (sLang == 'ar' || sLang == 'mx'  || sLang == 'la')
        url="http://es.pacificpoker.com/PokerInstaller?lang=es&" +sCutLang + "&dl="+loc;       
    else if (sLang=='cz')
        url="http://cs.pacificpoker.com/PokerInstaller?lang=cs&" +sCutLang + "&dl="+loc;       
    else if (sLang == 'br') 
        url="http://pt.pacificpoker.com/PokerInstaller?" +sCutLang + "&dl="+loc;       
    else if (sLang == 'cns') 
        url="http://www.pacificpoker.com/PokerInstaller?" +sCutLang + "&lang=en&dl="+loc;       
    else if (sLang == 'ee') 
        url="http://et.pacificpoker.com/PokerInstaller?" +sCutLang + "&lang=et&dl="+loc;       
	else    
        url="http://" + sLang + ".pacificpoker.com/PokerInstaller?" +sCut + "&dl="+loc;
    window.open(url,"popDown","width=1,height=1,top=0,left=0");
    //if arrived from landing page (out of the frame)
    if (window.name == "") {
        document.location.href = "/?page=download_short_poker&" + sCut;        
    }
    else {    
        setDownloadStatus();
        if (sLang == 'de')
            document.location.href = "/de/poker/download_short.htm?" + sCut + "&dl="+loc;       
        else if (sLang == 'bg'  || sLang == 'el'  || sLang == 'hu'  || sLang == 'pl'  || sLang == 'ro' || sLang == 'ee' || sLang == 'lt') 
            document.location.href = "/new888/home.htm?page=download_short_poker&" + sCut + "&dl="+loc; 
        else if ( sLang =='jp' )  
            document.location.href = "/?page=download_short_poker&" + sCut + "&dl="+loc; 
        else
            document.location.href = "/new888/home.htm?page=download_short_poker&" + sCut + "&dl="+loc;         
    }
    
}

function OpenPokerDownload(loc) {
    OpenDownPoker(loc);
} 

function getCookieValue(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 DownloadPoker(loc, brand)
{
    try {
        ntptAddPair("dl",loc);
        ntptEventTag("ev=download_poker_from_"+sLang + "_version58");
    }catch(err){}
    var currentDomain = location.host;
    var ipPattern = /\d+\.\d+\.\d+\.\d+/;
    var devDomainPattern = /\.dev:\d{4}$/; 
    
    var url="http://www.pacificpoker.com/PokerInstaller?" +sCut + "&dl="+loc + "&brand=" + brand;
    if (ipPattern.test(currentDomain) || devDomainPattern.test(currentDomain))
    {
         url="http://10.20.40.14:5500/PokerInstaller?" +sCut + "&dl="+loc + "&brand=" + brand;    
    }
    else if (currentDomain.indexOf("stage.") != -1)
    {
           url="http://newstage.pacificpoker.com/PokerInstaller?" +sCut + "&dl="+loc + "&brand=" + brand; 
    }
    
    var origcid = getCookieValue(origCoockieName);
    var username = getCookieValue(userCoockieName);
    if (origcid != null)
        url = url + "&originalcid=" + origcid;
    if (username != null)
        url = url + "&username=" + username;

    window.open(url,"popDown","width=1,height=1,top=0,left=0");
    setDownloadStatus();
    document.location.href = "/new888/home.htm?page=download_short_poker_v58&" + sCut + "&dl="+loc;             
}

//this function downlads poker client with 8$ bonus (ver- 5.75) also an Unica event is invoked
function openDownWsop(location, unicaMsg)
{
   try {ntptEventTag("ev=wsop888poker_"+sLang+"_DOWNLOAD_" + unicaMsg);} catch(err) {} 
   
   //since  WsopInstaller is only in En no need to pass language to the installer servlet
   var url="/WsopInstaller?" + sCutLang + "&wsopLang=" + sLang + "&dl="+location;
    window.open(url,"popDown","width=1,height=1,top=0,left=0");    
}
