﻿    var t;
    function SetRequest(cityddl_id, hotelnametxt_id, districtddl_id, minpricetxt_id, maxpricetxt_id, chBx_id, startdate_id, enddate_id, DescriptionDivId, OnlineHotelsChbx_id, DayRB_id, login, passwordhash, mincom_id, time)
    {
        clearTimeout(t);
        t = setTimeout("gethotelcount('" + cityddl_id + "','" + hotelnametxt_id + "','" + districtddl_id + "','" + minpricetxt_id + "','" + maxpricetxt_id + "','" + chBx_id + "','" + startdate_id + "','" + enddate_id + "','" + DescriptionDivId + "','" + OnlineHotelsChbx_id + "','" + DayRB_id + "','"  + login + "','" + passwordhash + "','" + mincom_id + "')", time);
    }

    function gethotelcount(cityddl_id, hotelnametxt_id, districtddl_id, minpricetxt_id, maxpricetxt_id, chBx_id, startdate_id, enddate_id, DescriptionDivId, OnlineHotelsChbx_id, DayRB_id, login, passwordhash, mincom_id)
    {
        var xmlHttp = ReturnNewXmlHttp();
        var cityddl = document.getElementById(cityddl_id);
        var hotelnametxt = document.getElementById(hotelnametxt_id);
        var districtddl = document.getElementById(districtddl_id);
        var minpricetxt = document.getElementById(minpricetxt_id);
        var maxpricetxt = document.getElementById(maxpricetxt_id);
        var startdate = document.getElementById(startdate_id);
        var enddate = document.getElementById(enddate_id);        
        var OnlineHotelsChbx = document.getElementById(OnlineHotelsChbx_id);
        var DayRB = document.getElementById(DayRB_id);
        var mincom = document.getElementById(mincom_id);
            
        var Stars ="";
        var chbx_1 = document.getElementById(chBx_id +"_0");
        var chbx_2 = document.getElementById(chBx_id +"_1");
        var chbx_3 = document.getElementById(chBx_id +"_2");
        var chbx_4 = document.getElementById(chBx_id +"_3");
        var chbx_5 = document.getElementById(chBx_id +"_4");
        var chbx_6 = document.getElementById(chBx_id + "_5");

        var mincomvalue = 0;

        if (mincom)
            mincomvalue = mincom.options[mincom.selectedIndex].value;
        
        if(chbx_1.checked  == true)
            Stars = "12";
            
        if(chbx_2.checked  == true)
            if(Stars == "")
                Stars = "10";
            else
               Stars += ",10";
               
        if(chbx_3.checked  == true)
            if(Stars == "")
                Stars = "11";
            else
               Stars += ",11";
               
        if(chbx_4.checked  == true)
            if(Stars == "")
                Stars = "1";
            else
               Stars += ",1";
               
        if(chbx_5.checked  == true)
            if(Stars == "")
                Stars = "3";
            else
               Stars += ",3";
               
        if(chbx_6.checked  == true)
            if(Stars == "")
                Stars = "4";
            else
               Stars += ",4";
     
        if(cityddl.childNodes.length > 0)
        {
            var cityvalue = parseInt(cityddl.options[cityddl.selectedIndex].value);
            if (cityvalue > 1000000000)
                cityvalue -= 1000000000;
            var hotelnamevalue = trim(hotelnametxt.value);
            var districtvalue = districtddl.options[districtddl.selectedIndex].value;
            var minpricevalue = minpricetxt.value;
            var maxpricevalue = maxpricetxt.value;    
            if(minpricevalue == "")
                 minpricevalue = 0;
            if(maxpricevalue == "")
                maxpricevalue = 0;

            var startdatevalue = startdate.value;
            var enddatevalue = enddate.value;                   

            var UseOnlyOnlineHotels = OnlineHotelsChbx.checked;  
            
            var ReturnDayPrice = false;

            if (DayRB.checked)
                ReturnDayPrice = true;

            xmlHttp.onreadystatechange = function() {
                if (xmlHttp.readyState == 4) {
                    // alert(xmlHttp.responseText);
                    if (xmlHttp.responseText != "") {
                        eval("var objResults = " + xmlHttp.responseText);
                        document.getElementById(DescriptionDivId).innerHTML = objResults.GetHotelCountForDefaultResult;                    
                    }
                }
                else {
                    document.getElementById(DescriptionDivId).innerHTML = '<img id="LoadingImage"  src="Pictures/spinner.gif" style="border-width:0px;" />';
                }
            }

            var url = "XmlHttpRequestService/service.svc/ajaxEndpoint/GetHotelCountForDefault";
            url = ChangeAjaxServer(url);
         
            //var url = "XmlHttpRequestService/service.svc/ajaxEndpoint/GetHotelCountForDefault";

            // Build the body of the JSON message
            var body = '{"IdCity":"'+ cityvalue +'"';
            body = body + ',"Name":"' + hotelnamevalue +'"';
            body = body + ',"IdDistr":"' + districtvalue +'"';
            body = body + ',"MaxPrice":"' + maxpricevalue +'"';
            body = body + ',"MinPrice":"' + minpricevalue +'"';
            body = body + ',"Stars":"' + Stars +'"';
            body = body + ',"DateFrom":"' + startdatevalue + '"';  
            body = body + ',"DateTo":"' + enddatevalue +'"';  
            body = body + ',"UseOnlyOnlineHotels":"' + UseOnlyOnlineHotels + '"';
            body = body + ',"ReturnDayPrice":"' + ReturnDayPrice + '"';
            body = body + ',"login":"' + login + '"';
            body = body + ',"passwordhash":"' + passwordhash + '"';
            body = body + ',"mincom":"' + mincomvalue + '"}';
            
            //alert(body);
            // Send the HTTP request
            xmlHttp.open("POST", url, true);
            xmlHttp.setRequestHeader("Content-type", "application/json");
            xmlHttp.send(body);  
        }
        else
        {
             document.getElementById(DescriptionDivId).innerHTML = "&nbsp;";
        }      
    }
    
    function SetGoogleLnkValue(cityddl_id, text, link_id)
    {
        var cityddl = document.getElementById(cityddl_id);
        var link = document.getElementById(link_id);

        link.innerHTML = text;

        var cityvalue = parseInt(cityddl.options[cityddl.selectedIndex].value);
        if (cityvalue > 1000000000)
            cityvalue -= 1000000000;

        link.href = "GoogleMap.aspx?cityid=" + cityvalue;        
    } 
    
    function SetMetroLnkValue(cityddl_id, text, link_id, array, img_id)
    {
        var img = document.getElementById(img_id);
        var cityddl = document.getElementById(cityddl_id);

        var cityId = parseInt(cityddl.options[cityddl.selectedIndex].value);
        if (cityId > 1000000000)
            cityId -= 1000000000;        
        
        var link = document.getElementById(link_id);
        
        var b = Array.contains(array, cityId);
        if(b == true){
        
            link.innerHTML = text;
            link.href = "MetroMap.aspx?id=" + cityId;
            img.src = "Pictures/metro_icon.jpg";           
        }
        else{
            link.innerHTML = "";
            img.src = "Pictures/e.gif"; 
        }
    }  
    
    function SetAllHotelsLnkValue(cityddl_id, text, link_id)
    {
        var cityddl = document.getElementById(cityddl_id);
        var link = document.getElementById(link_id);

        var cityId = parseInt(cityddl.options[cityddl.selectedIndex].value);
        if (cityId > 1000000000)
            cityId -= 1000000000;  
        
        link.innerHTML = text + " " + cityddl.options[cityddl.selectedIndex].text;
        link.href = "Hotellist.aspx?cityid=" + cityId;
    }

    function GhangeHotelsNearPortsLink(cityddl_id, link_id, startdate_id, enddate_id) {
        var cityddl = document.getElementById(cityddl_id);
        var link = document.getElementById(link_id);

        var cityId = parseInt(cityddl.options[cityddl.selectedIndex].value);
        if (cityId > 1000000000)
            cityId -= 1000000000;

        link.href = "HotelsNearPorts.aspx?id=" + cityId;

        var startdate = document.getElementById(startdate_id);
        var enddate = document.getElementById(enddate_id);
        if (startdate && enddate) {
        
            var startdatevalue = startdate.value;
            var enddatevalue = enddate.value;

            if (startdatevalue != "" && enddatevalue != "")
                link.href += "&datefrom=" + startdatevalue + "&dateto=" + enddatevalue;
        }
    }    
   
       
    function ChangePriceLinkValue(obj, period_value, day_value, field_id)
    {
        var field = document.getElementById(field_id);
        if(obj.innerHTML == period_value){
            obj.innerHTML = day_value;
            field.value = "day";
        }
        else {
            obj.innerHTML = period_value;
            field.value = "period";
        }
    }            
      
