var windPop = null;
var isDownload = false;
var IntroWnd = false;
var PopUpViewGame = false;
var InstallSerial = "938058";

 // Resize
if(document.all)
{
    var x = screen.width;
    var y = screen.height-22;
    window.moveTo(0,0);
    window.resizeTo(x,y);
}


var ShowPopup = true;

if (getCookie("flag"))
	if(getCookie("flag").substring(3,4) == "1")	// "1001" or "0001"
		ShowPopup = false;
	
function mouseDown(mEvent)
{

	var ref = ""
	var srcEl = ""
		
	if (mEvent.srcElement)
		srcEl = mEvent.srcElement
		
	else if (mEvent.target)
		srcEl = mEvent.target
	
	
	//check if the element that was pressed was an anchor
	while ((srcEl != null) && (srcEl.tagName != "A") && (srcEl.tagName != "BODY") && (srcEl.tagName != "AREA"))
		if (mEvent.srcElement)
				srcEl = srcEl.parentElement
		else if (mEvent.target)
				srcEl = srcEl.parentNode
	
	if ( ((srcEl.tagName == "A") || (srcEl.tagName == "AREA")) && (srcEl != null) )
	{
		if(mEvent.srcElement)
			ref = srcEl.getAttribute("href")
		else
			{
				var lastSlash = document.location.href.lastIndexOf("/");
				var directory = document.location.href.substring(0,lastSlash);
				ref = directory + '/' + srcEl.getAttribute("href");
			}
			
		if (ref)
		{
			//alert(ref);
			ref = ref.toUpperCase();
			//check if the the link of the anchor points back to this site
			if ((ref.indexOf("POKER-ON-NET") != -1)||
				(ref.indexOf("INSTALLER") != -1) || 
			(ref.indexOf("10.10.10") != -1) || 
			(ref.indexOf("DOWNLOAD(") != -1) || 
			(ref.indexOf("NODOWN(") != -1))
			{
			
				ShowPopup = false
			}
		}
	}
}

function beforeUnload()
{
	if (ShowPopup)
	{
		if (getCookie("flag").substring(3,4) == "2")
		{
			window.open("http://www.888.com/new888/lang/en/texts/exitpage.htm?sr=" + getCookie("serial"),"OPP","width=770,height=485,left=50,top=50,resizable=yes,status=no,scrollbars=auto,toolbar=no,menubar=no");
		}
		else
		{
			if (getCookie("isDownload") == null)
			{
				if (window.confirm("Start Playing Poker Now!\nNo download required."))
				{
					openGame('1');
				}
			}
		}
	}
}


function DownloadLink(obj,strBrand)
{
	//set download flag to true
	if (getCookie("isDownload") == null)
	{
		setCookie("isDownload", "true" ,null,"/")	
	}
	
	var tmpHref = document.getElementById(obj);	
	if(strBrand == 'casino')
		tmpHref.href = "http://www.888.com/CasinoInstaller?lang=en&sr=" + getCookie("serial");	
	else
		{
		tmpHref.href = "http://www.pacificpoker.com/PokerInstaller?sr=" + getCookie("serial");
		}
} 


function Download(location)
{
	//set download flag to true
	if (getCookie("isDownload") == null)
	{
		setCookie("isDownload", "true" ,null,"/")	
	}
	
	var tmpSr = InstallSerial;
    if(getCookie("serial"))
        tmpSr = getCookie("serial");
        
    window.location.href = "http://www.pacificpoker.com/PokerInstaller?sr=" + tmpSr;  
        
	//var dPath = "";
	//if (window.location.href.indexOf("/small")!=-1){dPath = "../";}
        //parent.isDownload = true;
	
         
        //window.open("http://www.pacificpoker.com/PokerInstaller?sr=" + tmpSr + ",'popupDown','width=1,height=1,top=0,left=0');
        //window.location.href = dPath + "home.htm?page=download_short&" + GetsCut(location) + "&dl=" + location;
}

function ContactUs(event)
{
	
	var obj
	if (!document.all)//if firefox
	{
		obj = event.target.parentNode
		obj.href = "javascript:void 0;";
		
	}	
	
    var w = 793;
    var h = 517;
    var LocationString = "http://www.pacificpoker.com/contactusform/contactus.htm";
    var l = 1; //(window.screen.width-w)/2;
    var t = 1; //(window.screen.height-h)/2;
    
    window.open(LocationString,"contactUsWnd","status=no,toolbar=no,menubar=no,location=no,left=" + l + ",top=" + t + ",width=" + w + ",height=" + h)
    
    if (!document.all)
	{		
		setTimeout("fixLink('" + obj.id + "','http://www.pacificpoker.com')",200);				
	} 
}

function NoDown(location)
{
	var tmpHref = document.getElementById(location);	
    tmpHref.href = "javascript:void(0);"
    
	openGame('1');
}


