function makeFlash(arquivo,id,largura,altura) {
    if (window.navigator.appName == "Microsoft Internet Explorer") {
        document.write('<object id="'+id+'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="'+largura+'" height="'+altura+'">');
        document.write('<param name="allowScriptAccess" value="sameDomain">');
        document.write('<param name="movie" value="'+arquivo+'">');
        document.write('<param name="quality" value="high">');
        document.write('<param name="menu" value="false">');
        //document.write('<param name="wmode" value="transparent">');
        document.write('<param name="salign" value="t">');
        document.write('</object>');

    }else{
        document.write('<embed src="'+arquivo+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+largura+'" height="'+altura+'" menu="false"></embed>');
    }
}
//Funcoes do display de produtos------------------------------------------------------------------------------------------------------------------
function displayProdutos(){
	ajax = objAjax();
	ajax.onreadystatechange=display;
	ajax.open("GET","requisicoes/display_produtos.php",true);
	ajax.setRequestHeader('encoding','ISO-8859-1');
    ajax.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
    ajax.setRequestHeader("Pragma", "no-cache");
    ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded, text/xml, charset=iso-8859-1');
    ajax.setRequestHeader("Connection", "close");
	ajax.send(null);
}
function display(){
	if (ajax.readyState==4){
		resposta = ajax.responseText;
		document.getElementById("produtos").innerHTML = resposta;
		window.setTimeout("displayProdutos()", 10000);
	}
}
//Funçõe de combo cidades / estado------------------------------------------------------------------------------------------------------------------
function buscaCidades(estado){
	ajax = objAjax();
	ajax.onreadystatechange = encheCombo;
    ajax.open("GET","requisicoes/cidades.php?estado="+estado,true);
    ajax.setRequestHeader('encoding','ISO-8859-1');
    ajax.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
    ajax.setRequestHeader("Pragma", "no-cache");
    ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded, text/xml, charset=iso-8859-1');
    ajax.setRequestHeader("Connection", "close");
    ajax.setRequestHeader('Content-Type','text/xml');
	ajax.send(null);
}
function encheCombo(){
	var select = document.getElementById('cidade');
	if (ajax.readyState <= 3){
		select.innerHTML = '';
		var op = document.createElement('option');
	    op.setAttribute('value', '');
	    op.appendChild(document.createTextNode("Carregando..."));
	    select.appendChild(op);
	}
	if (ajax.readyState == 4){			
		if (ajax.status == 200){
			select.innerHTML = '';
			var opcao = document.createElement('option');
			opcao.setAttribute('value', '');
			opcao.appendChild(document.createTextNode('Cidade'));
			select.appendChild(opcao);
			var xml = ajax.responseXML;			
			var cidade = xml.getElementsByTagName('cidade');
			for (var i = 0; i < cidade.length; i++){
				var idCidade = cidade[i].getElementsByTagName('id')[0].firstChild.nodeValue;
				var nomeCidade = cidade[i].getElementsByTagName('nome')[0].firstChild.nodeValue;
				var opcao = document.createElement('option');
				opcao.setAttribute('value', idCidade);
				opcao.appendChild(document.createTextNode(nomeCidade));
				select.appendChild(opcao);
			}
		}
	}
}
//Funcão que busca o CEP---------------------------------------------------------------------------------------------------------------------------
function buscaEndereco(cep){
	ajax = objAjax();
	cep = cep.replace("-", "");
	ajax.onreadystatechange=mostraCep;
	ajax.open("GET","../requisicoes/cep.php?cep="+cep,true);
    ajax.setRequestHeader('encoding','ISO-8859-1');
    ajax.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
    ajax.setRequestHeader("Pragma", "no-cache");
    ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded, text/xml, charset=iso-8859-1');
    ajax.setRequestHeader("Connection", "close");
	ajax.send(null);
}
function mostraCep(){
	if (ajax.readyState == 4){			
		if (ajax.status == 200){
			endereco = ajax.responseXML.getElementsByTagName('webservicecep')[0];
			document.getElementById('tipo').value = endereco.getElementsByTagName('tipo_logradouro')[0].firstChild.nodeValue;
			document.getElementById('endereco').value =  endereco.getElementsByTagName('logradouro')[0].firstChild.nodeValue;
			document.getElementById('bairro').value =  endereco.getElementsByTagName('bairro')[0].firstChild.nodeValue;
			document.getElementById('municipio').value =  endereco.getElementsByTagName('cidade')[0].firstChild.nodeValue;
			document.getElementById('uf').value =  endereco.getElementsByTagName('uf')[0].firstChild.nodeValue;
		}
	}
}
//Funcoes diversas----------------------------------------------------------------------------------------------------------------------------------
function MM_openBrWindow(theURL,winName,features) {
  window.open(theURL,winName,features);
}
function busca1(){
	MM_openBrWindow("paginas/resultado_produtos.php?palavra="+document.getElementById('palavra').value,"","location=no, toolbar=no, top=0, left=0, scrollbars=yes, width=950, height=650");
}

