var _ms_XMLHttpRequest_ActiveX = ""; // Holds type of ActiveX to instantiate
var _ajax;   

function executeReturn( AJAX ) {
    if (AJAX.readyState == 4) {
        if (AJAX.status == 200) {
//            logger('AJAXRequest is complete: ' + AJAX.readyState + "/" + AJAX.status + "/" + AJAX.statusText);
	    if ( AJAX.responseText ) {
//		    logger(AJAX.responseText);
//		    logger("-----------------------------------------------------------");
		    eval(AJAX.responseText);
	    }
	}
    }
}


function AJAXRequest( method, url, data, process, async, dosend) {
    // self = this; creates a pointer to the current function
    // the pointer will be used to create a "closure". A closure
    // allows a subordinate function to contain an object reference to the
    // calling function. We can't just use "this" because in our anonymous
    // function later, "this" will refer to the object that calls the function 
    // during runtime, not the AJAXRequest function that is declaring the function
    // clear as mud, right?
    // Java this ain't
    
    var self = this;

    // check the dom to see if this is IE or not
    if (window.XMLHttpRequest) {
	// Not IE
        self.AJAX = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
	// Hello IE!
        // Instantiate the latest MS ActiveX Objects
        if (_ms_XMLHttpRequest_ActiveX) {
            self.AJAX = new ActiveXObject(_ms_XMLHttpRequest_ActiveX);
        } else {
	    // loops through the various versions of XMLHTTP to ensure we're using the latest
	    var versions = ["Msxml2.XMLHTTP.7.0", "Msxml2.XMLHTTP.6.0", "Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP",
                        "Microsoft.XMLHTTP"];

            for (var i = 0; i < versions.length ; i++) {
                try {
		    // try to create the object
		    // if it doesn't work, we'll try again
		    // if it does work, we'll save a reference to the proper one to speed up future instantiations
                    self.AJAX = new ActiveXObject(versions[i]);

                    if (self.AJAX) {
                        _ms_XMLHttpRequest_ActiveX = versions[i];
                        break;
                    }
                }
                catch (objException) {
                // trap; try next one
                } ;
            }

            ;
        }
    }
    
    // if no callback process is specified, then assing a default which executes the code returned by the server
    if (typeof process == 'undefined' || process == null) {
        process = executeReturn;
    }

    self.process = process;

    // create an anonymous function to log state changes
    self.AJAX.onreadystatechange = function( ) {
        //logger("AJAXRequest Handler: State =  " + self.AJAX.readyState);
        self.process(self.AJAX);
    }

    // if no method specified, then default to POST
    if (!method) {
        method = "POST";
    }

    method = method.toUpperCase();

    if (typeof async == 'undefined' || async == null) {
        async = true;
    }

    //logger("----------------------------------------------------------------------");
    //logger("AJAX Request: " + ((async) ? "Async" : "Sync") + " " + method + ": URL: " + url + ", Data: " + data);

    self.AJAX.open(method, url, async);

    if (method == "POST") {
        self.AJAX.setRequestHeader("Connection", "close");
        self.AJAX.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        self.AJAX.setRequestHeader("Method", "POST " + url + "HTTP/1.1");
    }

    // if dosend is true or undefined, send the request
    // only fails is dosend is false
    // you'd do this to set special request headers
    if ( dosend || typeof dosend == 'undefined' ) {
	    if ( !data ) data=""; 
		//window.alert(data);
	    self.AJAX.send(data);
    }
    return self.AJAX;
}

// Method to get text from an XML DOM object
function getTextFromXML( oNode, deep ) {
    var s = "";
    var nodes = oNode.childNodes;

    for (var i = 0; i < nodes.length; i++) {
        var node = nodes[i];

        if (node.nodeType == Node.TEXT_NODE) {
            s += node.data;
        } else if (deep == true && (node.nodeType == Node.ELEMENT_NODE || node.nodeType == Node.DOCUMENT_NODE
                                       || node.nodeType == Node.DOCUMENT_FRAGMENT_NODE)) {
            s += getTextFromXML(node, true);
        };
    }

    ;
    return s;
}