function openGame(tmp)
{
    var tmpSr = InstallSerial;
    if( getCookie("serial") )
        tmpSr = getCookie("serial");

    var w = 795;
    var h = 545;
    var LocationString;
    var l = (window.screen.width-w)/2;
    var t = (window.screen.height-h)/2;
	
	if(tmp=='1')
		LocationString = "http://java1.pacificpoker.com/poker.asp?Real=" + tmp + "&s=11111111111111" + "&sr=" + tmpSr;
	else
		LocationString = "http://java1.pacificpoker.com/poker.asp?Real=1&s=11111111111111" + "&sr=" + tmpSr;
		
	if (window.screen.availWidth==800)
	{
		l = 0;
		t = 0;
		w = window.screen.availWidth;
		h = window.screen.availHeight;
	}
    var windowprops = "location=no,scrollbars=no,menubars=no,toolbars=no,resizable=no,left=" + l + ",top=" + t + ",width=" + w + ",height=" + h;
    var popup = window.open(LocationString,"PokerGame",windowprops);
}


function pokerSchool(event)
{
	var obj
	if (!document.all)//if firefox
	{
		obj = event.target.parentNode
		obj.href = "javascript:void 0;";
		
	}	
	
	var tmpSr = InstallSerial;
    if(getCookie("serial"))
        tmpSr = getCookie("serial");
	
	var Location;
	Location = "http://school.pacificpoker.com?sr=" + tmpSr;  
	window.open(Location); 
	
	if (!document.all)
	{		
		setTimeout("fixLink('" + obj.id + "','http://school.pacificpoker.com')",200);				
	} 
		
}


function onlineCasino(event)
{
	var tmpSr = InstallSerial;
    if(getCookie("serial"))
        tmpSr = getCookie("serial");
	
	var Location;
	Location = "http://www.online-casino.com?sr=" + tmpSr;  
	window.open(Location); 
	
		
}


function fixLink(o,link)
{	
	var link = document.getElementById(o)
	link.href = link; 
}

function con(event)
{
	
	var obj
	if (!document.all)//if firefox
	{
		obj = event.target.parentNode;
		obj.href = "javascript:void 0;";
	}	
	
	var tmpSr = InstallSerial;
    if(getCookie("serial"))
        tmpSr = getCookie("serial");

	//var tmpHref = document.getElementById(obj);	
	//tmpHref.href="javascript:void(0);";
	
	var Location;
	Location = "http://www.888.com?sr=" + tmpSr;  
	window.open(Location);  
	
	if (!document.all)
	{		
		setTimeout("fixLink('" + obj.id + "','http://www.888.com')",200);				
	} 
	
	
}
function affiliates(event)
{
	var tmpSr = InstallSerial;
    if(getCookie("serial"))
        tmpSr = getCookie("serial");
      
    var w = 794;
	var h = 530;


	var obj
	if (!document.all)//if firefox
	{
		obj = event.target
		obj.href = "javascript:void 0;";
		
	}	
	
	
	var Location;
	Location ="http://affiliates.888.com?trcode=TR00000012&sr=" + tmpSr;  
	window.open(Location);
	
	
	
	//Location = "http://affiliates.888.com?trcode=TR00000012&sr=" + tmpSr;  
	//window.open(Location,"","resizable=yes,status=no,scrollbars=no,toolbar=no,menubar=no,left=0,top=0,width=" + w + ",height=" + h);  
	
	if (!document.all)
	{		
		setTimeout("fixLink('" + obj.id + "','http://www.888.com')",200);				
	} 
	
}

function PlayersClub(event)
{
	var tmpSr = InstallSerial;
    if(getCookie("serial"))
        tmpSr = getCookie("serial");

	
	var obj
	if (!document.all)//if firefox
	{
		obj = event.target
		obj.href = "javascript:void 0;";
	}	
	
	var Location;
	Location = "http://playersclub.pacificpoker.com?sr=" + tmpSr;
	window.open(Location); 	
	
	if (!document.all)
	{		
		setTimeout("fixLink('" + obj.id + "','http://playersclub.pacificpoker.com')",200);				
	} 
}


function privacyPolicy()
{
	var tmpSr = InstallSerial;
    if(getCookie("serial"))
        tmpSr = getCookie("serial");
        
    window.location.href = "http://www.pacificpoker.com?page=privacyandsecurity&?sr=" + tmpSr;  
}

function PokerTutorial(dl)
{
	var tmpSr = InstallSerial;
    if( getCookie("serial") )
        tmpSr = getCookie("serial");
        
	var w = 794;
	var h = 530;

	var Location;
	Location = "http://standalone.888.com/pokertutorial/pokertutorial.htm?sr=" + tmpSr;
	window.open(Location,"","resizable=yes,status=no,scrollbars=no,toolbar=no,menubar=no,left=0,top=0,width=" + w + ",height=" + h);
}