function busca2(){
	MM_openBrWindow("paginas/resultado_produtos.php?categoria="+document.getElementById('categoria').value+"&tipo="+document.getElementById('tipo').value+"&classe="+document.getElementById('classe').value+"&uf="+document.getElementById('uf').value+"&fabricante="+document.getElementById('fabricante').value+"&serie="+document.getElementById('serie').value+"&modelo="+document.getElementById('modelo').value+"&cidade="+document.getElementById('cidade').value+"&busca=sim","","location=no, top=0, left=0, toolbar=no, scrollbars=yes, width=950, height=650");
}
function ativa(x, y, text){
	document.getElementById('divAltCalendario').className = 'divAltCalendario';
	document.getElementById('divAltCalendario').style.left = x+5+'px';
	document.getElementById('divAltCalendario').style.top = y+'px';
	document.getElementById('divAltDesc').innerHTML=text;
}
function desativa(){
	document.getElementById('divAltCalendario').className = 'divAltCalendarioHide';
}
function VoltarCalendario(Mes, Ano){
	if(Mes == 1){
		Ano--;
		Mes = 12;
	}else{
		Mes--;
	}
	window.location = "?mes="+Mes+"&a="+Ano;
}
function AvancarCalendario(Mes, Ano){
	if(Mes == 12){
		Ano++;
		Mes = 1;
	}else{
		Mes++;
	}
	window.location = "?mes="+Mes+"&a="+Ano;
}
function linkTo(url) {
	window.location.href = url;	
}
contatos = 1;

function addContatos(){
	if (contatos < 3){
		contatos++;
		copia = document.getElementById('divContato1').innerHTML;
		var novo = document.createElement('div');
		novo.innerHTML = copia;
		novo.id = 'divContato'+contatos;
		document.getElementById('divContatos').appendChild(novo);
		document.getElementById('divContato'+contatos).getElementsByTagName('div')[0].firstChild.nodeValue = 'Contato Pessoa '+contatos;
		//novo.id = 'divContato'contatos+1;
		//novo.id = 'divContato'contatos+1;
		//novo.appendChild(copia);
		//document.getElementById('divContatos').innerHTML = document.getElementById('divContatos').innerHTML + novo.innerHTML;
	}
}

/* ********************** Formulario *************************** */

function validarCadastro() {
  var passou = true;
  var alerta = "O sistema encontrou os seguintes erros no preenchimento do formulário:\n\n";

  // validações dos campos gerais
  if (document.getElementById("razao_social").value == "") {
	 alert("Razão Social preenchido incorretamente.\n");
	 document.getElementById("razao_social").focus();
	 return false;
  }
  if (document.getElementById("nome_fantasia").value == "") {
	 alert("Nome Fantasia preenchido incorretamente.\n");
	 document.getElementById("nome_fantasia").focus();
	 return false;
  }
  if (document.getElementById("cnpj").value.length <= 17) {
	 alert("CNPJ preenchido incorretamente.\n");
	 document.getElementById("cnpj").focus();
	 return false;
  }
  if (document.getElementById("cep").value == "") {
	 alert("CEP preenchido incorretamente.\n");
	 document.getElementById("cep").focus();
	 return false;
  }
  if (document.getElementById("endereco").value == "") {
	 alert("Endereço preenchido incorretamente.\n");
	 document.getElementById("endereco").focus();
	 return false;
  }
  if (document.getElementById("municipio").value == "") {
	 alert("Município preenchido incorretamente.\n");
	 document.getElementById("municipio").focus();
	 return false;
  }
  if (document.getElementById("bairro").value == "") {
	 alert("Bairro preenchido incorretamente.\n");
	 document.getElementById("bairro").focus();
	 return false;
  }
  if (document.getElementById("email_corporativo").value == "") {	
     alert("E-mail preenchido incorretamente.\n");
	 document.getElementById("email_corporativo").focus();
	 return false;
  }
  if(!validarEmail(document.getElementById("email_corporativo").value)) {
   	alert("E-mail preenchido incorretamente.\n");
 	document.getElementById("email_corporativo").focus();
 	return false;
  }
  if (document.getElementById("ddd_telefone_corp").value == ""){
	 alert("DDD preenchido incorretamente.\n");
	 document.getElementById("ddd_telefone_corp").focus();
	 return false;
  }
  if (document.getElementById("telefone_cooperativo").value == ""){
	 alert("Telefone preenchido incorretamente.\n");
	 document.getElementById("telefone_cooperativo").focus();
	 return false;
  }	
  if (document.getElementById("nomeContato[]").value == "") {
	 	alert("Nome preenchido incorretamente.\n");
	 	document.getElementById("nomeContato[]").focus();
	 	return false;
  }
  if (document.getElementById("cargoContato[]").value == "") {
	 	alert("Cargo preenchido incorretamente.\n");
	 	document.getElementById("cargoContato[]").focus();
	 	return false;
  }
  if 	(document.getElementById("emailContato[]").value == "") {
		alert("E-mail preenchido incorretamente.\n");
		document.getElementById("emailContato[]").focus();
		return false;
  }
  if (!validarEmail(document.getElementById("emailContato[]").value)) {
	   alert("E-mail de contato preenchido incorretamente.\n");
		document.getElementById("emailContato[]").focus();
		return false;
	}   

  if (document.getElementById("nome_administrador").value == "") {	
	 alert("Nome do Administrador preenchido incorretamente.\n");
	 document.getElementById("nome_administrador").focus();
	 return false;
  }
  if (document.getElementById("email_adiministrador").value == "") {
     alert("E-mail Administrador preenchido incorretamente.\n");
	 document.getElementById("email_adiministrador").focus();
	 return false;
  }
  if (!validarEmail(document.getElementById("email_adiministrador").value)) {
     alert("E-mail Administrador preenchido incorretamente.\n");
	 document.getElementById("email_adiministrador").focus();
	 return false;
  }
  return true;
}
function validarAdmProdutos() {
	
  var passou = true;
  var alerta = "O sistema encontrou os seguintes erros no preenchimento do formulário:\n\n";

  // validações dos campos gerais
  
  if(document.getElementById("categoria").value == 0){
  	alert("Categoria preenchido incorretamente.");
  	return false;
  }
  
  if(document.getElementById("tipo").value == 0){
  	alert("Tipo preenchido incorretamente.");
  	return false;
  	
  }
  
  if(document.getElementById("classe").value == 0){
  	alert("Classes preenchido incorretamente.");
  	return false;
  }
  
  if(document.getElementById("serie").value == 0){
  	alert("Série preenchido incorretamente.");
  	return false;
  }
  
  if(document.getElementById("fabricante").value == 0){
  	alert("Fabricante preenchido incorretamente.");
  	return false;
  }
  
  if(document.getElementById("foto").value == ""){
  	alert("Foto preenchido incorretamente.");
  	return false;
  }
  
  if (document.getElementById("modelo").value == "") {
	 passou = false; alerta += "- Modelo preenchido incorretamente.\n";
  }
  if (document.getElementById("caracteristicas").value == "") {
	 passou = false; alerta += "- Caracteristicas preenchido incorretamente.\n";
  }
  if (document.getElementById("disponibilidade").value == "") {
	 passou = false; alerta += "- Disponibilidade preenchido incorretamente.\n";
  }
  if (passou == true) { return true; }
  else { alert(alerta); return false; }
  
 
}


