Ajax.prototype.parametrosConexao = new Array();
function Ajax(){
this.conecta = ajax_conexao;
this.getValor = ajax_getValor;
this.getAtributo = ajax_getAtributo;
this.setCombo = ajax_setCombo;
this.adicionaParametro = ajax_adicionaParametro;
this.concatParametros = ajax_concatParametros;
this.setComboAguarde = ajax_setComboAguarde;
function ajax_conexao(url,funcao,combo){
try{
xmlhttp = new XMLHttpRequest();
}catch(ee){
try{
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
try{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}catch(E){
xmlhttp = false;
}
}
}
if(typeof(combo) != "undefined"){
if(combo.type == "select-multiple" || combo.type == "select-one"){
combo.disabled = true;
combo.options[0] = new Option('aguarde...');
combo.length = 0;
}
}
url+= this.concatParametros();
xmlhttp.open("GET", url);
xmlhttp.onreadystatechange = function() {
if(xmlhttp.readyState == 4){
try{
if(xmlhttp.status == 200){
eval(funcao + "(xmlhttp.responseXML)");
}
else if(xmlhttp.status != 0){
return "erro";
}
}catch(excecao){
return "erro";
}
}
}
xmlhttp.send(null);
}
function ajax_getValor(ajaxResponse,elemento){
try{
return ajaxResponse.getElementsByTagName(elemento).item(0).firstChild.data;
}catch(excecao){
return "";
}
}
function ajax_getAtributo(ajaxResponse,elemento,atributo){
try{
return ajaxResponse.getElementsByTagName(elemento).item(0).attributes.getNamedItem(atributo).value;
}catch(excecao){
return "";
}
}
function ajax_setCombo(ajaxResponse,campoXML,campoHtml,comboVazio){
if(typeof(campoHtml) != "undefined"){
if(campoHtml.type == "select-multiple" || campoHtml.type == "select-one"){
try{
campoHtml.disabled = false;
dado = ajaxResponse.getElementsByTagName("ajax");
dado = dado[0].getElementsByTagName(campoXML);
if(dado){
opcoes = dado[0].getElementsByTagName("opcao");
campoHtml.length = 0;
for(x = 0; x < opcoes.length; x++){
if(opcoes.item(x).firstChild.data,opcoes.item(x).attributes.getNamedItem('selecionado')){
if(opcoes.item(x).firstChild.data,opcoes.item(x).attributes.getNamedItem('selecionado').value == 'sim'){
campoHtml.options[x] = new Option(opcoes.item(x).firstChild.data,opcoes.item(x).attributes.getNamedItem('valor').value,true,true);
}
else {
campoHtml.options[x] = new Option(opcoes.item(x).firstChild.data,opcoes.item(x).attributes.getNamedItem('valor').value);
}
}
else{
campoHtml.options[x] = new Option(opcoes.item(x).firstChild.data,opcoes.item(x).attributes.getNamedItem('valor').value);
}
}
}
if(campoHtml.length == 0 && comboVazio == true){
campoHtml.length = 0;
campoHtml.disabled = true;
}
}catch(excecao){
return "erro";
}
}
}
}
function ajax_adicionaParametro(propriedade,valor){
this.parametrosConexao.push([propriedade,valor])
}
function ajax_concatParametros(){
if(this.parametrosConexao.length > 0){
str = "?";
for(i=0;i<this.parametrosConexao.length;i++){
str+= this.parametrosConexao[i][0] + "=" + this.parametrosConexao[i][1];
if(i != (this.parametrosConexao.length - 1)){
str+= "&";
}
}
this.parametrosConexao.splice(0,this.parametrosConexao.length);
str+= "&aleatorio=" + Math.ceil(Math.random() * 1000000);
return str;
}
else{
return "";
}
}
function ajax_setComboAguarde(combo){
if(typeof(combo) != "undefined"){
if(combo.type == "select-multiple" || combo.type == "select-one"){
combo.disabled = true;
combo.length = 0;
combo.options[0] = new Option('aguarde...');
}
}
}
}
