var xmlHttp=null;
var xmlHttp2=null;



function SelectDeliveryAddress( addID )
{
	var cmd="";
	form=document.InfoForm;
	cmd="SelectDeliveryAddress?wsid="+form.wsid.value+"&AddID="+addID
	location=cmd;
}

function ClearAddress()
{
	document.DropshipForm.DScompanyname.value="";
	document.DropshipForm.DScontactname.value="";
	document.DropshipForm.DStelephone.value="";
	document.DropshipForm.DSadd1.value="";
	document.DropshipForm.DSadd2.value="";
	document.DropshipForm.DSadd3.value="";
	document.DropshipForm.DSadd4.value="";
	document.DropshipForm.DSpcode.value="";
	document.DropshipForm.DSOtherInfo.value="";
	
}


function DoSearch()
{
	var form=document.QuickSearchFormA;
	var val=form.query.value;

	while ( val.indexOf("/") != -1)
	{
		val = val.replace("/", "");
	}
 	while ( val.indexOf("'") != -1)
	{
		val = val.replace("'", "");
	}
	
	form.action="Search_P01SA_"+val+".html";
	form.submit();
}





function mailpage(code,itemtitle)
{
mail_str = "mailto:?subject=Universal Furniture Wholesale - " + itemtitle;
mail_str += "&body=I thought you might be interested in " + itemtitle + " I’ve seen on Quality Cycles 4u. ";
mail_str += "You can view it at http://www.QualityCycles4u.com/" + code;
location.href = mail_str;
}
 

function CheckLoginForm(form)
{
var cmd="";
var error=false;
if (!error) error=CheckEmpty(form.CustomerCode,form.CustomerCode.value,"Please enter a Username");
if (!error) error=CheckEmpty(form.CustomerPassword,form.CustomerPassword.value,"Please enter a password");
return (!error);
}

function CheckAccountForm(form)
{
var cmd="";
var error=false;

if (!error) error=CheckEmpty(form.CompanyName,form.CompanyName.value,"Please enter a Customer Name");
if (!error) error=CheckEmpty(form.ContactName,form.ContactName.value,"Please enter a Contact Name");

if (!error) error=CheckEmpty(form.ContactTelephone,form.ContactTelephone.value,"Please enter a Contact Telephone");

if (!error) error=CheckEmpty(form.InvAdd1,form.InvAdd1.value,"Please enter a Invoice Address");
if (!error) error=CheckEmpty(form.InvPCode,form.InvPCode.value,"Please enter a Invoice Postcode");


/*
if (!error) error=CheckEmpty(form.DStelephone,form.DStelephone.value,"Please enter a Contact Telephone");
if (!error) error=CheckEmpty(form.DSadd1,form.DSadd1.value,"Please enter a Delivery Address");

if (!error) error=CheckEmpty(form.DSpcode,form.DSpcode.value,"Please enter a Delivery Postcode");
*/
return (!error);
}

function CheckDropshipForm(form)
{
var cmd="";
var error=false;

if (navigator.userAgent.indexOf("Firefox")!=-1)
{
	return true;
}
else
{
if (!error) error=CheckEmpty(form.DScompanyname,form.DScompanyname.value,"Please enter a Customer Name");
if (!error) error=CheckEmpty(form.DScontactname,form.DScontactname.value,"Please enter a Contact Name");
if (!error) error=CheckEmpty(form.OrderRef,form.OrderRef.value,"Please enter an Order Reference");

if (!error) error=CheckEmpty(form.DStelephone,form.DStelephone.value,"Please enter a Contact Telephone");
if (!error) error=CheckEmpty(form.DSadd1,form.DSadd1.value,"Please enter a Delivery Address");

if (!error) error=CheckEmpty(form.DSpcode,form.DSpcode.value,"Please enter a Delivery Postcode");

return (!error);
}
}

function BackToTop()
{
var cmd="";
form=document.InfoForm;
	
cmd="Welcome?wsid="+form.wsid.value;

location=cmd;//=EncodeURL(cmd);
}


function add_to_fave(code,itemtitle)
{	
	window.external.AddFavorite(code, itemtitle);	
}

function GoogleCheckout()
{
var cmd="";
form=document.InfoForm;

cmd="GoogleCheckout?wsid="+form.wsid.value;

location=cmd;//=EncodeURL(cmd);
}

function QuicksearchGo()
{
	form=document.QuickSearchFormA;
	
	if( (form.query.value=="Delivery")||(form.query.value=="delivery")||(form.query.value=="Deliver")||(form.query.value=="deliver"))
	{
		form.query.value="";
		GoToCheckout();
	}
	else
	{
		if(true)//( navigator.appName=="Netscape" )
		{
		form.submit();
		}
		else
		{
		GetList();	
		}
	}
}


function initAjax()
{
	try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    }
}

function GoogleTracker()
{
//	var pageTracker = _gat._getTracker("UA-3299213-1");
//  pageTracker._initData();
//	pageTracker._trackPageview();
}



