// Função para emular submit
// emula o submit dos formulários 
function emulaSubmit(form){ 

     if (confirm("Confirma a exclusão?"))
     {
         form.submit(); //popupMetodoAt
     }
}

function verifica(nameCheckbox)
{
    total = 0;
		chk = document.getElementsByName(nameCheckbox);
		for (x = 0; x < chk.length; x++) {
			if(chk[x].checked == true) {
				total++;
			}
		}
		if(total > 1) {
			desabilitaBotoes('alterar','excluir');
		} else if( total==0){
			desabilitaTodos('alterar','excluir');
			} else {habilitaBotoes('alterar','excluir');}
}

function desabilitaBotoes(n1,n2)
{
		document.getElementById(n1).disabled = true;
        try{disableLink(document.getElementById(n1))}
    catch(e){};
}

function habilitaBotoes(n1,n2)
{
		document.getElementById(n1).disabled = false;
    try{enableLink(document.getElementById(n1));}
    catch(e){};
    
		document.getElementById(n2).disabled = false;
        try{enableLink(document.getElementById(n2));}
    catch(e){};
}

function desabilitaTodos(n1,n2) 
{
		document.getElementById(n1).disabled = true;
    try{disableLink(document.getElementById(n1));}
    catch(e){};
		document.getElementById(n2).disabled = true;
        try{
        disableLink(document.getElementById(n2));
        }
    catch(e)
    {
    }
}
  
// Seleciona todos objetos do fromArray para gravar 
function selecionaTodos(fromArray)
{
    var i;
    for (i = 0; i < fromArray.length; i++) {
        fromArray[i].selected = true;
    }
    return false;
}

function voCheckboxSelecionados(form, campo)
{
   var i = 0;
   var checado;
   checkbox = document.getElementsByName(campo);
   for (x = 0; x < checkbox.length; x++) 
   {
     if(checkbox[x].checked == true) 
     {
		if(i > 0)
        	checado = checado +  "#" + checkbox[x].value;
		else
			checado = checkbox[x].value;
		i++;
	 }
   }
   if(i > 0){
	 	form.checks.value = checado;
        emulaSubmit(form);
   }
}

function chamarAlteracaoObjeto(){
   var i = 0;
   var checado;
   checkbox = document.getElementsByName("id_chamada");
   for (x = 0; x < checkbox.length; x++) 
   {
     if(checkbox[x].checked == true) 
     {
		checado = checkbox[x].value;
	 	document.alterar_chamada.id_chamada.value= checado;
       	document.alterar_chamada.submit();
	  }
   }
}

function alterarImovel(){
   var i = 0;
   var checado;
   checkbox = document.getElementsByName('id_imovel');
   for (x = 0; x < checkbox.length; x++) 
   {
     if(checkbox[x].checked == true) 
     {
		checado = checkbox[x].value;
	 	document.alterar_imovel.id_imovel.value = checado;
       	document.alterar_imovel.submit();
	  }
   }
}

function alterarCliente(){
   var i = 0;
   var checado;
   checkbox = document.getElementsByName("id_cliente");
   for (x = 0; x < checkbox.length; x++) 
   {
     if(checkbox[x].checked == true) 
     {
		checado = checkbox[x].value;
	 	document.alterar_cliente.id_cliente.value= checado;
       	document.alterar_cliente.submit();
	  }
   }
}

function alterarNoticia(){
   var i = 0;
   var checado;
   checkbox = document.getElementsByName("id_noticia");
   for (x = 0; x < checkbox.length; x++) 
   {
     if(checkbox[x].checked == true) 
     {
		checado = checkbox[x].value;
	 	document.alterar_noticia.id_noticia.value= checado;
       	document.alterar_noticia.submit();
	  }
   }
}

function alterarLink(){
   var i = 0;
   var checado;
   checkbox = document.getElementsByName("id_link");
   for (x = 0; x < checkbox.length; x++) 
   {
     if(checkbox[x].checked == true) 
     {
		checado = checkbox[x].value;
	 	document.alterar_link.id_link.value= checado;
       	document.alterar_link.submit();
	  }
   }
}

