$(function()
{
$("#contact_form").submit(function()
{
var cf = $(this);
var name = cf.find('#name');
var email = cf.find('#email');
var phone = cf.find('#phone');
var field4 = cf.find('#field4');
var field5 = cf.find('#field5');
var message = cf.find('#message');
var captcha = cf.find('#captcha');
var errors = 0;
var label_env = name.parent();
if( name.val().length == 0 )
{
if( label_env.find('.error').length == 0 )
label_env.append('
Please enter your name
');
name.focus();
return false;
}
else
{
label_env.find('.error').remove();
}
var label_env = email.parent();
if( !email.val().match(/^[a-z0-9\_\-\.]+\@[a-z0-9\-\.]+\.[a-z]{2,6}$/i) )
{
if( label_env.find('.error').length == 0 )
label_env.append('Please enter valid email address
');
email.focus();
return false;
}
else
{
label_env.find('.error').remove();
}
var label_env = message.parent();
if( message.val().length == 0 )
{
if( label_env.find('.error').length == 0 )
label_env.append('Some message is required
');
message.focus();
return false;
}
else
{
label_env.find('.error').remove();
}
var loader = cf.find('.loader');
var lbar = cf.find('.loader_bar');
if( loader.length == 0 )
{
cf.append( 'Sending your message...
' );
loader = cf.find('.loader');
lbar = cf.find('.loader_bar');
}
loader.css({'position':'absolute', 'top':'0px', 'left':'0px'});
loader.width( cf.outerWidth() );
loader.height( cf.outerHeight() );
lbar.css({'position':'absolute', 'top':'0px', 'left':'0px'});
lbar.width( cf.outerWidth() );
lbar.height( cf.outerHeight() );
loader.fadeTo(200,0.4, function(){
loader.css('filter',''); // ClearType Fix
});
lbar.fadeTo(200,1, function(){
lbar.css('filter',''); // ClearType Fix
});
jQuery.post("configuration.php", {ajx_send: "true", name: name.val(), email: email.val(), phone: phone.val(), field4: field4.val(), field5: field5.val(), message: message.val(), captcha: captcha.val(), send:'Send', token: Math.random()}, function(status){
if( status == 200 )
{
resetForm();
loader.fadeOut("normal");
lbar.fadeOut("normal", function()
{
hideContactForm();
});
}
else
if( status == 199 )
{
alert("You\'ve entered invalid captcha code, please enter the code you see on image!");
captcha.focus();
loader.fadeOut("fast");
lbar.fadeOut("fast");
}
else
{
alert("An error occoured. Your message cannot be send!");
loader.fadeOut("normal");
lbar.fadeOut("normal");
}
});
return false;
});
});
function hideContactForm()
{
var cf = $("#contact_form");
cf.animate({"left":380, "opacity":0, filter:""}, function()
{
cf.hide();
cf.before('
Your message has been sent...
Thank you for contacting me, I\'ll give you a response as soon as possible.
');
$('#success_message').fadeTo(500, 1, function()
{
$(this).css('filter',''); // ClearType Fix
});
});
}
function resetForm()
{
var cf = $("#contact_form");
var name = cf.find('#name');
var email = cf.find('#email');
var phone = cf.find('#phone');
var message = cf.find('#message');
name.val("").trigger('blur');
email.val("").trigger('blur');
phone.val("").trigger('blur');
message.val("").trigger('blur');
}