/* ------------------------------------------------------------------------------------------------------
Função para impedir que seja digitado apostrofo e aspas
-------------------------------------------------------------------------------------------------------*/
function ApagaApostrofoAspas (i,delKey,direction) {
   if (delKey!=9) { //tab
	//192 é o codigo 
	if(delKey==192) {
		i.value = i.value.substring(0,i.value.length-1)
	}          
   }

}

/* ------------------------------------------------------------------------------------------------------
Função para submeter o formulario para um action dado
-------------------------------------------------------------------------------------------------------*/
function SubmeterFormularioPara(actionFormulario){	
	document.Formulario.action = actionFormulario;
      	document.Formulario.submit();
}


/* ------------------------------------------------------------------------------------------------------
Função para verificar substituir as aspas
-------------------------------------------------------------------------------------------------------*/
function AdicionarAspasSimples() {
	TamanhoFormulario = document.forms["Formulario"].length;
	Expressao = /\s*\'\s*/;
	for (i = 0; i < TamanhoFormulario; i++) {
		valorCampo = new String(document.Formulario.elements[i].value);
		if (valorCampo.search(Expressao) != -1) {
			document.Formulario.elements[i].value = valorCampo.replace(Expressao,new String("`"));
		}
	}	
}


/* ------------------------------------------------------------------------------------------------------
Função para verificar campos obrigatórios no formulário
-------------------------------------------------------------------------------------------------------*/
function SubmeterFormulario(camposObrigatorios){
	AdicionarAspasSimples();
	
        if (camposObrigatorios!="null") {
              regExp = /(\w+),(\w+)/;
              if (camposObrigatorios.search(regExp) == -1) {
                      if (document.Formulario.elements[camposObrigatorios].value == ""){
                              alert("Os campos marcados com '*' são de preenchimento obrigatório!");
                              document.Formulario.elements[camposObrigatorios].focus();
                              return false;
                      }
              } else {
                      VetorCampos = camposObrigatorios.split(",");
                      for (i=0;i<VetorCampos.length;i++){
                              if (document.Formulario.elements[VetorCampos[i]].value == ""){
                                      alert("Os campos marcados com '*' são de preenchimento obrigatório!");
                                      document.Formulario.elements[VetorCampos[i]].focus();
                                      return false;
                              }
                      }
              }
        }
	// Só submete o formulário se o campo Submeter estiver true. Isto evita de salvar os mesmos dados várias vezes
	if (document.Formulario.elements.submeter.value == "true") {
        	document.Formulario.submit();
		document.Formulario.elements.submeter.value = "false";
	}
}

/* ------------------------------------------------------------------------------------------------------
Função para verificar campos obrigatórios no formulário de login
-------------------------------------------------------------------------------------------------------*/
function SubmeterFormularioLogin(camposObrigatorios){	
        if (camposObrigatorios!="null") {
              regExp = /(\w+),(\w+)/;
              if (camposObrigatorios.search(regExp) == -1) {
                      if (document.Formulario.elements[camposObrigatorios].value == ""){
                              alert("Os campos marcados com '*' são de preenchimento obrigatório!");
                              document.Formulario.elements[camposObrigatorios].focus();
                              return false;
                      }
              } else {
                      VetorCampos = camposObrigatorios.split(",");
                      for (i=0;i<VetorCampos.length;i++){
                              if (document.Formulario.elements[VetorCampos[i]].value == ""){
                                      alert("Por favor, informe seu login e sua senha!");
                                      document.Formulario.elements[VetorCampos[i]].focus();
                                      return false;
                              }
                      }
              }
        }
	// Só submete o formulário se o campo Submeter estiver true. Isto evita de salvar os mesmos dados várias vezes
	if (document.Formulario.elements.submeter.value == "true") {
        	document.Formulario.submit();
		document.Formulario.elements.submeter.value = "false";
	}
}



