var ie=(((navigator.userAgent.indexOf("MSIE")>-1)||(navigator.userAgent.indexOf("Mozilla/5.0")>-1))&&navigator.userAgent.indexOf("Opera")==-1?true:false);
var ns=(navigator.userAgent.indexOf("Netscape")>-1&&navigator.userAgent.indexOf("Opera")==-1?true:false);
//---------------

//#######################################################
// Caixa de confirmação                                //
//#######################################################
function ConfirmBox(msg,link) {
  if (confirm(msg)) {
    location.href=link;
  }
}

//#######################################################
// Caixa de confirmação                                //
//#######################################################
function ConfirmBox2(msg) {
  if (confirm(msg)) {
    return true;
  } else {
    return false;
  }
}

//#######################################################
// Valida Data                                         //
//#######################################################
function ValidarData(pStr) {
  var reDate1 = /^\d{1,2}\/\d{1,2}\/\d{1,4}$/;
  var reDate2 = /^[0-3]?\d\/[01]?\d\/(\d{2}|\d{4})$/;
  var reDate3 = /^(0?[1-9]|[12]\d|3[01])\/(0?[1-9]|1[0-2])\/(19|20)?\d{2}$/;
  var reDate4 = /^((0?[1-9]|[12]\d)\/(0?[1-9]|1[0-2])|30\/(0?[13-9]|1[0-2])|31\/(0?[13578]|1[02]))\/(19|20)?\d{2}$/;
  var reDate5 = /^((0[1-9]|[12]\d)\/(0[1-9]|1[0-2])|30\/(0[13-9]|1[0-2])|31\/(0[13578]|1[02]))\/\d{4}$/;
  var reDate = reDate4;
  eval("reDate = reDate");
  if (reDate.test(pStr.value)) { //nothing.
  } else
  if (pStr.value != null && pStr.value != "") {
    alert(pStr.value + " NÃO é uma data válida.");
    pStr.value="";
    pStr.focus();
  }
} // doDate

//#######################################################
// Formata campos CPF ou CNPJ                          //
//#######################################################
function ajustar_cnpj_cpf(input) {
  var valor= input.value;
  var valorsemchar="";
  var valornovo="";
  //retira os pontos, traços e barras.
  for (var i=0;i<valor.length;i++) {
    if ((valor.charAt(i)!='.') && ( valor.charAt(i)!='-') && (valor.charAt(i)!='/')) {
      valorsemchar=valorsemchar+valor.charAt(i);
    }
  }
  //se for CPF...........
  if (valorsemchar.length==11) {
    for (var i=0;i<11;i++) {
      if ((i==3) || (i==6)) { valornovo=valornovo+'.'; }
      if (i==9) { valornovo=valornovo+'-'; }
      valornovo=valornovo+valorsemchar.charAt(i);
    }
    input.value=valornovo ;
  } else
    //se for CNPJ...........
    if (valorsemchar.length==14) {
      for (var i=0;i<14;i++) {
        if ((i==2) || (i==5)) { valornovo=valornovo+'.'; }
        if (i==8) { valornovo=valornovo+'/'; }
        if (i==12) { valornovo=valornovo+'-'; }
        valornovo=valornovo+valorsemchar.charAt(i);
      }
      input.value=valornovo;
    } else {
      //se não for nenhum dos dois..........
      input.value='';
      alert('CPF ou CNPJ inválido!');
    }
  return true;
}
																		
//#######################################################
// Formata campos CNPJ                                 //
//#######################################################
function formatar_cnpj_blur(input) {
  var valor=input.value;
  var valorsemchar="";
  var valornovo="";
  //retira os pontos, traços e barras.
  for (var i=0;i<valor.length;i++) {
    if ((valor.charAt(i)!='.') && ( valor.charAt(i)!='-') && (valor.charAt(i)!='/')) {
      valorsemchar=valorsemchar+valor.charAt(i);
    }
  }
  //se tiver 14 digitos...........
  if (valorsemchar.length==14) {
    for (var i=0;i<14;i++) {
      if ((i==2) || (i==5)) { valornovo=valornovo+'.'; }
      if (i==8) { valornovo=valornovo+'/'; }
      if (i==12) { valornovo=valornovo+'-'; }
      valornovo=valornovo+valorsemchar.charAt(i);
    }
    input.value=valornovo;
  } else {
    //se não tiver..........
    input.value='';
    alert('CNPJ inválido!');
  }
  return true;
}

