// Contact us form validation script

function strip_lspaces(element){
		if (element != ""){
			while('' + element.charAt(0) == ' '){
				element = element.substring(1,element.length);
			}
		}
		return element;
	}
		
	function validate(field, type){
	
		var  valid = " ( ) -0123456789"
		var rs = ""
		if (type == "phone"){ valid = valid  + (rs = "")}
		if (type == "mobile"){ valid = valid  + (rs = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ) (-")}                                                                       if (type == "date"){ valid = valid  + (rs = "/")}                                           
		if (type == "zip"){ valid = valid  + (rs = "() ")}
		if (rs != ""){rs = "and ' " + rs + " '"} 
			var msg = "and "+ valid
			var ok = "yes";
			var temp;
		if (type == "email"){ 
			if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(field.value)){                                                                     
				return "Invalid E-mail Address! Please re-enter ";
			}else{
				return "Valid!!";
		  	}
		}
		for (var i=0; i<field.value.length; i++) {
			temp = "" + field.value.substring(i, i+1);
			if (valid.indexOf(temp) == "-1") ok = "no";
		}
		if (ok == "no") {
			return "Invalid entry! Only numbers "+ rs +" are accepted ";
		}
		return "Valid!!";
	}
function ChkVal(){
	  	var v_fname			= strip_lspaces(document.frmfeedback.fname.value); 
		var v_email			= strip_lspaces(document.frmfeedback.email.value); 
		var v_phone			= strip_lspaces(document.frmfeedback.phone.value); 
		var v_msg			= strip_lspaces(document.frmfeedback.comments.value); 
		var v_subject       = strip_lspaces(document.frmfeedback.subject.value);
		var v_message = "";
		var n_errorcount = 0;
		v_message = "Please check the following information: \n\n";
		
		if(v_subject == "") {
		      n_errorcount = n_errorcount + 1;
			  v_message = v_message + "(" + n_errorcount + ")" + " Please enter the Subject\n";  
		}   		
		if (v_fname == ""){
			 n_errorcount = n_errorcount + 1;
			 v_message =v_message + " (" + n_errorcount + ") " + " Please enter your Name\n";
		}
		if (v_email == ""){
			 n_errorcount = n_errorcount + 1;
			 v_message =v_message + " (" + n_errorcount + ") " + " Please enter your Email\n";
		}

		if (v_email != ""){
			valid_email = validate(document.frmfeedback.email, "email");
			if (valid_email != "Valid!!"){
				n_errorcount = n_errorcount + 1;
				v_message =v_message + " (" + n_errorcount + ") " + valid_email + " for Email \n";
			}
		}
		if (v_phone == ""){
			 n_errorcount = n_errorcount + 1;
			 v_message =v_message + " (" + n_errorcount + ") " + " Please enter your Phone number\n";
		}

		if (v_phone != ""){
			valid_email = validate(document.frmfeedback.phone, "phone");
			if (valid_email != "Valid!!"){
				n_errorcount = n_errorcount + 1;
				v_message =v_message + " (" + n_errorcount + ") " + valid_email + " for Phone \n";
			}
		}
		if (v_msg == ""){
			 n_errorcount = n_errorcount + 1;
			 v_message =v_message + " (" + n_errorcount + ") " + " Please enter your Comments\n";
		}
		
		if (n_errorcount == 0){
			return true;			
		}else{
			alert (v_message);
			return false;
		}

}