function alterarBairro(){
   var i = 0;
   var checado;
   checkbox = document.getElementsByName('id_bairro');
   for (x = 0; x < checkbox.length; x++) 
   {
     if(checkbox[x].checked == true) 
     {
		checado = checkbox[x].value;
	 	document.alterar_bairro.id_bairro.value = checado;
       	document.alterar_bairro.submit();
	  }
   }
}

function alterarTipo(){
   var i = 0;
   var checado;
   checkbox = document.getElementsByName('id_qualificacao');
   for (x = 0; x < checkbox.length; x++) 
   {
     if(checkbox[x].checked == true) 
     {
		checado = checkbox[x].value;
	 	document.alterar_tipo.id_qualificacao.value = checado;
       	document.alterar_tipo.submit();
	  }
   }
}

function confirmaCadastroImovel(){
	var error = 0;
	if (document.imovel.rua.value == '')
		error++;
	if (document.imovel.titulo.value == '')
		error++;
	if (document.imovel.descricao.value == '')
		error++;
	if (document.imovel.valor.value == '')
		error++;
	if (error > 0){
		alert("todos os campos devem serem preenchidos");
		return false;
	} else {
		document.imovel.submit();
	}
}

function confirmaContato(){
	var error = 0;
	if (document.contato.nome.value == '')
		error++;
	if (document.contato.fone.value == '')
		error++;
	if (document.contato.msg.value == '')
		error++;
	if (error > 0){
		alert("todos os campos devem serem preenchidos");
		return false;
	} else {
		document.contato.submit();
	}
}

function confirmaCadastroCliente(){
	var error = 0;
	if (document.cliente.nome.value == '')
		error++;
	if (document.cliente.email.value == '')
		error++;
	if (document.cliente.rua.value == '')
		error++;
	if (document.cliente.numero.value == '')
		error++;
	if (document.cliente.fone.value == '')
		error++;
	if (error > 0){
		alert("todos os campos devem serem preenchidos");
		return false;
	} else {
		document.cliente.submit();
	}
}

function confirmaCadastroNoticia(){
	var error = 0;
	if (document.noticia.titulo.value == '')
		error++;
	if (document.noticia.conteudo.value == '')
		error++;
	if (error > 0){
		alert("Os campos titulo e conteudo devem serem preenchidos");
		return false;
	} else {
		document.noticia.submit();
	}
}

function confirmaCadastro(form, campo){
	var error = 0;
	if (campo.value == '')
		error++;
	if (error > 0){
		msn = "Campo ";
		msn += campo.name;
		msn += " deve ser preenchido"
		alert(msn);
		return false;
	} else {
		form.submit();
	}
}

function confirmaCadastroBairro(){
	var error = 0;
	if (document.bairro.bairro.value == '')
		error++;
	if (error > 0){
		alert("todos os campos devem serem preenchidos");
		return false;
	} else {
		document.bairro.submit();
	}
}

var objBrow,LAST_ERR_VALUE="";
var ERRO=REPET_ERR=CANNOT_FORMAT=false;
var LAST_FIELD=CURRENT_FIELD=LAST_ERR_FIELD=null;
var SZ_DATE=8,
SZ_CEP=8,
SZ_ACCOUNT=7,
SZ_AG_ACCOUNT=11,
SZ_AG_SAVINGS=SZ_AG_ACCOUNT, 
SZ_MONEY=10,
SZ_FLOAT=10,
SZ_CPF=11,
SZ_CNPJ=14,
SZ_CPF_CNPJ=SZ_CNPJ,
SZ_PERCENT=6,
SZ_BRANCH=4,
SZ_MONTH_YEAR=6,
SZ_TIME=4,
MAX_VALUE=9999999.99;
function Browser(){
	this.name=this.platform="Unknown";
	this.majorver=this.version=this.minorver="";
	this.init=_Init;
	this.getName=function (){return this.name};
	this.getMinorver=function (){return this.minorver};
	this.getMajorver=function (){return this.majorver};
	this.getVersion=function (){return parseFloat(this.version,10)};
	this.getPlatform=function (){return this.platform}; 
	this.isIE=function (){return(this.name=="IE")};
	this.isNetscape=function (){return(this.name=="Netscape")};
	this.isWindows=function (){return _has(this.platform,["Windows","WinNT"])};
	this.isWinNT=function (){return _has(this.platform,["WinNT","Windows NT"])};
	this.isWin95=function (){return _has(this.platform,"Windows 95")};
	this.isWin98=function (){return _has(this.platform,"Windows 98")};
	this.isLinux=function (){return _has(this.platform,"Linux")};
	this.isMac=function (){return _has(this.platform,"Mac");};
	this.init();
}

