<!--

/* FUNÇÕES PÚBLICAS */

/***
* Descrição.: formata um campo do formulário de  acordo com a máscara informada...
* Parâmetros: - objForm (o Objeto Form) - strField (string contendo o nome do textbox) - sMask (mascara que define o
* formato que o dado será apresentado,  usando o algarismo "9" para definir números e o símbolo "!" para qualquer caracter...
* - evtKeyPress (evento) Uso.......: <input type="textbox" name="xxx"..... onkeypress="return autoFormat(document.rcfDownload, 'str_cep', '99999-999', event);">
* Observação: As máscaras podem ser representadas como os exemplos abaixo:
* CEP -> 99.999-999
* CPF -> 999.999.999-99
* CNPJ -> 99.999.999/9999-99
* Data -> 99/99/9999
* Tel Resid -> (99) 999-9999
* Tel Cel -> (99) 9999-9999
* Processo -> 99.999999999/999-99
* C/C -> 999999-!
* E por aí vai...
***/
function autoFormat(objForm, strField, sMask, evtKeyPress)
{
   var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;

   if(window.Event)//Internet Explorer
   {
      nTecla = evtKeyPress.keyCode;
   }
   else//FireFox
   {
      nTecla = evtKeyPress.which;
   }
   
   if(nTecla==8)return true;//backspace
   
   sValue = objForm[strField].value;
    
   // Limpa todos os caracteres de formatação que
   // já estiverem no campo.
   sValue = sValue.toString().replace( "-", "" );
   sValue = sValue.toString().replace( "-", "" );
   sValue = sValue.toString().replace( ".", "" );
   sValue = sValue.toString().replace( ".", "" );
   sValue = sValue.toString().replace( "/", "" );
   sValue = sValue.toString().replace( "/", "" );
   sValue = sValue.toString().replace( "(", "" );
   sValue = sValue.toString().replace( "(", "" );
   sValue = sValue.toString().replace( ")", "" );
   sValue = sValue.toString().replace( ")", "" );
   sValue = sValue.toString().replace( ":", "" );
   sValue = sValue.toString().replace( " ", "" );
   sValue = sValue.toString().replace( " ", "" );
   fldLen = sValue.length;
   mskLen = sMask.length;

   i = 0;
   nCount = 0;
   sCod = "";
   mskLen = fldLen;

   while (i <= mskLen) {
      bolMask = ((sMask.charAt(i) == ":") || (sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/"))
      bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))

      if (bolMask) {
         sCod += sMask.charAt(i);
         mskLen++;
      }
      else {
         sCod += sValue.charAt(nCount);
         nCount++;
      }

      i++;
   }

   objForm[strField].value = sCod;
   
   if (nTecla != 8)
   { // backspace
      if (sMask.charAt(i-1) == "9")
      { // apenas números...
        
        return somenteNumero(evtKeyPress);
         
      }// números de 0 a 9
      else 
      { // qualquer caracter...
         return true;
      }
   }
   else
   {
      return true;
   }
   
}

// Javascript responsável pela troca de função do enter pelo tab
function TranslateKey(keypress) {
if ( event.keyCode == 13) { event.keyCode = 9; }}

function fecharModal(pagina){
window.opener.location.href=pagina;window.close();
}

function mudarFoco(idControle)
{
    var controle;
    controle = document.forms[0][idControle];

    if(controle!=null)
        controle.focus();
}

/* teste de java script */
function confirma(msg){
	if( confirm(msg) )
		return true;
	else{
		return false;
	}
}

//funciona para IE e FF
function onlyNumbers(e) {
    var keyCode = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;
    var caract = new RegExp(/^[0-9\b/]+$/i);
    var caract = caract.test(String.fromCharCode(keyCode));

    if(!caract)
    {
        keyCode=0;
        return false;
    }
    else
     return true;
}

//funciona para IE e FF
function somenteNumero(event)
{
    var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
    var caract = new RegExp(/^[0-9\b/]+$/i);
    var caract = caract.test(String.fromCharCode(keyCode));

    if(!caract)
    {
        keyCode=0;
        return false;
    }
    else
     return true;
}


function isCPF(CPF)
{
   CPF = CPF.replace(".", "");
   CPF = CPF.replace("-", "");

   if (CPF.length != 11 || CPF == "00000000000" || CPF == "11111111111" ||
       CPF == "22222222222" || CPF == "33333333333" || CPF == "44444444444" ||
       CPF == "55555555555" || CPF == "66666666666" || CPF == "77777777777" ||
       CPF == "88888888888" || CPF == "99999999999")
      return false;

   soma = 0;

   for (i=0; i < 9; i ++)
      soma += parseInt(CPF.charAt(i)) * (10 - i);

   resto = 11 - (soma % 11);

   if (resto == 10 || resto == 11)
      resto = 0;

   if (resto != parseInt(CPF.charAt(9)))
      return false;

   soma = 0;

   for (i = 0; i < 10; i ++)
      soma += parseInt(CPF.charAt(i)) * (11 - i);

   resto = 11 - (soma % 11);

   if (resto == 10 || resto == 11)
      resto = 0;

   if (resto != parseInt(CPF.charAt(10)))
      return false;

   return true;
}

function isRG(RG)
{
   RG = RG.replace(".", "");
   RG = RG.replace("-", "");

   var ident = new Number(RG);

   if (RG.length == 0)
      return false;

   if (isNaN(ident) || ident == 0)
      return false;

   return isNumeric(ident);
}