function encode( uri ) {
    if (encodeURIComponent) {
        return encodeURIComponent(uri);
    }

    if (escape) {
        return escape(uri);
    }
}

function decode( uri ) {
    uri = uri.replace(/\+/g, ' ');

    if (decodeURIComponent) {
        return decodeURIComponent(uri);
    }

    if (unescape) {
        return unescape(uri);
    }

    return uri;
}

/*
Consulta CEP
*/
function consultaCep(cep, arquivoXML){
	if (cep.length == 9){
		return new AJAXRequest("POST", arquivoXML, "cep=" + encode(cep), consultaCepXML);
	}
}

function consultaCep2(cep){
	return new AJAXRequest("POST", "consultaCepXML.php", "cep=" + encode(cep), consultaCepXML);
}

function consultaCepXML( myAJAX )
{
	if (myAJAX.readyState == 4)
	{	
		if (myAJAX.status == 200)
		{
			xml = myAJAX.responseXML;

			// parse the XML
			if (xml.documentElement) {
				var status = xml.documentElement.getElementsByTagName("status")[0].firstChild.nodeValue;
				var msg    = xml.documentElement.getElementsByTagName("msg")[0].firstChild.nodeValue;

				if (status == 'true')
				{
					if (xml.documentElement.getElementsByTagName("endereco")[0])
					{
						document.getElementById("cmpEnderecoCob").value = xml.documentElement.getElementsByTagName("endereco")[0].firstChild.nodeValue;
					}

					if (xml.documentElement.getElementsByTagName("bairro")[0])
					{ 
						document.getElementById("cmpBairroCob").value = xml.documentElement.getElementsByTagName("bairro")[0].firstChild.nodeValue;
					}
					
					est = document.getElementById("cmpEstadoCob");
					estado = xml.documentElement.getElementsByTagName("estado")[0].firstChild.nodeValue;
					
					cidade = xml.documentElement.getElementsByTagName("cidade")[0].firstChild.nodeValue;
					
					for (i = 0; i < est.options.length; i++)
					{
						if (est.options[i].value == estado)
						{
							est.options[i].selected = true;
						}
					}
					
					if (cidade != document.getElementById("cmpCidadeCob").options[document.getElementById("cmpCidadeCob").selectedIndex].value)
					{
						loadCidade(est);
					}
					
					document.getElementById("cmpBairroCob").disabled = false;
					document.getElementById("cmpEstadoCob").disabled = false;
					document.getElementById("cmpCidadeCob").disabled = false;
					
					//alert(xml.documentElement.getElementsByTagName("id_cidade")[0].firstChild.nodeValue);
					
					/*
					var estado_selected = xml.documentElement.getElementsByTagName("estado")[0].firstChild.nodeValue;

					var estado = document.getElementById("cmpEstado");
					for (w=1; w < estado.options.length; w++)
					{
						if (estado.options[w].value == estado_selected)
						{
							estado.options[w].selected = true;
						}
					}

					document.getElementById("cidade_selected").value = xml.documentElement.getElementsByTagName("cidade")[0].firstChild.nodeValue;
					setCidade( estado );
					*/
				}else{
					//window.alert(msg);
					//document.getElementById("cmpCep").value = "";
					document.getElementById("cmpEnderecoCob").value = "";
					document.getElementById("cmpBairroCob").value = "";
					
					alert("CEP não encontrado!\nPor favor preencha manualmente os campos Endereço, Bairro, Estado e Cidade");
					
					cid = document.getElementById("cmpCidadeCob");
					// Limpa o select
					// Faz um loop do último options para o primeiro, pois se fizer o contrario,
					// quando limpar o 1, o 2 vira 1, etc.... não limpa corretamente!
					for (i = cid.options.length - 1; i > 0; i--)
					{
						cid.options[i] = null;
					}
					cid.options[0].innerText = "Selecione um Estado";

					est = document.getElementById("cmpEstadoCob");
					est.options[0].selected = true;
					
					document.getElementById("cmpBairroCob").disabled = false;
					document.getElementById("cmpEstadoCob").disabled = false;
					document.getElementById("cmpCidadeCob").disabled = false;

					//document.getElementById("cidade_selected").value = "";
				}
			}
		}
	}
}

