$(document).ready(function() {
		
	var options = { 
		target:        '#alert',
		beforeSubmit:  showRequest,
		success:       showResponse
	};
	
	$('#contactform').ajaxForm(options);
	$('#reset').click(function() { 
		$('#alert').html(''); 
		$('#contactform #submit').attr('disabled','');
		clearFieldColors();
		$('#alert').fadeOut(300);
	});
});
	
function showRequest(formData, jqForm, options) {
	var queryString = $.param(formData);
	//$('#submit').before('<img src="images/ajax-loader.gif" alt="loading..." class="loader" />').attr('disabled','disabled');
	//$('#alert').css('border-color','#e0ded4');
	$('#alert').fadeIn(300);
	$('#submit').attr('disabled','disabled');
	$("#contact-loader").fadeIn(100);
	clearFieldColors();
	return true; 
}

function showResponse(responseText, statusText)  {
	//$('#contactform img.loader').fadeOut(500,function(){$(this).remove()});
	$('#submit').attr('disabled','');
	$("#contact-loader").fadeOut(300);
} 

$.fn.clearForm = function() {
	return this.each(function() {
		var type = this.type, tag = this.tagName.toLowerCase();
		if (tag == 'form')
			return $(':input',this).clearForm();
		if (type == 'text' || type == 'password' || tag == 'textarea')
			this.value = '';
		else if (type == 'checkbox' || type == 'radio')
			this.checked = false;
		else if (tag == 'select')
			this.selectedIndex = -1;
	});
};

function clearFieldColors() {
	$('#name').css('background-color','#FFFFFF');
	$('#email').css('background-color','#FFFFFF');
	$('#message').css('background-color','#FFFFFF');
}
