$(document).ready(function () {
	// Comportamento dos campos do formulário
	$('input[type=text]').focus(function () {
		$(this).val('');
		$(this).css('color','#000000');
		$(this).parent().addClass('active');
	}).blur(function() {
		$(this).parent().removeClass('active');
		if (this.value == '') {
			$(this).css('color','#999999');
			$(this).val($(this).attr('label'));
		}
	});

	$('textarea').focus(function () {
		$(this).val('');
		$(this).css('color','#000000');
		$(this).parent().addClass('active');
	}).blur(function() {
		$(this).parent().removeClass('active');
		if (this.value == '') {
			$(this).css('color','#999999');
			$(this).val($(this).attr('label'));
		}
	});
	
  $("#submit").click(function() {
    $('.alert').hide();
		$('input,textarea').css("background-position","top");

	  var name = $("input#name").val();
		var email = $("input#email").val();
		var phone = $("input#phone").val();
		var message = $("textarea#message").val();
		if (name == "" || name == "Nome") {
      $(".alert.error").fadeIn();
      $("input#name").focus();
			$("input#name").css("background-position","bottom");
      return false;
    } else if (email == "" || email == "Email") {
      $(".alert.error").fadeIn();
      $("input#email").focus();
      $("input#email").css("background-position","bottom");
      return false;
    } else if (phone == "" || phone == "Telefone") {
      $(".alert.error").fadeIn();
      $("input#phone").focus();
      $("input#phone").css("background-position","bottom");
      return false;
    } else if (message == "" || message == "Mensagem") {
		  $(".alert.error").fadeIn();
      $("textarea#message").focus();
      $("textarea#message").css("background-position","bottom");
      return false;
		}
		var dataString = 'name='+ name + '&email=' + email + '&phone=' + phone + '&message=' + message;
		$.ajax({
      type: "POST",
      url: "send.php",
      data: dataString,
      success: function() {
				$("input#name").css('color','#999999').val("Nome");
				$("input#email").css('color','#999999').val("Email");
				$("input#phone").css('color','#999999').val("Telefone");
				$("textarea#message").css('color','#999999').val("Mensagem");
       	$(".alert.sucess").fadeIn();
      }
		});
		return false;  
	});
	
	$("#linkClients").click(function() {
		var code = $("input#code").val();
		if (code == "" || code == "Código") {
    	alert ("Código inválido!");	
      $("input#code").focus();
			$("input#code").css("background-position","bottom");
      return false;
    }
		var dataString = 'code='+ code;
		$.ajax({
      type: "POST",
      url: "clients.php",
      data: dataString,
      success: function(url) {
				if(url == 0) {
					alert ("Código inválido!");
				} else {
					$("form#client").fadeOut();
					window.location.href = url;
				}
      }
		});
		return false;  
  });
	
	
});

// Anti-spam
function noSpam(user,domain) {
	locationstring = 'mailto:' + user + '@' + domain;
	window.location = locationstring;
}