//#######################################################
// Formata campos CNPJ                                 //
//#######################################################
function ajustar_cnpj(input, evento) {
  var BACKSPACE=8;
  var TAB=9;
  var DEL=46;
  var FRENTE=39;
  var TRAS=37;
  var HOME=36;
  var END=35;
  var tecla=(evento.keyCode ? evento.keyCode: evento.which ? evento.which : evento.charCode)
  if ((tecla == BACKSPACE )||
      (tecla == DEL)||
      (tecla == FRENTE)||
      (tecla == TRAS)||
      (tecla == TAB)||
      (tecla == HOME)||
      (tecla == END)) { return true; }
  if (tecla == 13 ) { return false; }
  if ((tecla<48)||(tecla>57)) {
    evento.returnValue =false;
    return false;
  } else {
    if ((input.value.length==2)||(input.value.length==6)) { input.value=input.value + "." ; }
    else
    if (input.value.length==10) { input.value=input.value + "/" ; }
    else
    if (input.value.length==15) { input.value=input.value + "-" ; }
  }
  return true;
}

//#######################################################
// Formata campos CPF                                  //
//#######################################################
function formatar_cpf_blur(input) {
  var valor=input.value;
  var valorsemchar="";
  var valornovo="";
  //retira os pontos, traços e barras.
  for (var i=0;i<valor.length;i++) {
    if ((valor.charAt(i)!='.') && ( valor.charAt(i)!='-') && (valor.charAt(i)!='/')) {
      valorsemchar=valorsemchar+valor.charAt(i);
    }
  }
  //se tiver 11 digitos...........
  if (valorsemchar.length==11) {
    for (var i=0;i<11;i++) {
      if ((i==3) || (i==6)) { valornovo=valornovo+'.'; }
      if (i==9) { valornovo=valornovo+'-'; }
      valornovo=valornovo+valorsemchar.charAt(i);
    }
    input.value=valornovo ;
  } else {
    //se não tiver..........
    input.value='';
    alert('CPF inválido!');
  }
  return true;
}

//#######################################################
// Formata campos CPF                                  //
//#######################################################
function ajustar_cpf(input, evento) {
  var BACKSPACE=8;
  var TAB=9;
  var DEL=46;
  var FRENTE=39;
  var TRAS=37;
  var HOME=36;
  var END=35;
  var tecla=(evento.keyCode ? evento.keyCode: evento.which ? evento.which : evento.charCode)
  if ((tecla == BACKSPACE )||
      (tecla == DEL)||
      (tecla == FRENTE)||
      (tecla == TRAS)||
      (tecla == TAB)||
      (tecla == HOME)||
      (tecla == END)) { return true; }
  if (tecla == 13 ) { return false; }
  if ((tecla<48)||(tecla>57)) {
    evento.returnValue =false;
    return false;
  } else {
    if((input.value.length==3)||(input.value.length==7)) {
      input.value=input.value + "." ;
    } else {
      if(input.value.length==11) {
        input.value=input.value + "-" ;
      }
    }
  }
  return true;
}
													      
//#######################################################
// Formata campos DATA                                 //
//#######################################################
function ajustar_data(input, evento) {
  var BACKSPACE=8;
  var TAB=9;
  var DEL=46;
  var FRENTE=39;
  var TRAS=37;
  var HOME=36;
  var END=35;
  var tecla=(evento.keyCode ? evento.keyCode: evento.which ? evento.which : evento.charCode)
  if ((tecla == BACKSPACE )||
      (tecla == DEL)||
      (tecla == FRENTE)||
      (tecla == TRAS)||
      (tecla == TAB)||
      (tecla == HOME)||
      (tecla == END)) { return true; }
  if (tecla == 13) { return false; }
  if ((tecla<48)||(tecla>57)) {
    evento.returnValue =false;
    return false;
  } else {
    if ((input.value.length==2)||(input.value.length==5)) {
      input.value=input.value+"/"; }
    }
  return true;
}

//#######################################################
// Formata campos FONE                                 //
//#######################################################
function ajustar_fone(input, evento) {
  var BACKSPACE=8;
  var TAB=9;
  var DEL=46;
  var FRENTE=39;
  var TRAS=37;
  var HOME=36;
  var END=35;
  var tecla=(evento.keyCode ? evento.keyCode: evento.which ? evento.which : evento.charCode)
  if ((tecla == BACKSPACE )||
      (tecla == DEL)||
      (tecla == FRENTE)||
      (tecla == TRAS)||
      (tecla == TAB)||
      (tecla == HOME)||
      (tecla == END)) { return true; }
  if (tecla == 13 ) { return false; }
  if ((tecla<48)||(tecla>57)) {
    evento.returnValue=false;
    return false;
  } else {
    if (input.value.length==0) { input.value="(" + input.value; }
    if (input.value.length==4) { input.value=input.value+")"; }
    if (input.value.length==5) { input.value=input.value+" "; }
    if (input.value.length==10){ input.value=input.value+"-"; }
  }
  return true;
}

