$(document).ready(function() { 
	var options = { /*target: '#alert',*/
					beforeSubmit:  validateContactForm,  // pre-submit callback 
					success: showResponse,
					clearForm:     false
	}; 
	$('#contactForm').submit(function() {
		$('#contactForm').ajaxSubmit(options); 
		return false;
	});
}); 

$.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 showResponse(text){

	$("#alerts").html('<div class="success">Your message was sent successfully!</div>').stop().animate({ height: '37px'}, 'slow', 'easeOutQuad');
	
}
			
function validateContactForm(){
				
	var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
	var colorRed = '#FFC6C6';
	
	if($("#txtFName").val() == ''){
		resetFormCSS();
		$("#txtName").css('background-color', colorRed);
		$("#txtName").focus();
		return false;
	}else if($("#txtLName").val() == ''){
		resetFormCSS();
		$("#txtLName").css('background-color', colorRed);
		$("#txtLName").focus();
		return false;
	}else if($("#txtAddress").val() == ''){
		resetFormCSS();
		$("#txtAddress").css('background-color', colorRed);
		$("#txtAddress").focus();
		return false;
	}else if($("#txtCity").val() == ''){
		resetFormCSS();
		$("#txtCity").css('background-color', colorRed);
		$("#txtCity").focus();
		return false;
	}else if($("#txtState").val() == ''){
		resetFormCSS();
		$("#txtState").css('background-color', colorRed);
		$("#txtState").focus();
		return false;
	}else if($("#txtZip").val() == ''){
		resetFormCSS();
		$("#txtZip").css('background-color', colorRed);
		$("#txtZip").focus();
		return false;
	}else if($("#txtPhone").val() == ''){
		resetFormCSS();
		$("#txtPhone").css('background-color', colorRed);
		$("#txtPhone").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 if($("#method").val() == ''){
		resetFormCSS();
		$("#method").css('background-color', colorRed);
		$("#method").focus();
		return false;
	}

	return true;
}

function resetFormCSS(){
	$("#txtName").css('background-color', '');
	$("#txtEmail").css('background-color', '');
	$("#txtMessage").css('background-color', '');
}

function showError(){
	$("#alerts").html('<div class="error">There was a problem sending the message.</div>');
}


