function ajaxInit() {
    var req;
    try{ 
     req = new ActiveXObject("Msxml2.XMLHTTP");
    }catch(e){
      try{
        req = new ActiveXObject("Microsoft.XMLHTTP");
      }catch(ex){
        try{
          req = new XMLHttpRequest();
        }catch(exc){
          alert("Esse browser nao tem recursos para uso do Ajax");
          req = false;
        }
      }
    }
    return req;
  }  
function abreconteudo(link,div){
  var resposta = ajaxInit();
      if(resposta){
        resposta.onreadystatechange = function() {
          if (resposta.readyState == 1){
            document.getElementById(div).innerHTML = "<div style=\"position:relative;top:10px;left:200px;\"><img src=\"img/preloader.gif\" /></div>";
          }
          if (resposta.readyState == 4) {
            if (resposta.status == 200) {
              document.getElementById(div).innerHTML = resposta.responseText;
            }else{
              alert("Houve um problema para conseguir os dados:\n"+ resposta.statusText);
            }
          }
        }
      }
  resposta.open("GET",link,true);
  resposta.send(null);
}
function cadastroexterno(camposform,idform,url,div){
  var resposta = ajaxInit();
  var parametros,destino;
  var destino = div;
  if(resposta){
    resposta.onreadystatechange = function() {
          if (resposta.readyState == 1){
            document.getElementById(destino).innerHTML = "<div style=\"position:relative;top:10px;left:200px;\"><img src=\"img/preloader.gif\" /></div>";
          }
          if (resposta.readyState == 4) {
            if (resposta.status == 200) {
              document.getElementById(destino).innerHTML = resposta.responseText;
            }else{
              alert("Houve um problema para conseguir os dados:\n"+ resposta.statusText);
            }
          }
        }
      }
      var campos = camposform;
      var camposexp = campos.split(";");
      var form = document.getElementById(idform);
      var conteudo = camposexp[0];
      var valor = form.elements[0].value;
      var parametros = conteudo + "=" + valor;//+"\n";
      var sep = "&";
      for(var i = 1 ;i < form.length; i++){
        if (idform != "curriculo"){
          conteudo = camposexp[i];
          valor = form.elements[i].value;
          parametros += sep + conteudo + "=" + valor;//+"\n";
        }
      }
    //alert(parametros);
    resposta.open("POST",url,true);
    resposta.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8"); 
    resposta.setRequestHeader("Content-length", parametros.length);
    resposta.send(parametros);
  }
function mudalink(id1,id2,id3){
  var atual = id1;
  var anterior = document.getElementById(id2);
  var anterior2 = document.getElementById(id3);
  atual.style.color ='#FF0000';
  anterior.style.color = '#000000';
  anterior2.style.color = '#000000';
}
function valida(campos, idformulario){
  var form = document.getElementById(idformulario);
  var campoerro = campos.split(";");
  var msg = "";
  for(i = 0; i < campoerro.length; i++){
    var valor = form.elements[i].value;
    if (valor.length < 1){
      msg += "O campo " + campoerro[i] +" não pode estar vazio!\n";
    }
  }
  if(msg.length < 1){
    form.submit();
  }else{
    alert(msg);
  }
}
function validanovidades(onde){
  var nome = document.getElementById('nome').value;
  var email = document.getElementById('email').value;
  var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/); 
  var res = true;
  if(nome == ""){
    alert("por favor digite seunome!");
    res = false;
  }
  if(typeof(email) == "string"){ 
    if(!er.test(email)) { 
      alert("O e-mail nÃ£o estÃ¡ correto"); 
      res = false; 
    }
  }
  
  if (res == true){
    if(onde != 'ecom'){
      cadastroexterno('nome_news;email_news','cadastro_news','recebe_news.php','dir');
    }else{
      cadastroexterno('nome_news;email_news','cadastro_news','recebe_news_ecom.php','cont_caixa_pq_news');
    }
  }
}  
function NewWindow(mypage, myname, w, h, scroll) {
  var winl = (screen.width - w) / 2;
  var wint = (screen.height - h) / 2;
  winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
  win = window.open(mypage, myname, winprops)
  if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}
