
/*
.......................
:: Gestor de eventos ::
.......................
*/
function eventAssign(obj,event,func){
	if( obj.addEventListener ) {
		obj.addEventListener(event,func,false);
	}else if (obj.attachEvent) {
		obj['e'+event+func]=func;
		obj[event+func]=function(){
		    obj['e'+event+func]( window.event );
		}
		obj.attachEvent('on'+event,obj[event+func]);
	}else {
		alert('Este navegador no es soportado!!');
	}
}

/*
.............
:: Cookies ::
.............
*/
function saveCookie(cookieName,cookieValue,nDays) {
    var today = new Date();
    var expire = new Date();
    if (nDays==null || nDays==0) nDays=1;
    expire.setTime(today.getTime() + 3600000*24*nDays);
    document.cookie = cookieName + "=" + escape(cookieValue) + ";expires="+expire.toGMTString();
}

/*
............................
:: Comprobar email válido ::
............................
*/
function validarEmail(sTesteo) {
    var reEmail = /^(?:\w+\.?)*\w+@(?:\w+\.)+\w+$/;
    return reEmail.test(sTesteo);
}

/*
........................
:: Animacion de capas ::
...................................
:: Para usar con transiciones.js ::
...................................

*/

function animacion(objeto, propiedad, puntoPartida, puntoFinal) { // Requiere el uso de la librería prototype.js!!!
    var avance = 1; // Inicializa la animación (no cambiar)
    var pasos = 20; // Número de pasos de la animación
    var intervalo = 0.05; // Segundos de retraso entre un paso y otro de la animación
    var distancia = puntoFinal - puntoPartida;
    new PeriodicalExecuter(function(periodica) {
        var pos = Math.easeInOutQuint(avance, puntoPartida, distancia, pasos) + "px";
        objeto.style[propiedad] = pos;
        avance++;
        if (avance > pasos) {
            periodica.stop();
        }
    }, intervalo);
}