var oldsubcat="";
var dontclose=false;
function openMenu(idnam,button)
{
	if (oldsubcat) oldsubcat.style.display="none";
	dontclose=true;
	grabobj(idnam).style.position="absolute";
	grabobj(idnam).style.left="160px";
	grabobj(idnam).style.top=button;
	grabobj(idnam).style.display="";
	grabobj(idnam).onmouseover=dontCloseSub;
	grabobj(idnam).onmouseout=doCloseSub;
}
function closeMenu(idnam)
{
	oldsubcat=grabobj(idnam);
	dontclose=false;
	window.setTimeout(closeMenuDo,500);
}
function closeMenuDo()
{
	if (dontclose==false) { if (oldsubcat) { oldsubcat.style.display="none"; }}
	oldsubcat="";
}
function dontCloseSub()
{
	oldsubcat=this;
	dontclose=true;
}
function doCloseSub()
{
	oldsubcat=this;
	dontclose=false;
	window.setTimeout(closeMenuDo,500);
}
function telOver(o){
 o.style.color='#FFFFCC';
}
function telOut(o){
 o.style.color='#FFFFFF';
}
function searchfix() {
  var item = document.forms["form1"].elements[0].value
  if(item.length==0){
	alert("Please enter a search term or product code");
	return false;
  }
  else return true;
}

function doSearch() {
  if(document.form1.CSPCHD.value) {
	parent.frames['mainframe'].location.href = "#(baseurl)#results.csp?CSPCHD="+document.form1.CSPCHD.value;
  }
  else {
	parent.frames['mainframe'].location.href = "#(baseurl)#results.csp?search="+document.form1.search.value+"&cat="+document.form1.cat.value;
  }
}

