// JavaScript Document

<!--


function difdatas (data1, data2) {

if ( parseInt( data2.split( "/" )[2].toString() + data2.split( "/" )[1].toString() + data2.split( "/" )[0].toString() ) > parseInt( data1.split( "/" )[2].toString() + data1.split( "/" )[1].toString() + data1.split( "/" )[0].toString() ) )
{
  return false;
}
else
{
  return true;
}
	
}


function ComparaSenha(valor1, valor2)
{
  var result = false;
  if (valor1.value == valor2.value) {
	  result = true;
  } else {
	alert('A senha está diferente da confirmação. Verifique.');
	valor1.focus();
	result = false;
  }
	
  return result;
}

function VerificaEmail(email)
{
  var result = false;
  var theStr = new String(email);
  var index = theStr.indexOf("@");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
	result = true;
  }
  return result;
}

function ValidaCampo(formField,fieldLabel)
{
	var result = true;
	
	if (formField.value == "")
	{
		alert('O campo "' + fieldLabel +'" está em branco.');
		formField.focus();
		result = false;
	}
	
	return result;
}

function Digitos(str)
{
	return ValidaChar(str,"0123456789");
}

function ValidaChar(str,charset)
{
	var result = true;

	// Note: doesn't use regular expressions to avoid early Mac browser bugs	
	for (var i=0;i<str.length;i++)
		if (charset.indexOf(str.substr(i,1))<0)
		{
			result = false;
			break;
		}
	
	return result;
}

function ValidaEmail(formField,fieldLabel,required)
{
	var result = true;
	
	if (required && !ValidaCampo(formField,fieldLabel))
		result = false;

	if (result && ((formField.value.length < 3) || !VerificaEmail(formField.value)) )
	{
		alert("Por favor, insira um endereço de email completo. Exemplo: seunome@seudominio.com.br");
		formField.focus();
		result = false;
	}
   
  return result;

}

function ValidaNumeros(formField,fieldLabel,required)
{
	var result = true;

	if (required && !ValidaCampo(formField,fieldLabel))
		result = false;
  
 	if (result)
 	{
 		if (!Digitos(formField.value))
 		{
 			alert('Por favor, insira somente números no campo "' + fieldLabel +'".');
			formField.focus();		
			result = false;
		}
	} 
	
	return result;
}


function ValidaInteiro(formField,fieldLabel,required)
{
	var result = true;

	if (required && !ValidaCampo(formField,fieldLabel))
		result = false;
  
 	if (result)
 	{
 		var num = parseInt(formField.value,10);
 		if (isNaN(num))
 		{
 			alert('Por favor, insira numeros, ",", "."  no campo "' + fieldLabel +'".');
			formField.focus();		
			result = false;
		}
	} 
	
	return result;
}


function ValidaData(formField,fieldLabel,required)
{
	var result = true;

	if (required && !ValidaCampo(formField,fieldLabel))
		result = false;
  
 	if (result)
 	{
 		var elems = formField.value.split("/");
 		
 		result = (elems.length == 3); // should be three components
 		
 		if (result)
 		{
 			var month = parseInt(elems[1],10);
  			var day = parseInt(elems[0],10);
 			var year = parseInt(elems[2],10);
			result = Digitos(elems[0]) && (month > 0) && (month < 13) &&
					 Digitos(elems[1]) && (day > 0) && (day < 32) &&
					 Digitos(elems[2]) && ((elems[2].length == 2) || (elems[2].length == 4));
 		}
 		
  		if (!result)
 		{
 			alert('Por favor, insira uma data no formato DD/MM/AAAA no campo "' + fieldLabel +'".');
			formField.focus();		
		}
	} 
	
	return result;
}



function abrir_janela(endereco){
janela=window.open(endereco,"","width=700,height=500,scrollbars=yes,status=yes");

//interceptacao de erro na abertura da janela
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; }
//fim
janela.moveTo(120,120);
}


function abrir_janela_loja(endereco){
janela=window.open(endereco,"","width=400,height=600,scrollbars=yes,status=no");

//interceptacao de erro na abertura da janela
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; }
//fim
janela.moveTo(300,150);
}



function abre(endereco){
janela=window.open(endereco,"","width=700,height=580,scrollbars=no,status=no");
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; }
//fim
janela.moveTo(120,70);
}


function send(country){
window.opener.document.form1.nome.value=country;
self.close();
}

/*
function EnterTab(){
if (event.keyCode == 13) event.keyCode = 9;

}*/

function EnterTab (field, event) {
var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
if (keyCode == 13) {
var i;
for (i = 0; i < field.form.elements.length; i++)
if (field == field.form.elements[i])
break;
i = (i + 1) % field.form.elements.length;
field.form.elements[i].focus();
return false;
}
else
return true;
}


function Numeros(event){
var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
var caract = new RegExp(/[0-9\b\t/]+$/i);
var caract = caract.test(String.fromCharCode(keyCode));
if(!caract){
keyCode=0;
return false;
}
}


function Numeros_Reais(event){
var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
var caract = new RegExp(/[0-9.\b\t/]+$/i);
var caract = caract.test(String.fromCharCode(keyCode));
if(!caract){
keyCode=0;
return false;
}
}

function dialogo(){
caixa = "window.showModalDialog('http://localhost/aplicacao/consjuizo.php', 'nome', 'resizable:no; dialogHeight: 300px; dialogWidth: 400px; status:no;center:yes;');";
eval(caixa);
}