function SesCloseWin()
{
	SesClose = true;
}

function changeSelectSR(newSR)
{
	SelectSR = newSR;
	srChanged = true;
}



function questionOpener()
{   
	if(confirm('Click OK to download our free software while browsing the site'))
		{
			Download('67');
		}
}

function openIntroWnd()
{
    //currently will open same pop for all countries !!!
    
	setTimeout("questionOpener()", 1000);
}

function closeIntroWnd()
{
	if (!document.layers)
	{
		if(IntroWnd){IntroWnd.close();}
		if(PopUpViewGame){PopUpViewGame.close();}
	}
}
						
function OpenExitPage()
{
    closeIntroWnd();
		if(!document.layers && isDownload!=true)
		{
				if(confirm("Start Playing Poker Now!\nNo download required."))
				{
					openGame('1');	
				}
		}
}
				
function window_onscroll()
{
	var pictTop = 160;
	var scrollTo = 0;
    if(document.all)
    {
		if(window.divDownload)
		{
			if(document.body.scrollTop > pictTop){scrollTo = 15;}
			else{scrollTo = pictTop - document.body.scrollTop - 15;}
			window.divDownload.style.top = document.body.scrollTop + scrollTo;
		}    
    }
}
	
function setPosition()
{
	if((document.all) && (window.divDownload != null))
    {
        window.divDownload.style.position = "absolute";
        var pos = (document.body.offsetWidth - 770)/2 + 5;
        if(pos < 10){pos=10;}
        window.divDownload.style.left=pos;
    }
}



function getCookie(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));
}


/**
 * Sets a Cookie with the given name and value.
 *
 * name       Name of the cookie
 * value      Value of the cookie
 * [expires]  Expiration date of the cookie (default: end of current session)
 * [path]     Path where the cookie is valid (default: path of calling document)
 * [domain]   Domain where the cookie is valid
 *              (default: domain of calling document)
 * [secure]   Boolean value indicating if the cookie transmission requires a
 *              secure transmission
 */
function setCookie(name, value, expires, path, domain, secure)
{
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

function PageQuery(q) 
{
	if(q.length > 1) 
		this.q = q.substring(1, q.length);
	else 
		this.q = null;
		
	this.keyValuePairs = new Array();
	if(q) 
	{
		for(var i=0; i < this.q.split("&").length; i++) 
		{
			this.keyValuePairs[i] = this.q.split("&")[i];
		}
	}
	this.getKeyValuePairs = function() 
		{ 
			return this.keyValuePairs; 
		}
	this.getValue = function(s) 
		{
			for(var j=0; j < this.keyValuePairs.length; j++) 
			{
				if(this.keyValuePairs[j].split("=")[0].toLowerCase() == s.toLowerCase())
				{
					return this.keyValuePairs[j].split("=")[1];
				}
			}
			return false;
		}
	this.getParameters = function() 
		{
			var a = new Array(this.getLength());
			for(var j=0; j < this.keyValuePairs.length; j++) 
			{
				a[j] = this.keyValuePairs[j].split("=")[0];
			}
			return a;
		}
	this.getLength = function() 
		{ 
			return this.keyValuePairs.length; 
		}	
}

function queryString(key)
{
	var page = new PageQuery(window.location.search); 
	return unescape(page.getValue(key)); 
}


function GetSerialByReferrer()
{
	//return a serial number
			
	var serial;
	var referrer = document.referrer.toLowerCase();
	//var referrer = "http://search.msn.com/results.aspx?FORM=MSNH&srch_type=0&q=site%3Awww.casino-on-net.com";

	if(referrer.length > 0)
	{
		serial = "938057";
		if (referrer.indexOf("msn.") != -1)
		{
			serial = "938055";
		}
		else
			if (referrer.indexOf("google.") != -1)
			{
				serial = "938053";
			}
			else
				if (referrer.indexOf("yahoo.") != -1)
				{
					serial = "938054";
				}
				else
					if (referrer.indexOf("aol.") != -1)
					{
						serial = "938056";
					}
	}
	else
	{
		//no referrer
		serial = InstallSerial;	//default serial
	}	
			
	return serial;
}



/***** set cookie *******/

if (queryString("sr") != 'false')
{
	//get serial from querystring
	setCookie("serial", queryString("sr"),null,"/")	
}
else
{
	if (getCookie("serial") == null)
	{
		//get serial from referrer if any, else use default serial.
		setCookie("serial", GetSerialByReferrer(),null,"/")	
	}
}

if (queryString("flag") != 'false')
{
	//get serial from querystring
	setCookie("flag", queryString("flag"),null,"/")	
}
else
{
	if (getCookie("flag") == null)
	{
		setCookie("flag", "0000" ,null,"/")	
	}
}
/***************************/