function _has(s,a){
	s=String(s);
	if(typeof(a)=="string")return s.indexOf(a)!=-1;
	else{
		for(var i=0;i<a.length;i++)
			if(s.indexOf(a[i])!=-1) return true;
		return false;
	}
}

function _Init(){
	var ua=navigator.userAgent,t="",ts="",i,bv;
	bv=ua.slice(0,ua.indexOf("("));
	ts=ua.slice(ua.indexOf("(")+1,ua.indexOf(")")).split(";");
	for(i=0;i<ts.length;i++){
		t=trim(ts[i]);
		if(_has(t,["MSIE","Opera"]))bv=t;
		else if(_has(t,["X11","SunOS","Linux"]))this.platform="Unix";
		else if(_has(t,["Mac","PPC","Win"]))this.platform=t;
	}
	var idx=bv.indexOf("MSIE"),lo="";
	if(idx>=0)bv=bv.slice(idx);
	if(bv.slice(0,7)=="Mozilla"){
		this.name="Netscape";lo=bv.slice(8);
	}else if(bv.slice(0,4)=="Lynx"){
		this.name="Lynx";lo=bv.slice(5);
	}else if (bv.slice(0,4)=="MSIE"){
		this.name="IE";lo=bv.slice(5);
	}else if (bv.slice(0,27)=="Microsoft Internet Explorer"){
		this.name="IE";lo=bv.slice(28);
	}else if (bv.slice(0,5)=="Opera"){
		this.name="Opera";lo=bv.slice(6);
	}
	lo=trim(lo);
	i=lo.indexOf(" ");
	if(i>=0)this.version=lo.slice(0,i);
	else this.version=lo;
	j=this.version.indexOf(".");
	if(j>=0){
		this.majorver=this.version.slice(0,j);
		this.minorver=this.version.slice(j+1);
	}else this.majorver=this.version;
}