function validarAdmPontoVista() {
  var passou = true;
  var alerta = "O sistema encontrou os seguintes erros no preenchimento do formulário:\n\n";

  // validações dos campos gerais
  if (document.getElementById("tituloNoticia").value == "") {
	 passou = false; alerta += "- Título da Notícia preenchido incorretamente.\n";
  }
  if (document.getElementById("texto_inicial").value == "") {
	 passou = false; alerta += "- Título Inicial preenchido incorretamente.\n";
  }
  if (document.getElementById("tituloLeiaMais").value == "") {
	 passou = false; alerta += "- Título Leia Mais preenchido incorretamente.\n";
  }
  if (document.getElementById("texto_completo_noticia").value == "") {
	 passou = false; alerta += "- Texto Completo preenchido incorretamente.\n";
  }
  if (passou == true) { return true; }
  else { alert(alerta); return false; }
}
function validarAdmEventos() {
  var passou = true;
  var alerta = "O sistema encontrou os seguintes erros no preenchimento do formulário:\n\n";

  // validações dos campos gerais
  if (document.getElementById("titulo").value == "") {
	 passou = false; alerta += "- Título preenchido incorretamente.\n";
  }
  if (document.getElementById("descricao").value == "") {
	 passou = false; alerta += "- Descrição preenchido incorretamente.\n";
  }
  if (document.getElementById("data").value == "") {
	 passou = false; alerta += "- Data do Evento preenchido incorretamente.\n";
  }
  if (passou == true) { return true; }
  else { alert(alerta); return false; }
}
function validarAdmEntrevista() {
  var passou = true;
  var alerta = "O sistema encontrou os seguintes erros no preenchimento do formulário:\n\n";

  // validações dos campos gerais
  if (document.getElementById("entrevistado").value == "") {
	 passou = false; alerta += "- Entrevistado preenchido incorretamente.\n";
  }
  if (document.getElementById("assunto").value == "") {
	 passou = false; alerta += "- Assunto preenchido incorretamente.\n";
  }
  if (document.getElementById("cargo").value == "") {
	 passou = false; alerta += "- Cargo preenchido incorretamente.\n";
  }
  if (document.getElementById("data").value == ""){
  	 passou = false; alerta += "- Data preenchido incorretamente.\n";
  }
  if (passou == true) { return true; }
  else { alert(alerta); return false; }
}
function validarAdmPubAnuncios() {
  var passou = true;
  var alerta = "O sistema encontrou os seguintes erros no preenchimento do formulário:\n\n";

  // validações dos campos gerais
  if (document.getElementById("titulo").value == "") {
	 passou = false; alerta += "- Título preenchido incorretamente.\n";
  }
  if (document.getElementById("link").value == "") {
	 passou = false; alerta += "- Link preenchido incorretamente.\n";
  }
  if (document.getElementById("texto_completo_noticia").value == "") {
	 passou = false; alerta += "- Texto preenchido incorretamente.\n";
  }
  if (passou == true) { return true; }
  else { alert(alerta); return false; }
}
function validarAssAddUsuario() {
  var passou = true;
  var alerta = "O sistema encontrou os seguintes erros no preenchimento do formulário:\n\n";

  // validações dos campos gerais
  if (document.getElementById("cargo").value == "") {
	 passou = false; alerta += "- Cargo preenchido incorretamente.\n";
  }
  if (document.getElementById("loginUsuario").value == "") {
	 passou = false; alerta += "- Login preenchido incorretamente.\n";
  }
  if (document.getElementById("senha").value == "") {
	 passou = false; alerta += "- Senha preenchido incorretamente.\n";
  }
  if (document.getElementById("confirmaSenha").value == "") {
	 passou = false; alerta += "- Confirmar Senha preenchido incorretamente.\n";
  }
  if (passou == true) { return true; }
  else { alert(alerta); return false; }
}
function validarAssAltCadastro() {
  var passou = true;
  var alerta = "O sistema encontrou os seguintes erros no preenchimento do formulário:\n\n";

  // validações dos campos gerais
  if (document.getElementById("cargo").value == "") {
	 passou = false; alerta += "- Cargo preenchido incorretamente.\n";
  }
  if (document.getElementById("loginUsuario").value == "") {
	 passou = false; alerta += "- Login preenchido incorretamente.\n";
  }
  if (document.getElementById("senha").value == "") {
	 passou = false; alerta += "- Senha preenchido incorretamente.\n";
  }
  if (document.getElementById("confirmaSenha").value == "") {
	 passou = false; alerta += "- Confirmar Senha preenchido incorretamente.\n";
  }
  if (passou == true) { return true; }
  else { alert(alerta); return false; }
}
function validarAssAltCadastro() {
  var passou = true;
  var alerta = "O sistema encontrou os seguintes erros no preenchimento do formulário:\n\n";

  // validações dos campos gerais
  if (document.getElementById("razaoSocial").value == "") {
	 passou = false; alerta += "- Razão Social preenchido incorretamente.\n";
  }
  if (document.getElementById("nomeFantasia").value == "") {
	 passou = false; alerta += "- Razão Fantasia preenchido incorretamente.\n";
  }
  if (document.getElementById("tipo").value == "") {
	 passou = false; alerta += "- Tipo preenchido incorretamente.\n";
  }
  if (document.getElementById("endereco").value == "") {
	 passou = false; alerta += "- Endereço preenchido incorretamente.\n";
  }
  if (document.getElementById("numero").value == "") {
	 passou = false; alerta += "- Numero preenchido incorretamente.\n";
  }
  if (document.getElementById("municipio").value == "") {
	 passou = false; alerta += "- Município preenchido incorretamente.\n";
  }
  if (document.getElementById("bairro").value == "") {
	 passou = false; alerta += "- Bairro preenchido incorretamente.\n";
  }
  if (document.contato.email.value == "") {
     passou = false; alerta += "- E-mail preenchido incorretamente.\n";
  }else{
      if (!validarEmail(document.contato.email.value)) {
           passou = false; alerta += "- E-mail preenchido incorretamente.\n";
      }
  }
  if (document.getElementById("website").value == "") {
	 passou = false; alerta += "- Website preenchido incorretamente.\n";
  }
  if (document.getElementById("nome").value == "") {
	 passou = false; alerta += "- Nome preenchido incorretamente.\n";
  }
  if (document.getElementById("cargoContato").value == "") {
	 passou = false; alerta += "- Cargo preenchido incorretamente.\n";
  }
  if (document.contato.emailContato.value == "") {
     passou = false; alerta += "- E-mail preenchido incorretamente.\n";
  }else{
      if (!validarEmail(document.contato.emailContato.value)) {
           passou = false; alerta += "- E-mail preenchido incorretamente.\n";
      }
  }
  if (passou == true) { return true; }
  else { alert(alerta); return false; }
}
function validarAssAltSenha() {
  var passou = true;
  var alerta = "O sistema encontrou os seguintes erros no preenchimento do formulário:\n\n";

  // validações dos campos gerais
  if (document.getElementById("novaSenha").value == "") {
	 passou = false; alerta += "- Senha preenchido incorretamente.\n";
  }
  if (document.getElementById("confirmarSenha").value == "") {
	 passou = false; alerta += "- Confirmar Senha preenchido incorretamente.\n";
  }
  if (passou == true) { return true; }
  else { alert(alerta); return false; }
}
function validarCadEngenheiro() {
  var passou = true;
  var alerta = "O sistema encontrou os seguintes erros no preenchimento do formulário:\n\n";

  // validações dos campos gerais
  if (document.getElementById("razaoSocial").value == "") {
	 passou = false; alerta += "- Razão Social preenchido incorretamente.\n";
  }
  if (document.getElementById("nomeFantasia").value == "") {
	 passou = false; alerta += "- Razão Fantasia preenchido incorretamente.\n";
  }
  if (document.getElementById("nome").value == "") {
	 passou = false; alerta += "- Nome preenchido incorretamente.\n";
  }
  if (document.getElementById("tipo").value == "") {
	 passou = false; alerta += "- Tipo preenchido incorretamente.\n";
  }
  if (document.getElementById("endereco").value == "") {
	 passou = false; alerta += "- Endereço preenchido incorretamente.\n";
  }
  if (document.getElementById("numero").value == "") {
	 passou = false; alerta += "- Numero preenchido incorretamente.\n";
  }
  if (document.getElementById("municipio").value == "") {
	 passou = false; alerta += "- Município preenchido incorretamente.\n";
  }
  if (document.getElementById("bairro").value == "") {
	 passou = false; alerta += "- Bairro preenchido incorretamente.\n";
  }
  if (document.contato.email.value == "") {
     passou = false; alerta += "- E-mail preenchido incorretamente.\n";
  }else{
      if (!validarEmail(document.contato.email.value)) {
           passou = false; alerta += "- E-mail preenchido incorretamente.\n";
      }
  }
  if (document.getElementById("website").value == "") {
	 passou = false; alerta += "- Website preenchido incorretamente.\n";
  }
  if (document.getElementById("nomeContato").value == "") {
	 passou = false; alerta += "- Nome preenchido incorretamente.\n";
  }
  if (document.getElementById("cargoContato").value == "") {
	 passou = false; alerta += "- Cargo preenchido incorretamente.\n";
  }
  if (document.contato.emailContato.value == "") {
     passou = false; alerta += "- E-mail preenchido incorretamente.\n";
  }else{
      if (!validarEmail(document.contato.emailContato.value)) {
           passou = false; alerta += "- E-mail preenchido incorretamente.\n";
      }
  }
  if (document.getElementById("nomeMaster").value == "") {
	 passou = false; alerta += "- Nome preenchido incorretamente.\n";
  }
  if (document.contato.emailMaster.value == "") {
     passou = false; alerta += "- E-mail preenchido incorretamente.\n";
  }else{
      if (!validarEmail(document.contato.emailMaster.value)) {
           passou = false; alerta += "- E-mail preenchido incorretamente.\n";
      }
  }
  if (passou == true) { return true; }
  else { alert(alerta); return false; }
}
function validarConsumidor() {
  var passou = true;
  var alerta = "O sistema encontrou os seguintes erros no preenchimento do formulário:\n\n";

  // validações dos campos gerais
  if (document.getElementById("razaoSocial").value == "") {
	 passou = false; alerta += "- Razão Social preenchido incorretamente.\n";
  }
  if (document.getElementById("nomeFantasia").value == "") {
	 passou = false; alerta += "- Razão Fantasia preenchido incorretamente.\n";
  }
  if (document.getElementById("segmento").value == "") {
	 passou = false; alerta += "- Principal Segmento preenchido incorretamente.\n";
  }
  if (document.getElementById("tipo").value == "") {
	 passou = false; alerta += "- Tipo preenchido incorretamente.\n";
  }
  if (document.getElementById("endereco").value == "") {
	 passou = false; alerta += "- Endereço preenchido incorretamente.\n";
  }
  if (document.getElementById("numero").value == "") {
	 passou = false; alerta += "- Numero preenchido incorretamente.\n";
  }
  if (document.getElementById("municipio").value == "") {
	 passou = false; alerta += "- Município preenchido incorretamente.\n";
  }
  if (document.getElementById("bairro").value == "") {
	 passou = false; alerta += "- Bairro preenchido incorretamente.\n";
  }
  if (document.contato.email.value == "") {
     passou = false; alerta += "- E-mail preenchido incorretamente.\n";
  }else{
      if (!validarEmail(document.contato.email.value)) {
           passou = false; alerta += "- E-mail preenchido incorretamente.\n";
      }
  }
  if (document.getElementById("website").value == "") {
	 passou = false; alerta += "- Website preenchido incorretamente.\n";
  }
  if (document.getElementById("nomeContato").value == "") {
	 passou = false; alerta += "- Nome preenchido incorretamente.\n";
  }
  if (document.getElementById("cargoContato").value == "") {
	 passou = false; alerta += "- Cargo preenchido incorretamente.\n";
  }
  if (document.contato.emailContato.value == "") {
     passou = false; alerta += "- E-mail preenchido incorretamente.\n";
  }else{
      if (!validarEmail(document.contato.emailContato.value)) {
           passou = false; alerta += "- E-mail preenchido incorretamente.\n";
      }
  }
  if (document.getElementById("nomeMaster").value == "") {
	 passou = false; alerta += "- Nome preenchido incorretamente.\n";
  }
  if (document.contato.emailMaster.value == "") {
     passou = false; alerta += "- E-mail preenchido incorretamente.\n";
  }else{
      if (!validarEmail(document.contato.emailMaster.value)) {
           passou = false; alerta += "- E-mail preenchido incorretamente.\n";
      }
  }
  if (passou == true) { return true; }
  else { alert(alerta); return false; }
}
function validarOpiniao() {
  var passou = true;
  var alerta = "O sistema encontrou os seguintes erros no preenchimento do formulário:\n\n";

  // validações dos campos gerais
/*
  if (document.getElementById("loginUsuario").value == "") {
	 passou = false; alerta += "- Login preenchido incorretamente.\n";
  }
  if (document.getElementById("senha").value == "") {
	 passou = false; alerta += "- Senha preenchido incorretamente.\n";
  }
*/
  if (document.getElementById("nome").value == "") {
	 passou = false; alerta += "- Nome preenchido incorretamente.\n";
  }
  if (document.getElementById("opiniao").value == "") {
	 passou = false; alerta += "- Opinião preenchido incorretamente.\n";
  }
  if (passou == true) { return true; }
  else { alert(alerta); return false; }
}
function validarAeresp() {
  var passou = true;
  var alerta = "O sistema encontrou os seguintes erros no preenchimento do formulário:\n\n";

  // validações dos campos gerais
  if (document.getElementById("nome").value == "") {
	 passou = false; alerta += "- Nome preenchido incorretamente.\n";
  }
  if (document.contato.email.value == "") {
     passou = false; alerta += "- E-mail preenchido incorretamente.\n";
  }else{
      if (!validarEmail(document.contato.email.value)) {
           passou = false; alerta += "- E-mail preenchido incorretamente.\n";
      }
  }  
  if (document.getElementById("empresa").value == "") {
	 passou = false; alerta += "- Empresa preenchido incorretamente.\n";
  }
  if (document.getElementById("departamento").value == "") {
	 passou = false; alerta += "- Departamento preenchido incorretamente.\n";
  }
  if (document.getElementById("cargoAtual").value == "") {
	 passou = false; alerta += "- Cargo Atual preenchido incorretamente.\n";
  }
  if (document.getElementById("endereco").value == "") {
	 passou = false; alerta += "- Endereço preenchido incorretamente.\n";
  }
  if (document.getElementById("opiniao").value == "") {
	 passou = false; alerta += "- Opinião preenchido incorretamente.\n";
  }
  if (passou == true) { return true; }
  else { alert(alerta); return false; }
}
function validarOuvidoria() {
  var passou = true;
  var alerta = "O sistema encontrou os seguintes erros no preenchimento do formulário:\n\n";

  // validações dos campos gerais
  if (document.getElementById("nome").value == "") {
	 passou = false; alerta += "- Nome preenchido incorretamente.\n";
  }
  if (document.getElementById("opiniao").value == "") {
	 passou = false; alerta += "- Opinião preenchido incorretamente.\n";
  }
  if (passou == true) { return true; }
  else { alert(alerta); return false; }
}
function validarPublicidade() {
  var passou = true;
  var alerta = "O sistema encontrou os seguintes erros no preenchimento do formulário:\n\n";

  // validações dos campos gerais
  if (document.getElementById("categoria").value == "") {
	 passou = false; alerta += "- Nome da categoria preenchido incorretamente.\n";
  }
  if (passou == true) { return true; }
  else { alert(alerta); return false; }
}
function validarEmail(email) {
	if(email.indexOf("@") != -1 && email.indexOf(".") != -1){
		return true;
	}else{
		return false;
	}
}