/* ------------------------------------------------------------------------------------------------------
Função para verificar campos obrigatórios no formulário consulta e setar o campo operação para 2 (consulta)
-------------------------------------------------------------------------------------------------------*/
function SubmeterFormularioConsulta(camposObrigatorios){
        document.forms.Formulario.elements.operacao.value = 2;
        if (camposObrigatorios!="null") {
              regExp = /(\w+),(\w+)/;
              if (camposObrigatorios.search(regExp) == -1) {
                      if (document.Formulario.elements[camposObrigatorios].value == ""){
                              alert("Os campos marcados com '*' são de preenchimento obrigatório!");
                              document.Formulario.elements[camposObrigatorios].focus();
                              return false;
                      }
              } else {
                      VetorCampos = camposObrigatorios.split(",");
                      for (i=0;i<VetorCampos.length;i++){
                              if (document.Formulario.elements[VetorCampos[i]].value == ""){
                                      alert("Os campos marcados com '*' são de preenchimento obrigatório!");
                                      document.Formulario.elements[VetorCampos[i]].focus();
                                      return false;
                              }
                      }
              }
        }
        document.Formulario.submit();
}


/* ------------------------------------------------------------------------------------------------------
Função para evitar que um formulário seja submetido
-------------------------------------------------------------------------------------------------------*/
function EvitaSubmit(){
         return false;
}


/* ------------------------------------------------------------------------------------------------------
Função para formatar um campo data
-------------------------------------------------------------------------------------------------------*/
function FormataData(campo,teclapres) {

  var tecla = teclapres.keyCode;
  vr = document.Formulario[campo].value;
  vr = vr.replace( ".", "" );
  vr = vr.replace( "/", "" );
  vr = vr.replace( "/", "" );
  vr = vr.replace( "/", "" );
  tam = vr.length + 1;

  if ( tecla != 9 && tecla != 8 ){
    if ( tam > 2 && tam < 5 ){
      document.Formulario[campo].value = vr.substr( 0, tam - 2  ) + '/' + vr.substr( tam - 2, tam );}
    if ( tam >= 5 && tam <= 10 ){
      document.Formulario[campo].value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 );}
  }

}

/* ------------------------------------------------------------------------------------------------------
Função para verificar se a data foi digitada corretamente
-------------------------------------------------------------------------------------------------------*/
function verificaData(THISDATE) {	
	var err = 0;
	dataCompleta = THISDATE.value;
	PadraoData = new RegExp("[0-9][0-9]/[0-9][0-9]/[0-9][0-9][0-9][0-9]");
      OcorrenciaData = PadraoData.test(dataCompleta);
      if (!OcorrenciaData) {
		err = 1;
      } else {		
		dia = dataCompleta.substring(0,2);
		mes = dataCompleta.substring(3,5);
		ano = dataCompleta.substring(6,10);
		if (dia<1 || dia>31) err = 1;
		if (mes<1 || mes>12) err = 1;
		if (ano<1900) err = 1;
		if (mes==4 || mes==6 || mes==9 || mes==11) {
			if (dia==31) err = 1;
		}
		if (mes==2) {
			g = parseInt(ano/4)
            	if (isNaN(g)) err=1;
            	if (dia>29) err=1;
            	if (dia==29 && ((ano/4)!=parseInt(ano/4))) err=1;
		}
	}
	if (err == 1 && dataCompleta!="") {
		alert(dataCompleta + ' não é uma data válida!');
		THISDATE.value = "";
		THISDATE.focus();
	}
}

/*
-------------------------------------------------------------------------------------------------------
Função para formatar um campo de nota
-------------------------------------------------------------------------------------------------------*/
function FormataNota(campo,teclapres) {
  var tecla = teclapres.keyCode;
  charanterior = document.Formulario[campo].value.substring(document.Formulario[campo].value.length-1,document.Formulario[campo].value.length);
  if (charanterior!="0" && charanterior!="1" && charanterior!="2" && charanterior!="3" && charanterior!="4" && charanterior!="5" && charanterior!="6" && charanterior!="7" && charanterior!="8" && charanterior!="9") {
    if (charanterior==","||charanterior==".") {
      document.Formulario[campo].value = document.Formulario[campo].value.replace(charanterior,".");
    } else {
      document.Formulario[campo].value = document.Formulario[campo].value.replace(charanterior,"");
    }
  }
}

