var ARR_ACTIVEX = ["MSXML4.DOMDocument", 
                   "MSXML3.DOMDocument",
                   "MSXML2.DOMDocument", 
                   "MSXML.DOMDocument",
                   "Microsoft.XmlDom"];
var STR_ACTIVEX = "";
var bIsIE = (window.ActiveXObject?true:false);
var bIsMoz = ((!window.activeXObject && document.implementation && document.implementation.createDocument && Document.prototype.__defineGetter__)?true:false);

if(bIsIE)
{
	var bFound = false;
	for (var i=0; i < ARR_ACTIVEX.length && !bFound; i++) {
		try {
			var objXML = new ActiveXObject(ARR_ACTIVEX[i]);
			STR_ACTIVEX = ARR_ACTIVEX[i];
			bFound = true
		}
		catch (objException) {}
	}
	if (!bFound)
		throw "MSXML not found on your computer."
}

function nmXML(){}
nmXML.createDOMDocument = function(strNamespaceURI, strRootTagName){
	var objDOM = null;
	if (bIsMoz) {
		objDOM = document.implementation.createDocument(strNamespaceURI,strRootTagName, null);
		objDOM.addEventListener("load", function() {this.handleonload();}, false);
	}
	else if (bIsIE) {
		objDOM = new ActiveXObject(STR_ACTIVEX);
		if (strRootTagName) {
			if (strNamespaceURI) {
				objDOM.loadXML("<a0:" + strRootTagName + "xmlns:a0=\"" + strNamespaceURI + "\" />");
			}
			else {
				objDOM.loadXML("<" + strRootTagName + "/>");
			}
		}
	}
	else
		throw "This script is unsupported on your browser!";
		
	return objDOM;
}

if(bIsMoz)
{
	Node.prototype.__defineGetter__("xml", function() {
		var objXMLSerializer = new XMLSerializer;
		var strXML = objXMLSerializer.serializeToString(this);
		return strXML;	
	});

	Document.prototype.loadXML = function(strXML) {
		this.changereadystate(1);
		var objDOMParser = new DOMParser();
		var objDoc = objDOMParser.parseFromString(strXML, "text/xml");
		while(this.hasChildNodes()) {
			this.removeChild(this.lastChild);
		}
		
		for(var i = 0; i < objDoc.childNodes.length; i++) {
			var objImportedNode = this.importNode(objDoc.childNodes[i], true);
			this.appendChild(objImportedNode);
		}
		this.handleonload();
	}
	
	Document.prototype.readyState = 0;
	Document.prototype.parseError = 0;
	Document.prototype.onreadystatechange = null;
	Document.prototype.__load__ = Document.prototype.load;
	Document.prototype.load = function(strURL) {
		this.parseError = 0;
		this.changereadystate(1);
		try{
			this.__load__(strURL);
		}catch(e){
			this.parseError = -9999999;
			this.changereadystate(4);
		}
	}

	Document.prototype.changereadystate = function(iReadyState) {
		this.readyState = iReadyState;
		if(this.onreadystatechange != null && typeof this.onreadystatechange == "function")
			this.onreadystatechange();
	}
	
	Document.prototype.handleonload = function() {
		if(!this.documentElement || this.documentElement.tagName == "parseerror")
			this.parseError = -9999999;
		this.changereadystate(4);
	}
	
	// returns a string result of the xsl transformation
	Document.prototype.transformNode = function(xslDoc) {
		var xslproc = new XSLTProcessor();
		var resultDoc = null;
		var resultStr = "";
		
		try{
			xslproc.importStylesheet(xslDoc);
			resultDoc = xslproc.transformToDocument(this);
			resultStr = resultDoc.xml;
		}catch(e){}
		return resultStr;
	}	
}

var g_aCalls = new Array();
var g_strLoadingText = " ... Loading ... ";

function CallObject(strAddressType, xml, frm, callback)
{
	this.addressType = strAddressType;
	this.xml = xml;
	this.form = frm;
	this.callback = callback;
}


function resend_password(frm)
{
	if(isIE())
	{
    return showModalDialog("/resend_password.html", frm, "dialogwidth: 287px; dialogheight: 250px; resizable: no; help: no;");
	}
	else
	{
	return window.open("/resend_password.html", frm, "width=287, height=250, resizable=no");
	}
}


