

function doValidationForm(formElementId)
{
    var url = '/async/validateform'
    var data = {};
   

    $("#reservaForm input:text").each(function()
    {
        if ($(this).attr('type')!="file")
        {
            data[$(this).attr('name')] = $(this).val();
        }
    });

    $("#reservaForm textarea").each(function()
    {
        data[$(this).attr('name')] = $(this).val();
    });

    $("#reservaForm input:checkbox").each(function()
    {
        var id = $(this).attr('id');
        data[$(this).attr('name')] = $(this).val();
        $("#"+id).parent().find('.errors').remove();
    });
    
    $("#reservaForm input:hidden").each(function()
    {
        data[$(this).attr('name')] = $(this).val();
    });


    

           
    $.post(url,data,function(resp)
    {
        var errors=0;

        
        
        if (formElementId == undefined)
        {
            if (!$('input[name=condiciones]').is(':checked'))
            {
                $("#condiciones").parent().append(getErrorHtml(["Debes aceptar las condiciones"], "condiciones"));
                errors+=1;
            }

            for(respKey in resp)
            {
                $("#reservaForm #"+respKey).parent().find('.errors').remove();
                $('#reservaForm #'+respKey).before(getErrorHtml(resp[respKey], respKey));
                errors+=1;
            }
        }
        else
        {
            $("#reservaForm #"+formElementId).parent().find('.errors').remove();
            $('#reservaForm #'+formElementId).before(getErrorHtml(resp[formElementId], formElementId));
             errors+=1;
        }

        if (errors==0) $("#reservaForm").submit();

    },'json');

    

}



function getErrorHtml(formErrors,id)
{
    var errors=0;
    var o = '<ul id="errors-'+id+'" class="errors">';
    for(errorKey in formErrors)
    {
        if (formErrors[errorKey]!="")
            errors+=1;
        
        o += '<li>' + formErrors[errorKey] + '</li>';
        
    }
    o += '</ul>';

    if (errors==0)
        return "";
    else
        return o;
}