function stateChanged() 
{ 
	if (xmlHttp.readyState==4)
	{ 
		document.getElementById("listzone").style.visibility= 'hidden';
		document.getElementById("listzone").innerHTML=xmlHttp.responseText;
		document.getElementById("queryzone").innerHTML=document.getElementById("querypart").innerHTML;
		innerHTML=document.getElementById("querypart").innerHTML="";
		document.getElementById("menuzone").innerHTML=document.getElementById("menupart").innerHTML;
		innerHTML=document.getElementById("menupart").innerHTML="";
		document.getElementById("basketzone").innerHTML=document.getElementById("basketpart").innerHTML;
		innerHTML=document.getElementById("basketpart").innerHTML="";
		document.getElementById("listzone").style.visibility= 'visible';
		document.title="Universal Furniture Wholesale - Discount Furniture - "+document.getElementById("titlepart").innerHTML;
		document.getElementById("titlepart").innerHTML="";
		//GoogleTracker();
		document.getElementById("waitarea").innerHTML="";

		//	document.QuickSearchFormA.midcategory.value=document.HiddenStuff.currentcategory.value;
	}
} 


function GetList()
{
	if(1)//( navigator.appName=="Netscape")
	{
	return true;
	}
	else
	{
		initAjax();
	
	//	document.getElementById("waitarea").innerHTML="<img src='Images/1-0.gif' width='16px' height='16px'/>";
	
		var url="web_SearchFormAjax?wsid="+document.QuickSearchFormA.wsid.value;
		url=url+"&category="+encodeURIComponent( document.getElementById("category").value );
		
		url=url+"&midcategory="+encodeURIComponent( document.getElementById("midcategory").value );
		url=url+"&subcategory="+encodeURIComponent( document.getElementById("subcategory").value );
			
		url=url+"&query="+encodeURIComponent( document.getElementById("query").value );
		url=url+"&pricefrom2="+encodeURI( document.getElementById("pricefrom2").value );
		
		url=url+"&query2="+encodeURI( document.getElementById("query2").value );
		url=url+"&SortBox="+encodeURI( document.getElementById("SortBox").value );
			
		xmlHttp.onreadystatechange=stateChanged;
		xmlHttp.open("GET",url,true);
	
		xmlHttp.send(null);
		return false;	
	}
}

function stateChangedImage() 
{ 
	if (xmlHttp.readyState==4)
	{ 
	document.getElementById("imagezone2").innerHTML=xmlHttp.responseText;
	
		
	}
} 


function ChangeImage( imagename , pcode )
{
	if(0)//( navigator.appName=="Netscape")
	{
	return true;
	}
	else
	{
		initAjax();
		
	//	document.getElementById("waitarea").innerHTML="<img src='Images/1-0.gif' width='16px' height='16px'/>";
		var url="ChangeImage?ImageName="+imagename+"&cPartCode="+pcode;
			
		xmlHttp.onreadystatechange=stateChangedImage;
		xmlHttp.open("GET",url,true);
	
		xmlHttp.send(null);
		//return false;	
	}
}

function stateChangedForTime() 
{ 
	if (xmlHttp.readyState==4)
	{ 

		document.getElementById("timezone").innerHTML=xmlHttp.responseText;

		//	document.QuickSearchFormA.midcategory.value=document.HiddenStuff.currentcategory.value;
	}
} 


function GetTimeFromServer()
{
	if(1)//( navigator.appName=="Netscape")
	{
	return true;
	}
	else
	{
		initAjax();
	

		var url="web_Time"
		
		xmlHttp.onreadystatechange=stateChangedForTime;
		xmlHttp.open("GET",url,true);
	
		xmlHttp.send(null);
		return false;	
	}
}



function stateChangedFlipSort() 
{ 
	if (xmlHttp.readyState==4)
	{ 
		document.getElementById("waitarea").innerHTML="";
		document.getElementById("listzone").innerHTML=xmlHttp.responseText;
		
		GoogleTracker();
	}
} 


function CallFlipSort()
{

	if(false)//( navigator.appName=="Netscape")
	{
	return true;
	}
	else
	{
	initAjax();
//  alert("cdsdcd0");
//	document.getElementById("LoadZone").innerHTML="<img src='/WebMediaUS/progressbar.gif' style='height:12px;width:51px'/>";


	document.getElementById("waitarea").innerHTML="<img src='Images/1-0.gif' width='220px' height='19px'/>";
	
	var url="web_FlipSort?wsid="+document.QuickSearchFormA.wsid.value;
	if( document.InfoForm.SortBox.value=="" )
	{
		url=url+"&SortBox=Ascending";
	}
	else
	{
		url=url+"&SortBox="+encodeURI( document.InfoForm.SortBox.value );
	}

	xmlHttp.onreadystatechange=stateChangedFlipSort;
	xmlHttp.open("GET",url,true);

	xmlHttp.send(null);
	return false;	
	}
}


function stateChangedForPage() 
{ 
	if (xmlHttp.readyState==4)
	{ 
//	document.getElementById("waitarea").innerHTML="";
		document.getElementById("listzone").innerHTML=xmlHttp.responseText;
		document.getElementById("menupart").innerHTML="";
		//GoogleTracker();
		window.scroll(0,0);
	//	document.getElementById("LoadZone").innerHTML=" ";
	
	}
} 

function stateChangedForPageNum() 
{ 
	if (xmlHttp.readyState==4)
	{ 
	document.getElementById("waitarea").innerHTML="";
		document.getElementById("listzone").innerHTML=xmlHttp.responseText;
	//	document.getElementById("topmenuzone").innerHTML=document.getElementById("menupart").innerHTML;
	//	document.getElementById("menupart").innerHTML="";
		//GoogleTracker();
		//window.scroll(0,0);
	//	document.getElementById("LoadZone").innerHTML=" ";
	
	}
} 