//Mascaras de formulários_----------------------------------------------------------------------------------------------------
function mascaraCNPJ(campo, teclapres){
	var tecla = teclapres.keyCode;
	var vr = new String(campo.value);
	vr = vr.replace(".", "");
	vr = vr.replace("/", "");
	vr = vr.replace("-", "");
	tam = vr.length + 1;
	if (tecla != 8){
		if (tam == 3)
			campo.value = vr.substr(0, 2) + '.';
		if (tam == 6)
			campo.value = vr.substr(0, 2) + '.' + vr.substr(2, 5) + '.';
		if (tam == 10)
			campo.value = vr.substr(0, 2) + '.' + vr.substr(2, 3) + '.' + vr.substr(6, 3) + '/';
		if (tam == 15)
			campo.value = vr.substr(0, 2) + '.' + vr.substr(2, 3) + '.' + vr.substr(6, 3) + '/' + vr.substr(9, 4) + '-' + vr.substr(13, 2);
	}
}
function mascaraNumeros(e){
	navegador = /msie/i.test(navigator.userAgent);
    var tecla = e.keyCode;
	if (tecla ==""){
		var tecla= e.which;
	}
	if (tecla ==""){
		var tecla= e.charCode;
	}
	if(tecla==9){
		return true;
	}else{
		if(tecla==44 || tecla==46){
			return true;
		}
	     if (tecla > 47 && tecla < 58){
	         return true;
	     }else{  
	         if (tecla == 8){
	             return true;
	         }else{
	             return false;
	         }
	     }
	}
}
function mascaraCEP(campo, e){
	var tecla = e.keyCode;
	var vr = new String(campo.value);
	vr = vr.replace("-", "");
	tam = vr.length + 1;
	if (tecla != 8){
		if (tam == 6){
			campo.value = vr.substr(0, 5) + '-' + vr.substr(6, 6);
		}
	}
}