/* ------------------------------------------------------------------------------------------------------
Função para verificar se a nota foi digitada corretamente
-------------------------------------------------------------------------------------------------------*/
function verificaNota(THISGRADE) {
  if (THISGRADE.value.length>0) {
    var err=0
    a=THISGRADE.value
    if (a.length >4) err=1
    if ((a>10) || (a<0)) err=1
    if (err==1) {
            alert(THISGRADE.value + ' não é uma nota válida!');
            THISGRADE.value = ""
    }
  }
}


/* ------------------------------------------------------------------------------------------------------
Função para impedir que sejam digitados caractres diferentes de números
-------------------------------------------------------------------------------------------------------*/
function FormatNumber(campo,teclapress) {
  var tecla = teclapress.keyCode;

    if (tecla!=9 && tecla!=13) { //tab e enter
      if(tecla!=8 && tecla!=46 && tecla!=16 &&  !(tecla>36 && tecla<41)){
        //Se for Números escreve na caixa de texto
        if (((tecla >= 48) && (tecla <= 57)) || (tecla >= 96 && tecla <=105)){
          //Não faz nada
        } else {

            if (document.Formulario[campo].value.length == 0) {
              document.Formulario[campo].value = ""
            } else if (tecla!=8) {
              document.Formulario[campo].value = document.Formulario[campo].value.substring(0,document.Formulario[campo].value.length-1)
            }

        }
        document.Formulario[campo].focus()
      }
    } 
}

/* ------------------------------------------------------------------------------------------------------
Função para verificar se foi digitado apenas números
-------------------------------------------------------------------------------------------------------*/
function verificaNumero(THISNUMBER) {
  if (THISNUMBER.value.length>0) {
    PadraoNumero = new RegExp ("[0-9]");
    OcorrenciaNumero = PadraoNumero.test(THISNUMBER.value);
    if (!OcorrenciaNumero ) {
         THISNUMBER.value = "";
         alert ("Número inválido!");
    }
  }
}

/* ------------------------------------------------------------------------------------------------------
Função para verificar se o e-mail foi digitado corretamente
-------------------------------------------------------------------------------------------------------*/
function verificaEmail(i) {
        PadraoEmail        =  new RegExp ("^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)+$");
           OcorrenciaEmail    =  PadraoEmail.test(i.value);
        if (!OcorrenciaEmail ) {
                      document.forms[0].email.value = "";
                      alert ("Email inválido!");
            }
}


/* ------------------------------------------------------------------------------------------------------
Função para formatar um campo de cep
-------------------------------------------------------------------------------------------------------*/
function FormataCep(campo,tammax,teclapres) {  

  var tecla = teclapres.keyCode;
  vr = document.Formulario[campo].value;
  vr = vr.replace( ",", "" );	
  vr = vr.replace( ",", "" );	
  vr = vr.replace( ".", "" );	
  vr = vr.replace( ".", "" );	
  vr = vr.replace( "-", "" );	
  vr = vr.replace( "-", "" );	  
  tam = vr.length;	

  if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }
  if (tecla == 8 ){ tam = tam - 1 ; }
		
  if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){       
    if ( tam <= 5 ) { 
      document.Formulario[campo].value = vr ; 
    } 
    if ( (tam > 5) && (tam <= 9) ) {      
      document.Formulario[campo].value = vr.substr( 0, 5 ) + '-' + vr.substr( 5, tam ) ;
    }
  //apaga se nao for numero
  } else {
    
  }
	
}

/* ------------------------------------------------------------------------------------------------------
Função para verificar se o cep foi digitado corretamente
-------------------------------------------------------------------------------------------------------*/
function verificaCep(i){
  if (i.value.length>0) {
      expReg = /(\d{5})-(\d{3})$/;
      if (i.value.search(expReg)==-1){
           alert("CEP inválido!");
           i.value = "";
           i.focus();
      }
  }
}