/*
	carrega cidades
*/
function loadCidade(obj)
{
	cid = document.getElementById("cmpCidadeCob");
	
	if (obj.selectedIndex != 0)
	{
		if (document.all)
		{
			document.getElementById("trLoadingCidades").style.display = 'block';
		} else {
			document.getElementById("trLoadingCidades").style.display = 'table-row';
		}
		
		document.getElementById("trCidades").style.display = "none";
		
		cid.disabled = true;
		
		AJAXRequest("POST", "../includes/xml/cidadesXML.php", "estado=" + obj.options[obj.selectedIndex].value, loadCidadeAjax);
	} else {
		// Limpa o select
		// Faz um loop do último options para o primeiro, pois se fizer o contrario,
		// quando limpar o 1, o 2 vira 1, etc.... não limpa corretamente!
		for (i = cid.options.length - 1; i > 0; i--)
		{
			cid.options[i] = null;
		}
		cid.options[0].innerText = "Selecione um Estado";
				
		document.getElementById("trLoadingCidades").style.display = 'none';
	}
}

function loadCidadeAjax( myAJAX )
{
	if (myAJAX.readyState == 4) {
		if (myAJAX.status == 200)
		{
			xml = myAJAX.responseXML;

			var status = xml.getElementsByTagName("status")[0].firstChild.nodeValue;
			if (status == "erro")
			{
				for (i = cid.options.length - 1; i > 0; i--)
				{
					cid.options[i] = null;
				}	
			
				cid.options[0].innerText = "Selecione um Estado";
				
			} else {
			
				for (i = cid.options.length - 1; i > 0; i--)
				{
					cid.options[i] = null;
				}
				
				for (i = 0; i < xml.getElementsByTagName("data").length; i++) {
					valor = xml.getElementsByTagName("data")[i].getElementsByTagName("cidade")[0].firstChild.nodeValue
					
					opt = document.createElement("option");
					opt.setAttribute("value",valor);
					/*
					if (cidade == valor)
					{
						opt.setAttribute("selected","selected");
					}
					*/
					
					txt = document.createTextNode(valor);
					opt.appendChild(txt);

					cid.appendChild(opt);
				}
				document.getElementById("trLoadingCidades").style.display = "none";
				
				if (document.all)
				{
					document.getElementById("trCidades").style.display = 'block';
				} else {
					document.getElementById("trCidades").style.display = 'table-row';
				}

				cid.options[0].innerText = "Selecione uma Cidade";
				cid.disabled = false;
			}
		}
	}
}
function Retirar_Embalagem(id_prod) {
	try {
		ajax = new ActiveXObject("Microsoft.XMLHTTP");
	}catch(e) {
		try {
			ajax = new ActiveXObject("Msxml2.XMLHTTP");
		}catch(ex) {
			try {
				ajax = new XMLHttpRequest();
			}
			catch(exc) {
				alert("Esse browser não tem recursos para uso do Ajax");
				ajax = null;
			}
		}
	}
	if(ajax){  
		//alert("Teste");
		ajax.onreadystatechange = function(){ 
												if (ajax.readyState == 4) { 
													if (ajax.status ==200) { 
														cont_emb=document.getElementById("img_embalagem"+id_prod).innerHTML = ajax.responseText; 
													} else { 
														alert("Houve um problema ao obter os dados:\n" + ajax.statusText); 
													} 
												} 
											}; 
		//alert("chegou até aqui !!!");
		ajax.open("GET", "carrinho/retirar_embalagem.php?id_prod="+id_prod,true);
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send(null);
		Calculo_embalagem(); 
	}   
}

