// JavaScript Document

$(document).ready(function(){
$("#twitter_div").hide();
$("#twitter_div").show('slow');


//Newsletter
$("input").focus(function () {
         $(this).reset();
 });

$("#submit").click(function(){

		$(".error").hide();
		var hasError = false;
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		
		var emailToVal = "babylonstudios2009@gmail.com";
		var subjectVal = "Cliente assina newsLetter";
		
		var subjectVal = $("#newsName").val();
		if(subjectVal == '' || subjectVal == 'Nome') {
			$("#mailInfo").html('Voc&ecirc; esqueceu de incluir o seu Nome.');
			hasError = true;
		}

		var emailFromVal = $("#newsMail").val();
		if(emailFromVal == '' || emailFromVal == 'E-mail') {
			$("#mailInfo").html('Voc&ecirc; esqueceu de incluir um endere&ccedil;o de email.');
			hasError = true;
		} else if(!emailReg.test(emailFromVal)) {
			$("#mailInfo").html('Insira um endere&ccedil;o de email v&aacute;lido.');
			hasError = true;
		}
		
		if(hasError == false) {
			$(this).hide();
			$("#mailInfo").html("Enviando...");
			//$("#newsForm buttons").append('<img src="/images/template/loading.gif" alt="Loading" id="loading" />');
			$.ajax({
			type: "POST",
			url: "../php/phpNewsContact.php",
			data: $("form").serialize(),
			success: function(msg){
				$("#mailInfo").hide();
				$(".thankYou").html("Obrigado por assinar nossa newsletter!");
				$("form")[ 1 ].reset();
				$("#newsFormDiv").animate({height: 'toggle', opacity: 'toggle'},"slow");
				//alert(msg);
			}
		});
		}
		
		
		return false;
	});

$("#submitRequest").click(function(){

		$(".error").hide();
		var hasError = false;
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		
		var emailToVal = "babylonstudios2009@gmail.com";
		var subjectVal = $("#nomeSolicit").val();
		if(subjectVal == '') {
			$("#mailInfo2").html('Voc&ecirc; esqueceu de incluir o seu Nome.');
			hasError = true;
		}

		var emailFromVal = $("#emailSolicit").val();
		if(emailFromVal == '') {
			$("#mailInfo2").html('Voc&ecirc; esqueceu de incluir um endere&ccedil;o de email.');
			hasError = true;
		} else if(!emailReg.test(emailFromVal)) {
			$("#mailInfo2").html('Insira um endere&ccedil;o de email v&aacute;lido.');
			hasError = true;
		}
		var corpoVal = $("#corpoSolicit").val();
		if(corpoVal == '') {
			$("#mailInfo2").html('Voc&ecirc; esqueceu de incluir sua solicita&ccedil;&atilde;o.');
			hasError = true;
		}
		
		if(hasError == false) {
			$(this).hide();
			$("#mailInfo2").html("Enviando...");
			//$("#newsForm buttons").append('<img src="/images/template/loading.gif" alt="Loading" id="loading" />');
			$.ajax({
			type: "POST",
			url: "../php/phpSolicitContact.php",
			data: $("#myForm").serialize(),
			success: function(msg){
				$("#mailInfo2").hide();
				$("#myForm")[ 0 ].reset();
				$("#myAnimated").toggle("slow");
				$(".thankYou2").html("Obrigado! Entraremos em contato o mais breve possivel");
				//animate({height: 'toggle', opacity: 'toggle'},"slow");
				//alert(msg);
			}
		});
		}
		
		
		return false;
	});
	
	
$("#submit").hover(function (){
        $(this).html('<span style="text-decoration:underline;">Enviar.</span>');
    },function(){
        $(this).html("Enviar.");
    }
	
);
$("#submitRequest").hover(function (){
        $(this).html('<span style="text-decoration:underline;">Enviar.</span>');
    },function(){
        $(this).html('<span style="text-decoration:none;">Enviar.</span>');
    }
);


	
});