// Ensure the load page status is set for non-IE browsers...
attachEventHandler(window, "load", new Function("document.pageInitialised = true;"));
// General utilities

function superStorePage() {
	this.pageType;
}

function qsItem(name, value) {
	this.name = name;
	this.value = value;
}

qs.prototype.item = qs_item;
qs.prototype.toString = qs_toString;

function qs_toString() {
	var sQS = "?";

	for(var i = 0; i < this.items.length; i++) {
		sQS += this.items[i].name + "=" + escape(this.items[i].value) + (i < (this.items.length - 1) ? "&" : "");
	}
	
	return sQS;
}


function qs() {
	this.items = new Array();
}

function qs_item(name) {
	var bFound = false;

	for(var i = this.items.length - 1; i >= 0; i--) {
		if(this.items[i].name.toUpperCase() == name.toUpperCase()) {
			return this.items[i];
		}
	}
	var newItem = new qsItem(name);
	this.items[this.items.length] = newItem;

	return newItem;
}

// Break up a querystring...
//		url	(optional)	Url containing the querystring. Defaults to the document url.

var oQS;
function queryString(sUrl) {
	if(!oQS) {
		oQS = new qs();
		if(!sUrl) {
			sUrl = document.URL;
		}
		var sQS = sUrl.substring(sUrl.indexOf("?") + 1);
		var items = sQS.split("&");
		var item, name, value;
		
		for(var i = 0; i < items.length; i++) {
			item = items[i].split("=");
			if(item[0]) {
				name = item[0];
			} else {
				name = "";
			}
			if(item[1]) {
				value = unescape(item[1]);
			} else {
				value = "";
			}
			oQS.items[i] = new qsItem(name, value);
		}
	}
	
	return oQS;	
}

function openWindow(url, title, width, height, scrollbar, focus, returnWin) {
	var iLeft = (screen.width - width) / 2;
	var iTop = (screen.height - height) / 2;
	
	if(typeof(returnWin)=="undefined") {
		returnWin=true;
	}

	if(typeof(focus)=="undefined") {
		focus=true;
	}
	if(!scrollbar || scrollbar == "no" || scrollbar == "No" || scrollbar == "NO") {
		scrollbar = "no";
	} else {
		scrollbar = "yes";
	}

	var oWin = window.open(url, title, "toolbar=no,menubar=no,hotkeys=no,location=no,scrollbars=" + scrollbar + ",width=" + width + ",height=" + height + ",top=" + iTop + ",left=" + iLeft);
	if(oWin && (focus)) {
		oWin.focus();
	}
	if(returnWin) {
		return oWin;
	}
}

function openPromoWindow(url, title, width, height, scrollbar, focus) {
	var iLeft = (screen.width - width) / 2;
	var iTop = (screen.height - height) / 2;
	
	if(typeof(focus)=="undefined") {
		focus=true;
	}
	if(!scrollbar) {
		scrollbar = "no";
	} else {
		scrollbar = "yes";
	}

	var oWin = window.open(url, title, "toolbar=no,menubar=no,hotkeys=no,location=no,scrollbars=" + scrollbar + ",width=" + width + ",height=" + height + ",top=" + iTop + ",left=" + iLeft);
	if(oWin && (focus)) {
		oWin.focus();
	}
}


function openPopup(windowTitle, title, bodyContent, buttons, height, action, target) {
	document.popupBodyContent = bodyContent;
	if(!height) {
		height = 200;
	}
	if(action && !target) {
		target = "mainContentRight";
	}
	
	var sUrl = "/superstore/content/popup.html?windowTitle=" + escape(windowTitle) + "&title=" + escape(title) + "&buttons=" + escape(buttons);
	if(action) {
		sUrl += ("&action=" + escape(action) + "&target=" + escape(target));
	}
	var o = openWindow(sUrl, "applicationPopup", 400, height);
}

// String object extensions...
String.prototype.trim = function() {
	return this.replace(/^\s*/,"").replace(/\s*$/,"");
}

String.prototype.capitaliseWords = function() {
	var astrAllWords = this.split(" ");
	
	for(var i = 0; i < astrAllWords.length; i++) {
		astrAllWords[i] = astrAllWords[i].toLowerCase();
		astrAllWords[i]=  astrAllWords[i].charAt(0).toUpperCase() + astrAllWords[i].substring(1);
	}
	
	return astrAllWords.join(" ");
}

