function basename (path, suffix) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Ash Searle (http://hexmen.com/blog/)
    // +   improved by: Lincoln Ramsay
    // +   improved by: djmix
    // *     example 1: basename('/www/site/home.htm', '.htm');
    // *     returns 1: 'home'
    // *     example 2: basename('ecra.php?p=1');
    // *     returns 2: 'ecra.php?p=1'

    var b = path.replace(/^.*[\/\\]/g, '');
    
    if (typeof(suffix) == 'string' && b.substr(b.length-suffix.length) == suffix) {
        b = b.substr(0, b.length-suffix.length);
    }
    
    return b;
}

function actualizar(elt) {
    $('.loading').hide().after(
        '<img src="/static/loading.gif" ' +
          'class="loading_animation" />');
    var data = {};
    elt.parents('form').find('input[type=hidden]')
    .each(function () {
        data[this.id] = $(this).val();
    });
    $('#extras input').each(function () {
        if ($(this).attr('checked'))
            data[this.id] = 1;
    });
    $('#extras select').each(function () {
        data[this.id] = $(this).val();
    });
    $.post('http://www.alquilercochesmenorca.com/en/', data, function (data) {
        data = data.sub(/^.*<body>/, '').sub(/<\/body>.*$/, '');
        $('#precio_extras span').text(
            $(data).find('#precio_extras span').text());
        $('#precio_final_valor span').text(
            $(data).find('#precio_final_valor span').text());
        $('#botones_pago').html(
            $(data).find('#botones_pago').html());
         $('.loading').show();
         $('.loading_animation').detach();
    });
}
 
$(document).ready(function(){
    /*COLORBOX*/
	$('a[rel=individual]').colorbox({rel:'nofollow', close:"Exit"});
	$("a[rel=lightbox]").colorbox({width:700, close:"Exit"});
	$(".html_lightbox").colorbox({iframe:true, innerWidth:760, innerHeight:500, close:"Exit"});

    $('#fecha_nacimiento').mask('99/99/9999');
    $('#extras input, #extras select').change(function () {
        if ($(this).parents('.seguro').size() == 1) {
            var cb = this;
            $('.seguro').find('input').each(function () {
                if (cb != this)
                    $(this).removeAttr('checked')
            });
        }
        actualizar($(this));
    }).each(function () {
        if ($(this).val() != '0') {
            actualizar($(this));
            return false;
        }
    });
    $('form span.error').each(function () {
        var x = $(this).parent().find('input');
        if (x.attr('id') == 'sin_seguro')
            $('.seguro').wrap('<span class="revisar" />');
        else
            x.wrap('<span class="revisar" />');
    });
    $('.seguro input').change(function () {
        $('.seguro').parents('.revisar').removeClass('revisar');
        $('.seguro').closest('td').find('.error').detach();
    });
});