function maskd(campo){
 if (campo.value.length == 2){
	 campo.value += '/';
 }
 if (campo.value.length == 5){
 	campo.value += '/';
 }
} 
function mascaraTelefone(campo, e){
	var tecla = e.keyCode;
	if (tecla ==""){
		var tecla= e.which;
	}
	if (tecla ==""){
		var tecla= e.charCode;
	}
	var vr = new String(campo.value);
	vr = vr.replace("-", "");
	tam = vr.length + 1;
	if (tecla != 8 && tecla!=9){
		if (tam == 5){
			campo.value = vr.substr(0, 4) + '-' + vr.substr(6, 4);
		}
	}
}



//funcao do ricardo teste

function buscaCep(){
	
	var cep = document.getElementById("cep").value;
//	var c = cep.replace("-", "");
	
	ajax = objAjax();
	ajax.onreadystatechange=function(){
		if(ajax.readyState == 4){
			var xml = ajax.responseXML;
			
			//var res = xml.getElementsByTagName("webservicecep")[0];
			
			var result = xml.getElementsByTagName("resultado")[0].firstChild.nodeValue;
			
			if(result == 1){
				var uf 		=	  xml.getElementsByTagName("uf")[0].firstChild.nodeValue;
				var cid 	= 	  xml.getElementsByTagName("cidade")[0].firstChild.nodeValue;
				var bai 	=	  xml.getElementsByTagName("bairro")[0].firstChild.nodeValue;
				var tip_l	=	  xml.getElementsByTagName("tipo_logradouro")[0].firstChild.nodeValue;
				var log     =     xml.getElementsByTagName("logradouro")[0].firstChild.nodeValue;
				
				document.getElementById('tipo').value 		=	 tip_l;
				document.getElementById('endereco').value 	=  	 log;
				document.getElementById('bairro').value 	=    bai;
				document.getElementById('municipio').value  =  	 cid;
				document.getElementById('uf').value 		=  	 uf;
			}else if (result == 0){
				var erro    =     xml.getElementsByTagName("erro")[0].firstChild.nodeValue;
				alert(erro);
			}
		}
	}
	ajax.open("GET","../requisicoes/busca_cep.php?cep="+cep,true);
	ajax.send(null);
}
function numeros(e){
	if(e.keyCode){
		tecla = e.keyCode;
	}else{
		tecla= e.which;
	}
	if (tecla >= 48 && tecla <= 57 || tecla==8 || tecla==9){
	    return true;
	}else{
	    return false;
	}
}
/*$(document).ready(function(){
	$("#busca_cep").click(function(){
		if($("#campoCEP").val() != ""){
			var cep = $("#campoCEP").val();
			$.post("ajax.php", { "cep": cep, "campo": "rua"}, function(retorna_cep){			
				$("#rua").val("");			
				$("#rua").val(retorna_cep);
			});
			$.post("ajax.php", { "cep": cep, "campo": "cidade"}, function(retorna_cep){			
				$("#cidade").val("");
				$("#cidade").val(retorna_cep);
			});
			$.post("ajax.php", { "cep": cep, "campo": "bairro"}, function(retorna_cep){			
				$("#bairro").val("");
				$("#bairro").val(retorna_cep);
			});
			$.post("ajax.php", { "cep": cep, "campo": "uf"}, function(retorna_cep){			
				$("#uf").val("");
				$("#uf").val(retorna_cep);
			});
			$.post("ajax.php", { "cep": cep, "campo": "tipo_logradouro"}, function(retorna_cep){			
				$("#tipo_logradouro").val("");
				$("#tipo_logradouro").val(retorna_cep);
			});
			$.post("ajax.php", { "cep": cep, "campo": "cidade"}, function(retorna_cep){			
				$("#cidade").val("");
				$("#cidade").val(retorna_cep);				
			});
		}else{
			alert("Favor preencher campo CEP.");
		}
	});
});*/
function habilitamotorola(){
	var x = document.getElementById("tipo_motorola");	
	if(x.disabled == true){
		x.disabled = false;
	}
	else{
		x.disabled = true;
		x.value = "t";
	}
}

