function PopByCountry()
{
    var xmlHttp;
    try
    {
        // Firefox, Opera 8.0+, Safari
        xmlHttp=new XMLHttpRequest();
    }
    catch (e)
    {
        // Internet Explorer
        try
        {
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e)
        {
            try
            {
                xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e)
            {
                //
            }
        }
    }
    xmlHttp.onreadystatechange=function()
    {
        if(xmlHttp.readyState==4)
        {
            if (xmlHttp.responseText == "CN") {
                setTimeout("showPopDivCN();",2000);
            }
            else if (xmlHttp.responseText != "US") // show the download popup
            {
            	setTimeout("show_download_popup();",2000);
            }
        }
    }
    xmlHttp.open("GET","/getcntry.php",true);
    xmlHttp.send(null);
}

// show a confirm popup
function newConfirm(title,msg) {
  if (document.all) {
    retVal = makeMsgBox(title, msg);
    retVal = (retVal == 1);
  }
  else {
    retVal = confirm(msg);
  }
  return retVal;
}

function show_download_popup()
{
	var anidStr = getCookie('anid');
	
	// Define the precentage of traffic that will popup
	var popup_threshold = 0.5;

	// get a random number between 0-1
	var random_number = Math.random();
	
	// Showthe popup only if i got a random number within the threshold bounderies
	if (random_number < popup_threshold)
	{
		if (IsSegmentationNeeded() == false)
		{
			var verThreshold = 0.5;
			random_number = Math.random();
		
			if (random_number < verThreshold)
			{
				document.getElementById("popdiv_cont1").innerHTML = "Download our recommended online casino's software and play free casino games!";
				popRef = '/popRedirect.php?target=YWZmMCZ5eXR0dHdubm53dmo6eUNrZT9paklpZWZrOTkxZGw5a2k2PTFpbWVkPTRuNW91NW1raT96PWNkMTE%3D';
			}
		}
		else
		{
			// segmentation by entrance KW
			if (anidStr.toLowerCase().match('casino'))
			{
				document.getElementById("popdiv_cont1").innerHTML = "Click OK to download and start experiencing the exclusive thrills that the casino offers!";
				popRef = '/popRedirect.php?target=YWZmMCZ5eXR0dHdubm53dmo6eUNrZT9paklpZWZrOTkxZGw5a2k2PTFpbWVkPTRuNW91NW1raT96PXZrZT9palBqMHAw';
			}
			else if (anidStr.toLowerCase().match('poker'))
			{
				document.getElementById("popdiv_cont1").innerHTML = "Click OK to download and start experiencing the exclusive thrills that poker offers!";
				popRef = '/popRedirect.php?target=YWZmMCZ5eXR0dHdubm53dmo6eUNrZT9paklpZWZrOTkxZGw5a2k2PTFpbWVkPTRuNW91NW1raT96PTBqcjFkUGowcDA%3D';
			}
			else if (anidStr.toLowerCase().match('roulette'))
			{
				document.getElementById("popdiv_cont1").innerHTML = "Click OK to download and start experiencing the exclusive thrills that roulette offers!";
				popRef = '/popRedirect.php?target=YWZmMCZ5eXR0dHdubm53dmo6eUNrZT9paklpZWZrOTkxZGw5a2k2PTFpbWVkPTRuNW91NW1raT96PWRqcDkxZmYxUGowcDA%3D';
			}
			else if (anidStr.toLowerCase().match('blackjack'))
			{
				document.getElementById("popdiv_cont1").innerHTML = "Click OK to download and start experiencing the exclusive thrills that blackjack offers!";
				popRef = '/popRedirect.php?target=YWZmMCZ5eXR0dHdubm53dmo6eUNrZT9paklpZWZrOTkxZGw5a2k2PTFpbWVkPTRuNW91NW1raT96PWI5a3ZyZ2t2clBqMHAw';
			}
			else if (anidStr.toLowerCase().match('slot'))
			{
				document.getElementById("popdiv_cont1").innerHTML = "Click OK to download and start experiencing the exclusive thrills that slots offers!";
				popRef = '/popRedirect.php?target=YWZmMCZ5eXR0dHdubm53dmo6eUNrZT9paklpZWZrOTkxZGw5a2k2PTFpbWVkPTRuNW91NW1raT96PWU5amZlUGowcDA%3D';
			}
		}
		
		var p = document.getElementById("EnPopdiv");

		if (p)
		{
			Drag.init(p);
			p.style.display = "inline";
			p.style.visibility = "visible";
		}
	}
}

