
window.defaultStatus=window.defaultStatus="C R I - Colégio do Registro de Imóveis do Paraná";

function Trim(str){
  while (str.charAt(0) == " ")
  str = str.substr(1,str.length -1);

  while (str.charAt(str.length-1) == " ")
  str = str.substr(0,str.length-1);

  return str;
} 

function openBrWindow(theURL,winName,features) { 
window.open(theURL,winName,features);
/*
 * <a href='#'
 * onClick="openBrWindow('k.htm','','status=no,menubar=no,width=767,height=480,top=10,left=10')">
 */
}

function fechar(refreshParent) {
	if (refreshParent && window.opener) {
		window.opener.location.reload();
	}
	window.close();
	// <input type='button' name='fechar' value='fechar' onclick='fechar(true)'>
}

// funï¿½ï¿½o para validar CNPJ-CGC ou CPF
function ValidaCPF(){
	if(document.form.cep.value==''){
		alert('Por favor informe o cpf');
		document.form.cep.focus();
		return false;
	}
	else{
		pfValidaCPF_CGC(document.form.cep, 'CPF ou CNPJ inválido');
		document.form.cep.focus();
		return false;
	}
			
}
			
function pfValidaCPF_CGC(msCPF_CGC, msMSG){
	if (!(checa(msCPF_CGC.value, msMSG))){
		msCPF_CGC.focus();
		return false;
	}
	else{ 
		return true; 
	}
}

function checa(msCPF_CGC, msMSG){
	if ((msCPF_CGC.length != 14) && (msCPF_CGC.length !=11)){
		alert(msMSG);
		return false;
	}

    if ((!(modulo(msCPF_CGC.substring(0,msCPF_CGC.length - 2)).toString()+modulo(msCPF_CGC.substring(0,msCPF_CGC.length - 1)).toString() == msCPF_CGC.substring(msCPF_CGC.length - 2,msCPF_CGC.length))) && (modulo_cic(msCPF_CGC.substring(0,msCPF_CGC.length - 2)) + "" + modulo_cic(msCPF_CGC.substring(0,msCPF_CGC.length - 1)) != msCPF_CGC.substring(msCPF_CGC.length - 2,msCPF_CGC.length))){
       alert(msMSG);
       return false;
    }
	return true;
}


function modulo(msCPF_CGC){
	soma=0;
	ind=2;
				
	for(pos=msCPF_CGC.length-1;pos>-1;pos=pos-1){
    	soma = soma + (parseInt(msCPF_CGC.charAt(pos)) * ind);
		ind++;
			      
		if(msCPF_CGC.length>11){ 
  		   if(ind>9) ind=2; 
		}
    }
				
    resto = soma - (Math.floor(soma / 11) * 11);
					 
 	if(resto < 2){ 
       return 0; 
	}
	else{ 
       return (11 - resto); 
	}
	
}


function modulo_cic(msCPF_CGC){
   	soma=0;
	ind=2;

	for(pos=msCPF_CGC.length-1;pos>-1;pos=pos-1){
       soma = soma + (parseInt(msCPF_CGC.charAt(pos)) * ind);
       ind++;
					 
       if(msCPF_CGC.length>11){	
		 if(ind>9) ind=2; 
       }
	}				
				
	resto = soma - (Math.floor(soma / 11) * 11);
					  
	if(resto < 2){	
   	   return 0; 
	}
	else{ 
 	   return 11 - resto;
	}
	
}

// FUNCAO PARA FORMATAR CAMPOS
function formata(campo, mask, evt) {
 	// EX: input type="text" name="cep" id="cep" onkeypress="return formata(this, '???.???.???-??', event)">
	// Formata o campo para cep
	if(document.all) { // Internet Explorer
		key = evt.keyCode; }
	else{ // Nestcape
		key = evt.which;
	}

	if (key == 8) {
		return true;
	}

	string = campo.value;  
	i = string.length;

	if (i < mask.length) {
		if (mask.charAt(i) == '?') {
			return (key > 47 && key < 58);
		} else {
			if (mask.charAt(i) == '!') {  return true;  }
		
			for (c = i; c < mask.length; c++) {
				if (mask.charAt(c) != '?' && mask.charAt(c) != '!')
					campo.value = campo.value + mask.charAt(c);
				else if (mask.charAt(c) == '!'){
					return true;
				} else {
					return (key > 47 && key < 58);
				}
			}
		}
	} else return false;
}