/* FUNÇÕES PRIVADAS OU PARTICULARES DA APLICAÇÃO */
function confirmaEnvio(numeroTitulo, numeroCPF)
{
    var janela;
    window.location.href = "Confirmacao.aspx?bol=" + numeroTitulo;
    //window.location.href = window.location.href.replace('FichaPreMatricula.aspx?cpf='+numeroCPF, 'Confirmacao.aspx?bol='+numeroTitulo );
}

function mascarar()
{    
    var cep = document.forms[0]["txtCEP"];
    var dataNascimento = document.forms[0]["txtDataNascimento"];
    var telResidencial = document.forms[0]["txtTelResidencial"];
    var fax = document.forms[0]["txtFax"];
    
    autoFormat(cep, cep.name, "99.999-999", event);
    autoFormat(dataNascimento, dataNascimento.name, '99/99/9999', event);
    
    if(telResidencial.value!="")
        autoFormat(telResidencial, telResidencial.name, '(99)9999-9999', event);
        
    if(fax.value != "")
        autoFormat(fax, fax.name, '(99)9999-9999', event);
}

function centralizar()
{
    var larguraJanela = self.outerWidth;
    var alturaJanela = self.outerHeight;
    
    var esquerda = (screen.width -larguraJanela)/2;
    var topo = (screen.height -alturaJanela)/2;
    
    //alert(larguraJanela);
    //alert(alturaJanela);
    
    //window.moveTo( esquerda, topo);
    //window.moveTo( 0, 0);
}

function abrirBoleto()
{
    var esquerda = (screen.width -670)/2;
    var topo = (screen.height -690)/2;
    var janela;
    var text;
    
    janela = window.open('../Boleto/aspx/boleto.aspx','Boleto','left='+esquerda+', top='+topo+',scrollbars=no, toolbar=no, statusbar=no, height=690, width=670');
    text = "Se a janela nao estava abrindo\ntalvez seja porque voce tenha um\nprograma bloqueador de pop-up!\nObservacao » O windows XP service pack 2\nbloqueia pop-ups!";
    
    if(janela == null)
        { alert(text); return; }
    else
        janela.focus();
}

function validarNaturalidade(source, arguments)
{
    var indexSelecionado;
    indexSelecionado = document.forms[0]["ddlNaturalidade"].selectedIndex;
    
    if( indexSelecionado<1 )
    {
    arguments.IsValid = false;
    }
    else
    arguments.IsValid = true;
}

function validarUF(source, arguments)
{
    var indexSelecionado;
    indexSelecionado = document.forms[0]["ddlUF"].selectedIndex;
    
    if( indexSelecionado==0 )
    {
    arguments.IsValid = false;
    }
    else
    arguments.IsValid = true;
}

/*
function desabilitaPagina()
{
	var botao = document.forms[0]["btnClicado"];
    var retorno = true; 
    var clicado = botao.value;
    var opcao1, opcao2, opcao3;
    
    opcao1 = document.forms[0]["ddlPrimeiraOpcao"].value;
    opcao2 = document.forms[0]["ddlSegundaOpcao"].value;
    opcao3 = document.forms[0]["ddlTerceiraOpcao"].value;
        
    if(opcao2 != "0" && opcao1 == opcao2)
		retorno = false;
		
	if(opcao3 != "0" && opcao1 == opcao3)
		retorno = false;
		
	if(opcao2 != "0" && opcao3 != "0" && opcao2 == opcao3)
		retorno = false;
	
	if(!retorno) {
		window.alert("As opções de curso devem ser diferentes.");
		document.forms[0]["ddlPrimeiraOpcao"].focus();
    }
    else
    {
		retorno = Page_ClientValidate();
	}
    
    if(retorno==true)
    {
        document.forms[0]["btnClicado"].value= 'sim';
        document.forms[0]["imgConfirmar"].disabled = true;
        document.frmFichaPreMatricula.submit();
    }
}
*/

function desabilitaPagina()
{
	var botao = document.forms[0]["btnClicado"];
    var retorno = true; 
    var clicado = botao.value;
    var opcao1, opcao2, opcao3;
    
    opcao1 = document.forms[0]["ddlPrimeiraOpcao"].value;
    opcao2 = document.forms[0]["ddlSegundaOpcao"].value;
    opcao3 = document.forms[0]["ddlTerceiraOpcao"].value;
        
    if(opcao2 != "0" && opcao1 == opcao2)
		retorno = false;
		
	if(opcao3 != "0" && opcao1 == opcao3)
		retorno = false;
		
	if(opcao2 != "0" && opcao3 != "0" && opcao2 == opcao3)
		retorno = false;
	
	if(!retorno) {
		window.alert("As opções de curso devem ser diferentes.");
		document.forms[0]["ddlPrimeiraOpcao"].focus();
    }
    else if(navigator.appName.indexOf('Internet Explorer')>0)//IE
    {
		retorno = Page_ClientValidate();
    }
    
    if(retorno==true)
    {
        document.forms[0]["btnClicado"].value= 'sim';
        document.forms[0]["imgConfirmar"].disabled = true;
        document.frmFichaPreMatricula.submit();
    }
}

function validaComoSoube(source, arguments)
{
    var indexSelecionado;
    indexSelecionado = document.forms[0]["ddlComoSoube"].selectedIndex;
    
    if( indexSelecionado==0 )
    {
        arguments.IsValid = false;
    }
    else
        arguments.IsValid = true;
}

-->