///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Constructor
$(document).ready(function() {
	
});
$(document).ready(function() {
	$("#contactform").hide();
	
	$.getScript("/_Content/JS/jquery/jquery.scrollTo.js")
	$.getScript("/_Content/JS/jquery/jquery.localscroll.js", init)
});

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//  Initializes the events
function init(){
	// Submit Handler
	$("#submitform").click(function(){
		if($("#contactform").valid()){
			submitForm_POST();
		}
		$('#message').fadeOut();
		return false;
	})
	
	$("form").validate({
		rules: {
			"name": {required: true},
			"email": {required: true,email: true},
			"comment": {required: true}
		},
		invalidHandler: function(e, validator) {
			$(".errorcontainer").hide().fadeIn();
			$.scrollTo('.error:visible:first', 500)
		}
	})
	
	$("#contactform").slideDown(1000);
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//  Submits the order
function submitForm_POST(){

	// Hides the form and shows the loading icon

	var options = { 
		type: "POST",
		url: "centurionmail.php",
		success: function(html){
			$('#message').html("<p>"+ html +"</p>")
			.hide()
			.fadeIn(1500);
			$(".errorcontainer").hide();
			$("#contactform").clearForm();
		},
		error: function(){
			alert('error');
		}
    }; 
	
	//Submits the form
	$('form').ajaxSubmit(options);
}

