var articulos = [];
var resultados = [];
var categorias = [];
var tiendas = [];


var categoria_a_buscar = 0;
var lastSearchQuery = '';
var oriSearchHtml = '';
var lastSort = 0;

var globalPosOnArray = 0;
var escaparateIndex = 0;

var cooldown = 0;
var updateTo;
var lastHtml = '';
var artiPrint = '';
var pollID = false;
var autoprint = true;

var Buscar_en = -1;

var busy = false;
var busy_str_hold = '';
var lastDb = 't';


var catForumRelation = [
		{'catId': 15, 'forumId': 60}, //Altavoces
		{'catId': 99, 'forumId': 9}, //Barebones
		{'catId': 46, 'forumId': 90}, //Cables
		{'catId': 102, 'forumId': 67}, //Camaras Accesorios
		{'catId': 41, 'forumId': 68}, //Camaras Digitales
		{'catId': 120, 'forumId': 12}, //Carcasas disco duro
		{'catId': 24, 'forumId': 91}, //CD DVD Virgenes
		{'catId': 113, 'forumId': 84}, //Consolas
		{'catId': 115, 'forumId': 85}, //Consolas Accesorios
		{'catId': 3, 'forumId': 14}, //Discos duros
		{'catId': 119, 'forumId': 15}, //Discos duros externos
		{'catId': 9, 'forumId': 16}, //Disqueteras
		{'catId': 122, 'forumId': 58}, //Domotica
		{'catId': 19, 'forumId': 39}, //Escaners
		{'catId': 111, 'forumId': 18}, //Fuentes Alimentacion
		{'catId': 27, 'forumId': 19}, //Grabadoras DVD
		{'catId': 39, 'forumId': 54}, //Hubs Switch
		{'catId': 17, 'forumId': 40}, //Impresoras
		{'catId': 29, 'forumId': 41}, //Joysticks
		{'catId': 114, 'forumId': 77}, //Juegos
		{'catId': 123, 'forumId': 87}, //Juguetes
		{'catId': 10, 'forumId': 13}, //Lector DVD
		{'catId': 116, 'forumId': 92}, //Limpiadores
		{'catId': 121, 'forumId': 69}, //Marcos Digitales
		{'catId': 4, 'forumId': 20}, //Memorias Ram
		{'catId': 14, 'forumId': 61}, //Microfono Auricular
		{'catId': 105, 'forumId': 21}, //Modding
		{'catId': 18, 'forumId': 55}, //Modems
		{'catId': 6, 'forumId': 43}, //Monitores
		{'catId': 71, 'forumId': 64}, //MP3 MP4
		{'catId': 61, 'forumId': 44}, //Multifunciones
		{'catId': 93, 'forumId': 17}, //Multilectores
		{'catId': 117, 'forumId': 8}, //Ordenadores Marca
		{'catId': 82, 'forumId': 22}, //Otras Memorias
		{'catId': 70, 'forumId': 105}, //Papel Impresora
		{'catId': 52, 'forumId': 46}, //PDA GPS
		{'catId': 96, 'forumId': 23}, //Placas Base Amd
		{'catId': 2, 'forumId': 24}, //Placas Base Intel
		{'catId': 91, 'forumId': 25}, //Portatil Accesorios
		{'catId': 88, 'forumId': 26}, //Portatil Base
		{'catId': 81, 'forumId': 27}, //Portatil CD DVD
		{'catId': 89, 'forumId': 28}, //Portatil Disco Duro
		{'catId': 90, 'forumId': 29}, //Portatil Memorias
		{'catId': 31, 'forumId': 7}, //Portatiles
		{'catId': 1, 'forumId': 30}, //Procesadores
		{'catId': 59, 'forumId': 47}, //Proyectores
		{'catId': 12, 'forumId': 48}, //Ratones
		{'catId': 126, 'forumId': 0}, //Promociones ---------------------??????
		{'catId': 94, 'forumId': 56}, //Redes Inalambrica
		{'catId': 108, 'forumId': 70}, //Reprod. Domesticos
		{'catId': 66, 'forumId': 57}, //Routers
		{'catId': 38, 'forumId': 49}, //Sais
		{'catId': 16, 'forumId': 79}, //Sistemas Operativos
		{'catId': 98, 'forumId': 80}, //Software
		{'catId': 33, 'forumId': 50}, //Tabletas Digitales
		{'catId': 11, 'forumId': 34}, //Tarjetas Graficas
		{'catId': 60, 'forumId': 32}, //Tarjetas Pcmcia
		{'catId': 34, 'forumId': 31}, //Tarjetas Red
		{'catId': 13, 'forumId': 33}, //Tarjetas Sonido
		{'catId': 36, 'forumId': 35}, //Tarjetas TV TDT
		{'catId': 7, 'forumId': 51}, //Teclados
		{'catId': 100, 'forumId': 63}, //Telefonia
		{'catId': 107, 'forumId': 71}, //Televisores
		{'catId': 83, 'forumId': 95}, //Tintas Canon
		{'catId': 87, 'forumId': 96}, //Tintas Canon Comp
		{'catId': 62, 'forumId': 97}, //Tintas Epson
		{'catId': 84, 'forumId': 98}, //Tintas Epson Comp
		{'catId': 63, 'forumId': 99}, //Tintas HP
		{'catId': 85, 'forumId': 100}, //Tintas HP Comp
		{'catId': 64, 'forumId': 101}, //Tintas Lexmark
		{'catId': 106, 'forumId': 102}, //Tintas Samsung
		{'catId': 35, 'forumId': 103}, //Toners
		{'catId': 86, 'forumId': 104}, //Toners Comp
		{'catId': 5, 'forumId': 36}, //Torres
		{'catId': 109, 'forumId': 52}, //TPVs
		{'catId': 8, 'forumId': 37}, //Ventiladores
		{'catId': 124, 'forumId': 74}, //Video vigilancia
		{'catId': 73, 'forumId': 72}, //Videocamara Digital
		{'catId': 37, 'forumId': 73}, //Videoconferencia
		{'catId': 121, 'forumId': 69}, //Marco Digital
		{'catId': 110, 'forumId': 0}, //Torres Kit   -------------------?????????

		{'catId': 125, 'forumId': 88}, //Juguetes Accesorios

		{'catId': 127, 'forumId': 78}, //Seguridad
		{'catId': 128, 'forumId': 82}, //Utilidades
		{'catId': 129, 'forumId': 62}, //Sonido Profesional
		{'catId': 130, 'forumId': 86}, //Juegos Consola
		{'catId': 131, 'forumId': 76}, //Educativos
		{'catId': 132, 'forumId': 42}, //Libros Electronicos
		{'catId': 133, 'forumId': 94}, //Tintas Brother
		{'catId': 134, 'forumId': 81}, //Software Gestion
		{'catId': 136, 'forumId': 93}, //Material de Oficina
		{'catId': 137, 'forumId': 65}, //MP5
		{'catId': 103, 'forumId': 0}, //Montaje -------------------------?????????

		//FAMILIAS GENERALES
		{'catId': 988, 'forumId': 5}, //ORDENADORES
		{'catId': 989, 'forumId': 11}, //COMPONENTES
		{'catId': 990, 'forumId': 66}, //IMAGEN
		{'catId': 991, 'forumId': 89}, //CONSUMIBLES
		{'catId': 992, 'forumId': 38}, //PERIFERICOS
		{'catId': 993, 'forumId': 53}, //REDES
		{'catId': 994, 'forumId': 59}, //SONIDO
		{'catId': 995, 'forumId': 75}, //TODOSOFTWARE
		{'catId': 996, 'forumId': 83}, //TODOJUEGOS

		//FAMILIAS ESPECIALES
		{'catId': 997, 'forumId': 4}, //OFERTAS
		{'catId': 998, 'forumId': 3}, //NOVEDADES
		{'catId': 999, 'forumId': 2} //TOPVENTAS
];

function submitSearch(event, e) {
		if(event.keyCode == 13) doSearch(false);
}

function addObject(Descripcion, Precio, Stock, Rank, Cat, Irank, Istock, Iupdown, devol){

	articulos[articulos.length++] = {
		descripcion: Descripcion,
		precio: Precio,
		stock: Stock,
		rank: Rank,
		cat: Cat,
		iRank: Irank,
		iStock: Istock,
		iUpDown: Iupdown,
		devolucion: (typeof (devol) == "undefined") ? 0 : devol
	};

}

