function EnviarFormReservas(){
    if(Validate('#frm_reservas')){
        BtnDesactivator(true);
        _divfomulario = jQuery(".contenedor_formulario_reservas");
        _divfomulario.hide();
        $("#ajax_loader").show();
        jQuery("#frm_reservas").ajaxSubmit({
            dataType:'json',
            target: "#result",
            success: function(resp) {
                $("#ajax_loader").hide();
                _divresultado = jQuery("#resultado_envio_reservas");
                if (resp.envio == 'ok' ){
                    _divresultado.html("Se ha enviado correctamente su solicitud. <a style='color:#FFF' href='javascript:ReservasVolver();'>Volver</a>");
                    _divresultado.addClass("validator_message_ok");
                    _divresultado.show();
                }
                if (resp.envio == 'error'){
                    _divresultado.html("Se ha producido un error inesperado. Por favor, vuelva a intentarlo más tarde. <a style='color:#FFF' href='javascript:ReservasVolver();'>Volver</a>");
                    _divresultado.addClass("validator_message_error");
                    _divresultado.show();
                }
                if (resp.envio == 'invalidcaptcha' ){
                    _divresultado.html("El código ingresado para la imagen no corresponde, por favor, vuelva a ingresarlo.");
                    jQuery(".contenedor_formulario_reservas").show();
                    _divresultado.addClass("validator_message_error");
                    _divresultado.show();
                    $('.validator_container').hide();
                }
                BtnDesactivator(false);
            }
        });
    }
}

function BtnDesactivator(_state){
    if(_state){
        $("#btn_enviar").attr("disabled",true);
    }
    else{
        $("#btn_enviar").attr("disabled",false);
    }
}

function ReservasVolver(){
    jQuery("#boton_reset").click();
    jQuery("#boton_volver").hide();
    jQuery("#resultado_envio_reservas").hide();
    jQuery('.validator_container').hide();
    jQuery(".contenedor_formulario_reservas").show();
}
function GetEntityType(){
    var $habitaciones = $("#habitaciones")
    var aux = $habitaciones.val().split('|');
    var entitytype = {id:aux[0],
                            capacidad:aux[1],
                            name:$habitaciones[0].options[$habitaciones[0].selectedIndex].text
                        }
    
    return entitytype;    
}
function SetEntityType(){
    $("#entitytype_name").val(GetEntityType().name);
    $("#entitytype_id").val(GetEntityType().id);
}
function SetPersonas(total){
    var $personas = $("#personas");    
    $personas.removeOption(/./);
    for(i=1;i<=total;i++){    
        $personas.addOption(i,i);
    }
    $personas.val(1);
}
/*$(document).ready(function(){
    SetPersonas(GetEntityType().capacidad);
    SetEntityType();
    $("#habitaciones").change(function(){        
        SetPersonas(GetEntityType().capacidad);
        SetEntityType();
    });

});*/

