function _id(id) { return document.getElementById(id); }
function _value(id) { return escape(document.getElementById(id).value); }
function _valueCheckBox(id) { if (document.getElementById(id).checked==true) { return escape(document.getElementById(id).value); } else { return ""; } }
function _valueComboBox(id) { return _id(id).options[_id(id).selectedIndex].value; }


try{
    xmlhttp = new XMLHttpRequest();
}catch(ee){
    try{
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }catch(e){
        try{
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }catch(E){
            xmlhttp = false;
        }
    }
}
fila=[]
ifila=0
function ajaxHTML(id,url){
    //document.getElementById(id).innerHTML="<span class='carregando'>Carregando...</span>";
    fila[fila.length]=[id,url];
    if((ifila+1)==fila.length)ajaxRun();
}
function ajaxRun(){
    xmlhttp.open("GET",fila[ifila][1],true);
	xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4){
            retorno=unescape(xmlhttp.responseText.replace(/\+/g," "));
			//ajaxConclui(fila[ifila][0],retorno);
            ifila++;
            if(ifila<fila.length)setTimeout("ajaxRun()",20);
        }
	}   
    xmlhttp.send(null);
}
function ajaxAnexa(metodo, id) {
    if (metodo.length > 0 && id.length > 0) {
        evalStr = metodo + " = document.getElementById('" + id + "');";
        eval(evalStr);
    }
}
function ajaxRecebeArray(retorno) {
    eval('var ret = ' + retorno);
    return ret;
}

function CreateXMLDOM(txtxml){
    if(window.ActiveXObject){
        myDocument=new ActiveXObject("Microsoft.XMLDOM")
        myDocument.loadXML(txtxml)
    }else{
        parser=new DOMParser();
        myDocument=parser.parseFromString(txtxml, "text/xml");
    }
    return myDocument;
}

function ajaxExecuta(arquivo, dadosPost,func_posterior,layoutXml,loading) {
	try{
	    xmlhttpTemp = new XMLHttpRequest();
	}catch(ee){
	    try{
	        xmlhttpTemp = new ActiveXObject("Msxml2.xmlhttp");
	    }catch(e){
	        try{
	            xmlhttpTemp = new ActiveXObject("Microsoft.xmlhttp");
	        }catch(E){
	            xmlhttpTemp = false;
	        }
	    }
	}

	if (loading==true) ajaxLoading();
	document.body.style.cursor = "wait";
	xmlhttpTemp.open("POST",arquivo,true);
	xmlhttpTemp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xmlhttpTemp.onreadystatechange=function() {		
		switch( xmlhttpTemp.readyState ) {
			case 4: {
				document.body.style.cursor = "default";
				//if (loading==true) ajaxLoading();
				if (xmlhttpTemp.status==200) {
					if (layoutXml==false) {
						var texto = xmlhttpTemp.responseText;
						texto = texto.replace(/\+/g," ");
						texto = unescape(texto);	
						eval(func_posterior+"(texto);");
					} else {
						eval(func_posterior+"(xmlhttpTemp.responseXML);");
					}
				}
				break;
			}
		}
	}
	xmlhttpTemp.send(dadosPost);
}

/* loading */
var ajaxLoadingRolagemativo=0;
function ajaxLoading(){
	if (!_id('box_loading')) document.write('<div id="box_loading" style="position:absolute;visibility:hidden;z-index:99;background:#c44;color:white;font-size:12px;font-family:Arial;top:1px;right:16px;padding:2px">Carregando...</div>');
	if (_id('box_loading').style.visibility=='hidden') {
		_id('box_loading').style.visibility='';
		document.body.style.cursor = "wait";
		if (ajaxLoadingRolagemativo==0) ajaxLoadingRolagemativo = setInterval("ajaxLoadingRolagem()",50);
	} else {
		_id('box_loading').style.visibility='hidden';
		if (ajaxLoadingRolagemativo!=0) {
			clearInterval(ajaxLoadingRolagemativo);
			ajaxLoadingRolagemativo=0;
		}
	}
	if (ajaxLoadingRolagemativo==0) setInterval("ajaxLoadingRolagem()",50);
}
function ajaxLoadingDiv(divId) {
	document.getElementById(divId).innerHTML = '<center><img src="./imagens/ajax_loading.gif" /></center>';
}
function ajaxLoadingRolagem() {
	if (!document.getElementById('box_loading')) return;
	var LocX=0
	var LocY=0
	var LocX=0
	var LocY=0		
	if (document.layers){
		menuBlock=_id('box_loading');
		menuBlock.visibility="show";
		LocX=window.pageXOffset;
		LocY=window.pageYOffset;
	} else if (document.all){
		menuBlock=_id('box_loading');
		menuBlock.visibility="visible";
		LocX=document.body.scrollLeft;
		LocY=document.body.scrollTop;
	} else if (document.getElementById){
		menuBlock=_id('box_loading');
		menuBlock.style.visibility="visible";
		LocX=window.pageXOffset;
		LocY=window.pageYOffset;
	}		
	if(document.getElementById){
		menuBlock.style.top= (LocY+5);
	} else if(document.layers||document.all){ 
		menuBlock.top= (LocY+5);
	}
}

function ajaxCria() {
	var xmlhttp;
	try{
	    xmlhttp = new XMLHttpRequest();
	}catch(ee){
	    try{
	        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	    }catch(e){
	        try{
	            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	        }catch(E){
	            xmlhttp = null;
	        }
	    }
	}
	return xmlhttp;
}