DocumentRoot = (typeof(DocumentRoot)=="undefined" || DocumentRoot == "/") ? "" : DocumentRoot; //Base for paths

/**
 * To attach to window.onload
 */
init = function () {
	
	//StoreChooser (); -- enable when live
	
	var MenuItems = [
		{
			"Label" : "Store Chooser", 
			"SubNav" : [
				{"LinkHTML" : "<a href=javascript:SetStore('us')><img src='" + DocumentRoot + "/images/global/store_chooser/north_america_sm.gif' />North American Store</a>"},
				{"LinkHTML" : "<a href=javascript:SetStore('eu')><img src='" + DocumentRoot + "/images/global/store_chooser/europe_sm.gif' />European Store</a>"}
			]
		}
		,
		{
			"Label" : "Language Chooser", 
			"SubNav" : [
				{"LinkHTML" : "<a href='" + DocumentRoot + "/default.aspx' onclick=\"return SetLang('en')\"><img src='" + DocumentRoot + "/images/global/store_chooser/british_sm.gif' />English</a>"},
				{"LinkHTML" : "<a href='" + DocumentRoot + "/default_fr.aspx' onclick=\"return SetLang('fr')\"><img src='" + DocumentRoot + "/images/global/store_chooser/french_sm.gif' />Fran&ccedil;ais</a>"},
				{"LinkHTML" : "<a href='" + DocumentRoot + "/default_it.aspx' onclick=\"return SetLang('it')\"><img src='" + DocumentRoot + "/images/global/store_chooser/italian_sm.gif' />Italiano</a>"}
			]
		}
	];
	Rvlt.BuildMenu ('StoreChooser', MenuItems, false);
	StoreChooser ();
}

/*----------------------------------
Store chooser overlay
-----------------------------------*/
var OverlayHTML = "\
<h1>Please Choose your store</h1>\
<div class='Left'>\
	<p><a href=javascript:SetStore('us')><img src='" + DocumentRoot + "/images/global/store_chooser/north_america_lg.gif'></a></p>\
	<p><strong><a href=javascript:SetStore('us')>North American store</a></strong><br />\
	For users with 110v Electricity<br />\
	<span class='Small'>(USA, Canada, Japan, Columbia, Mexico and Puerto Rico)</span>\
	</p>\
</div>\
<div class='Right'>\
	<p><a href=javascript:SetStore('eu')><img src='" + DocumentRoot + "/images/global/store_chooser/europe_lg.gif'></a></p>\
	<p><strong><a href=javascript:SetStore('eu')>European store</a></strong><br />\
		For users with 220v Electricity <br />\
		<span class='Small'>\
		(everyone else)<br />\
	</p>\
</div>\
<div class='Clear'>\
";

