
function checkCountry(sCountry) {
	  var sCookieCountry = "";
	  sCookieCountry = checkCountryCookie();
		if (sCookieCountry != "") {
				checkCountryGoTo(sCookieCountry);//if cookies exist go there
		} else {
			if (!getCookie("GeoPopup_dontShowCountrySelector"))
				displayCountrySelector(sCountry);
		}
	
}

function checkCountryCookie() {
	var sCookieCountry = getCookie("GeoPopup_goto"); 
	if (sCookieCountry != null && sCookieCountry != "") {
			return sCookieCountry;
	} else {
			return "";
	}
}

function checkCountryGoTo(sCountry) {
	if (sCountry == "AU")
		document.location.href = "http://www.canbet.com.au/";	
	else
		document.location.href = "http://www.canbet.com/";		
}

function displayCountrySelector(sCountry) {
	
		//fade out the page the emphasise the selector window
		PartFadeOut("boxin", 500)
		
		var div = document.createElement('div');
		var divContent = "";
		var sSuggestedSite = "";
		if (sCountry == 'AU')
			sSuggestedSite = "canbet.com";
		else
			sSuggestedSite = "canbet.com.au";	
		
		//create content for div
		divContent = divContent + ('<p class="GeoPopup_Close"><a href="#" id="GeoPopup_Close" onclick="closeCountrySelector();">X</a></p>');
		divContent = divContent + ('<p class="heading">' + CLIENT_ResourceString.GeoPopup_Intro + ' ' + sSuggestedSite + '?</p>');
		if (CLIENT_ResourceString.GeoPopup_Intro1 != null && CLIENT_ResourceString.GeoPopup_Intro1 != '')
			divContent = divContent + ('<p>' + CLIENT_ResourceString.GeoPopup_Intro1 + '</p>');
		if (CLIENT_ResourceString.GeoPopup_Intro2 != null && CLIENT_ResourceString.GeoPopup_Intro2 != '')
			divContent = divContent + ('<p>' + CLIENT_ResourceString.GeoPopup_Intro2 + '</p>');
		//if (CLIENT_ResourceString.GeoPopup_CurrentSite.toLowerCase().indexOf('au') > 0) //canbet.com.au
		if (sCountry == 'AU') //canbet.com.au
		{
			divContent = divContent + ('<table><tr><td class="radio"><input type="radio" name="inputCountry" id="GeoPopup_OptionROW" value="true" checked=\"checked\" /></td><td class="option">' + CLIENT_ResourceString.GeoPopup_OptionROW + '</td></tr>');
			divContent = divContent + ('<tr><td class="radio"><input type="radio" name="inputCountry"  id="GeoPopup_OptionAU" value="true" /></td><td class="option">' + CLIENT_ResourceString.GeoPopup_OptionAU + '</td></tr>');
		}
		else //canbet.com	
		{
			divContent = divContent + ('<table><tr><td class="radio"><input type="radio" name="inputCountry" id="GeoPopup_OptionAU" value="true" checked=\"checked\" /></td><td class="option">' + CLIENT_ResourceString.GeoPopup_OptionAU + '</td></tr>');
			divContent = divContent + ('<tr><td class="radio"><input type="radio" name="inputCountry"  id="GeoPopup_OptionROW" value="true" /></td><td class="option">' + CLIENT_ResourceString.GeoPopup_OptionROW + '</td></tr>');
		}
		
		divContent = divContent + ('<tr><td class="radio"><input type="checkbox" name="inputCountryAlways" id="GeoPopup_AlwaysDirect" value="true" /></td><td class="option" style="font-size:12px;">' + CLIENT_ResourceString.GeoPopup_AlwaysDirect + '</td></tr>');
		divContent = divContent + ('<tr><td colspan="2"><p><input type="button" name="GeoPopup_BtnContinue" value="' + CLIENT_ResourceString.GeoPopup_BtnContinue + '" id="countryContinue" onclick="doCountrySelect(\'' + sCountry + '\');"/></p></td></tr>');
		divContent = divContent + ('<tr><td colspan="2"><p><a href="#" id="countryCancel" onclick="cancelCountrySelector();">' + CLIENT_ResourceString.GeoPopup_Cancel + '</a></p></td></tr></table><br>');
		
		//add content to the div, give it an id and append it to the page
		div.innerHTML = (divContent);
		div.id = "GeoPopup_CountrySelector";
		document.getElementById("container").appendChild(div);
}

function doCountrySelect(sCountry) {
	
		var countryLinkAU = document.getElementById("GeoPopup_OptionAU");
		var countryLinkROW = document.getElementById("GeoPopup_OptionROW");
		var countryAlways = document.getElementById("GeoPopup_AlwaysDirect");
		
		if (sCountry != 'AU') //canbet.com
		{
			if(countryLinkAU.checked){
				
				if(countryAlways.checked) {
					setCookie("GeoPopup_goto","AU","July 4, 2080");
				}
				checkCountryGoTo('AU');
				
			}
			
			if(countryLinkROW.checked){
				if(countryAlways.checked) {
					setCookie("GeoPopup_dontShowCountrySelector",true,"July 4, 2080");
					setCookie("GeoPopup_goto","","July 4, 2080");
				}
				closeCountrySelector();
			}	
		}
		else //canbet.com.au
		{
			if(countryLinkROW.checked){
				
				if(countryAlways.checked) {
					setCookie("GeoPopup_goto","ROW","July 4, 2080");
				}
				checkCountryGoTo('ROW');
				
			}
			
			if(countryLinkAU.checked){
				if(countryAlways.checked) {
					setCookie("GeoPopup_dontShowCountrySelector",true,"July 4, 2080");
				}
				closeCountrySelector();
			}	
		}
}

function closeCountrySelector() {
	div = document.getElementById("container");
	div.removeChild(div.lastChild);
	PartFadeIn("boxin", 1000)
}

function cancelCountrySelector() {
		closeCountrySelector();
		setCookie("GeoPopup_dontShowCountrySelector",true,"July 4, 2080");
}

function checkGeoPopup() {
	
	if (CLIENT_ResourceString.GeoPopup_CurrentSite.toLowerCase().indexOf('canbet.com.au') > 0) //canbet.com.au
	{
		if (CLIENT_ResourceString.GeoPopup_UserOrigin.toUpperCase() != 'AU') //ROW client
			checkCountry('AU');
	}
	else //canbet.com
	{
		if (CLIENT_ResourceString.GeoPopup_CurrentSite.toLowerCase().indexOf('canbet.com') > 0) //canbet.com
		{	if (CLIENT_ResourceString.GeoPopup_UserOrigin.toUpperCase() == 'AU') //AU client
				checkCountry('ROW');
		}
	}	
}