function GetPage( pagenum )
{
	var url="";
	initAjax();
	window.scroll(0,0);
//	document.getElementById("LoadZone").innerHTML="<img src='/WebMediaUS/progressbar.gif' style='height:12px;width:51px'/>";
//	document.getElementById("waitarea").innerHTML="<img src='Images/1-0.gif' width='220px' height='19px'/>";
	url="GetPage?wsid="+document.InfoForm.wsid.value;
	url=url+"&PageNo="+pagenum;
	
	xmlHttp.onreadystatechange=stateChangedForPage;
	xmlHttp.open("GET",url,true);
	
	xmlHttp.send(null);
	
//GetMenu();
}

function GetPageNum( pagenum )
{
	var url="";
	initAjax();
	//window.scroll(0,0);
//	document.getElementById("LoadZone").innerHTML="<img src='/WebMediaUS/progressbar.gif' style='height:12px;width:51px'/>";
	document.getElementById("waitarea").innerHTML="<img src='Images/1-0.gif' width='220px' height='19px'/>";
	url="Page?wsid="+document.InfoForm.wsid.value;
	url=url+"&PageNo="+pagenum;
	
	xmlHttp.onreadystatechange=stateChangedForPageNum;
	xmlHttp.open("GET",url,true);
	
	xmlHttp.send(null);
	
//GetMenu();
}

