/******************************/
/*                            */
/* Check required form fields */
/*                            */
/******************************/

function checkform(frm) {
	 var Booze = false;
	 for (var i=0; i < frm.elements.length; ++i) {		 
        // Get the current field
        frm_field = frm.elements[i];        
        if ((frm_field.className.indexOf("required") > -1) && (frm_field.value == "")) {
	        alert("\"" + frm_field.name + "\" is a compulsory field.");
	        frm_field.focus();
	        return false;
        } else if ((frm_field.className.indexOf("email") > -1) && ((frm_field.className.indexOf("required") > -1) | (frm_field.value != "")) && (!isValidEmail(frm_field.value))) {
	        alert("Please enter a valid email address.");
			frm_field.focus();
			return false;	        
        } else if ((frm_field.name.indexOf("Bottle") > -1) && (frm_field.name.indexOf("Total") > -1) && (frm_field.value > 0)) {
	        Booze = true;
        }
    }
    if (!Booze) {
	    return confirm("Your selection does not include a bottle of wine.\n\nIf you would like to add a bottle to your hamper, please click Cancel to return to the order form. \n\nOtherwise, click OK to finalise your order. ");
    }
    return true;
}

function isValidEmail (daEmail) {	
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(daEmail))  return true;
	else return false;	
}