//Funci�n que calcula la fecha actual
function fecha_actual()
{
	var ahora=new Date();
	var meses=new Array("enero","febrero","marzo","abril","mayo","junio","julio",
						"agosto","septiembre","octubre","noviembre","diciembre");

	var dia=ahora.getDate();
	var mes=ahora.getMonth();
	var ano=ahora.getFullYear();

	var fecha = dia+" de "+meses[mes]+" del "+ano;
	return fecha;
}

// Valida si los datos aportados para una fecha son correctos
function validarFecha(anio, mes, dia){
	if ((mes>=1 && mes<=12) && (dia>=1 && dia<=31)){
		if (mes==2){
			if (dia==29 && (((anio%4==0) && ((anio%100!=0) || (anio%400==0))))){
				return true;
			} else if (dia<=28) {
				return true;
			}
		} else if ((mes==4 || mes==6 || mes==9 || mes==11) && dia<=30) {
			return true;
		} else {
			return true;
		}
	} 
	return false
}

// Formatea un objeto fecha a "dd/mm/yyyy hh:mm:ss"
function formatearFechaHora(fecha){
	var cadena = "";
	if (fecha!=null){
		var anio = fecha.getFullYear();
		var mes = ((fecha.getMonth()+1)<10)? "0" + (fecha.getMonth()+1) : fecha.getMonth()+1;
		var dia = (fecha.getDate()<10)? "0" + fecha.getDate() : fecha.getDate();
		var hora = (fecha.getHours()<10)? "0" + fecha.getHours() : fecha.getHours();
		var minutos = (fecha.getMinutes()<10)? "0" + fecha.getMinutes() : fecha.getMinutes();
		var segundos = (fecha.getSeconds()<10)? "0" + fecha.getSeconds() : fecha.getSeconds();
		cadena = dia+"/"+mes+"/"+anio+"&nbsp;"+hora+":"+minutos+":"+segundos;
	}
	return cadena;
}

//Formatea un objeto fecha a "hh:mm:ss"
function formatearHora(fecha){
	var cadena = "";
	if (fecha!=null){
		var hora = (fecha.getHours()<10)? "0" + fecha.getHours() : fecha.getHours();
		var minutos = (fecha.getMinutes()<10)? "0" + fecha.getMinutes() : fecha.getMinutes();
		var segundos = (fecha.getSeconds()<10)? "0" + fecha.getSeconds() : fecha.getSeconds();
		cadena = hora+":"+minutos+":"+segundos;
	}
	return cadena;
}


//Formatea un objeto fecha a "dd/mm/yyyy"
function formatearFecha(fecha){
	var cadena = "";
	if (fecha!=null){
		var anio = fecha.getFullYear();
		var mes = ((fecha.getMonth()+1)<10)? "0" + (fecha.getMonth()+1) : fecha.getMonth()+1;
		var dia = (fecha.getDate()<10)? "0" + fecha.getDate() : fecha.getDate();
		cadena = dia+"/"+mes+"/"+anio;
	}
	return cadena;
}


//Funci�n que calcula los d�as que quedan para las ferias
function countdown(yr,m,d)
{
	var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
	var codigo;
	var today=new Date();
	var todayy=today.getFullYear();
	if (todayy < 1000)
			todayy+=1900;

	var todaym=today.getMonth();
	var todayd=today.getDate();
	var todaystring=montharray[todaym]+" "+todayd+", "+todayy;
	var futurestring=montharray[m-1]+" "+d+", "+yr;
	var difference=(Math.round((Date.parse(futurestring)-Date.parse(todaystring))/(24*60*60*1000))*1);

		if (difference>0)
		{
			if (difference==1)
				eval("codigo='Solo falta 1 día para las Ferias "+yr+"';");
			else
				eval("codigo='Solo faltan "+difference+" días para las Ferias "+yr+"';");			
		}
		else
		{
			eval("codigo='¡¡ Felices FERIAS "+yr+" !!';");
		}
		
	return codigo;
}

function validarEmail(email) {
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	if (filter.test(email)){
		return true;
	} 
	return false;
}


function cuenta_atras(div, anio, mes , dia, desc, desc_fin){
	var austDay = new Date(anio, mes-1, dia);
	div.countdown({
		until: austDay,
		//format: "D",
		expiryText: desc_fin,
		alwaysExpire: true,
		layout: "Faltan {dn} {dl} {desc}",
		description: desc
	});
}