/* ------------------------------------------------------------------------------------------------------
Função para adicionar ou retirar os valores de check boxes caso eles tenham sido clicados
-------------------------------------------------------------------------------------------------------*/
function AdicionarCodigosExcluir(campo,codigo,nomeControle)
{
         codigosAtuais = "," + document.forms["Formulario"].elements["codigosAtuais"].value;
         codigosExcluir = document.forms["Formulario"].elements["codigosExcluir"].value;

         if (campo.checked) { //marcou o controle
            if (codigosExcluir.search(codigo)!=-1){ //não é para excluir
                codigosExcluir = codigosExcluir.replace(","+codigo,"");
                //alert(codigosExcluir);
                document.forms["Formulario"].elements["codigosExcluir"].value = codigosExcluir;
            }
         } else {
            if (codigosAtuais.search(codigo)!=-1) { //é para excluir
                document.forms["Formulario"].elements["codigosExcluir"].value = document.forms["Formulario"].elements["codigosExcluir"].value + "," + codigo;
                //alert(document.forms["Formulario"].elements["codigosExcluir"].value);
            }
         }
}



/* ------------------------------------------------------------------------------------------------------
Função para formatar um campo de cpf
-------------------------------------------------------------------------------------------------------*/
function FormataCpf(campo,tammax,teclapres) {

  var tecla = teclapres.keyCode;
  vr = document.Formulario[campo].value;
  vr = vr.replace( ".", "" );
  vr = vr.replace( ".", "" );
  vr = vr.replace( ".", "" );
  vr = vr.replace( ".", "" );
  vr = vr.replace( "-", "" );
  vr = vr.replace( "-", "" );
  vr = vr.replace( "-", "" );
  vr = vr.replace( "-", "" );
  vr = vr.replace( "-", "" );
  tam = vr.length;

  if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }
  if (tecla == 8 ){ tam = tam - 1 ; }
		
  if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
    if ( tam <= 2 ){ 
      document.Formulario[campo].value = vr ; }
    if ( (tam > 2) && (tam <= 5) ){
      document.Formulario[campo].value = vr.substr( 0, tam - 2 ) + '-' + vr.substr( tam - 2, tam ) ; }
    if ( (tam >= 6) && (tam <= 8) ){
      document.Formulario[campo].value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + '-' + vr.substr( tam - 2, tam ) ; }
    if ( (tam >= 9) && (tam <= 11) ){
      document.Formulario[campo].value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + '-' + vr.substr( tam - 2, tam ) ; }
    if ( (tam >= 12) && (tam <= 14) ){
      document.Formulario[campo].value = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + '-' + vr.substr( tam - 2, tam ) ; }
    if ( (tam >= 15) && (tam <= 17) ){
      document.Formulario[campo].value = vr.substr( 0, tam - 14 ) + '.' + vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + '-' + vr.substr( tam - 2, tam ) ;}
  //apaga se nao for numero
  } else {
    
  }		
}