//    function SetVisibilityForCalculatePriceBlock(obj, PeriodPriceTextValue, DayPriceTextValue,PriceLinkId, CalculatePriceBlockId, cityddl_id, hotelnametxt_id, districtddl_id, minpricetxt_id, maxpricetxt_id, chBx_id, startdate_id, enddate_id, DescriptionDivId, CalculatePriceChbx_id, OnlineHotelsChbx_id)
//    {
//        var CalculatePriceBlock = document.getElementById(CalculatePriceBlockId);
//        var PriceLink = document.getElementById(PriceLinkId);
//        
//        if(obj.checked  == true)
//        {
//            PriceLink.innerHTML =   PeriodPriceTextValue;
//            CalculatePriceBlock.style.display='block';        
//        }
//        else
//        {
//            PriceLink.innerHTML =   DayPriceTextValue;
//            CalculatePriceBlock.style.display='none';        
//        }
//        gethotelcount(cityddl_id, hotelnametxt_id, districtddl_id, minpricetxt_id, maxpricetxt_id, chBx_id, startdate_id, enddate_id, DescriptionDivId, CalculatePriceChbx_id,OnlineHotelsChbx_id);
//    }   
    
    
    
//    function SetStartUpScript(cityddl_id,hotelnametxt_id,districtddl_id, minpricetxt_id, maxpricetxt_id, chBx_id, startdate_id, enddate_id, DescriptionDivId, OnlineHotelsChbx_id, google_text, google_link_id, metro_text, metro_link_id, array, guid, allhotels_text, allhotelslink_id)
//    {
//        var xmlHttp = ReturnNewXmlHttp();
//        var cityddl = document.getElementById(cityddl_id);
//        var hotelnametxt = document.getElementById(hotelnametxt_id);
//        var districtddl = document.getElementById(districtddl_id);
//        var minpricetxt = document.getElementById(minpricetxt_id);
//        var maxpricetxt = document.getElementById(maxpricetxt_id);
//        var startdate = document.getElementById(startdate_id);
//        var enddate = document.getElementById(enddate_id);   
//        var OnlineHotelsChbx = document.getElementById(OnlineHotelsChbx_id);    
//        var chbx_1 = document.getElementById(chBx_id +"_0");
//        var chbx_2 = document.getElementById(chBx_id +"_1");
//        var chbx_3 = document.getElementById(chBx_id +"_2");
//        var chbx_4 = document.getElementById(chBx_id +"_3");
//        var chbx_5 = document.getElementById(chBx_id +"_4");
//        var chbx_6 = document.getElementById(chBx_id +"_5");
//        var ProgressMetter = document.getElementById(DescriptionDivId); 

