
function PopUp(theURL,winName,features) {
	window.open(theURL,winName,features);
}

function ToggleItem(myItem) {
	if (myItem.style.visibility != 'hidden') {
		HideItem(myItem);
	} else {
		ShowItem(myItem);
	}
	return false;
}
function ShowItem(myItem) {
	myItem.style.visibility = 'visible';
	myItem.style.display = '';
}
function HideItem(myItem) {
	myItem.style.visibility = 'hidden';
	myItem.style.display = 'none';
}


function CheckPurchaseOrder(GatewayTrue)
{
	if (document.CheckOutForm.O_PurchaseOrderNo)
		{
			if( GatewayTrue="True" &&  document.CheckOutForm.O_PurchaseOrderNo.value=="")
			{
				alert("Please enter a Purchase Order Number");
				document.CheckOutForm.O_PurchaseOrderNo.focus();
				return false;
			}
	}

		if(document.CheckOutForm.InvoiceAddress.value=="")
	{
			{
				alert("Please select an Invoice Address from the list");
				document.CheckOutForm.InvoiceAddress.focus();
				return false;
			}
	}

		if(document.CheckOutForm.DeliveryAddress.value=="")
	{
			{
				alert("Please select a Delivery Address from the list");
				document.CheckOutForm.DeliveryAddress.focus();
				return false;
			}
	}

	if (document.CheckOutForm.C_Card_BuildingNumber)
	{
	
		if(document.CheckOutForm.C_Card_BuildingNumber.value =="")
			{
				alert("Please enter the Credit Card Postcode")
				document.CheckOutForm.C_Card_BuildingNumber.focus();
				return false;
			}
	}

return true;
}


function ProcessContact(theForm) 
{
	Name=theForm.strContactName.value
	Address1=theForm.strContactAddress1.value
	Address2=theForm.strContactAddress2.value
	Postcode=theForm.strContactPostcode.value
	Email=theForm.strContactEmail.value
	//** Check the form
	if(Name=="")
	{
		alert("Please enter your Name");
		theForm.strContactName.focus();
		return false;
	}
	if(Name.length<5)
	{
		alert("Please enter at least 5 characters in the Name field");
		theForm.strContactName.focus();
		return false;
	}
	if(Email=="")
	{
		alert("Please enter your Email Address");
		theForm.strContactEmail.focus();
		return false;
	}
	return echeck(Email, theForm);
	if(Address1=="")
	{
		alert("Please enter the first line of your address");
		theForm.strContactAddress1.focus();
		return false;
	}
	if(Address1.length<5)
	{
		alert("Please at least 5 characters in the first line of your address");
		theForm.strContactAddress1.focus();
		return false;
	}	
	if(Address2=="")
	{
		alert("Please enter the second line of your address");
		theForm.strContactAddress2.focus();
		return false;
	}
	if(Address2.length<5)
	{
		alert("Please at least 5 characters in the second line of your address");
		theForm.strContactAddress2.focus();
		return false;
	}
		if(Postcode=="")
	{
		alert("Please enter your post code");
		theForm.strContactPotcode.focus();
		return false;
	}
	if(Address2.length<3)
	{
		alert("Please at least 3 characters in your post code");
		theForm.strContactPotcode.focus();
		return false;
	}
return true;	
}

function echeck(str, theForm) {
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Please enter a valid email address");
		   theForm.strContactEmail.focus();
		   return false;
		}
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Please enter a valid email address");
		   theForm.strContactEmail.focus();
		   return false;
		}
		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Please enter a valid email address");
			theForm.strContactEmail.focus();
		    return false;
		}
		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Please enter a valid email address");
		    theForm.strContactEmail.focus();
		    return false;
		 }
		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Please enter a valid email address");
		    theForm.strContactEmail.focus();
		    return false;
		 }
		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Please enter a valid email address");
		    theForm.strContactEmail.focus();
			return false;
		 }
	
		 if (str.indexOf(" ")!=-1){
		    alert("Please enter a valid email address");
		    theForm.strContactEmail.focus();
		    return false;
		 }
 		 return true;			
	}
	
// Limit Text area character amounts
function imposeMaxLength(Object, MaxLen)
{
  return (Object.value.length <= MaxLen);
}
//Checks that an imput value is a number
function checkValueIsNumeric(frmItm){
	var theValue  = frmItm.value
	if(theValue.length == 0){
		alert('You must enter a numeric value to order this product')
		frmItm.focus()
		return false
	}
	if(isNaN(theValue)){
		alert('The value you entered is not numeric.\nYou may only enter character 0-9')
		frmItm.value = ""
		frmItm.focus()
		return false
	}
return true;	
}

function CheckSpeedOrder(LineCount)
{
	for (var x = 1; x <= LineCount; x++)
	{
		GetProdCode=document.forms['speedorder'].elements['strCode'+x].value;
		GetQuant=document.forms['speedorder'].elements['numQuant'+x].value;
		if(GetProdCode!="" && GetQuant=="")
		{
			alert("Please enter a quantity for Product Code "+GetProdCode);

			document.forms['speedorder'].elements['numQuant'+x].focus()	
			return false
		}
		if(GetQuant!="" && GetProdCode=="")
		{
			alert("Please enter a Product Code on line " + x);
			document.forms['speedorder'].elements['strCode'+x].focus();
			return false
		}
	}
	// Now check to see if they've put anything in any of the fields - if not
	// don't submit the form
	blankCount = 0
	for (var x = 1; x <= LineCount; x++)
	{
		GetProdCode=document.forms['speedorder'].elements['strCode'+x].value;
		if(GetProdCode=="")
			{
				blankCount++
			}
	}		

		if(blankCount == LineCount)
		{
			alert("Please enter at least one product code");
			document.forms['speedorder'].elements['strCode1'].focus();
			return false;
		}
return true;		
}

function checkSearchKeyword(frm){
	var itm = frm.strKeywords
	if (itm.value.length == 0){
		alert('You must enter a keyword to search on');
		itm.focus();
		return false;
	}
return true;	
}