function isValidCheckout1() {
	var form=document.checkout1, msg="", status=true;	
	if (form.CustomerName.value == "") { msg += "\nEmpty Name"; form.CustomerName.focus(); form.CustomerName.className = "alert"; status=false; } else form.CustomerName.className = ""
	if (!CheckEmail(form.CustomerEMail.value)) {msg += "\nInvalid Email Address"; form.CustomerEMail.focus(); form.CustomerEMail.className = "alert"; status=false; } else form.CustomerEMail.className = ""
	if (form.ContactNumber.value == "") { msg += "\nEmpty Contact Number"; form.ContactNumber.focus(); form.ContactNumber.className = "alert"; status=false; } else form.ContactNumber.className = ""

	if (form.BillingAddress.value == "") { msg += "\nEmpty Billing Address"; form.BillingAddress.focus(); form.BillingAddress.className = "alert"; status=false; } else form.BillingAddress.className = ""
	if (form.BillingPostCode.value == "") { msg += "\nEmpty Billing Zip Code / Post Code"; form.BillingPostCode.focus(); form.BillingPostCode.className = "alert"; status=false; } else form.BillingPostCode.className = ""
	if (form.BillingCountry.value == "") { msg += "\nEmpty Billing Country"; form.BillingCountry.focus(); form.BillingCountry.className = "alert"; status=false; } else form.BillingCountry.className = ""

	if (form.UseDelv[1].checked) {
		if (form.DeliveryAddress.value == "") { msg += "\nEmpty Delivery Address"; form.DeliveryAddress.focus(); form.DeliveryAddress.className = "alert"; status=false; } else form.DeliveryAddress.className = ""
		if (form.DeliveryPostCode.value == "") { msg += "\nEmpty Delivery Zip Code / Post Code"; form.DeliveryPostCode.focus(); form.DeliveryPostCode.className = "alert"; status=false; } else form.DeliveryPostCode.className = ""
		if (form.DeliveryCountry.value == "") { msg += "\nEmpty Delivery Country"; form.DeliveryCountry.focus(); form.DeliveryCountry.className = "alert"; status=false; } else form.DeliveryCountry.className = ""
	}

	if (status) {
		return true;
	} else {
		if (msg != "") alert ("You need to correct the following before you can proceed:\n" + msg);
		return false;
	}
}

function isValidProtxForm() {
	var form=document.protxForm, msg="", status=true;	
	if (form.CardHolder.value == "") { msg += "\nEmpty Cardholder Name"; form.CardHolder.focus(); form.CardHolder.className = "alert"; status=false; } else form.CardHolder.className = ""
	if (form.CardNumber.value == "") { msg += "\nEmpty Card Number"; form.CardNumber.focus(); form.CardNumber.className = "alert"; status=false; } else form.CardNumber.className = ""
	if (form.CV2.value == "") { msg += "\nEmpty CVV Value"; form.CV2.focus(); form.CV2.className = "alert"; status=false; } else form.CV2.className = ""

	if (status) {
		return true;
	} else {
		if (msg != "") alert ("You need to correct the following before you can proceed:\n" + msg);
		return false;
	}
}

function isValidForm(n) {
	if (n == 1) {
		var form=document.contact, msg="", status=true;	

		if (form.name.value == "") { msg += "\nEmpty Name"; form.name.focus(); status=false; }
		if (form.telephone.value == "") { msg += "\nEmpty Telephone Number"; form.telephone.focus(); status=false; }
		if (form.email.value == "") { msg += "\nEmpty Email Address"; form.email.focus(); status=false; }
	}
	
	if (n == 2) {
		var form=document.quote, msg="", status=true;	

		if (form.name.value == "") { msg += "\nEmpty Name"; form.name.focus(); status=false; }
		if (form.telephone.value == "") { msg += "\nEmpty Telephone Number"; form.telephone.focus(); status=false; }
		if (form.email.value == "") { msg += "\nEmpty Email Address"; form.email.focus(); status=false; }
	}

	if (n == 3) {
		var form=document.newsletter, msg="", status=true;	

		if (form.name.value == "") { msg += "\nEmpty Name"; form.name.focus(); status=false; }
		if (form.email.value == "") { msg += "\nEmpty Email Address"; form.email.focus(); status=false; }
	}

	if (status) {
		return true;
	} else {
		if (msg != "") alert ("Please correct the following before you continue: \n" + msg);
		return false;
	}
}

function processForm(n) {
	switch(n) {
		case "protx":
			var valid = isValidProtxForm();
			if (valid)
				document.protxForm.submit();
			break    
		case "checkout":
			var valid = isValidCheckout1();
			if (valid)
				document.checkout1.submit();
			break    
		case "mail":
			var valid = isValidMailForm();
			if (valid)
				document.webcontact.submit();
			break    
		case 1:
			var valid = isValidForm(n);
			if (valid)
				document.contact.submit();
			break    
		case 2:
			var valid = isValidForm(n);
			if (valid)
				document.quote.submit();
			break    
		case 3:
			var valid = isValidForm(n);
			if (valid)
				document.newsletter.submit();
			break    
		default:
	}
}

function CheckEmail(email) {
	AtPos = email.indexOf("@")
	StopPos = email.lastIndexOf(".")
	Message = ""

	if (email == "") {
		return false;
	}

	if (AtPos == -1 || StopPos == -1) {
		return false;
	}

	if (StopPos < AtPos) {
		return false;
	}

	if (StopPos - AtPos == 1) {
		return false;
	}

	return true;
}
