$(document).ready(function() {
    // Init Data for page
    Whl.Site.initPage();
    // 
    Whl.getMore();
    // Accm By Region/Type
    Whl.tab('accm-tab', 'active');
    
    new Whl.Accm.Rate(accmUrl);
    // VIew special offer detail
    $('.so-detail').tooltip({prefixCont: 'so-detail'});
    // View Food arrangement
    $('.food-arrangement').tooltip({title: Message.food});
    // Room detail
    //$('.room-detail').tooltip({prefixCont: 'room-detail', width: 450});
    $('.room-detail').click(function(){
        var dlgButtons = {};
        var id = this.id.split('-');
        dlgButtons[Message.Dlg.close] = function(){
            $(this).dialog('close');
        };
        $('#room-detail-'+id[1]+'-'+id[2]).dialog('destroy').dialog({
            title: $('#'+id.join('-')).attr('title'),
            bgiframe: true, autoOpen: false,
            width: 480, height:'auto',
            modal:true, resizable:false,
            buttons: dlgButtons
        }).dialog('open');
        arguments[0].preventDefault();
    });
    // Applied SO
    $('.applied-so').tooltip({prefixCont: 'roomso-detail', positionLeft: true});
    
    $('#book').click(function(event) {
        event.preventDefault();
        Whl.Accm.submitBooking();
    });
    $('#add-tour').click(function(event) {
        event.preventDefault();
        Whl.Accm.submitBooking(1);
    });
    // Pickup info
    $('#get_pickup').click( Whl.Accm.getPickup.bind() );
    $('#pickup_none').click(function() {
        $('#pickup_service').val(-1);
        $('#pickup').hide();
        $('#err_pickup').removeClass('error').addClass('error-hide').html('');
    });
    $('#pickup_type_single,#pickup_type_round').click(function() {
        //reset pickup time        
        $('#start_hour').val(-1);
        $('#start_minute').val(-1);
        $('#click_see_opt').val(0);
        $('#pickup').show();
        if (this.id == 'pickup_type_round') $('#pickup_return_time').show();
        else $('#pickup_return_time').hide();
        $('#uxPickupService').hide();
        /*if($('#pickup_service').IsExist())
        	Whl.Combo.get('pickup_service').removeAll().addItem({text: Message.Combo.select, value: -1, selected: true});
        else*/
        	
    });
    $('#pickup_free').click(function() {
        $('#pickup').show();
    });
    $('#insurance_inf').click(function(){
        window.open("/insurance_inf","insurance_inf","width=550,height=600,toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no,status=no");
    });
    //Checking instant available for per category    
    if(arrIds.length > 0 && almApply) Whl.Site.checkRmRateInstant(); 
    else{                
        $('td .tbl_w02 img').each(function(i, val){
            if(val.className == 'alm') $(val).remove();
        });    
    }
    
    /*$('#start_hour,#start_minute,#end_hour,#end_minute').change(function(){
        Whl.Combo.get('pickup_service').removeAll().addItem({text: Message.Combo.select, value: -1, selected: true});
    });*/
    
    $('#pickup_service').change(function(){
        if($(this).val() != -1) $('label[for="transport_no"]').html('<span>*</span><em>Transport/Flight No:</em>');
        else $('label[for="transport_no"]').html('<em>Transport/Flight No:</em>');
    });
    
    //request more info links
    $(".info_request").click(function(event){
        event.preventDefault();
        var href = $(this).attr("href");
        href += "?checkin=" + $("#checkin").val();    
        href += "&checkout=" + $("#checkout").val();        
        href += "&adult=" + $("#adult").val();
        href += $("#child").length == 1 ? ( "&child=" + $("#child").val() ) : "";
        //
        var roomNum = 0;
        $("select.bed").each(function(){
            roomNum += parseInt($(this).val());
        })
        href += roomNum ? ( "&roomnum=" + roomNum ) : "";
        //
        window.location.href = href;
    });
});
