// JavaScript Document
var isIE = false;
var req;
function List(url) {

	document.getElementById("gamb").innerHTML=' <h2 style="margin-left:50px; margin-top:50px;"> <img alt="Carregando" src="carregando.gif"> </h2>';

	CarregaDocumentoXML(url);
}

function CarregaDocumentoXML(url) { 
 if (window.XMLHttpRequest) {
    req = new XMLHttpRequest();
    req.onreadystatechange = processar;
    req.open("GET", url, true);
    req.send(null);
 } else if (window.ActiveXObject) {
    isIE = true;
    req = new ActiveXObject("Microsoft.XMLHTTP");
    if (req) {
       req.onreadystatechange = processar;
	   req.open("GET", url, true);
       req.send();
    }
 }
}

function processar() {
 if (req.readyState == 4) {
    if (req.status == 200) {
       carregarProdutos();
    }else {
       alert("Erro aqui:\n" + req.statusText);
    }
 }
}

function getElementTextNS(prefix, local, parentElem, index) {
 var result = "";
 if (prefix && isIE) {        
	alert("entrou");
     result = parentElem.getElementsByTagName(prefix + ":" + local)[index];
 } else {        
     result = parentElem.getElementsByTagName(local)[index];
 }
 if (result) {
     if (result.childNodes.length > 1) {
         return result.childNodes[1].nodeValue;
     } else {
         return result.firstChild.nodeValue;
     }
 } else {
     return "n/a";
 }
}

function InserirNoticia(div,content) {
 opt = document.getElementById(div);
 opt.innerHTML=content;
}

function carregarProdutos() {
 var items = req.responseXML.getElementsByTagName("produto");
 var a=0;
 var b=0;
 var retorno='';
 for (var i = 0; i < items.length; i++) {
      var titulo=getElementTextNS("", "titulo", items[i], 0);
	  var parcela=getElementTextNS("", "parcelamento", items[i], 0);
      var url=getElementTextNS("", "url_detalhes", items[i], 0);
	  retorno = retorno+'<a href="'+url+'" class="linkshop" target="_blank"><strong>'+titulo+'</strong><br />'+parcela+'</a>';
 }
 	document.getElementById('gamb').innerHTML=retorno;
}