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

function centrar(obj){
	var ancho_total = $(document).width();
	var alto_total = $(document).height();
	var ancho = obj.attr("width");
	var xpos = (ancho_total-ancho)/2;
	
	obj.parent().parent().css({width:ancho_total+"px",height:alto_total+"px"});
	obj.parent().css({left:xpos+"px",top:"100px"});
	obj.parent().parent().fadeIn(500);	
}

function montar_parrafos(){
	var alt_total =  0;
	var alt_curso = $(".col_info_curso").height() + 30;
	//if (safari()){
		alt_curso += 214;
	//}
	$(".parrafo").each(function(){
		var alt = $(this).height();
		alt_total += alt;
		if(alt_total > alt_curso){
			$(this).remove();
			$(".col_texto_der").append($(this).html());			
		}		
	});
	$(".col_texto_der").append($(".enlaces_Wrapper"));
 
}

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 = $("body").width();
	var ancho_contenido = $(".contenido").width();
	var xpos = $(".contenido").css("left").replace("px","");
	
	if(xpos > (ancho_mascara - ancho_contenido) && ancho_contenido > ancho_mascara){
		$(".contenido").animate({left:"-="+vel+"px"},0);
		$("#flecha_izq").show();
	} else {
		var tope = ancho_mascara - ancho_contenido;
		$(".contenido").css({left:tope+"px"});
		$("#flecha_der").hide();
	}		
}

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

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

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;
 	}	
}



