if (!http){
	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();

	function addEvent( obj, type, fn ) {
		if (obj.addEventListener) {
			obj.addEventListener( type, fn, false );
			EventCache.add(obj, type, fn);
		}
		else if (obj.attachEvent) {
			obj["e"+type+fn] = fn;
			obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
			obj.attachEvent( "on"+type, obj[type+fn] );
			EventCache.add(obj, type, fn);
		}
		else {
			obj["on"+type] = obj["e"+type+fn];
		}
	}

	var EventCache = function(){
		var listEvents = [];
		return {
			listEvents : listEvents,
			add : function(node, sEventName, fHandler){
				listEvents.push(arguments);
			},
			flush : function(){
				var i, item;
				for(i = listEvents.length - 1; i >= 0; i = i - 1){
					item = listEvents[i];
					if(item[0].removeEventListener){
						item[0].removeEventListener(item[1], item[2], item[3]);
					};
					if(item[1].substring(0, 2) != "on"){
						item[1] = "on" + item[1];
					};
					if(item[0].detachEvent){
						item[0].detachEvent(item[1], item[2]);
					};
					item[0][item[1]] = null;
				};
			}
		};
	}();

	// 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); old version
			//for CR 699 store targeting groc performacne improvement
			http.open('get', '/StoreTargeting/'+action +'/'+offer+'.htm'); 			
			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
		}
	}
	addEvent(window,'load',sT.init);
}



/*
	Haircare Diagnostic Tool v. 20070411beta
*/

var username = "Isabelle";
var decisionTreeLocation = "/superstore/p/haircaretool/BACKEND/haircare_tool_xml.aspx";
var imagesLocation = "/superstore/p/haircaretool/FRONTEND/images/";

// 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.write("advert");
    }
}
function showBanner(banner) {
    document.getElementById(banner).style.height='586px';
}
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);
	}
}
function addFullSet(id1, title1, price1, id2, title2, price2, id3, title3, price3, id4, title4, price4, numberOfSet){
	for (i=1; i<=numberOfSet; i++) {
		add(id1,title1, price1);
		add(id2,title2, price2);
		add(id3,title3, price3);
		add(id4,title4, price4);
	}
}
function insertFlashBanner(){
	var sFlashlocation="/superstore/p/haircaretool/FRONTEND/haircare_tool.swf";
	var iHeight=586;
	var iWidth=565;

	var sCookie = unescape(document.cookie);    
	var sBranch="BranchNumber=";
	var aSplit = sCookie.split(sBranch);
	var branchID = aSplit[1].substr(0,4);

	var sFlash = '<div id="advert" style="width:565px; height:113px; overflow:hidden; background-color:#fff;"><object style="background-color:#fff;" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" height="'+ iHeight +'" width="'+ iWidth +'" id="banner"><param name="movie" value="'+ sFlashlocation +'" /><param name="bgcolor" value="#ffffff" /><param name="quality" value="high" /><param name="wmode" value="transparent" /><param name="flashvars" value="username=Isabelle&decisionTreeLocation='+ decisionTreeLocation +'&imagesLocation='+imagesLocation+'&branchID='+branchID+'" /><embed type="application/x-shockwave-flash" src="'+ sFlashlocation +'" id="banner" name="banner" bgcolor="#ffffff" quality="high" wmode="transparent" flashvars="username=Isabelle&amp;decisionTreeLocation='+ decisionTreeLocation +'&amp;imagesLocation='+imagesLocation+'&amp;branchID='+branchID+'" height="'+ iHeight +'" width="'+ iWidth +'" style="background-color:#fff;"></object></div>';

	var oPlaceholder = document.getElementById('placeholderHaircareDiagnosticTool');
	if (oPlaceholder){
		oPlaceholder.innerHTML=sFlash;
	}
}