//#######################################################
// Formata campos CEP                                  //
//#######################################################
function formatar_cep_blur(input) {
  var valor=input.value;
  var valorsemchar="";
  var valornovo="";
  //retira os pontos, traços e barras.
  for (var i=0;i<valor.length;i++) {
    if ((valor.charAt(i)!='.') && ( valor.charAt(i)!='-') && (valor.charAt(i)!='/')) {
      valorsemchar=valorsemchar+valor.charAt(i);
    }
  }
  //se tiver 8 digitos...........
  if (valorsemchar.length==8) {
    for (var i=0;i<8;i++) {
      if (i==5) { valornovo=valornovo+'-'; }
      valornovo=valornovo+valorsemchar.charAt(i);
    }
    input.value=valornovo ;
  } else {
  //se não tiver..........
    input.value='';
    alert('CEP inválido!');
  }
  return true;
}


//#######################################################
// Formata campos CEP                                  //
//#######################################################
function ajustar_cep(input, evento){
  var BACKSPACE=8;
  var TAB=9;
  var DEL=46;
  var FRENTE=39;
  var TRAS=37;
  var HOME=36;
  var END=35;
  var tecla=(evento.keyCode ? evento.keyCode: evento.which ? evento.which : evento.charCode)
  if ((tecla == BACKSPACE )||
      (tecla == DEL)||
      (tecla == FRENTE)||
      (tecla == TRAS)||
      (tecla == TAB)||
      (tecla == HOME)||
      (tecla == END)) { return true; }
  if (tecla == 13) { return false; }
  if ((tecla<48)||(tecla>57)) {
    evento.returnValue=false;
    return false;
  } else {
//    if (input.value.length==2) { input.value=input.value+"."; }
    if (input.value.length==5) { input.value=input.value+"-"; }
  }
  return true;
}
									    
//#######################################################
// Aceita somente numeros                              //
//#######################################################
function somente_numeros(input, evento) {
  var tecla=(evento.keyCode ? evento.keyCode: evento.which ? evento.which : evento.charCode)
  if ((tecla > 32 && tecla < 48) || tecla > 57) { return false; } else { return true; }
}
    
//#######################################################
// RETIRA O PONTO EM CAMPOS MONETARIOS                 //
//#######################################################
function Money_Focus(input) {
  stt=input.value;
  if (stt!='') {
    i=0;
    valor='';
    while(i < stt.length) {
      s=stt.charAt(i)
      if (s != '.') { valor+=s; }
      i++;
    }
    input.value=valor;
  }
}

//#######################################################
// COLOCA O PONTO EM CAMPOS MONETARIOS                 //
//#######################################################
function Money_Blur(input) {
  stt=input.value;
  if (stt=='') { return false; }
  if (stt.length==1) { input.value='0.0'+stt; }
  if (stt.length==2) { input.value='0.'+stt; }
  if (stt.length>2) {
    inteiros=stt.slice(0,stt.length-2); //tudo menos os 2 ultimos numeros.
    centavos=stt.slice(stt.length-2); //soh os 2 ultimos numeros
    valor=inteiros+'.'+centavos;
    input.value=valor;
  }
}									

//#######################################################
// Para campos monetarios                              //
//#######################################################
function somente_money(input, evento) {
  var BACKSPACE=8;
  var TAB=9;
  var DEL=46;
  var FRENTE=39;
  var TRAS=37;
  var HOME=36;
  var END=35;
  var PONTO=190;
  var tecla=(evento.keyCode ? evento.keyCode: evento.which ? evento.which : evento.charCode)
  if ((tecla == BACKSPACE )||
      (tecla == DEL)||
      (tecla == TAB)||
      (tecla == FRENTE)||
      (tecla == TRAS)||
      (tecla == HOME)||
      (tecla == END)||
      (tecla == PONTO)) { return true; }
  if ( tecla == 13 ) return false;
  //verifica qualquer outra tecla que nao seja numero.
  if ((tecla<48)||(tecla>57)) {
    evento.returnValue=false;
    return false;
  }
  return true;
}


//#######################################################
// Zoomifyer                                           //
//#######################################################
function Zoomify(picture, title) {
  Zoom = window.open("jaragua/zoomify.php?picture="+picture+"&title="+title, "Zoom", "width=764,height=520,resizable=no,toolbar=no,menubar=no,scrollbars=no");
}

//#######################################################
// Funcão para abrir popup com fotos.                  //
//#######################################################
function AbrirAlbum(album) {
  Album = window.open("Fotos/album.php?album="+album, "Album", "width=650,height=657,resizable=no,toolbar=no,menubar=no,scrollbars=no");
}

//#######################################################
// Funcão para abrir popup com fotos.                  //
//#######################################################
function AbrirAlbum2(album) {
  Album = window.open("Fotos/album2.php?album="+album, "Album", "width=710,height=601,resizable=no,toolbar=no,menubar=no,scrollbars=no");
}

//#######################################################
// Funcão para abrir popup com foto do piloto.         //
//#######################################################
function FotoPiloto(codigo) {
  Piloto = window.open("fotopiloto.php?codigo="+codigo, "Piloto", "width=160,height=207,resizable=no,toolbar=no,menubar=no,scrollbars=no");
}