function formatCamp(campo,tp,par1,par2,par3){
	if(brow().isIE()&& CANNOT_FORMAT){
		CANNOT_FORMAT=false;
		campo.focus();
		return true;
	}
	var nArg=formatCamp.arguments.length;
	ERRO=false;
	var vr=trim(campo.value);
	if(!campo|| !vr ||vr.length==0)return false;
	if(nArg==2)par1="";
	if(tp=="interval"){
		if(nArg<=4) par3="";
		return formatType(campo,tp,par3,par1,par2);
	}else return formatType(campo,tp,par1,par2);
}
function formatType(f,tp,msgErr,adarg1,adarg2){
	var vr=unformatField(f.value,tp);
	LAST_FIELD=f;
	var ret=isValidValue(vr,tp,adarg1,adarg2);
	if(!ret){
		showError(tp,msgErr,adarg1);
		if(brow().isNetscape())f.value="";
		f.focus();
		return false;
	}else f.value=getFmtValue((typeof ret=="boolean")?vr:ret,tp);
	ERRO=false;
	return true;
}
function validaConteudo(event,el,tp)
{
	var NS=brow().isNetscape();
	var key=String.fromCharCode((NS?event.which:event.keyCode));
	if(NS && event.which==8)return true;
	var tp_sp=/^sp_/.test(tp);
	if(/^(percent|float(\d{0,1})|money(\d{0,1}))$/.test(tp)){
		return isNumeric(key)||(key=="," && el.value.indexOf(",")==-1);
	}else if(/^(sp_)?alfanumeric$/.test(tp))
		return isAlfaNumeric(key)||(tp_sp && key==" ");
	else if(/^(sp_)?textnumber$/.test(tp))
		return isTextNumber(key)||(tp_sp && key==" ");
	else{
		switch(tp){
			case "email":
			case "uppercase":return true;
			case "text":return isAlfa(key)|| /[ ]/.test(key);
      		case "date": return isDate(key) || / \/ /.test(key);
			default:return isNumeric(key);
		}
	}
}
function unformatField(valor,tipo){
	var vr=(typeof valor=="object")?valor.value:String(valor);
	var t=(arguments.length < 1)?"default":String(tipo);
	if(!trim(vr)||trim(vr).length==0)return "";
	if(/^(date|month_year|time|ag_account|ag_savings|branch|account|cep|numeric|interval)$/.test(t))
		vr=justNumbersStr(vr);
	else
	if(/^(percent|float(\d{0,1})|money(\d{0,1}))$/.test(t)){
		var arr=t.match(/(\d+)$/);
		vr=toFloat(vr,arr?parseInt(arr[1],10):2);	
	}else{
		if(/^(cpf|cnpj|cpf_cnpj)$/.test(t)){
			vr=justNumbersStr(vr);
			var isCPF=tipo=="cpf"||(tipo=="cpf_cnpj" && vr.length<=SZ_CPF);
			vr=repeatStr(vr,"0",isCPF?SZ_CPF:SZ_CNPJ);
		}else if(t=="email")vr=trim(vr)
	}
	if(typeof valor=="object")valor.value=vr;
	else return vr;
}
function removeCaracs(f,type){
	var vr=unformatField(f.value,type);
	if(f.value!=vr)f.value=vr;
	focusNetscape(f);
}
function isValidValue(vr,tp,adarg1,adarg2){
	var re,isNum=isNumeric(vr);
	if(/^(ag_account|ag_savings|branch|cep)$/.test(tp))
		return isNum && vr.length==eval("SZ_"+tp.toUpperCase());
	else if(/^(percent|float(\d{0,1})|money(\d{0,1}))$/.test(tp))
		return isFloatNumber(vr);
	else if(/textnumber$/.test(tp))
		return isTextNumber((tp.indexOf("sp_")==0)?removeStr(vr," "):vr);
	else if(/alfanumeric$/.test(tp)){
		return isAlfaNumeric((tp.indexOf("sp_")==0)?removeStr(vr," "):vr);
	}else{
		switch(tp){
			case "time":
				switch(vr.length){
					case 1:vr="0"+vr+"00";break;
					case 2:vr+="00";break;
					case 3:vr="0"+vr+"0";break;
				}
				vr=repeatStr(vr,"0",4,"right");
				return(isNum && /^([0-1]\d[0-5]\d)|(2[0-3][0-5]\d)$/.test(vr))?vr:null;
			case "date":
				var obj=new DateValidation(vr);
				return (isNum && obj.isDate())?obj:null;
			case "month_year":
				var obj=new DateValidation("01"+vr);
				return (isNum && obj.isDate())?obj:null;
			case "text":return isAlfa(vr.replace(/[ ]/g,""));
			case "email":return isEmail(vr);
			case "cpf":return isCPF(vr);
			case "cnpj":return isCNPJ(vr);
			case "cpf_cnpj":return (vr.length <=SZ_CPF)?isCPF(vr):isCNPJ(vr);
			case "interval":
				vr=parseInt(vr,10);
				return vr>=adarg1 && vr<=adarg2;
			default:return true;
		}
	}
}
function getFmtValue(vr,tp){
	if(tp=="cpf_cnpj")tp=(vr.length <=SZ_CPF)?"cpf":"cnpj";
	if(/^money/.test(tp))return fmtMoney(vr);
	else{
		switch(tp){
			case "time":return vr.slice(0,2)+":"+vr.slice(2,4); 
			case "date":return vr.getDateValue();
			case "month_year":return vr.getMonthDateValue();
			case "ag_account":return vr.slice(0,4)+"-"+vr.slice(4,9)+"-"+vr.slice(9,11);
			case "ag_savings":return vr.slice(0,4)+"-"+vr.slice(4,10)+"-"+vr.slice(10,11);
			case "account":return vr.slice(0,5)+"-"+vr.slice(5,7);
			case "cep":return vr.slice(0,5)+"-"+vr.slice(5,8);
			case "uppercase":return vr.toUpperCase();
			case "cpf":return vr.slice(0,3)+"."+vr.slice(3,6)+"."+ vr.slice(6,9)+ "-"+vr.slice(9,11);
			case "cnpj":return vr.slice(0,2)+"."+vr.slice(2,5)+"."+vr.slice(5,8)+"/"+vr.slice(8,12)+"-"+vr.slice(12,14);
			default:return vr;
		}
	}
}
function fmtMoney(vr){
	if(verifyMaxValue(vr)){ERRO=true;return "0,00";}
	var vraux="",p,pDec=vr.indexOf(",");
	var vrDec=vr.slice(pDec+1);
	for(var i=pDec;i>0;i--){
		p=i-pDec;
		if(i !=pDec && (p % 3==0))
			vraux+=".";
		vraux+=vr.charAt(i-1);
	}
	return invertStr(vraux)+","+vrDec;
}
function setMaxValue(vr){MAX_VALUE=vr;}
function verifyMaxValue(vr){return vr.length>0 && (parseFloat(vr)>MAX_VALUE);}
function toFloat(src,numdec){
   src=trim(src);
   var tam=src.length,posDec=src.indexOf(",");
   if(src.length==0)src="0"; 
   if(posDec==-1)return removeStr(src,".")+","+repeatNStr("0",numdec);
   else{
      src=removeStr(src,".");
      if(posDec==0)return "0"+src+repeatNStr("0",numdec+1-src.length);
      else{
         if((posDec>tam-numdec-1))
            src+=repeatNStr("0",posDec-(tam-numdec-1));
         posDec=src.indexOf(",");
         return parseInt(src.slice(0,posDec),10)+src.slice(posDec,posDec+numdec+1);
      }
   }
}