/*----------------------------------
Ultimate oral care
Avoid the dreaded 'click to activate' by setting the flash in JS
-----------------------------------*/
function UltimateOralCare (){
document.write ('\
<OBJECT id="science_of_pleasure" codeBase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"\
width="499" height="499" align="middle" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" VIEWASTEXT>\
<PARAM NAME="_cx" VALUE="12991">\
<PARAM NAME="_cy" VALUE="8334">\
<PARAM NAME="FlashVars" VALUE="">\
<PARAM NAME="Movie" VALUE="' + DocumentRoot + '/images/ultimate_oral_care/ultimate_oral_care_' + CurLang + '.swf">\
<PARAM NAME="Src" VALUE="' + DocumentRoot + '/images/ultimate_oral_care/ultimate_oral_care_' + CurLang + '.swf">\
<PARAM NAME="WMode" VALUE="opaque">\
<PARAM NAME="Play" VALUE="-1">\
<PARAM NAME="Loop" VALUE="-1">\
<PARAM NAME="Quality" VALUE="High">\
<PARAM NAME="SAlign" VALUE="">\
<PARAM NAME="Menu" VALUE="-1">\
<PARAM NAME="Base" VALUE=".">\
<PARAM NAME="AllowScriptAccess" VALUE="sameDomain">\
<PARAM NAME="Scale" VALUE="ShowAll">\
<PARAM NAME="DeviceFont" VALUE="0">\
<PARAM NAME="EmbedMovie" VALUE="0">\
<PARAM NAME="BGColor" VALUE="FFFFFF">\
<PARAM NAME="SWRemote" VALUE="">\
<PARAM NAME="MovieData" VALUE="">\
<PARAM NAME="SeamlessTabbing" VALUE="1">\
<PARAM NAME="Profile" VALUE="0">\
<PARAM NAME="ProfileAddress" VALUE="">\
<PARAM NAME="ProfilePort" VALUE="0">\
<embed src="' + DocumentRoot + '/images/ultimate_oral_care/ultimate_oral_care_' + CurLang + '.swf" quality="high" bgcolor="#ffffff" \
	base="." width="499" height="499" name="Ultimate Oral Care" align="middle" allowScriptAccess="sameDomain"\
	type="application/x-shockwave-flash" wmode="opaque" pluginspage="http://www.macromedia.com/go/getflashplayer" />\
</OBJECT>\
');
}

/*----------------------------------
Store chooser
-----------------------------------*/

var Stores = [
	{store: "eu", url: "http://eu.broxo.com"}, 
	{store: "us", url: "http://www.broxo.com"}
];

var ThisStore = 'eu';

function StoreChooser (){
	if (ShowStoreChooserOverlay == true) { //ShowStoreChooserOverlay is set by the server
		DisplayOverlay ();	
	}
}

function Redirect (theStore){
	for (var i=0;i< Stores.length; i++) {
		if (Stores[i].store == theStore){
			location.href= Stores[i].url + "?st=" + theStore;
		}
	}	
}

function GetStoreQueryVal (){
	var query = window.location.search;
	if(query.length > 1) {
		queryArray = query.substring(1, query.length).split("&"); //Removes the ? and splits the querystring
		for(var i=0; i < queryArray.length; i++) {
			if (queryArray[i].split("=")[0] == "st") return queryArray[i].split("=")[1]; //if key = st then return value
		}
	}
	return null;	
}

function SetStore (theStore){
	SetStoreCookie(theStore);
	if (ThisStore != theStore) {
		Redirect (theStore);
	}
	else {
		HideOverlay();
	}
}

function GetStoreCookie (){
	var CookieArray = document.cookie.split(';');
	for(var i=0;i < CookieArray.length;i++) {
		var theCookie = CookieArray[i];
		while (theCookie.charAt(0)==' ') theCookie = theCookie.substring(1,theCookie.length);
		if (theCookie.indexOf('st') == 0) return theCookie.split("=")[1];
	}
	return null;
}

function SetStoreCookie(theStore) {
	Rvlt.Utils.SetCookie ('st', theStore);
}

function SetLang(theLang) {
	Rvlt.Utils.SetCookie ('brxLang', theLang);
	if (theLang == CurLang) {
		return false;
	}
	return true;
}

function DisplayOverlay (){
	document.getElementById("StoreOverlayBg").style.display = "block";
	document.getElementById("StoreOverlay").innerHTML = OverlayHTML;
	document.getElementById("StoreOverlay").style.display = "block";
	PositionLayer ()
	document.documentElement.style.overflow = "hidden";
	window.onresize = PositionLayer;
}

function PositionLayer (){
	theOverlay = document.getElementById("StoreOverlay");
	theOverlay.style.left = (document.body.clientWidth / 2) - (theOverlay.clientWidth / 2) + 'px';
}

function HideOverlay (){
	document.getElementById("StoreOverlay").style.display = "none";
	document.getElementById("StoreOverlayBg").style.display = "none";
	document.documentElement.style.overflow = "auto";
	window.onresize = "";
}


