$(document).ready(function(){

$("#mx_simplemail_main input, #mx_simplemail_main textarea").focus(function(){
    $(this).parent().addClass('focus');
}).blur(function(){
    $(this).parent().removeClass('focus');
});


$("#arrival_date").datepicker({ dateFormat: 'yy-mm-dd' });
$("#departure_date").datepicker({ dateFormat: 'yy-mm-dd' });

/* Hide / Show */

if ($('div.to-hide').length) {
    $('div.to-hide').hide();
}

if ($('a#hide-to-hide').length) {
    $('a#hide-to-hide').hide();
}


$('a#show-to-hide').click(function(){
    $('.to-hide').show();
    $('a#hide-to-hide').show();
    $('a#show-to-hide').hide();
});

$('a#hide-to-hide').click(function(){
    $('.to-hide').hide();
    $('a#hide-to-hide').hide();
    $('a#show-to-hide').show();
});


$(".chk-line *").focus(function(){
    $(this).parent().addClass('focus');
}).blur(function(){
    $(this).parent().removeClass('focus');
});


jQuery.fn.update_bg = function(){
    if ($(".chk-line input").length) {
        $(".chk-line input").parent().removeClass('checked');
        $(".chk-line input:checked").parent().addClass('checked');
    }
}

$(".chk-line input").change(function(){
    $(".chk-line input").parent().removeClass('checked');
    $(".chk-line input:checked").parent().addClass('checked');
});

$('a#select_all').click(function(){
    $('.chk-line input').attr('checked', 'checked');
    $().update_bg()
});

$('a#deselect_all').click(function(){
    $('.chk-line input').removeAttr('checked');
    $().update_bg()
});

$().update_bg()

if ($(".mxclass_accomodation.mxattr_accomodation_type").length > 1)
{
$(".mxclass_accomodation:first").each(function(){
    values = new Array();
    input_list = new String();
    $("input[@name='accomodation[]']").each(function(){
        values.push($(this).val());
        input_list += '<input type="hidden" name="accomodation[]" value="' + $(this).val() + '"/>';
   });
   $(this).before(
       '<form class="requestall before" enctype="application/x-www-form-urlencoded" method="post" action="/it/mx_simplemail/compose">'+
       input_list +
       '<input type="Submit" value="Richiedi Informazioni a tutte le Strutture" />'+
       '</form>');
});
$(".mxclass_accomodation:last").each(function(){
    values = new Array();
    input_list = new String();
    $("input[@name='accomodation[]']").each(function(){
        values.push($(this).val());
        input_list += '<input type="hidden" name="accomodation[]" value="' + $(this).val() + '"/>';
   });
   $(this).parent().parent().after(
       '<form class="requestall after" enctype="application/x-www-form-urlencoded" method="post" action="/it/mx_simplemail/compose">'+
       input_list +
       '<input type="Submit" value="Richiedi Informazioni a tutte le Strutture" />'+
       '</form>');
});
}

$('.place_single_form').each(function(){
    var value = $(this).parent().find("input[@name='accomodation[]']").val();
    $(this).append(
      '<form enctype="application/x-www-form-urlencoded" method="post" action="/it/mx_simplemail/compose">' + '<input type="hidden" name="accomodation[]" value="' + value + '" />' + ' <input type="submit" value="Richiedi Informazioni" />' + '</form>');
});


$('div.submit').append('<input type="hidden" value="nagh7laiG4pheeghei6Ieweadoehaaw6" name="chance" />')


});