function updateForm(strAddressType, geouid, frm, callback)
{
	strAddressType = strAddressType.toLowerCase();

	// abort previous downloads in progress
	for(var l_Idx = 0; l_Idx < g_aCalls.length; l_Idx++)
	{
		if (g_aCalls[l_Idx] && g_aCalls[l_Idx].addressType == strAddressType)
		{
			g_aCalls[l_Idx].xml.abort();
			g_aCalls[l_Idx] = null;
		}
	}

	var l_strRequest = document.location.protocol + "//" + document.location.host + "/data/destinationdata.xml?destination=" + escape(geouid) + "&type=" + escape(strAddressType);

	var l_elCountry			= frm.elements[strAddressType + "country"];
	var l_elDivision		= frm.elements[strAddressType + "division"];
	var l_elDivisionText	= frm.elements[strAddressType + "division_text"];

	var l_iCall = g_aCalls.length;
	var l_oCall = new CallObject(strAddressType, nmXML.createDOMDocument(), frm, callback);

	// copy down if appropriate	
	if (strAddressType == "deliver" && frm.elements["billcopydown"] && frm.elements["billcopydown"].checked)
	{
		var l_elBillCountry	= frm.elements["billcountry"];

		if (l_elBillCountry && l_elCountry)
		{
				// search for a corresponding bill country
				for(var l_idx = 0; l_idx < l_elBillCountry.options.length; l_idx++)
				{
					// there is a match
					if (l_elBillCountry.options[l_idx].value == l_elCountry.value)
					{
						l_elBillCountry.selectedIndex = l_idx;

						// add the division download for bill address to the remote request
						l_strRequest += "&destination=" + escape(l_elBillCountry.value) + "&type=bill";
						
						l_oCall.copydown = true;

						break;
					}
				}
			}					
	}

	g_aCalls[l_iCall] = l_oCall;

	l_oCall.xml.async = true;
	l_oCall.xml.onreadystatechange = new Function("onDestinationDownload(" + l_iCall + ");");
	l_oCall.xml.load(l_strRequest);


	if (l_elDivision)
	{
		l_elDivision.style.display = "inline";
		l_elDivision.innerHTML = "";

		var l_oOption = document.createElement("OPTION");
		l_elDivision.options.add(l_oOption);
		l_oOption.value = "";
		l_oOption.innerText = g_strLoadingText;
	}
	if (l_elDivisionText)
	{
		l_elDivisionText.style.display = "none";
	}
};
  
function onDestinationDownload(iCall)
{
	if (g_aCalls[iCall].xml.readyState == 4)
	{

		var l_strDivisionInnerHtml	= "";

		var l_elDivision		= g_aCalls[iCall].form.elements[g_aCalls[iCall].addressType + "division"];
		var l_elDivisionText	= g_aCalls[iCall].form.elements[g_aCalls[iCall].addressType + "division_text"];
	
		if (l_elDivision)
		{
			var l_uidDeliver = null;
			
			if (g_aCalls[iCall].addressType == "bill" && g_aCalls[iCall].form.elements["billcopydown"] && g_aCalls[iCall].form.elements["billcopydown"].checked)
			{
				var l_elDeliverDivision = g_aCalls[iCall].form.elements["deliverdivision"];
				
				if (l_elDeliverDivision)
				{
					l_uidDeliver = l_elDeliverDivision.value;
				}
			}
		
			var l_xslDoc = nmXML.createDOMDocument();
			l_xslDoc.loadXML("<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/TR/WD-xsl\" version=\"1.0\"><xsl:template match=\"/\"><xsl:for-each select=\"destinationdata/destinationset[@type = '" + g_aCalls[iCall].addressType + "']/place\"><option><xsl:attribute name=\"value\"><xsl:value-of select=\"@geouid\"/></xsl:attribute>" + (l_uidDeliver ? "<xsl:if test=\".[@geouid = '" + l_uidDeliver + "']\"><xsl:attribute name=\"selected\">selected</xsl:attribute></xsl:if>" : "") + "<xsl:value-of select=\"@name\"/></option></xsl:for-each></xsl:template></xsl:stylesheet>");

			l_strDivisionInnerHtml = g_aCalls[iCall].xml.transformNode(l_xslDoc);

			if (l_strDivisionInnerHtml.length > 0)
			{
				l_elDivision.options.length = 0;
				l_elDivision.outerHTML = l_elDivision.outerHTML.substr(0, l_elDivision.outerHTML.length - 8) + l_strDivisionInnerHtml + "</SELECT>";
			}
			else
			{
				l_elDivision.style.display = "none";
				
				if (l_elDivisionText)
					l_elDivisionText.style.display = "inline";
			}
		}
	
		if (g_aCalls[iCall].copydown)
		{
			var l_elBillDivision		= g_aCalls[iCall].form.elements["billdivision"];
			var l_elBillDivisionText	= g_aCalls[iCall].form.elements["billdivision_text"];
			
			if (l_elBillDivision)
			{
				var l_xslDoc = nmXML.createDOMDocument();
				l_xslDoc.loadXML("<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/TR/WD-xsl\" version=\"1.0\"><xsl:template match=\"/\"><xsl:for-each select=\"destinationdata/destinationset[@type = 'bill']/place\"><option><xsl:attribute name=\"value\"><xsl:value-of select=\"@geouid\"/></xsl:attribute><xsl:value-of select=\"@name\"/></option></xsl:for-each></xsl:template></xsl:stylesheet>");

				l_strDivisionInnerHtml = g_aCalls[iCall].xml.transformNode(l_xslDoc);
				
				if (l_strDivisionInnerHtml.length > 0)
				{	
					l_elBillDivision.options.length = 0;
					l_elBillDivision.style.display = "inline";
					l_elBillDivision.outerHTML = l_elBillDivision.outerHTML.substr(0, l_elBillDivision.outerHTML.length - 8) + l_strDivisionInnerHtml + "</SELECT>";
										
					if (l_elBillDivisionText)
						l_elBillDivisionText.style.display = "none";
				}
				else
				{
					l_elBillDivision.style.display = "none";
				
					if (l_elBillDivisionText)
						l_elBillDivisionText.style.display = "inline";				
				}
								
			}
		}

		if (g_aCalls[iCall].callback) eval(g_aCalls[iCall].callback);

		g_aCalls[iCall] = null;
	}
}
  

