// JavaScript Document
var Busqueda = function(url,anexo){
		
	var valores = new Array();
	var arrCont = new Array();
	var blocker = null;
	var loader = null;
	var contTodo = null;
	var itemAnterior = null;
	this.init = function(){
		valores['uso'] = new Array();
		valores['color'] = new Array();
		valores['tamanio'] = new Array();
		for(i in valores){
			var tipo = oCookie.get(i+'Find'+this.anex);

			if(tipo != ''){

				var partes = tipo.substr(0,tipo.length-1).split(',');
				for(j=0;j<partes.length;j++){
					this.setBusqueda(partes[j],i);	
				}
			}
		}
		
	}
	
	this.url = url;
	this.anex = '';
	if(anexo)this.anex = anexo;
	this.file = 'file' + SEP_IGUAL + 'busqueda.php' + SEP_AND;
		
	this.setBusqueda = function(idItem,tipoItem,e){

		if(!valores[tipoItem][idItem]){
			valores[tipoItem][idItem] = idItem;
			$(tipoItem+'Find'+this.anex+idItem).className = 'On';
			if(tipoItem == 'tamanio'){
				if(itemAnterior){
					$(tipoItem+'Find'+this.anex+itemAnterior).className = '';
					delete(valores[tipoItem][itemAnterior]);	
				}
				itemAnterior = idItem;
			}
			
		}
		else{
			delete(valores[tipoItem][idItem]);	
			$(tipoItem+'Find'+this.anex+idItem).className = '';
			if(tipoItem == 'color')itemAnterior = null;
		}
		
		if(this.request){
			mostrarBlockeadorBusq(true);
			buscando();		
			req.pedir(DIR_ROOT + 'requests/cargar.php?busqueda=1', this.file);
		}
	
		if(e)StopEvent(e);
	}
	var buscando = function(){
		for(i in valores){
			var v = '';
			for(j in valores[i])v += j + ',';
			oCookie.unset(i+'Find'+this.anex);
			oCookie.set(i+'Find'+this.anex, v);
		}
	}.closure(this);
	this.buscar = function(e){
		if(e)StopEvent(e);
		buscando();
		document.location.href = this.url;	
	}
	var mostrarBlockeadorBusq = function(mostrar){
		if(!blocker){
			blocker = $('blockBusqueda');
			loader = $('loaderBusqueda');
			contTodo = $('contProductos');
			blocker.style.marginTop = '0px';
			blocker.style.marginLeft = '0px';			
		}
		if(mostrar){
			blocker.style.width = contTodo.offsetWidth-203+'px';
			blocker.style.height = contTodo.offsetHeight+'px';			
			loader.style.marginTop = Math.round((contTodo.offsetHeight-73)/2)+'px';
			loader.style.marginLeft = Math.round((contTodo.offsetWidth-250)/2)+'px';			
			blocker.style.display = 'block';
			loader.style.display = 'block';
			
		}
		else{
			blocker.style.display = 'none';	
			loader.style.display = 'none';
		}
	}
	var onRequestLoad = function(){
		var d = req.respuestaXML;
		if(!d){
			mostrarBlockeadorBusq();			
			return false;
		}
		$('contProductos').innerHTML = (Nav.esIE)? d.firstChild.text : d.firstChild.textContent;
		mostrarBlockeadorBusq();
		
	}
	var req = new Request(onRequestLoad);
	this.init();
}