function confirma () {
  if (confirm('Confirma a exclusão?')) {
    return true;
  }else{
    return false;
  }
}
function subMenu(id){
  if (document.getElementById(id).style.display == 'none') {
	document.getElementById(id).style.display = 'inline';
  } else {
	document.getElementById(id).style.display = 'none';
  }
}
function over(src,cursor) {src.bgColor = "#AFB8CF"}
function out(src) {src.bgColor = ""}
function voltar() {window.history.back()}
function imprimir() {window.print()}
function fechar() {window.close()}
function abrir() {
	var windowFeatures = "", nomeArquivo = "", nomeJanela = "", erro = null
	Argumentos = abrir.arguments; noArgumentos = Argumentos.length; nomeArquivo = Argumentos[0]
	for (i = 1; i < noArgumentos; i++) {
		valor = Argumentos[i].substring(2,Argumentos[i].length)
		switch(Argumentos[i].substring(0,2)) {
			case "nj" : nomeJanela = valor; break
			case "to" : windowFeatures += "top=" + valor + ", "; break
			case "le" : windowFeatures += "left=" + valor + ", "; break
			case "he" : windowFeatures += "height=" + valor + ", "; break
			case "wi" : windowFeatures += "width=" + valor + ", "; break
			case "lb" : windowFeatures += "location=" + valor + ", "; break
			case "mb" : windowFeatures += "menubar=" + valor + ", "; break
			case "sc" : windowFeatures += "scrollbars=" + valor + ", "; break
			case "st" : windowFeatures += "status=" + valor + ", "; break
			case "tb" : windowFeatures += "toolbar=" + valor + ", "; break
			case "tt" : windowFeatures += "titlebar=" + valor + ", "; break
			case "re" : windowFeatures += "resizable=" + valor + ", "; break
			default : erro = '"Código de atributo não informado no '+(i+1)+' º argumento (' +Argumentos[i]+ ')"'
		}
	}
	windowFeatures = windowFeatures.substring(0,windowFeatures.lastIndexOf(","))
	if (erro) { alert(erro) } else { novaJanela = window.open(nomeArquivo, nomeJanela, windowFeatures) }
}

var aLabelList = new Array()
var aErrorList = new Array()
var regEx = /^.+@.+\..{2,3}$/
function fgFormValidate(oForm) {
    var iLabelCount = 0
    var sError = ""

    aLabelList.splice(0, aLabelList.length)
    aErrorList.splice(0, aErrorList.length)
        	
    feFormValidate(oForm)
        	
    if (aLabelList.length == 1)
        sError += "* O campo '" + aLabelList[0] + "' é obrigatório.\n"
    if (aLabelList.length > 1) {
        iLabelCount = 0
        sError += "* Os campos "
        for (i = 0; i < aLabelList.length; i++) {
            iLabelCount++
            sError += "'" + aLabelList[i] + "'"
            if (iLabelCount != aLabelList.length) 
                if (iLabelCount == (aLabelList.length - 1)) sError += " e "; else sError += ", " 
        }
        sError += " são obrigatórios.\n"
    }
    if (aErrorList.length > 0) {
        sError += "\n"
        for (i = 0; i < aErrorList.length; i++) sError += "* " + aErrorList[i] + "\n"
        sError = sError.substr(0, (sError.length - 1))
    }
    if (sError == "") { return true } else { alert(sError); return false }
}
function fgFormValidateBusca(oForm) {
    var iLabelCount = 0
    var sError = ""

    aLabelList.splice(0, aLabelList.length)
    aErrorList.splice(0, aErrorList.length)
        	
    feFormValidateBusca(oForm)
        	
    if (aLabelList.length == 1)
        sError += "* O campo '" + aLabelList[0] + "' é obrigatório.\n"
    if (aLabelList.length > 1) {
        iLabelCount = 0
        sError += "* Os campos "
        for (i = 0; i < aLabelList.length; i++) {
            iLabelCount++
            sError += "'" + aLabelList[i] + "'"
            if (iLabelCount != aLabelList.length) 
                if (iLabelCount == (aLabelList.length - 1)) sError += " e "; else sError += ", " 
        }
        sError += " são obrigatórios.\n"
    }
    if (aErrorList.length > 0) {
        sError += "\n"
        for (i = 0; i < aErrorList.length; i++) sError += "* " + aErrorList[i] + "\n"
        sError = sError.substr(0, (sError.length - 1))
    }
    if (sError == "") { return true } else { alert(sError); return false }
}