function autoAddress(type, idx, frm)
{

	var t = type.toLowerCase();

	if (frm.elements[t + 'copydown'])
	{
		frm.elements[t + 'copydown'].checked = false;
		copydown_update(t, frm);
		copy_details(t, frm);
	}

	if (frm.elements['addressid'])
		frm.elements['addressid'].value = l_arrAddress[type][idx].id;
	if (frm.elements[t + 'uidPlace'])
		frm.elements[t + 'uidPlace'].value = l_arrAddress[type][idx].uidPlace;
	if (frm.elements[t + 'uidDivision'])
		frm.elements[t + 'uidDivision'].value = l_arrAddress[type][idx].uidDivision;


	if (frm.elements[t + 'salutation'])
		frm.elements[t + 'salutation'].selectedIndex = l_arrAddress[type][idx].salutation;
	if (frm.elements[t + 'firstname'])
		frm.elements[t + 'firstname'].value = l_arrAddress[type][idx].firstname;
	if (frm.elements[t + 'lastname'])
		frm.elements[t + 'lastname'].value = l_arrAddress[type][idx].lastname;
	if (frm.elements[t + 'company'])
		frm.elements[t + 'company'].value = l_arrAddress[type][idx].company
	if (frm.elements[t + 'emailaddress'])
		frm.elements[t + 'emailaddress'].value = l_arrAddress[type][idx].emailaddress;
	if (frm.elements[t + 'phone'])
		frm.elements[t + 'phone'].value = l_arrAddress[type][idx].phone;
	if (frm.elements[t + 'fax'])
		frm.elements[t + 'fax'].value = l_arrAddress[type][idx].fax;
	if (frm.elements[t + 'address1'])
		frm.elements[t + 'address1'].value = l_arrAddress[type][idx].address1;
	if (frm.elements[t + 'address2'])
		frm.elements[t + 'address2'].value = l_arrAddress[type][idx].address2;
	if (frm.elements[t + 'address3'])
		frm.elements[t + 'address3'].value = l_arrAddress[type][idx].address3;
	if (frm.elements[t + 'postalcode'] != null)
		frm.elements[t + 'postalcode'].value = l_arrAddress[type][idx].postalcode;
	if (frm.elements[t + 'place_text'] != null)   
		frm.elements[t + 'place_text'].value = l_arrAddress[type][idx].place;
	if (frm.elements[t + 'division_text'] != null)
		frm.elements[t + 'division_text'].value = l_arrAddress[type][idx].division;
	if (frm.elements[t + 'country_text'])
		frm.elements[t + 'country_text'].value = l_arrAddress[type][idx].country_text;	
        if (frm.elements[t + 'uidCountry'])
		frm.elements[t + 'uidCountry'].value = l_arrAddress[type][idx].uidCountry;

	if (frm.elements[t + 'country'])
	{
		var l_elCountry = frm.elements[t + 'country'];

		if (l_elCountry.options)
		{		
			if (l_elCountry.value != l_arrAddress[type][idx].uidCountry)
			{
				for(var l_idx = 0; l_idx < l_elCountry.options.length; l_idx++)
				{
					if (l_elCountry.options[l_idx].value == l_arrAddress[type][idx].uidCountry)
					{					
						l_elCountry.selectedIndex = l_idx;
						
						updateForm(type, l_elCountry.value, frm, "autoAddressComplete('" + type + "', " + idx + ", document.forms['" + frm.name + "']);");

						return;
					}
				}
			}
		}
		else l_elCountry.value = l_arrAddress[type][idx].uidCountry;
	}

	autoAddressComplete(type, idx, frm);
};

