

// ========================================================================

//  DROPDOWN MENU

// ========================================================================



	// Son of Suckerfish

	// http://www.htmldog.com/articles/suckerfish/

	

	sfHover = function() {

	  

		var nav = document.getElementById("nav");

		if(!nav) { return }

		

		var sfEls = nav.getElementsByTagName("li");

		

		for (var i=0; i<sfEls.length; i++) {

			sfEls[i].onmouseover=function() {

				this.className+=" sfhover";

			}

			sfEls[i].onmouseout=function() {

				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");

			}

		}

	}

	

	if (window.attachEvent) window.attachEvent("onload", sfHover);





// ========================================================================

//  VALIDATION FUNCTIONS

// ========================================================================



	function validateAlpha(strValue) {

	  	strValue = strValue.replace(/\s/g,"");

		return strValue.match(/^[a-zA-Z]$/);

	}



// -----------------------------------------------------------------------



	function validateLength(item, len) {

		return (item.length >= len);

	}



// -----------------------------------------------------------------------



	function validatePhone(phone) {

		phone = phone.replace(/\D/g, "");

		return phone.match(/^[0-9]{8,10}$/);

	}



// -----------------------------------------------------------------------



	function validateEmailAddress(email) {



		var emailExp;

		emailExp = new RegExp(/^(([^<>()[\]\\.,;:\s@\"\$]+(\.[^<>()[\]\\.,;:\s@\"\$]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/);



		if(!validateLength(email, 5))	return false;

		if(!emailExp.test(email))		return false;

		return true;

	}



	

// ========================================================================

//  CONTACT PAGE

// ========================================================================





	function validateContactForm() {

	  

		var isValid = true;

	  

	  	var strError = " The following fields are required:\n\n";

	  	var strErrorMessage = "";

	  	

		if (document.contactForm.first_name.value.replace(/\s/g,"").length == 0) {

			strErrorMessage = strErrorMessage + " - Please enter your first name \n";

		}

	

		if (document.contactForm.family_name.value.replace(/\s/g,"").length == 0) {

			strErrorMessage = strErrorMessage + " - Please enter your family name \n";

		}	

	

		if (document.contactForm.email.value.replace(/\s/g,"").length == 0) {

			strErrorMessage = strErrorMessage + " - Please enter your email address \n";

		} else {

			if(!validateEmailAddress(document.contactForm.email.value)) {

		   		strErrorMessage = strErrorMessage +  "  - Please ensure your email address is correct" + "\n";

			}

		}

		

		if(document.contactForm.enquiry.value.replace(/\s/g,"").length == 0) {

			strErrorMessage = strErrorMessage + "  - Please enter your enquiry or question.\n";

		}

		

		if (strErrorMessage != "") {

		  	strError = strError + strErrorMessage;

			alert(strError);

			isValid = false;

		}

		

		return isValid;

	}





// ========================================================================

//  ORDER PAGE

// ========================================================================



	// VALIDATE ORDERFORM

	function validateOrderForm() {

	  

		var isValid = true;

	  

	  	var strError = " Please correct the following fields:\n\n";

	  	var strErrorMessage = "";

	  	

		if (document.orderForm.fullname.value.replace(/\s/g,"").length == 0) {

			strErrorMessage = " - You must enter your name \n";

		}

	

		if(!validatePhone(document.orderForm.phone.value)) {

		   	strErrorMessage = strErrorMessage +  "  - Please ensure your phone contains between 8 and 11 digits" + "\n";

		}

		

		if(document.orderForm.address.value.replace(/\s/g,"").length == 0) {

			strErrorMessage = strErrorMessage + "  - Please enter your preferred postal address.\n";

		}

		

		if(document.orderForm.city.value.replace(/\s/g,"").length == 0) {

			strErrorMessage = strErrorMessage + "  - Please enter your city/suburb/town.\n";

		}

		

		if(document.orderForm.postcode.value.replace(/\s/g,"").length == 0) {

			strErrorMessage = strErrorMessage + "  - Please enter your postcode.\n";

		}



		if (strErrorMessage != "") {

		  	strError = strError + strErrorMessage;

			alert(strError);

			isValid = false;

		}

		

		return isValid;

	}





// -----------------------------------------------------------------------



	// UPDATE ORDERFORM TOTAL

	function updateOrderFormTotal() {

	  

		var orderTotal 	= 0;

		

	

	// 2005 Wines


		if(!isNaN(document.orderForm.Quantity_2005_GSM.value) && document.orderForm.Quantity_2005_GSM.value > 0) {

			orderTotal = orderTotal + (document.orderForm.Price_2005_GSM.value*document.orderForm.Quantity_2005_GSM.value);

		} 



		if(!isNaN(document.orderForm.Quantity_2005_FortShiraz.value) && document.orderForm.Quantity_2005_FortShiraz.value > 0) {

			orderTotal = orderTotal + (document.orderForm.Price_2005_FortShiraz.value*document.orderForm.Quantity_2005_FortShiraz.value);

		}



	// 2006 Wines

		
		if(!isNaN(document.orderForm.Quantity_2006_Shiraz.value) && document.orderForm.Quantity_2006_Shiraz.value > 0) {

			orderTotal = orderTotal + (document.orderForm.Price_2006_Shiraz.value*document.orderForm.Quantity_2006_Shiraz.value);

		}

	

	// 2007 Wines


		
	// 2008 Wines
		
		if(!isNaN(document.orderForm.Quantity_2008_Rose.value) && document.orderForm.Quantity_2008_Rose.value > 0) {

			orderTotal = orderTotal + (document.orderForm.Price_2008_Rose.value*document.orderForm.Quantity_2008_Rose.value);

		}
		
		if(!isNaN(document.orderForm.Quantity_2008_Riesling.value) && document.orderForm.Quantity_2008_Riesling.value > 0) {

			orderTotal = orderTotal + (document.orderForm.Price_2008_Riesling.value*document.orderForm.Quantity_2008_Riesling.value);

		}



	// Mixed Dozen



		if(!isNaN(document.orderForm.Quantity_Mixed.value) && document.orderForm.Quantity_Mixed.value > 0) {

			orderTotal = orderTotal + (document.orderForm.Price_Mixed.value*document.orderForm.Quantity_Mixed.value);

		}

		

	  	document.orderForm.total.value = orderTotal;

	}



// -----------------------------------------------------------------------

