function formatar(src, mask) {
		var i = src.value.length;
		var saida = mask.substring(i,i+1);
		var ascii = event.keyCode;
		if (saida == "A") {
			if ((ascii >=97) && (ascii <= 122)) { event.keyCode -= 32; }
			else { event.keyCode = 0; }
		} else if (saida == "0") {
			if ((ascii >= 48) && (ascii <= 57)) { return }
			else { event.keyCode = 0 }
		} else if (saida == "#") {
			return;
		} else {
			src.value += saida;
			i += 1
			saida = mask.substring(i,i+1);
			if (saida == "A") {
				if ((ascii >=97) && (ascii <= 122)) { event.keyCode -= 32; }
				else { event.keyCode = 0; }
			} else if (saida == "0") {
				if ((ascii >= 48) && (ascii <= 57)) { return }
				else { event.keyCode = 0 }
			} else { return; }
		}
	}
function abre_janela(width, height, nome) {
var top; var left;
top = ( (screen.height/2) - (height/2) )
left = ( (screen.width/2) - (width/2) )
window.open('',nome,'width='+width+',height='+height+',scrollbars=no,toolbar=no,location=no,status=no,menubar=no,resizable=no,left='+left+',top='+top);
}	
function verifica_data(date) {
   var err = 0
   string = date
   var valid = "0123456789/"
   var ok = "yes";
   var temp;
   for (var i=0; i< string.length; i++) {
     temp = "" + string.substring(i, i+1);
     if (valid.indexOf(temp) == "-1") err = 1;
   }
   if (string.length != 10) err=1
   b = string.substring(3, 5)        // month
   c = string.substring(2, 3)        // '/'
   d = string.substring(0, 2)        // day 
   e = string.substring(5, 6)        // '/'
   f = string.substring(6, 10)    // year
   if (b<1 || b>12) err = 1
   if (c != '/') err = 1
   if (d<1 || d>31) err = 1
   if (e != '/') err = 1
   if (f<1850 || f>2050) err = 1
   if (b==4 || b==6 || b==9 || b==11){
     if (d==31) err=1
   }
   if (b==2){
     var g=parseInt(f/4)
     if (isNaN(g)) {
         err=1 
     }
     if (d>29) err=1
     if (d==29 && ((f/4)!=parseInt(f/4))) err=1
   }
   if (err==1) {
       alert("Formado de Data inválido");
	   document.form_cad.txtData.focus();
    return false;
   }
 }	
function limparCampo(id, cont){
  var campo = document.getElementById(id);
  if (campo.value == cont){
  campo.value = '';
  }else if(campo.value == ''){
  campo.value = cont;
  }
}
function Valida_Cadastro() {
	if(document.form2.email.value=="") {
		alert('Preencha o Campo E-mail!');
		document.form2.email.focus();
		return false;
	}
	if (document.form2.email.value.search("@") == -1 || document.form2.email.value.search("[.*]") == -1){
	window.alert ("O e-mail não é válido!");   
	document.form2.email.focus();     
	return false;    
	}
	if(document.form2.email2.value=="") {
		alert('Confirme seu E-mail!');
		document.form2.email2.focus();
		return false;
	}
	if (document.form2.email2.value.search("@") == -1 || document.form2.email2.value.search("[.*]") == -1){
	window.alert ("O e-mail não é válido!");   
	document.form2.email2.focus();     
	return false;    
	}
	if(document.form2.email.value != document.form2.email2.value ) {
		alert('Os E-mails não são iguais!');
		document.form2.email.focus();
		return false;
	}
	if(document.form2.cpf.value=="") {
		alert('Preencha o Campo CPF!');
		document.form2.cpf.focus();
		return false;
	}
	if(document.form2.rg.value=="") {
		alert('Preencha o Campo RG!');
		document.form2.rg.focus();
		return false;
	}
	if(document.form2.ano.value=="") {
		alert('Preencha o Campo Ano de Nascimento!');
		document.form2.ano.focus();
		return false;
	}
	if(document.form2.senha.value=="") {
		alert('Preencha o Campo Senha!');
		document.form2.senha.focus();
		return false;
	}
	if(document.form2.senha2.value=="") {
		alert('Confirme sua Senha!');
		document.form2.senha2.focus();
		return false;
	}
	if(document.form2.senha.value != document.form2.senha2.value ) {
		alert('As Senhas não são iguais!');
		document.form2.senha.focus();
		return false;
	}
}	
function Valida_Newsletter() {
	if(document.form_news.txtNome.value=="" || document.form_news.txtNome.value=="seu nome") {
		alert('Preencha o Campo Nome!');
		document.form_news.txtNome.focus();
		return false;
	}
	if(document.form_news.txtEmail.value=="" || document.form_news.txtEmail.value=="seu@email.com.br") {
		alert('Preencha o Campo E-mail!');
		document.form_news.txtEmail.focus();
		return false;
	}
	if (document.form_news.txtEmail.value.search("@") == -1 || document.form_news.txtEmail.value.search("[.*]") == -1){
	window.alert ("O e-mail não é válido!");   
	document.form_news.txtEmail.focus();     
	return false;    
	}
}	

