//SIMPLICA O USO DO document.getElementById
function e(objeto){
	return document.getElementById(objeto);	
}

//Lê a URL pegando as variaveis
function urlDecode(string, overwrite){
    if(!string || !string.length){
        return {};
    }
    var obj = {};
    var pairs = string.split('&');
    var pair, name, value;
    var lsRegExp = /\+/g;
    for(var i = 0, len = pairs.length; i < len; i++){
        pair = pairs[i].split('=');
        name = unescape(pair[0]);
        value = unescape(pair[1]).replace(lsRegExp, " ");
        if(overwrite !== true){
            if(typeof obj[name] == "undefined"){
                obj[name] = value;
            }else if(typeof obj[name] == "string"){
                obj[name] = [obj[name]];
                obj[name].push(value);
            }else{
                obj[name].push(value);
            }
        }else{
            obj[name] = value;
        }
    }
    return obj;
}

//usa a urlDecode pra passando como parametro a variavel GET desejada e retornando seu valor
function jsGet(param)
{
	var wl = window.location.href;
	var params = urlDecode(wl.substring(wl.indexOf("?")+1));
	return(params[param]);
}

//FAZ A CHAMA AJAX ESPERANDO O RESULTADO EM XML
function ajaxXML(url){
	http_request = new XMLHttpRequest();
	http_request.onreadystatechange = function()
	{
	if(http_request.readyState < 4)
	{
		e('setor_status').innerHTML = "Processando...";
	}
	else if(http_request.readyState == 4)
	{
		if(http_request.status == 200){
			return http_request.responseXML;
		}else{
			alert("Erro ao recuperar os dados");
		}
	}
}
	http_request.open('GET', url);
	http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	http_request.send(null);
}

function openAjax() {
	var ajax;
	try {
		ajax = new XMLHttpRequest();
	} catch(ee) {
		try {
			ajax = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e)  {
			try {
				ajax = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(E)  {
				ajax = false;
			}
		}
	}
	return ajax;
}


//FAZ A CHAMA AJAX ESPERANDO O RESULTADO EM HTML, TEXTO
function ajaxHTML(url, retorno){
	http_request = new openAjax();
	http_request.onreadystatechange = function()
	{
	if(http_request.readyState < 4)
	{
		e('status').innerHTML = "Processando...";
	}
	else if(http_request.readyState == 4)
	{
		if(http_request.status == 200){
			e('status').innerHTML = "";			
			e(retorno).innerHTML = http_request.responseText;
		}else{
			alert("Erro ao recuperar os dados");
		}
	}
}
	http_request.open('GET', url);
	http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	http_request.send(null);
}
function ajaxHTMLnovo(url, retorno){
	http_requestnovo = new openAjax();
	http_requestnovo.onreadystatechange = function()

	{
	if(http_requestnovo.readyState < 4)
	{
		e('status').innerHTML = "Processando...";
	}
	else if(http_requestnovo.readyState == 4)
	{
		if(http_requestnovo.status == 200){
			e('status').innerHTML = "";			
			e(retorno).innerHTML = http_requestnovo.responseText;
		}else{
			alert("Erro ao recuperar os dados");
		}
	}
}
	http_requestnovo.open('GET', url);
	http_requestnovo.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	http_requestnovo.send(null);
}

function atualiza_extrato(chv_conta) {
	url = 'ajax/capital_extrato.php?conta='+chv_conta+'&data_inicial='+e('dta_inicial').value+'&data_final='+e('dta_final').value;
	retorno = 'extrato_capital';
	ajax = ajaxHTML(url, retorno);
}
function atualiza_extrato_cea(chv_conta) {
	url = 'ajax/capital_cea.php?conta='+chv_conta+'&data_inicial='+e('dta_inicial').value+'&data_final='+e('dta_final').value;
	retorno = 'extrato_capital';
	ajax = ajaxHTML(url, retorno);
}
//Lista de convenio com as imagens
function listaConveniosCompleto(filtro){
	ajaxHTML('includes/inc_convenios.php?filtro='+filtro,'convenios');
}

//Tabela com lista de convenios
function listaConvenios(filtro){
	ajaxHTML('includes/inc_solicita_comprovante.php?filtro='+filtro,'convenios');
}

function popupConvenio(convenio){
	window.open("comprovante.php?ajax=1&convenio="+convenio,"Confirmacao","width=350, height=500, scrollbars=1, top=0,left=0");
}
function verificaLogin(idForm, urlDestino){
	if(e(idForm)){
		alert('Somente cooperados logados podem acessar esta página');
		e(idForm).style.border = "1px #F00 solid";
		return false;
	}
	location = urlDestino;
}
