String.prototype.trim=new Function("return this.replace(/^\\s+|\\s+$/g,'')");
String.prototype.nocr=new Function("return this.replace(/(\\r\\n|[\\r\\n])/g,'')");
var agt=navigator.userAgent.toLowerCase();
var ie  = (agt.indexOf("msie") != -1);

var currNav=0;
var currSubNav=0;
var sNavFile=new Array("home","about-us","customer-services");
var aiNavWidth=new Array(54,76,131)
var aiNav=new Array();
var aiNavo=new Array();
for (var i=0 ; i<sNavFile.length ; i++) {
		aiNav[i]=new Image(aiNavWidth[i],26); aiNav[i].src="img/nav/"+sNavFile[i]+".gif";
		aiNavo[i]=new Image(aiNavWidth[i],28); aiNavo[i].src="img/nav/"+sNavFile[i]+"_o.gif";	
	
}
var currNavOpt="";

function showSubNav(sID){
	subNav=getElement('subnav'+sID);
	mainNav=getElement('nav'+sID);
	if (currNavOpt!="")hideSubNav(currNavOpt);
	if (subNav && mainNav){		
		var mainL=0;
		var mainT=0;	
		who=mainNav;
		while(who){
			mainL+= who.offsetLeft;
			mainT+= who.offsetTop;
			who= who.offsetParent;
		}
		mainT=mainT+17;
		subNav.style.left=mainL+"px";
		subNav.style.top=mainT+"px";
		subNav.style.display="block";
		currNavOpt=sID;
	}
}
function hideSubNav(sID){
	subNav=getElement('subnav'+sID);
	if (subNav) subNav.style.display="none";
	currNavOpt="";
}

function btnOv(sID,sImg) {
	if (sImg==null)
		setImg("i"+sID,"",eval("img"+sID+"o.src"));
	else
		setImg(sID,"",eval("img"+sImg+"o.src"));
}
function btnOut(sID,sImg) {
	if (sImg==null)
		setImg("i"+sID,"",eval("img"+sID+".src"));
	else
		setImg(sID,"",eval("img"+sImg+".src"));
}

function mOv(i) {
	setImg("iNav",i,aiNavo[i].src);
}
function mOut(i) {
	setImg("iNav",i,aiNav[i].src);
}
function atbOv(obj) { obj.src=imgAddBasketo.src; }
function atbOut(obj) { obj.src=imgAddBasket.src; }
function goOv(obj) { obj.src=imgGoo.src; }
function goOut(obj) { obj.src=imgGo.src; }
function setImg(id,i,src) {
	if (src!=null) {
		var img=getImage(id+i);
		if (img) img.src=src;
	}
}
function getImage(id) {
	if (document.images && document.images[id])
		return document.images[id];
	else
		return null;
}
function getElement(sName) {
	return document.getElementById(sName);
}

function popWindow(w,h,sUrl) {
	var wclwin=window.open(sUrl,"wclwin","toolbar=no,location=no,directories=no,margin=0,status=no,menubar=no,scrollbars=yes,resizable=no,width="+w+",height="+h);
	wclwin.focus();
}

function isInteger(sName) {
	var sVal=getElement(sName).value;
	var re=/(^\d+$)/;
	return (re.test(sVal));
}

String.prototype.ltrim=new Function("return this.replace(/^\\s+/,'')");
String.prototype.rtrim=new Function("return this.replace(/\\s+$/,'')");
String.prototype.trim=new Function("return this.replace(/^\\s+|\\s+$/g,'')");

function popImg(sID,sUrl,iNum) {
	var w=window.open(sUrl+"?part="+sID+"&img="+iNum,"asw","width=580,height=630,scrollbars=yes");
	w.focus();
}
function doClose(){
	window.close();
}
function TogglePrices(){
	
	obj=getElement("toggleprices");
	
	if (obj ){
	
		obj.value="yes";
		
		document.toggle.submit();
	}
}
function TogglePricesRRP(){
	
	obj=getElement("togglepricesrrp");
	
	if (obj ){
	
		obj.value="yes";
		
		document.togglerrp.submit();
	}
}
function extractXML(sXML,sTag) {
	var iFrom=sXML.indexOf("<"+sTag+">");
	var iTo=sXML.indexOf("</"+sTag+">",iFrom);
	return (iFrom!=-1 && iTo!=-1 ? sXML.substring(iFrom+(sTag.length+2),iTo) : "");
}

