contact_info_sent = function(t){
$('contact_form_container').update(t.responseText);
}

function submitContactRequest() {
var form = $('contact_form');
new Ajax.Request('include/php/form_handler.php', {
 parameters:{first_name: form['first_name'].getValue(), last_name: form['last_name'].getValue(), street: form['street'].getValue(), city: form['city'].getValue(), state: form['state'].getValue(), zip: form['zip'].getValue(), tlf: form['tlf'].getValue(), email: form['email'].getValue(), inquiry: form['inquiry'].getValue(), contact_method: form['contact_method'].getValue(), notes: form['notes'].getValue()},
 onSuccess:contact_info_sent
});
}

function validate_form(){

var errors = 0;

var errorElements = document.getElementsByClassName('validation_error');
errorElements.each( function(e) { new Effect.Fade(e,{duration:0.5}); });

var form = $('contact_form');

var first_name = form['first_name'];
var first_name_val = $(first_name).getValue();
if(first_name_val == ''){
new Insertion.Before('contact_form',"<div class=\"validation_error\">Please give us your first name.</div>");
errors += 1;
}

var last_name = form['last_name'];
var last_name_val = $(last_name).getValue();
if(last_name_val == ''){
new Insertion.Before('contact_form',"<div class=\"validation_error\">Please give us your last name.</div>");
errors += 1;
}

var email = form['email'];
var email_pattern = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
var email_val = $(email).getValue();
if(email_val != ''){
if(!email_val.match(email_pattern)){
new Insertion.Before('contact_form',"<div class=\"validation_error\">Please enter a valid email address.</div>");
errors += 1;
}
}else{
new Insertion.Before('contact_form',"<div class=\"validation_error\">Please enter a valid email address.</div>");
errors += 1;
}

if(errors > 0){return false;}else{return true;}

}
