/****************************************************************************************************************************************/
/*FUNCTION feature = Arma la lista de los features

Parametros:

	page= pagina (family page/card page/compara)
	id= id de la tarjeta/familia
	tipo= tipo de feature a buscar

*/

function muestrafeature(page, id, tipo, nombre){
		
	loadXMLDoc('/xml/FeaturesCartoes.xml', 'features', function(xmlDoc) {
		var oHtml='';
		var oCartao, oFeature, oFamilia, oVariante;
		var sEmisor, sGrupo, sVariante, id_fam;
		var features = new Array();
		
		oFeature = xmlDoc.getElementsByTagName("Featuress")[0].getElementsByTagName("Feature");
		oFamilia = xmlDoc.getElementsByTagName("Familias")[0].getElementsByTagName("Familia");
		oVariante = xmlDoc.getElementsByTagName("Variantes")[0].getElementsByTagName("Variante");
		oCartao = xmlDoc.getElementsByTagName("Cartoes")[0].getElementsByTagName("Cartao");



		if(page != "comp"){
			if (tipo=="M"){
				oHtml+="<ul class='inverte'>";
			}else{
				oHtml+="<ul>";
			}
		/*}else{
			oHtml+="<br />";*/
		}
		
		
		if (page == "card" || page == "comp" || page == "card_e_fam"){
			for (x=0; x<oCartao.length; x++){
				if (oCartao[x].getElementsByTagName("ID")[0].firstChild.nodeValue == id){
          id_fam = oCartao[x].getElementsByTagName("Familia")[0].firstChild.nodeValue;
					for (y=0; y<oCartao[x].getElementsByTagName("Features")[0].getElementsByTagName("Feature").length; y++){
						features[features.length]=oCartao[x].getElementsByTagName("Features")[0].getElementsByTagName("Feature")[y].firstChild.nodeValue
					}
				}
			}
		}
		if (page == "card_e_fam"){
			for (x=0; x<oFamilia.length; x++){
				if (oFamilia[x].getElementsByTagName("ID")[0].firstChild.nodeValue == id_fam){
					for (y=0; y<oFamilia[x].getElementsByTagName("Features")[0].getElementsByTagName("Feature").length; y++){
						features[features.length]=oFamilia[x].getElementsByTagName("Features")[0].getElementsByTagName("Feature")[y].firstChild.nodeValue
					}
				}
			}
		}
		if (page == "fam"){
			for (x=0; x<oFamilia.length; x++){
				if (oFamilia[x].getElementsByTagName("ID")[0].firstChild.nodeValue == id){
					for (y=0; y<oFamilia[x].getElementsByTagName("Features")[0].getElementsByTagName("Feature").length; y++){
						features[features.length]=oFamilia[x].getElementsByTagName("Features")[0].getElementsByTagName("Feature")[y].firstChild.nodeValue
					}
				}
			}
		}
		flag=0;
		for (x=0; x<features.length; x++){
			for (y=0; y<oFeature.length; y++){
				if (features[x]==oFeature[y].getElementsByTagName("ID")[0].firstChild.nodeValue){
					if (tipo==oFeature[y].getElementsByTagName("Tipo")[0].firstChild.nodeValue){
						flag=1;
						if (tipo=="M"){
							if (oFeature[y].getElementsByTagName("Icone")[0].firstChild){
								img=oFeature[y].getElementsByTagName("Icone")[0].firstChild.nodeValue
							}else{
								img='';	
							}
							if(page != "comp"){
								oHtml+="<li onclick='abreFecha(this);'><img src='"+img+"' alt='"+oFeature[y].getElementsByTagName("Titulo")[0].firstChild.nodeValue+"' /><div>"+oFeature[y].getElementsByTagName("Resumo")[0].firstChild.nodeValue;
							}else{
								oHtml+="<img src='"+img+"' alt='"+oFeature[y].getElementsByTagName("Titulo")[0].firstChild.nodeValue+"' /><br/>"+oFeature[y].getElementsByTagName("Resumo")[0].firstChild.nodeValue+"<br/><br/>";
							}
						}else{
							oHtml+="<li onclick='abreFecha(this);'>"+oFeature[y].getElementsByTagName("Titulo")[0].firstChild.nodeValue+"<div>"+oFeature[y].getElementsByTagName("Resumo")[0].firstChild.nodeValue;
						}
						if (oFeature[y].getElementsByTagName("Detalhes")[0].firstChild.nodeValue==''){
							oHtml+="</div></li>"
						}else{
							nombre = escape(nombre);
							oHtml+="<div class='saiba_mais'><a href='javascript:popup(\"/cartoes/popcars.htm?"+nombre+"="+oFeature[y].getElementsByTagName("ID")[0].firstChild.nodeValue+"\");' title='Saiba mais'>Saiba mais</a></div></div></li>"
						}
					}
				}
			}
		}
		
		if (document.getElementById(tipo)) if (flag == 0 ) document.getElementById(tipo).style.display='none';
		
		if(page != "comp") oHtml+="</ul>";
		if (page == "comp"){
			document.getElementById("mainben_"+id).innerHTML=oHtml;
		}else{
			switch(tipo){
				case "M":
					if (document.getElementById("mainben")){
						document.getElementById("mainben").innerHTML=oHtml;
						if (flag!=0) document.getElementById("mainben").getElementsByTagName("li")[(document.getElementById("mainben").getElementsByTagName("li").length-1)].className='last_child'
					}
				break;    
				case "V":
					if (document.getElementById("ventajas")){
						document.getElementById("ventajas").innerHTML=oHtml;
						if (flag!=0) document.getElementById("ventajas").getElementsByTagName("li")[(document.getElementById("ventajas").getElementsByTagName("li").length-1)].className='last_child'
					}
					if (document.getElementById("M").style.display == 'none' && document.getElementById("V").style.display == 'none') document.getElementById("MV").style.display='none';
				break;
				case "D":
					if (document.getElementById("default")){
						document.getElementById("default").innerHTML=oHtml;
						if (flag!=0) document.getElementById("default").getElementsByTagName("li")[(document.getElementById("default").getElementsByTagName("li").length-1)].className='last_child'
					}
				break;    
				case "S":
					if (document.getElementById("servicio")){
						// Retirada do Item de Photocard
						oHtml = oHtml.substring(0, 288);
						oHtml += "</ul>";
						
						document.getElementById("servicio").innerHTML=oHtml;
						if (flag!=0) document.getElementById("servicio").getElementsByTagName("li")[(document.getElementById("servicio").getElementsByTagName("li").length-1)].className='last_child'						
					}
					if (document.getElementById("D").style.display == 'none' && document.getElementById("S").style.display == 'none') document.getElementById("DS").style.display='none';
				break;
			}
		}
	});
}
/*FIN DE FUNCION*/