//valida o CPF digitado
function ValidarCPF(Objcpf){
    var cpf = Objcpf.value;
    exp = /\.|\-/g
    cpf = cpf.toString().replace( exp, "" ); 
    var digitoDigitado = eval(cpf.charAt(9)+cpf.charAt(10));
    var soma1=0, soma2=0;
    var vlr =11;
    
    for(i=0;i<9;i++){
        soma1+=eval(cpf.charAt(i)*(vlr-1));
        soma2+=eval(cpf.charAt(i)*vlr);
        vlr--;
    }    
    soma1 = (((soma1*10)%11)==10 ? 0:((soma1*10)%11));
    soma2=(((soma2+(2*soma1))*10)%11);
    
    var digitoGerado=(soma1*10)+soma2;
        


if(digitoGerado!=digitoDigitado) {
		 cadastro_revenda.cpfvalido.value = 'errado';  
       
}

if(digitoGerado==digitoDigitado) {
		 cadastro_revenda.cpfvalido.value = 'certo';  
		 }

}

// Dingolandia Alterações para cadastro de engenheiro acesse www.com.br

function CadastroEngDin() {
  var passou = true;
  var alerta = "O sistema encontrou os seguintes erros no preenchimento do formulário:\n\n";

  // validações dos campos gerais
  if (document.getElementById("razao_social").value == "") {
	 alert("Razão Social preenchido incorretamente.\n");
	 document.getElementById("razao_social").focus();
	 return false;
  }
  if (document.getElementById("nome_fantasia").value == "") {
	 alert("Nome Fantasia preenchido incorretamente.\n");
	 document.getElementById("nome_fantasia").focus();
	 return false;
  }
  if (document.getElementById("cnpj").value != ""){
  		if (document.getElementById("cnpj").value.length <= 17) {
	 		alert("CNPJ preenchido incorretamente.\n");
	 		document.getElementById("cnpj").focus();
	 			return false;
  		}
  }
  if (document.getElementById("cep").value == "") {
	 alert("CEP preenchido incorretamente.\n");
	 document.getElementById("cep").focus();
	 return false;
  }
  if (document.getElementById("endereco").value == "") {
	 alert("Endereço preenchido incorretamente.\n");
	 document.getElementById("endereco").focus();
	 return false;
  }
  if (document.getElementById("municipio").value == "") {
	 alert("Município preenchido incorretamente.\n");
	 document.getElementById("municipio").focus();
	 return false;
  }
  if (document.getElementById("bairro").value == "") {
	 alert("Bairro preenchido incorretamente.\n");
	 document.getElementById("bairro").focus();
	 return false;
  }
  if (document.getElementById("email_corporativo").value == "") {	
     alert("E-mail preenchido incorretamente.\n");
	 document.getElementById("email_corporativo").focus();
	 return false;
  }
  if(!validarEmail(document.getElementById("email_corporativo").value)) {
   	alert("E-mail preenchido incorretamente.\n");
 	document.getElementById("email_corporativo").focus();
 	return false;
  }
  if (document.getElementById("ddd_telefone_corp").value == ""){
	 alert("DDD preenchido incorretamente.\n");
	 document.getElementById("ddd_telefone_corp").focus();
	 return false;
  }
  if (document.getElementById("telefone_cooperativo").value == ""){
	 alert("Telefone preenchido incorretamente.\n");
	 document.getElementById("telefone_cooperativo").focus();
	 return false;
  }	
  if (document.getElementById("nomeContato[]").value == "") {
	 	alert("Nome preenchido incorretamente.\n");
	 	document.getElementById("nomeContato[]").focus();
	 	return false;
  }
  if (document.getElementById("cargoContato[]").value == "") {
	 	alert("Cargo preenchido incorretamente.\n");
	 	document.getElementById("cargoContato[]").focus();
	 	return false;
  }
  if 	(document.getElementById("emailContato[]").value == "") {
		alert("E-mail preenchido incorretamente.\n");
		document.getElementById("emailContato[]").focus();
		return false;
  }
  if (!validarEmail(document.getElementById("emailContato[]").value)) {
	   alert("E-mail de contato preenchido incorretamente.\n");
		document.getElementById("emailContato[]").focus();
		return false;
	}   

  if (document.getElementById("nome_administrador").value == "") {	
	 alert("Nome do Administrador preenchido incorretamente.\n");
	 document.getElementById("nome_administrador").focus();
	 return false;
  }
  if (document.getElementById("email_adiministrador").value == "") {
     alert("E-mail Administrador preenchido incorretamente.\n");
	 document.getElementById("email_adiministrador").focus();
	 return false;
  }
  if (!validarEmail(document.getElementById("email_adiministrador").value)) {
     alert("E-mail Administrador preenchido incorretamente.\n");
	 document.getElementById("email_adiministrador").focus();
	 return false;
  }
  return true;
}