/* ------------------------------------------------------------------------------------------------------
Função para verificar se o cpf é válido
-------------------------------------------------------------------------------------------------------*/
function verificaCpf(campocpf) {  
  d1 = 0;
  d2 = 0
  digito1 = 0;
  digito2 = 0;
  resto = 0;

  //Retira pontos e hifen
  cpf = new String(campocpf.value);
  while (cpf.search(/\./) != -1) {
    cpf = cpf.replace(".","");    
  }
  while (cpf.search(/\-/) != -1) {
    cpf = cpf.replace("-","");    
  }

  //Verifica se tem 11 digitos
  if (cpf.length != 11) {
    alert("Valor inválido!");
    campocpf.value = "";
    campocpf.focus();
    return false;
  }

  for (nCount=1; nCount<cpf.length-1; nCount++)
  {
     digitoCPF = cpf.substring(nCount-1,nCount);

     //multiplique a ultima casa por 2 a seguinte por 3 a seguinte por 4 e assim por diante.
     d1 = d1 + ( 11 - nCount ) * digitoCPF;

     //para o segundo digito repita o procedimento incluindo o primeiro digito calculado no passo anterior.
     d2 = d2 + ( 12 - nCount ) * digitoCPF;
  };

  //Primeiro resto da divisão por 11.
  resto = (d1 % 11);

  //Se o resultado for 0 ou 1 o digito é 0 caso contrário o digito é 11 menos o resultado anterior.
  if (resto < 2)
    digito1 = 0;
  else
    digito1 = 11 - resto;

  d2 += 2 * digito1;

  //Segundo resto da divisão por 11.
  resto = (d2 % 11);

  //Se o resultado for 0 ou 1 o digito é 0 caso contrário o digito é 11 menos o resultado anterior.
  if (resto < 2)
    digito2 = 0;
  else
    digito2 = 11 - resto;

  //Digito verificador do CPF que está sendo validado.
  nDigVerific = cpf.substring(cpf.length-2,cpf.length);

  //Concatenando o primeiro resto com o segundo.
  nDigResult = new String(digito1) + new String(digito2);

  //comparar o digito verificador do cpf com o primeiro resto + o segundo resto.
  if (nDigVerific != nDigResult) {
    alert("Valor inválido!");
    campocpf.value = "";
    campocpf.focus();
    return false;
  }

}

/* ------------------------------------------------------------------------------------------------------
Função para formatar um campo de valor
-------------------------------------------------------------------------------------------------------*/
function FormataValor(campo,tammax,teclapres) {
  var tecla = teclapres.keyCode;
  vr = document.Formulario[campo].value;
  vr = vr.replace( "/", "" );
  vr = vr.replace( "/", "" );
  vr = vr.replace( ",", "" );
  vr = vr.replace( ".", "" );
  vr = vr.replace( ".", "" );
  vr = vr.replace( ".", "" );
  vr = vr.replace( ".", "" );
  tam = vr.length;

  if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }
  if (tecla == 8 ){ tam = tam - 1 ; }
		
  if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
    if ( tam <= 2 ){ 
      document.Formulario[campo].value = vr ; }
    if ( (tam > 2) && (tam <= 13) ){
      document.Formulario[campo].value = vr.substr( 0, tam - 2 ) + '.' + vr.substr( tam - 2, tam ) ;
    }	 	
  //apaga se nao for numero
  } else {
    
  }		
	
}

/* ------------------------------------------------------------------------------------------------------
Função para verificar se o valor foi digitado corretamente
-------------------------------------------------------------------------------------------------------*/
function verificaValor(i) {
  if (i.value.length>0) {
      expReg = /(\d)+/;
      if (i.value.search(expReg)==-1){
           alert("Valor inválido!");
           i.value = "";
           i.focus();
      }
  }
}


/* ------------------------------------------------------------------------------------------------------
Função para verificar se a confirmação de um valor está correta
-------------------------------------------------------------------------------------------------------*/
function verificaConfirmacao(campo1,campo2){
  if (document.Formulario.elements[campo1].value!=document.Formulario.elements[campo2].value) {
      alert("Confirmação inválida!");
  }
}

