// JavaScript Document
//Função do ajax
function makeRequest(url,dive,tipo_load) {
				
				toTop();
				
				 if (!dive) {
					dive = 'Corpo' 
				 }
				 				 
				loading(dive,tipo_load);
								
				url = antiCacheRand(url);
				
				//toTop();
                http_request = false;

                if (window.XMLHttpRequest) { // Mozilla, Safari,...
                    http_request = new XMLHttpRequest();
                    if (http_request.overrideMimeType) {
                        http_request.overrideMimeType('text/xml');
                    }
                } else if (window.ActiveXObject) { // IE
					
                    try {
                        http_request = new ActiveXObject("Msxml3.XMLHTTP");
						
                    } catch (e) {
                        try {
                        http_request = new ActiveXObject("Microsoft.XMLHTTP");
						
                        } catch (e) {}
                    }
                }

                if (!http_request) {
                    alert('Seu navegador não suporta este site!');
                    return false;
                }
                //alert(http_request.onreadystatechange)
				http_request.onreadystatechange = function(){ carrega_pagina(dive); };
                http_request.open('get', url, true);
                http_request.send(null);
				
            }

            function carrega_pagina(dive) {

                if (http_request.readyState == 4) {
                   if (http_request.status == 200) {
						document.getElementById(dive).innerHTML=http_request.responseText;
                   } else {
                        alert('Houve um erro nesta página. Tente novamente mais tarde!');
                   }
  	 		}
	
}
//a função que gera o randomico *********
function antiCacheRand(aurl){
    var dt = new Date();
    if(aurl.indexOf("?")>=0){// já tem parametros
        return aurl + "&" + encodeURI(Math.random() + "_" + dt.getTime());
    }else{ return aurl + "?" + encodeURI(Math.random() + "_" + dt.getTime());}
}

//Funcao do loading
function loading(dive,tipo) {
	if (tipo == undefined) {
		tipo = '1'
	}
	
	if (tipo != '3') {
		if (tipo == '' || tipo == '1') {
			document.getElementById(dive).innerHTML='<center><span class=tahoma_12_fff>Carregando...</span></center>';
		} else {
			if (tipo == '2') {
				document.getElementById(dive).innerHTML='<table width=100 border=0 cellspacing=0 cellpadding=0><tr><td width=23><img src=icon/loading.gif width=16 height=16></td><td width=77 class=tahoma_12_fff>carregando...</td></tr></table>';
			}
		}
	}
}
//Joga para o topo
function toTop() {
        self.scrollTo(0, 512)
}

//Funçao que abre ou fecha uma div como display
// Pode-se chamar uma função para acão quando a div aparece. (Somente com um parametro. Por exemplo fuc_div('observacoes','selecionaFoco(cli_observacao)'); )
function fuc_div(div,funcao) {
	var dive_esta = document.getElementById(div).style.display;
	if (dive_esta == '') {
		document.getElementById(div).style.display='block';
		if (funcao != '') {
			funcao_splt = funcao.split("(");						 
			funcao_fuc = funcao_splt[0];	
			funcao_campo = funcao_splt[1];
			funcao_campo = funcao_campo.replace(")", ""); 
				
			eval(funcao_fuc+'('+String.fromCharCode(39)+funcao_campo+String.fromCharCode(39)+')');
		}
	} else {
		if (dive_esta == 'block') {
			document.getElementById(div).style.display='none';
		} else {
			document.getElementById(div).style.display='block';
			if (funcao != '') {
				funcao_splt = funcao.split("(");
				funcao_fuc = funcao_splt[0];	
				funcao_campo = funcao_splt[1];
				funcao_campo = funcao_campo.replace(")", "") 
				
				eval(funcao_fuc+'('+String.fromCharCode(39)+funcao_campo+String.fromCharCode(39)+')');
			}
		}
	}
}