
/////////////////////////////////////////
//--------> +-------------------------+//
// script by: *jsrebuck <-------------|//
//--------------> *___vitalweb.net----+//
/////////////////////////////////////////

// last updated 6-7-06

//<---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------+
contact_max = 60;
contact_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 = 5;

//+--------language changes------+

//what the error box is titled
error_box = "FORM CORRECTIONS";

length_error = " uses too many characters.";  //****** uses too many characters
filled_error = "You must fill in the "; //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 = "Message";



//<------------END CONFIG VARS --------------------->

//error alert box display
fullerrormsg = "\n" + error_box +":\n\n"; //make string
errorflag = 0; //sets alert box off until it finds an error

//get values from input boxes
contact = page.contact.value;
phone = page.phone.value;
//call_time = page.call_time.value; //___not used______*
//address = page.address.value; //___not used______*
email = page.email.value;
message = page.message.value;


//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( contact, contact_max, name_box);
check_length( email, email_max, email_box);
check_length( message, message_max, message_box);

//check if value is filled in
name_check = check_fill(contact, contact_min, name_box);
valid_email = check_email(email);
message_check = check_fill(message, message_min, message_box);

numchecked = 3; //number of values checked if filled in
filled = name_check + valid_email + message_check; //add values if filled in


//submit or give full alert error message
give_results();

}


// <-----------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 > 0 ){
ck = 1;
return(ck);
}else { fullerrormsg = fullerrormsg + "\n - " +  filled_error+ msg+ " "+boxes_name+ "."; 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 );
  page.pass.value = "yes";
  page.submit();
}else {
	alert(fullerrormsg+"\n\n"); 
	} //end else
}	//end function
	