/* ------------------------------------------------------------------------------------------------------
Função para abrir uma janela pop up para baixa automatica
-------------------------------------------------------------------------------------------------------*/
function AbrirJanela(Arquivo)
{
  var browser = navigator.appName + " " + navigator.appVersion;  
  
  nomeJanela = new String(Arquivo);
  while (nomeJanela.search(/\=/) != -1) {
    nomeJanela = nomeJanela.replace("=","");    
  }
  while (nomeJanela.search(/\?/) != -1) {
    nomeJanela = nomeJanela.replace("?","");    
  }
  while (nomeJanela.search(/\&/) != -1) {
    nomeJanela = nomeJanela.replace("&","");    
  }
  while (nomeJanela.search(/\//) != -1) {
    nomeJanela = nomeJanela.replace("/","");    
  }
 
  if (browser.substring(0, 8)=="Netscape")
  {
       var newWind=window.open(Arquivo,nomeJanela,'toolbar=0,location=0,directories=0,status=0,resizable=1,scrollbars=1,width=500,height=300');
       if (newWind.opener == null)
       {
          newWind.opener = top;
       }
       else
       {
         if (browser.substring(0, 12)=="Netscape 3.0")
            newWind.focus();
         if (browser.substring(0, 12)=="Netscape 2.0")
            newWind.document.forms["Formulario"].display.focus();
       }
   }
   else
      {
       var newWind=window.open(Arquivo,nomeJanela,'toolbar=0,location=0,directories=0,status=0,resizable=1,scrollbars=1,width=500,height=300');
       if (newWind.blue == null)
       {
          //newWind.blue = window;
       }
   }
}

/* ------------------------------------------------------------------------------------------------------
Função para abrir uma janela pop up
-------------------------------------------------------------------------------------------------------*/
function AbrirJanela(Arquivo)
{
        var browser=navigator.appName + " " + navigator.appVersion;
  if (browser.substring(0, 8)=="Netscape")
  {
       var newWind=window.open(Arquivo,'remoteWin','toolbar=0,location=0,directories=0,status=0,resizable=1,scrollbars=1,width=500,height=300');
       if (newWind.opener == null)
       {
          newWind.opener = top;
       }
       else
       {
         if (browser.substring(0, 12)=="Netscape 3.0")
            newWind.focus();
         if (browser.substring(0, 12)=="Netscape 2.0")
            newWind.document.forms["Formulario"].display.focus();
       }
   }
   else
      {
       var newWind=window.open(Arquivo,'remote','toolbar=0,location=0,directories=0,status=0,resizable=1,scrollbars=1,width=500,height=300');
       if (newWind.blue == null)
       {
          //newWind.blue = window;
       }
   }
}

function DataAtual ()
{
hoje = new Date ();
day = hoje.getDay();
date = hoje.getDate();
month = hoje.getMonth();
year = hoje.getFullYear();

switch (day)
{case (0):
{ var dia = "Domingo"; }
break;
case (1):
{ var dia = "Segunda"; }
break;
case (2):
{ var dia = "Terça-feira"; }
break;
case (3):
{ var dia = "Quarta-feira"; }
break;
case (4):
{ var dia = "Quinta-feira"; }
break;
case (5):
{ var dia = "Sexta-feira"; }
break;
case (6):
{ var dia = "Sábado"; }
break;}

switch (month)
{case (0):
{ var mes = "Janeiro"; }
break;
case (1):
{ var mes = "Fevereiro"; }
break;
case (2):
{ var mes = "Março"; }
break;
case (3):
{ var mes = "Abril"; }
break;
case (4):
{ var mes = "Maio"; }
break;
case (5):
{ var mes = "Junho"; }
break;
case (6):
{ var mes = "Julho"; }
break;
case (7):
{ var mes = "Agosto"; }
break;
case (8):
{ var mes = "Setembro"; }
break;
case (9):
{ var mes = "Outubro"; }
break;
case (10):
{ var mes = "Novembro"; }
break;
case (11):
{ var mes = "Dezembro"; }
break;}

/*
if (year < 100)
{  year = "19" + year;}
else year = 1900 + year;

if (date < 10)
{  date = "0" + date;}
*/


document.write ("<font face='Arial' size='1' align='right' color='#000080'>" + dia + ", " + date + " de " + mes + " de " + year + "</font>");
}

/* ------------------------------------------------------------------------------------------------------
Função para redirecionar para a tela que exibe as características do local selecionado na combo
-------------------------------------------------------------------------------------------------------*/
function RedirecionarCaracteristicas(nomeControle,evento){
  	local = document.Formulario.elements[nomeControle].value;
	if (local!="") {
  		codigoLocal = local.split(",");
		link = "caracteristicaLocal?evento=" + evento + "&codigoLocal=" + codigoLocal[2];
		AbrirJanela(link);
	} else {
		alert("Por favor, selecione um local");
	}
}


/* ------------------------------------------------------------------------------------------------------
Função para desmarcar o campo Reposição quando algum horário for selecionado e vice-versa
-------------------------------------------------------------------------------------------------------*/
function DesmarcarControle(nomeControle) {  
  if (nomeControle == 'horarios') {
    tamanho = document.Formulario.elements['horarios'].length;
    for (i=0; i<tamanho; i++) {      
      document.Formulario.elements['horarios'][i].checked = false;   
    }
    document.Formulario.elements.horaInicial.focus();
  } else {
    document.Formulario.elements[nomeControle].checked = false;
    document.Formulario.elements.horaInicial.value = "";
    document.Formulario.elements.horaFinal.value = "";
  }
}


/*
------------------------------------------------------------------------------------------------------
Função para formatar um campo hora
------------------------------------------------------------------------------------------------------
*/

function FormataHora(campo,tammax,teclapres) {  

  var tecla = teclapres.keyCode;
  vr = document.Formulario[campo].value;
  vr = vr.replace( ",", "" );	
  vr = vr.replace( ",", "" );	
  vr = vr.replace( ".", "" );	
  vr = vr.replace( ".", "" );	
  vr = vr.replace( ":", "" );	
  vr = vr.replace( ":", "" );	
  vr = vr.replace( "-", "" );	
  vr = vr.replace( "-", "" );	
  tam = vr.length;	

  if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }
  if (tecla == 8 ){ tam = tam - 1 ; }
		
  if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){       
    if ( tam <= 2 ) { 
      document.Formulario[campo].value = vr ; 
    } 
    if ( (tam > 2) && (tam <= 5) ) {      
      document.Formulario[campo].value = vr.substr( 0, 2 ) + ':' + vr.substr( 2, tam ) ;
    }
  //apaga se nao for numero
  } else {
    
  }
	
}