function Valida_Contato() {
	if(document.form4.txtNome.value=="") {
		alert('Preencha o Campo Nome!');
		document.form4.txtNome.focus();
		return false;
	}
	if(document.form4.txtEmail.value=="") {
		alert('Preencha o Campo E-mail!');
		document.form4.txtEmail.focus();
		return false;
	}
	if (document.form4.txtEmail.value.search("@") == -1 || document.form4.txtEmail.value.search("[.*]") == -1){
	window.alert ("O e-mail não é válido!");   
	document.form4.txtEmail.focus();     
	return false;    
	}
	if(document.form4.txtAssunto.value=="") {
		alert('Preencha o Campo Assunto!');
		document.form4.txtAssunto.focus();
		return false;
	}
	if(document.form4.txtMensagem.value=="") {
		alert('Preencha o Campo Assunto!');
		document.form4.txtMensagem.focus();
		return false;
	}
}	

function Valida_Cadastro() {

	if(document.form_cad.txtEmail.value=="") {
		alert('Preencha o Campo E-mail!');
		document.form_cad.txtEmail.focus();
		return false;
	}
	if (document.form_cad.txtEmail.value.search("@") == -1 || document.form_cad.txtEmail.value.search("[.*]") == -1){
	window.alert ("O e-mail não é válido!");   
	document.form_cad.txtEmail.focus();     
	return false;    
	}
	if(document.form_cad.txtSenha.value=="") {
	alert('Preencha o Campo Senha!');
	document.form_cad.txtSenha.focus();
	return false;
	}	
	if(document.form_cad.txtSenha2.value=="") {
	alert('Preencha o Campo de Confirmação de Senha!');
	document.form_cad.txtSenha2.focus();
	return false;
	}	
	if(document.form_cad.txtSenha.value != document.form_cad.txtSenha2.value) {
	alert('As Senhas não conferem!');
	document.form_cad.txtSenha.focus();
	return false;
	}	
	if(document.form_cad.txtNome.value=="") {
	alert('Preencha o Campo Nome!');
	document.form_cad.txtNome.focus();
	return false;
	}		
	if(document.form_cad.txtData.value=="") {
	alert('Preencha o Campo Data de Nascimento!');
	document.form_cad.txtData.focus();
	return false;
	}
	if(document.form_cad.txtRg.value=="") {
		alert('Preencha o Campo RG!');
		document.form_cad.txtRg.focus();
		return false;
	}
	if(document.form_cad.txtTelefone.value=="") {
		alert('Preencha o Campo Telefone de Contato!');
		document.form_cad.txtTelefone.focus();
		return false;
	}
	if(document.form_cad.txtCidade.value=="") {
		alert('Preencha o Campo Cidade!');
		document.form_cad.txtCidade.focus();
		return false;
	}
	if(document.form_cad.txtUf.value=="") {
		alert('Preencha o Campo Estado!');
		document.form_cad.txtUf.focus();
		return false;
	}
	if(document.form_cad.txtEndereco.value=="") {
		alert('Preencha o Campo Endereço!');
		document.form_cad.txtEndereco.focus();
		return false;
	}
	if(document.form_cad.txtBairro.value=="") {
		alert('Preencha o Campo Bairro!');
		document.form_cad.txtBairro.focus();
		return false;
	}
}	

function Valida_Promocao() {
	if(document.form_promo.txtResposta.value=="") {
	alert('Preencha sua Resposta para a Promoção!');
	document.form_promo.txtResposta.focus();
	return false;
	}
	if(document.form_promo.txtNome.value=="") {
	alert('Preencha o Campo Nome!');
	document.form_promo.txtNome.focus();
	return false;
	}
	if(document.form_promo.txtEmail.value=="") {
	alert('Preencha o Campo E-mail!');
	document.form_promo.txtEmail.focus();
	return false;
	}
	if (document.form_promo.txtEmail.value.indexOf("@") == -1 || document.form_promo.txtEmail.value.indexOf(".") == -1 ) {
	alert("ATENÇÃO!\n\nVocê deve preencher um email válido!");
    document.form_promo.txtEmail.focus();
	document.form_promo.txtEmail.value = "";
    return false;
	}
	if(document.form_promo.txtFone.value=="") {
	alert('Preencha o Campo Telefone!');
	document.form_promo.txtFone.focus();
	return false;
	}
}	
function Valida_Login() {
	if(document.form_login.txtEmail.value=="") {
		alert('Preencha o Campo E-mail!');
		document.form_login.txtEmail.focus();
		return false;
	}
	if(document.form_login.txtSenha.value=="") {
	alert('Preencha o Campo Senha!');
	document.form_login.txtSenha.focus();
	return false;
	}	
}	
function Valida_Anuncio() {
	if(document.form_cla.txtCategoria.value=="") {
		alert('Selecione uma Categoria!');
		document.form_cla.txtCategoria.focus();
		return false;
	}
	if(document.form_cla.txtProduto.value=="") {
	alert('Preencha o Campo Produto!');
	document.form_cla.txtProduto.focus();
	return false;
	}	
	if(document.form_cla.txtPreco.value=="") {
	alert('Preencha o Campo Preço!');
	document.form_cla.txtPreco.focus();
	return false;
	}	
	if(document.form_cla.txtQtd.value=="") {
	alert('Preencha o Campo Quantidade!');
	document.form_cla.txtQtd.focus();
	return false;
	}	
	if(document.form_cla.txtDescricao.value=="") {
	alert('Preencha o Campo Descrição do Produto!');
	document.form_cla.txtDescricao.focus();
	return false;
	}	
}	