function formatar(src, mask) { // onkeypress="formatar(this,'00/00/0000')" NAO
								// USA MAIS
	var i = src.value.length;
	var saida = mask.substring(i,i+1);
	var ascii = event.keyCode;
	
	if (saida == "A") {
		if ((ascii >=97) && (ascii <= 122)) { event.keyCode -= 32; }
		else { event.keyCode = 0; }
	} else if (saida == "0") {
		if ((ascii >= 48) && (ascii <= 57)) { return; }
		else { event.keyCode = 0; }
	} else if (saida == "#") {
		return;
	} else {
		src.value += saida;
		i += 1;
		saida = mask.substring(i,i+1);
		if (saida == "A") {
			if ((ascii >=97) && (ascii <= 122)) { event.keyCode -= 32; }
			else { event.keyCode = 0; }
		} else if (saida == "0") {
			if ((ascii >= 48) && (ascii <= 57)) { return; }
			else { event.keyCode = 0; }
		} else { return; }
	}
}

function validarData(campo){
	var expReg = /^(([0-2]\d|[3][0-1])\/([0]\d|[1][0-2])\/[1-2][0-9]\d{2})$/;
	var msgErro = 'Formato invï¿½lido de data.';
	if ((campo.value.match(expReg)) && (campo.value!='')){
		var dia = campo.value.substring(0,2);
		var mes = campo.value.substring(3,5);
		var ano = campo.value.substring(6,10);
		if(mes==4 || mes==6 || mes==9 || mes==11 && dia > 30){
			alert("Dia incorreto !!! O mês especificado contém no máximo 30 dias.");
			return false;
		} else{
			if(ano%4!=0 && mes==2 && dia>28){
				alert("Data incorreta!! O mês especificado contém no máximo 28 dias.");
				return false;
			} else{
				if(ano%4==0 && mes==2 && dia>29){
					alert("Data incorreta!! O mês especificado contém no máximo 29 dias.");
					return false;
				} else{ 
					// alert ("Data correta!");
					return true;
				}
			}
		}
	}
	else {
		alert(msgErro);
		campo.focus();
		return false;
	}
}

function enviar(opcao) {
  // OPï¿½ï¿½O EXCLUIR SELECIONADA
  if(opcao == 'E') {
    document.form.opc_excluir.value = 1;
    document.form.submit();
  }// FECHA IF
  // OPï¿½ï¿½O ATUALIZAR SELECIONADA
  // if(opcao == 'A') {
  // document.forms[0].opc_atualizar.value = 1;
  // document.forms[0].submit();
  // }//FECHA IF

  // OPï¿½ï¿½O FINALIZAR SELECIONADA
  // if(opcao == 'F') {
  // document.forms[0].opc_finalizar.value = 1;
  // document.forms[0].action = "finalizar.php";
  // document.forms[0].submit();
  // }//FECHA IF
	  
}// FECHA FUNCTION


function currencyFormat(fld, milSep, decSep, e) {  // nao usa mais
	// onKeyPress="return(currencyFormat(this,',','.',event))"
	var sep = 0;
	var key = '';
	var i = j = 0;
	var len = len2 = 0;
	var strCheck = '0123456789';
	var aux = aux2 = '';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	if (whichCode == 13) return true;  // Enter
	key = String.fromCharCode(whichCode);  // Get key value from key code
	if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
	len = fld.value.length;
	for(i = 0; i < len; i++)
		if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;
	aux = '';
	for(; i < len; i++)
		if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
	aux += key;
	len = aux.length;
	if (len == 0) fld.value = '';
	if (len == 1) fld.value = '0'+ decSep + '0' + aux;
	if (len == 2) fld.value = '0'+ decSep + aux;
	if (len > 2) {
		aux2 = '';
		for (j = 0, i = len - 3; i >= 0; i--) {
			if (j == 3) {
				aux2 += milSep;
				j = 0;
			}
			aux2 += aux.charAt(i);
			j++;
		}
		fld.value = '';
		len2 = aux2.length;
		for (i = len2 - 1; i >= 0; i--)
			fld.value += aux2.charAt(i);
		fld.value += decSep + aux.substr(len - 2, len);
	}
	return false;
}

