function StandardOnLoad()
{
	if (document.getElementById)
	{		  
		/* Associate logo's onclick event with home page */
		var logo = document.getElementById("logo");
 		if (logo != null) {
			logo.onclick = function() {
				window.location = 'index.php';
				return false;
			}
		}
		
		var menu = document.getElementById("topmenu");
 		if (menu != null) 
		{
			var lis = menu.getElementsByTagName("li");
			for(aliindex=0;aliindex<lis.length;aliindex++)
			{
				if(lis[aliindex].className=='level1')
				{
					lis[aliindex].onclick = JSFnMenuLiClick;
					
					lis[aliindex].onmouseover = JSFnMenuLiOver;
					lis[aliindex].onmouseout = JSFnMenuLiOut;
				}
			}
		}		

		var aContactForm = document.getElementById('contactform');
		if (aContactForm != null) aContactForm.onsubmit = JSFnValidateContactForm;

		var aEbulletinForm = document.getElementById('Ebulletin');
		if (aEbulletinForm != null) aEbulletinForm.onsubmit = JSFnValidateEbulletinForm;

		var aMobileForm = document.getElementById('mobileform');
		if (aMobileForm != null) aMobileForm.onsubmit = JSFnValidateMobileForm;
		
		var aImageZoom = document.getElementById('productlink');
		if (aImageZoom != null) aImageZoom.onclick = JSFnImageZoom;
		
		var aCheckoutForm = document.getElementById('checkoutform');
		if (aCheckoutForm != null) aCheckoutForm.onsubmit = JSFnValidateCheckout;
		
		var aDeliveryForm = document.getElementById('deliveryinformation');
		if (aDeliveryForm != null) aDeliveryForm.onsubmit = JSFnValidateDelivery;		

		var aUserLoginForm = document.getElementById('UserLoginForm');
		if (aUserLoginForm != null) aUserLoginForm.onsubmit = JSFnValidateUserLoginForm;

		var aUserRegistrationForm = document.getElementById('UserRegistrationForm');
		if (aUserRegistrationForm != null) aUserRegistrationForm.onsubmit = JSFnValidateUserRegistrationForm;

		var aUserForm = document.getElementById('UserForm');
		if (aUserForm != null) aUserForm.onsubmit = JSFnValidateUserForm;
	}
}

function JSFnMenuLiOver()
{
	this.className = 'level1 hover';
}

function JSFnMenuLiOut()
{
	this.className = 'level1';
}

function JSFnMenuLiClick()
{
	window.location = this.childNodes[0].href;
	//alert(this.childNodes[0]);
}

function JSFnGoBack()
{
	history.go(-1);
}

function JSFnImageZoom()
{
	var aWindow = window.open(this.href, 'productbig', 'scrollbars=yes, menubar=no, resizeable=no, toolbar=no, width=600px, height=800px')
	aWindow.focus();
	return false;
}
/************************************************************************************************************************************/

/* User Registration Required Fields */
var aUserRegistrationRequiredFields = new Array ("FirstName","Please enter your first name to continue",
		 									 	 "Surname","Please enter a surname to continue",
		 									 	 "CompanyName","Please enter a company name to continue",
		 									 	 "EmailAddress","Please enter an email address to continue",
		 									 	 "TelephoneNo","Please enter a telephone no. to continue",
		 									 	 "DeliveryAddressLine1","Please enter address line 1 to continue",
		 									 	 "DeliveryAddressLine4","Please enter a town to continue",
		 									 	 "DeliveryAddressLine5","Please enter a county to continue",
		 									 	 "DeliveryPostCode","Please enter a postcode to continue",
		 									 	 "Username","Please enter a username to continue",
										 		 "Password","Please enter a password to continue",
										 		 "PasswordRepeat","Please repeat password to continue");
/* User Registration Form Validation */
function JSFnValidateUserRegistrationForm()
{
	if (this.Password.value.length < 6)
	{
		alert("Please enter at least 6 characters in the \"Password\" field.");
		this.Password.focus();
		return (false);
	}
	
	// check if both password fields are the same
	if (this.Password.value != this.PasswordRepeat.value)
	{
		alert("The two passwords are not the same.");
		this.PasswordRepeat.focus();
		return (false);
	}
	
	return JSFnValidateForm(aUserRegistrationRequiredFields);
}
/************************************************************************************************************************************/

/* User Registration Required Fields */
var aUserRequiredFields = new Array ("FirstName","Please enter your first name to continue",
		 									 	 "Surname","Please enter a surname to continue",
		 									 	 "CompanyName","Please enter a company name to continue",
		 									 	 "EmailAddress","Please enter an email address to continue",
		 									 	 "TelephoneNo","Please enter a telephone no. to continue",
		 									 	 "DeliveryAddressLine1","Please enter address line 1 to continue",
		 									 	 "DeliveryAddressLine4","Please enter a town to continue",
		 									 	 "DeliveryAddressLine5","Please enter a county to continue",
		 									 	 "DeliveryPostCode","Please enter a postcode to continue",
		 									 	 "Username","Please enter a username to continue");
/* User Registration Form Validation */
function JSFnValidateUserForm()
{
	return JSFnValidateForm(aUserRequiredFields);
}
/************************************************************************************************************************************/

