/*
Functions to do all the domain redirects needed by the 5react website
*/

//=======================================================================================================
// Helper functions

function addQueryParameter(__text, __param) {
	return __text.indexOf("?") > -1 ? "&" + __param : "?" + __param;
}


//=======================================================================================================
// Actual behaviors

//-------------------------------------------------------------------------------------------------------
// Do all domain redirects if needed

var loc = window.location.href;

//-------------------------------------------------------------------------------------------------------
// Redirect when coming from 5react.com

if (loc.substr(0,7) == "http://" && loc.substr(7,3) != "www" && loc.substr(7,6) != "origin" && loc.substr(7,3) != "fak" && loc.substr(7,3) != "the") window.location = "http://www." + loc.substr(7);

//-------------------------------------------------------------------------------------------------------
// Country-based redirects

var redirectDomains = [];
redirectDomains.push(["5react.ca", "ca"]);
redirectDomains.push(["www.5react.ca", "ca"]);
redirectDomains.push(["5react.com.au", "au"]);
redirectDomains.push(["www.5react.com.au", "au"]);
redirectDomains.push(["5react.co.nz", "nz"]);
redirectDomains.push(["www.5react.co.nz", "nz"]);

for (var i = 0; i < redirectDomains.length; i++) {
	if (loc.substr(7, redirectDomains[i][0].length) == redirectDomains[i][0]) {
		window.location = "http://www.5react.com" + addQueryParameter(loc.substr(7 + redirectDomains[i][0].length), "c=" + redirectDomains[i][1]);
	}
}

