function xmlhttpPost(strURL, qsrt, target) {
    var xmlHttpReq = false;
    var self = this;
    
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    
    
    self.xmlHttpReq.open('GET', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=ISO-8859-1');
    self.xmlHttpReq.setRequestHeader("encoding", "ISO-8859-1");

    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            updatepage(self.xmlHttpReq.responseText, target);
            executarScript(self.xmlHttpReq.responseText);
        }
    }

    self.xmlHttpReq.send(qsrt);
}

function updatepage(str, target){
    document.getElementById(target).innerHTML = str;    
}

function executarScript(texto){
    var ini = 0;
    var codigo;
    
    while (ini != -1){
        codigo = '';

        ini = texto.indexOf('<script', ini);

        if (ini >= 0){
            ini = texto.indexOf('>', ini) + 1;
            var fim = texto.indexOf('</script>', ini);

            codigo = texto.substring(ini,fim);
        }
        
        if (codigo) {
            var ini_codigo = 0;
            while (ini_codigo != -1){

                ini_codigo = codigo.indexOf('<!--', ini_codigo);
                if (ini_codigo >= 0){
                    ini_codigo = codigo.indexOf('-', ini_codigo) + 2;
                }
                
                if ((codigo.indexOf('Begin', ini_codigo)) == ini_codigo + 1) {
                    ini_codigo += 7;
                }

                if (ini_codigo >= 0){
                    var fim = codigo.indexOf('//', ini_codigo);

                    codigo = codigo.substring(ini_codigo,fim);
                }

            }
        }
        
        if (codigo) eval(codigo);
    }

}

function submit_form(form_name, target) {

        var qstr = '';
        eval('var form = document.' + form_name);
        
        var i;
        for (i = 0; i < form.length; i++) {
            qstr += form.elements[i].name;
            qstr += '=';
            qstr += form.elements[i].value;
            
            if (i < form.length - 1) qstr += '&';
        }
        
	xmlhttpPost(form.action, qstr, target);
	return true;
        
}

function linky(url, target) {
	
	if (target != null) {
		document.getElementById(target).innerHTML = flashCarregando();
		setTimeout("xmlhttpPost('" + url + "', '', '" + target + "');",1000);
		return;
	}
    
    window.location = url;
        
}

function link(url, target) {
	
	if (target != null) {
		document.getElementById(target).innerHTML = '<div class="carregando">' + getFlash('swf/carregando.swf',100,60) + '</div>';
		setTimeout("xmlhttpPost('" + url + "', '', '" + target + "');",500);
		return;
	}
    
    window.location = url;
        
}

function link_wait(url, target, time) {
	
	if (target != null) {
		//document.getElementById(target).innerHTML = '<div class="carregando">' + getFlash('swf/carregando.swf',100,60) + '</div>';
		setTimeout("xmlhttpPost('" + url + "', '', '" + target + "');",time);
		return;
	}
    
    window.location = url;
        
}