String.prototype.capitaliseFirstWord = function() {
	return this.charAt(0).toUpperCase() + this.substring(1).toLowerCase();
}

// These two are not complete, but works fine for now
String.prototype.URLEncode = function() {
	var s = this.replace(/</g, "&lt;");
	s = s.replace(/>/g, "&gt;");
	return s;
}

String.prototype.URLDecode = function() {
	var s = this.replace(/&lt;/g, "<");
	s = s.replace(/&gt;/g, ">");
	return s;
}

// 'Full' URLEncode/URLDecode...
String.prototype.URLEncode2 = function() {
	var SAFECHARS = "0123456789" +
		"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +
		"abcdefghijklmnopqrstuvwxyz" +
		"-_.!~*'()";
	var HEX = "0123456789ABCDEF";

	function gethex(decimal) {
		return "%" + HEX.charAt(decimal >> 4) + HEX.charAt(decimal & 0xF);
	}
  	
	var encoded = "";
	for (var i = 0; i < this.length; i++ ) {
		var ch = this.charAt(i);
		if(ch == " ") {
			encoded += "+";								// x-www-urlencoded, rather than %20
		} else if(SAFECHARS.indexOf(ch) != -1) {
			encoded += ch;
		} else {
			var charCode = ch.charCodeAt(0);

			if(charCode < 128) {
				encoded = encoded + gethex(charCode);
			} else if(charCode > 127 && charCode < 2048) {
				encoded = encoded + gethex((charCode >> 6) | 0xC0);
				encoded = encoded + gethex((charCode & 0x3F) | 0x80);
			} else if(charCode > 2047 && charCode < 65536) {
				encoded = encoded + gethex((charCode >> 12) | 0xE0);
				encoded = encoded + gethex(((charCode >> 6) & 0x3F) | 0x80);
				encoded = encoded + gethex((charCode & 0x3F) | 0x80);
			} else if(charCode > 65535) {
				encoded = encoded + gethex((charCode >> 18) | 0xF0);
				encoded = encoded + gethex(((charCode >> 12) & 0x3F) | 0x80);
				encoded = encoded + gethex(((charCode >> 6) & 0x3F) | 0x80);
				encoded = encoded + gethex((charCode & 0x3F) | 0x80);
			}
		}
	}
	
	return encoded;
}

