// 

// Field Validations for the Request Quote, Free Evaluation, and Contact Us forms
function chkextns (str) {
	var bad_val = "";
	
	var extnsn = new Array(4)
		extnsn[0] = ".doc"
		extnsn[1] = ".txt"
		extnsn[2] = ".pdf"
		extnsn[3] = ".docx"
	
	for (var i = 0; i < extnsn.length; i++) {
		bad_val = extnsn[i];
		/// alert(bad_val);
		this_result = str.search(bad_val);
		// alert (this_result);
					// returns -1 if value not found
		if (this_result > -1) {
			return this_result
		}
	}
	return this_result
}
////////////////////////////////////////////////////////////////////////////////////////////
function checkfrm() {
	var f = document.inquiryfrm;
	var badCount = 0;
	var msg = "";
	var a_period = "."; 
	var str ="";
	

	f.recipients.value="beverly@harveycareers.com";
	
	// f.recipients.value="karen@adventuresonline.com";
	
// Name	
	tmp = f.name.value;
	if (tmp.length < 5) {
		msg = msg + "\nEnter your Full Name";
		badCount = badCount + 1;
	}
	
// Phone	
	tmp = f.phone.value;
	if (tmp.length < 10) {
		msg = msg + "\nEnter a valid Phone Number";
		badCount = badCount + 1;
	}
	
if (f.f_id.value != "contact") {	
// Best Day
	tmp = f.best_day.value;
	if (tmp.length < 3) {
		msg = msg + "\nEnter the Best Day";
		badCount = badCount + 1;
	}
	
// Best Time
	tmp = f.best_time.value;
	if (tmp.length < 3) {
		msg = msg + "\nEnter the Best Time";
		badCount = badCount + 1;
	}
	
// Time Zone
	tmp = f.time_zone.value;
	if (tmp.length < 3) {
		msg = msg + "\nEnter your Time Zone";
		badCount = badCount + 1;
	}	

} // end of if it is not the contact form


//E-mail
	var goodchars = 0;
    if (f.email.value == "") {
		badCount = badCount + 1;
		msg = msg + "\nEnter your E-mail address.";
	}
	
	if (f.email.value != "") {
   		inputVal = f.email.value;
   		inputStr = inputVal.toString()
    
   		for (var i = 0; i < inputStr.length; i++) { 
      		var oneChar = inputStr.charAt(i) 
      		if (oneChar == "." || oneChar == "@") { 
         		goodchars = goodchars + 1;
      		}  
   		}
		
		if (goodchars <2) {
   			badCount = badCount + 1;
			msg = msg + "\nEnter a valid E-mail address.";
		}
	}
	
if (f.f_id.value == "contact") {	
	f.good_url.value = "contact-harvey-careers-thanks.html";
	f.subject.value="Contact Harvey Careers Inquiry";
	f.mail_options.value = "PlainTemplate=contact.txt,TemplateMissing=No_Entry";
	
	// if it is not the contact us form, check for a Resume upload
	
} else {
	tmpval = f.hc_file.value;
	if (f.f_id.value == "evaluation") {
	 	f.good_url.value = "resume-evaluation-thanks.html";
		f.subject.value="Resume Evaluation";
		f.mail_options.value = "PlainTemplate=evaluation.txt,TemplateMissing=No_Entry";
	 
	 	// validate resume uploaded	
		if (tmpval.length < 7) {
			msg = msg + "\nName of resume file is too short. Must be at least 7 characters";
			badCount = badCount + 1;
		} else {
			 str = tmpval.substring(tmpval.length,tmpval.length-5);	// .docx
			 if (str.substring(0,1) != a_period) {
				 // alert(str);		// g.oc for example
				  str = tmpval.substring(tmpval.length,tmpval.length-4);	//.doc, .txt,.pdf 
				 // alert(str);
			 }
			 str = str.toLowerCase();
			 // alert (str);
			 tmp = chkextns(str);
			// alert (tmp);
			if (tmp == -1) {
				badCount = badCount + 1;
				msg = msg + "\nResume does not have correct naming format.";
			}
		}
	 } else { 
	 	f.good_url.value = "request-quote-thanks.html";
		f.subject.value="Request a Quote";
		f.mail_options.value = "PlainTemplate=quote.txt,TemplateMissing=No_Entry";
	 	if (tmpval.length >0) {
			str = tmpval.substring(tmpval.length,tmpval.length-5);	// .docx
			if (str.substring(0,1) != a_period) {
				 // alert(str);		// g.oc for example
				str = tmpval.substring(tmpval.length,tmpval.length-4);	//.doc, .txt,.pdf 
				 // alert(str);
			 }
		  	str = str.toLowerCase();
		  	// alert (str);
		 	tmp = chkextns(str);
			// alert (tmp);
			if (tmp == -1) {
				badCount = badCount + 1;
				msg = msg + "\nResume does not have correct naming format.";
			}
		}
	}
}
	if (badCount == 0) {
    	return true;
    } else {
		alert (msg);
		return false;
	}
}