// JavaScript Document

function gE(ID)
{
	return document.getElementById(ID);
}

function limpaFormOrcamento()
{
	var nome =	gE('orc-nome');
	var cidade = gE('orc-cidade');
	var tel = gE('orc-tel');
	var desc = gE('orc-desc');
	var email = gE('orc-email');
	
	nome.value = 'Nome:';
	cidade.value = 'Cidade:';
	tel.value = 'Tel:';
	email.value = 'E-mail:';
	desc.value = 'Descreva seu orçamento:';
}

function validaFormOrcamento()
{
	var nome =	gE('orc-nome');
	var cidade = gE('orc-cidade');
	var tel = gE('orc-tel');
	var desc = gE('orc-desc');
	var email = gE('orc-email');
	
	if ((nome.value == "") || (nome.value == null) || (nome.value == "Nome:"))
	{
		alert("Campo Nome em branco");
		nome.focus();
		return false;
	}
	
	if ((cidade.value == "") || (cidade.value == null) || (cidade.value == "Cidade:"))
	{
		alert("Campo Cidade em branco");
		cidade.focus();
		return false;
	}
	
	if ((tel.value == "") || (tel.value == null) || (tel.value == "Tel:"))
	{
		alert("Campo Tel em branco");
		tel.focus();
		return false;
	}
	
	if ((email.value == "") || (email.value == null) || (email.value == "E-mail:"))
	{
		alert("Campo Email em branco");
		email.focus();
		return false;
	}
	
	if ((desc.value == "") || (desc.value == null) || (desc.value == "Descreva seu orçamento:"))
	{
		alert("Campo Descrição em branco");
		desc.focus();
		return false;
	}	
	
	return true;
}

function limpaFrmContato()
{
	var nome = gE('f_cont_nome');
	var email = gE('f_cont_email');
	var telefone = gE('f_cont_tel');
	var assunto = gE('f_cont_assunto');
	var msg = gE('f_cont_msg');
	
	nome.value = "";
	email.value = "";
	telefone.value = "";
	assunto.value = "";
	msg.value = "";
}

var Validacao = {
	ValidaItens: function(){
		var args = Validacao.ValidaItens.arguments; // coloca os parametros em uma variavel no qual se tornará um Array
		if (args.length > 0){ // verifica se há parametros atribuidos a função
			for (var x = 0; x < args.length; x++){
				var vItem = gE(args[x]);
				if (vItem.value == "" || vItem.value == null){
					vItem.focus();
					vItem.style.border = 'solid 1px red';
					alert("Campo em branco");
					return(false);
				}else{
					vItem.style.border = '';
				}				
				//verifica se há algum campo de e-mail para chamar o validaEmail
				var vCampo = args[x].toLowerCase();		
				if (vCampo.indexOf('email') > 0){
					if (Validacao.ValidaEmail(vItem) == false)
						return(false);
				}				
			} // fim do for			
			return(true);
		}else{
			alert('Ocorreu um erro ao realizar operação');
			return(false);			
		}// else (args.length > 0){
	}, // fim do ValidaItens
	
	ValidaEmail: function(pCampo){
		var email = pCampo.value;
		var resp = email.search(/(\w[\w\.\+]+)@(.+)\.(\w+)$/)==0;
		
		if (resp == false){
			pCampo.focus();
			pCampo.style.border = 'solid 1px red';
			alert('E-mail inválido');
			return(false);
		}else{
			return(true);
		}
	}
};
