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_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_findObj(n, d) { //v3.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); 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_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

//--------
// this function is in for backwards compatiblity
//should use MM_openBrWindow
function openWin(URL,winName,features)
{
  MM_openBrWindow(URL,winName,features);
}



//---------
   function doBasketSubmit(){
       document.BasketForm.submit();
            }
//----------

//-------------
function pageReload(){
  window.location.reload( false);
 }
//-------------


//-------------
function checkSmallSearch(){
 if(document.SmallSearch.SearchProductName.value=="" || document.SmallSearch.SearchProductName.value==" ")
  {
    document.SmallSearch.SearchProductName.value="click to search";
  }
 }
//-------------

//------------------
function changeContentFrame(href){
   top.frames.main.content.location=href;
}
//------------------


//---- break row script ---------
// itemno of this cell, no at which the row should split, the number of items per page
function prodsPerLine(itemno,endrow,endofitems)
     {
         // close tr's
         if((itemno % endrow) == 0)document.write('</tr>');
         // check if not end of page
         if(itemno != endofitems)
                  {
                   //if start of new row
                     if(itemno % endrow == 0)document.write('<tr>');  //open new row IF not end of list so don't open new tr
                  }

     }
//----------------------


// by Aubrey Blazey 5/1/01
// function to convert currency into a proper decimal format ---------
function formatCurrency(num) {
   if(isNaN(num)) num = "0";
   pence = Math.floor((num*100+0.5)%100);
   num = Math.floor((num*100+0.5)/100).toString();
   if(pence < 10) pence = "0" + pence;
   for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
   num = num.substring(0,num.length-(4*i+3))+','+num.substring(num.length-(4*i+3));
   return (num + '.' + pence);
}



//----------------------
function SetStatusBar(msg){window.status = msg;}
//---------------------


function submitIt(aForm){
  if (aForm.sh_zipcode.value=='' || aForm.sh_zipcode.value==' ')
   {
    alert('Post Code is required');
    aForm.sh_zipcode.focus();
    return false;
   }
   else
   {
    return true;
   }

}//end function


//-------------------------

// by Lance Keay 30/Jan/2002
// function to limit the size of a string
// pass the string, start index and the size to limit it to
// eg sizeString('Octavia rules mars', 0, 5);
// output = Octav
// The commented out lines are there because Netscape seems to want them... dunno why.

/*
        <script language=javascript>
            document.write(sizeString('#ProductDescription',0,20));
        </script>
*/

function sizeString(vStr,vStart,vLen)
{
    //alert (vStr + vStart + vLen);
    vStr = (vStr.slice(vStart,vLen) + "...");
    //vStr = (vStr + "...");
    //alert (vStr);
   return (vStr);
}


//------------------------

/* 	Lance Keay 1/feb/2002
	This will open a window containing the image passed in using the path variable.
	
	syntax example - <td valign="top" align="right">
			#IF(#AlternativeMediaFile)<a href="JAVASCRIPT:imageWindow('#StoreImagePath/#AlternativeMediaFile');">
			<img src="#StoreImagePath/Images/close_up_button.gif" width="67" height="18" border="0"></a>#ENDIF</td>

*/

function imageWindow(path)
{
  window.open(path,'mywindow','width=300,height=300,scrollbars=no,resizable=yes');
}


//----------------------

/*	Lance Keay 1/feb/2002
	Switch card entry form validation
	
	syntax example:
	
	<FORM #FormTagAttributesSSL name=CardForm onSubmit="return checkForm()">
*/	

function checkForm()
{
	// This will check each field on the form for validity
	
	var vCard = document.CardForm.CardType.value;
	var vCardNo = document.CardForm.CreditCardNo.value;
	var vExpMo = document.CardForm.CreditCardExpireMonth.value;
	var vExpYr = document.CardForm.CreditCardExpireYear.value;
	var vSwitchIssNo = document.CardForm.SwitchIssueNumber.value;
	var vSwitchStMo = document.CardForm.SwitchStartMonth.value;
	var vSwitchStYr = document.CardForm.SwitchStartYear.value;
	var vDate = new Date();
	var vYr = vDate.getFullYear();
	var vMo = vDate.getMonth();
	
	//alert("Debugging.. Numbers " + vCard);
	
	if(vCardNo < 9999999999)
	{
		alert("Please enter your entire card number.");
		document.CardForm.CreditCardNo.focus();
		return(false);
	}

	if(vExpYr <= vYr)
	{
		if(vExpYr == vYr && vExpMo < vMo)
		{
			alert("Please enter a valid expiry date.");
			document.CardForm.CreditCardExpireMonth.focus();
			return(false);
		}
		if(vExpYr < vYr)
		{
			alert("Please enter a valid expiry date.");
			document.CardForm.CreditCardExpireMonth.focus();
			return(false);
		}		
	}
	
	if(vCard == 3)
	{
		if(vSwitchIssNo.length < 2)
		{
			alert("Please enter an issue number of at least two digits.  eg 01, 07, 12, etc.");
			document.CardForm.SwitchIssueNumber.focus();
			return(false);
		}
	}
}


//----------------------  FUNCTIONS FOR COOKIES -----
// get a 'named' cookie from a browser
function GetCookie (name){

  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen){
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg){
      return getCookieVal (j);
    }
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break;
  }
  return null;
}

//------------------------------------------
// set a cookie on a users browser
function SetCookie(name, value)  
   { 
    //var never = new Date(); 
   //never.setTime(never.getTime() + 2000*24*60*60*1000); 
   //var expString = "; expires=" + never.toGMTString(); 
   var newpath = "; path=/"; 
   //document.cookie = name + "=" + escape(value) + expString + newpath; 
   document.cookie = name + "=" + escape(value) + newpath; 
   }
   
//------------------------------------------
// set a cookie on a users browser
function DeleteCookie(name)  
   { 
   var expString = "; expires=Thu, 01-Jan-1970 00:00:01 GMT";
   var newpath = "; path=/"; 
   document.cookie = name + "=" + "" + expString + newpath; 
   }

//---------------------------------------
// called from get cookie function
function getCookieVal(offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}
//--------------------------------------

function LogOff(url){
DeleteCookie('LoggedIn');
location.replace(url);
}