function escondeDiv(){
	div = document.getElementById("msgAlerta");
	div.style.display = "none";
}

function busca(id){
	if(id != 'no'){
		document.location.href = "busca.php?id=" + id;
		return;
	}
}

function goToProduto(id){
	if(id != 'no'){
		document.location.href = "produtos.php?id=" + id;
		return;
	}
}


/*
 * Função para verificar todos os campos de um formulario
 * @return bool
 */
function validaTudo() {
	var erro = "";
	divError = document.getElementById("divErro");
	for(var i = 0; i < document.forms[0].length; i++) {
		if(document.forms[0].elements[i].type != "submit" && document.forms[0].elements[i].type != "button" && document.forms[0].elements[i].type != "file" && document.forms[0].elements[i].type != "hidden") {
			if(document.forms[0].elements[i].value == "") {
				erro += "O campo <em>" + document.forms[0].elements[i].name + "</em> é obrigatório.<br />";
			} else if(document.forms[0].elements[i].name == 'email') {
				erro += validaEmail('email');
			}
		}
	}
	
	if(erro != "") {
		divError.style.display = "block";
		divError.innerHTML = erro;
		return false;
	} else {
		return true;
	}//fim if erro
}


/*
 * Função para verificar email digitado
 * @param1 id
 * @return bool
 */
function validaEmail(id) {
	var erro = "";
	email = document.getElementById(id);
	
	expr = /^[\w!#$%&'*+\/=?^`{|}~-]+(\.[\w!#$%&'*+\/=?^`{|}~-]+)*@(([\w-]+\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
	if(!expr.test(email.value)) erro+="Digite um email válido.<br />";
	
	return erro;
	/*if(erro != "") {
		return erro;
	} else {
		return erro;
	}*/
}


/*
 * Função para verificar todos os campos de um formulario
 * @return void
 */
function mudaCampo(VemDe, IrPara, tammax) {

	if (VemDe.value.length == tammax)  {
		document.getElementById(IrPara).focus();
	}
}


/*
 * Função para preencher telefone corretamente
 * @param1 obj
 * @return void
 */
function maskTel(obj) {
 if(obj.value.length == 4)
     obj.value = obj.value + '-';
}

/*
 * Função para verificar todos os campos de um formulario
 * @return bool
 */
function validaTrabalhe() {
	var erro = "";
	divError = document.getElementById("divErro");
	file = document.getElementById("cv");
	for(var i = 0; i < document.forms[0].length; i++) {
		if(document.forms[0].elements[i].type != "submit" && document.forms[0].elements[i].type != "button" && document.forms[0].elements[i].type != "file" && document.forms[0].elements[i].type != "hidden") {
			if(document.forms[0].elements[i].value == "") {
				erro += "O campo <em>" + document.forms[0].elements[i].name + "</em> é obrigatório.<br />";
			} else if(document.forms[0].elements[i].name == 'email') {
				erro += validaEmail('email');
			}
		}
	}
	
	if(file.value.indexOf('.doc', 0) == -1 && file.value.indexOf('.pdf', 0) == -1 && file.value != "") {
		erro += "Verifique seu <em>currículo</em> (Somente .doc e .pdf).<br />";
	}
	
	if(erro != "") {
		divError.style.display = "block";
		divError.innerHTML = erro;
		return false;
	} else {
		return true;
	}//fim if erro
}

function finalizaPedido(){
	
	tpPagamento = document.getElementById("formaPagamento").value;
	document.location.href = 'finalizaPedido.php?tpPagamento=' + tpPagamento;
	
}

/*
 * Função para validar form cadastro 1
 * @return bool
 */
function validaCadastro1() {
	
	if(!validaEmailCadastro('emailClienteCadastro')){
		return false;
	}
	
	if(!validaCep('cep1')){
		return false;
	}
	
	if(!validaCep('cep2')){
		return false;
	}
	
	return true;
}


/*
 * Função para validar form contato
 * @return bool
 */
function validaContato() {
	
	if(!validaPreenchimento('nome')){
		return false;
	}
	
	if(!validaEmailCadastro('email')){
		return false;
	}
	
	if(!validaPreenchimento('assunto')){
		return false;
	}
	
	if(!validaPreenchimento('mensagem')){
		return false;
	}
	
	return true;
}

/*
 * Função para verificar preenchimentoo
 * @param1 campo
 * @return bool
 */
function validaPreenchimento(id) {
	
	var erro = "";
	divError = document.getElementById("msgErro");
	
	campo = document.getElementById(id);
	
	if(campo.value == "") erro+="<p>O campo <em>" + id + "</em> é obrigatório.</p>";
	
	if(erro != "") {
		divError.style.display = "block";
		divError.innerHTML = erro;
		campo.focus();
		return false;
	} else {
		divError.style.display = "none";
		return true;
	}//fim if erro
}


/*
 * Função para verificar preenchimentoo
 * @param1 campo
 * @return bool
 */
function validaCep(id) {
	
	var erro = "";
	divError = document.getElementById("msgErro");
	
	campo = document.getElementById(id);
	
	if(isNaN(campo.value)) erro+="<p>Digite um <em>cep</em> válido.</p>";
	else if(campo.value == "") erro+="<p>O campo <em>" + id + "</em> é obrigatório.</p>";
	else {
		if(id == 'cep1' && campo.length < 5) erro+="<p>O campo deve conter <em>5</em> digitos.</p>";
		else if(id == 'cep2' && campo.length < 3) erro+="<p>O campo deve conter <em>3</em> digitos.</p>";
	}
	
	
	
	if(erro != "") {
		divError.style.display = "block";
		divError.innerHTML = erro;
		campo.focus();
		return false;
	} else {
		divError.style.display = "none";
		return true;
	}//fim if erro
}


/*
 * Função para verificar email digitado
 * @param1 id campo email
 * @return bool
 */
function validaEmailCadastro(id) {
	var erro = "";
	divError = document.getElementById("msgErro");
	
	email = document.getElementById(id);
	
	expr = /^[\w!#$%&'*+\/=?^`{|}~-]+(\.[\w!#$%&'*+\/=?^`{|}~-]+)*@(([\w-]+\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
	if(!expr.test(email.value)) erro+="<p>Preencha o campo <em>e-mail</em> corretamente.</p>";
	
	if(erro != "") {
		divError.style.display = "block";
		divError.innerHTML = erro;
		email.focus();
		return false;
	} else {
		return true;
	}//fim if erro
}

