/*
..........................................................................
:: Menus desplegables de n-niveles                                      ::
..........................................................................
*/

$(document).ready(function() { // Prepara eventos del menu
    var desplegables = $("#nav li > ul");
	desplegables.hide();
    desplegables.parent().bind("mouseenter", function() { despliega(this) });
    desplegables.parent().bind("mouseleave", function() { pliega(this)    });
});

function despliega(padre) {
    clearTimeout(padre.temporizador);
    $("#nav li > ul").parent().css({zIndex: 1});
    $(padre).css({zIndex: 1000});
	$(padre).children("UL").fadeIn(300);
}

function pliega(padre) {
    padre.temporizador = setTimeout(function() {
		$(padre).children("UL").fadeOut(300);
    }, 300)
}

/*
..........................................................................
:: Links en ventana nueva                                               ::
..........................................................................
*/
$(document).ready(function() {
	$("a[rel=external]").attr({target: "_blank"})
});

/*
..........................................................................
:: 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 );
}

/*
..........................................................................
:: Pop up generico                                                      ::
..........................................................................
*/

function pop(url, name, width, height, centered, features) {
    if(window.screen)if(centered)if(centered=="1"){
        var l = (screen.width-width)/2;
        var t = (screen.height-height)/2;
        features+=(features!='')?',':'';
        features+='left='+l+',top='+t;
    }
    var flop=window.open(url, name, features+((features!='')?',':'')+'width='+width+',height='+height);
    flop.focus();
}