function autoAddressComplete(type, idx, frm)
{
	var t = type.toLowerCase();

	if (frm.elements[t + 'division'])
	{
		var l_elDivision = frm.elements[t + 'division'];
		
		if (l_elDivision.options)
		{
			if (l_elDivision.value != l_arrAddress[type][idx].uidDivision)
			{
				for(var l_idx = 0; l_idx < l_elDivision.options.length; l_idx++)
				{
					if (l_elDivision.options[l_idx].value == l_arrAddress[type][idx].uidDivision)
					{
						l_elDivision.selectedIndex = l_idx;
						break;
					}
				}
			}
		}
		else l_elDivision.value = l_arrAddress[type][idx].uidDivision;
	}

	copy_details(t, frm);
}


function copy_details(type, frm)
{
	type = type.toLowerCase();

	var destType;

	switch(type)
	{
	case "contact":
		destType  = "deliver";
		break;
	case "deliver":
		destType = "bill";
		break;
	}

	if (!frm.elements[destType + 'copydown'] || !frm.elements[destType + 'copydown'].checked) return;

	if (frm.elements[destType + 'salutation'] && frm.elements[type + 'salutation'])
		frm.elements[destType + 'salutation'].selectedIndex = frm.elements[type + 'salutation'].selectedIndex;
	if (frm.elements[destType + 'firstname'] && frm.elements[type + 'firstname'])
		frm.elements[destType + 'firstname'].value = frm.elements[type + 'firstname'].value;
	if (frm.elements[destType + 'lastname'] && frm.elements[type + 'lastname'])
		frm.elements[destType + 'lastname'].value = frm.elements[type + 'lastname'].value;
	if (frm.elements[destType + 'company'] && frm.elements[type + 'company'])
		frm.elements[destType + 'company'].value = frm.elements[type + 'company'].value;
	if (frm.elements[destType + 'emailaddress'] && frm.elements[type + 'emailaddress'])
		frm.elements[destType + 'emailaddress'].value = frm.elements[type + 'emailaddress'].value;
	if (frm.elements[destType + 'fax'] && frm.elements[type + 'fax'])
		frm.elements[destType + 'fax'].value = frm.elements[type + 'fax'].value;
	if (frm.elements[destType + 'phone'] && frm.elements[type + 'phone'])
		frm.elements[destType + 'phone'].value = frm.elements[type + 'phone'].value;
	if (frm.elements[destType + 'address1'] && frm.elements[type + 'address1'])
		frm.elements[destType + 'address1'].value = frm.elements[type + 'address1'].value;
	if (frm.elements[destType + 'address2'] && frm.elements[type + 'address2'])
		frm.elements[destType + 'address2'].value = frm.elements[type + 'address2'].value;
	if (frm.elements[destType + 'address3'] && frm.elements[type + 'address3'])
		frm.elements[destType + 'address3'].value = frm.elements[type + 'address3'].value;
	if (frm.elements[destType + 'place_text'] && frm.elements[type + 'place_text'] && frm.elements[type + 'place_text'].type != "hidden")
		frm.elements[destType + 'place_text'].value = frm.elements[type + 'place_text'].value;
	if (frm.elements[destType + 'division_text'] && frm.elements[type + 'division_text'])
		frm.elements[destType + 'division_text'].value = frm.elements[type + 'division_text'].value;
	if (frm.elements[destType + 'postalcode'] && frm.elements[type + 'postalcode'])
		frm.elements[destType + 'postalcode'].value = frm.elements[type + 'postalcode'].value;
	
	
	// copy the country stuff down
	if (frm.elements[destType + 'country'] && frm.elements[type + 'country'])
	{
		var l_destCountry	= frm.elements[destType + 'country'];
		var l_srcCountry	= frm.elements[type + 'country'];
		
		if (l_destCountry.value != l_srcCountry.value)
		{
			for(var l_idx = 0; l_idx < l_destCountry.options.length; l_idx++)
			{
				if (l_destCountry.options[l_idx].value == l_srcCountry.value)
				{
					l_destCountry.selectedIndex = l_idx;
					
					// call update form to repopulate division list
					
					updateForm(destType, l_destCountry.value, frm);
					
					return;
				}
			}
		}
	}
	
	// copy the division drop down state over if possible
	if (frm.elements[destType + 'division'] && frm.elements[type + 'division'])
	{
		var l_destDivision	= frm.elements[destType + 'division'];
		var l_srcDivision	= frm.elements[type + 'division'];
	
		if (l_destDivision.value != l_srcDivision.value)
		{	
			for(var l_idx = 0; l_idx < l_destDivision.options.length; l_idx++)
			{
				if (l_destDivision.options[l_idx].value == l_srcDivision.value)
				{
					l_destDivision.selectedIndex = l_idx;
					break;
				}
			}
		}
	}
	
	
	if (destType == "deliver")
		copy_details("deliver", frm);
}