//      //  ProgressMetter.innerHTML = '<img id="LoadingImage"  src="Pictures/spinner.gif" style="border-width:0px;" />'; 
//       // ProgressMetter.innerHTML = "&nbsp;";
//        xmlHttp.onreadystatechange=function(){
//           if(xmlHttp.readyState == 4){
//               if(xmlHttp.responseText != ""){  
//                    eval("var objResults = " + xmlHttp.responseText);
//                    if(objResults.GetHotelSearchParamByGuidResult != ""){
//                        var DataArray = objResults.GetHotelSearchParamByGuidResult.split('|');
//                        
//	                    for(var i= 0; i< cityddl.options.length; i++){
//	                        if(cityddl.options[i].value == DataArray[0]){
//	                            setTimeout("setSelectedElement('"+cityddl.id +"','"+ i+"')",0);
//	                            break;
//	                        }
//	                    }   
//        	           
//        	            hotelnametxt.value = DataArray[1];
//        	            
//	                    for(var i= 0; i< districtddl.options.length; i++){
//	                        if(districtddl.options[i].value == DataArray[2]){
//	                            setTimeout("setSelectedElement('"+districtddl.id +"','"+ i+"')",0);
//	                            break;
//	                        }
//	                    }  	
//    	                
//                        minpricetxt.value = DataArray[3];
//                        maxpricetxt.value = DataArray[4]; 
//                        startdate.value =  DataArray[5];
//                        enddate.value = DataArray[6];
//                        	
//                        var Hoteltypes = DataArray[7].split(',');            	                                  
//                       
//                        if(Array.contains(Hoteltypes, "12") == true)
//                            chbx_1.checked  = true;     
//                        if(Array.contains(Hoteltypes, "10") == true)
//                            chbx_2.checked  = true;    
//                        if(Array.contains(Hoteltypes, "11") == true)
//                            chbx_3.checked  = true;    
//                        if(Array.contains(Hoteltypes, "1") == true)
//                            chbx_4.checked  = true;    
//                        if(Array.contains(Hoteltypes, "3") == true)
//                            chbx_5.checked  = true;    
//                        if(Array.contains(Hoteltypes, "4") == true)
//                            chbx_6.checked  = true; 
//                       
//                        if(DataArray[8] == "1")     
//                            OnlineHotelsChbx.checked = true;                     
//                            
//                        ProgressMetter.innerHTML = DataArray[9];
//                        
//                        SetGoogleLnkValue(cityddl_id, google_text, google_link_id);
//                        SetMetroLnkValue(cityddl_id, metro_text, metro_link_id, array);  
//                        SetAllHotelsLnkValue(cityddl_id, allhotels_text, allhotelslink_id);                                    
//                                                
//                    }                 
//               }
//           } 
//        }
//        
//        var url = "XmlHttpRequestService/service.svc/ajaxEndpoint/GetHotelSearchParamByGuid";
//                  
//        var body = '{"guid":"'+ guid + '"}';
//        xmlHttp.open("POST", url, true);
//        xmlHttp.setRequestHeader("Content-type", "application/json");
//        xmlHttp.send(body);  
//    }      
    
    function SetVisibleContactsTable(tbl_id){
        var tbl = document.getElementById(tbl_id); 
        tbl.style.display='block';  
    }
    
    function ValidateReserv(postback_ctrl_id,tbl_id,bustoddl_id,message){
        var tbl = document.getElementById(tbl_id);
        if(tbl.style.display != 'block') 
            tbl.style.display = 'block';
        
        var bustoddl = document.getElementById(bustoddl_id);  
        
        if(bustoddl.options[bustoddl.selectedIndex].value == -1)
            alert(message);
        else
            WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(postback_ctrl_id, "", true, "", "", false, true));
    }
    
    

    function dragendhandler(sender, args) {
        var obj = document.getElementById(sender._multiHandleSliderTargets[1].ControlID);
        var txtslider = document.getElementById(sender._element.id);
        if (obj) {
            var currprice = parseInt(obj.value);
            if (currprice == sender._maximum)
                obj.value = txtslider.value;
        }
    }

    function valuechanged(sender, args) {
        var obj = document.getElementById(sender._multiHandleSliderTargets[1].ControlID);
        var txtslider = document.getElementById(sender._element.id);
        var curr_price = parseInt(obj.value);
        if (curr_price == sender._maximum)
            obj.value = txtslider.value;
        else if (curr_price > sender._maximum)
            obj.value = curr_price;
    }

    function cliendload(sender, args) {
        var obj = document.getElementById(sender._multiHandleSliderTargets[1].ControlID);
        var txtslider = document.getElementById(sender._element.id);
        var curr_price = parseInt(obj.value);
        if (curr_price == sender._maximum)
            obj.value = txtslider.value;
    }

    function showModalPopup(datedatafield_id, datetime, modalpopupbehavior) {
        var datedatafield = document.getElementById(datedatafield_id);
        datedatafield.innerHTML = datetime;
        var modalPopupBehavior = $find(modalpopupbehavior);
        if (modalPopupBehavior)
            modalPopupBehavior.show();
    }
    
    function hideModalPopup(modalpopupbehavior) {
        var modalPopupBehavior = $find(modalpopupbehavior);
        if (modalPopupBehavior)
            modalPopupBehavior.hide();
    }

    function setStartDate(StartDateHiddenFieldID, datetime, PostBackCtrlID) {
        var StartDateHiddenField = document.getElementById(StartDateHiddenFieldID);
        StartDateHiddenField.value = datetime;
        __doPostBack(PostBackCtrlID, '');
    }

    function setEndDate(EndDateHiddenFieldID, datetime, PostBackCtrlID) {
        var EndDateHiddenField = document.getElementById(EndDateHiddenFieldID);
        EndDateHiddenField.value = datetime;
        __doPostBack(PostBackCtrlID, '');
    }

    function setOtherDate(OtherDateHiddenFieldID, datetime, PostBackCtrlID) {
        var OtherDateHiddenField = document.getElementById(OtherDateHiddenFieldID);
        OtherDateHiddenField.value = datetime;
        __doPostBack(PostBackCtrlID, '');
    }

    
    function ChangeDateModalOkScript(modalpopupbehavior, PostBackCtrlID) {
        var modalPopupBehavior = $find(modalpopupbehavior);
        if (modalPopupBehavior)
            modalPopupBehavior.hide();
        __doPostBack(PostBackCtrlID, '');
    }    



     
    

 