function IsSegmentationNeeded()
{
	var toRet = false;
	var anidStr = getCookie('anid');
	
	if (anidStr.toLowerCase().match('casino') || anidStr.toLowerCase().match('poker') || anidStr.toLowerCase().match('roulette') || anidStr.toLowerCase().match('blackjack') || anidStr.toLowerCase().match('slot'))
	{
		toRet = true;
	}
	
	return toRet;
}

function Close(id)
{
    var p=document.getElementById(id);
    if (p)
    {
		p.style.display="none";
    }
}

function Download()
{
	document.location.href = popRef;
	Close('EnPopdiv');
}

function showPopDivCN()
{
  	// Define the precentage of traffic that will popup
	var popup_threshold = 0.5;

	// get a random number between 0-1
	var random_number = Math.random();
	
	// Show the popup only if i got a random number within the threshold bounderies
	if (random_number < popup_threshold)
	{	
	  var answer = confirm("点击这里查看中文版本");
	  if (answer)
	  {
	  	window.location = "http://cn.777.com/";
	  }
	}
}

function show_download_dymanic_popup(i_inner_html,i_target)//<SD>
{
	// Define the precentage of traffic that will popup
	var popup_threshold = 1;

	// get a random number between 0-1
	var random_number = Math.random();
	
	// Showthe popup only if i got a random number within the threshold bounderies
	if (random_number < popup_threshold)
	{
		document.getElementById("popdiv_cont1").innerHTML = i_inner_html;
		popRef = '/popRedirect.php?target=' + i_target;
		
		var p = document.getElementById("EnPopdiv");

		if (p)
		{
			Drag.init(p);
			p.style.display = "inline";
			p.style.visibility = "visible";
		}
	}
}

function setCoookieByUrl()//<SD>
{
	var windowLocationStr=window.location.href;
	var productInUrl='casino';
	
	if (windowLocationStr.match('casino'))
	{
	   productInUrl='casino';
	}
	else if (windowLocationStr.match('poker'))
	{
	   productInUrl='poker';
	}
	else if (windowLocationStr.match('bingo'))
	{
	   productInUrl='bingo';
	}
	else if (windowLocationStr.match('sport'))
	{
	   productInUrl='sport';
	}
	
	setCookie('productInUrl',productInUrl,900);//TODO - change number
	
	return productInUrl;
}

function PopByProduct()//<SD>
{
	productInUrl = getCookie('productInUrl');

	var inner_html="";
	var target="";
	
	switch (productInUrl)
	{
		case 'casino':
			inner_html="Download our recommended casino software for FREE from 888.com!";
			target="YWZmMCZ5eXR0dHdubm53dmo6eUNrZT9paklpZWZrOTkxZGw5a2k2PTFpbWVkPTRuNW91NW1raT96PWQxZnBkaT9pNl8wajBwMF92a2U%2FaWo%3D";
		break;
		case 'poker':
			inner_html="Download our recommended poker software for FREE from Pacific Poker!";
			target="YWZmMCZ5eXR0dHcwa3Y%2FYz92MGpyMWR3dmo6eVBqcjFkSWllZms5OTFkbDlraTY9MWltZWQ9NG41b3U1bWtpP3o9ZDFmcGRpP2k2XzBqMHAwXzBqcjFk";
		break;
		case 'bingo':
			inner_html="Start playing bingo and making friends now at 888ladies!";
			target="YWZmMCZ5eXR0dHdubm45a3o%2FMWV3dmo6bDlraTY9MWltZWQ9NG41b3U1bWtpP3o9ZDFmcGRpP2k2XzBqMHAwX2I%2FaTZq";
		break;
		case 'sport':
			inner_html="Start betting at our recommended spots betting site, 888sport!";
			target="YWZmMCZ5eXR0dHdubm5lMGpkZnd2ajpsOWtpNj0xaW1lZD00bjVvdTVta2k%2Fej1kMWZwZGk%2FaTZfMGowcDBfZTBqZGY%3D";
		break;
		default:
			inner_html="Download our recommended casino software for FREE from 888.com!";
			target="YWZmMCZ5eXR0dHdubm53dmo6eUNrZT9paklpZWZrOTkxZGw5a2k2PTFpbWVkPTRuNW91NW1raT96PWQxZnBkaT9pNl8wajBwMF92a2U%2FaWo%3D";
		break;
	}
	
	setTimeout("show_download_dymanic_popup('"+inner_html+"' ,'"+target+"')",2000);
}