
var httpRequest,httpRequest2;

// url_encode version 1.0 
function url_encode(str) { 
	var hex_chars = "0123456789ABCDEF"; 
	var noEncode = /^([a-zA-Z0-9\_\-\.])$/; 
	var n, strCode, hex1, hex2, strEncode = ""; 

	for(n = 0; n < str.length; n++) { 
		if (noEncode.test(str.charAt(n))) { 
			strEncode += str.charAt(n); 
		} else { 
			strCode = str.charCodeAt(n); 
			hex1 = hex_chars.charAt(Math.floor(strCode / 16)); 
			hex2 = hex_chars.charAt(strCode % 16); 
			strEncode += "%" + (hex1 + hex2); 
		} 
	} 
	return strEncode; 
} 

// url_decode version 1.0 
function url_decode(str) { 
	var n, strCode, strDecode = ""; 

	for (n = 0; n < str.length; n++) { 
		if (str.charAt(n) == "%") { 
			strCode = str.charAt(n + 1) + str.charAt(n + 2); 
			strDecode += String.fromCharCode(parseInt(strCode, 16)); 
			n += 2; 
		} else { 
			strDecode += str.charAt(n); 
		} 
	} 

	return strDecode; 
}

function requestPage(endereco, id_div, opcao)
{
	div				=	id_div;

	if (window.XMLHttpRequest)
	{
		httpRequest		=	new XMLHttpRequest();
		
		httpRequest.onreadystatechange		=	carregar;
		httpRequest.open("GET", endereco+"?&opcao="+opcao, true);
		httpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		httpRequest.send(null);

	} else if (window.ActiveXObject)
			{
				httpRequest		= 	new ActiveXObject("Microsoft.XMLHTTP");
				httpRequest.onreadystatechange		=	carregar;
				httpRequest.open("GET", endereco, true);
				httpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				httpRequest.send();
			}
}


function carregar()
{
	if (httpRequest.readyState == 4)
	{
		if (httpRequest.status == 200)
			{
			  document.getElementById(div).innerHTML		=	httpRequest.responseText;
			 
			}
		else
		{
			alert("Sistema indisponível.");
			document.getElementById(div).innerHTML			=	'';
		}
	}
	else
		document.getElementById(div).innerHTML			=	"<img border=0 src='../images/loading.gif' />";
}



function carregaRelatorioUsuario(endereco, id_div,opcao, dataInicial,dataFinal)
{
	div				=	id_div;
	
	if (window.XMLHttpRequest)
	{
		httpRequest		=	new XMLHttpRequest();
		
		httpRequest.onreadystatechange		=	carregar;
		httpRequest.open("GET", endereco+"?&opcao="+opcao+"&dataInicial="+dataInicial+"&dataFinal="+dataFinal, true);
		httpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		httpRequest.send(null);
		
		
	} else if (window.ActiveXObject)
			{
				httpRequest		= 	new ActiveXObject("Microsoft.XMLHTTP");
				httpRequest.onreadystatechange		=	carregar;
				httpRequest.open("GET", endereco+"?&opcao="+opcao+"&dataInicial="+dataInicial+"&dataFinal="+dataFinal, true);
				httpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				httpRequest.send();
			}
}

function carregaRelatorioUsuarioMes(endereco, id_div,opcao,mes,ano)
{
	div				=	id_div;
	
	if (window.XMLHttpRequest)
	{
		httpRequest		=	new XMLHttpRequest();
		
		httpRequest.onreadystatechange		=	carregar;
		httpRequest.open("GET", endereco+"?&opcao="+opcao+"&mes="+mes+"&ano="+ano, true);
		httpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		httpRequest.send(null);
		
		
	} else if (window.ActiveXObject)
			{
				httpRequest		= 	new ActiveXObject("Microsoft.XMLHTTP");
				httpRequest.onreadystatechange		=	carregar;
				httpRequest.open("GET", endereco+"?&opcao="+opcao+"&mes="+mes+"&ano="+ano, true);
				httpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				httpRequest.send();
			}
}

function carregaRelatorioUsuarioDestino(endereco, id_div,opcao, dataInicial,dataFinal)
{
	div				=	id_div;
	
	if (window.XMLHttpRequest)
	{
		httpRequest		=	new XMLHttpRequest();
		
		httpRequest.onreadystatechange		=	carregar;
		httpRequest.open("GET", endereco+"?&opcao="+opcao+"&dataInicial="+dataInicial+"&dataFinal="+dataFinal, true);
		httpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		httpRequest.send(null);
		
		
	} else if (window.ActiveXObject)
			{
				httpRequest		= 	new ActiveXObject("Microsoft.XMLHTTP");
				httpRequest.onreadystatechange		=	carregar;
				httpRequest.open("GET", endereco+"?&opcao="+opcao+"&dataInicial="+dataInicial+"&dataFinal="+dataFinal, true);
				httpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				httpRequest.send();
			}
}

