var loading="<img src='"+SerUrl+"images/loading.gif' />";
var sloading="<img src='"+SerUrl+"images/s_loading.gif' />";
var hloading="<img src='"+SerUrl+"images/hbload.gif' />";
//------------------Validate Date Input---------------------------------
function sld()//ShowLoading
{
    ShowLoading(loading);
}
function ShowLoading(l)//ShowLoading
{
    ShowBackgroup();
    try
    {
        ShowDiv("<table height='100%' width='100%'><tr><td valign='middle' align='right'>"+l+"</td><td valign='middle' align='left'>"+str_loading+"</td></tr></table>",250,100,"#CEDCEB","#CEDCEB",0,38);
    }
    catch(e)
    {
        ShowDiv("<table height='100%' width='100%'><tr><td valign='middle' align='right'>"+l+"</td><td valign='middle' align='left'>Loading......</td></tr></table>",250,100,"#CEDCEB","#CEDCEB",0,38);
    }
}
function login_info(is_append)
{
    var flag="?";
    if(is_append)flag="&";
    return flag+"username="+username+"&password="+password;
}
function ChangeSort(value)
{   
    sld();
    window.location=encodeURI(GetCurrentPage()+'?sort='+value+login_info(true));
}
function ChangePageSize(obj)
{
    sld();
    window.location=GetCurrentPage()+'?pagesize='+obj.value+login_info(true);
}
function HtlFilterLocation(obj)
{   
    sld();
    window.location=encodeURI(GetCurrentPage()+'?page=1&filter=' + obj.value+login_info(true));
}
function HotelSearch()
{
    if(o('txtHtlCity')==null)return;
    if(oa('txtHtlCity')=="")
    {
        Error(getAttibuteValue('txtHtlCity','isempty'));
        o('txtHtlCity').focus();
        return;
    }
    sld();
    var param="?do_search_htl=1"+
              "&countrycode="+o('txtHtlCountry').value+
              "&citycode="+o('txtHtlCity').value+
              "&indate="+o('txtChkIn').value+
              "&outdate="+o('txtChkOut').value+
              "&htlname="+o('txtHtlName').value+login_info(true);
    window.location=GetCurrentPage()+param,"","","selft";
}
function GetSearchForm()
{
    if(o("dv_search")!=null)
    {
        a("dv_search","Hotel_GetInfo.aspx","type=0"+login_info(true),"post",EndGetSearchForm,true);
        o("dv_search").innerHTML=loading;
    }
}
function EndGetSearchForm(str,objId)
{
    RegCss(SerUrl+"calendar/calendar-brown.css");
    RegJs(SerUrl+"calendar/lang/calendar-en.js");
    o(objId).innerHTML=str;

    if(o('txtHtlCountry')==null||o('txtHtlCity')==null)return;
    new SuggestFromJS('txtHtlCountry',null,htlc,htlc,10,null,null,true,null,"FilterHtlCity()");
    FilterHtlCity();    
    new DateControl('txtChkIn',"cal-CI",HtlCompareData);
    new DateControl('txtChkOut',"cal-CO",HtlCompareData);
    o('slHtlNights').onchange=HtlSelChange;
}
function FilterHtlCity()
{
    if(oa('txtHtlCountry')=="")
    {new SuggestFromJS('txtHtlCity',null,htl,HTL,10,'HotelSearch()',null,true,null,null);}
    else
    {
        var countryCode=oa('txtHtlCountry');
        var tmpCode="";
        var tmp="";
        for(var iTmp=0;iTmp<htl.length;iTmp++)
        {
            if(htl[iTmp][2].toUpperCase()==countryCode)
            {
                tmp+="['"+htl[iTmp][0]+"','"+htl[iTmp][1].replace(",","\,").replace("'","\\'")+"'],";
                tmpCode=countryCode;
            }
            if(tmpCode!=""&&tmpCode!=countryCode){break;}
        }
        tmp="["+tmp.substr(0,tmp.length-1)+"]";
        var htlfcity=eval(tmp);
        new SuggestFromJS('txtHtlCity',null,htlfcity,htlfcity,100,'HotelSearch()',null,true,null,null);
        ClickHtlCity(o("txtHtlCity").value=="");
    }
}
function ClickHtlCity(clear)
{
    var obj=o("txtHtlCity");
    if(obj==null)return;
    if(clear)
    {
        obj.value="";    
        if(Browser.isIE){obj.focus();obj.click();}
        else{obj.click();obj.focus();}
    }
    else
    {
        obj.focus();
    }
}
function HtlSelChange()
{
    HtlCompareData(false);
}
function HtlCompareData(txtChange)
{
    var selN=o('slHtlNights');
    selN.style.color = "";
    if (txtChange == 'txtChkIn') {
        if (ConvertDate(oa('txtChkIn')) < new Date()) {
            o('txtChkIn').value = getDateToStr(new Date());
        }
        o('txtChkOut').value = getDateToStr(DateAdd('d', parseInt(selN.value), ConvertDate(oa('txtChkIn'))));
        return;
    }
    var num=1;
    var i=daysElapsed(ConvertDate(oa('txtChkOut')),ConvertDate(oa('txtChkIn')));
    if(!txtChange)
    {
        num=parseInt(selN.value,10);
    }
    else
    {
        if(i>14){num=14;txtChange=false;selN.options[13].selected=true;selN.style.color="Red";}
        else if(i<1){selN.options[0].selected=true;}
        else{selN.options[i-1].selected=true;}
        
    }
    compareDate(ConvertDate(oa('txtChkIn')),ConvertDate(oa('txtChkOut')),'txtChkOut',num,!txtChange);
}
function GetFooter()
{
    if(o("dv_footer")!=null)
    {
        a("dv_footer",SerUrl+"Hotel_GetInfo.aspx","type=1"+login_info(true),"post",EndGetFooter,true);
        o("dv_footer").innerHTML=loading;
    }
}
function EndGetFooter(str,objId)
{
    o(objId).innerHTML=str;
}
function SetupCalendar()
{
    RegCss(SerUrl+"calendar/calendar-brown.css");
    RegJs(SerUrl+"calendar/lang/calendar-en.js");
}
window.setTimeout("GetSearchForm()","10");
function launch_pop(newURL, newName, newFeatures, orgName) 
{
	var remote = window.open(newURL, newName, newFeatures);
	if (remote.opener == null)
		remote.opener = window;
	remote.focus();
	return remote;
}

