// JavaScript Document
// JavaScript Document
var warning_color = "#FFCCCC";
var normal_color = "#EEEEEE";
// 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("name","Your Name")


// check for blank text fields
function missing_content(){
	// 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++){
		if (document.contact[txt_name[j][0]].value == "") {
			missing_empty+= txt_name[j][1] + "\n";
			document.contact[txt_name[j][0]].style.backgroundColor = warning_color;
		} else {
			document.contact[txt_name[j][0]].style.backgroundColor = normal_color;
		}
	}
	return missing_empty;
}

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



function validation(){
	var missing = "";
	// ck for blank fields
	missing = missing_content();

	

	// ck and validate the email address
	email = checkEmail (document.contact["email"].value);
	
	if (email == false){
		missing+= "Invalid Email Address\n";
		document.contact["email"].style.backgroundColor = warning_color;
	} else {
		document.contact["email"].style.backgroundColor = normal_color;
	}
	// FINALE: is anything missing?
	if (missing != ""){
		missing_hdr = "Please fill in the required information:\n";
		alert (missing_hdr + missing);
		return false;
	} else {	
		return true;
	}
}