function saltaCampo(ev,field,tp,size){
	var tc,max,nargs=saltaCampo.arguments.length;
	if(/^float/.test(tp))max=(nargs>3)?size:SZ_FLOAT;
	else if(/^money/.test(tp)){
		if(!verifyMaxValue(field.value))max=(nargs>3)?size:SZ_MONEY;
		else field.value="0,00";
	}else if(/^(date|month_year|time|cpf|cnpj|cpf_cnpj|cep|account|branch|percent|ag_account|ag_savings)$/.test(tp))
		max=eval("SZ_"+tp.toUpperCase());
	else if(/^(text|uppercase|interval|(sp_)?alfanumeric|(sp_)?textnumber|default|numeric|email)$/.test(tp))
		max=size;
	tc=brow().isNetscape()?ev.which:ev.keyCode;
	if(String(field.value).length>=max && tc>=48){
		autoSkip(field);
		return true;
	}else return false;
}
function showError(type,msgU,langU){
	if(!langU || langU=="") langU="PT";
	ERRO=true;
	var b=brow();
	var canShow=true;
	if(b.isIE() && parseInt(b.getMajorver(),10)<5){
		if(CURRENT_FIELD && LAST_ERR_FIELD==CURRENT_FIELD && LAST_ERR_VALUE==CURRENT_FIELD.value){
			REPET_ERR=true;
			CURRENT_FIELD.value=LAST_ERR_VALUE="";
			LAST_ERR_FIELD=null;
			canShow=false;
		}else{
			LAST_ERR_FIELD=CURRENT_FIELD;
			LAST_ERR_VALUE=(CURRENT_FIELD?CURRENT_FIELD.value:null);
			REPET_ERR=false;
		}
	}
	if(canShow){
		var m="";
		switch(type){
			case "date":msg=getMsg(langU,1)+m;break;
			case "time":msg=getMsg(langU,2)+m;break;
			case "ag_account":msg="Agência/Conta corrente incorretos"+m;break;
			case "ag_savings":msg="Agência/Conta poupança incorretos"+m;break;
			case "branch":msg="Agência inválida"+m;break;
			case "account":msg="Conta corrente inválida"+m;break;
			case "cep":msg=getMsg(langU,3)+m;break;
			case "email":msg=getMsg(langU,4)+m;break;
			case "cpf":msg=getMsg(langU,5)+m;break;
			case "cnpj":msg=getMsg(langU,6)+m;break;
			case "cpf_cnpj":msg=getMsg(langU,7)+m;break;
			case "month_year":msg=getMsg(langU,8)+m;break;
			default:msg=getMsg(langU,9)+m;
		}
		alert((!msgU || msgU=="")?msg:msgU);
	}
}
function focusCamp(f){
	if(brow().isNetscape())f.value="";
	else f.focus();
	ERRO=true;
}
function focusNetscape(f){
	CURRENT_FIELD=f;
	var b=brow();
	if(b.isNetscape()){
		if(ERRO){LAST_FIELD.focus();ERRO=false;}
	}else if(b.isIE()&& parseInt(b.getMajorver(),10)>4)if(f.select)f.select();
}
function focusField(f){
	if(brow().isIE()){
		CANNOT_FORMAT=true;
		var ac=document.activeElement;var tp=ac.type;
		if(ac && tp && tp=="text")window.focus();
	}
	f.focus();
}
function brow(){
	if(typeof objBrow!="object")objBrow=new Browser();
	return objBrow;
}
function repeatNStr(vr,n){
	var r="",i;
	for(i=0;i<n;i++)r+=vr;
	return r;
}
function unformatFields(form){
   var f,i,tp;
   if(!form)return;
   for(i=0;i<form.length;i++){
      f=form.elements[i];
      if(f.type=="text"){
         tp=getFieldType(f);
         if(tp){
            vr=unformatField(f.value,tp);
            f.value=(!vr?"":vr);
         }
      }
   }
}
function getFieldType(f){
	var blur=f.onblur;
   if(!blur)return null;
   var c=changeStr(removeStr(blur.toString()," "),"\'","\"");
   c=c.replace(/[\n\t]/g,"").toLowerCase();
   var ret=/^.*formatcamp\((.*)\).*$/.exec(c)[1];
   return ret.split("\"")[1];
}