function ohi(c,v)//OpenHotelInfo
{
    var h = '630';
    var w = '940';
    if ($.browser.mozilla) {
        h = '650';
        w = '950';
    }
    else if ($.browser.msie) {
        h = '630';
        w = '940';
    }
    else {
        h = '645';
        w = '950';
    }
    launch_pop(SerUrl + "B2C/Information.aspx?Code=" + c + "&ViewType=" + v + login_info(true), "hotelinfo", "width=" + w + ",height=" + h + ",top=100,left=200,channelmode=0,dependent=0,directories=0,fullscreen=0,location=0,menubar=0,resizable=0,scrollbars=0,status=0,toolbar=0", "hotelinfo");
}

function ord(id)//OpenRoomDetails
{
    var h = '630';
    if ($.browser.mozilla) {
        h = '570';
    }
    else if ($.browser.msie) {
        h = '630';
    }
    else {
        h = '645';
    }
    launch_pop("RoomDetails.aspx?&ID="+id+login_info(true), "roominfo",
    "top=100,left=200,height="+h+",width=800,channelmode=0,dependent=0,directories=0,fullscreen=0,location=0,menubar=0,resizable=0,scrollbars=0,status=0,toolbar=0", "roominfo");
}
function ordcur(id)//OpenRoomDetails
{
    parent.sld('htl-info-group');
    parent.location = SerUrl + "B2C/RoomDetails.aspx?ID=" + id + login_info(true);
}
function getHtlCityName(sId)
{
    var obj=o(sId);
    if(obj!=null&&htl!=null)
    {
       obj.innerHTML=getCityName(obj.innerHTML,htl);
    }
}
function getCityName(code,ds)
{
    for(i=0;i<ds.length;i++)
    {
        if(ds[i][0].toLowerCase()==code.toLowerCase())
        {
            return ds[i][1];
        }
    }
    return "";
}
function HtlPrint(print) {
    function display(enable) {
        if (enable) {
            var width = Browser.isIE ? '600px' : '950px';
            o('imgADLogo').style.display = '';
            $('div.divPrint').width(width);
            $('#divHtlAlert').width(width);
        }
        else {
            o('imgADLogo').style.display = 'none';
            $('div.divPrint').width('');
            $('#divHtlAlert').width('');
        }
    }

    if (print == null)
    { PrintPage("HtlPrint('S');", "HtlPrint('E');"); }
    else if (print == "S") { display(true); }
    else if (print == "E") { display(false); }
}
var HtlInfoWidth;
function HtlInfoPrint(print) {
    function display(enable) {
        if (enable) {
            o('imgADLogo').style.display = '';
            if ($.browser.msie && $.browser.version != '6.0') {
                HtlInfoWidth = $('#HtlInfo').width();
                $('#HtlInfo').width('625px');
            }
            if ($.browser.mozilla) {
                HtlInfoWidth = $('#HtlInfo').width();
                $('#HtlInfo').width('650px');
            }
        }
        else {
            o('imgADLogo').style.display = 'none';
            if (($.browser.msie && $.browser.version != '6.0') || $.browser.mozilla) {
                $('#HtlInfo').width(HtlInfoWidth);
            }
        }
    }
    if (print == null)
    { PrintPage("HtlInfoPrint('S');", "HtlInfoPrint('E');"); }
    else if (print == "S") { display(true); }
    else if (print == "E") { display(false); }
}
function setGMapLinks(cityCode) {
    if (o('city-map') == null)
        return;
    $.getJSON(SerUrl + 'B2C/Hotel_GetInfo.aspx', { type: 2, r: Math.random, username: username,password:password }, function(data) {
        if (data.length == 0)
            return;
        else {
            $('#city-map').show();
            var mapStr = $('#city-map').attr('rs-map');
            for (var i = 0; i < data.length; i++) {
                if (o('map-' + data[i][0]) != null) {
                    $('#map-' + data[i][0]).html("<a href=\"javascript:ohi('" + data[i][0] + "','M')\">" + mapStr + "</a>").show();
                }
            }
        }
    });
}