//  ENDEREÇO DO SCRIPT DE FORMULARIO
urlform="http://www.sketch.art.br/formmail/skore/form.php";

//  BACKGROUND INPUT:OUT
bginput1="#fff";
//  BACKGROUND INPUT:OVER
bginputhover1="#f0f0f0";
//  BACKGROUND INPUT FOCUS
bginput2="#ffffdd";

//  BORDER INPUT:OUT
borderinput1="1px solid #444";
//  BORDER INPUT:OVER
borderinput2="1px solid #ffff55";

//  TEXTO DO INPUT:OUT
colorinputout="#666";
//  TEXTO DO INPUT:OVER
colorinputhover="#000";



//  #####OUPUT#####
//  ERRO CAMPO NOME
msgnome=" - favor preencher o campo <strong>nome</strong>.";
//  ERRO CAMPO IDADE
msgidade=" - favor preencher o campo <strong>idade</strong>.";
//  ERRO CAMPO EMAIL
msgemail=" - favor preencher o campo <strong>e-mail</strong>.";
//  ERRO CAMPO CIDADE
msgcidade=" - favor preencher o campo <strong>cidade</strong>.";
//  ERRO CAMPO UF
msguf=" - favor preencher o campo <strong>UF</strong>.";
//  ERRO CAMPO EMAIL DE AMIGO
msgemailamigo=" - favor preencher o campo <strong>e-mail de amigo</strong>.";
//  COR PARA A MENSAGEM DE SUCESSO
corconfirmado="#ff0000";
//  MENSAGEM COM SUCESSO
msgsucesso=" - <strong>e-mail enviado com sucesso!</strong>";







$(document).ready(function() {
		$("input, textarea").bind("keydown", function(e){
        if (e.keyCode == 13) {
			$("input").blur();
            $("#form_enviar").click();
            return false;
        }
    });

	$("input, textarea").css("color",colorinputout);
	$("input, textarea").css("border",borderinput1);
	$("input, textarea").css("background-color",bginput1);
	$("input, textarea").hover(function(){
			$(this).addClass("over");
			$(this).css("background-color",bginputhover1);
			},function(){
			$(this).addClass("out");
			$(this).css("background-color",bginput1);
	});
	function foco(local, valor) { 
		$(local).css("color",colorinputhover);
		$(local).css("background-color",bginput2);
		$(local).css("border",borderinput2);
		if ($(local).val() == "" || $(local).val() == valor) {
			$(local).val("");
		} 
		$(local).hover(function(){
			$(this).addClass("over");
			$(this).css("background-color",bginput2);
			},function(){
			$(this).addClass("out");
			$(this).css("background-color",bginput2);
		});
	}

	function desfoco(local, valor) { 
		$(local).css("background-color",bginput1);
		$(local).css("border",borderinput1);
		if ($(local).val() == "" || $(local).val() == valor) {
			$(local).css("color",colorinputout);
			$(local).val(valor);
		}
		$(local).hover(function(){
			$(this).addClass("over");
			$(this).css("background-color",bginputhover1);
			},function(){
			$(this).addClass("out");
			$(this).css("background-color",bginput1);
		});
	}


	$("#aparecer").hide();
	$("#aparecer2").hide();
	$("#form_nome").focus( function() { foco('#form_nome',' nome'); $("#aparecer").fadeIn("slow"); $("#aparecer2").fadeIn("slow"); } );
	$("#form_idade").focus( function() { foco('#form_idade',' idade'); } );
	$("#form_email").focus( function() { foco('#form_email',' e-mail'); } );
	$("#form_cidade").focus( function() { foco('#form_cidade',' cidade'); } );
	$("#form_uf").focus( function() { foco('#form_uf',' UF'); } );
	$("#form_comentarios").focus( function() { foco('#form_comentarios',' comentários'); } );

	$("#form_nome").blur( function() { desfoco('#form_nome',' nome'); } );
	$("#form_idade").blur( function() { desfoco('#form_idade',' idade'); } );
	$("#form_email").blur( function() { desfoco('#form_email',' e-mail'); } );
	$("#form_cidade").blur( function() { desfoco('#form_cidade',' cidade'); } );
	$("#form_uf").blur( function() { desfoco('#form_uf',' UF'); } );
	$("#form_comentarios").blur( function() { desfoco('#form_comentarios',' comentários'); } );


	$("#form_enviar").click( function() {
		$("#output").empty();
		var nome = $("#form_nome").val();
		var idade = $("#form_idade").val();
		var email = $("#form_email").val();
		var cidade = $("#form_cidade").val();
		var uf = $("#form_uf").val();
		var amigo1 = $("#form_amigo1").val();
		var amigo2 = $("#form_amigo2").val();
		var amigo3 = $("#form_amigo3").val();
		var amigo4 = $("#form_amigo4").val();
		if (nome==" nome" || nome=="") { 	
			$("#output").hide();
			$("#output").append(msgnome);
			$("#output").fadeIn("slow");
			$("#form_nome").focus();
		} else if (idade.length >= 3 || idade==" idade" || idade=="")	{
			$("#output").hide();
			$("#output").append(msgidade);
			$("#output").fadeIn("slow");
			$("#form_idade").focus();
		} else if (email.indexOf("@") == -1 || email.indexOf(".") == -1) {
			$("#output").hide();
			$("#output").append(msgemail);
			$("#output").fadeIn("slow");
			$("#form_email").focus();
		} else if (cidade=="" || cidade==" cidade") {
			$("#output").hide();
			$("#output").append(msgcidade);
			$("#output").fadeIn("slow");
			$("#form_cidade").focus();
		} else if (uf==" UF" ||uf=="") {
			$("#output").hide();
			$("#output").append(msguf);
			$("#output").fadeIn("slow");
			$("#form_uf").focus();
		} else {
			document.getElementById('formulario').action=urlform;
			document.getElementById('formulario').submit();
			$("#output").hide();
			$("#output").append(msgsucesso);
			$("#output").fadeIn("slow");
			$("#output").css("color",corconfirmado);
		}
	});
});
