//obtiene longitud de la base de datos
var longitud = BaseDatos.length

function IniciaBuscador(clave) {
	
	//obtiene valor de select
	palabraClave=clave.value;
	var desde = 0
	var partes
	var CadenasEntrada
	var descripcion = ''
	var lugares = ''
	
	//detiene busqueda si palabra clave vacia
	if ( palabraClave == "" ) {
		alert("¡Introduzca cadena de búsqueda!")
		return
	}
		
	//busca entrada de pagina que contenga la clave
	//recorre el array en busca de la palabra clave ( nombre del evento)
	for (var i = 0; i < longitud; i++)
	{
	
		if ( BaseDatos[i][0].search(palabraClave) != -1 ) 
		{
			//ancho del arrreglo las ciudades
			largo = BaseDatos[i].length
			
			//eliminacion de los options del select
			eliminarOpcion()
			
			//creacion de la lista de los eventos
			for (var j = 1; j < largo; j++) 		
			{
				lugares=BaseDatos[i][j];
				adicionarOpcion(lugares)
				
			}
			
			//activa la lista con las ciudades de ese evento
			document.getElementById("ciudad").disabled=false;
		}
		
	}
}

function MuestraEvento()
{
	pagina= '<label style="color: #A70303; font-size: 15px; font-family:arial, verdana, sans-serif;">Seleccione el Artista / Evento:</label>';
	pagina+='<div style="margin-top: 7px;">';
	pagina+= '<select style="width: 300px; height:28px; color: #A70303; border-left: ridge 2px #606060;	border-right: ridge 2px #505050; border-top: ridge 2px #808080; border-bottom: ridge 2px #404040; background: url(http://nuestroticket.com/images/tfbg2.gif) repeat-x; padding-top: 4px; padding-left: 7px;" id="evento"; onchange="IniciaBuscador(this)">';
	pagina+= '<option value="s1">- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - </option>';
	
	for (var i = 0; i < longitud; i++)
	{
		evento= BaseDatos[i][0];
		pagina+= '<option value="'+evento+'">'+evento+'</option>';
	}
	pagina+='</select>';
	pagina+='</div>';
	pagina+='<br/>';
	pagina+= '<label style="color: #A70303; font-size: 15px; font-family:arial, verdana, sans-serif;">Seleccione la Ciudad:</label>';
	pagina+='<br/>';
	pagina+= '<select style="width: 150px; height:28px;  color: #A70303; font-size: 15px; padding-top: 3px; padding-left: 7px; margin-top: 7px; border-left: ridge 2px #606060; border-right: ridge 2px #505050; border-top: ridge 2px #808080; border-bottom: ridge 2px #404040; background: url(http://www.nuestroticket.com/images/tfbg2.gif) repeat-x;" id="ciudad" disabled="disabled">';
	pagina+= '<option  value="ciudad">- - - - - - - - - - - - -</option>';
	pagina+='</select>';

	document.write(pagina);

}

function eliminarOpcion()
{
  var selec = document.getElementById('ciudad');
  var i;
  for (i = selec.length - 1; i>=0; i--) 
  {
   selec.remove(i);    
  }

}

function adicionarOpcion(city)
{
  var nameCity=city.split(',');
  var optionNew = document.createElement('option');
  optionNew.text = city;
  optionNew.value = nameCity[0];
  var selet = document.getElementById('ciudad');

  try {
    selet.add(optionNew, null); // standards compliant; doesn't work in IE
  }
  catch(ex) {
    selet.add(optionNew); // IE only
  }
}

function Buscar() 
{
	var kwds = document.getElementById('evento').value;
	var city = document.getElementById('ciudad').value;
	if (kwds == ""||kwds=="s1") return;
	
	window.location = "ResultsGeneral.aspx?stype=0&kwds=" + escape(kwds)+"&city="+escape(city); 
}





	
