//*** INICIO FUNCAO PARA MOSTRAR E OCULTAR CAMPOS ***//
	// Mostra a camada
	function mostrar_camada(camadas) {
		var camada = camadas.split(",");

		for(i=0;i<camada.length;i++) {
			document.getElementById(camada[i]).style.display="block";
		}
	}

	// Oculta a camada
	function ocultar_camada(camadas) {
		var camada = camadas.split(",");

		for(i=0;i<camada.length;i++) {
			document.getElementById(camada[i]).style.display="none";
		}
	}
//*** FIM FUNCAO PARA MOSTRAR E OCULTAR CAMPOS ***//

//*** INICIO VARIAS FUNCOES ***//
	// Confirma exclusao
	function confirma_acao(msg,url){
		if(confirm(msg)) {
			open(url,"_self");
		}
	}

	// Abrir janela pop-up
	function nova_janela(url,nome_janela,largura_janela,altura_janela) {
		posicao_x = ((window.screen.width-50)-largura_janela)/2;
		posicao_y = ((window.screen.height)-altura_janela)/2;

		window.open(url, nome_janela, 'top='+ posicao_y +',left='+ posicao_x +',width='+ largura_janela +',height='+ altura_janela +'');
	}
	
	// Abre nova URL
	function jump_url(targ,selObj){ //v3.0
		eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
	}	
	
	// Abrir foto ampliada
	function ampliar_foto_detalhesimovel(imagem) {
		var subImages = document.getElementById('foto_ampliada_di');
		subImages.src = imagem;
	}
	
	// Maxima a tela e centraliza
	function maximiza_tela() {
		window.moveTo(0,0);
		window.resizeTo(screen.width,screen.height);
	}

//CNPJ//
function mascaraCnpj(campo, teclapres){
	var tecla = teclapres.keyCode;
	var vr = new String(campo.value);
	vr = vr.replace(".", "");
	vr = vr.replace("/", "");
	vr = vr.replace("-", "");
	tam = vr.length + 1;
		if (tecla != 14){
		if (tam == 3)
			campo.value = vr.substr(0, 2) + '.';
		if (tam == 6)
			campo.value = vr.substr(0, 2) + '.' + vr.substr(2, 5) + '.';
		if (tam == 10)
			campo.value = vr.substr(0, 2) + '.' + vr.substr(2, 3) + '.' + vr.substr(6, 3) + '/';
		if (tam == 15)
			campo.value = vr.substr(0, 2) + '.' + vr.substr(2, 3) + '.' + vr.substr(6, 3) + '/' + vr.substr(9, 4) + '-' + vr.substr(13, 2);
	}
}

//INSCRIÇÃO ESTADUAL//
function mascaraInscEstadual(campo, teclapres){
	var tecla = teclapres.keyCode;
	var vr = new String(campo.value);
	vr = vr.replace(".", "");
	vr = vr.replace("-", "");
	tam = vr.length + 1;
		if (tecla != 9){
		if (tam == 3)
			campo.value = vr.substr(0, 2) + '.';
		if (tam == 6)
			campo.value = vr.substr(0, 2) + '.' + vr.substr(2, 5) + '.';
		if (tam == 10)
			campo.value = vr.substr(0, 2) + '.' + vr.substr(2, 3) + '.' + vr.substr(6, 3) + '-' + vr.substr(9, 4);
	}
}

//CEP//
function mascaraCEP(campo, teclapres){
	var tecla = teclapres.keyCode;
	var vr = new String(campo.value);
	vr = vr.replace("-", "");
	tam = vr.length + 1;
		if (tecla != 9){
		if (tam == 6)
			campo.value = vr.substr(0, 5) + '-';
	}
}

//TELEFONE//
function mascaraTelefone(element, e){
  if (e.keyCode != 8){
    length = element.value.length;
    if (length == 2){
      if (element.value.charAt(0)!="(")
        element.value = "(" + element.value + ")";
    }
    if (length == 3)
      if (element.value.charAt(0)=="(")
        element.value += ")";
    if (length == 8)
      element.value += "-";
  }
}

//*** INICIO - HINT ***/
var horizontal_offset = "5px"; //horizontal offset of hint box from anchor link

var vertical_offset="0" //horizontal offset of hint box from anchor link. No need to change.
var ie=document.all
var ns6=document.getElementById&&!document.all