function moeda2float(moeda){
	moeda = moeda.replace(".","");
	moeda = moeda.replace(",",".");
	return parseFloat(moeda);
}

function float2moeda(num) {
	x = 0;
	if(num<0) {
		num = Math.abs(num);
		x = 1;
	}
	if(isNaN(num)) num = "0";

	cents = Math.floor((num*100+0.5)%100);
	num = Math.floor((num*100+0.5)/100).toString();

	if(cents < 10) cents = "0" + cents;
		for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
			num = num.substring(0,num.length-(4*i+3))+'.'+num.substring(num.length-(4*i+3));
		
		ret = num + ',' + cents;
		if (x == 1) ret = ' - ' + ret;return ret;
}

// #####################
// retira caracteres invalidos da string
function Limpar(valor, validos) {
	var result = "";
	var aux;
	for (var i=0; i < valor.length; i++) {
		aux = validos.indexOf(valor.substring(i, i+1));
		if (aux>=0) {
			result += aux;
		}
	}
	return result;
}

// Formata número tipo moeda usando o evento onKeyDown
function Formata(campo,tammax,teclapres,decimal) { // onKeydown="Formata(this,20,event,2)"
	var tecla = teclapres.keyCode;
	vr = Limpar(campo.value,"0123456789");
	tam = vr.length;
	dec=decimal;
	
	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 <= dec ){ campo.value = vr ; }

		if ( (tam > dec) && (tam <= 5) ){
			campo.value = vr.substr( 0, tam - 2 ) + "," + vr.substr( tam - dec, tam ) ; 
		}
		if ( (tam >= 6) && (tam <= 8) ){
			campo.value = vr.substr( 0, tam - 5 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; 
		}
		if ( (tam >= 9) && (tam <= 11) ){
			campo.value = vr.substr( 0, tam - 8 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ;
		}
		if ( (tam >= 12) && (tam <= 14) ){
			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 - dec, tam ) ;
		}
		if ( (tam >= 15) && (tam <= 17) ){
			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 ) ;
		}
	} 

}
// ####################

// FUNCAO QUE FAZ MUDAR A COR DAS CELULAR DA TABELA--- MENU
function changeme(id,color,childcolor){
   elmnt=document.getElementById(id);
   elmnt.style.backgroundColor= color;
   elmnt.style.color= childcolor;
}

// MENU TABELA.....
function mOvr(src,clrOver,evt) {
	if(document.all) { // Internet Explorer
		key = evt.keyCode; }
	else{ // Nestcape
		key = evt.which;
	}
   if (!src.contains(key.fromElement)) {
      // src.style.cursor = 'hand'; //hand
      src.bgColor = clrOver;
   }
}
function mOut(src,clrIn,evt) {
	if(document.all) { // Internet Explorer
		key = evt.keyCode; }
	else{ // Nestcape
		key = evt.which;
	}
   if (!src.contains(key.toElement)) {
      // src.style.cursor = 'default';
      src.bgColor = clrIn;
   }
}

// ABRIR JANELA
function MM_openBrWindow(theURL,winName,features) { // v2.0
  window.open(theURL,winName,features);
}

// CARREGA NOTICA
function carrega_noticia(id,livre,logado){
	if ( (logado == "SIM") || (livre == "S") ){
		location.href='index.php?modulo=ver_noticia&iD='+id;
	}
	else {
		alert("Atenção:\nÉ necessario estar logado para acessar esta notícia.");
	}
}

function SomenteNumero(e){
	// onkeypress='return SomenteNumero(event)'
    var tecla=(window.event)?event.keyCode:e.which;   
    if((tecla>47 && tecla<58)) return true;
    else{
    	if (tecla==8 || tecla==0) return true;
	else  return false;
    }
}


