// (c)2002 Douglas Crockford

var fila=new Array();var ifila=0
try{xmlhttp=new XMLHttpRequest();try{if(xmlhttp.overrideMimeType){xmlhttp.overrideMimeType('text/xml');}}catch(e1){}}catch(e2){try{xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");}catch(e3){try{xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}catch(e4){xmlhttp=false;}}}
if(!xmlhttp){alert("AJAX error. Your browser must support XMLHttpRequest object or enable use of scripting.");}
function ajaxLink(id_target,url){ajaxMensagemCarregando(id_target);fila[fila.length]=[id_target,url,null];if(fila.length==1){ajaxRun();}
return;}
function ajaxForm(id_target,id_form){var url=document.getElementById(id_form).action;fila[fila.length]=[id_target,url,id_form];if(fila.length==1){ajaxRun();}
return;}
function ajaxRun(){var url=fila[ifila][1];var elementosForm=null;var metodoEnvio;if(fila[ifila][2]==null){metodoEnvio="GET";}else{metodoEnvio=document.getElementById(fila[ifila][2]).method.toUpperCase();if(metodoEnvio==""){metodoEnvio="POST";}
elementosForm=BuscaElementosForm(fila[ifila][2]);if(metodoEnvio=="GET"){url=url+"?"+elementosForm;}}
xmlhttp.open(metodoEnvio,url,true);xmlhttp.onreadystatechange=ajaxXMLHTTP_StateChange;if(metodoEnvio=="POST"){xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");xmlhttp.setRequestHeader("Content-length",elementosForm.length);xmlhttp.setRequestHeader("Connection","close");xmlhttp.send(elementosForm);}else{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.send(null);xmlhttp.send(null);}
return;}
function ajaxXMLHTTP_StateChange(){if(xmlhttp.readyState==1){ajaxXMLHTTP_StateChange_Carregando(fila[ifila][0]);}else{if(xmlhttp.readyState==4){ajaxXMLHTTP_StateChange_Completo(xmlhttp,fila[ifila][0]);}}}
function ajaxXMLHTTP_StateChange_Carregando(id){ajaxMensagemCarregando(id);return;}
function ajaxXMLHTTP_StateChange_Completo(xmlhttp,id){var retorno;if(xmlhttp.status==200||xmlhttp.status==0){retorno=unescape(xmlhttp.responseText.replace(/\+/g," "));}else{retorno=ajaxPaginaErro(xmlhttp);}
document.getElementById(id).innerHTML=retorno;ExtraiScript(retorno);ifila++;if(ifila<fila.length){setTimeout("ajaxRun()",20);}else{fila=null;fila=new Array();ifila=0;}
return;}
function ajaxPaginaErro(xmlhttp){var retorno;switch(xmlhttp.status){case 404:return"<div id='carregando'>Página não encontrada!!!</div>";break;case 500:return"<div id='carregando'>Erro interno do servidor!!!</div>";break;default:return"<div id='carregando'>Erro desconhecido!!!<br>"+xmlhttp.status+" - "+xmlhttp.statusText.replace(/\+/g," ")+"</div>";}}
function ajaxMensagemCarregando(id){document.getElementById(id).innerHTML="<div id='carregando'><img src='imagens/loading.gif'><br /><strong>Please wait, sending...</strong></div>";}
function ExtraiScript(texto){var ini,pos_src,fim,codigo,texto_pesquisa;texto_pesquisa=texto.toLowerCase()
var objScript=null;ini=texto_pesquisa.indexOf('<script',0)
while(ini!=-1){var objScript=document.createElement("script");pos_src=texto_pesquisa.indexOf(' src',ini)
ini=texto_pesquisa.indexOf('>',ini)+1;if(pos_src<ini&&pos_src>=0){ini=pos_src+4;fim=texto_pesquisa.indexOf('.',ini)+4;codigo=texto.substring(ini,fim);codigo=codigo.replace("=","").replace(" ","").replace("\"","").replace("\"","").replace("\'","").replace("\'","").replace(">","");objScript.src=codigo;}else{fim=texto_pesquisa.indexOf('</script>',ini);codigo=texto.substring(ini,fim);objScript.text=codigo;}
document.body.appendChild(objScript);ini=texto.indexOf('<script',fim);objScript=null;}}
function BuscaElementosForm(idForm){var elementosFormulario=document.getElementById(idForm).elements;var qtdElementos=elementosFormulario.length;var queryString="";var elemento;this.ConcatenaElemento=function(nome,valor){if(queryString.length>0){queryString+="&";}
queryString+=encodeURIComponent(nome)+"="+encodeURIComponent(valor);};for(var i=0;i<qtdElementos;i++){elemento=elementosFormulario[i];if(!elemento.disabled){switch(elemento.type){case'text':case'password':case'hidden':case'textarea':this.ConcatenaElemento(elemento.name,elemento.value);break;case'select-one':if(elemento.selectedIndex>=0){this.ConcatenaElemento(elemento.name,elemento.options[elemento.selectedIndex].value);}
break;case'select-multiple':for(var j=0;j<elemento.options.length;j++){if(elemento.options[j].selected){this.ConcatenaElemento(elemento.name,elemento.options[j].value);}}
break;case'checkbox':case'radio':if(elemento.checked){this.ConcatenaElemento(elemento.name,elemento.value);}
break;}}} return queryString;} //setInterval ("window.status = 'Mais Brindes'",1);