function validaPerguntaResposta(){
	var pergunta = document.getElementById("pergunta").value;
	var resposta = document.getElementById("resposta").value;
	
	if(pergunta == ""){
		alert("Informe a pergunta.");
		return false;
	}
	
	if(resposta == ""){
		alert("Informe a resposta.");
		return false;
	}
	return true;
}

// Dingolandia Alterações para cadastro de engenheiro acesse www.com.br

function CadastroEngDin() {
  var passou = true;
  var alerta = "O sistema encontrou os seguintes erros no preenchimento do formulário:\n\n";

  // validações dos campos gerais
  if (document.getElementById("razao_social").value == "") {
	 alert("Razão Social preenchido incorretamente.\n");
	 document.getElementById("razao_social").focus();
	 return false;
  }
  if (document.getElementById("nome_fantasia").value == "") {
	 alert("Nome Fantasia preenchido incorretamente.\n");
	 document.getElementById("nome_fantasia").focus();
	 return false;
  }
  if (document.getElementById("cnpj").value != ""){
  		if (document.getElementById("cnpj").value.length <= 17) {
	 		alert("CNPJ preenchido incorretamente.\n");
	 		document.getElementById("cnpj").focus();
	 			return false;
  		}
  }
  if (document.getElementById("cep").value == "") {
	 alert("CEP preenchido incorretamente.\n");
	 document.getElementById("cep").focus();
	 return false;
  }
  if (document.getElementById("endereco").value == "") {
	 alert("Endereço preenchido incorretamente.\n");
	 document.getElementById("endereco").focus();
	 return false;
  }
  if (document.getElementById("municipio").value == "") {
	 alert("Município preenchido incorretamente.\n");
	 document.getElementById("municipio").focus();
	 return false;
  }
  if (document.getElementById("bairro").value == "") {
	 alert("Bairro preenchido incorretamente.\n");
	 document.getElementById("bairro").focus();
	 return false;
  }
  if (document.getElementById("email_corporativo").value == "") {	
     alert("E-mail preenchido incorretamente.\n");
	 document.getElementById("email_corporativo").focus();
	 return false;
  }
  if(!validarEmail(document.getElementById("email_corporativo").value)) {
   	alert("E-mail preenchido incorretamente.\n");
 	document.getElementById("email_corporativo").focus();
 	return false;
  }
  if (document.getElementById("ddd_telefone_corp").value == ""){
	 alert("DDD preenchido incorretamente.\n");
	 document.getElementById("ddd_telefone_corp").focus();
	 return false;
  }
  if (document.getElementById("telefone_cooperativo").value == ""){
	 alert("Telefone preenchido incorretamente.\n");
	 document.getElementById("telefone_cooperativo").focus();
	 return false;
  }	
  if (document.getElementById("nomeContato[]").value == "") {
	 	alert("Nome preenchido incorretamente.\n");
	 	document.getElementById("nomeContato[]").focus();
	 	return false;
  }
  if (document.getElementById("cargoContato[]").value == "") {
	 	alert("Cargo preenchido incorretamente.\n");
	 	document.getElementById("cargoContato[]").focus();
	 	return false;
  }
  if 	(document.getElementById("emailContato[]").value == "") {
		alert("E-mail preenchido incorretamente.\n");
		document.getElementById("emailContato[]").focus();
		return false;
  }
  if (!validarEmail(document.getElementById("emailContato[]").value)) {
	   alert("E-mail de contato preenchido incorretamente.\n");
		document.getElementById("emailContato[]").focus();
		return false;
	}   

  if (document.getElementById("nome_administrador").value == "") {	
	 alert("Nome do Administrador preenchido incorretamente.\n");
	 document.getElementById("nome_administrador").focus();
	 return false;
  }
  if (document.getElementById("email_adiministrador").value == "") {
     alert("E-mail Administrador preenchido incorretamente.\n");
	 document.getElementById("email_adiministrador").focus();
	 return false;
  }
  if (!validarEmail(document.getElementById("email_adiministrador").value)) {
     alert("E-mail Administrador preenchido incorretamente.\n");
	 document.getElementById("email_adiministrador").focus();
	 return false;
  }
  return true;
}