function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
var edgeoffset=(whichedge=="rightedge")? parseInt(horizontal_offset)*-1 : parseInt(vertical_offset)*-1
if (whichedge=="rightedge"){
var windowedge=ie && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-30 : window.pageXOffset+window.innerWidth-40
dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure+obj.offsetWidth+parseInt(horizontal_offset)
}
else{
var windowedge=ie && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure-obj.offsetHeight
}
return edgeoffset
}

function showhint(menucontents, obj, e, tipwidth){
if ((ie||ns6) && document.getElementById("hintbox")){
dropmenuobj=document.getElementById("hintbox")
dropmenuobj.innerHTML=menucontents
dropmenuobj.style.left=dropmenuobj.style.top=-500
if (tipwidth!=""){
dropmenuobj.widthobj=dropmenuobj.style
dropmenuobj.widthobj.width=tipwidth
}
dropmenuobj.x=getposOffset(obj, "left")
dropmenuobj.y=getposOffset(obj, "top")
dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+obj.offsetWidth+"px"
dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+"px"
dropmenuobj.style.visibility="visible"
obj.style.cursor="default"
obj.onmouseout=hidetip
}
}

function hidetip(e){
dropmenuobj.style.visibility="hidden"
dropmenuobj.style.left="-500px"
}

function createhintbox(){
var divblock=document.createElement("div")
divblock.setAttribute("id", "hintbox")
document.body.appendChild(divblock)
}

if (window.addEventListener)
window.addEventListener("load", createhintbox, false)
else if (window.attachEvent)
window.attachEvent("onload", createhintbox)
else if (document.getElementById)
window.onload=createhintbox
//*** FIM - HINT ***/

//DATAS//
function mascaraData_inicio(campoData_inicio){              
		var data_inicio = campoData_inicio.value;              
			if (data_inicio.length == 2){                  
		data_inicio = data_inicio + '/';                  
		document.form1[0].data_inicio.value = data_inicio;
		    return true;
				}
			if (data_inicio.length == 5){                  
		data_inicio = data_inicio + '/';                  
		document.form1[0].data_inicio.value = data_inicio;                  
			return true;              
			}
		} 

function mascaraData_fim(campoData_fim){              
		var data_fim = campoData_fim.value;              
			if (data_fim.length == 2){                  
		data_fim = data_fim + '/';                  
		document.forms[0].data_fim.value = data_fim;
		    return true;
				}
			if (data_fim.length == 5){                  
		data_fim = data_fim + '/';                  
		document.forms[0].data_fim.value = data_fim;                  
			return true;              
			}
		}
		
function mascaraData(campoData){              
		var data = campoData.value;              
			if (data.length == 2){                  
		data = data + '/';                  
		document.forms[0].data.value = data;
		    return true;
				}
			if (data.length == 5){                  
		data = data + '/';                  
		document.forms[0].data.value = data;                  
			return true;              
			}
		} 
		
function mascaraData_doc(campoData_doc){              
		var data_doc = campoData_doc.value;              
			if (data_doc.length == 2){                  
		data_doc = data_doc + '/';                  
		document.forms[0].data_doc.value = data_doc;
		    return true;
				}
			if (data_doc.length == 5){                  
		data_doc = data_doc + '/';                  
		document.forms[0].data_doc.value = data_doc;                  
			return true;              
			}
		}
		
function mascaraData_venc(campoData_venc){              
		var data_venc = campoData_venc.value;              
			if (data_venc.length == 2){                  
		data_venc = data_venc + '/';                  
		document.forms[0].data_venc.value = data_venc;
		    return true;
				}
			if (data_venc.length == 5){                  
		data_venc = data_venc + '/';                  
		document.forms[0].data_venc.value = data_venc;                  
			return true;              
			}
		}
	
//SELECIONA TUDO //
function marcar_tudo(){ 
   for (i=0;i<document.form1.elements.length;i++) 
      if(document.form1.elements[i].type == "checkbox")	
         document.form1.elements[i].checked=1 
}

function desmarcar_tudo(){ 
   for (i=0;i<document.form1.elements.length;i++) 
      if(document.form1.elements[i].type == "checkbox")	
         document.form1.elements[i].checked=0 
}