/**
 * Recebe uma string como parametro e um caracter coringa
 * Remove da string todas as ocorrencias do caracter coringa encontrada.
 */
function removeStr(src,arg){
	var v=(typeof arg=="string")?[arg]:arg;
	var r="";
	for(var i=0;i<v.length;i++)r=changeStr(src,v[i],"");
	return r;
}
function repeatStr(src,str,size,orient){
	var r=String(src);
	if(!orient)orient="left";
	while(r.length < size)r=orient.toLowerCase()=="right"?(r+str):(str+r);
	return r;
}
function changeStr(src,from,to)
{
	src=String(src);
	var i,li=0,lFrom= from.length,dst="";
	while((i=src.indexOf(from,li))!=-1){
		dst+=src.substring(li,i)+to;
		li=i+lFrom;
	}
	dst+=src.substring(li);
	return dst;
}
function isNumeric(v){return /^[0-9]+$/.test(v);}
function isAlfa(v){return /^[a-zA-ZáéíóúçãõâêôàÁÉÍÓÚÇÃÕÂÊÔÀ]+$/.test(v);}
function isDate(v){return /^[0-9\/]+$/.test(v);}

function isAlfaNumeric(v){return /^[0-9a-zA-Z]+$/.test(v);}
function invertStr(s){
	var t="",i;
	for(i=0;i<s.length;i++)t=s.charAt(i)+t;
	return t;
}
function isTextNumber(v){return /^[0-9a-zA-ZáéíóúçãõâêôàÁÉÍÓÚÇÃÕÂÊÔÀ]+$/.test(v);
}
function isFloatNumber(n){return /^\d+(,\d+|\d*)$/.test(n);}
//deprecated
//function popup(url,j,atr){var w= window.open(url,j,removeStr(atr," "));}
function random(r1,r2){return Math.round(Math.random()*(r2-r1))+ r2>r1?r1:r2;}
function trim(s){return String(s).replace(/^\s+/,"").replace(/\s+$/,"");}
function autoSkip(field,orient){
	var ind=-1;
	var f= field.form;
	for(i=0;i<f.elements.length;i++)
		if(field==f.elements[i]){ind=i;break;}
	focusCampByPos(f,ind,orient);
}
function autoFocus(f){focusCampByPos((arguments.length==0?document.forms[0]:f),-1);}
function focusCampByPos(fr,ind,orient){
	orient=orient?orient:"down";
	var iNext=(orient=="down"?1:-1),el;
	if((typeof fr.elements[ind+iNext])=="undefined"){
		if(ind!=-1)fr.elements[ind].blur();
		return;
	}
	for(var i=ind+iNext;i<fr.elements.length;i+=iNext){
		el=fr.elements[i];
		if(/^(text|password|select.*)$/.test(el.type) && !el.disabled){el.focus();return;}
	}
	fr.elements[ind].blur();
}
function getMsg(cd_idioma, nr_msg)
{
	var msg = new Array ();
	msg["PT"] = new Array ();
	msg["PT"][1] = "Data inválida";
	msg["PT"][2] = "Hora inválida";
	msg["PT"][3] = "CEP inválido";
	msg["PT"][4] = "Email incorreto";
	msg["PT"][5] = "CPF inválido";
	msg["PT"][6] = "CNPJ inválido";
	msg["PT"][7] = "CPF/CNPJ inválido";
	msg["PT"][8] = "Mês e ano inválidos";
	msg["PT"][9] = "Valor inválido";
    msg["EN"] = new Array ();
	msg["EN"][1] = "Invalid date";
	msg["EN"][2] = "Invalid hour";
	msg["EN"][3] = "Invalid CEP";
	msg["EN"][4] = "Email is not correct";
	msg["EN"][5] = "Invalid CPF";
	msg["EN"][6] = "Invalid CNPJ";
	msg["EN"][7] = "Invalid CPF/CNPJ";
	msg["EN"][8] = "Invalid month and year";
	msg["EN"][9] = "Invalid value";
	return msg[cd_idioma][nr_msg];
}