function Adicionar_Embalagem(id_prod, id_produto) {
	try {
		ajax = new ActiveXObject("Microsoft.XMLHTTP");
	}catch(e) {
		try {
			ajax = new ActiveXObject("Msxml2.XMLHTTP");
		}catch(ex) {
			try {
				ajax = new XMLHttpRequest();
			}catch(exc) {
				alert("Esse browser não tem recursos para uso do Ajax");
				ajax = null;
			}
		}
	}

	if(ajax){  
	
		ajax.onreadystatechange = function(){ 
												if (ajax.readyState == 4) { 
													if (ajax.status ==200) { 
														cont_emb=document.getElementById("img_embalagem"+id_prod).innerHTML = ajax.responseText; 
													} else { 
														alert("Houve um problema ao obter os dados:\n" + ajax.statusText); 
													} 
												} 
											};
		//alert(id_prd);                                         
		ajax.open("GET", "embalagem_add2.php?id_prod="+id_prod+"&id_produto=" + id_produto,true);
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send(null);
		Calculo_embalagem(); 
	}   

}
function Calculo_embalagem(){
	
	try {
		ajax1 = new ActiveXObject("Microsoft.XMLHTTP");
	}catch(e) {
		try {
			ajax1 = new ActiveXObject("Msxml2.XMLHTTP");
		}catch(ex) {
			try {
				ajax1 = new XMLHttpRequest();
			}catch(exc) {
				alert("Esse browser não tem recursos para uso do Ajax");
				ajax1 = null;
			}
		}
	}
	if(ajax1){  
		//alert("Teste");
		ajax1.onreadystatechange = function(){ 
												if (ajax1.readyState == 4) { 
													if (ajax1.status ==200) { 
														//alert(document.getElementById("div_valor_embalagem"));
														document.getElementById("div_valor_embalagem").innerHTML = ajax1.responseText; 
													} else { 
														alert("Houve um problema ao obter os dados:\n" + ajax1.statusText); 
													} 
												} 
											}; 
		//alert("chegou ate aqui !!!");
		ajax1.open("GET", "carrinho/calculo_embalagem.php",true);
		ajax1.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax1.send(null);  
	} 
}



function Recalcular_cep(cep) {
	try {
		ajax = new ActiveXObject("Microsoft.XMLHTTP");
	}catch(e) {
		try {
			ajax = new ActiveXObject("Msxml2.XMLHTTP");
		}catch(ex) {
			try {
				ajax = new XMLHttpRequest();
			}catch(exc) {
				alert("Esse browser não tem recursos para uso do Ajax");
				ajax = null;
			}
		}
	}
	if(ajax){  
		var conteudo=document.getElementById("id_cep");
		conteudo.innerHTML='<strong>Carregando valor do frete...</strong>';
		ajax.onreadystatechange = processCepChange; 
		ajax.open("GET", "carrinho/frete.php?id_cep="+cep,true);
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send(null); 
	}   
}


