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

// last updated 7-19-07
// version .0931
//changes for MLRCF

//<---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;
co_name = "Sharon Battle Travel ";

//+-----input you are using------+
full_name = page.one.value;
phone = page.two.value;
message= page.four.value;
email = page.three.value;

//number of items that have to be filled
numchecked = 3; //number of input boxes that have to be filled in


//+-----length of char allowed------+
name_max = 60;
name_min = 2;
//address_max = 160;
phone_max = 14;
phone_min = 7;
//time_max = 40;

email_max = 80;
email_min = 6;

message_max = 2000;
message_min = 5;

basic_min = 1;

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

//what the error box is titled
error_box = co_name; //title of error box

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.";
radio_error = "You must check a quanity desired ";

thankyoumsg = "Thank you for your message.";

//what the boxes are called
name_box = "Name";
phone_box = "Telephone Number";
email_box = "Email Address";
address_box = "Address";
city_box = "City";
state_box = "State";
zip_box = "Zip Code";
quantity_box = "Quantity";
message_box = "Message";



//<------------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
filled = 0;  //the number of items + 1 (count starts from 0)
failsafe = "Error...Please Use Email Address Provided On This Page.";

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


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

//check length of each value
check_length( full_name, name_max, name_box);
check_length( phone, phone_max, phone_box);
check_length( message, message_max, message_box);

//check if value is filled in (change "num_checked" value to how many times check_fill or check_email is called)
filled += check_fill(full_name, name_min, name_box);
filled += check_email(email);
filled += check_fill(message, message_min, message_box);

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

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


}


// <-----------helper functions (don't change)--------------->//

//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-1) ){
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 check_radios(box) {
	if (box) {
		return(1);
	} else {
		fullerrormsg = fullerrormsg + "\n - " + radio_error;
 		errorflag = 1;
  return(0);
	} //end else
} //end function


function give_results() {

if ((errorflag == 0) && (filled == numchecked)){
  alert( thankyoumsg );
  page.pass.value = email;
  page.submit();
}else if (errorflag > 0) {
	alert(fullerrormsg+"\n\n"); 
	} //end else
else {
	
alert(fullerrormsg+"\n"+failsafe+"\n\n"); 	
	
}



}	//end function
	
	
	








