	function PostcodeLookup() {

		var PostString = document.ContactDetails.postcode.value
		var PostString = PostString.Server.URLEncode(" ","")
		
		document.location = 'https://www.hcsdirect.co.uk/basket/basket.asp?step=2&pc=' + PostString + '&hn=' + document.ContactDetails.flat.value ;
	}

	function PostcodeLookup2(URL) {

		var pcLookup;
		var pcWinAddress = URL;
		
		pcWinAddress += pcWinAddress + '?postcode=' + document.ContactDetails.postcode.value
		pcWinAddress += pcWinAddress + '&flat=' + document.ContactDetails.flat.value
		
		pcLookup = window.open(pcWinAddress,'Address found','toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=390,height=400,left = 337,top = 284');
	}

	function VerifyColour(f)
	{
		
		if(f.colour.options[f.colour.selectedIndex].value == "")
		{
			alert("Please select a colour.")
			f.colour.focus();
			return false
		}
		
	}

	

	function verify(f)
	{
		var msg;
		var empty_fields = "";
		
		if (document.ContactDetails.PostcodeLookup.value == "" && document.ContactDetails.HouseNo.value == "")
		{
			// Loop through the elements of the form, looking for all
			// text and textarea elements and if they are empty.
			for(var i = 0; i < f.length; i++)
			{
				var e = f.elements[i];
				{
					if (e.alt == "y")
	//				if ((e.name == "name") || (e.name == "position") || (e.name == "tradingname")
				//		  || (e.name == "productmaintaining") || (e.name == "workshop"))
					{
						if ((e.value == null) || (e.value == ""))
						{
							empty_fields += "\n          " + e.title;
						}
					}
				}
			}
	
			// Now, if there were errors, display a message, stating which fields are missing.
	
			if(!empty_fields)
			{
				return true;
				document.ContactDetails.submit();
			}
			
			msg = "____________________________________________\n\n"
			msg += "   The form was not submitted, because the following\n";
			msg += "   field(s) are required:\n";
			msg += "___________________________________________\n"
		
		
			if (empty_fields)
			{
				msg += empty_fields + "\n";
			}
			
			alert(msg);
			return false;
		}
	}
	
	function CheckEmail(e)
	{
		var noAt = e.indexOf("@");
		
		// Now, if there were errors, display a message, stating which fields are missing.

		if(noAt != -1) return true;
		
		alert('Incorrect email format. Please add "@".');
		return false;
	}

	function CheckPostCode(e)
	{
		var gotSpace = e.indexOf(" ");
		
		// Now, if there were errors, display a message, stating which fields are missing.

		if(gotSpace != -1) return true;
		
		alert('Incorrect postcode. Please add a space.');
		return false;
	}

	function RefineTopSearch(DropObject)
	{

		var LocItems = DropObject.value.split("~");
		var LocationString = "http://www.hcsdirect.co.uk/Products"; //mk=" + escape(LocItems[0]);
		
		if(LocItems != '')
		{
			LocationString = LocationString + "/";
		}
		
		for(var i = 0; i < LocItems.length; i++)
		{
			LocationString = LocationString + escape(LocItems[i]) + "/";
		}
		document.location = LocationString ;
			
	}



function ValidateQuantity(field)
{
   if(IsEmpty(field)) 
   { 
      alert('Please enter a quantity.') 
      field.focus(); 
      return false; 
   } 
 
 
   if (!IsNumeric(field.value)) 
   { 
      alert('Only numbers are allowed for this field.') 
      field.focus(); 
      return false; 
      } 
 
return true;
 
} 

function ValidatePriceField(field)
{

   if (!IsNumeric(field.value)) 
   { 
      alert('Only numbers are allowed for this field.') 
      field.focus(); 
      return false; 
      } 
 
return true;
 
} 


function IsEmpty(aTextField)
{
   if ((aTextField.value.length==0) || (aTextField.value==null))
   {
    	return true;
   }
   else
   {
   	return false;
	}
}	

function IsNumeric(TxtFld)
	{
		var ValidChars = "0123456789";
	   	var IsNumber=true;
   		var Char;

 		for (i = 0; i < TxtFld.length && IsNumber == true; i++) 
      	{ 
			Char = TxtFld.charAt(i); 
			if (ValidChars.indexOf(Char) == -1) 
         	{
         		IsNumber = false;
         	}
      	}
		return IsNumber;
	}
	
function UpdateDelivery(CostValue)
{
	location = 'https://www.hcsdirect.co.uk/basket/basket.asp?del=' + CostValue;
}

function SendOffProductPage(WhichForm,WhichItem,WhichContent)
	{
		var FormName = "ProductPageForm" + WhichForm;
		
		if(WhichItem == 'Sort')
		{
			document.forms[FormName].s.value = WhichContent;
		}
		else if(WhichItem == 'Rec')
		{
			document.forms[FormName].rec.value = WhichContent;
		}
		else
		{
			document.forms[FormName].pg.value = WhichContent;
		}
		
		document.forms[FormName].submit();
	}

function SendMultiple(WkDesc,WkQty,WkPrice)
{
		
		document.orderitem.MultipleDescription.value = WkDesc;
		document.orderitem.Multiple.value = WkQty;
		document.orderitem.price.value = WkPrice;
		document.orderitem.submit();	
		
}

	function openWindowCentered(mypage,myname,w,h,features) 
	{
		if(screen.width)
		{
			var winl = (screen.width-w)/2;
			var wint = (screen.height-h)/2;
		}
		else
		{	winl = 0;wint =0;	}
		
		if (winl < 0) winl = 0;
		if (wint < 0) wint = 0;
		var settings = 'height=' + h + ',';
		settings += 'width=' + w + ',';
		settings += 'top=' + wint + ',';
		settings += 'left=' + winl + ',';
		settings += features;
		win = window.open(mypage,myname,settings);
		win.window.focus();
}