function validaPerguntaResposta(){
	var pergunta = document.getElementById("pergunta").value;
	var resposta = document.getElementById("resposta").value;
	
	if(pergunta == ""){
		alert("Informe a pergunta.");
		return false;
	}
	
	if(resposta == ""){
		alert("Informe a resposta.");
		return false;
	}
	return true;
}

function habilitaCampos(valor,id_txt,id_input){
	c = document.getElementById(id_input);
	t = document.getElementById(id_txt);
	if(valor == '1'){
		c.style.display='inline';
		t.style.display='inline';
	}else{
		c.style.display='none';
		t.style.display='none';
	}
	
	
}

function validaBolsa(){
	if (document.getElementById("nome_produto").value == "") {	
	 alert("Nome do produto preenchido incorretamente.\n");
	 document.getElementById("nome_produto").focus();
	 return false;
  }
  if (document.getElementById("descricao").value == "") {	
	 alert("Descrição do produto preenchido incorretamente.\n");
	 document.getElementById("descricao").focus();
	 return false;
  }
  if (document.getElementById("fabricante").value == "0") {	
	 alert("Escolha um fabricante ou cadastre um Novo.\n");
	 document.getElementById("fabricante").focus();
	 return false;
  }
  if (document.getElementById("tipo").value == "0") {	
	 alert("Escolha um tipo ou cadastre um Novo.\n");
	 document.getElementById("tipo").focus();
	 return false;
  }
  if (document.getElementById("vr_unitario").value == "") {	
	 alert("Valor unitário do produto preenchido incorretamente.\n");
	 document.getElementById("vr_unitario").focus();
	 return false;
  }
  if (document.getElementById("vr_total").value == "") {	
	 alert("Valor total do produto preenchido incorretamente.\n");
	 document.getElementById("vr_total").focus();
	 return false;
  }
  if (document.getElementById("quantidade").value == "") {	
	 alert("Quantidade de produto preenchido incorretamente.\n");
	 document.getElementById("quantidade").focus();
	 return false;
  }
  if (document.getElementById("nota").value == "") {	
	 alert("Campo Nota preenchido incorretamente.\n");
	 document.getElementById("nota").focus();
	 return false;
  }
  return true;
}