// hcp kit order form validation


/* BEGIN FORM VALIDATION */
// Create new main array. Good for empty text fields
var txt_name = new Array() 
// Form field names is listed first followed by a descriptive name to be show in the js pop up if left blank
txt_name[0] = new Array("Clinic_Name","Clinic Name") 
txt_name[1] = new Array("Clinic_Address1","Clinic Address")
txt_name[2] = new Array("City","City") 
txt_name[3] = new Array("State","State / Province") 
txt_name[4] = new Array("Zip","Zip Code")


// email validation
function checkEmail(myForm) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(myForm)){
		return (true)
	}
	return (false)
}

// function for the blank text fields: parameter -> which array
function missing_content(){
	// alert ("missing_content array");
	
	// check the regular text fields for empty content
	var j;
	var missing_empty = "";
	// [01] CHECK THE TEXT FIELDS FROM THE ARRAY ABOVE
	for (j=0; j<txt_name.length; j++){
		// alert ("in loop");
		if (document.hcp_form[txt_name[j][0]].value == "") {
			missing_empty+= txt_name[j][1] + "\n";
			//alert (txt_name[j][0] + " " + txt_name[j][1]);
			
		}
	}
	return missing_empty;
}
// function for the value of the dropdown field
function drop_valid(drop_name) { // this will only work when the first value is set to: ""
	var d;
	var missing_drop = "";
	
	for (d=0; d<drop_name.length; d++){
		if (document.hcp_form[drop_name[d][0]].selectedIndex == ""){
			missing_drop+= drop_name[d][1] + "\n";
			
		}
	}
	return missing_drop;
}

function validation(){
	
	// full validation from the form
	var missing = "";
	// ck for blank fields
	missing = missing_content();
	
	// check the contact method
	if (document.hcp_form["Contact_Phone"].value == '' && document.hcp_form["Contact_Email"].value == ''){
		
		missing += 'Contact Information must be entered, either Phone Number or Email\n';
	}
	
	// if email is filled out, verify it is a valid email address
	if (document.hcp_form["Contact_Email"].value != ''){
		email = checkEmail (document.hcp_form["Contact_Email"].value);
		
		if (email == false){
			missing+= "Invalid Email Address\n";
		}
	}
	
	
	
	// FINALE: is anything missing?
	if (missing != ""){
		missing_hdr = "Please fill in the required information:\n";
		alert (missing_hdr + missing);
		return false;
	} else {	
		return true;
	}

}