function confirma_exclusao(url)
{
if (confirm ("Você tem certeza que deseja excluir esse registro?" + "\n\n"+ "Aperte OK para confirmar a exclusão ou Cancelar.")){
window.location.assign(url);
return true;
}
}

function confirma_exclusao_popup(url)
{
if (confirm ("Você tem certeza que deseja excluir esse registro?" + "\n\n"+ "Aperte OK para confirmar a exclusão ou Cancelar.")){
abrir_janela(url);
window.location.reload();
return true;
}
}

function confirma_cancelamento_popup(url)
{
if (confirm ("Você tem certeza que deseja cancelar esse registro?" + "\n\n"+ "Aperte OK para confirmar a exclusão ou Cancelar.")){
abrir_janela(url);
return true;
}
}

function FormataData(objeto,teclapress) 
{ 
    //var tecla = teclapress.keyCode; 
	var tecla = (teclapress.which) ? teclapress.which : teclapress.keyCode;

    //Testa se o campo está selecionado, se estiver, limpa o conteúdo para nova digitação. 
    var selecionado = document.selection.createRange();  
    var selecao        = selecionado.text;  
    if((selecao != "") && (tecla != 8) && (tecla != 9) && (tecla != 13) && (tecla != 35) && (tecla != 36) && (tecla != 46) && (tecla != 16) && (tecla != 17) && (tecla != 18) && (tecla != 20) && (tecla != 27) && (tecla != 37) && (tecla != 38) && (tecla != 39) && (tecla != 40)) {objeto.value = "";} 



    if(((window.event.keyCode == 13) || (window.event.keyCode == 9))&&objeto.value != "") 
    { 
        if(!(ValidaData(objeto))) 
            { 
                window.event.cancelBubble = true; 
                window.event.returnValue = false; 
                alert("Data Inválida"); 
                objeto.value = ""; 
                objeto.focus(); 
            } 
    } 

    if (( tecla == 8 || tecla == 88 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 )&& objeto.value.length < (10)) 
    { 
        vr = objeto.value; 
        vr = vr.replace( "/", "" ); 
        vr = vr.replace( "/", "" ); 
        tam = vr.length; 

        if (tam < 8) 
            { 
                if (tecla != 8) {tam = vr.length + 1 ;} 
            } 
        else 
            { 
                window.event.cancelBubble = true; 
                window.event.returnValue = false; 
            } 
         
        if ((tecla == 8) && (tam > 1)) 
            { 
                tam = tam - 1 ; 
                objeto.value = vr.substr(0,tam); 
                window.event.cancelBubble = true; 
                window.event.returnValue = false; 
            } 
                if ( tam <= 4 && tecla != 8){  
                     objeto.value = vr ; } 

                if ( (tam >= 4) && (tam <= 6) ){ 
                     objeto.value = vr.substr(0, tam - 4) + '/' + vr.substr( tam - 4, 4 ); } 

                if ( (tam >= 6) && (tam <= 8) ){ 
                    objeto.value = vr.substr(0, tam - 6 ) + '/' + vr.substr( tam - 6, 2 ) + '/' + vr.substr( tam - 4, 4 ); } 

                if ((tam == (8)) && tecla != 8) 
                    { 
                        if(tecla >=96 && tecla <=105) 
                            { 
                                tecla = tecla - 48; 
                            } 

                        objeto.value = objeto.value + (String.fromCharCode(tecla)); 
                        window.event.cancelBubble = true; 
                        window.event.returnValue = false; 

                        if (!(ValidaData(objeto))) 
                            { 
                                alert("Data Inválida"); 
                                objeto.value = ""; 
                                objeto.focus(); 
                            } 
                    } 
    } 
    else if((window.event.keyCode != 8) && (window.event.keyCode != 9) && (window.event.keyCode != 13) && (window.event.keyCode != 35) && (window.event.keyCode != 36) && (window.event.keyCode != 46)) 
        { 
            event.returnValue = false; 
        } 
} 


/***
* 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:
* "9" para definir números 
* "x" para definir somente letras maiusculas e minusculas SEM espaço
* "!" para qualquer caracter
*
* - evtKeyPress (evento)
* Uso...: <input type="textbox"
* name="xxx".....
* onkeypress="return txtBoxFormat(document.rcfDownload, 'str_cep', '99999-999', event);">
*
* Caracteres aceitos para mascara : -,;:./() espaço
* 
* 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-!
* Hora -> 99:99:99 
* Placa -> xxx - 9999
***/

function txtBoxFormat(objForm, strField, sMask, evtKeyPress) {
var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;
nTecla = (evtKeyPress.which) ? evtKeyPress.which : evtKeyPress.keyCode;
sValue = objForm[strField].value;
// Limpa todos os caracteres de formatação que
// já estiverem no campo.
expressao = /[\.\/\-\(\)\,\;\: ]/gi;
sValue = sValue.toString().replace(expressao, '');
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) == ",") || (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 && nTecla != 13)
{ // backspace enter
if (sMask.charAt(i-1) == "9") 
{ // apenas números...
return ((nTecla > 47) && (nTecla < 58)); 
} // números de 0 a 9
else 
{ 
if (sMask.charAt(i-1) == "x") 
{ // apenas letras... Sem espaco
return ((nTecla > 64) && (nTecla < 123)); 
} // maiusculas e minusculas de A a z sem acentos
else 
{ // qualquer caracter...
return true;
} 
} 
}
else 
{
return true;
}
}
//Fim da Função Máscaras Gerais


//-->