/* User Login Required Fields */
var aUserLoginRequiredFields = new Array ("Username","Please enter a username to continue",
									 	  "Password","Please enter a password to continue");
/* User Login Form Validation */
function JSFnValidateUserLoginForm()
{
	return JSFnValidateForm(aUserLoginRequiredFields);
}
/************************************************************************************************************************************/

/* Mobile Required Fields */
var aMobileRequiredFields = new Array ("FullName","Please enter your name to continue",
									   "CompanyName","Please enter your company name to continue",
									   "TelephoneNo","Please enter your telephone number to continue",
									   "EmailAddress","Please enter your email address to continue",
									   "MobilePhoneNo","Please enter the number of mobile handsets ready for dispatch to continue");
/* Mobile Form Validation */
function JSFnValidateMobileForm()
{
	return JSFnValidateForm(aMobileRequiredFields);
}
/************************************************************************************************************************************/
/* Ebulletin Required Fields */
var aEbulletinRequiredFields = new Array ("FullName","Please enter your name to continue",
									   "CompanyName","Please enter your company name to continue",
									   "EmailAddress","Please enter your email address to continue");
/* Ebulletin Form Validation */
function JSFnValidateEbulletinForm()
{
	return JSFnValidateForm(aEbulletinRequiredFields);
}
/************************************************************************************************************************************/

var aContactRequiredFields = new Array ("FullName","Please enter your name to continue");

function JSFnValidateContactForm()
{
	var aEmail = document.getElementById('EmailAddress');
	var aTelephone = document.getElementById('TelephoneNo');
	var aMobile = document.getElementById('MobileNo');
	if ((aEmail != null) && (aTelephone != null) && (aMobile != null))
	{
		if ((aEmail.value == '') && (aTelephone.value == '') && (aMobile.value == ''))
		{
			alert('You must provide either your telephone/mobile number or email address to continue.');
			return false;
		}
	}

	return JSFnValidateForm(aContactRequiredFields);
}
/************************************************************************************************************************************/

CheckoutRequiredFields = new Array ("terms","You must tick to say that you agree to our terms and conditions in order to checkout.",
									"privacy","You must tick to say that you have read our privacy policy in order to continue.");
function JSFnValidateCheckout()
{
	return JSFnValidateForm(CheckoutRequiredFields);
}

DeliveryRequiredFields = new Array ("CustomerName","You must enter your name to continue.",
//									"CompanyName","You must enter your company name to continue.",
									"DeliveryAddressLine1","You must enter the first line of your delivery address to continue.",
									"DeliveryAddressLine4","You must enter your delivery city/town to continue.",
									"DeliveryPostCode","You must enter your delivery postcode to continue.",
									"CustomerEmail","You must enter your email address to continue.",
									"ContactNumber","You must enter a contact number to continue.");

DeliveryBillingRequiredFields = new Array ("BillingName","You must enter your billing name to continue.",									   
//		 								   "BillingCompanyName","You must enter your billing company name to continue.",
										   "BillingAddressLine1","You must enter the first line of your billing address to continue.",
										   "BillingAddressLine4","You must enter your billing city/town to continue.",
										   "BillingPostCode","You must enter your billing postcode to continue.");

function JSFnValidateDelivery()
{
	aResult = JSFnValidateForm(DeliveryRequiredFields);

	if (aResult != false)
	{
/*		var aBillingFirstName = document.getElementById('BillingName');
		var aBillingAddress = document.getElementById('BillingAddressLine1');
		var aBillingCity = document.getElementById('BillingAddressLine4');
		var aBillingPostcode = document.getElementById('BillingPostcode');
		if ((aBillingFirstName.value != '') || (aBillingAddress.value != '') || (aBillingCity.value != '') || (aBillingPostcode.value != ''))
		{*/
/*			aResult = JSFnValidateForm(DeliveryBillingRequiredFields);	 */
		/*}*/
	}

	if (aResult != false)
	{
		aResult = JSFnValidateCheckout(CheckoutRequiredFields);	
	}

	return aResult;
}

function JSFnValidateForm(aRequiredFields)
{
	for (aIndex = 0; aIndex < aRequiredFields.length; aIndex = aIndex + 2)
	{
		currElement = document.getElementById(aRequiredFields[aIndex]);
		if (currElement != null)
		{
			if  (   (   (currElement.type == 'text')
				     && (currElement.value == ''))
				 || (   (currElement.type == 'password')
				     && (currElement.value == ''))
				 || (   (currElement.type == 'checkbox')
				     && (currElement.checked == false))
				 || (   (currElement.type == 'file')
				     && (currElement.value == ''))
				 || (   (currElement.type == 'textarea')
				     && (currElement.value == ''))
				 || (   (currElement.type == 'select-one')
				     && (currElement.value == '')))
			{
				alert(aRequiredFields[aIndex + 1]);
				return false;
			}
			else if (currElement.type == 'radio')
			{
				aIndex = aIndex + 2;
				if (!currElement.checked)
				{
					currElement = document.getElementById(aRequiredFields[aIndex]);
					if ((currElement.type == 'radio') && (!currElement.checked))
					{
						alert(aRequiredFields[aIndex + 1]);
						return false;
					}
				}
			}
		}
	}
	return true;
}