// JavaScript Document
$(document).ready(function() { 
		
	$("#contactForm").ajaxForm({ 
		beforeSubmit:  validateContactForm,  // pre-submit callback 
		success:       showResponse,  // post-submit callback
		error:         showError,     // error callback
		url:           'mailman.php?action=send&method=ajax',
		clearForm:     false
	}); 
	
});

function showResponse(text){
	if(text == 'error'){
		$("#alerts").html('<div class="error">There was a problem sending the message. Please try again.</div>').stop().animate({ height: '37px'}, 'slow', 'easeOutQuad');
	}else if(text == 'success'){
		$("#alerts").html('<div class="success">Your message was sent successfully!</div>').stop().animate({ height: '37px'}, 'slow', 'easeOutQuad');
	}
}

function showError(){
	$("#alerts").html('<div class="error">There was a problem sending the message. Please try again.</div>');
}

function validateContactForm(){
				
	var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
	var colorRed = '#FFC6C6';
	
	if($("#txtName").val() == ''){
		resetFormCSS();
		$("#txtName").css('background-color', colorRed);
		$("#txtName").focus();
		return false;
	}else if($("#txtEmail").val() == ''){
		resetFormCSS();
		$("#txtEmail").css('background-color', colorRed);
		$("#txtEmail").focus();
		return false;
	}else if($("#txtMessage").val() == ''){
		resetFormCSS();
		$("#txtMessage").css('background-color', colorRed);
		$("#txtMessage").focus();
		return false;
	}else{
		return true;
	}
}

function resetFormCSS(){
	$("#txtName").css('background-color', '');
	$("#txtEmail").css('background-color', '');
	$("#txtMessage").css('background-color', '');
}


