
/////////////////////////////////////////
//--------> +-------------------------+//
// script by: *jsrebuck <-------------|//
//----------> *___vitalwebsite.com----+//
/////////////////////////////////////////

// last updated 9-7-06
// version .0918
// changes for ar

//<---main function that is called from form (when clicked)------>

function checkform() {

//<----------CONFIG VARS --------------------------->

//+-----what the form is named on page------+
page = window.document.contact_us;

//+-----length of char allowed------+
name_max = 60;
name_min = 2;
//address_max = 160;
//phone_max = 14;
phone_min = 7;
//time_max = 40;

email_max = 60;
email_min = 6;

message_max = 200;
message_min = 1;


//number of items that have to be filled
numchecked = 5;
filled = 0; 

//+--------language changes------+

//what the error box is titled
error_box = "Required Fields";

length_error = " uses too many characters.";  //****** uses too many characters
filled_error = "You must fill in a "; //You must fill in the ******* box
boxes_name = "box"; //name of the input boxes
email_error = "You must fill in a valid email address.";

thankyoumsg = "Thank you for your message.";

//what the boxes are called
name_box = "Name";
phone_box = "Telephone Number";
email_box = "Email Address";
message_box = "Comment";
company_box = "Company";
city_box = "City";
zip_box = "Zip Code";
state_box = "State";
address_box = "Address";
pref_method_box = "Prefered Method of Contact";


//<------------END CONFIG VARS --------------------->


//<-----------ADV CONFIG VARS --------------------->

//error alert box display
fullerrormsg = "\n" + error_box +":\n"; //make string
errorflag = 0; //sets alert box off until it finds an error

//get values from input boxes
full_name = document.getElementById('one').value;
company = document.getElementById('two').value;
address = document.getElementById('three').value;
//city = document.getElementById('four').value;
//state = document.getElementById('five').value;
//zip = document.getElementById('six').value;
phone = document.getElementById('seven').value;
email = document.getElementById('eight').value;
pref_method = document.getElementById('nine').value; //___not used______*
message = document.getElementById('ten').value;

pass = 'p';

//<---------- END ADV CONFIG VARS ----------------->


//<---------- MAIN PROGRAM ------------------------>

//check length of each value
//check_length( phone, phone_max, phone_box);
//check_length( call_time, time_max, "Call Time");  //___not used______*
//check_length( address, address_max, "Address"); //___not used______*

check_length( full_name, name_max, name_box);
check_length( company, name_max, company_box);
check_length( address, message_max, address_box);
//check_length( city, name_max,city_box);
//check_length( state, name_max, state_box);
//check_length( zip, name_max, zip_box);
check_length( phone, name_max, phone_box);
check_length( email, email_max, email_box);
check_length( pref_method, name_max, pref_method_box);
check_length( message, message_max, message_box);

//check if value is filled in
filled += check_fill(full_name, name_min, name_box);
filled += check_fill(phone, phone_min, phone_box);
filled += check_email(email);
filled += check_fill(pref_method, 4, pref_method_box);
filled += check_fill(message, message_min, message_box);

//submit or give full alert error message
give_results();

//<---------- END MAIN PROGRAM ----------------->


}


// <-----------helper functions--------------->//

//check to see if lenght is under max
function check_length(thing, howbig, msg) {

if ( thing.length > howbig){
fullerrormsg = fullerrormsg + "\n - "  + msg + length_error;
errorflag = 1;
	} //end if
}//emd function

//check if filled in
function check_fill( thingy, howlittle, msg){
if ( thingy.length > howlittle ){
ck = 1;
return(ck);
}else { fullerrormsg = fullerrormsg + "\n - " +  filled_error+ msg+ "."; ck=0; return(ck); 
errorflag = 1;} //end else
} //end function

//check if it is an email address
function check_email( myemail){

if( (myemail.indexOf('@') < 0) || (myemail.length < email_min) || (myemail.indexOf('.') < 0) ){
 fullerrormsg = fullerrormsg + "\n - " + email_error;
 errorflag = 1;
  return(0);
} else { return(1);} //end else
} //end function


function give_results() {

if ((errorflag == 0) && (filled == numchecked)){
  alert( thankyoumsg );
  document.getElementById(pass).value = email;
  page.submit();
}else {
	alert(fullerrormsg+"\n"); 
	} //end else
}	//end function
	