String.prototype.URLDecode2 = function() {
	var HEX = "0123456789ABCDEFabcdef"; 
	var plaintext = "";
	var i = 0;

  var decoded = "";
  var notallowed = "";
  var illegalencoding = "";

	function getdec(hexencoded) {
		if(hexencoded.length == 3 && hexencoded.charAt(0) == "%" && HEX.indexOf(hexencoded.charAt(1)) != -1 && HEX.indexOf(hexencoded.charAt(2)) != -1) {
			return parseInt(hexencoded.substr(1,2),16);
		}
		return 256;
	}
	
	var unreserved = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_.~";
	var reserved = "!*'();:@&=+$,/?%#[]";
	var allowed = unreserved + reserved;
	
	while(i < this.length) {
		var ch = this.charAt(i);
		if(ch == "+") {
			decoded += " ";
			i++;
		} else if(ch == "%") {
			if(getdec(this.substr(i, 3)) < 255) {
				byte1 = getdec(this.substr(i, 3));
				byte2 = getdec(this.substr(i + 3, 3));
				byte3 = getdec(this.substr(i + 6, 3));
				byte4 = getdec(this.substr(i + 9, 3));
		
				if(byte1 < 128) {
					decoded += String.fromCharCode(byte1);
					i += 3;
				}
		
				if(byte1 > 127 && byte1 < 192) {
					decoded += this.substr(i, 3);
					illegalencoding += this.substr(i, 3) + " ";
					i += 3;
				}
		
				if(byte1 > 191 && byte1 < 224) {
					if(byte2 > 127 && byte2 < 192) {
						decoded += String.fromCharCode(((byte1 & 0x1F) << 6) | (byte2 & 0x3F));
					} else {
						decoded += this.substr(i, 6);
						illegalencoding += this.substr(i, 6) + " ";
					}
					i += 6;
				}
		
				if(byte1 > 223 && byte1 < 240) {
					if(byte2 > 127 && byte2 < 192) {
						if(byte3 > 127 && byte3 < 192) {
							decoded += String.fromCharCode(((byte1 & 0xF) << 12) | ((byte2 & 0x3F) << 6) | (byte3 & 0x3F));
						} else {
							decoded += this.substr(i, 9);
							illegalencoding += this.substr(i, 9) + " ";
						}
					} else {
						decoded += this.substr(i, 9);
						illegalencoding += this.substr(i, 9) + " ";
					}
					i += 9;
				}
		
				if(byte1 > 239) {
					if(byte2 > 127 && byte2 < 192) {
						if(byte3 > 127 && byte3 < 192) {
							if(byte4 > 127 && byte4 < 192) {
								decoded += String.fromCharCode(((byte1 & 0x7) << 18) | ((byte2 & 0x3F) << 12) | ((byte3 & 0x3F) << 6) | (byte4 & 0x3F));
							} else {
								decoded += this.substr(i, 12);
								illegalencoding += this.substr(i, 12) + " ";
							}
						} else {
							decoded += this.substr(i, 12);
							illegalencoding += this.substr(i, 12) + " ";
						}
					} else {
						decoded += this.substr(i, 12);
						illegalencoding += this.substr(i, 12) + " ";
					}
					i += 12;
				}
			} else {
				decoded += this.substr(i, 3);
				illegalencoding += this.substr(i, 3) + " ";
				i += 3;
			}
		} else {
			if (allowed.indexOf(ch) == -1) {
				notallowed += ch + " ";
			}
			decoded += ch;
			i++;
		}
	}
	
	return decoded;
}

