if (typeof baseDomain == "undefined") {
	var baseDomain = ".go.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".
}
if (typeof COUNTRYLIST == "undefined") {
	var COUNTRYLIST = ["united states", "canada", "puerto rico", "guam", "us virgin islands", "american samoa", "northern mariana islands"]; // list of acceptable country designations.
}

if (typeof INTERNATIONALSITE == "undefined") {
	INTERNATIONALSITE = "http://home.disney.go.com/guestservices/international";
}

if (typeof LIGHTSITE == "undefined") {
	var LIGHTSITE = "http://home.disney.go.com/lite/index"; // Where to go for a light-weight version of the site.
}

if (typeof USERAGENTREDIRECTS == "undefined") {
	var USERAGENTREDIRECTS = ["iphone,ipod,nexus one,pre||http://home.disney.go.com/iphone/index",
		"iPad||http://home.disney.go.com/mobile/?device=ipad",
		"Nitendo Wii||http://m.disney.go.com/t/index",
		"PlayStation Portable||http://disney.go.com/connectedMedia/pconsole/?e=177"];
} 





if (typeof REDIRECTCOUNTRY == "undefined") {
	var REDIRECTCOUNTRY = [
		"australia||http://www.disney.com.au/", 
		"japan||http://www.disney.co.jp/", 
		"united kingdom||http://www.disney.co.uk/",
		"new zealand||http://www.disney.com.au/",
		"italy,holy see (vatican city state),malta||http://www.disney.it/",
		"spain||http://www.disney.es/",
		"singapore||http://home.disney.com.sg",
		"malaysia||http://home.disney.com.my",
		"argentina,antigua and barbuda,bolivia,chile,colombia,costa rica,cuba,dominica,dominican republic,ecuador,el salvador,guatemala,haiti,honduras,mexico,nicaragua,panama,paraguay,peru,uruguay,venezuela,Guayana,Guyana,Antigua y Barbuda,Barbados,Bermudas,Belice,United States Virgin Islands,British Virgin Islands,Reino Unido,Dominica,Republica Dominicana,Guayana Francesa,Guadalupe,Guatemala,guyana,Guayana,Honduras,Jamaica,Martinica,Montserrat,Aruba,Nicaragua,Panama,Saint Kitts y Nevis,Anguilla,Surinam,Trinidad and Tobago,Turks and Caicos Islands,Bahamas,Granada,Santa Lucia,San Vicente and Granadinas||http://www.disneylatino.com/"
		];
}




var QS = new Object;
var theUserAgent = navigator.userAgent;




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;

// Check for iPhone and other userAgents that need to be redirected
for (var i = 0; i < USERAGENTREDIRECTS.length; i++) {
	var userAgentHalves = USERAGENTREDIRECTS[i].split("||");
	var userAgents = userAgentHalves[0].split(",");
	for (var j = 0; j < userAgents.length; j++) {
		if (theUserAgent.toLowerCase().indexOf(userAgents[j].toLowerCase()) > -1) {
			document.location.replace(userAgentHalves[1]);
			break;
		}
	}
}
// Check for dialup
if (connection=="dialup") {
	loaded = false;
	narrowBand = true;
}
// Check for allowed user country
try {
	for (var i = 0; i < COUNTRYLIST.length; i++) { // Make sure we're in an allowed country
		if (country == COUNTRYLIST[i]) {
			cload = true;
			break;
		}
	}
	var intercheck=params(document.cookie,"INTER",null);
	if(intercheck=="1") {
		cload=false;
	} else 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) {

		//Check for specific foreign countries.
		for (var i = 0; i < REDIRECTCOUNTRY.length; i++) {
			var countryparts = REDIRECTCOUNTRY[i].split("||");
			var countrynames = countryparts[0].split(",");
			for (var j = 0; j < countrynames.length; j++) {
				if (country.toLowerCase() == countrynames[j].toLowerCase()) {
					document.location.replace(countryparts[1]);
					OKToSetRedirect = false;
				}
			}
		}
		if (OKToSetRedirect) {
			document.location.replace(INTERNATIONALSITE);
			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){
		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;
}