function carregaRelatorioUsuarioDestinoMes(endereco, id_div,opcao,mes,ano)
{
	div				=	id_div;
	
	if (window.XMLHttpRequest)
	{
		httpRequest		=	new XMLHttpRequest();
		
		httpRequest.onreadystatechange		=	carregar;
		httpRequest.open("GET", endereco+"?&opcao="+opcao+"&mes="+mes+"&ano="+ano, true);
		httpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		httpRequest.send(null);
		
		
	} else if (window.ActiveXObject)
			{
				httpRequest		= 	new ActiveXObject("Microsoft.XMLHTTP");
				httpRequest.onreadystatechange		=	carregar;
				httpRequest.open("GET", endereco+"?&opcao="+opcao+"&mes="+mes+"&ano="+ano, true);
				httpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				httpRequest.send();
			}
}

function carregaRelatorioCliente(endereco, id_div,opcao, dataInicial,dataFinal)
{
	div				=	id_div;
	
	if (window.XMLHttpRequest)
	{
		httpRequest		=	new XMLHttpRequest();
		
		httpRequest.onreadystatechange		=	carregar;
		httpRequest.open("GET", endereco+"?&opcao="+opcao+"&dataInicial="+dataInicial+"&dataFinal="+dataFinal, true);
		httpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		httpRequest.send(null);
		
		
	} else if (window.ActiveXObject)
			{
				httpRequest		= 	new ActiveXObject("Microsoft.XMLHTTP");
				httpRequest.onreadystatechange		=	carregar;
				httpRequest.open("GET", endereco+"?&opcao="+opcao+"&dataInicial="+dataInicial+"&dataFinal="+dataFinal, true);
				httpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				httpRequest.send();
			}
}

function carregaRelatorioClienteMes(endereco, id_div,opcao,mes,ano)
{
	div				=	id_div;
	
	if (window.XMLHttpRequest)
	{
		httpRequest		=	new XMLHttpRequest();
		
		httpRequest.onreadystatechange		=	carregar;
		httpRequest.open("GET", endereco+"?&opcao="+opcao+"&mes="+mes+"&ano="+ano, true);
		httpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		httpRequest.send(null);
		
		
	} else if (window.ActiveXObject)
			{
				httpRequest		= 	new ActiveXObject("Microsoft.XMLHTTP");
				httpRequest.onreadystatechange		=	carregar;
				httpRequest.open("GET", endereco+"?&opcao="+opcao+"&mes="+mes+"&ano="+ano, true);
				httpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				httpRequest.send();
			}
}

function carregaRelatorioStatus(endereco, id_div,opcao, dataInicial,dataFinal)
{
	div				=	id_div;
	
	if (window.XMLHttpRequest)
	{
		httpRequest		=	new XMLHttpRequest();
		
		httpRequest.onreadystatechange		=	carregar;
		httpRequest.open("GET", endereco+"?&opcao="+opcao+"&dataInicial="+dataInicial+"&dataFinal="+dataFinal, true);
		httpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		httpRequest.send(null);
		
		
	} else if (window.ActiveXObject)
			{
				httpRequest		= 	new ActiveXObject("Microsoft.XMLHTTP");
				httpRequest.onreadystatechange		=	carregar;
				httpRequest.open("GET", endereco+"?&opcao="+opcao+"&dataInicial="+dataInicial+"&dataFinal="+dataFinal, true);
				httpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				httpRequest.send();
			}
}

function carregaRelatorioStatusMes(endereco, id_div,opcao,mes,ano)
{
	div				=	id_div;
	
	if (window.XMLHttpRequest)
	{
		httpRequest		=	new XMLHttpRequest();
		
		httpRequest.onreadystatechange		=	carregar;
		httpRequest.open("GET", endereco+"?&opcao="+opcao+"&mes="+mes+"&ano="+ano, true);
		httpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		httpRequest.send(null);
		
		
	} else if (window.ActiveXObject)
			{
				httpRequest		= 	new ActiveXObject("Microsoft.XMLHTTP");
				httpRequest.onreadystatechange		=	carregar;
				httpRequest.open("GET", endereco+"?&opcao="+opcao+"&mes="+mes+"&ano="+ano, true);
				httpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				httpRequest.send();
			}
}