function copydown_update(type, frm)
{
	type = type.toLowerCase();


	if (!frm.elements[type + 'copydown'] || !frm.elements[type + 'copydown'].checked)
	{
		if (frm.elements[type + 'salutation'])	frm.elements[type + 'salutation'].disabled = false;
		if (frm.elements[type + 'firstname'])	frm.elements[type + 'firstname'].disabled = false;
		if (frm.elements[type + 'lastname'])	frm.elements[type + 'lastname'].disabled = false;
		if (frm.elements[type + 'company'])	frm.elements[type + 'company'].disabled = false;
		if (frm.elements[type + 'emailaddress'])frm.elements[type + 'emailaddress'].disabled = false;
		if (frm.elements[type + 'fax'])		frm.elements[type + 'fax'].disabled = false;
		if (frm.elements[type + 'phone'])	frm.elements[type + 'phone'].disabled = false;
		if (frm.elements[type + 'address1'])	frm.elements[type + 'address1'].disabled = false;
		if (frm.elements[type + 'address2'])	frm.elements[type + 'address2'].disabled = false;
		if (frm.elements[type + 'address3'])	frm.elements[type + 'address3'].disabled = false;
		if (frm.elements[type + 'place'])	frm.elements[type + 'place'].disabled = false;
		if (frm.elements[type + 'place_text'])	frm.elements[type + 'place_text'].disabled = false;
		if (frm.elements[type + 'division'])	frm.elements[type + 'division'].disabled = false;
		if (frm.elements[type + 'division_text'])	frm.elements[type + 'division_text'].disabled = false;
		if (frm.elements[type + 'country'])	frm.elements[type + 'country'].disabled = false;
		if (frm.elements[type + 'postalcode'])	frm.elements[type + 'postalcode'].disabled = false;

		var postcodelink = frm.ownerDocument.getElementById(type + "postalcodelink");
		if (postcodelink) postcodelink.disabled = false;
	}
	else
	{
		if (frm.elements[type + 'salutation'])	frm.elements[type + 'salutation'].disabled = true;
		if (frm.elements[type + 'firstname'])	frm.elements[type + 'firstname'].disabled = true;
		if (frm.elements[type + 'lastname'])	frm.elements[type + 'lastname'].disabled = true;
		if (frm.elements[type + 'company'])	frm.elements[type + 'company'].disabled = true;
		if (frm.elements[type + 'emailaddress'])frm.elements[type + 'emailaddress'].disabled = true;
		if (frm.elements[type + 'fax']) 	frm.elements[type + 'fax'].disabled = true;
		if (frm.elements[type + 'phone']) 	frm.elements[type + 'phone'].disabled = true;
		if (frm.elements[type + 'address1'] && type == "bill") 	frm.elements[type + 'address1'].disabled = true;
		if (frm.elements[type + 'address2'] && type == "bill")  frm.elements[type + 'address2'].disabled = true;
		if (frm.elements[type + 'address3'] && type == "bill") 	frm.elements[type + 'address3'].disabled = true;
		if (frm.elements[type + 'place'] && type == "bill") 	frm.elements[type + 'place'].disabled = true;
		if (frm.elements[type + 'place_text'] && type == "bill") 	frm.elements[type + 'place_text'].disabled = true;
		if (frm.elements[type + 'division'] && type == "bill") 	frm.elements[type + 'division'].disabled = true;
		if (frm.elements[type + 'division_text'] && type == "bill") frm.elements[type + 'division_text'].disabled = true;
		if (frm.elements[type + 'country'] && type == "bill") 	frm.elements[type + 'country'].disabled = true;
		if (frm.elements[type + 'postalcode'] && type == "bill") 	frm.elements[type + 'postalcode'].disabled = true; 

		var postcodelink = frm.ownerDocument.getElementById(type + "postalcodelink");
		if (postcodelink && type == "bill") postcodelink.disabled = true;

		var strDest;

		switch(type)
		{
		case "deliver":
			strDest = "contact";
			break;
		case "bill":
			strDest = "deliver";
			break;
		}

		copy_details(strDest, frm);		
	}
}


