var httpReq;
var items;
var vcate;
function cargaItems(cual,cate){
	vcate=cate;
	getXML("dame_ficha.php?vidt=" + cual);
}
function getXML(url){
	if (window.XMLHttpRequest){
		httpReq = new XMLHttpRequest();
	}else{
		httpReq = new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (httpReq != null){
		httpReq.onreadystatechange = finCarga;
		httpReq.open("GET", url, true)
		httpReq.send(null);
	}
}
function finCarga(){
	if (httpReq.readyState == 4){
		if (httpReq.status == 200){
			items = httpReq.responseXML.getElementsByTagName("item");
			ProcesaItems();
		}else{
			alert("No se pudo recuperar la información de localidades: " + httpReq.statusText);
		}
	}
}
function ProcesaItems(){
	document.getElementById("cont_ficha").style.visibility="visible";
	document.getElementById("cont_ficha").style.display="inline";
	document.getElementById('foto_4_maxi').style.visibility="visible";
	var vdatos = "";
	vdatos=items[0].childNodes[0].nodeValue.split("|");
	var vficha = "";
	var vitems = "";
	document.getElementById("cont_ficha").style.border = "1px solid "+ vdatos[9];
	vficha = document.getElementById("cont_ficha");
	vitems = "<img src='imagenes/comunes/cabecera_"+ vcate +".png' width='755' height='45' />";
	vitems = vitems.concat("<div id='ficha_izqda'><div id='con_fotos_maxi'><div id='foto_1_maxi'><img src='imagenes/tiendas/t" + vdatos[0]+ "/" + vdatos[0] +"_foto_1_maxi.jpg' width='165' /></div><div id='foto_2_maxi'><img src='imagenes/tiendas/t" + vdatos[0]+ "/" + vdatos[0] +"_foto_2_maxi.jpg' width='165' /></div><div id='foto_3_maxi'><img src='imagenes/tiendas/t" + vdatos[0]+ "/" + vdatos[0] +"_foto_3_maxi.jpg' width='165' /></div><div id='foto_4_maxi'><img src='imagenes/tiendas/t" + vdatos[0]+ "/" + vdatos[0] +"_foto_4_maxi.jpg' width='165' /></div></div><div id='con_fotos_mini'><div id='foto_1_mini' onmouseover='muestraFotoMaxi(1)' onmouseout='muestraFotoMaxi1()'><img src='imagenes/tiendas/t"+ vdatos[0]+"/"+ vdatos[0] +"_foto_1_mini.jpg' width='62' height='50' /></div><div id='foto_2_mini' onmouseover='muestraFotoMaxi(2)' onmouseout='muestraFotoMaxi1()'><img src='imagenes/tiendas/t"+ vdatos[0]+"/"+ vdatos[0] +"_foto_2_mini.jpg' width='62' height='50' /></div><div id='foto_3_mini' onmouseover='muestraFotoMaxi(3)' onmouseout='muestraFotoMaxi1()'><img src='imagenes/tiendas/t"+ vdatos[0]+"/"+ vdatos[0] +"_foto_3_mini.jpg' width='62' height='50' /></div></div></div>");
	vitems = vitems.concat("<div id='ficha_dcha'><a href='#' onclick='ocultaFicha()'><img id='cierraFicha' src='imagenes/comunes/cerrar.png' width='48' height='18' border='0'/></a><img src='imagenes/comunes/tnosotros_" + vcate + ".png' width='200' height='25'><p id='txtnosotros'>"+ vdatos[4] +"</p><img src='imagenes/comunes/tbuscas_" + vcate + ".png' width='200' height='25'><p id='txtbuscas'>" + vdatos[5] + "</p><img src='imagenes/comunes/tconocernos_" + vcate + ".png' width='200' height='25'><p id='txtconocernos'>" + vdatos[6] + "</p></div><div id='datos_comercio'><h4>" + vdatos[1] + "<br/>" + vdatos[2] +"<br/>" + vdatos[3] + "</h4><h5>" + vdatos[8] +"<br/><a href='http://"+ vdatos[7] +"' target='_blank'>" + vdatos[7] + "</a>");																																																																																																																																																																																					if(vdatos[10]=='S'){
	vitems = vitems.concat("<br/><a href='index.php?opc=5&idt=" + vdatos[0]+ "'>ver escaparate</a>");																																																																																																																																																															}
	vitems = vitems.concat("</h5></div>");																																																																																																																																																																			
	vficha.innerHTML = vitems;
}
function CambiarEstilo(id) {
var elementosMenu = getElementsByClassName(document, "a", "activo");
for (k = 0; k< elementosMenu.length; k++) {
	elementosMenu[k].className = "inactivo";
}
if(id=="bt"){
	id="bt0";
}
var identity=document.getElementById(id);
identity.className="activo";
}
/*
    function getElementsByClassName
    Written by Jonathan Snook, http://www.snook.ca/jonathan
    Add-ons by Robert Nyman, http://www.robertnyman.com
*/
function getElementsByClassName(oElm, strTagName, strClassName){
    var arrElements = (strTagName == "*" && document.all)? document.all : oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    strClassName = strClassName.replace(/\-/g, "\\-");
    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
    var oElement;
    for(var i=0; i<arrElements.length; i++){
        oElement = arrElements[i];      
        if(oRegExp.test(oElement.className)){
            arrReturnElements.push(oElement);
        }   
    }
    return (arrReturnElements)
}

function validate(que){
	var Validar = new clsValidator();
	if(que==1){
		Validar.Longitud("palabras", ">", 3, "Escriba una palabra mayor de 2 letras, por favor");
	}else{
		Validar.Longitud("usuario", ">", 5, "El usuario debe ser mayor de 5 letras y menor de 10");
		Validar.Longitud("contra", ">", 5, "La contraseña debe ser mayor de 5 letras y menor de 10");
		Validar.Longitud("usuario", "<", 10, "");
		Validar.Longitud("contra", "<", 10, "");
	}
	if (Validar.Validar()){
		return true;
	} else {
		Validar.getErrors();
		return false;
	}
}
function ocultaFicha(){
	document.getElementById("cont_ficha").style.visibility="hidden";
	document.getElementById('foto_4_maxi').style.visibility="hidden";
}
function muestraFotoMaxi(cual){
	document.getElementById('foto_4_maxi').style.visibility="hidden";
	document.getElementById('foto_4_maxi').style.display = "none";
	document.getElementById('foto_' + cual + '_maxi').style.visibility="visible";
	document.getElementById('foto_' + cual + '_maxi').style.display = "block";
}
function muestraFotoMaxi1(){
	for(i=1;i<4;i++){
		document.getElementById('foto_'+ i +'_maxi').style.visibility="hidden";
		document.getElementById('foto_'+ i +'_maxi').style.display = "none";
	}
	document.getElementById('foto_4_maxi').style.visibility="visible";
	document.getElementById('foto_4_maxi').style.display = "block";
}