function Fetcher() {
	var me=this;
	this.fnCB=null;
	this.xmlHttp=null;
	try { this.xmlHttp=new XMLHttpRequest(); }
	catch (trymicrosoft) {
		try { this.xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }
		catch (othermicrosoft) {
			try { this.xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }
			catch (failed) {
				this.xmlHttp=null;
			}  
		}
	}
	this.now=function(sURL) {
		var sRet="";
		if (this.xmlHttp) {
			this.xmlHttp.open("GET",cacheBust(sURL),false);
			this.xmlHttp.send(null);
  			if (this.xmlHttp.readyState==4)
				sRet=this.xmlHttp.responseText.nocr().trim();
		}
		return sRet;
	}	
	this.whenever=function(sURL,fnCB) {
		if (this.xmlHttp) {
			this.fnCB=fnCB;
			this.xmlHttp.open("GET",cacheBust(sURL),true);
			this.xmlHttp.onreadystatechange=this.loader;
			this.xmlHttp.send(null);
		}
	}
	this.loader=function() {
		if (me.xmlHttp) {
			if (me.xmlHttp.readyState==4 && me.xmlHttp.status==200) {
				me.fnCB(me.xmlHttp.responseText.nocr().trim());
			}
		}
	}
	this.abortme=function() {
		if (me.xmlHttp) {
			if (me.xmlHttp.readyState!=4 && me.xmlHttp.readyState!=0) {
				me.abort();
			}
		}
	}
	
}
function cacheBust(sURL) {
	return sURL+(sURL.indexOf('?')==-1 ? '?' : '&')+'cbzz='+(new Date()).getTime();
}

function showCat(sID){
	if ( sID!=currNav){
		obj=getElement("catdiv"+sID);		
		if (obj) obj.style.display="inline";
		obj=getElement("catttl"+sID);		
		if (obj) obj.style.display="inline";
		obj=getElement("catttllnk"+sID);		
		if (obj) obj.style.display="none";
		if (currNav!=""){
			obj=getElement("catdiv"+currNav);
			if (obj) obj.style.display="none";
			obj=getElement("catttl"+currNav);		
			if (obj) obj.style.display="none";
			obj=getElement("catttllnk"+currNav);		
			if (obj) obj.style.display="inline";		
		}
		currNav=sID;
		currSubNav=0;
	}
}
function showSubCat(sID){
	if ( sID!=currSubNav){
		obj=getElement("subcatdiv"+sID);				
		if (obj)obj.style.display="inline";
		obj=getElement("subcatttl"+sID);		
		if (obj) obj.style.display="inline";
		obj=getElement("subcatttllnk"+sID);		
		if (obj) obj.style.display="none";
		if (currSubNav!=0){
			obj=getElement("subcatdiv"+currSubNav);
			if (obj) obj.style.display="none";
			obj=getElement("subcatttl"+currSubNav);		
			if (obj) obj.style.display="none";
			obj=getElement("subcatttllnk"+currSubNav);		
			if (obj) obj.style.display="inline";	
		}
		currSubNav=sID;
		
	}
}
var fetchBasket=new Fetcher();
function clickclear(thisfield, defaulttext) {
	if (thisfield.value == defaulttext) {
		thisfield.value = "";
	}
}

function clickrecall(thisfield, defaulttext) {
	if (thisfield.value == "") {
		thisfield.value = defaulttext;
	}
}
function cacheBust(sURL) {
	return sURL+(sURL.indexOf('?')==-1 ? '?' : '&')+'cbzz='+(new Date()).getTime();
}
function makeElink(user,host,domain,ltext) {
	
	var atsign = "&#64;";
	var addr = user + atsign + host + domain;
	if (ltext!="")
		document.write("<" + "a" + " " + "href=" + "mail" + "to:" + addr + ">" + ltext + "<\/a>");
	else 
		document.write("<" + "a" + " " + "href=" + "mail" + "to:" + addr + ">" + addr + "<\/a>");
}