// This method does a standard escape and also escapes forward slashes. We may want to extend this further?
function escapeAll(str) {
	str = escape(str);
	str = str.replace(/\//g, "%2F%C2"); 
	return str;
}

// Array object extensions for browsers which do not support some of the Array functions...
var o = new Array();
if(!o.unshift) {
	Array.prototype.unshift = function() {
		if(arguments.length > 0) {
			for(var i = this.length - 1; i >= 0; i--) {
				this[i + arguments.length] = this[i];
			}
			for(var i = 0; i < arguments.length; i++) {
				this[i] = arguments[i];
			}
		}
		return this.length;
	}
}

if(!o.pop) {
	Array.prototype.pop = function() {
		var s;
		if(this.length > 0) {
			s = this[this.length - 1];
			this.length = this.length - 1;
		}
		return s;
	}
}

// General functions
var oImages;
function addPreloadImage(url) {
	if(!oImages) {
		oImages = new Array();
	}
	
	oImages[oImages.length] = new Image();
	oImages[oImages.length - 1].src = url;
}

function attachEventHandler(o, e, f) {
	if(o) {
		if(o.addEventListener) {
			o.addEventListener(e, f, false);
		} else if(o.attachEvent) {
			o.attachEvent("on" + e, f);
		}
	}
}

// -- COOKIES ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

// This section has been moved into a common javascript file: /js/cookies.js

// -- END COOKIES ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

function openHelpWindow(url) {
	var width=(width)?width:screen.width; 
	var height=(height)?height:screen.height; 
	var screenX = (screen.width - 100); 
	var screenY = (screen.height - 100); 
	var features= "width=" + screenX + "px,height=" + screenY +"px,scrollbars=no,status=no,top=20,left=50"; 
	return window.open(url, "Help", features);
}

function formatNumber(n, decimalPlaces, formatThousands) {
	var ret;
	if(n.toFixed) {
		ret = n.toFixed(decimalPlaces);
	} else {
		if(decimalPlaces == 0) {
			ret = Math.round(n);
		} else if(decimalPlaces) {
			var i = Math.pow(10, decimalPlaces);
			ret = Math.round(n * i) / i;
			
			var s = new String(ret);
			var iIndex = s.indexOf(".");
			if(iIndex == -1) {
				iIndex = s.length;
				s += ".0";
			}
			var sDec = s.substr(iIndex + 1);
			for(var i = sDec.length; sDec.length < decimalPlaces; i++) {
				sDec += "0";
			}
			ret = s.substr(0, iIndex + 1) + sDec;
		}
	}
	
	if(formatThousands) {
		ret = new String(ret);
		var dp = ret.indexOf(".");
		if(dp != -1) {
			var iN = ret.substr(0, dp);
			var sRet = "", len, pos;
			for(var i = iN.length - 3; i > -3; i-=3) {
				if(i < 0) {
					len = 3 + i;
					pos = 0;
				} else {
					len = 3;
					pos = i;
				}
				sRet = ((pos > 0 ? "," : "") + iN.substr(pos, len)) + sRet;
			}
			ret = sRet + ret.substr(dp);
		}
	}
	
	return ret;
}


//Function used by links external from topnav to highlight correct tab
function navSwitch(tabNum) 
			{		
				var o = document.appFrames.topNav().document.getElementById("primaryNav");
				
				if(o) 
				{
					var oLi = o.getElementsByTagName("li");
					for (var i = 0; i < oLi.length; i++) 
					{
					oLi[i].className = oLi[i].className.replace(new RegExp("\\s*current\\b"), "");
					}
										
					oLi[tabNum].className = "current";
				}
			}
			

/*
	Haircare Diagnostic Tool v. 20070411beta
*/

var username = "";
var decisionTreeLocation = "http://pgtesco.dev4.fullsix.co.uk/haircare_tool_xml.aspx";
var imagesLocation = "http://pgtesco.dev4.fullsix.co.uk/haircare_release/FRONTEND/images/";

if(location.host != "pgtesco.dev4.fullsix.co.uk" && location.host != "localhost") {
	var sCookie = unescape(document.cookie);    
	var sBranch="BranchNumber=";
	var aSplit = sCookie.split(sBranch);
	var branchID = aSplit[1].substr(0,4);
} else {
	var branchID = 2329;
}

/**
 * SWFObject v1.4.4: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
 *
 * SWFObject is (c) 2006 Geoff Stearns and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 * **SWFObject is the SWF embed script formerly known as FlashObject. The name was changed for
 *   legal reasons.
 */
if(typeof deconcept=="undefined"){var deconcept=new Object();}
if(typeof deconcept.util=="undefined"){deconcept.util=new Object();}
if(typeof deconcept.SWFObjectUtil=="undefined"){deconcept.SWFObjectUtil=new Object();}
deconcept.SWFObject=function(_1,id,w,h,_5,c,_7,_8,_9,_a,_b){if(!document.getElementById){return;}
this.DETECT_KEY=_b?_b:"detectflash";
this.skipDetect=deconcept.util.getRequestParameter(this.DETECT_KEY);
this.params=new Object();
this.variables=new Object();
this.attributes=new Array();
if(_1){this.setAttribute("swf",_1);}
if(id){this.setAttribute("id",id);}
if(w){this.setAttribute("width",w);}
if(h){this.setAttribute("height",h);}
if(_5){this.setAttribute("version",new deconcept.PlayerVersion(_5.toString().split(".")));}
this.installedVer=deconcept.SWFObjectUtil.getPlayerVersion();
if(c){this.addParam("bgcolor",c);}
var q=_8?_8:"high";
this.addParam("quality",q);
this.setAttribute("useExpressInstall",_7);
this.setAttribute("doExpressInstall",false);
var _d=(_9)?_9:window.location;
this.setAttribute("xiRedirectUrl",_d);
this.setAttribute("redirectUrl","");
if(_a){this.setAttribute("redirectUrl",_a);}};
deconcept.SWFObject.prototype={setAttribute:function(_e,_f){
this.attributes[_e]=_f;
},getAttribute:function(_10){
return this.attributes[_10];
},addParam:function(_11,_12){
this.params[_11]=_12;
},getParams:function(){
return this.params;
},addVariable:function(_13,_14){
this.variables[_13]=_14;
},getVariable:function(_15){
return this.variables[_15];
},getVariables:function(){
return this.variables;
},getVariablePairs:function(){
var _16=new Array();
var key;
var _18=this.getVariables();
for(key in _18){_16.push(key+"="+_18[key]);}
return _16;},getSWFHTML:function(){var _19="";
if(navigator.plugins&&navigator.mimeTypes&&navigator.mimeTypes.length){
if(this.getAttribute("doExpressInstall")){
this.addVariable("MMplayerType","PlugIn");}
_19="<embed type=\"application/x-shockwave-flash\" src=\""+this.getAttribute("swf")+"\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\"";
_19+=" id=\""+this.getAttribute("id")+"\" name=\""+this.getAttribute("id")+"\" ";
var _1a=this.getParams();
for(var key in _1a){_19+=[key]+"=\""+_1a[key]+"\" ";}
var _1c=this.getVariablePairs().join("&");
if(_1c.length>0){_19+="flashvars=\""+_1c+"\"";}_19+="/>";
}else{if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","ActiveX");}
_19="<object id=\""+this.getAttribute("id")+"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\">";
_19+="<param name=\"movie\" value=\""+this.getAttribute("swf")+"\" />";
var _1d=this.getParams();
for(var key in _1d){_19+="<param name=\""+key+"\" value=\""+_1d[key]+"\" />";}
var _1f=this.getVariablePairs().join("&");
if(_1f.length>0){_19+="<param name=\"flashvars\" value=\""+_1f+"\" />";}_19+="</object>";}
return _19;
},write:function(_20){
if(this.getAttribute("useExpressInstall")){
var _21=new deconcept.PlayerVersion([6,0,65]);
if(this.installedVer.versionIsValid(_21)&&!this.installedVer.versionIsValid(this.getAttribute("version"))){
this.setAttribute("doExpressInstall",true);
this.addVariable("MMredirectURL",escape(this.getAttribute("xiRedirectUrl")));
document.title=document.title.slice(0,47)+" - Flash Player Installation";
this.addVariable("MMdoctitle",document.title);}}
if(this.skipDetect||this.getAttribute("doExpressInstall")||this.installedVer.versionIsValid(this.getAttribute("version"))){
var n=(typeof _20=="string")?document.getElementById(_20):_20;
n.innerHTML=this.getSWFHTML();return true;
}else{if(this.getAttribute("redirectUrl")!=""){document.location.replace(this.getAttribute("redirectUrl"));}}
return false;}};
deconcept.SWFObjectUtil.getPlayerVersion=function(){
var _23=new deconcept.PlayerVersion([0,0,0]);
if(navigator.plugins&&navigator.mimeTypes.length){
var x=navigator.plugins["Shockwave Flash"];
if(x&&x.description){_23=new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/,"").replace(/(\s+r|\s+b[0-9]+)/,".").split("."));}
}else{try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");}
catch(e){try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
_23=new deconcept.PlayerVersion([6,0,21]);axo.AllowScriptAccess="always";}
catch(e){if(_23.major==6){return _23;}}try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");}
catch(e){}}if(axo!=null){_23=new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));}}
return _23;};
deconcept.PlayerVersion=function(_27){
this.major=_27[0]!=null?parseInt(_27[0]):0;
this.minor=_27[1]!=null?parseInt(_27[1]):0;
this.rev=_27[2]!=null?parseInt(_27[2]):0;
};
deconcept.PlayerVersion.prototype.versionIsValid=function(fv){
if(this.major<fv.major){return false;}
if(this.major>fv.major){return true;}
if(this.minor<fv.minor){return false;}
if(this.minor>fv.minor){return true;}
if(this.rev<fv.rev){
return false;
}return true;};
deconcept.util={getRequestParameter:function(_29){
var q=document.location.search||document.location.hash;
if(q){var _2b=q.substring(1).split("&");
for(var i=0;i<_2b.length;i++){
if(_2b[i].substring(0,_2b[i].indexOf("="))==_29){
return _2b[i].substring((_2b[i].indexOf("=")+1));}}}
return "";}};
deconcept.SWFObjectUtil.cleanupSWFs=function(){if(window.opera||!document.all){return;}
var _2d=document.getElementsByTagName("OBJECT");
for(var i=0;i<_2d.length;i++){_2d[i].style.display="none";for(var x in _2d[i]){
if(typeof _2d[i][x]=="function"){_2d[i][x]=function(){};}}}};
deconcept.SWFObjectUtil.prepUnload=function(){__flash_unloadHandler=function(){};
__flash_savedUnloadHandler=function(){};
if(typeof window.onunload=="function"){
var _30=window.onunload;
window.onunload=function(){
deconcept.SWFObjectUtil.cleanupSWFs();_30();};
}else{window.onunload=deconcept.SWFObjectUtil.cleanupSWFs;}};
if(typeof window.onbeforeunload=="function"){
var oldBeforeUnload=window.onbeforeunload;
window.onbeforeunload=function(){
deconcept.SWFObjectUtil.prepUnload();
oldBeforeUnload();};
}else{window.onbeforeunload=deconcept.SWFObjectUtil.prepUnload;}
if(Array.prototype.push==null){
Array.prototype.push=function(_31){
this[this.length]=_31;
return this.length;};}
var getQueryParamValue=deconcept.util.getRequestParameter;
var FlashObject=deconcept.SWFObject;
var SWFObject=deconcept.SWFObject;

