/*
..........................................................................
:: Menus desplegables de n-niveles                                      ::
..........................................................................
*/
function despliega(padre) {
    clearTimeout(padre.temporizador);
    $("#nav li > ul").parent().css({zIndex: 1});
    $(padre).css({zIndex: 1000});
    $(padre).children("UL").show(300);
}

function pliega(padre) {
    padre.temporizador = setTimeout(function() {
        $(padre).children("UL").hide(300);
    }, 400)
}


$(document).ready(function() { // Prepara eventos del menu
    var desplegables = $("#nav li > ul");
    desplegables.parent().bind("mouseenter", function() { clearTimeout(this.temporizador); });
    desplegables.parent().bind("mouseleave", function() { pliega(this)      });
    desplegables.parent().bind("click",      function() { despliega(this)   });
});

/*
..........................................................................
:: Links en ventana nueva o pop-up                                               ::
..........................................................................
*/
$(document).ready(function() {
	$("a[rel=external]").attr({target: "_blank"});
	$("a[rel=popup]").bind("click", function() {
		window.open(this.href, "popup", "width=350, height=450, resizable=1, scrollbars=1");
		return false;
	});
});

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

/*
..........................................................................
:: Validar fecha                                                        ::
:: Formato correcto: dd/mm/aaaa                                         ::
..........................................................................
*/
function validarFecha( sFecha ) {
    var reFecha = /\b(0?[1-9]|[12][0-9]|3[01])\/([1-9]|0[1-9]|1[0-2])\/(19|20\d{2})/;
    return reFecha.test( sFecha );
}