
function check_form(the_form) {

	var str_msg="";

	if(the_form.account_name.value=="") if(str_msg==""){str_msg="Account Name"}else{str_msg+=", Account Name"};
	if(the_form.account_number.value=="") if(str_msg==""){str_msg="Account Number"}else{str_msg+=", Account Number"};
	
	if(the_form.phone.value=="") if(str_msg==""){str_msg="Phone Number"}else{str_msg+=", Phone Number"};

	if(the_form.email.value=="") {
		if(str_msg==""){str_msg="Email"}else{str_msg+=", Email"};
	}else{
		var pattern_email = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
		if(!pattern_email.test(the_form.email.value)) if(str_msg==""){str_msg="valid Email Address"}else{str_msg+=", valid Email Address"};
	}
	
	if(str_msg!="") str_msg = "Please enter "+str_msg;

	if(str_msg!=""){
		alert(str_msg);
	}else{

		var form_para="";
		for(var i=0; i<the_form.elements.length; i++){
			switch (the_form.elements[i].type){
			
				case "checkbox":
				case "radio":
					if(the_form.elements[i].checked) form_para += ((form_para!="")? "&":"") + the_form.elements[i].name+"="+encodeURIComponent(the_form.elements[i].value);
					break; 
				
				case "select-one":
					form_para += ((form_para!="")? "&":"") + the_form.elements[i].name+"="+encodeURIComponent(the_form.elements[i].options[the_form.elements[i].selectedIndex].value);
					break; 
				
				case "select-multiple":
					for(var ii=0; ii<the_form.elements[i].length; ii++){
						if(the_form.elements[i].options[ii].selected) form_para += ((form_para!="")? "&":"") + the_form.elements[i].name+"="+encodeURIComponent(the_form.elements[i].options[ii].value);
					}
					break;
					
				default:
					form_para += ((form_para!="")? "&":"") + the_form.elements[i].name+"="+encodeURIComponent(the_form.elements[i].value);
			}
		}
		
		var d = new Date();
		var t = d.getTime();
		form_para += "&t=" + t;
	
		$.ajax(
			{
				url: "_include/script_form_request_access.php",
				type: "post",
				dataType: "text",
				data: form_para,
				beforeSend: function(){form_submission_response("SENDING");},
				success: function(return_data){
					if(return_data=="SUCCESS") form_submission_response("SUCCESS");
					if(return_data=="ERROR") form_submission_response("ERROR");
				},
				error: function(){form_submission_response("ERROR");}
			}
		);

	}

	return false;


}

function form_submission_response(str_submission_response_code){

	if(str_submission_response_code=="") return false;
	var array_code_text=new Array();
	pushin(array_code_text, new Array("FILL", "Please fill out the following fields."));
	pushin(array_code_text, new Array("SENDING", "<span style='color:#f80;'>Sending your information ...</span>"));
	pushin(array_code_text, new Array("SUCCESS", "<span style='color:#9c0;'>Your information has been successfully sent. Thank you!</span>"));
	pushin(array_code_text, new Array("ERROR", "<span style='color:#f00;'>Sorry, your information was not sent successfully.</span>"));

	var str_msg="";
	for(i=0; i<array_code_text.length; i++){
		if(array_code_text[i][0]==str_submission_response_code){
			str_msg=array_code_text[i][1];
			break;
		}
	}

	$("#div_form_submission_message").html(str_msg);
	
}