// This is our code...
function alertSize() {
    var myWidth = 0;
    var myHeight = 0;
    if (typeof(window.innerWidth) == 'number') {
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }
    return (myWidth > 800 && myHeight > 600);
}

function showFlash(banner,banWidth,banHeight) {
    if (alertSize()) {
        var so = new SWFObject(banner + ".swf", "banner", banWidth, banHeight, "6", "#ffffff");
        so.addParam("wmode", "transparent");
		so.addVariable("username", username);
		so.addVariable("decisionTreeLocation", decisionTreeLocation);
		so.addVariable("imagesLocation", imagesLocation);
		so.addVariable("branchID",branchID);	
		so.addVariable("branchID",branchID);	
        so.write("advert");
    }
}
function showBanner(banner) {
    document.getElementById(banner).style.height='586px';
}
function closeWindow() {
	window.opener=self; 
	window.close();
}


function popuponclick()
{
 tool_window = window.open("/superstore/p/haircaretool/FRONTEND/haircare_tool.html", "toolwindow","status=1,width=600,height=650");

} 

function hideBanner(banner) {
    document.getElementById(banner).style.height='113px';
}
function showWindow(strURL,strTitle,strWidth,strHeight) {
    var windowOpts = 'resizeable=yes,width=' + strWidth + ',height=' + strHeight;
    window.open(strURL,strTitle,windowOpts);
}
function goToProd(product,strWidth,strHeight) {
    if (product) {
        showWindow(product,'productWindow',strWidth,strHeight)
    }
}
function addMultiple(id, title, price, numberOfItems){
	for (i=1; i<=numberOfItems; i++) {
		add(id,title, price);
	}
}
//No longer used - DBrooks FullSix 17.10.07
function addFullSet(id1, title1, price1, id2, title2, price2, id3, title3, price3, id4, title4, price4, numberOfSet){
	alert(title+" "+id+" "+" "+price+" "+numberOfItems);
	
	for (i=1; i<=numberOfSet; i++) {
		add(id1,title1, price1);
		add(id2,title2, price2);
		add(id3,title3, price3);
		add(id4,title4, price4);
	}
}


