var list_booking_id_for_show = [];
var prices_per_day = [];
var availability_per_day = [];
var cost_curency = '';
var highlight_availability_word = '';

function changeFilter(selectObj){
     var idx = selectObj.selectedIndex;
     // get the value of the selected option
     var which = selectObj.options[idx].value;
     // alert(which);
     // alert(location.href);
     var loc = location.href;
     if ( loc.indexOf('sybtypefilter=') == -1 ) {
        loc = location.href + '&sybtypefilter=' +which;}
     else { // Alredy have this paremeter at URL
         var start = loc.indexOf('&sybtypefilter=');
         var fin = loc.indexOf('&', (start+15));
         if (fin == -1) {loc = loc.substr(0,start) + '&sybtypefilter=' +which;} // at the end of row
         else { // at the middle of the row
              var loc1 = loc.substr(0,start) + '&sybtypefilter=' +which;alert(loc)
              loc = loc1 + loc.substr(fin);
         }
     }
     location.href = loc;
}


function highlightSubtype(myClass){ //return;


       jWPDev('a.subtypenum').removeClass('admin_calendar_selection');
       if (myClass != '')
           jWPDev('a.'+myClass  ).addClass('admin_calendar_selection');


}


function filterBookingRowsApply(){
    //  alert(list_booking_id_for_show);
    hide_bk_rows = [];
    for(var i=0; i<list_booking_id_for_show.length;i++){
        if (list_booking_id_for_show[i] == 'hide') {
            hide_bk_rows[hide_bk_rows.length] = 'booking_row'+i;
            jWPDev('#booking_appr_'+ i).removeClass('booking_appr0');
            jWPDev('#booking_appr_'+ i).removeClass('booking_appr1');
            jWPDev('#booking_row'+i).hide();
        }
        // alert(i + '  ' + list_booking_id_for_show[i])
    }
    // alert(hide_bk_rows);
}

if (location.href.indexOf( 'sybtypefilter=') > 0 ) jWPDev(document).ready(filterBookingRowsApply);

function setavailabilitycontent(contnt){
    document.getElementById('selectword').innerHTML = contnt;
}



function is_this_day_available( date, bk_type){

                    function in_array(what, where) {
                        var a=false;
                        for(var i=0; i<where.length; i++) {
                            if(what == where[i]) {
                                a=true;
                                break;
                            }
                        }
                        return a;
                    }

                    var filters_cnt = avalaibility_filters[ bk_type ].length;
                    var filter_week_days = [];
                    var filter_days = [];
                    var filter_monthes = [];
                    var filter_years = [];

                    var d_w = date.getDay();
                    var d_m = ( date.getMonth()+1 );
                    var d_d = date.getDate();
                    var d_y = date.getFullYear();
//alert(date+ ' ' +d_w+ ' ' +d_m+ ' ' +d_d+ ' ' +d_y);
                    var is_day_inside_filters = 0 ;

                    for(var k=0; k<filters_cnt; k++ ) {
                        filter_week_days = avalaibility_filters[ bk_type ][k][0];
                        filter_days = avalaibility_filters[ bk_type ][k][1];
                        filter_monthes = avalaibility_filters[ bk_type ][k][2];
                        filter_years = avalaibility_filters[ bk_type ][k][3];

                        is_day_inside_filters = '';
                        if ( in_array( d_w , filter_week_days ) ) { is_day_inside_filters += 'week '; }
                        if ( in_array( d_d , filter_days ) )      { is_day_inside_filters += 'day '; }
                        if ( in_array( d_m , filter_monthes ) )   { is_day_inside_filters += 'month '; }
                        if ( in_array( d_y , filter_years ) )     { is_day_inside_filters += 'year '; }

                        if (is_day_inside_filters == 'week day month year ') { break; } // the days is apply to filter (apply to week days monthes and years of filter)

                    }
//alert( is_day_inside_filters );
                    if (is_day_inside_filters == 'week day month year ') { is_day_inside_filters = true; } else {is_day_inside_filters = false;}

                    var is_this_day_available = true;

                    if (is_day_inside_filters) {
                        if ( is_all_days_available[ bk_type ] ) is_this_day_available = false;
                        else                                    is_this_day_available = true;
                    } else {
                        if ( is_all_days_available[ bk_type ] ) is_this_day_available = true;
                        else                                    is_this_day_available = false;
                    }
//alert(is_this_day_available);
                    return is_this_day_available;
}

function getDayPrice4Show(bk_type, tooltip_time, td_class){

    if (is_show_cost_in_tooltips) {

       if(typeof(  prices_per_day[bk_type] ) !== 'undefined')
           if(typeof(  prices_per_day[bk_type][td_class] ) !== 'undefined') {
                if (tooltip_time!== '') tooltip_time = tooltip_time + '<br/>';
                return  tooltip_time + cost_curency + prices_per_day[bk_type][td_class] ;

           }
    
    }

    return  tooltip_time   ;
    
}


function getDayAvailability4Show(bk_type, tooltip_time, td_class){

    if (is_show_availability_in_tooltips) { 

       if(typeof(  availability_per_day[bk_type] ) !== 'undefined')
           if(typeof(  availability_per_day[bk_type][td_class] ) !== 'undefined') {
                if (tooltip_time!== '') tooltip_time = tooltip_time + '<br/>';
                return  tooltip_time + highlight_availability_word + availability_per_day[bk_type][td_class] ;

           }

    }

    return  tooltip_time   ;

}