/* ------------------------------------------------------------------------------------------------------
Função para verificar se a hora foi digitada corretamente
-------------------------------------------------------------------------------------------------------*/
function verificaHora(i){
  if (i.value.length>0) {
      expReg = /(\d{2}):(\d{2})$/;
      if (i.value.search(expReg)==-1){
           alert("Hora inválida!");
           i.value = "";
           i.focus();
      }
  }

  horaInicial = new Number(document.Formulario.elements.horaInicial.value.substring(0,2));
  if (horaInicial > 23) { 
    horaInicial = 0;
  }
  minutos = document.Formulario.elements.horaInicial.value.substring(2,5);
  horaFinal = horaInicial + 1;
  document.Formulario.elements.horaFinal.value = horaFinal + minutos;
  document.Formulario.elements.horaInicial.focus();

}

function menu(urlBase) {
	imagemAux = new Array(0,1,2,3,4,5,6,7,8,9);
	imagem = new Array(10);	
	indice = Math.floor(Math.random()*imagemAux.length);
      stringIndice = new String(indice);
	imagem[0] = imagemAux[indice];

	for (i=1; i<10; i++) { 
		indice = Math.floor(Math.random()*imagemAux.length);	
		while (stringIndice.search(indice) != -1) {
			indice = Math.floor(Math.random()*imagemAux.length);
		}
      	imagem[i] = imagemAux[indice];
		stringIndice = stringIndice + indice;
		//imagemAux.splice(indice,1);
	}	

	document.writeln('<table border="1" cellspacing="0" cellpadding="0" bordercolor="#336699" bgcolor="#C8D6E3">');
	document.writeln('	<tr>'); 
	document.writeln('		  <td><a href="#"><img src="' +urlBase + 'imagens/' + imagem[0] + '.gif" onClick="montarSenha(' + imagem[0] + ')" border="0"></a></td>');
	document.writeln('        <td><a href="#"><img src="' +urlBase + 'imagens/' + imagem[1] + '.gif" onClick="montarSenha(' + imagem[1] + ')" border="0"></a></td>');
	document.writeln('        <td><a href="#"><img src="' +urlBase + 'imagens/' + imagem[2] + '.gif" onClick="montarSenha(' + imagem[2] + ')" border="0"></a></td>');
	document.writeln('        <td><a href="#"><img src="' +urlBase + 'imagens/' + imagem[3] + '.gif" onClick="montarSenha(' + imagem[3] + ')" border="0"></a></td>');
	document.writeln('        <td><a href="#"><img src="' +urlBase + 'imagens/' + imagem[4] + '.gif" onClick="montarSenha(' + imagem[4] + ')" border="0"></a></td>');
	document.writeln('    </tr>');
	document.writeln('    <tr>');
	document.writeln('        <td><a href="#"><img src="' +urlBase + 'imagens/' + imagem[5] + '.gif" onClick="montarSenha(' + imagem[5] + ')" border="0"></a></td>');
	document.writeln('        <td><a href="#"><img src="' +urlBase + 'imagens/' + imagem[6] + '.gif" onClick="montarSenha(' + imagem[6] + ')" border="0"></a></td>');
	document.writeln('        <td><a href="#"><img src="' +urlBase + 'imagens/' + imagem[7] + '.gif" onClick="montarSenha(' + imagem[7] + ')" border="0"></a></td>');
	document.writeln('        <td><a href="#"><img src="' +urlBase + 'imagens/' + imagem[8] + '.gif" onClick="montarSenha(' + imagem[8] + ')" border="0"></a></td>');
	document.writeln('  	  <td><a href="#"><img src="' +urlBase + 'imagens/' + imagem[9] + '.gif" onClick="montarSenha(' + imagem[9] + ')" border="0"></a></td>');
	document.writeln('	</tr>');
	document.writeln('</table>');
}

