$(document).ready(function(){

//inicializacao dos elementos
var animationEasing = "easeOutSine";













/* -------------------------------------------------------------------------------------- */
/* -- VALIDAÇÃO DO FORMULARIO DE REGISTO ------------------------------------------------ */
/* -------------------------------------------------------------------------------------- */

//Controla o show e o hidde das labes q estao em cima dos inputs
$(".formContainer input:text, .formContainer input:password, .formContainer textarea").each(function(){
	if($(this).val() != ""){$(this).prev("label").hide();}
});
$(".formContainer input:text, .formContainer input:password, .formContainer textarea").focus(function(){
	$(this).prev("label").hide();
});
$(".formContainer input:text, .formContainer input:password, .formContainer textarea").blur(function(){
	if(!$(this).val()) $(this).prev("label").show();
});





// Validacao dos inputs obrigadtorios e submit do form
$("#form1").validate({
	focusInvalid: false,
	highlight: false,
	onkeyup: false,
	errorPlacement: function(error, element) {
		error.appendTo( element.prev("label") );
	},
	errorElement: "span",
	errorClass: "alert",
	rules: {
		fldName: {required: true},
		fldEmail: {required: true, email: true},
		fldMessage: {required: true}
	},
	messages: {
		fldName: {required: "(obrigat&oacute;rio)"},
		fldEmail: {required: "(obrigat&oacute;rio)", email: function(rule, element){$(element).prev("label").show().find("span.alert").html("email inv&aacute;lido");}},
		fldMessage: {required: "(obrigat&oacute;rio)"}
	},
	submitHandler: function(form){
		$.post("../services/contactos/SendEmail.aspx", $(form).serialize(), function(data, textStatus){
			$(".loading").fadeIn("slow");
			
			$(".fillContent").fadeTo("slow", 0.11, function(){
				if(data.status.success){
					$(".loading").fadeOut("slow", function(){
						$(".fillContent").fadeOut("slow");
						$(".okContent").fadeIn("slow");
						$(".submitConfig").fadeOut("slow");
					});
				} else {	
					$(".loading").fadeOut("slow", function(){
						$(".fillContent").fadeOut("slow");
						$(".errorContent").fadeIn("slow");
						$(".submitConfig").fadeOut("slow");
					});
				}
			});
		}, "json");
	}
});

$(".formFill a.submit").click(function(event){
	event.preventDefault();
	$("#form1").validate();
	if($("#form1").valid()){
		$("#form1").submit();
	}
});


$(".errorContent a.tryagain").click(function(event){
	event.preventDefault();
	$(".fillContent").fadeTo("fast", 1, function(){
		$(".errorContent").fadeOut("slow");
		$(".fillContent").fadeIn("slow");
		$(".submitConfig").fadeIn("slow");
	});
	
});
/* -------------------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------------------- */















});