function javascriptSafe(str)
{

return str.replace(/'/g, "\\'");

}

function htmlSafe(str)
{

var 	s = str;
	s = s.replace(/"/g, "&quot;");


return s;

}


var g_popuptimer;

function show_popup(imgsrc, x, y) 
{
	if(isIE6()) // only do this for IE6.0
	{
		if (!g_popuptimer)
		{
			g_popuptimer = setTimeout("show_popup('" + javascriptSafe(imgsrc) + "', " + event.clientX + ", " + (event.srcElement.offsetHeight + event.clientY - event.offsetY + 10) + ");", 500);
			return;
		}
		else
		{
			popup.innerHTML='<img src="' + htmlSafe(imgsrc) + '" border="0" >';



			popup.style.left = Math.round( (x + document.body.scrollLeft +12 )/20)*20;

			popup.style.top = Math.round( (y + document.body.scrollTop + 10)/8 )*8;

			popup.style.visibility = "visible";

					
			if(popup.style.pixelTop + popup.offsetHeight > document.body.offsetHeight + document.body.scrollTop)
			{
			popup.scrollIntoView(false);
			}
			
		}	

	}
}



function hide_popup() 
{

if(isIE5point5_OrBetter()) // only do this for ie5.5+
	{

		if (g_popuptimer)
		{
			clearTimeout(g_popuptimer);
			g_popuptimer = null;
		}

		popup.style.visibility="hidden";
	}
}




// Script for the cart summary page

var g_currentLink = null;

function onbuttonover (bover)
{
if(isIE()) // only do this for IE

{	
	if (g_currentLink != window.event.srcElement)
	{
	
		if (window.event.srcElement.className == 'cartsummary_buttons' || window.event.srcElement.className == 'cartsummary_buttons_hover')
		{
		window.event.srcElement.className = bover? "cartsummary_buttons_hover" :"cartsummary_buttons";
		}
		
	}

	if (g_currentLink != window.event.srcElement)
	{
	
		if (window.event.srcElement.className == 'header_buttons' || window.event.srcElement.className == 'header_buttons_hover')
		{
		window.event.srcElement.className = bover? "header_buttons_hover" :"header_buttons";
		}
		
	}

}	
}


function onButtonClick()
{
if(isIE()) // only do this for IE
{
	var l_previousselectedlink = g_currentLink;
	g_currentLink = window.event.srcElement;

	if (l_previousselectedlink != null)
	{
	
		if (l_previousselectedlink.className == 'cartsummary_buttons_hover' )
		{
				l_previousselectedlink.className = "cartsummary_buttons";
		}
		
	}
		
	if (g_currentLink.className == 'cartsummary_buttons_hover' || g_currentLink.className == 'cartsummary_buttons')
	{
		g_currentLink.className = "cartsummary_buttons_hover";
	}

	if (l_previousselectedlink != null)
	{
	
		if (l_previousselectedlink.className == 'header_buttons_hover' )
		{
				l_previousselectedlink.className = "header_buttons";
		}
		
	}
		
	if (g_currentLink.className == 'header_buttons_hover' || g_currentLink.className == 'header_buttons')
	{
		g_currentLink.className = "header_buttons_hover";
	}
}	
}

var g_cartsummary_popup;
var g_cartsummary_timer;

function cartsummary_popup(divtoshow, show)
{

	if(isIE5point5_OrBetter()) // only do this for ie5.5+
	{
		// if the cartsummary popup is already up and the close timer is active then clear any outstanding close timer
		if (g_cartsummary_popup && g_cartsummary_popup.isOpen)
		{
			if (g_cartsummary_timer)
			{
				clearTimeout(g_cartsummary_timer);
				g_cartsummary_timer = null;
			}
		}
		else
		{
			// if the timer has been hidden manually
			if (g_cartsummary_popup)
			{
				// kill off the popup	
				g_cartsummary_popup = null;
				// kill off any outstanding timers
				if (g_cartsummary_timer)
					clearTimeout(g_cartsummary_timer);
				// restart the open timer
				g_cartsummary_timer = setTimeout("cartsummary_popup('" + divtoshow + "', true)", 500);			
			}
			// if the timer has expired the show argument will be true so create and show the popup
			else if (show == true)
			{
				var l_div = document.getElementById(divtoshow);
			
				g_cartsummary_popup = window.createPopup();

				var summaryHeight = l_div.offsetHeight;


				// apply the stylesheets of the parent window to the popup object (keep dimensions and styles consistent
				for(var l_StyleIdx = 0; l_StyleIdx < document.styleSheets.length; l_StyleIdx++)
				{
					g_cartsummary_popup.document.createStyleSheet(document.styleSheets.item(l_StyleIdx).href);
				}

				g_cartsummary_popup.document.body.topMargin = 0;
				g_cartsummary_popup.document.body.leftMargin = 0;
				g_cartsummary_popup.document.body.scroll = "yes";
				g_cartsummary_popup.document.body.style.overflow = "auto";
				g_cartsummary_popup.document.body.innerHTML = l_div.outerHTML;
				g_cartsummary_popup.document.body.className = 'cartsummary_popup';
				g_cartsummary_popup.document.body.firstChild.style.visibility = "visible";
				

				g_cartsummary_popup.document.body.onmouseover = cartsummary_popup;
				g_cartsummary_popup.document.body.onmouseout = cartsummary_close;

				var targetBody = window.top.frames['header'].frames['cartsummary'].document.body;
	  
				var popupWidth	= scaleFactorX() * l_div.offsetWidth;
				var popupHeight = Math.min((scaleFactorY() * l_div.offsetHeight), (scaleFactorY() * (top.frames['main'].document.body.clientHeight + top.frames['header'].document.body.clientHeight - targetBody.offsetHeight))); 
				var popupX	= (scaleFactorX() * targetBody.clientWidth) - (popupWidth);
				var popupY	= scaleFactorY() * targetBody.clientHeight;

				//davedave							

				g_cartsummary_popup.show(popupX, popupY, popupWidth, popupHeight, targetBody);
				g_cartsummary_timer = null;
			}
			else if (!g_cartsummary_timer)
			{
				g_cartsummary_timer = setTimeout("cartsummary_popup('" + divtoshow + "', true)", 500);
			}
		}
	}
}

function cartsummary_close(hide)
{

	if(isIE5point5_OrBetter) // only do this for ie5.5+
	{
		
		// if the cartsummary popup is not active, then don't worry
		if (g_cartsummary_timer && !g_cartsummary_popup)
		{
			clearTimeout(g_cartsummary_timer);
			g_cartsummary_timer = null;
		}

		if (!g_cartsummary_popup) return;

		if (hide)
		{
			g_cartsummary_popup.hide();
			g_cartsummary_popup = null;
			g_cartsummary_timer = null;
		}
		else if (!g_cartsummary_timer)
		{
			g_cartsummary_timer = setTimeout("cartsummary_close(true)", 1200);
		}
	}
}



var g_previous_popup;

function previous_popup(type,obj,container)
{

	if(isIE() && IEversion() >=5.5) // only do this for ie5.5+
	{
		g_previous_popup = window.createPopup();
		
		// apply the stylesheets of the parent window to the popup object (keep dimensions and styles consistent
		for(var l_StyleIdx = 0; l_StyleIdx < document.styleSheets.length; l_StyleIdx++)
		{
			g_previous_popup.document.createStyleSheet(document.styleSheets.item(l_StyleIdx).href);
		}

		g_previous_popup.document.body.topMargin = 0;
		g_previous_popup.document.body.leftMargin = 0;
		g_previous_popup.document.body.style.border = "1px solid gray";
		g_previous_popup.document.body.style.overflow = "auto";
		g_previous_popup.document.oncontextmenu = new Function("return false;");


		var l_srcElement;

		switch(type)
		{
		case "Contact": l_srcElement = document.getElementById("previous_contact"); break;
		case "Deliver": l_srcElement = document.getElementById("previous_deliver"); break;
		case "Bill": l_srcElement = document.getElementById("previous_bill"); break;
		}

		l_srcElement.runtimeStyle.display = "block";

		var l_height = l_srcElement.offsetHeight + 2;

		l_srcElement.runtimeStyle.display = "none";

		g_previous_popup.document.body.innerHTML = l_srcElement.innerHTML;

		if (calcClientTop(container) + container.offsetHeight > document.body.scrollTop + document.body.offsetHeight)		
			container.scrollIntoView(false);	

		g_previous_popup.show(0, obj.offsetHeight, obj.offsetWidth, Math.min(175, l_height), obj);
	}

}

function previous_close()
{

	if(isIE() && IEversion() >=5.5) // only do this for ie5.5+
	{

		if (g_previous_popup)
		{


			if (g_previous_popup)
			{
				g_previous_popup.hide();
				g_previous_popup = null;
			}
		}
	}
}

function calcClientTop(obj)
{
	if (obj == document.body)
	{
		return 0;
	}
	else
	{
		return obj.offsetTop + calcClientTop(obj.offsetParent);
	}
}

function calcClientLeft(obj)
{
	if (obj == document.body)
	{
		return 0;
	}
	else
	{
		return obj.offsetLeft + calcClientLeft(obj.offsetParent);
	}
}

/**
* Commented out as it has now been moved into the standard template library as an order query string option needs to appended and dynamically generated.
function proceed_to_checkout(items,securehost)
{
	if (items > 0)
		{

			top.location.href="/?mode=checkout&domaintransfer=secure";
		}
	if (items == 0)
	{
	alert('Your cart is empty.');
	}
}
*/

function edit_user_profile(securehost)
{
		top.location.href="/?mode=user_profile&domaintransfer=secure";
}

function return_to_nonsecure(defaulthost)
{
		top.location.href="/?domaintransfer=default";
}

function domainMatch(strDomain1, strDomain2)
{
	var strTemp;

	if (strDomain1.length > strDomain2.length)
	{
		strTemp		= strDomain1;
		strDomain1	= strDomain2;
		strDomain2	= strTemp;
	}

	return strDomain2.substr(strDomain2.length - strDomain1.length) == strDomain1;
}

var g_ListMenu_popup;
var g_ListMenu_timer;

function ListMenu_popup(menuitem, divtoshow)
{

	if(isIE() && IEversion() >=5.5) // only do this for ie5.5+
	{

		var l_div = document.getElementById(divtoshow);
			
		g_ListMenu_popup = window.createPopup();

		var summaryHeight = l_div.offsetHeight;


		// apply the stylesheets of the parent window to the popup object (keep dimensions and styles consistent
		for(var l_StyleIdx = 0; l_StyleIdx < document.styleSheets.length; l_StyleIdx++)
			g_ListMenu_popup.document.createStyleSheet(document.styleSheets.item(l_StyleIdx).href);

		g_ListMenu_popup.document.body.topMargin = 0;
		g_ListMenu_popup.document.body.leftMargin = 0;
		g_ListMenu_popup.document.body.scroll = "yes";
		g_ListMenu_popup.document.body.style.overflow = "auto";
		g_ListMenu_popup.document.body.innerHTML = l_div.innerHTML;
		g_ListMenu_popup.document.body.attachEvent("onunload", new Function("g_ListMenu_popup = null"));
		g_ListMenu_popup.document.body.attachEvent("onmouseleave", ListMenu_hide);

	 
		var popupWidth	= 170 * scaleFactorX();
		var popupHeight = 82 * scaleFactorY(); 
		var popupX	= 0;
		var popupY	= menuitem.offsetHeight * scaleFactorY();

		g_ListMenu_popup.show(popupX, popupY, popupWidth, popupHeight, menuitem);
	}
}

function ListMenu_hover()
{
	if(isIE() && IEversion() >=5.5) // only do this for ie5.5+
	{
		if (g_ListMenu_popup && g_ListMenu_popup.document && g_ListMenu_popup.document.body && event.toElement)
		{
			return g_ListMenu_popup.document.body.contains(event.toElement);
		}
		else return true;
	}
}

function ListMenu_hide()
{
	if(isIE() && IEversion() >=5.5) // only do this for ie5.5+
	{
		g_ListMenu_popup.hide();
	}
}

function loadCatalogueTreeInLeftNav(urlToNavigateTo)
{
	if(urlToNavigateTo !="")
	{
	top.frames['nav'].location.href = 'catalogue_tree.html?urlToNavigateTo='+urlToNavigateTo;
	}
	else
	{
	top.frames['nav'].location.href = 'catalogue_tree.html';
	}

}


//dave

function scaleFactorX()
  {

	if (!isIE6())
	{
		return 1;
	}
	else
	{
	    var nScaleFactor = screen.deviceXDPI / screen.logicalXDPI;
	    return nScaleFactor;
	}

  }

function scaleFactorY()
  {
	if (!isIE6())
	{
		return 1;
	}
	else
	{
		 var nScaleFactor = screen.deviceYDPI / screen.logicalYDPI;
		 return nScaleFactor;
	}
  }



function isIE6()
{
	var userAgent = navigator.userAgent;
	var MSIEIndex = userAgent.indexOf("MSIE");
	var MSIEVersion;

	if (MSIEIndex != -1)
	{
		MSIEVersion = parseFloat(userAgent.substring((MSIEIndex + 5),(MSIEIndex + 8)));
	}

	return (navigator.appName == "Microsoft Internet Explorer" && MSIEVersion == 6);
}

function isIE()
{
	var userAgent = navigator.userAgent;
	var MSIEIndex = userAgent.indexOf("MSIE");
	var MSIEVersion;

	if (MSIEIndex != -1)
	{
		MSIEVersion = parseFloat(userAgent.substring((MSIEIndex + 5),(MSIEIndex + 8)));
	}

	return (navigator.appName == "Microsoft Internet Explorer");
}

function IEversion()
{
	var userAgent = navigator.userAgent;
	var MSIEIndex = userAgent.indexOf("MSIE");
	var MSIEVersion;

	if (MSIEIndex != -1)
	{
		MSIEVersion = parseFloat(userAgent.substring((MSIEIndex + 5),(MSIEIndex + 8)));
	}

	if(navigator.appName == "Microsoft Internet Explorer")
	{
	return (MSIEVersion);
	}
	else
	{
	return;
	}
}

function isIE5point5_OrBetter()
{
	var userAgent = navigator.userAgent;
	var MSIEIndex = userAgent.indexOf("MSIE");
	var MSIEVersion = 0.0;

	if (MSIEIndex != -1)
	{
		MSIEVersion = parseFloat(userAgent.substring((MSIEIndex + 5),(MSIEIndex + 8)));
	}

	return (navigator.appName == "Microsoft Internet Explorer" && MSIEVersion >= 5.5);
}
	

function warnIfNortonActive()
{
	if(typeof(SymError) != "undefined")//symError is a function inserted by Nortons to do anti-popup extc.
	{
	alert('Warning!\r\n\r\nNetMerchant has detected that you have pop-ups disabled in your Nortons setting.\r\nSome features on this site will not work correctly. \r\nFor correct operation you need to allow popups for use on this site.');
	}
}