function addFaves(){
  if(window.external) {
	window.external.AddFavorite('http://shopping.yours.co.uk', 'Yours Shopping')
  }
  else {
    alert('To bookmark this page, please go to "Bookmarks" on your browser toolbar and click on "Add to bookmarks" or "Bookmark this page"');
  }
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function MM_callJS(jsStr) { //v2.0
  return eval(jsStr)
}

if (document.getElementById) {
  DOMtype = "std";
}
else if (document.all) {
  DOMtype = "ie4";
}
else if (document.layers) {
  DOMtype = "ns4";
}

function grabobj(objname) {
  var ret = null;
	switch (DOMtype) {
	  case "std": { ret = document.getElementById(objname); }
	  break;
	  case "ie4": { ret = document.all[objname]; }
	  break;
	  case "ns4": { ret = document.layers[objname]; }
	  break;
	}
  return ret;
}
function copypage()
{
grabobj("pagedata2").innerHTML=grabobj("pagedata").innerHTML;
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') {
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (val<min || max<val) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}


function swapImg(elemId,src) {
	if (src=='') src=defaultSwapImg;
	grabobj(elemId).src=src;
}



/*	Added for Stock PopUps	*/
function outofstock(stno,type) {
// This gateway dosn't work with trailing slash
//	var ajax = new ajaxObject('/stockmessage/',evalAjax);
	var ajax = new ajaxObject('/stockmessage.htm',evalAjax);
	ajax.update('STNO='+stno+'&type='+type,'GET');
}
function evalAjax (t,s) {
	displayBox('stock',unescape(t));
//	alert(t);
}
function ajaxObject(url, callbackFunction) {
	var that=this;
	this.updating = false;
	this.abort = function() {
		if (that.updating) {
			that.updating=false;
			that.AJAX.abort();
			that.AJAX=null;
		}
	}
	this.update = function(passData,postMethod) {
	if (that.updating) { return false; }
		that.AJAX = null;
		if (window.XMLHttpRequest) {
			that.AJAX=new XMLHttpRequest();
		} else {
			try {
				that.AJAX=new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e) {
				that.AJAX=new IFrameXMLHttpRequest();
			}
		}
		if (that.AJAX==null) {                             
			return false;                               
		} else {
		that.AJAX.onreadystatechange = function() {  
			if (that.AJAX.readyState==4) {             
				that.updating=false;
				that.callback(that.AJAX.responseText,that.AJAX.status,that.AJAX.responseXML);        
				that.AJAX=null;                                         
			}                                                      
		}                                                        
		that.updating = new Date();        

		if ($('ajaxcall')) $('ajaxcall').innerHTML=new Date();
			if (/post/i.test(postMethod)) {
				var uri=urlCall+'?'+that.updating.getTime();
				that.AJAX.open("POST", uri, true);
				that.AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
				that.AJAX.send(passData);
			} else {
				var uri=urlCall+'?'+passData+'&stamp='+(that.updating.getTime()); 
				that.AJAX.open("GET", uri, true);                             
				that.AJAX.send(null);                                         
			}              
			return true;                                             
		}
	}
	var urlCall = url;
	this.callback = callbackFunction || function () { };
}
/*
coded by Kae - http://verens.com/
use this code as you wish, but retain this notice
*/

var kXHR_instances=0;
var kXHR_objs=[];


IFrameXMLHttpRequest=function()
{
	var i=0;
	var url='';
	var responseText='';
	var iframe='';
	this.onreadystatechange=function(){
		return false;
	}
	this.open=function(method,url)
	{
		//TODO: POST methods
		this.i=++kXHR_instances; // id number of this request
		this.url=url;
		iFrame	=	document.createElement('iframe');
		iFrame.id	=	"kXHR_iframe_"+this.i;
		iFrame.style.display = 'none';
		iFrame.style.width = '1px';
		iFrame.style.height = '1px';
		document.body.appendChild(iFrame);
	}
	this.send=function(postdata)
	{
		//TODO: use the postdata
		document.getElementById('kXHR_iframe_'+this.i).src=this.url;
		kXHR_objs[this.i]=this;
		setTimeout('XMLHttpRequest_checkState('+this.i+',2)',2);
	}
	return true;
}
XMLHttpRequest_checkState=function(inst,delay)
{
	var el=document.getElementById('kXHR_iframe_'+inst);
	if(el.readyState=='complete')
	{
		var responseText=document.frames['kXHR_iframe_'+inst].document.body.innerText;
		kXHR_objs[inst].responseText=responseText;
		kXHR_objs[inst].readyState=4;
		kXHR_objs[inst].status=200;
		kXHR_objs[inst].onreadystatechange();
		el.parentNode.removeChild(el);
	}else{
		delay*=1.5;
		setTimeout('XMLHttpRequest_checkState('+inst+','+delay+')',delay);
	}
}
/*	END Added for Stock PopUps	*/














function grabobj(objname) // v1.0
{
	return $(objname);
}
function $(objname)
{
if (document.getElementById) return document.getElementById(objname);if (document.all) return document.all[objname];if (document.layers) return document.layers[objname];
}
var curMen='';
function displayM(men)
{

	var i;
	for (var i=0;i<20;i++)
	{
	 if (men!='menul'+i)
	 {
		if ($('menul'+i+'inner'))
		{
			$('menul'+i).style.display='none';
			$('menul'+i+'inner').style.display='none';
		}
	 }
	}

	
	
	if ($(men+'inner')) curMen=men;
	if ($(men)) $(men).style.display='inline';
	if ($(men+'inner')) $(men+'inner').style.display='inline';
	clearTimeout(doClose);
	if (men!=closeMenu) hideMDo();

	
}
function displayM2(men)
{

	var i;
	for (var i=0;i<20;i++)
	{
	 if (men!='menu2'+i)
	 {
		if ($('menu2'+i+'inner'))
		{
			$('menu2'+i).style.display='none';
			$('menu2'+i+'inner').style.display='none';
		}
	 }
	}

	
	
	if ($(men+'inner')) curMen=men;
	if ($(men)) $(men).style.display='inline';
	if ($(men+'inner')) $(men+'inner').style.display='inline';
	clearTimeout(doClose);
	if (men!=closeMenu) hideMDo2();
}
var closeMenu;
var doClose;
var keepMenuOpen='';
function hideM(men)
{
	if (curMen!=men&curMen!="")
	{
	 
		if ($(curMen)) if (closeMenu) $(curMen).style.display='none';
		if ($(curMen+'inner')) if (closeMenu) $(curMen+'inner').style.display='none';
	}
	if (keepMenuOpen!=men)
	{
		closeMenu=men;
		doClose=window.setTimeout("hideMDo()",400);
	}

	
}
function hideM2(men)
{
	if (curMen!=men&curMen!="")
	{
	 
		if ($(curMen)) if (closeMenu) $(curMen).style.display='none';
		if ($(curMen+'inner')) if (closeMenu) $(curMen+'inner').style.display='none';
	}
	if (keepMenuOpen!=men)
	{
		closeMenu=men;
		doClose=window.setTimeout("hideMDo2()",400);
	}

	
}
function hideMDo()
{

	if ($(closeMenu)) if (closeMenu) if (closeMenu.style) $(closeMenu).style.display='none';
	if ($(closeMenu+'inner')) if (closeMenu) $(closeMenu+'inner').style.display='none';
	curMen='';
}
function hideMDo2()
{
	if ($(closeMenu)) if (closeMenu) $(closeMenu).style.display='none';
	if ($(closeMenu+'inner')) if (closeMenu) $(closeMenu+'inner').style.display='none';
	curMen='';
}
function displayMM(men)
{
	$(men).style.display='inline';
	clearTimeout(doClose);
	if (men!=closeMenu) hideMMDo();
}
function hideMMDo()
{
	if (closeMenu) $(closeMenu).style.display='inline';
}