function NextPage()
{
	var url="";
	initAjax();
	//window.scroll(0,0);
//	document.getElementById("LoadZone").innerHTML="<img src='/WebMediaUS/progressbar.gif' style='height:12px;width:51px'/>";
	document.getElementById("waitarea").innerHTML="<img src='Images/1-0.gif' width='220px' height='19px'/>";
	url="NextPage?wsid="+document.InfoForm.wsid.value;
	xmlHttp.onreadystatechange=stateChangedForPageNum;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function LastPage()
{
	var url="";
	initAjax();
	//window.scroll(0,0);
//	document.getElementById("LoadZone").innerHTML="<img src='/WebMediaUS/progressbar.gif' style='height:12px;width:51px'/>";
	document.getElementById("waitarea").innerHTML="<img src='Images/1-0.gif' width='220px' height='19px'/>";
	url="LastPage?wsid="+document.InfoForm.wsid.value;
	xmlHttp.onreadystatechange=stateChangedForPageNum;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}


function GetLastPage()
{
	var url="";
	initAjax();
//	document.getElementById("LoadZone").innerHTML="<img src='/WebMediaUS/progressbar.gif' style='height:12px;width:51px'/>";

	url="LastPage?wsid="+document.InfoForm.wsid.value;	
	xmlHttp.onreadystatechange=stateChangedForPage;
	xmlHttp.open("GET",url,true);
	
	xmlHttp.send(null);

//GetMenu();
}


function stateChangedForDetail() 
{ 
	if (xmlHttp.readyState==4)
	{ 
		document.getElementById("listzone").innerHTML=xmlHttp.responseText;
		document.title="Universal Furniture Wholesale     "+document.getElementById("titlepart").innerHTML;
		document.getElementById("titlepart").innerHTML="";
		window.scroll(0,0);
		GoogleTracker();
	//	document.getElementById("LoadZone").innerHTML=" ";
	}
} 

function GetDetail(code)
{
var url="";
initAjax();

form=document.InfoForm;

url="AjaxDetail?wsid="+form.wsid.value+"&thecode="+code;

xmlHttp.onreadystatechange=stateChangedForDetail;
xmlHttp.open("GET",url,true);

xmlHttp.send(null);
}


function stateChangedBasket() 
{ 
	if (xmlHttp.readyState==4)
	{ 
		document.getElementById("basketzone").innerHTML=xmlHttp.responseText;
		GoogleTracker();
	}
} 

function AjaxBasketAdd( thecode , Quant )
{
initAjax();
	var url="AjaxAddToBasket?wsid="+document.QuickSearchFormA.wsid.value;
	url=url+"&thecode="+thecode;
	url=url+"&Quant="+Quant;
	xmlHttp.onreadystatechange=stateChangedBasket;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	return false;
//GetMenu();
}

function LostPassword()
{
var cmd="";
form=document.QuickSearchFormA;

cmd="LostPassword?wsid="+form.wsid.value;

location=cmd;//=EncodeURL(cmd);
	
}


function CheckEmpty(field,text,msg)
{	var error=false;
	if (text=='') { error=true; }
	if (error) { alert(msg); field.focus(); field.select(); }
	return error;
}

// ------------------------------------------------------------------------------
// check if a menu item has been selected
// error=CheckEmptyMenu(form.Menu,"Select a menu item.");
// ------------------------------------------------------------------------------
function CheckEmptyMenuItem(field,msg)
{	var error=false;
	if (field.selectedIndex==0) { error=true; }
   	if (error) { alert(msg); field.focus();}
	return error;
}

// ------------------------------------------------------------------------------
// check if a checkbox is unchecked
// error=CheckEmptyCheckbox(form.Checkbox,"Check that box !");
// ------------------------------------------------------------------------------
function CheckEmptyCheckbox(field,msg)
{	var error=false;
	if (field.checked==0) { error=true; }
   	if (error) { alert(msg); field.focus();}
	return error;
}

// ------------------------------------------------------------------------------
// check if an email address seems to be in a correct format
// error=CheckBadEMail(form.Email,"This email address is not valid.");
// ------------------------------------------------------------------------------
function CheckBadEMail(field,msg)
{    var error=true;
    var pos,posdot,str,end;
    if (field.value.indexOf("@")>=2)
    {    posdot=0;
        pos=0;
        str=field.value;
        pos=str.indexOf(".");
        while(pos>0)
        {    posdot+=pos;
            posdot+=1;
            str=str.substring(pos+1,str.length);
            pos=str.indexOf(".");
        }
        end=str;
       
        if(end!="")
            if(posdot>=4)
                if(end.length>=1)
                    error=false;
    }
    if (error) { alert(msg); field.focus(); field.select(); }
    return error;
} 

// ------------------------------------------------------------------------------
// check if a field does not contain any of characters found in a set
// error=CheckNotInSet(form.Number,"-0123456789.,","This is not a number.");
// ------------------------------------------------------------------------------
function CheckNotInSet(field,set,msg)
{	var error=false;
	var text;
	for (var i=0;i<field.value.length;i++)
	{	text=field.value.substring(i,i+1);
		if (set.indexOf(text)=="-1")  error=true;
	}
	if (error) { alert(msg); field.focus(); field.select(); }
	return error;
}

// ------------------------------------------------------------------------------
// check if some characters found in a field are in a set
//	error=CheckInSet(form.Name,"\:/&éàç","Some characters are not valid.");
// ------------------------------------------------------------------------------
function CheckInSet(field,set,msg)
{	var error=false;
	var text;
	for (var i=0;i<field.value.length;i++)
	{	text=field.value.substring(i,i+1);
		if (set.indexOf(text)!="-1")  error=true;
	}
	if (error) { alert(msg); field.focus(); field.select(); }
	return error;
}
// ------------------------------------------------------------------------------
// check if a string is found in a field
//	error=CheckStringDoesExist(form.Name,"root","You url is not valid.");
// ------------------------------------------------------------------------------
function CheckStringDoesExist(field,set,msg)
{	var error=false;
	if (field.value.indexOf(set)!=-1)  error=true;
	if (error) { alert(msg); field.focus(); field.select(); }
	return error;
}
// ------------------------------------------------------------------------------
// check if a string is not found in a field
//	error=CheckStringDoesNotExist(form.Name,"XUY","Your key is not valid.");
// ------------------------------------------------------------------------------
function CheckStringDoesNotExist(field,set,msg)
{	var error=false;
	if (field.value.indexOf(set)==-1)  error=true;
	if (error) { alert(msg); field.focus(); field.select(); }
	return error;
}
// ------------------------------------------------------------------------------
// check the max length of a field
// error=CheckMaxLength(form.Name,20,"This name is too long.");
// ------------------------------------------------------------------------------
function CheckMaxLength(field,length,msg)
{	var error=false;
	if (field.value.length > length)  error=true;
	if (error) { alert(msg); field.focus(); field.select(); }
	return error;
}

// ------------------------------------------------------------------------------
// check the min length of a field
// error=CheckMinLength(form.Name,20,"This name is too short.");
// ------------------------------------------------------------------------------
function CheckMinLength(field,length,msg)
{	var error=false;
	if (field.value.length < length) error=true;
	if (error) { alert(msg); field.focus(); field.select(); }
	return error;
}

// ------------------------------------------------------------------------------
// check the date format
// error=CheckBadDate(form.Date,"This is not a date.");
// ------------------------------------------------------------------------------
function CheckBadDate(field,msg)
{	var error=false;
	var set="0123456789/"
	for (var i=0;i<field.value.length;i++)
	{	if(set.indexOf(""+field.value.substring(i,i+1))=="-1") error=true;
	}
	if (field.value.length != 8) error=true
	b=field.value.substring(0,2) // day
	c=field.value.substring(2,3)// '/'
	d=field.value.substring(3,5) // month
	e=field.value.substring(5,6)// '/'
	f=field.value.substring(6,8) // year
	if(b<1 || b>31) error=true
	if(c != '/') error=true
	if(d<1 || d>12) error=true
	if(e != '/') error=true
	if(f<0 || f>99) error=true
	if(b==4 || b==6 || b==9 || b==11)
	{	if (d==31) error=true	}
	if (b==2)
	{	var g=parseInt(f/4)
		if (isNaN(g))
		{	error=true	}
		if (d>29) error=true
		if (d==29 && ((f/4)!=parseInt(f/4))) error=true
	}
	if (error)
	{	alert(msg); field.focus(); field.select(); }
	return error;
}

// ------------------------------------------------------------------------------
// check the format of credit card number
// errorstr=CheckCard(form.CardNumber.value,form.CardDate.value);
// if (errorstr!="")
//      switch(errorstr)
//		{	case "DATEXP" : alert("Your card has expired..."); error=true; break;
//			case "BADNUM" : alert("This number is not valid..."); error=true; break;
//			case "UNKCAR" : alert("This card's type is not valid..."); error=true; break;
//			case "INVLEN" : alert("Key's length of this card is not valid..."); error=true; break;
//			case "INVKEY" : alert("Key of this card is not valid..."); error=true; break;
//			default : alert("Your card is a "+errorstr);
//		} 
// ------------------------------------------------------------------------------
function CheckCard(cardnumber,carddate)
{	var error=false;
	var errorstr="";
	var cardsprefix=new Array(22);
	var cardsnames=new Array(22);
	var cardsmasks=new Array(22);
	var cardname="";
	var cardidx=0;
	var cardlength=cardnumber.length;

	cardsprefix[0]="4";
	cardsprefix[1]="51";
	cardsprefix[2]="52";
	cardsprefix[3]="53";
	cardsprefix[4]="54";

	cardsprefix[5]="55";
	cardsprefix[6]="37";
	cardsprefix[7]="34";
	cardsprefix[8]="6011";
	cardsprefix[9]="56";
	cardsprefix[10]="3";
	cardsprefix[11]="1800";
	cardsprefix[12]="2131";
	cardsprefix[13]="2014";
	cardsprefix[14]="2149"
	cardsprefix[15]="300";
	cardsprefix[16]="301";
	cardsprefix[17]="302";
	cardsprefix[18]="303";
	cardsprefix[19]="304";
	cardsprefix[20]="305";
	cardsprefix[21]="36";
	cardsprefix[22]="38";
	
	cardsnames[0]="VISA";
	cardsnames[1]="MasterCard";
	cardsnames[2]="MasterCard";
	cardsnames[3]="MasterCard";
	cardsnames[4]="MasterCard";
	cardsnames[5]="MasterCard";
	cardsnames[6]="American Express";
	cardsnames[7]="American Express";
	cardsnames[8]="Discover";
	cardsnames[9]="BankCard"
	cardsnames[10]="JCB";
	cardsnames[11]="JCB";
	cardsnames[12]="JCB";
	cardsnames[13]="enRoute";
	cardsnames[14]="enRoute";
	cardsnames[15]="Diners Club/Carte Blanche";
	cardsnames[16]="Diners Club/Carte Blanche";
	cardsnames[17]="Diners Club/Carte Blanche";
	cardsnames[18]="Diners Club/Carte Blanche";
	cardsnames[19]="Diners Club/Carte Blanche";
	cardsnames[20]="Diners Club/Carte Blanche";
	cardsnames[21]="Diners Club/Carte Blanche";
	cardsnames[22]="Diners Club/Carte Blanche";

	cardsmasks[0]=10;	// (((13-12) << 1) | ((16-12) << 1))
	cardsmasks[1]=8;	// (16-12) << 1
	cardsmasks[2]=8;
	cardsmasks[3]=8;
	cardsmasks[4]=8;
	cardsmasks[5]=8;
	cardsmasks[6]=6;	// (15-12) << 1
	cardsmasks[7]=6;
	cardsmasks[8]=8;	// (16-12) << 1
	cardsmasks[9]=8;	// (16-12) << 1
	cardsmasks[10]=6;	// (15-12) << 1
	cardsmasks[11]=6;
	cardsmasks[12]=6;
	cardsmasks[13]=6;	// (15-12) << 1
	cardsmasks[14]=6;
	cardsmasks[15]=4;	// (14-12) << 1
	cardsmasks[16]=4;
	cardsmasks[17]=4;
	cardsmasks[18]=4;
	cardsmasks[19]=4;
	cardsmasks[20]=4;
	cardsmasks[21]=4;
	cardsmasks[22]=4;
	
	var result=true;
	var badnumber=false;
	
	cardnumber=cardnumber.replace(/ /gi,"");
	cardnumber=cardnumber.replace(/-/gi,"");
	cardnumber=cardnumber.replace(/\//gi,"");
	
	if(!error)
	{	var month=Number(carddate.substring(0,2));
		var year=Number(carddate.substring(3,5));
	//	alert(month+"-"+year);
		year=((year<80) ? 2000+year : 1900+year);
		var expiresdate=new Date(year,month,1);
		today=new Date();
	//	alert("Exp: "+expiresdate.toGMTString());
	
		var deltayears=expiresdate.getFullYear()-today.getFullYear();
		var deltamonthes=expiresdate.getMonth()-today.getMonth();
	//	alert(deltamonthes+" "+deltayears);
		if(expiresdate<today) { error=true; errorstr="DATEXP"; }
		
	//	if(deltayears<0) { error=true; errorstr="DATEXP"; }
	//	else
	//		if(deltayears>=0)
	//			if(deltamonthes<=0) { error=true; errorstr="DATEXP"; }
	}
	
	if(!error)
	{	for (var i=0;(i<cardlength) && (!error);i++)
		{	thecode=cardnumber.charCodeAt(i);
			if((thecode<48) || (thecode>57))
			{ error=true; errorstr="BADNUM"; }
		} 
	}
	
	if(!error)
	{	var digits4=cardnumber.substring(0,4);
		var digits3=cardnumber.substring(0,3);
		var digits2=cardnumber.substring(0,2);
		var digits1=cardnumber.substring(0,1);
		var found=false;
		for (var i=0;(i<cardsprefix.length) && (!found);i++)
			if(cardsprefix[i]==digits4) { cardidx=i; cardname=cardsnames[i]; found=true; }
		for (var i=0;(i<cardsprefix.length) && (!found);i++)
			if(cardsprefix[i]==digits3) { cardidx=i; cardname=cardsnames[i]; found=true; }
		for (var i=0;(i<cardsprefix.length) && (!found);i++)
			if(cardsprefix[i]==digits2) { cardidx=i; cardname=cardsnames[i]; found=true; }
		for (var i=0;(i<cardsprefix.length) && (!found);i++)
			if(cardsprefix[i]==digits1) { cardidx=i; cardname=cardsnames[i]; found=true; }

		if(!found)
			{ error=true; errorstr="UNKCAR"; }
	}
	
	if(!error)
	{	if (cardlength < 29)
		{	var checksum=((cardlength-12) << 1)// & cardsmasks[cardidx];
			if ((cardlength < 12) || (checksum==0)) { error=true; errorstr="INVLEN"; }
			else
			{	if (cardname!="enRoute")
				{	checksum=0;
					var nu=0;
					var cnt=cardlength;
					var flag=false;
					while(cnt>0)
					{	nu=Number(cardnumber.substring(cnt-1,cnt));
						if (flag)
						{	nu*=2;
							nu=((nu>9) ? nu-=9 : nu);
						}
						checksum+=nu;
						flag=!flag;
						cnt--;
					}
					if((checksum % 10)!=0) { error=true; errorstr="INVKEY"; }
				}
			}
		  
		}
		else { error=true; errorstr="INVLEN"; }
	}
	
	if(errorstr=="") errorstr=cardname;
	return(errorstr);
}
	

function CheckCustomerForm(form)
{
var cmd="";
var error=false;
if (!error) error=CheckEmpty(form.cLoginName,form.cLoginName.value,"Please enter a Username");

if (!error) error=CheckEmpty(form.cLoginPassword,form.cLoginPassword.value,"Please enter a password");
if (!error) error=CheckInSet(form.cLoginPassword,"\:/&,;@éèàç","Your password contains invalid characters.");
if (!error) error=CheckMinLength(form.cLoginPassword,4,"Your password is too short (min. 4 chars).");

if (!error) error=CheckEmpty(form.cFirstName,form.cFirstName.value,"Please enter your first name");
if (!error) error=CheckEmpty(form.cLastName,form.cLastName.value,"Please enter your last name.");
if (!error) error=CheckEmpty(form.cTelephone,form.cTelephone.value,"PLease enter your phone number.");
if (!error) error=CheckNotInSet(form.cTelephone,"0123456789-+()/ ","A phone number is required.");

if (!error) error=CheckEmpty(form.cemail,form.cemail.value,"Please enter your e-mail address.");
if (!error) error=CheckBadEMail(form.cemail,"The e-mail address is invalid.");

if (!error) error=CheckEmpty(form.cAdd1,form.cAdd1.value,"Please enter a billing address.");
if (!error) error=CheckEmpty(form.cPostcode,form.cPostcode.value,"Please enter a billing postcode");

if (!error) error=CheckEmpty(form.cDelAdd1,form.cDelAdd1.value,"Please enter a delivery address.");
if (!error) error=CheckEmpty(form.cDelPostcode,form.cDelPostcode.value,"Please enter delivery postcode");

if (!error) error=CheckEmpty(form.cSecretQuestion,form.cSecretQuestion.value,"Please enter secret question");
if (!error) error=CheckEmpty(form.cSecretAnswer,form.cSecretAnswer.value,"Please enter secret answer");
return (!error);

}

function DoDeliveryCheck()
{
	document.AccountForm.AddressTicking.value="Yes";
	document.AccountForm.submit();
}

function ViewOrder(code)
{
	var cmd="";
	form=document.InfoForm;
	
	cmd="ViewOrder?wsid="+form.wsid.value+"&Code="+code
	location=cmd;
}

function CheckRMAForm(form)
{
var cmd="";
var error=false;

if (!error) error=CheckEmpty(form.aUsername,form.aUsername.value,"Please enter a Username");
if (!error) error=CheckEmpty(form.aOrderNumber,form.aOrderNumber.value,"Please enter an order number");
if (!error) error=CheckEmpty(form.aItem,form.aItem.value,"Please enter an item.");

if (!error) error=CheckEmpty(form.aReason,form.aReason.value,"Please enter a Reason");

return (!error);
}

function CheckCallbackForm(form)
{
var cmd="";
var error=false;
if (!error) error=CheckEmpty(form.aFirstName,form.aFirstName.value,"Please enter your first name");
if (!error) error=CheckEmpty(form.aLastName,form.aLastName.value,"Please enter your surname");
if (!error) error=CheckEmpty(form.aTelephone,form.aTelephone.value,"Please enter your telephone number");
if (!error) error=CheckEmpty(form.aemail,form.aemail.value,"Please enter your email");

if (!error) error=CheckEmpty(form.aInformation,form.aInformation.value,"Please enter some details");


return (!error);
}

function NewTrolley()
{
form=document.QuickSearchFormA;
cmd="NewTrolley?wsid="+form.wsid.value;
location=cmd;
}

function QuickSearchSelect(code)
{
form=document.QuickSearchFormA;
cmd="QuickSearchSelect?wsid="+form.wsid.value+"&searchcode="+code;
location=cmd;
}

function GetProductRange()
{
form=document.QuickSearchFormA;
cmd="ProductRange?wsid="+form.wsid.value;
location=cmd;
}

function NewTrolleyYes()
{
form=document.QuickSearchFormA;
cmd="NewTrolleyYes?wsid="+form.wsid.value;
location=cmd;
}

function NewTrolleyNo()
{
form=document.QuickSearchFormA;
cmd="NewTrolleyNo?wsid="+form.wsid.value;
location=cmd;
}


function InformationDelivery()
{
var cmd="";
form=document.QuickSearchFormA;
cmd="Information_Delivery?wsid="+form.wsid.value;
location=cmd;
}

function InformationTearms()
{
var cmd="";
form=document.QuickSearchFormA;
cmd="Information_Tearms?wsid="+form.wsid.value;
location=cmd;
}

function InformationManufacturer()
{
var cmd="";
form=document.QuickSearchFormA;
cmd="Information_Manufacturer?wsid="+form.wsid.value;
location=cmd;
}


function ContactTelephone()
{
var cmd="";
form=document.QuickSearchFormA;
cmd="ContactTelephone?wsid="+form.wsid.value;
location=cmd;
}

function ContactCallback()
{
var cmd="";
form=document.QuickSearchFormA;
cmd="ContactCallback?wsid="+form.wsid.value;
location=cmd;
}

function ContactRMA()
{
var cmd="";
form=document.QuickSearchFormA;
cmd="ContactRMA?wsid="+form.wsid.value;
location=cmd;
}


function GoToHome()
{
var cmd="";
form=document.QuickSearchFormA;

cmd="Default?wsid="+form.wsid.value;

location=cmd;
}

function GoToPrintform()
{
var cmd="";
form=document.QuickSearchFormA;

cmd="PrintForm?wsid="+form.wsid.value;
myRef = window.open('','mywin','left=20,top=20,width=800,height=1200,toolbar=1,resizable=0');
myRef.location=cmd;

//_top.location=cmd;
}




function GoToDetailsDescription()
{
var cmd="";
form=document.QuickSearchFormA;

cmd="Show_Detail_Description?wsid="+form.wsid.value;

location=cmd;//=EncodeURL(cmd);	
}


function ShowTypes()
{
var cmd="";
form=document.QuickSearchFormA;
cmd="showTypes?wsid="+form.wsid.value
location=cmd;
}

function RemoveType(code)
{
var cmd="";
form=document.QuickSearchFormA;
cmd="RemoveType?wsid="+form.wsid.value+"&typecode="+code
location=cmd;
}

function ChangeType(productcode,typecode)
{
var cmd="";

form=document.QuickSearchFormA;
cmd="RemoveType?wsid="+form.wsid.value+"&productcode="+productcode+"&typecode="+typecode
location=cmd;
}


function GoToDetailsFeatures()
{
var cmd="";
form=document.QuickSearchFormA;

cmd="Show_Detail_Features?wsid="+form.wsid.value;

location=cmd;//=EncodeURL(cmd);	
}

function GoToDetailsAttributes()
{
var cmd="";
form=document.QuickSearchFormA;

cmd="Show_Detail_Attributes?wsid="+form.wsid.value;

location=cmd;//=EncodeURL(cmd);	
}

function GoToHistory()
{
var cmd="";
form=document.InfoForm;

cmd="History?wsid="+form.wsid.value;

location=cmd;//=EncodeURL(cmd);
}


function GoToAbout()
{
var cmd="";
form=document.QuickSearchFormA;

cmd="About?wsid="+form.wsid.value;

location=cmd;//=EncodeURL(cmd);
}

function GoToContact()
{
var cmd="";
form=document.QuickSearchFormA;

cmd="Contact?wsid="+form.wsid.value;

location=cmd;//=EncodeURL(cmd);
}

function GoToInformation()
{
var cmd="";
form=document.QuickSearchFormA;

cmd="Information?wsid="+form.wsid.value;

location=cmd;//=EncodeURL(cmd);
}

function GoToCheckout()
{
var cmd="";

form=document.QuickSearchFormA;

cmd="Checkout?wsid="+form.wsid.value;

location=cmd;//=EncodeURL(cmd);
}

function GoToLogin()
{
var cmd="";
form=document.QuickSearchFormA;

cmd="Login?wsid="+form.wsid.value;

location=cmd;//=EncodeURL(cmd);
}


function GoToConfirmLeave()
{
var cmd="";
form=document.QuickSearchFormA;

cmd="ConfirmLeave?wsid="+form.wsid.value;

location=cmd;//=EncodeURL(cmd);	
}

function FlipSort()
{
	form=document.QuickSearchFormA;

	if( form.SortBox.value=="Descending Price" )
	{
		form.SortBox.value="Ascending Price";
		CallFlipSort();	
	}
	else
	{
		form.SortBox.value="Descending Price";
		CallFlipSort();	
	}
}


function GoToLogout()
{
var cmd="";
form=document.InfoForm;

cmd="Logout?wsid="+form.wsid.value;

location=cmd;//=EncodeURL(cmd);
}

function GoToLogoutConfirm()
{
var cmd="";
form=document.InfoForm;

var answer = confirm("Log out of this session?")
if (answer){
			cmd="Logout?wsid="+form.wsid.value;
			location=cmd;//=EncodeURL(cmd);
			}
}

function SetShipping()
{
var cmd="";
form=document.shipping;
	
cmd="SetShipping="+form.shippingmenu.options[form.shippingmenu.selectedIndex].value+"?wsid="+form.wsid.value;

location=cmd;//=EncodeURL(cmd);
}




function IncreaseItem(code)
{
var cmd="";
form=document.InfoForm;
	
cmd="IncreaseItem="+code+"?wsid="+form.wsid.value;

location=cmd;//=EncodeURL(cmd);
}


function DecreaseItem(code)
{
var cmd="";
form=document.InfoForm;
	
cmd="DecreaseItem="+code+"?wsid="+form.wsid.value;

location=cmd;//=EncodeURL(cmd);
}


function CancelItem(code)
{
var cmd="";
form=document.InfoForm;
	
cmd="CancelItem="+code+"?wsid="+form.wsid.value;

location=cmd;//=EncodeURL(cmd);
}


function GoToAccount()
{
var cmd="";
form=document.QuickSearchFormA;

cmd="AccountMenu?wsid="+form.wsid.value;

location=cmd;//=EncodeURL(cmd);
}

function DoCommand( comd )
{
var cmd="";
form=document.QuickSearchFormA;

cmd=comd+"?wsid="+form.wsid.value;

location=cmd;//=EncodeURL(cmd);
}


function GoToAccount2()
{
var cmd="";
form=document.InfoForm;

cmd="Redirect?wsid="+form.wsid.value;

location=cmd;//=EncodeURL(cmd);
}

function GoToAccount2()
{
var cmd="";
form=document.InfoForm;

cmd="Redirect?wsid="+form.wsid.value;

location=cmd;//=EncodeURL(cmd);
}


function GoToAccountNew3()
{
var cmd="";
form=document.InfoForm;

cmd="AccountNew3?wsid="+form.wsid.value;

location=cmd;//=EncodeURL(cmd);
}



function GoToAccountNew4()
{
var cmd="";
form=document.form1;

cmd="AccountNew4?wsid="+form.wsid.value;

location=cmd;
}




function LoginDetails(name,password)
{
var cmd="";
form=document.QuickSearchFormA;

cmd="LoginDetails?wsid="+form.wsid.value;

location=cmd;//=EncodeURL(cmd);

}

function LoginDetails2(name,password)
{
var cmd="";
form=document.QuickSearchFormA;

cmd="LoginDetails2?wsid="+form.wsid.value;

location=cmd;//=EncodeURL(cmd);

}

var idstring;
function SetManName()
{
form=document.QuickSearchFormA;
	
cmd="SetManName="+form.manufacturer.options[form.manufacturer.selectedIndex].value+"?wsid="+form.wsid.value;

location=cmd;

}

function GoBack()
{
	if(2)//( navigator.appName=="Netscape" )
	{
	form.submit();
	}
	else
	{
	GetLastPage();	
	}
}

var idstring;
function AddToBasket(code,numb)
{
form=document.InfoForm;
	
	if( numb<99 )
	{
		if( numb<10)
		{
		cmd="AddToBasket=0"+numb+"="+code+"?wsid="+form.wsid.value;
		}
		else
		{
		cmd="AddToBasket="+numb+"="+code+"?wsid="+form.wsid.value
		}
	}
	location=cmd;
}

function AbdToBasket(code,numb)
{
form=document.InfoForm;
	
	if( numb<99 )
	{
		if( numb<10)
		{
		cmd="AbdToBasket=0"+numb+"="+code+"?wsid="+form.wsid.value;
		}
		else
		{
		cmd="AbdToBasket="+numb+"="+code+"?wsid="+form.wsid.value
		}
	}
	location=cmd;
}

function P7_Uberlink(cl,d){
	var i,ob,tA,h=document.location.href;
	if(document.getElementById){
	ob=(d)?document.getElementById(d):document;
	if(ob){
	tA=ob.getElementsByTagName('A');
	for(i=0;i<tA.length;i++){
	if(tA[i].href==h){
	tA[i].className=cl;
}}}}}




function GetDetailwithShipping(code)
{
var cmd="";
form=document.QuickSearchFormA;

cmd="Detail="+code+"?wsid="+form.wsid.value

location=cmd;//=EncodeURL(cmd);
}

function CreateCategoriesLeft(cat)
{
	var cmd="";
	
	form=document.QuickSearchFormA;
	
	form.category.value=cat;
	form.midcategory.value="";
	form.subcategory.value="";
	form.query.value="";

	if(1)//( navigator.appName=="Netscape" )
	{
	form.submit();
	}
	else
	{
	GetList();	
	}
}

function PRange()
{
	var cmd="";
	
	form=document.QuickSearchFormA;
	
	form.category.value="";
	form.midcategory.value="";
	form.subcategory.value="";
	form.query.value="";

	if(1)//( navigator.appName=="Netscape" )
	{
	form.submit();
	}
	else
	{
	GetList();	
	}
}

function CreateSubcategoriesLeft(cat)
{
	var cmd="";
	form=document.QuickSearchFormA;
	form.query.value="";
	form.midcategory.value=cat;
	form.subcategory.value="";
	if(true) //(navigator.appName=="Netscape" )
	{
	form.submit();
	}
	else
	{
	GetList();	
	}
}

function ProductSearch(prodname)
{
	var cmd="";
	form=document.QuickSearchFormA;
	form.query.value=prodname;
	
	if(1)//( navigator.appName=="Netscape" )
	{
	form.submit();
	}
	else
	{
	GetList();	
	}
}

function stateChangedStatic() 
{ 
	if (xmlHttp.readyState==4)
	{ 
		document.getElementById("listzone").innerHTML=xmlHttp.responseText;
		
		GoogleTracker();
	}
} 

function BrowseByRoom(roomname)
{
	initAjax();

	var url="BrowseByRoom?wsid="+document.QuickSearchFormA.wsid.value;
	url=url+"&RoomName="+roomname;

	xmlHttp.onreadystatechange=stateChangedStatic;
	xmlHttp.open("GET",url,true);

	xmlHttp.send(null);
	return false;	
}

function CallStaticPage(pagename)
{
	initAjax();

	var url="AjaxStaticPage?wsid="+document.QuickSearchFormA.wsid.value;
	url=url+"&PageName="+pagename;

	xmlHttp.onreadystatechange=stateChangedStatic;
	xmlHttp.open("GET",url,true);

	xmlHttp.send(null);
	return false;	
}


function BrowseRoom( room , wsid )
{
	var url="BrowseRoom?wsid="+wsid;
	url=url+"&RoomName="+room;

	location=url;//EncodeURL(url);
}

function BrowseType( typename , wsid )
{
	var url="BrowseType?wsid="+wsid;
	
	url=url+"&TypeName="+typename;

	location=url;//EncodeURL(url);
}


function ChooseSubcategory(cat)
{
	var cmd="";
	form=document.QuickSearchFormA;
	form.query.value="";
	form.subcategory.value=cat;
	
	if(1)//( navigator.appName=="Netscape" )
	{
	form.submit();
	}
	else
	{
	GetList();
	}
}