﻿function init(){
    setTimeout(function(){SetDefaultMenu("#mhotel","ms0");},20);
    setTimeout(function(){setRoomType();},100);
    setTimeout(function(){CheckChatToolState();},150);
    setTimeout(function(){$(".leftMenu ul").css("display","block");},200);
}
function setRoomType(){
    var queryDates=$("#divQueryDates").html();        
    var roomtype_pricedetail_temp="<table border='0' cellpadding='0' cellspacing='1' class='pricedetail'><tr><th>Sun</th><th>Mon</th><th>Tue</th><th>Wed</th><th>Thu</th><th>Fri</th><th>Sat</th></tr><tr><td><!--{Sunday}--></td><td><!--{Monday}--></td><td><!--{Tuesday}--></td><td><!--{Wednesday}--></td><td><!--{Thursday}--></td><td><!--{Friday}--></td><td><!--{Saturday}--></td></tr><tr><td colspan='7' class='bPrice'>Breakfast Price: ${BF}</td></tr></table>";            
    
    var roomtype_table_temp="<table border='0' cellpadding='0' cellspacing='1' class='roomtype'><tr><th style='width:50%'>Room Type</th><th style='width:15%'>Price($)</th><th style='width:20%'>Breakfast</th><th style='width:10%'>&nbsp;</th></tr>{roomtype_table_trs}</table>";
    
    var roomtype_tr_temp="<tr><td class='roomtype_name'><a href='HotelBook.aspx?HotelID={hotelID}&HotelPriceID={id}&HotelPriceName={name}' title='{name}'>{name}</a></td><td><a class='price_detail' href='###'>Details</a>{detail}</td><td>{breakfast}</td><td><a href='HotelBook.aspx?HotelID={hotelID}&HotelPriceID={id}&HotelPriceName={name}'>Book</a></td></tr>";
    
    
    var set_roomtype_pricedetail=function(data){
        var data=data.split(',');
        var html=roomtype_pricedetail_temp;
        
        if(queryDates.indexOf('Sunday')>=0)
            html=html.replace('<!--{Sunday}-->',data[0]);
        
        if(queryDates.indexOf('Monday')>=0)    
            html=html.replace('<!--{Monday}-->',data[1]);         
            
        if(queryDates.indexOf('Tuesday')>=0)    
            html=html.replace('<!--{Tuesday}-->',data[2]);   

        if(queryDates.indexOf('Wednesday')>=0)    
            html=html.replace('<!--{Wednesday}-->',data[3]);
        
        if(queryDates.indexOf('Thursday')>=0)    
            html=html.replace('<!--{Thursday}-->',data[4]);        
        
        if(queryDates.indexOf('Friday')>=0)    
            html=html.replace('<!--{Friday}-->',data[5]);
        
        if(queryDates.indexOf('Saturday')>=0)    
            html=html.replace('<!--{Saturday}-->',data[6]);
        
        html=html.replace('{BF}',data[7]);
        return html;
    }
    var set_roomtype_trs=function(data){
        var trs="";
        $(data).each(function(){
            var items=this.split('`');
            var tr=roomtype_tr_temp;
            tr=tr.replace(/{hotelID}/g,items[0]);
            tr=tr.replace(/{id}/g,items[1]);
            tr=tr.replace(/{name}/g,items[2]);
            tr=tr.replace('{detail}',set_roomtype_pricedetail(items[3]));
            tr=tr.replace('{breakfast}',items[4]);
            trs=trs+tr;
        });
        return trs;                
    }
    var set_table=function(div){     
        var table=roomtype_table_temp;
        var data=div.html().substring(1).split('|');            
        table=table.replace('{roomtype_table_trs}',set_roomtype_trs(data));
        div.html(table);
    }
    var setRoomTypeStart=function(){
        $(".room_type").each(function(){ 
            var div=$(this); 
            setTimeout(function(){set_table(div);},100);
        });
        setTimeout(function(){setRoomTypeComplete()},300);
    }
    setRoomTypeStart();
}
function setRoomTypeComplete(){
    $(".room_type").css("display","block");
    $(".price_detail").each(function(){            
        $(this).hover(function(){
            $(this).next().show();
        },function(){
            $(this).next().hide();
        });
    });
    $(".roomtype tr").each(function(){
        $(this).hover(function(){
            $(this).css("backgroundColor","#efefef");
        },function(){
            $(this).css("backgroundColor","#ffffff");
        });
    });
}