var QS = new Object;

var baseDomain = ".disneylatino.com";  // This is used to set the correct domain for the international redirect over-ride cookie. In the US, this is set to ".go.com". 


var COUNTRYLIST = [ "anguilla", "antigua and barbuda", "antigua y barbuda", "netherlands antilles", "argentina", "aruba", "bahamas", "barbados", "bermuda", "bolivia", "belize", "cayman islands", "chile", "colombia", "costa rica", "dominica", "dominican republic", "ecuador", "el salvador", "grenada", "french guiana", "guadaloupe", "guatemala", "guyana", "haiti", "honduras", "jamaica", "martinique", "montserrat", "mexico", "nicaragua", "panama", "puerto rico", "paraquay", "saint kitts and nevis", "saint lucia", "saint vincent and the grenadines", "trinidad and tobago", "turks and caicos islands", "uruguay", "venezuela", "us virgin islands", "british virgin islands", "united states", "spain", "canada", "italy", "japan", "india", "united kingdom", "germany", "france", "portugal" ];

var LIGHTSITE = "http://disneylatino.com/lite/index"; // Where to go for a light-weight version of the site.
var iPHONESITE = "http://disneylatino.com/iphone/index"; // Where to go for the iPhone version of the site.


parseQueryString(QS);
if ((QS['intoverride'] != undefined) && (QS['intoverride'] == 'true')) {
	setcookie('intoverride','true',0,0,baseDomain,false);
}

var OKToSetRedirect = true;
var loaded = true;
var cload = false;
var narrowBand = false;
var iphone = false;
if ((navigator.userAgent.indexOf('iPhone') != -1) || (navigator.userAgent.indexOf('iPod') != -1)) {
	iphone = true;
}
if (connection=="dialup"||connection=="wireless"||iphone == true) {
	loaded = false;
	narrowBand = true;
}






try {
	for (var i = 0; i < COUNTRYLIST.length; i++) {
		if (country.indexOf(COUNTRYLIST[i]) > -1) {
			cload = true;
		}
	}
	var intercheck=params(document.cookie,"INTER",null);
	if(intercheck=="1") {
		cload=false;
	}
	if(intercheck=="0") {
		cload=true;
	}

	var internetoverrideCookie = "";
	internetoverrideCookie = params(document.cookie,"intoverride",null);
	//As an extra check, manually set internetoverrideCookie to "true" if we have the query string.
	 if ((QS['intoverride'] != undefined) && (QS['intoverride'] == 'true')) {
		internetoverrideCookie = "true";
	 }
	if (internetoverrideCookie != "true" && cload == false) {
	
		if (country == "australia") {
			document.location.replace("http://www.disney.com.au/");
			OKToSetRedirect = false;
		} else if (country == "japan") {
			document.location.replace("http://www.disney.co.jp/");
			OKToSetRedirect = false;
		} else if (country == "united kingdom") {
			document.location.replace("http://www.disney.co.uk/");
			OKToSetRedirect = false;
		} else if (country == "new zealand") {
			document.location.replace("http://www.disney.com.au/");
			OKToSetRedirect = false;
		} else if ((country == "italy") || (country == "holy see (vatican city state)") || (country == "malta")) {
			document.location.replace("http://www.disney.it/");
			OKToSetRedirect = false;
		} else {
			document.location.replace("http://home.disneylatino.com/guestservices/international");
			OKToSetRedirect = false;
		}
	}

	var modecheck=params(document.cookie,"MODE",null);
	if (modecheck=="1") {
		loaded=false;
	}
	if (modecheck=="0") {
		loaded=true;
	}
}catch(e){
	loaded=true;
}


if(!loaded){
	if(iphone){
		document.location.replace(iPHONESITE);
	} else {
		 // document.location.replace(LIGHTSITE);	
	}
}





function params(wut,qp,dflt){
	dflt=(dflt==null)?'':dflt;
	try {
		r=unescape(wut.match(new RegExp(qp+"=+([^&;]*)"))[1]);
	} catch(qp){
		r=dflt;
	}
	return r;
}
