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

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 explorer(){
	if ('\v'=='v'){
		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_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;
 	}	
}



