var QS = new Object;

var baseDomain = "home.disney.es";  // 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 = ["canada", "anon", "spain"]; // list of acceptable country designations.

var LIGHTSITE = "http://disney.es/lite/index"; // Where to go for a light-weight version of the site.
var iPHONESITE = "http://disney.es/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.disney.go.com/guestservices/international");
			OKToSetRedirect = false;
		}
		*/
		document.location.replace("http://home.disney.es/guestservices/international");
		OKToSetRedirect = false;
		// cload = true;
	}

	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;
}