/*
function NovaJanela(url,nome)
{
	window.open(url,nome);
}
*/

function openJanela(id)
{
  	window.open('m_mostrarImagensImovel.php?id_imovel='+id,'Imovel','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,menubar=no,width=320,height=390');
}

function openJanelaFoto(id)
{
  	window.open('image.php?id_image='+id,'Imovel','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,menubar=no,width=320,height=390');
}


/**
 * Abre a janela pop up com os detalhes do apartamento em promoção
 */
function openJanelaPromocao(id)
{
  	window.open('promocao_janela.php?id_imovel='+id,'Promocao','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,menubar=no,width=320,height=390');
}

/**
 * Abre a janela pop up para que o usuário faça a sua reserva.
 */
function openJanelaReserva(id)
{
  	window.open('m_reserva.php?id_imovel='+id,'Reserva','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,menubar=no,width=460,height=470');
}

/**
 * Escreve na tela a data atual.
 */
function getDataAtual()
{
	
    hoje = new Date()
	
	dia = hoje.getDate()
	
	dias = hoje.getDay()
	
	mes = hoje.getMonth()
	
	ano = hoje.getYear()

    if (dia < 10)
		dia = "0" + dia
    if (ano < 2000)
		ano = "19" + ano


	function CriaArray (n) 
	{
	    this.length = n 
	}
	NomeDia = new CriaArray(7)
	NomeDia[0] = "Domingo"
	NomeDia[1] = "Segunda-feira"
	NomeDia[2] = "Ter&ccedil;a-feira"
	NomeDia[3] = "Quarta-feira"
	NomeDia[4] = "Quinta-feira"
	NomeDia[5] = "Sexta-feira"
	NomeDia[6] = "S&aacute;bado"

	NomeMes = new CriaArray(12)
	NomeMes[0] = "Janeiro"
	NomeMes[1] = "Fevereiro"
	NomeMes[2] = "Mar&ccedil;o"
	NomeMes[3] = "Abril"
	NomeMes[4] = "Maio"
	NomeMes[5] = "Junho"
	NomeMes[6] = "Julho"
	NomeMes[7] = "Agosto"
	NomeMes[8] = "Setembro"
	NomeMes[9] = "Outubro"
	NomeMes[10] = "Novembro"
	NomeMes[11] = "Dezembro"

	function WriteDate() {
	    document.write (NomeDia[dias] + ", " + dia + " de " + NomeMes[mes] + " de " + ano)
	}
	WriteDate();
}