function validaUsuario(campo) {
   if(campo.value == ''){
   	campo.value = 'Usuário';
   }
}
function validaSenha(campo) {
   if(campo.value == ''){
   	campo.value = 'Senha';
   }
}
function Sel_pag(targ,selObj,restore){ 
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
function formatarValor(src, mask) {
			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 formataDecimal(campo,tammax,teclapres) {
	
	var tecla = teclapres.keyCode;
		vr = document.frmContato[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.frmContato[campo].value = vr; 
			}
			if ( (tam > 2) && (tam <= 5) ){
				document.frmContato[campo].value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ); 
			}
			if ( (tam >= 6) && (tam <= 8) ){
				document.frmContato[campo].value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ); 
			}
			if ( (tam >= 9) && (tam <= 11) ){
				document.frmContato[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.frmContato[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.frmContato[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 );
			}
		}
}
	function IsNum(obj,event){
			var str = obj.value;
			var Tecla = event.which;
			if(Tecla == null)
				Tecla = event.keyCode;
			if ( Tecla <= 46 || Tecla > 59){
				event.returnValue = false;
				alert("Só devem ser digitados números.")
				return false;
			}
			event.returnValue = true;
			return true;
		}	
	function comboTroca(strNegociacao){
	  document.frmBusca.nmValor.options.length = 0;
		  if (strNegociacao == "Locação"){
				document.frmBusca.nmValor.options[0] = new Option("Qualquer","");
				document.frmBusca.nmValor.options[1] = new Option("R$250 a R$450","1");
				document.frmBusca.nmValor.options[2] = new Option("R$451 a R$600","2");
				document.frmBusca.nmValor.options[3] = new Option("R$601 a R$800","3");
				document.frmBusca.nmValor.options[4] = new Option("R$801 a R$1.000","4");
				document.frmBusca.nmValor.options[5] = new Option("R$1.001 a R$1.500","5");
				document.frmBusca.nmValor.options[6] = new Option("R$1.501 a R$2.000","6");
				document.frmBusca.nmValor.options[7] = new Option("Acima de  R$2.000","7");
		  }
		  if (strNegociacao == "Venda"){
				document.frmBusca.nmValor.options[0] = new Option("Qualquer","");
				document.frmBusca.nmValor.options[1] = new Option("até R$ 100.000","1");
				document.frmBusca.nmValor.options[2] = new Option("R$101.000 a R$150.000","2");
				document.frmBusca.nmValor.options[3] = new Option("R$151.000 a R$200.000","3");
				document.frmBusca.nmValor.options[4] = new Option("R$201.000 a R$250.000","4");
				document.frmBusca.nmValor.options[5] = new Option("R$251.000 a R$300.000","5");
				document.frmBusca.nmValor.options[6] = new Option("R$301.000 a R$350.000","6");
				document.frmBusca.nmValor.options[7] = new Option("R$351.000 a R$400.000","7");
				document.frmBusca.nmValor.options[8] = new Option("R$401.000 a R$450.000","8");
				document.frmBusca.nmValor.options[9] = new Option("R$451.000 a R$500.000","9");
				document.frmBusca.nmValor.options[10] = new Option("R$501.000 a R$550.000","10");
				document.frmBusca.nmValor.options[11] = new Option("R$551.000 a R$600.000","11");
				document.frmBusca.nmValor.options[12] = new Option("Acima de R$600.000","12");
		  }
		 
	  }	
	function ExibeFlash(src, larg, alt, vars)
	{
		var strHtml = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="'+ larg +'" height="'+ alt +'">';
		strHtml += '<param name="movie" value="'+ src +'" />';
		strHtml += '<param name="quality" value="high" />';
		strHtml += '<param name="menu" value="false" />';
		strHtml += ' <param name="wmode" value="transparent">';
		strHtml += '<embed src="'+ src +'" wmode="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+ larg +'" height="'+ alt +'"></embed>';
		strHtml += '</object>';
		
		document.write(strHtml);
	}