function addCatego(id, name, keywords) {
	categorias[categorias.length++] = {
		id: id,
		name: name
	};
}

function addTienda(_id, _prov, _pobl, _dire, _tele) {
	tiendas[tiendas.length++] = {
		id: _id,
		provincia: _prov,
		poblacion: _pobl,
		direccion: _dire,
		telefono: _tele
	};
}

function rqDb(db) {
	if (typeof(db) != "undefined")
		var cat = db;
	else
		var cat = document.getElementById('where').value || 0;

	var xmlHttp;
	try {
		xmlHttp=new XMLHttpRequest();
	} catch (e) {
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				alert("Navegador incompatible, por favor, actualice a la ultima versión de su navegador");
				return false;
			}
		}
	}
	xmlHttp.onreadystatechange = function() {
		switch(xmlHttp.readyState) {
		case 1:
				busy = true;
				break;
		case 4:
				if (xmlHttp.status == 200) {
					busy = false;
					eval(xmlHttp.responseText);
					lastDb = cat;
				}
				break;
		}
	}

	if (lastDb != cat && cat != 'tiendas') {
	articulos = [];
	xmlHttp.open('GET', '/db/dbReq.php?file='+cat, true);
	xmlHttp.send(null);
	} else if (lastDb != cat && cat == 'tiendas') {
	tiendas = [];
	xmlHttp.open('GET', '/db/dbReq.php?file=tiendas', true);
	xmlHttp.send(null);
	}
}

function swapSearchEngine(tipo) {

	var newEngine = (typeof(tipo) != "undefined" ) ? tipo : document.getElementById('where').value;
	var Select = '', html = '';


	if (newEngine == 'tiendas') {
		for (var i = 0; i < categorias.length; i++) {
			if ((categorias[i].id < 980) && (categorias[i].id != 103)) {
				Select+= ' <option value="'+categorias[i].id+'">'+categorias[i].name+'</option>';
			}
		}

		globalOption = (CATEGORIA_GLOBAL != 0) ? ' <option value="'+CATEGORIA_GLOBAL+'">- En '+getCategoStr2(CATEGORIA_GLOBAL)+'</option>' : '';

		html =	'<form action="#" method="post" name="browser" id="browser" onsubmit="return false;">';
		html+=	'<div class="left clearfix">'+
					'<div class="selectFamHolder">'+
						'<select id="where" name="where" onchange="swapSearchEngine(); return false;">'+
						globalOption +
						' <option value="0">- Todos los articulos</option>'+
						' <option value="tiendas" selected="selected">- Buscar tu Tienda APP</option>'+
						' <option value="0">--------------------------</option>'+
						Select +
						'</select>'+
					'</div>'+
					'<div class="searchFieldHolder"><input name="fprov" type="text" id="fprov" value="Por Provincia..." onfocus="if (this.value == \'Por Provincia...\') this.value = \'\'; rqDb();" onkeyup="submitSearch(event, this)" /></div>'+
					'<div class="searchFieldHolder"><input name="fpobl" type="text" id="fpobl" value="Poblacion..." onfocus="if (this.value == \'Poblacion...\') this.value = \'\'; rqDb();" onkeyup="submitSearch(event, this)" /></div>'+
					'<div class="searchFieldHolder"><input name="fcalle" type="text" id="fcalle" value="Calle..." onfocus="if (this.value == \'Calle...\') this.value = \'\'; rqDb();" onkeyup="submitSearch(event, this)" /></div>'+
				'</div>';
		html+=	'</form>';

		document.getElementById('busca').innerHTML = html;
	} else {

		for (var i = 0; i < categorias.length; i++) {
			if ((categorias[i].id < 980) && (categorias[i].id != 103)) {
				if (newEngine == categorias[i].id)
					 Select+= ' <option value="'+categorias[i].id+'" selected="selected">'+categorias[i].name+'</option>';
				else Select+= ' <option value="'+categorias[i].id+'">'+categorias[i].name+'</option>';
			}
		}

		globalOption = (CATEGORIA_GLOBAL != 0) ? ' <option value="'+CATEGORIA_GLOBAL+'">- En '+getCategoStr2(CATEGORIA_GLOBAL)+'</option>' : '';


		var html ='<form action="#" method="post" name="browser" id="browser" onsubmit="return false;">';
		html+='<div class="left clearfix">'+
					'<div class="selectFamHolder">'+
						'<select id="where" name="where" onchange="swapSearchEngine(); return false;">'+
						globalOption +
						' <option value="0" '+((newEngine == 0) ? "selected" : '')+'>- Todos los articulos</option>'+
						' <option value="tiendas">- Buscar tu Tienda APP</option>'+
						' <option value="0">--------------------------</option>'+
						Select +
						'</select>'+
					 '</div>'+
				 	 '<div class="searchFieldHolder"><input name="query" type="text" id="query" value="&iquest;Qu&eacute; buscas?" onfocus="this.value = \'\'; rqDb();" onkeyup="submitSearch(event, this)" /></div>'+
				 '</div>'+

				 '<div class="right clearfix">'+
				 	 '<div class="sortLinkHolder" id="linkEscap"><a href="#" onclick="escaparate(0, true); return false;">Escaparate Virtual</a></div>'+
					 '<div class="sortLinkHolder" id="linkSort" style="display:none;"><a href="#" onclick="showData(-1, 1, true, 21); return false;">Ordenar<br />por precio</a></div>'+
					 '<div class="sortLinkHolder" id="linkPrint" style="display:none;"><a href="#" onclick="printVisible(); return false;">Imprimir<br /> P&aacute;gina </a></div>';
		html+= (CATEGORIA_GLOBAL != 997) ? loadForumLink() : '';
		html+= (CATEGORIA_GLOBAL == 997) ? '<div class="sortLinkHolder" id="linkOfPdf"><a href="ofertas-app.rar" target="_blank">OFERTAS<br />en PDF</a></div>': '<div class="" id="linkPdf"><a href="#" onclick="downloadPdf(); return false;"><img height="20" border="0" width="15" src="/images/blank.gif"/></a></div>';


		html+= '</div>';
		html+='</form>';

		document.getElementById('busca').innerHTML = html;
	}
}

