// JavaScript Document
var oFilterSocial = new function(){

	//C
	var cuandoTerminoOcultarFotografos = function(){
		if(ocultarInput){
			$('campoSelFotografo').style.display = 'none';
			$('contFotografoSeleccionado').parentNode.style.display = 'block';
			ocultarInput = false;
		}
		
		Blocker.hide();	
	}
	var cuandoTerminoMostrarFotografos = function(){
		
		Blocker.show();	
	}
	
	this.filtrar = function(){
		var i;
		var ArrTemp = new Array();
		ArrTemp['categorias'] = '';
		for(i in CATEGORIAS_SELECCIONADAS){
			ArrTemp['categorias'] += i + ',';
		}
		if(ArrTemp['categorias'] != '')ArrTemp['categorias'] = ArrTemp['categorias'].substr(0,ArrTemp['categorias'].length-1);
		ArrTemp['fotografo'] = ID_FOTOGRAFO_SELECCIONADO;
		if(trim($('fechaFiltro').innerHTML.toLowerCase()) != 'seleccionar fecha')ArrTemp['fecha'] = trim($('fechaFiltro').innerHTML);
		else ArrTemp['fecha'] = '';
		
		Cookie.set('filtroSociales',serialize(ArrTemp));
		if(URL_REDIRECCIONAR != ''){
			document.location = URL_REDIRECCIONAR;	
		}
		
	}

	//I
	this.iniciar = function(url){
		
		
		URL_REDIRECCIONAR = url;//SE UTILIZA PARA INDICAR SI DEBO IR A LA LISTA DE GALERIAS O SOLO USAR EL REQUEST PARA RECARGAR.
		iniciado = true;
		oZoom = new ZoomElement();		
		var val = Cookie.get('filtroSociales');
		if(val){
			var i;
			var serial = unserialize(val);
			if(serial['categorias'] && serial['categorias'] != ''){
				var partCat = serial['categorias'].split(',');
				for(i=0;i<partCat.length;i++){
					oFilterSocial.setCategoria($('filterSocialCategoria' + partCat[i]),partCat[i]);
				}
			}
			if(serial['fecha'] && serial['fecha'] != ''){
				$('fechaFiltro').innerHTML = serial['fecha'];
				$('btnQuitarFecha').style.display = '';
			}
			ID_FOTOGRAFO_SELECCIONADO = serial['fotografo'];
			if(serial['fotografo'] > 0){
				$('btnQuitarFotografo').style.display = 'block';
				ID_FOTOGRAFO_SELECCIONADO = serial['fotografo'];
				$('campoSelFotografo').style.display = 'none';
				$('contFotografoSeleccionado').parentNode.style.display = 'block';
			}
		}
		AddEvent($('cerrarPopFotografo'),'click',ocultarFotografos);
		A_TCALDEF.funcionSeleccionar = seleccionarFecha;
	}
	var seleccionarFecha = function(){
		if($('fechaFiltro').innerHTML != 'Seleccionar fecha'){
			$('btnQuitarFecha').style.display = '';
		}
		else{
			$('btnQuitarFecha').style.display = 'none';
		}
	}
		
	//L
	this.limpiarCalendario = function(){
		$('fechaFiltro').innerHTML = 'Seleccionar fecha';	
		$('btnQuitarFecha').style.display = 'none';
	}
	this.limpiarFotografos = function(){
		$('campoSelFotografo').style.display = 'block';
		$('contFotografoSeleccionado').parentNode.style.display = 'none';
		$('contFotografoSeleccionado').innerHTML = '';
		ID_FOTOGRAFO_SELECCIONADO = 0;
		$('btnQuitarFotografo').style.display = 'none';
	}
	
	var listener = function(){
		var d = req.respuestaXML;
		if(d){

			if(accion == 'devolverFotografos'){
				$('contFotografoSociales').innerHTML = d.firstChild.data;
				FOTOGRAFOS_SETEADOS = true;
				this.mostrarFotografos();
			}
		}
		else{
			alert(req.respuestaHTML);	
		}
		Loader.hide();
		
		
	}.closure(this);
	
	this.mostrarFotografos = function(objDesde){
		if(!FOTOGRAFOS_SETEADOS){
			Blocker.show();
			Loader.show();
			accion = 'devolverFotografos';
			req.pedir(DIR_ROOT + 'requests/devolver_fotografos_sociales.php','objeto' + SEP_IGUAL + 'oFilterSocial' + SEP_AND);
		}
		else{
			if(trim($('contFotografoSeleccionado').innerHTML) != ''){
				var obj = $('contFotografoSeleccionado');
			}
			else{
				var obj = $('campoSelFotografo');
			}
			oZoom.zoomElement(obj, $('layFotografo'), cuandoTerminoMostrarFotografos, cuandoTerminoOcultarFotografos, false);	
		}
	}
	
	
	//O
	var ocultarFotografos = function(){
		oZoom.zoomElementOut();	
	}
	
	//Q
	this.quitarFiltros = function(e,linkRed){
		StopEvent(e);
		var ArrTemp = new Array();
		ArrTemp['categorias'] = '';
		ArrTemp['fotografo'] = 0;
		ArrTemp['fecha'] = '';		
		
		Cookie.set('filtroSociales',serialize(ArrTemp));
		if(linkRed != ''){
			document.location = linkRed;	
		}
	}
	
	//S
	this.setCategoria = function(a,idCategoria,e){
		if(!iniciado)return false;
		if(CATEGORIAS_SELECCIONADAS[idCategoria]){
			a.className = a.className.replace('On','');
			delete(CATEGORIAS_SELECCIONADAS[idCategoria]);
		}
		else{
			a.className = a.className + 'On';
			CATEGORIAS_SELECCIONADAS[idCategoria] = true;
		}
		if(e)StopEvent(e);
	}
	this.seleccionarFotografo = function(idFotografo,cuadro){
		ID_FOTOGRAFO_SELECCIONADO = idFotografo;
		$('contFotografoSeleccionado').innerHTML = cuadro.innerHTML;
		$('btnQuitarFotografo').style.display = 'block';
		ocultarInput = true;
		ocultarFotografos();
	}
	
	var CATEGORIAS_SELECCIONADAS = new Array();
	var ID_FOTOGRAFO_SELECCIONADO = 0;
	var iniciado = false;
	var accion = '';
	var input 
	var req = new Request(listener);	
	var oZoom;
	var FOTOGRAFOS_SETEADOS = false;
	var ocultarInput = false;
	var URL_REDIRECCIONAR = '';
}