
function extraiScript(texto){
//Maravilhosa função feita pelo SkyWalker.TO do imasters/forum
//http://forum.imasters.com.br/index.php?showtopic=165277&
    // inicializa o inicio ><
    var ini = 0;
    // loop enquanto achar um script
    while (ini!=-1){
        // procura uma tag de script
        ini = texto.indexOf('<script', ini);
        // se encontrar
        if (ini >=0){
            // define o inicio para depois do fechamento dessa tag
            ini = texto.indexOf('>', ini) + 1;
            // procura o final do script
            var fim = texto.indexOf('</script>', ini);
            // extrai apenas o script
            codigo = texto.substring(ini,fim);
            // executa o script
            //eval(codigo);
            /**********************
            * Alterado por Micox - micoxjcg@yahoo.com.br
            * Alterei pois com o eval não executava funções.
            ***********************/
            novo = document.createElement("script")
            novo.text = codigo;
            document.body.appendChild(novo);
        }
    }
}

/*  FUNÇÃO AJAX*/
function ajaxRead(file,destino,semaviso) {
  var xmlObj = null;
  if(window.XMLHttpRequest){
      xmlObj = new XMLHttpRequest();
  } else if(window.ActiveXObject){
      xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
  } else {
      return;
  }

xmlObj.onreadystatechange = function(){   
	
	if(xmlObj.readyState == 1){
		//**** USAR PARA ARQUIVOS HTML *****
		if (semaviso == 1) {
			updateObj(destino,"Aguarde ...");
		}
		if (semaviso == 2) {
			updateObj(destino,"<span class='carregando'><div align=\"center\"><img src=\"loading.gif\"></div></span>");
		}
    }

	if(xmlObj.readyState == 4){
		if (xmlObj.status == 200) { //se nao ocorreu nenhum erro
			//**** USAR PARA ARQUIVOS HTML *****
			texto=unescape(xmlObj.responseText.replace(/\+/g," "));
			updateObj(destino, xmlObj.responseText);
			extraiScript(texto);
			/* extraindo script e executando */			
		} else {
            alert("Houve um problema ao obter os dados:\n" + xmlObj.statusText);
        }
}
}
xmlObj.open ('GET', file, true);
xmlObj.send ('');
}

function ajaxReadPost(file,destino,semaviso,dados) {
  
  var xmlObj = null;
  if(window.XMLHttpRequest){
      xmlObj = new XMLHttpRequest();
  } else if(window.ActiveXObject){
      xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
  } else {
      return;
  }

xmlObj.onreadystatechange = function(){   
	
	
	if(xmlObj.readyState == 1){
		//**** USAR PARA ARQUIVOS HTML *****
		if (semaviso == 1) {
			updateObj(destino,"Aguarde ...");
		}
		if (semaviso == 2) {
			updateObj(destino,"<span class='carregando'><div align=\"center\"><img src=\"loading.gif\"></div></span>");
		}
    }

	if(xmlObj.readyState == 4){
		if (xmlObj.status == 200) { //se nao ocorreu nenhum erro
			//**** USAR PARA ARQUIVOS HTML *****
			texto=unescape(xmlObj.responseText.replace(/\+/g," "));
			updateObj(destino, xmlObj.responseText);
			extraiScript(texto);
			/* extraindo script e executando */			
		} else {
            alert("Houve um problema ao obter os dados:\n" + xmlObj.statusText);
        }
	}
}
xmlObj.open ('POST', file, true);
xmlObj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlObj.send (dados);
}

//***********************************************************************************

function getDados(objForm) {
    
	var params = new Array();

    for (var i=0 ; i < objForm.elements.length; i++) {
        var parametro = encodeURIComponent(objForm.elements[i].name);
        parametro += "=";
        parametro += encodeURIComponent(objForm.elements[i].value);
        params.push(parametro);
    }

    return params.join("&");
	
}

function updateObj(obj, data){
	document.getElementById(obj).innerHTML = data;
}