function Recalcular_vale(vale) {
	try {
		ajax = new ActiveXObject("Microsoft.XMLHTTP");
	} 
	catch(e) {
		try {
			ajax = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(ex) {
			try {
				ajax = new XMLHttpRequest();
			}
			catch(exc) {
				alert("Esse browser não tem recursos para uso do Ajax");
				ajax = null;
			}
		}
	}
	if(ajax){  
		var conteudo=document.getElementById("id_vale");
		conteudo.innerHTML='<strong>Carregando...</strong>';
		ajax.onreadystatechange = processValeChange; 
		ajax.open("GET", "carrinho/recalcular_vale.php?vale="+vale,true);
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send(null); 
		Total_Compra();
		Desconto_Compra();
		Saldo_Vale_Presente(vale);
	}   
}

function Saldo_Vale_Presente(vale){
	try {
		ajax_saldo = new ActiveXObject("Microsoft.XMLHTTP");
	}catch(e) {
		try {
			ajax_saldo = new ActiveXObject("Msxml2.XMLHTTP");
		}catch(ex) {
			try {
				ajax_saldo = new XMLHttpRequest();
			}catch(exc) {
				alert("Esse browser não tem recursos para uso do Ajax");
				ajax_saldo = null;
			}
		}
	}
	if(ajax_saldo){  
		var conteudo = document.getElementById("id_vale_saldo");
		conteudo.innerHTML='<strong>Carregando...</strong>';
		ajax_saldo.onreadystatechange = function(){
													if (ajax_saldo.readyState == 4) { 
														if (ajax_saldo.status ==200) { 
															conteudo.innerHTML = ajax_saldo.responseText; 
														} else { 
															alert("Houve um problema ao obter os dados:\n" + ajax_saldo.statusText); 
														} 
												    } 
	
												  };
		
		ajax_saldo.open("GET", "carrinho/calcular_saldo_vale.php?vale="+vale,true);
		ajax_saldo.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax_saldo.send(null); 

	}   
}

function Recalcular_vale2(valor){
	window.location.href="carrinho/recalcular_vale2.php?vale="+valor;
}

function Atualizar_Valores(linhas) {
	try {
		ajax = new ActiveXObject("Microsoft.XMLHTTP");
	} 
	catch(e) {
		try {
			ajax = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(ex) {
			try {
				ajax = new XMLHttpRequest();
			}
			catch(exc) {
				alert("Esse browser não tem recursos para uso do Ajax");
				ajax = null;
			}
		}
	}
	if(ajax){  
		if (linhas > "0"){
			for (i=1;i <= linhas; i++){
				if (i == 1)
					texto = eval('document.getElementById("cmp_qtd'+i+'").value');
				else
					texto = texto + ',' + eval('document.getElementById("cmp_qtd'+i+'").value');
			}
				
		}else
			texto="";

		var conteudo=document.getElementById("lista");
		//conteudo.innerHTML='<div class="texto-roxo"><strong>Carregando...</strong></div>';
		ajax.onreadystatechange = processReqChange;
		ajax.open("GET", "carrinho/atualizar_valores.php?texto="+texto+"&linhas="+linhas,true);
		//ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		//alert(ajax.readyState);
		ajax.send(null); 
		Calculo_embalagem();
		Desconto_Compra();
		Total_Compra();
	}   
}
   


function Total_Compra() {
	try {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	} 
	catch(e) {
		try {
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(ex) {
			try {
				xmlhttp = new XMLHttpRequest();
			}
			catch(exc) {
			alert("Esse browser não tem recursos para uso do Ajax");
			xmlhttp = null;
			}
		}
	}
	if(xmlhttp){  
		var cont_preco = document.getElementById("preco_total");
		var cod_vale = document.frm_vale.cmp_vale.value;
		var id_frete = document.getElementById("opEntrega").value;
		
		if (id_frete > "0") 
		   var vr_frete = eval('document.getElementById("total_frete'+id_frete+'").value');
		else
		   var vr_frete = "0";
		
		cont_preco.innerHTML='<div class="texto-roxo"><strong>Carregando...</strong></div>';
		xmlhttp.onreadystatechange = processTotalChange; 
		xmlhttp.open("GET", "carrinho/total_compra.php?vale="+cod_vale+"&vr_frete="+vr_frete,true);
		xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xmlhttp.send(null);             
	}   
}


function Desconto_Compra() {
	try {
		deschttp = new ActiveXObject("Microsoft.XMLHTTP");
	} 
	catch(e) {
		try {
			deschttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(ex) {
			try {
			   deschttp = new XMLHttpRequest();
			}
			catch(exc) {
			   alert("Esse browser não tem recursos para uso do Ajax");
			   deschttp = null;
			}
		}
	}
	if(deschttp){  
		var cont_desc = document.getElementById("id_desconto");
		cont_desc.innerHTML='<div class="texto-roxo"><strong>Carregando...</strong></div>';
		deschttp.onreadystatechange = processDescChange; 
		deschttp.open("GET", "carrinho/desconto_compra.php",true);
		deschttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		deschttp.send(null); 
	}   
}



function Limpar_Carrinho() {
	try {
		ajax = new ActiveXObject("Microsoft.XMLHTTP");
	} 
	catch(e) {
		try {
			ajax = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(ex) {
			try {
				ajax = new XMLHttpRequest();
			}catch(exc) {
					alert("Esse browser não tem recursos para uso do Ajax");
					ajax = null;
			}
		}
	}

	if(ajax){  
		var conteudo=document.getElementById("lista");
		conteudo.innerHTML='<div class="texto-roxo"><strong>Carregando...</strong></div>';
		document.getElementById("id_Atualizar").innerHTML = '<a href="#" onClick="javascript:Atualizar_Valores(0);"><img src="imagens/bt_atualizar_valores.gif" border="0" width="74" height="14">';
		ajax.onreadystatechange = processReqChange; 
		ajax.open("POST", "carrinho/limpar_carrinho.php",true);
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send(null); 
		Atualizar_Valores(0);
	}   
}


function Remover_Item(valor) {
	try {
		ajax = new ActiveXObject("Microsoft.XMLHTTP");
	} 
	catch(e) {
		try {
			ajax = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(ex) {
			try {
				ajax = new XMLHttpRequest();
			}
				catch(exc) {
					alert("Esse browser não tem recursos para uso do Ajax");
					ajax = null;
				}
			}
		}
		if(ajax){  
			var total = document.getElementById("hd_total").value;
	
		total = total -1;
		var conteudo=document.getElementById("lista");
		conteudo.innerHTML='<div class="texto-roxo"><strong>Carregando...</strong></div>';
		document.getElementById("id_Atualizar").innerHTML = '<a href="#" onClick="javascript:Atualizar_Valores('+total+');"><img src="imagens/bt_atualizar_valores.gif" border="0" width="74" height="14">';
		ajax.onreadystatechange = processReqChange2; 
		ajax.open("GET", "carrinho/remover_item.php?n="+valor,true);
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send(null);
	}   
}
   
function processReqChange(){ 

    if (ajax.readyState == 4) {
        if (ajax.status ==200) { 
			conteudo=document.getElementById("lista").innerHTML = ajax.responseText; 
        } else { 
            alert("Houve um problema ao obter os dados:\n" + ajax.statusText); 
        } 
    }
}    

function processReqChange2(){ 
	if (ajax.readyState == 4) { 
		if (ajax.status ==200) { 
			conteudo=document.getElementById("lista").innerHTML = ajax.responseText;
			Atualizar_Valores(document.getElementById("hd_total").value);
		} else { 
			alert("Houve um problema ao obter os dados:\n" + ajax.statusText); 
		} 
	} 
}    

function processTotalChange(){ 
    if (xmlhttp.readyState == 4) { 
        if (xmlhttp.status ==200) { 
			cont_preco=document.getElementById("preco_total").innerHTML = xmlhttp.responseText; 
        } else { 
            alert("Houve um problema ao obter os dados:\n" + xmlhttp.statusText); 
        } 
    } 
}    



function processSaldoVale(){
    if (ajax.readyState == 4) { 
        if (ajax.status ==200) { 
			conteudo=document.getElementById("id_vale_saldo").innerHTML = ajax_saldo.responseText; 
        } else { 
            alert("Houve um problema ao obter os dados:\n" + ajax_saldo.statusText); 
        } 
    } 

}

function processValeChange(){ 
    if (ajax.readyState == 4) { 
        if (ajax.status ==200) { 
			conteudo=document.getElementById("id_vale").innerHTML = ajax.responseText; 
        } else { 
            alert("Houve um problema ao obter os dados:\n" + ajax.statusText); 
        } 
    } 
}    

function processCepChange() 
{ 
    if (ajax.readyState == 4) { 
        if (ajax.status ==200) { 
			//alert(ajax.responseText);
			document.getElementById("id_cep").innerHTML = ajax.responseText; 
        } else { 
            alert("Houve um problema ao obter os dados:\n" + ajax.statusText); 
        } 
    } 
}    

function processDescChange() 
{ 
    if (deschttp.readyState == 4) { 
        if (deschttp.status ==200) { 
			if (deschttp.responseText != 'R$0,00')
			{
				if (document.all)
				{
					document.getElementById("trDesconto").style.display = "block";
					document.getElementById("trDesconto2").style.display = "block";
				} else {
					document.getElementById("trDesconto").style.display = "table-row";
					document.getElementById("trDesconto2").style.display = "table-row";
				}
				cont_desc=document.getElementById("id_desconto").innerHTML = deschttp.responseText; 
			} else {
				document.getElementById("trDesconto").style.display = "none";
				document.getElementById("trDesconto2").style.display = "none";
			}
        } else { 
            alert("Houve um problema ao obter os dados:\n" + deschttp.statusText); 
        } 
    } 
}