﻿$(document).ready(function(){

	/****** formulario de cadastro *******/
  $("#formCadastro").submit(function() {
    $("#msgCadastro").html("Aguarde...").fadeIn();
    //var $nome = $("#txNomeCad").attr("value"); ;
    var $email = $("#txEmail").attr("value"); ;;
    $("#msgCadastro").load(
          "enviaCadastro.php",
          //{nome: $nome, email: $email},
          {email: $email},
          function () {
          		window.setTimeout(
          			function() {
              	    $("#msgCadastro").fadeOut();
                    //$("#txNomeCad").val($("#txNomeCad").attr('title'));
                    $("#txEmail").val($("#txEmail").attr('title'));
										$("#txEmail").removeClass("txInputOn").addClass("txInputOff");
              	},
          			3000
              );
          }
    );
  	return false;
	});

  $('#formCadastro input[type=text][title!=""]').each(function() {
	  if ($.trim($(this).val()) == '') {
	  	$(this).val($(this).attr('title'));
			$(this).addClass("txInputOff");
		}
  }).focus(switchText).blur(switchText);

	function switchText() {
		if ($(this).val() == $(this).attr('title')) {
			$(this).val('');
			$(this).removeClass("txInputOff").addClass("txInputOn");;
		} else if ($.trim($(this).val()) == '') {
			$(this).removeClass("txInputOn").addClass("txInputOff");;
			$(this).val($(this).attr('title'));
		}
	}


	/**** Formulario de contato ****/
	$("#cmdEnviar").click(function(){
		$("#formContato").submit();
	});

	$("#cmdLimpar").click(function(){
    $("#nome").val("");
    $("#email").val("");
    $("#telefone").val("");
    $("#assunto").val("");
    $("#mensagem").val("");

	});

  $("#formContato").submit(function() {
    $("#divMsg").html("Aguarde...").fadeIn();
    var $nome = $("#nome").attr("value");
    var $email = $("#email").attr("value");
    var $telefone = $("#telefone").attr("value");
    var $assunto = $("#assunto").attr("value");
    var $mensagem = $("#mensagem").attr("value");
    $("#divMsg").load(
          "enviaContato.php",
          {nome: $nome, email: $email, telefone: $telefone, assunto: $assunto, mensagem: $mensagem},
          function () {
          		window.setTimeout(
          			function() {
              	    $("#divMsg").fadeOut();
                    $("#nome").val("");
                    $("#email").val("");
                    $("#telefone").val("");
                    $("#assunto").val("");
                    $("#mensagem").val("");
              	},
          			3000
              );
          }
    );
    //$("#divMsg").load("enviaCadastro.php");
  	return false;
	});


});