function verifica2(pg, opcao, id_grupo, pg_grupo) {
res = true;
  if (opcao == "novo") {
     email1  = document.cadastro_email.email1.value;
     email2  = document.cadastro_email.email2.value;
     email3  = document.cadastro_email.email3.value;
     email4  = document.cadastro_email.email4.value;
     email5  = document.cadastro_email.email5.value;
     email6  = document.cadastro_email.email6.value;
     email7  = document.cadastro_email.email7.value;
     email8  = document.cadastro_email.email8.value;
     email9  = document.cadastro_email.email9.value;
     email10 = document.cadastro_email.email10.value;
    /*if (document.cadastro.email1.value == "") {
      alert("O e-mail não foi preenchido");
      res = false;
    }*/
    if ((email1 == "") && (email2 == "") && (email3 == "") && (email4 == "") && (email5 == "") && (email6 == "") && (email7 == "") && (email8 == "") && (email9 == "") && (email10 == "")) {
      alert("Nenhum e-mail foi preenchido");
      res = false;
    } if (email1 != "") {
      mail = document.cadastro_email.email1.value; 
      var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/); 
      if(typeof(mail) == "string"){ 
        if(!er.test(mail)) { 
          alert("O e-mail 1 não está correto"); 
          res = false; 
        }
      }
    } if (email2 != "") {
      mail = document.cadastro_email.email2.value; 
      var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/); 
      if(typeof(mail) == "string"){ 
        if(!er.test(mail)) { 
          alert("O e-mail 2 não está correto"); 
          res = false; 
        }
      }
    } if (email3 != "") {
      mail = document.cadastro_email.email3.value; 
      var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/); 
      if(typeof(mail) == "string"){ 
        if(!er.test(mail)) { 
          alert("O e-mail 3 não está correto"); 
          res = false; 
        }
      }
    } if (email4 != "") {
      mail = document.cadastro_email.email4.value; 
      var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/); 
      if(typeof(mail) == "string"){ 
        if(!er.test(mail)) { 
          alert("O e-mail 4 não está correto"); 
          res = false; 
        }
      }
    } if (email5 != "") {
      mail = document.cadastro_email.email5.value; 
      var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/); 
      if(typeof(mail) == "string"){ 
        if(!er.test(mail)) { 
          alert("O e-mail 5 não está correto"); 
          res = false; 
        }
      }
    } if (email6 != "") {
      mail = document.cadastro_email.email6.value; 
      var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/); 
      if(typeof(mail) == "string"){ 
        if(!er.test(mail)) { 
          alert("O e-mail 6 não está correto"); 
          res = false; 
        }
      }
    } if (email7 != "") {
      mail = document.cadastro_email.email7.value; 
      var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/); 
      if(typeof(mail) == "string"){ 
        if(!er.test(mail)) { 
          alert("O e-mail 7 não está correto"); 
          res = false; 
        }
      }
    } if (email8 != "") {
      mail = document.cadastro_email.email8.value; 
      var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/); 
      if(typeof(mail) == "string"){ 
        if(!er.test(mail)) { 
          alert("O e-mail 8 não está correto"); 
          res = false; 
        }
      }
    } if (email9 != "") {
      mail = document.cadastro_email.email9.value; 
      var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/); 
      if(typeof(mail) == "string"){ 
        if(!er.test(mail)) { 
          alert("O e-mail 9 não está correto"); 
          res = false; 
        }
      }
    } if (email10 != "") {
      mail = document.cadastro_email.email10.value; 
      var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/); 
      if(typeof(mail) == "string"){ 
        if(!er.test(mail)) { 
          alert("O e-mail 10 não está correto"); 
          res = false; 
        }
      }
    }
  } else {
    if (document.cadastro_email.email.value == "") {
      alert("O e-mail não foi preenchido");
      res = false;
    } else {
      mail = document.cadastro_email.email.value; 
      var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/); 
      if(typeof(mail) == "string"){ 
        if(!er.test(mail)) { 
          alert("O e-mail não está correto"); 
          res = false; 
        }
      }
    }
  }
  if (res == true) {
    if (opcao == "novo"){
      grava_novo_email(pg, id_grupo, pg_grupo);
    }else{
      grava_email(pg, id_grupo, pg_grupo);
    }
  }
}
function valida_email(campo){
var camp = campo.value;
var i,cont,ret;
i=0;
while(i<camp.length){
if(camp.charAt(i)=="@")
{
cont = 1;
break;
}
i++
}
if(cont!=1)
{
alert("Email invalido!!")
return false;
}
}

function validaCampo(campo){
  if(campo.value==""){
    alert ("o campo  " + campo.name + "  não pode ficar em branco!")
  }
}