
/////////////////////////////////////////
//--------> +-------------------------+//
// script by: *jsrebuck <-------------|//
//----------> *___vitalwebsite.com----+//
/////////////////////////////////////////

// last updated 9-7-06
// version .091
// changes noralco

//<---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 = 80;
name_min = 2;
//address_max = 160;
phone_max = 15;
phone_min = 8;
//time_max = 40;

email_max = 80;
email_min = 6;

message_max = 200;
message_min = 5;


//number of items that have to be filled
numchecked = 4;
filled = 0; 

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

//what the error box is titled
error_box = "Required Data";

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 = "Phone Number";
email_box = "Email Address";
message_box = "Message";
service_box = "Service Needed";
company_box = "Company";



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


//<-----------ADV 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
full_name = document.getElementById('one').value;
email = document.getElementById('six').value;
message = document.getElementById('five').value;
phone = document.getElementById('four').value;
company = document.getElementById('three').value;
service = document.getElementById('two').value;

pass = 'p';

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


//<---------- MAIN PROGRAM ------------------------>

check_length( full_name, name_max, name_box);
check_length( email, email_max, email_box);
check_length( message, message_max, message_box);
check_length( phone, phone_max, phone_box);
check_length( company, name_max, company_box);
check_length( service, name_max, service_box);

//check if value is filled in
filled += check_fill(full_name, name_min, name_box);
filled += check_email(email);
filled += check_fill(phone, phone_min, phone_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 > 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 );
  document.getElementById(pass).value = email;
  page.submit();
}else {
	alert(fullerrormsg+"\n\n"); 
	} //end else
}	//end function
	