function busca_tienda() {
	var container = document.getElementById('resultados');

	if (busy) {
		//busy_str_hold = document.getElementById('query').value;
		container.innerHTML='<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="Results"><tr><td align="center">&nbsp;</td></tr><tr><td align="center">Buscando...<br>Espere por favor</td></tr><tr><td align="center">&nbsp;</td></tr></table>';
		setTimeout('busca_tienda();', 1000);
		return false;
	}

	var results = new Array();
	var to = 0;

	var qprov = (document.getElementById('fprov').value != 'Por Provincia...') ? document.getElementById('fprov').value : '';
	var qpobl = (document.getElementById('fpobl').value != 'Poblacion...') ? document.getElementById('fpobl').value : '';
	var qcalle = (document.getElementById('fcalle').value != 'Calle...') ? document.getElementById('fcalle').value : '';

	var kprov = qprov.match(/"[^"]*"|[^ ]*/g);
	var kpobl = qpobl.match(/"[^"]*"|[^ ]*/g);
	var kcalle = qcalle.match(/"[^"]*"|[^ ]*/g);
	kprov = array_delEmpty(unique(kprov));
	kpobl = array_delEmpty(unique(kpobl));
	kcalle = array_delEmpty(unique(kcalle));


	//aviso que estoy buscando
	container.innerHTML='<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="Results"><tr><td align="center">&nbsp;</td></tr><tr><td align="center">Buscando...<br>Espere por favor</td></tr><tr><td align="center">&nbsp;</td></tr></table>';

	to = tiendas.length;
	for (var i = 0; i < to; i++) {
		//~ if (keywordsInStr(qkeywords, tiendas[i]['PROV'] + ' ' + tiendas[i]['POBL'] + ' ' +tiendas[i]['DIRE']))
		if (
			(keywordsInStr(kprov, tiendas[i].provincia)) &&
			(keywordsInStr(kpobl, tiendas[i].poblacion)) &&
			(keywordsInStr(kcalle, tiendas[i].direccion))
			)
			results[results.length++] = tiendas[i];
	}

	if (results.length < 1) {
		container.innerHTML='<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="Results_MSG"><tr><td align="center">&nbsp;</td></tr><tr><td align="center">Busqueda Sin Resultados =(</td></tr><tr><td align="center">&nbsp;</td></tr></table>';
		return false;
	}

	html = '<div id="tiendas" class="clearfix">'+
			'<table id="storeList" class="storesTable" border="0" cellpadding="0" cellspacing="0">'+
						'<tr>'+
							'<th class="storeName">Provincias</th>'+
							'<th class="storeTel">Tel&eacute;fono</th>'+
							'<th class="storeAddress">Direcci&oacute;n</th>'+
							'<th class="provincia">Provincia</th>'+
						'</tr>';

	var pro, pob, url;

	to = results.length;
	var odd = 0;
	for (var i = 0; i < to; i++) {
		pro = results[i].provincia.toLowerCase().replace(/[\ \']/g, "-").replace(/ñ/g, "n");
		pob = results[i].poblacion.toLowerCase().replace(/[\ \']/g, "-").replace(/ñ/g, "n");
		url = '/tienda-de-informatica-'+pro+'-'+pob+'.php';
		provUrl = '/tienda-de-informatica-'+pro+'.php';

		if (results[i].telefono == '') {
			//si es proxima apertura (no tiene telefono) no hacemos nada por ahora
		} else {
			html += '<tr class="'+ ((odd++%2 != 0) ? 'even' : 'odd') +'">'+
				'<td class="storeName"><a href="'+url+'" target="_blank">'+ pob.toUpperCase() +'</a></td>'+
				'<td class="storeTel"><a href="'+url+'" target="_blank">'+ results[i].telefono +'</a></td>'+
				'<td class="storeAddress"><a href="'+url+'" target="_blank">'+ results[i].direccion +'</a></td>'+
				'<td class="provincia"><a href="'+provUrl+'" target="_blank">'+ results[i].provincia +'</a></td>'+
			'</tr>';
		}

	}

	html+='</table>';

	container.innerHTML = html;

	return false;
}

function _dep_busca_tienda() {
	var container = document.getElementById('resultados');

	if (busy) {
		//busy_str_hold = document.getElementById('query').value;
		container.innerHTML='<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="Results"><tr><td align="center">&nbsp;</td></tr><tr><td align="center">Buscando...<br>Espere por favor</td></tr><tr><td align="center">&nbsp;</td></tr></table>';
		setTimeout('busca_tienda();', 1000);
		return false;
	}

	var results = new Array();
	var to = 0;

	var qprov = (document.getElementById('fprov').value != 'Por Provincia...') ? document.getElementById('fprov').value : '';
	var qpobl = (document.getElementById('fpobl').value != 'Poblacion...') ? document.getElementById('fpobl').value : '';
	var qcalle = (document.getElementById('fcalle').value != 'Calle...') ? document.getElementById('fcalle').value : '';

	var kprov = qprov.match(/"[^"]*"|[^ ]*/g);
	var kpobl = qpobl.match(/"[^"]*"|[^ ]*/g);
	var kcalle = qcalle.match(/"[^"]*"|[^ ]*/g);
	kprov = array_delEmpty(unique(kprov));
	kpobl = array_delEmpty(unique(kpobl));
	kcalle = array_delEmpty(unique(kcalle));


	//aviso que estoy buscando
	container.innerHTML='<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="Results"><tr><td align="center">&nbsp;</td></tr><tr><td align="center">Buscando...<br>Espere por favor</td></tr><tr><td align="center">&nbsp;</td></tr></table>';

	to = tiendas.length;
	for (var i = 0; i < to; i++) {
		//~ if (keywordsInStr(qkeywords, tiendas[i]['PROV'] + ' ' + tiendas[i]['POBL'] + ' ' +tiendas[i]['DIRE']))
		if (
			(keywordsInStr(kprov, tiendas[i].provincia)) &&
			(keywordsInStr(kpobl, tiendas[i].poblacion)) &&
			(keywordsInStr(kcalle, tiendas[i].direccion))
			)
			results[results.length++] = tiendas[i];
	}

	if (results.length < 1) {
		container.innerHTML='<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="Results_MSG"><tr><td align="center">&nbsp;</td></tr><tr><td align="center">Busqueda Sin Resultados =(</td></tr><tr><td align="center">&nbsp;</td></tr></table>';
		return false;
	}

	var html='<table width="714" border="0" cellpadding="0" cellspacing="0" background="/imf/fondo-tienda.jpg" id="tiendas_result">';
	html+='  <tr>';
	html+='    <td height="52" colspan="4">';
	html+='	<div class="tienda_sombra_a" align="left"><br><span class="tienda_sombra_a1">TIENDAS APP INFORM&Aacute;TICA</span></div>';
	html+='	<div class="tienda_sombra_b" align="left">TIENDAS <span class="tienda_sombra_a2">APP INFORM&Aacute;TICA</span></div></td>';
	html+='  </tr>';
	html+='  <tr align="center" valign="middle">';
	html+='    <th width="211" height="16">POBLACION</th>';
	html+='    <th width="90">TEL&Eacute;FONO</th>';
	html+='    <th width="300">DIRECCI&Oacute;N</th>';
	html+='    <th width="113">PROVINCIA</th>';
	html+='  </tr>';
	html+='   <tr>';
	html+='    <td height="26" colspan="4">';
	html+='	  <table width="714" border="0" cellpadding="0" cellspacing="0" background="/imf/fondo-tabla.gif">';

	var pro, pob, url;

	to = results.length;
	for (var i = 0; i < to; i++) {
		pro = results[i].provincia.toLowerCase().replace(/[\ \']/g, "-").replace(/ñ/g, "n");
		pob = results[i].poblacion.toLowerCase().replace(/[\ \']/g, "-").replace(/ñ/g, "n");
		url = '/tienda-de-informatica-'+pro+'-'+pob+'.php';
		provUrl = '/tienda-de-informatica-'+pro+'.php';

		if (results[i].telefono == '') {
			html+='<tr valign="middle" onMouseOver="this.className=\'highlight\'" onMouseOut="this.className = \'\';" onclick="document.location.href=\'/franquicias-de-informatica.php\'"> ';
			html+='	<td width="210" height="24" align="right" nowrap><a href="/franquicias-de-informatica.php">'+results[i].poblacion.toUpperCase()+'&nbsp;&nbsp;</a></td>';
			html+='	<td width="92" align="center" nowrap>--- --- ---</td>';
			html+='	<td width="298" align="left" nowrap class="globito" >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="/franquicias-de-informatica.php"><span class="signos-exclamacion">&iexcl;&iexcl;&iexcl;</span> PROXIMA APERTURA <span class="signos-exclamacion">!!!</span></a></td>';
			html+='	<td width="114" align="center" nowrap ><a href="/franquicias-de-informatica.php">'+results[i].provincia.toUpperCase()+'</a></td>';
			html+='</tr>';
		} else {
			html+='<tr onMouseOver="this.className=\'highlight\';" onMouseOut="this.className = \'\';" onclick="document.location.href=\''+url+'\'">';
			html+='	<td width="210" height="24" align="right"><a href="'+url+'">'+results[i].poblacion.toUpperCase()+'&nbsp;</a></td>';
			html+=' <td width="91" height="24" align="center"><a href="'+url+'">'+results[i].telefono.toUpperCase()+'</a></td>';
			html+=' <td width="299" height="24" align="left" class="globito">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="'+url+'">'+results[i].direccion.toUpperCase()+'</a></td>';
			html+=' <td width="113" height="24" align="center" ><a href="'+url+'">'+results[i].provincia.toUpperCase()+'</a></td>';
			html+='	</tr>';
		}

	}

	html+='</td></tr></table><table width="714" height="100%" border="0" cellpadding="0" cellspacing="0"><tr>';
	html+='<td valign="top" bgcolor="#26B1AB"><img src="/imf/fondo-busqueda.jpg" width="714" height="76"></td>';
	html+='</tr></table>';

	container.innerHTML = html;

	return false;
}


function busca_tienda_div() {
	var container = document.getElementById('resultados');

	if (busy) {
		//busy_str_hold = document.getElementById('query').value;
		container.innerHTML='<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="Results"><tr><td align="center">&nbsp;</td></tr><tr><td align="center">Buscando...<br>Espere por favor</td></tr><tr><td align="center">&nbsp;</td></tr></table>';
		setTimeout('busca_tienda();', 1000);
		return false;
	}

	var results = new Array();
	var to = 0;

	var qprov = (document.getElementById('fprov').value != 'Por Provincia...') ? document.getElementById('fprov').value : '';
	var qpobl = (document.getElementById('fpobl').value != 'Poblacion...') ? document.getElementById('fpobl').value : '';
	var qcalle = (document.getElementById('fcalle').value != 'Calle...') ? document.getElementById('fcalle').value : '';

	var kprov = qprov.match(/"[^"]*"|[^ ]*/g);
	var kpobl = qpobl.match(/"[^"]*"|[^ ]*/g);
	var kcalle = qcalle.match(/"[^"]*"|[^ ]*/g);
	kprov = array_delEmpty(unique(kprov));
	kpobl = array_delEmpty(unique(kpobl));
	kcalle = array_delEmpty(unique(kcalle));


	//aviso que estoy buscando
	container.innerHTML='<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="Results"><tr><td align="center">&nbsp;</td></tr><tr><td align="center">Buscando...<br>Espere por favor</td></tr><tr><td align="center">&nbsp;</td></tr></table>';

	to = tiendas.length;
	for (var i = 0; i < to; i++) {
		//~ if (keywordsInStr(qkeywords, tiendas[i]['PROV'] + ' ' + tiendas[i]['POBL'] + ' ' +tiendas[i]['DIRE']))
		if (
			(keywordsInStr(kprov, tiendas[i].provincia)) &&
			(keywordsInStr(kpobl, tiendas[i].poblacion)) &&
			(keywordsInStr(kcalle, tiendas[i].direccion))
			)
			results[results.length++] = tiendas[i];
	}

	if (results.length < 1) {
		container.innerHTML='<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="Results_MSG"><tr><td align="center">&nbsp;</td></tr><tr><td align="center">Busqueda Sin Resultados =(</td></tr><tr><td align="center">&nbsp;</td></tr></table>';
		return false;
	}

	html = '<div id="tiendas" class="clearfix">';

	var pro, pob, url;

	to = results.length;
	for (var i = 0; i < to; i++) {
		pro = results[i].provincia.toLowerCase().replace(/[\ \']/g, "-").replace(/ñ/g, "n");
		pob = results[i].poblacion.toLowerCase().replace(/[\ \']/g, "-").replace(/ñ/g, "n");
		url = '/tienda-de-informatica-'+pro+'-'+pob+'.php';
		provUrl = '/tienda-de-informatica-'+pro+'.php';

		if (results[i].telefono == '') {
			//si es proxima apertura (no tiene telefono) no hacemos nada por ahora
		} else {
			html +=	'<div class="tarjTienda">'+
						'<div class="tarjBorde">'+
							'<div class="storeName"><a href="'+url+'" target="_blank">'+ pob +'</a></div>'+
							'<div class="storePicture"><img border="0" src="/comunicador/'+ results[i].id +'/small/2.jpg" alt="'+ pob +'" title="'+ pob +'" /></div>'+
							'<div class="storeAddress"><a href="'+url+'" target="_blank">'+ results[i].direccion +'</a></div>'+
							'<div class="getInn"><a href="'+url+'" target="_blank">entrar <img src="/images/flechita.gif" border="0" width="7" height="9"></a></div>'+
							'<div class="provincia"><div class="provinciaholder"><a href="'+provUrl+'" target="_blank">'+ results[i].provincia +'</a></div></div>'+
						'</div>'+
					'</div>';
		}

	}

	html+='</div>';

	container.innerHTML = html;

	return false;
}


function busca_tienda_dep() {
if (busy) {
	busy_str_hold = document.getElementById('query').value;
	container.innerHTML='<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="Results"><tr><td align="center">&nbsp;</td></tr><tr><td align="center">Buscando...<br>Espere por favor</td></tr><tr><td align="center">&nbsp;</td></tr></table>';
	setTimeout('doSearch('+auto+');', 1000);
	return false;
}

var Cerca = new Array();
var ctas = 0;
var esta = false;
var html = '';
var color = '';
var url = '';
var container = document.getElementById('resultados');


	var qprov = (document.getElementById('fprov').value != 'Por Provincia...') ? document.getElementById('fprov').value : '';
	var qpobl = (document.getElementById('fpobl').value != 'Poblacion...') ? document.getElementById('fpobl').value : '';
	var qcalle = (document.getElementById('fcalle').value != 'Calle...') ? document.getElementById('fcalle').value : '';

	var kprov = qprov.match(/"[^"]*"|[^ ]*/g);
	var kpobl = qpobl.match(/"[^"]*"|[^ ]*/g);
	var kcalle = qcalle.match(/"[^"]*"|[^ ]*/g);
	kprov = array_delEmpty(unique(kprov));
	kpobl = array_delEmpty(unique(kpobl));
	kcalle = array_delEmpty(unique(kcalle));

	//aviso que estoy buscando
	container.innerHTML='<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="Results"><tr><td align="center">&nbsp;</td></tr><tr><td align="center">Buscando...<br>Espere por favor</td></tr><tr><td align="center">&nbsp;</td></tr></table>';

	for (var i=0; i < tiendas.length; i++) {
		if (
			(keywordsInStr(kprov, tiendas[i]['PROV'])) &&
			(keywordsInStr(kpobl, tiendas[i]['POBL'])) &&
			(keywordsInStr(kcalle, tiendas[i]['DIRE']))
			)
			{
				Cerca[ctas++]=tiendas[i];
			}
	}
	if (ctas < 1) {
	container.innerHTML="<table width=\"100%\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\" class=\"Results_MSG\"><tr><td align=\"center\">&nbsp;</td></tr><tr><td align=\"center\">Busqueda Sin Resultados =(</td></tr><tr><td align=\"center\">&nbsp;</td></tr></table>";
	return false;
	}

	html+='<table width="714" border="0" cellpadding="0" cellspacing="0" background="/imf/fondo-tienda.jpg" id="tiendas_result">';
	html+='  <tr>';
	html+='    <td height="52" colspan="4">';
	html+='	<div class="tienda_sombra_a" align="left"><br><span class="tienda_sombra_a1">TIENDAS APP INFORM&Aacute;TICA</span></div>';
	html+='	<div class="tienda_sombra_b" align="left">TIENDAS <span class="tienda_sombra_a2">APP INFORM&Aacute;TICA</span></div></td>';
	html+='  </tr>';
	html+='  <tr align="center" valign="middle">';
	html+='    <th width="211" height="16">POBLACION</th>';
	html+='    <th width="90">TEL&Eacute;FONO</th>';
	html+='    <th width="300">DIRECCI&Oacute;N</th>';
	html+='    <th width="113">PROVINCIA</th>';
	html+='  </tr>';
	html+='   <tr>';
	html+='    <td height="26" colspan="4">';
	html+='	  <table width="714" border="0" cellpadding="0" cellspacing="0" background="/imf/fondo-tabla.gif">';


		for (var i = 0; i < Cerca.length;i++) {

		var pro, pob = "";

		pro = Cerca[i]['PROV'].toLowerCase().replace(/ /g, '-');
		pob = Cerca[i]['POBL'].toLowerCase().replace(/ /g, '-');
		pro = pro.toLowerCase().replace(/'/g, '-');
		pob = pob.toLowerCase().replace(/'/g, '-');
		pro = pro.replace(/ñ/g, "n");
		pob = pob.replace(/ñ/g, "n");


		url = '/tienda-de-informatica-'+pro+'-'+pob+'.php';

			if (Cerca[i]['TELE'] == '') {

			html+='<tr valign="middle" onMouseOver="this.className=\'highlight\'" onMouseOut="this.className = \'\';" onclick="document.location.href=\'/franquicias-de-informatica.php\'"> ';
			html+='	<td width="210" height="24" align="right" nowrap><a href="/franquicias-de-informatica.php">'+Cerca[i]['POBL'].toUpperCase()+'&nbsp;&nbsp;</a></td>';
			html+='	<td width="92" align="center" nowrap>--- --- ---</td>';
			html+='	<td width="298" align="left" nowrap class="globito" >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="/franquicias-de-informatica.php"><span class="signos-exclamacion">&iexcl;&iexcl;&iexcl;</span> PROXIMA APERTURA <span class="signos-exclamacion">!!!</span></a></td>';
			html+='	<td width="114" align="center" nowrap ><a href="/franquicias-de-informatica.php">'+Cerca[i]['PROV'].toUpperCase()+'</a></td>';
			html+='</tr>';

			} else {
				html+='<tr onMouseOver="this.className=\'highlight\';" onMouseOut="this.className = \'\';" onclick="document.location.href=\''+url+'\'">';
				html+='	<td width="210" height="24" align="right"><a href="'+url+'">'+Cerca[i]['POBL'].toUpperCase()+'&nbsp;</a></td>';
				html+=' <td width="91" height="24" align="center"><a href="'+url+'">'+Cerca[i]['TELE'].toUpperCase()+'</a></td>';
				html+=' <td width="299" height="24" align="left" class="globito">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="'+url+'">'+Cerca[i]['DIRE'].toUpperCase()+'</a></td>';
				html+=' <td width="113" height="24" align="center" ><a href="'+url+'">'+Cerca[i]['PROV'].toUpperCase()+'</a></td>';
				html+='	</tr>';
			}
		}

		html+='</td></tr></table><table width="714" height="100%" border="0" cellpadding="0" cellspacing="0"><tr>';
		html+='<td valign="top" bgcolor="#26B1AB"><img src="/imf/fondo-busqueda.jpg" width="714" height="76"></td>';
		html+='</tr></table>';

	if (ctas > 0) {
	container.innerHTML=html;
	//ConvertRowsToLinks("convert");
	}
	return false;
}

function doSearch(auto) {
	categoria_a_buscar = document.getElementById('where').value;
	cat_a_pdf = categoria_a_buscar;

	if (categoria_a_buscar == 'tiendas') {
			busca_tienda();
			return false;
	}

	if (busy) {
		if (document.getElementById('query').value != 'Buscando...')
			busy_str_hold = document.getElementById('query').value;

		document.getElementById('query').value = 'Buscando...';
		setTimeout('doSearch('+auto+');', 500);
		return false;
	} else {
		document.getElementById('query').value = busy_str_hold || document.getElementById('query').value;
		busy_str_hold = false;
	}

	resultados = [];

	globalPosOnArray = 0;


	//extraigo la consulta,
	var query = (document.getElementById('query').value.indexOf('buscas') == -1) ? document.getElementById('query').value : '';
	lastSearchQuery = query;


	if ( (query == '') && (!auto) ){return doSearch(true)};

	//determino las keywords
	var keywords = query.match(/"[^"]*"|[^ ]*/g);
	keywords = array_delEmpty(unique(keywords));


	if (
		(categoria_a_buscar == 988) ||
		(categoria_a_buscar == 989) ||
		(categoria_a_buscar == 990) ||
		(categoria_a_buscar == 991) ||
		(categoria_a_buscar == 992) ||
		(categoria_a_buscar == 993) ||
		(categoria_a_buscar == 994) ||
		(categoria_a_buscar == 995) ||
		(categoria_a_buscar == 996) ||
		(categoria_a_buscar == 997) ||
		(categoria_a_buscar == 998) ||
		(categoria_a_buscar == 999)
	) categoria_a_buscar = 0;

	//recorro la db
	for (var i = 0; i < articulos.length; i++) {

		var articulo = getCategoStr(articulos[i].cat)+' '+articulos[i].descripcion.toLowerCase();

		if (
		(keywordsInStr(keywords, articulo)) &&
		/*(articulos[i].precio >= min_price) &&
		(articulos[i].precio <= max_price) &&*/
		((articulos[i].cat == categoria_a_buscar) || (categoria_a_buscar == 0))
		) {
			resultados[resultados.length++] = articulos[i];
		}

	}

	return showData(Buscar_en, 0, auto, 21);
 }

function appendData(tableId, start, qToAdd) {
	//pTable = document.getElementById(tableId);

	articulosHolder = document.getElementById(tableId);

	for (var i = start; i < (start + qToAdd); i++) {

		if (i >= resultados.length) {
		document.getElementById('manualAppend').style.display = 'none';
		window.clearInterval(pollID);
		break;
		}

		//if (i%3 == 0) { row1 = pTable.insertRow(pTable.rows.length); }

		//cell1 = row1.insertCell(-1);
    	//cell1.className = "celda"+Math.ceil(i%3);
		articulosHolder.appendChild(formatData(resultados[i].descripcion, fmtMoney(resultados[i].precio, 2, ",", '.'), resultados[i].stock, resultados[i].rank, resultados[i].cat, resultados[i].iRank, resultados[i].iStock, resultados[i].iUpDown, i, resultados[i].devolucion));

	}

	globalPosOnArray = start + qToAdd;

	return true;
}



function detectScroll() {
	var intElemScrollHeightOuter = document.documentElement.clientHeight;
	var intElemScrollHeightInner = document.documentElement.scrollHeight;
	var intElemScrolled = window.pageYOffset || document.documentElement.scrollTop;

	var height = intElemScrollHeightInner - intElemScrollHeightOuter;
	var list_height = (document.getElementById('tabla') != null) ? document.getElementById('tabla').offsetHeight : 0;
	var faq_height = (document.getElementById('faq') != null) ? document.getElementById('faq').offsetHeight : 0;

	if ((intElemScrolled >= height - list_height - faq_height - 250) && (globalPosOnArray < resultados.length )) {

		appendData('artiresu', globalPosOnArray, 9);

	}
	return 'CH: '+intElemScrollHeightOuter+', SH: '+intElemScrollHeightInner+', ST: '+intElemScrolled;
}

function manualAppend() {

	appendData('articulos', globalPosOnArray, 21);

}

function showData(pagina, orden, auto, cantPorPagina) {
	var container = document.getElementById('resultados');
	container.style.height="";
	document.getElementById('linkSort').style.display="";
	//document.getElementById('linkPdf').style.display="";
	document.getElementById('linkPrint').style.display="";

	if (document.getElementById('linkPrintFicha') != null) {
	document.getElementById('linkPrintFicha').style.display = 'none';
	}


	var html = '';
	var breaker = 0;

	if (resultados.length == 0) {
		container.innerHTML = '<div id="paginado_superior"><table width="714" height="217" border="0" align="center" cellpadding="0" cellspacing="1" background="/imf-listado/fon-lista.jpg"><tr><td valign="middle" align="center" class="noResults">No se produjeron resultados</td></tr></table></div>';
		return false;
	}

	if (pollID) {
	window.clearInterval(pollID);
	}

	//ordena los resultados
	if (orden == 0) {
		resultados.sort(SortRank);
		lastSort = 0;
		document.getElementById('linkSort').innerHTML = '<a href="javascript:;" onClick="return showData(-1, 1, true, 21)">Ordenar<br />por precio</a>';
	} else {
		resultados.sort(SortPrice);
		lastSort = 1;
		document.getElementById('linkSort').innerHTML = '<a href="javascript:;" onClick="return showData(-1, 0, true, 21)">Ordenar Top Ventas</a>';
	}

	html+= '<div id="articulos" class="clearfix">';

	if (pagina == -1) {
		globalPosOnArray = 0;
		html+= '</div>';
		html+= '<div id="manualAppend"><img src="/images/flechitas.png" border="0" alt="" />&nbsp&nbsp&nbsp&nbsp&nbsp<a href="#" onclick="manualAppend(); return false;" >Ver Siguientes Art&iacute;culos</a>&nbsp&nbsp&nbsp&nbsp&nbsp<img src="/images/flechitas.png" border="0" alt="" /></div>';
		container.innerHTML = html;

		appendData('articulos', globalPosOnArray, 21);
		//pollID = setInterval("detectScroll()", 500);

		return false;
	}

	html+= '</div>';

	container.innerHTML = html;

	return false;
 }

function LoadFicha(resultado) {

	/*Constantes*/
	var _rankGraph	= '<img src="{#starsGraph}" alt="{#rankingApp}" />';
	var _rankPos	= '{#rankingApp} <img src="{#upDownGraph}" alt="{#upDown}" />';
	var _stockGraph	= '<img src="{#stockGraph}" width="22" height="12" alt="{#stockApp}" />';



	var rankGraph  	= document.getElementById('rankGraph');
	var rankPos 	= document.getElementById('rankPos');
	var stockGraph 	= document.getElementById('stockGraph');
	var priceArt 	= document.getElementById('priceArt');
	var stockApp 	= document.getElementById('stockApp');

	var imgPremio 	= document.getElementById('Premio');


	switch(resultado.iUpDown) {
		case 0: var iUpDown = '/imf-dis/sube.gif'; altIUpDown = 'Baja'; break;
		case 1: var iUpDown = '/imf-dis/baja.gif'; altIUpDown = 'Sube'; break;
		case 2: var iUpDown = '/imf-list/nuevo-java.gif';  altIUpDown = 'Nuevo'; break;
		case 3: var iUpDown = '/imf-list/oferta-java.gif'; altIUpDown = 'Oferta'; break;
	}


	rankGraph.innerHTML  = _rankGraph.replace(/{#starsGraph}/g, '/imf-dis/stars'+resultado.iRank+'.gif').replace(/{#rankingApp}/g, resultado.rank);


	if (resultado.iUpDown >= 2)
	rankPos.innerHTML 	 = _rankPos.replace(/{#rankingApp}/g, '').replace(/{#upDownGraph}/g, iUpDown).replace(/{#upDown}/g, altIUpDown);
	else
	rankPos.innerHTML 	 = _rankPos.replace(/{#rankingApp}/g, resultado.rank).replace(/{#upDownGraph}/g, iUpDown).replace(/{#upDown}/g, altIUpDown);


	stockGraph.innerHTML = _stockGraph.replace(/{#stockGraph}/g, '/imf-dis/stock'+resultado.iStock+'.gif').replace(/{#stockApp}/g, resultado.stock);
	stockApp.innerHTML	 = resultado.stock;
	priceArt.innerHTML	 = fmtMoney(resultado.precio, 2, ",", '.');

	var newSrc = '/imf-plantilla/precio-calidad-garantia.gif';	//este precio-calidad-garantia se reemplazo por una imagen sin logo.
																//pero cambiar el src no tiene sentido.
	var newAlt = '';

	/*Pregunto si es oferta*/
	if (resultado.iUpDown == 3) {
		newSrc = '/imf-plantilla/oferta.gif';
		newAlt = 'OFERTA!!';
	}

	/*Pregunto si es Top1 y no es oferta*/



	/*Pregunto si es nuevo y no es 4..5 estrellas*/
	if ( (resultado.iUpDown == 2) ) {
		newSrc = '/imf-plantilla/new.gif';
		newAlt = 'ARTICULO NUEVO!!';
	}

	if ((resultado.iRank == 9) && (resultado.iUpDown != 3)) {
		newSrc = '/imf-plantilla/topventas.gif';
		newAlt = 'TOP VENTAS APP!!';
	}


	var top = getTopList(articulos);
	if ( (top.descripcion == resultado.descripcion) && (resultado.iUpDown != 3) && (resultado.iRank != 9) ) {
		newSrc = 'imf-top/n1familia.gif';
		newAlt = 'ARTICULO MAS VENDIDO!!';
	}


	if ((resultado.iRank == 10) && (resultado.iUpDown != 3)) {
		newSrc = '/imf-plantilla/premiado.gif';
		newAlt = 'PREMIADO APP!!';
	}

	if (resultado.devolucion > 3 && resultado.devolucion != 88) {
		 newSrc = '/imf-plantilla/RMA.gif';
		 newAlt = 'ALTO RMA';
	}



	if (imgPremio.src != newSrc) {
		imgPremio.src = newSrc;
		imgPremio.title = newAlt;
		imgPremio.alt = newAlt;
	}

	artiPrint = resultado.descripcion;
	document.getElementById('linkPrintFicha').style.display = '';

}

function showBrowser(Layer, tipo) {
		var browser = '';
		var Select = '';

		for (var i = 0; i < categorias.length; i++) {
			if ((categorias[i].id < 980) && (categorias[i].id != 103)) {
				Select+= ' <option value="'+categorias[i].id+'">'+categorias[i].name+'</option>';
			}
		}


		globalOption = (CATEGORIA_GLOBAL != 0) ? ' <option value="'+CATEGORIA_GLOBAL+'" selected="selected">- En '+getCategoStr2(CATEGORIA_GLOBAL)+'</option>' : '';


		browser+='<form action="#" method="post" name="browser" id="browser" onsubmit="return false;">';

		/*izq*/
		browser+='<div class="left clearfix">'+
					'<div class="selectFamHolder">'+
						'<select id="where" name="where" onchange="swapSearchEngine(); return false;">'+
						globalOption +
						' <option value="0">- Todos los articulos</option>'+
						' <option value="tiendas">- Buscar tu Tienda APP</option>'+
						' <option value="0">--------------------------</option>'+
						Select +
						'</select>'+
						//'<label><input type="radio" name="where" value="0" id="search_0" checked="checked" />Artículos</label> '+
						//'<label><input type="radio" name="where" value="tiendas" id="search_1" onclick="include_tiendas();" />Tiendas</label>'+
					 '</div>'+
				 	 '<div class="searchFieldHolder"><input name="query" type="text" id="query" value="&iquest;Qu&eacute; buscas?" onfocus="this.value = \'\'; rqDb();" onkeyup="submitSearch(event, this)" /></div>'+
				 '</div>'+
				 /*derecha*/
				 '<div class="right clearfix">'+
				 	 '<div class="sortLinkHolder" id="linkEscap"><a href="#" onclick="escaparate(0, true); return false;">Escaparate Virtual</a></div>'+
					 '<div class="sortLinkHolder" id="linkSort" style="display:none;"><a href="#" onclick="showData(-1, 1, true, 21); return false;">Ordenar<br />por precio</a></div>'+
					 '<div class="sortLinkHolder" id="linkPrint" style="display:none;"><a href="#" onclick="printVisible(); return false;">Imprimir<br /> P&aacute;gina </a></div>';
		browser+= (tipo == 'ficha') ? '<div class="sortLinkHolder" id="linkPrintFicha" style="display:none;"><a href="#" onclick="printFicha(); return false;">Imprimir<br /> Ficha </a></div>' : '';
		browser+= (CATEGORIA_GLOBAL != 997) ? loadForumLink() : '';
		//browser+= loadForumLink();
		browser+= (CATEGORIA_GLOBAL == 997) ? '<div class="sortLinkHolder" id="linkOfPdf"><a href="ofertas-app.rar" target="_blank">OFERTAS<br />en PDF</a></div>': '<div class="" id="linkPdf"><a href="#" onclick="downloadPdf(); return false;"><img height="20" border="0" width="15" src="/images/blank.gif"/></a></div>';


		browser+= '</div>';
		browser+='</form>';

		document.getElementById(Layer).innerHTML = browser;


		//makeCatStr();
		//makeFooterList()

	if (tipo == 'ficha') {
			laya = document.getElementById('resultados');

			var _categoname = getCategoStr(CATEGORIA_GLOBAL).replace(/ /g, "-").toUpperCase();

			var fileName = window.location.href.split("/");
			var query = fileName[fileName.length-1].replace(/\.php/g, "").toUpperCase();

			var resultado = new Array();
			var nota = true;

				for ( var i=0; i < articulos.length; i++ ) {
				nota = true;
				_descripcion = articulos[i].descripcion.toUpperCase();
				_descripcion = _categoname + '-' + _descripcion.replace(/[\\\|\\/\:\*\?\<\>\ ]/g, '-');

					if (_descripcion == query) {
						resultado = articulos[i];
						resultados = new Array(articulos[i]);

						nota = false;
						break;
					}

				}

				if (!nota) LoadFicha(resultado)
				else {
				var imgPremio 	= document.getElementById('Premio');
					imgPremio.src = '/imf-plantilla/descatalogado.gif';
					imgPremio.title = 'ARTICULO DESCATALOGADO';
					imgPremio.alt = 'ARTICULO DESCATALOGADO';
				};

	} else if (tipo == 'tienda') {
	} else if (tipo == 'default') {
	} else if (tipo == 'encuestas') {
		myJsProgressBarHandler = new JS_BRAMUS.jsProgressBarHandler();
	} else if (tipo == 'defaultA') {
		swapSearchEngine(0);
		document.getElementById('linkEscap').style.display = 'none';
		document.getElementById(Layer).className = 'clearfix';
	} else if (tipo == 'defaultT') {
		swapSearchEngine('tiendas');
		document.getElementById(Layer).className = 'clearfix';
	} else if (tipo == 'comunicador') {
		document.getElementById('linkEscap').style.display = 'none';
		oriSearchHtml =  document.getElementById(Layer).innerHTML;
		swapSearchEngine('tiendas');
		initGmaps();
	} else if (tipo == 'comunicador2') {
		document.getElementById('linkEscap').style.display = 'none';
		oriSearchHtml =  document.getElementById(Layer).innerHTML;
		swapSearchEngine('tiendas');

	} else if (tipo == 'foro') {
		document.getElementById('linkEscap').style.display = 'none';
	} else {
		doSearch(true);
		oriSearchHtml =  document.getElementById(Layer).innerHTML;
	}



	if (document.getElementById('printResults') == null) {
		var overLayBox = 	'<div class="popup">'+
								'<table>'+
									'<tr>'+
										'<td class="tl"/>'+
										'<td class="b"/>'+
										'<td class="tr"/>'+
									'</tr>'+
									'<tr>'+
										'<td class="b"/>'+
										'<td class="body">'+
											'<div class="footer" style="display: block;">'+
												'<a id="btnPrint" class="close" onclick="downloadPdf(); return false;" href="#">Imprimir PDF</a>'+
												'<a class="close" onclick="removePrintPreview(); return false;" href="#">Cerrar</a>'+
											'</div>'+
											'<div id="contentFaceBox" class="content" style="display: block;"></div>'+
										'</td>'+
										'<td class="b"/>'+
									'</tr>'+
									'<tr>'+
										'<td class="bl"/>'+
										'<td class="b"/>'+
										'<td class="br"/>'+
									'</tr>'+
								'</table>'+
							'</div>';

		var iframe = document.createElement('iframe');
		iframe.id = 'printResults';
		iframe.name = 'printResults';
		iframe.frameBorder = 'no';
		iframe.width = '1000';
		iframe.height = '600';
		iframe.scrolling = 'auto';
		iframe.src = 'about:blank';

		var iframe2 = document.createElement('iframe');
		iframe2.id = 'dldPdf';
		iframe2.name = 'dldPdf';
		iframe2.frameBorder = 'no';
		//iframe2.style.display = 'none';
		iframe2.width = '0';
		iframe2.height = '0';
		iframe2.scrolling = 'no';
		iframe2.src = 'about:blank';

		var facebox = document.createElement('div');
		facebox.id = 'facebox';
		facebox.style.top = '50px';
		facebox.innerHTML = overLayBox;

		body = document.getElementsByTagName('body')[0];
		body.appendChild(facebox);

		document.getElementById('contentFaceBox').appendChild(iframe);
		document.getElementById('contentFaceBox').appendChild(iframe2);

		facebox.style.left = (document.body.offsetWidth / 2) - (facebox.offsetWidth / 2) + 'px';
		facebox.style.display = 'none';

	}
}


function updateCd(fs) {

	if (--cooldown == 0) {
	escaparate(1, fs);
	} else {
	document.getElementById('scap-cd').innerHTML = cooldown+'&quot;';
	updateTo = setTimeout('updateCd('+fs+');', 1000);
	}

}

function removeEscaparate() {
clearTimeout(updateTo);

var el = document.getElementById('scap_overlay_fs');
el.parentNode.removeChild(el);

var el = document.getElementById('scap_semitrp');
el.parentNode.removeChild(el);
document.getElementById('where').style.display = '';
}

function rmFsMsg(fs) {
	var el = document.getElementById('removeMe');
	el.parentNode.removeChild(el);
	if (resultados.length > 1)	updateTo = setTimeout('updateCd('+fs+');', 1000);
}

function escaparate(newIndex, fs) {
	document.getElementById('where').style.display = 'none';

	if (newIndex == 0) escaparateIndex = 0;

	if ( document.getElementById('scap_overlay_fs') == null ) {
		var body = document.getElementsByTagName('body')[0];

		var escaparateOverlay	 = document.createElement('div');
			escaparateOverlay.id = 'scap_overlay_fs';

		var escaparateTransp	= document.createElement('div');
			escaparateTransp.id	= 'scap_semitrp';

		body.appendChild(escaparateTransp);
		body.appendChild(escaparateOverlay);

	} else {
		escaparateOverlay = document.getElementById('scap_overlay_fs');
	}

		escaparateIndex = (escaparateIndex == resultados.length-1) ? 0 : escaparateIndex + (newIndex);
		escaparateIndex = (escaparateIndex < 0) ? 0 : escaparateIndex;
	var item = resultados[escaparateIndex];


	var newSrc = 'images/escaparate-precio-calidad-garantia.png';
	var newAlt = '';

	/*Pregunto si es oferta*/
	if (item.iUpDown == 3) {
		newSrc = 'images/escaparate-oferta.png';
		newAlt = 'OFERTA!!';
	}

	/*Pregunto si es nuevo y no es 4..5 estrellas*/
	if ( (item.iUpDown == 2) ) {
		newSrc = 'images/escaparate-nuevo.png';
		newAlt = 'ARTICULO NUEVO!!';
	}

	if ((item.iRank == 9) && (item.iUpDown != 3)) {
		newSrc = 'images/escaparate-topventas.png';
		newAlt = 'TOP VENTAS APP!!';
	}

	/*Pregunto si es Top1 y no es oferta*/
	var top = getTopList(articulos);
	if ( (top.descripcion == item.descripcion) && (item.iUpDown != 3) && (item.iRank != 9) ) {
		newSrc = 'images/escaparate-n1.png';
		newAlt = 'ARTICULO MAS VENDIDO!!'
	}

	if ((item.iRank == 10) && (item.iUpDown != 3)) {
		newSrc = 'images/escaparate-premiado.png';
		newAlt = 'PREMIADO APP!!';
	}

	var imgPremio = '<img src="/'+newSrc+'" title="'+newAlt+'" alt="'+newAlt+'" border="0" />';
	var img	= '/imf/'+GetURL(getCategoStr(item.cat) +' '+ item.descripcion)+'.jpg';

	var _url 	= '/'+GetURL(getCategoStr(item.cat) +' '+ item.descripcion)+'.php';
	var catUrl = '/'+GetURL(getCategoStr(item.cat))+'.htm';

	var pre = fmtMoney(item.precio, 2, ",", '.');
	var ent = pre.split(",")[0];
	var dec = pre.split(",")[1];
	var name = adjust_text(item.descripcion, 25);



	innHTML = '<div class="scap_content">';

	if (newIndex == 0)
		innHTML += '<div id="removeMe" class="fsMsgHold"><div class="fsMsg"><b>Presiona F11</b><br />&ldquo;Pantalla Completa&rdquo;</div></div>';

	innHTML += '<div class="scap-app">'+
			'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="1000" height="113">'+
					  '<param name="movie" value="/images/fs-scap-head.swf" />'+
					  '<param name="quality" value="high" />'+
					  '<param value="transparent" name="wmode"/>'+
					  '<embed src="/images/fs-scap-head.swf" wmode="transparent" quality="high" width="1000" height="113" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed>'+
			'</object>'+
			'<div class="scap-close"><a href="#" onclick="removeEscaparate(); return false;"><img src="/images/x-fs.png" border="0" /></a></div>'+
		'</div>'+

		'<div class="ad-holder clearfix">'+
			'<div id="scap-cd">20&quot;</div>'+
			'<div class="scap-pic"><div class="workaround">'+
				'<img src="'+img+'" width="649" border="0" usemap="#mapEscaparate" />'+
				'<map name="mapEscaparate">'+
				'<area shape="rect" coords="350,360,649,404" href="'+_url+'" target="_blank">'+
				'<area shape="rect" coords="0,0,649,360" href="'+_url+'" target="_blank">'+
				'<area shape="rect" coords="0,360,350,404" href="'+catUrl+'" target="_blank">'+
				'</map>'+
			'</div></div>'+
			'<div class="scap-data clearfix">'+
				'<div class="scap-top">'+imgPremio+'</div>'+
				'<div class="scap-precio">'+
					'<div class="clearfix" style="letter-spacing:-4px;">'+
						'<div class="precio">'+ent+',</div>'+
						'<div class="decimales">'+dec+'</div>'+
					'</div>'+
					'<div class="iva">IVA INCLUIDO</div>'+
				'</div>'+
			'</div>'+
		'</div>'+

		'<div class="scap-descr-holder clearfix">'+
			'<div class="scap-left"><a href="#" onclick="escaparate(-1, true); return false;"><img src="/images/scap-left.gif" border="0" /></a></div>'+
			'<div class="scap-descr"><a href="'+_url+'" target="_blank">'+name[0]+'<br />'+name[1]+'</a></div>'+
			'<div class="scap-right"><a href="#" onclick="escaparate(1, true); return false;"><img src="/images/scap-right.gif" border="0" /></a></div>'+
			'<div class="scap-fs-help">Pantalla completa pulsar F11</div>'+
		'</div>'+
	'</div>';
	escaparateOverlay.innerHTML = innHTML;

	cooldown = 20;
	clearTimeout(updateTo);
	//updateTo = setTimeout('updateCd('+fs+');', 1000);
	if (resultados.length != 1) {
		if (newIndex == 0)
		updateTo = setTimeout('rmFsMsg('+fs+');', 10000);
		else
		updateTo = setTimeout('updateCd('+fs+');', 1000);
	} else {
		document.getElementById('scap-cd').style.display = 'none';
		updateTo = setTimeout('rmFsMsg('+fs+');', 10000);
	}
}


function printVisible() {
	var img, precio, name;
	var html =	'<div class="head"><img border="0" alt="" src="images/super_precios.jpg" /></div>';
		html+=	'<div class="holder">' +
				'	<div class="row clearfix">';

	var fin = resultados.length;

	for (var i = 0; i < fin; i++) {

		img	= 'imf/'+GetURL(getCategoStr(resultados[i].cat) +' '+ resultados[i].descripcion)+'.jpg';
		pre = fmtMoney(resultados[i].precio, 2, ",", '.');
		name = adjust_text(resultados[i].descripcion.toUpperCase(), 25);


		html+='<div class="artiHolder">'+
				'<div class="image"><img border="0" alt="" src="'+img+'" /></div>'+
				'<div class="precioBg"><img border="0" alt="" src="images/fondito-rojo.gif" /></div>'+
				'<div class="precioHolder">'+
					'<div class="precio">'+pre+'</div>'+
					'<div class="iva">IVA INCLUIDO</div>'+
				'</div>'+
				'<div class="descrip">'+name[0]+'<br />'+name[1]+'</div>'+
			  '</div>';

		if ((i+1)%6 == 0) {
			html+= '</div>'+
				'</div>'+
				'<div class="foot"><img border="0" alt="" src="images/foot-app-print.jpg" /></div>'+
				'<div class="pageBreak">&nbsp;</div>'+
				'<div class="head"><img border="0" alt="" src="images/super_precios.jpg" /></div>'+
				'<div class="holder">'+
				'	<div class="row clearfix">';

		} else if (((i+1)%2 == 0) && (fin-1 != i) && (i != 0))
			html+='</div><div class="row clearfix">';
		else
			html+='<div class="spacer">&nbsp;</div>';
	}
		html+='</div></div>';
		html+='<div class="foot"><img border="0" alt="" src="images/foot-app-print.jpg" /></div>';

	var ventana = window.open('/printVisible.htm', 'ventana', 'status=0,toolbar=0,menubar=1,height=600,width=1000,scrollbars=1,resizeable=1');

	lastHtml = html;

	//ventana.document.getElementsByTagName('body')[0].innerHTML = html;
	//ventana.print();

	//window.printResults.document.getElementsByTagName('body')[0].innerHTML = html;



	//document.getElementById('facebox').style.display = '';

	//window.printResults.focus();
	//window.printResults.window.print()
	// y termino..
}

function removePrintPreview() {
	document.getElementById('facebox').style.display = 'none';
}
/*
function sendPprintPreview() {
	window.printResults.focus();
	window.printResults.window.print()
}
*/

/*function pdf(longMode) {
	longMode = longMode || false;

	var queryStr = '';

	queryStr = 'dbId='+ categoria_a_buscar + '&q=' + lastSearchQuery + '&lastSort=' + lastSort;
	document.getElementById('printResults').src = 'printPdf.php?'+queryStr;

	document.getElementById('facebox').style.display = '';
}*/

function downloadPdf() {
	var queryStr = '';

	/*Load Dialog*/

	var msg = document.createElement('div');
	msg.id = 'msgPdf';
	msg.className = 'waitDialog';
	msg.innerHTML = ''+
			'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="225" height="82">'+
					  '<param name="movie" value="images/espere.swf" />'+
					  '<param name="quality" value="high" />'+
					  '<param value="transparent" name="wmode"/>'+
					  '<embed src="images/espere.swf" wmode="transparent" quality="high" width="225" height="82" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed>'+
			'</object>';

	document.getElementsByTagName('body')[0].appendChild(msg);
	msg.style.left = (document.body.offsetWidth / 2) - (msg.offsetWidth / 2) + 'px';

	setTimeout(function() {
		el = document.getElementById('msgPdf');
		el.parentNode.removeChild(el);
	}, 5000)
	/*End Load Dialog*/

	queryStr = 'dbId='+ cat_a_pdf + '&q=' + lastSearchQuery + '&lastSort=' + lastSort;

	var fullUrl = 'http://www.appinformatica.com/printPdf.php?'+queryStr
	document.getElementById('dldPdf').src = 'http://web2pdf.freepdfconvert.com/HTMLtoPDFMaster.aspx?cURL='+escape(fullUrl)+'&author=&subj=&title=Download&app=http://www.freepdfconvert.com&keywords=&allowcpy=&allowmodif=yes&allowprn=&keylen=&userpass=&ownerpass=&preservelinks=yes&compress=flate&marginleft=&marginright=&margintop=&marginbottom=&psize=&porient=&ctype=&allowscript=no&wsize=&outputmode=stream';

	//document.getElementById('btnPrint').className = 'close loading';
	//setTimeout(function() {document.getElementById('btnPrint').className = 'close';}, 3000);
}

function printFicha() {
	var url;

	url = 'printFicha.php?dbId='+CATEGORIA_GLOBAL+'&arti='+escape(artiPrint);

	var ventana = window.open(url, 'ventana', 'status=false,toolbar=false,menubar=false,height=600,width=1000,scrollbars=1,resizeable=true');

}

function linkForumCat(catId) {
	if (catId != 0) {
		for (i = 0; i < catForumRelation.length; i++) {
				if (catForumRelation[i].catId == catId) return catForumRelation[i].forumId;
		}
	}
	return false;
}

function linkCatForum(forumId) {
	if (forumId != 0) {
		for (i = 0; i < catForumRelation.length; i++) {
				if (catForumRelation[i].forumId == forumId) return catForumRelation[i].catId;
		}
	}
	return false;
}

function loadForumLink() {
	var loc = document.location.toString();

	if(loc.indexOf('foro') != -1) {
		var regex = /(&|\?)f=([0-9]*)/m;
		var match = regex.exec(document.location);
		if (match != null && match.length > 2) {
			forumId = match[2];
		} else {
			return '';
		}

		cat = linkCatForum(forumId);

		if (!cat) return '';

		catStr = getCategoStr2(cat);

		title = catStr;
		if (catStr.length > 10) catStr = catStr.substr(0,9)+'...';

		linkLabel = 'Listado<br />'+catStr;
		catUrl = '/'+GetURL(getCategoStr(cat))+'.htm';

		return '<div class="sortLinkHolder" id="linkForum" style="/*display:none;*/"><a title="Listado '+title+'" href="'+catUrl+'">'+linkLabel+'</a></div>';
	} else {

		/*forumId = linkForumCat(CATEGORIA_GLOBAL);

		if (!forumId) return '';

		forumUrl = '/foro/forumdisplay.php?f='+forumId

		catStr = getCategoStr2(CATEGORIA_GLOBAL);

		title = catStr;
		if (catStr.length > 10) catStr = catStr.substr(0,9)+'...';

		linkLabel = 'Listado<br />'+catStr;
		catUrl = '/'+GetURL(getCategoStr(CATEGORIA_GLOBAL))+'.htm';
		*/
		linkLabel = 'Entra al<br />Foro APP';

		return '<div class="sortLinkHolder" id="linkForum" style="/*display:none;*/"><a title="Foro APP" href="/foro">'+linkLabel+'</a></div>';

	}
}

function loadDefault() {

		document.getElementById('busca').innerHTML = '<div id="buscaHome">'+
														 '<div id="buscaArticulo" onclick="showBrowser(\'busca\', \'defaultA\');">Buscar Art&iacute;culos...</div>'+
														 '<div id="queBusca"></div>'+
														 '<div id="buscaTienda" onclick="showBrowser(\'busca\', \'defaultT\');">Buscar mi Tienda APP...</div>'
													 '</div>';


}


function suscribirEmail(email) {

	new Ajax.Request('/suscribir-email.php', {
		parameters: {
			email: email
			},
		onCreate: function() {
			//onCreate Event
		},
		onComplete: function(transp) {

			if (transp.responseText == 'ok')
			$('temsAndConds').remove();
			else alert('Error al suscribir su email');

		}
	});

}