﻿// Basic Ajax Framework for ASP
// http://www.rads.com.br/ajax_main.php?m=1&id=6
// Murilo Vieira

function enviaPage(url, metodo, modo, tagId, parametros)
{
    goAjax(url+"?"+parametros+"&rnd"+ Math.random(), metodo, modo, tagId);
}

function goAjax(url, metodo, modo, tagRetorno) {
    document.getElementById(tagRetorno).innerHTML='<div align="center" class="arial12cinza">carregando...</div>'

    var xmlhttp=false;

    try {
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
        try {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (E) {
            xmlhttp = false;
        }
    }
    
    if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
	    try {
		    xmlhttp = new XMLHttpRequest();
	    } catch (e) {
		    xmlhttp=false;
	    }
    }
    
    if (!xmlhttp && window.createRequest) {
	    try {
		    xmlhttp = window.createRequest();
	    } catch (e) {
		    xmlhttp=false;
	    }
    }

    if (metodo == "GET") {
        xmlhttp.open("GET", url, modo);
    } else {
        xmlhttp.open("POST", url, modo);
        xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=iso-8859-1");
        xmlhttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
        xmlhttp.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
        xmlhttp.setRequestHeader("Pragma", "no-cache");
    }    
    
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4) {
            retorno=xmlhttp.responseText
            document.getElementById(tagRetorno).style.visible = true;
            document.getElementById(tagRetorno).innerHTML = retorno
            //findScript(retorno)
        }
    }
    
    if (metodo == "GET") {
        xmlhttp.send(null);
    } else {        
        xmlhttp.send(parametros);
    }
}
