// Aplica los filtros activos
function aplicar_filtros(categorias,espacios){
	var cat = categorias.split(",");
	var esp = espacios.split(",");
	var i = 0;
	for(i=0;i<cat.length;i++){
			
	}
}

// Devuelve una cadena de ids separadas por comas de los eventos visibles en ese momento
function eventos(){
	var ids = "";
	$(".evento:visible").each(function(){
		ids += $(this).attr("id")+",";
	});
	var l = ids.length;
	ids = ids.substring(0,l - 1);
	return ids;
}
// Devuelve una cadena de ids separadas por comas de los filtros de eventos activos
function categorias(){
	var ids = "";
	$(".lista_filtros_eventos_categorias li").each(function(){
		if($(this).attr("class") == "filtro_on"){
			ids += $(this).attr("id")+",";
		}
	});
	var l = ids.length;
	ids = ids.substring(0,l - 1);
	return ids;
}
// Devuelve una cadena de ids separadas por comas de los filtros de espacios
function espacios(){
	var ids = "";
	$(".lista_filtros_eventos_espacios li").each(function(){
		if($(this).attr("class") == "filtro_on"){
			ids += $(this).attr("id")+",";
		}
	});
	var l = ids.length;
	ids = ids.substring(0,l - 1);
	return ids;
}


function strpos (haystack, needle, offset) {
  var i = (haystack+'').indexOf(needle, (offset || 0));
  return i === -1 ? false : i;
}

function isset(variable_name) {
	try {
		if (typeof(eval(variable_name)) != 'undefined')
    	if (eval(variable_name) != null)
    	return true;
    } catch(e) { }
	return false;
}

function replaceAll(find, replace, str) {
  return str.replace(new RegExp(find, 'g'), replace);
}

function explorer(){
	if ('\v'=='v'){
		return true;		
	} else {
		return false;	
	}
}

function esPc(){
	if(navigator.appVersion.indexOf('Win') != -1){
		return true;
	} else {
		return false;	
	}
}

function detectarNavegador(){
	var navegador = "Otro";

	if(navigator.appVersion.indexOf('Win') != -1){
		navegador = 'Windows';
	}else if(navigator.appVersion.indexOf('Linux') != -1){
		navegador = 'Linux';
	}else if(navigator.appVersion.indexOf('Mac') != -1){
		navegador = 'Macintosh';
	}
	return navegador;	
}

function safari(){
   var is_safari = navigator.userAgent.toLowerCase().indexOf('safari/') > -1;  
   if (is_safari ) return true;  	
}

function iPhoneCheck() {
	var agent = navigator.userAgent.toLowerCase();
	var iphone = (agent.indexOf('iphone')!=-1);
	if (iphone) {
		return true;
	} else {
		return false;
	}
}     
		
//###################################//
function mover_izq(vel){
	var ancho_mascara = $("#thumbnails_Wrapper").width();
	var ancho_contenido = $("#thumbs").width();
	var xpos = $("#thumbs").css("left").replace("px","");
	if(ancho_contenido > ancho_mascara){
		if(xpos > (ancho_mascara - ancho_contenido)){
			$("#thumbs").animate({left:"-="+vel+"px"},0);
			$(".b_flecha_izq_th").show();
		} else {
			var tope = ancho_mascara - ancho_contenido;
			$("#thumbs").css({left:tope+"px"});
			$(".b_flecha_der_th").hide();
		}
	}
}

function mover_der(vel){
	var xpos = $("#thumbs").css("left").replace("px","");
	var ancho_mascara = $("#thumbnails_Wrapper").width();
	var ancho_contenido = $("#thumbs").width();
	
	if(xpos < 0 && ancho_contenido > ancho_mascara){
		$("#thumbs").animate({left:"+="+vel+"px"},0);
		$(".b_flecha_der_th").show();
	} else {
		$("#thumbs").css({left:"0px"});
		$(".b_flecha_izq_th").hide();
	}	
}

function mover_izq_boton(){
	var ancho_mascara = $("#thumbnails_Wrapper").width();
	var ancho_contenido = $("#thumbs").width();
	var xpos = parseInt($("#thumbs").css("left").replace("px",""));
	var tope = ancho_mascara - ancho_contenido;
	
	if(ancho_contenido > ancho_mascara){
		var dif = (ancho_contenido-ancho_mascara)+xpos;
		//alert("xpos:"+xpos+"\nancho_contenido:"+ancho_contenido+"\nancho_mascara:"+ancho_mascara+"\ndif:"+dif);
		//alert(dif+"->"+ancho_mascara);
			
		if(dif < ancho_mascara){
			var desp = dif;
		} else {
			var desp = ancho_mascara;
		}
		
		$("#thumbs").animate({left:"-="+desp+"px"},500,function(){
			xpos = $(this).css("left").replace("px","");
			if(xpos <= tope){
				$(".b_flecha_der_th").hide();
			}
		});
		$(".b_flecha_izq_th").show();
	}
	
}