function montarSenha(i) {
	document.forms.Formulario.elements.exibeSenha.value = document.forms.Formulario.elements.exibeSenha.value + i;
	document.forms.Formulario.elements.Senha.value = document.forms.Formulario.elements.Senha.value + i;
}

function limparSenha() {
	senha = new String(document.forms.Formulario.elements.Senha.value);
	tamanho = senha.length - 1;
	document.forms.Formulario.elements.exibeSenha.value = senha.substr(0, tamanho);
	document.forms.Formulario.elements.Senha.value = senha.substr(0, tamanho);
	return false;
}

/* ------------------------------------------------------------------------------------------------------
Função para abrir uma janela pop up para baixa automatica
-------------------------------------------------------------------------------------------------------*/
function AbrirJanelaBaixa(Arquivo)
{
  var browser = navigator.appName + " " + navigator.appVersion;  
  
  nomeJanela = new String(Arquivo);
  while (nomeJanela.search(/\=/) != -1) {
    nomeJanela = nomeJanela.replace("=","");    
  }
  while (nomeJanela.search(/\?/) != -1) {
    nomeJanela = nomeJanela.replace("?","");    
  }
  while (nomeJanela.search(/\&/) != -1) {
    nomeJanela = nomeJanela.replace("&","");    
  }
  while (nomeJanela.search(/\//) != -1) {
    nomeJanela = nomeJanela.replace("/","");    
  }
 
  if (browser.substring(0, 8)=="Netscape")
  {
       var newWind=window.open(Arquivo,nomeJanela,'toolbar=0,location=0,directories=0,status=0,resizable=0,scrollbars=0,menubar=0,width=425,height=275');
       if (newWind.opener == null)
       {
          newWind.opener = top;
       }
       else
       {
         if (browser.substring(0, 12)=="Netscape 3.0")
            newWind.focus();
         if (browser.substring(0, 12)=="Netscape 2.0")
            newWind.document.forms["Formulario"].display.focus();
       }
   }
   else
      {
       var newWind=window.open(Arquivo,nomeJanela,'toolbar=0,location=0,directories=0,status=0,resizable=0,scrollbars=0,menubar=0,width=425,height=275');
       if (newWind.blue == null)
       {
          //newWind.blue = window;
       }
   }
}