// ================================================================================  Store targeting

	function createRequestObject() {
		var ro;
		var browser = navigator.appName;
		if(browser == "Microsoft Internet Explorer"){
			ro = new ActiveXObject("Microsoft.XMLHTTP");
		}else{
			ro = new XMLHttpRequest();
		}
		return ro;
	}
	var http = createRequestObject();


	// Removes leading whitespaces
	function LTrim( value ) {	
		var re = /\s*((\S+\s*)*)/;
		return value.replace(re, "$1");	
	}

	// Removes ending whitespaces
	function RTrim( value ) {	
		var re = /((\s*\S+)*)\s*/;
		return value.replace(re, "$1");	
	}

	// Removes leading and ending whitespaces
	function trim( value ) {	
		return LTrim(RTrim(value));	
	}


	function sndReq(action,offer) {
		// alert('4. sndReq\n action:' + action + '\n offer:' + offer);
		try{
			http.open('get', '/superstore/p/storeTargeting/ax.asp?action='+action+'&offer='+offer);
			http.onreadystatechange = handleResponse;
			http.send(null);		
		}catch (error){
		//	alert('4.  EXIT');
		}
	}

	function handleResponse() {
		//Set timer???
		try{
			// alert('handleResponse: "'+http.readyState+'"');

			if(http.readyState == 4){				
				if (http.responseText){
					var response = http.responseText;
					var update = new Array();
					if(response.indexOf('|' != -1)) {
						update = response.split('|');
					//	alert('5. handle\n id:' + trim(update[0]) +  '\n\n href:' + trim(update[1]) + '\n title:'+trim(update[2])+'\n value:'+trim(update[3])+'\n class:'+trim(update[4])+'\n src:'+trim(update[5])+'\n alt:'+trim(update[6])+'\n innerHTML:'+trim(update[7]));
						sT.makeStoreTargetChange(trim(update[0]),trim(update[1]),trim(update[2]),trim(update[3]),trim(update[4]),trim(update[5]),trim(update[6]),trim(update[7])); // id, href, title, value, src, alt, innerHTML
					}else{
						sT.setStoreTargeter();
					//	alert('response:' + response);						
					}
				}else{
					sT.setStoreTargeter(); // important - even if this response didn't return a matching offer, the next one might???
				}
			}
		}catch (error){
			//alert('BAD AJAX');
		}
	}

	var sT = {		
		init:function(){
			//Search for high level ID to see if storetargeting is required.
			var hID = document.getElementById('sT');
			if (hID){			
				sT.setStoreTargeter();
			}
			var oPlaceholderHaircareDiagnosticTool = document.getElementById('placeholderHaircareDiagnosticTool');
			if (oPlaceholderHaircareDiagnosticTool){
				/*insertFlashBanner();*/
			}
		},
		setStoreTargeter:function (){	
			var oAll = document.getElementsByTagName('*');
			if (oAll){
				for (var i=0; i<oAll.length; i++){
					if ((oAll[i].className) && (oAll[i].id)){
						var sObjectClass = oAll[i].className;
						if (sObjectClass.indexOf('sSpec') != -1){
							//node that store targeting has been found on
							oAll[i].className = oAll[i].className.replace('sSpec','');
							var sObjectID = oAll[i].id;
							sT.getStoreTargeter(sObjectID);
						//	alert('111' + sObjectID);
							break;			// we can break here break this function is called again once a successfull pass has been made.
						}
					}
				}
			}
		},
		getStoreTargeter:function (sObjectID){
			// this will need to be retreived from the cookie. existing method may be used.
			var sCookie = unescape(document.cookie);	
			var sBranch="BranchNumber=";
			var aSplit = sCookie.split(sBranch);
			var branchID = aSplit[1].substr(0,4);
			
			// alert('3. getStoreTargeter \n branchID:' + branchID + '\n sObjectID:' + sObjectID);
			sndReq(branchID,sObjectID);
		},
		makeStoreTargetChange:function(sOfferID, sHref, sTitle, sValue, sClass, sSrc, sAlt, sInnerHTML){
			// alert('6. makeStoreTargetChange \n magic \n sOfferID:' + sOfferID + '\n sHref:' + sHref + '\n sTitle:' + sTitle + '\n sValue:' + sValue + '\n sClass:' + sClass + '\n sSrc:' + sSrc + '\n sAlt:' + sAlt + '\n sInnerHTML:' + sInnerHTML);
			var oTarget = document.getElementById(sOfferID);
			if (oTarget){
				if (sHref!='x'){oTarget.setAttribute('href', sHref);}
				if (sTitle!='x'){oTarget.setAttribute('title', sTitle);}
				if (sValue!='x'){oTarget.setAttribute('value', sValue);}
				if (sClass!='x'){oTarget.className=' '; oTarget.className=sClass;}
				if (sSrc){
					var oImg = oTarget.getElementsByTagName('img');
					if (oImg){
						if (sSrc!='x'){oImg[0].setAttribute('src', sSrc);}
						if (sAlt!='x'){oImg[0].setAttribute('alt', sAlt);}
					}
				}
				if (sInnerHTML!='x'){oTarget.innerHTML = sInnerHTML;}
			}
			sT.setStoreTargeter();	//important - check to see if there are any more sSpecs on the page
		}
	}
	attachEventHandler(window,'load',sT.init);