function mover_der_boton(){
	var xpos = $("#thumbs").css("left").replace("px","");
	var ancho_mascara = $("#thumbnails_Wrapper").width();
	var ancho_contenido = $("#thumbs").width();
	
	if(xpos < 0 && ancho_contenido > ancho_mascara){
		var dif = -xpos;
		
		//alert("xpos:"+xpos+"\nancho_contenido:"+ancho_contenido+"\nancho_mascara:"+ancho_mascara+"\ndif:"+dif);
		
		if(dif < ancho_mascara){
			var desp = dif;
		} else {
			var desp = ancho_mascara;
		}
		
		$("#thumbs").animate({left:"+="+desp+"px"},500,function(){
			xpos = $(this).css("left").replace("px","");
			if(xpos == 0){
				$(".b_flecha_izq_th").hide();
			}	
		});
		
		$(".b_flecha_der_th").show();
	} 
}


//###################################//

function encripta2(){

	usu = document.getElementById('login').value;
	hash = hex_md5(document.getElementById('password').value);	
	url = document.getElementById('url').value;
	document.location = "valida.php?u="+usu+"&p="+hash+"&url="+url;

}

function encripta(myfield,e){
	
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;

	if (keycode == 13 || keycode == 32)	{
		usu = document.getElementById('login').value;
		hash = hex_md5(document.getElementById('password').value);	
		url = document.getElementById('url').value;
		document.location = "valida.php?u="+usu+"&p="+hash+"&url="+url;
	}
}

function hoy(dia,mes,anio){
	var ahora = new Date();
	var d = ahora.getDate();
	var m = ahora.getMonth() + 1;
	
	if(d < 10){
		d = "0"+d;	
	}
	
	if(m < 10){
		m = "0"+m;	
	}
	
	$("#"+dia).attr("value",d);
	$("#"+mes).attr("value",m);
	$("#"+anio).attr("value",ahora.getFullYear());
	
}

function ayer(dia,mes,anio){
	var d = $("#dia_ayer").attr("value");
	var m = $("#mes_ayer").attr("value");
	var a = $("#anio_ayer").attr("value");
	
	$("#"+dia).attr("value",d);
	$("#"+mes).attr("value",m);
	$("#"+anio).attr("value",a);
	
}

function esBisiesto(anio) {
	var BISIESTO;
	if(parseInt(anio)%4==0){
		if(parseInt(anio)%100==0){
			if(parseInt(anio)%400==0){
				BISIESTO=true;
			} else {
				BISIESTO=false;
			}
		} else {
			BISIESTO=true;
		}
	} else BISIESTO=false;
	return BISIESTO;
} 

function validar_anio(anio){
	if(esEntero(anio)){
		if(anio < 1998){
			return false;
		} else {
			return true;
		}
	} else {
		return false;	
	}
}

function validar_fecha(dia,mes,anio){

	if (esEntero(anio) && esEntero(mes) && esEntero(dia)){
		if(dia < 1 || dia > 31){
			return false;	
		} else if(mes < 1 || mes > 12){
			return false;	
		} else if(anio < 1000){ 
			return false;
		} else {
			if(mes == 02){
				if(dia > 29){
					return false;
				} else if(!esBisiesto(anio) && dia == 29){
					return false;
				} else {
					return true;	
				}
			} else {
				return true;	
			} 
		}
	} else return false; 
}

function esEntero(valor){
	if(!isNaN(valor)){

		for(var i = 0; i<valor.length;i++){
			if(valor.charCodeAt(i)<48 || valor.charCodeAt(i)>57)
			return false;
		}
    }else{
		return false;
    }
    return true;
}       

function validar_duracion(m,s) {
	if(m < 0){
		return false;
 	} else if(s < 0 || s > 60){
 		return false;
 	} else {
 		return true;
 	}	
}

function validar_hora(h,m) {
	if(h < 0 || h > 23){
		return false;
 	} else if(m < 0 || m > 59){
 		return false;
 	} else {
 		return true;
 	}	
}



