﻿// JScript File

            function selectOptColOn(){
	          document.getElementById('select1').className = 'HM_optSelectOn';
	          document.getElementById('select2').className = 'HM_optSelectOn';
	          document.getElementById('specific1').className = 'HM_optSelectOff';
	          document.getElementById('specific2').className = 'HM_optSelectOff';
	          var rb1 = document.getElementById('rbSelect');
	          rb1.checked = true;
	          var rb2 = document.getElementById('rbSpecfic');
	          rb2.checked = false;
	          
	          // set default values 
	          var cityHostelName = document.getElementById('txtHostelCityName');
	          if(cityHostelName)
	            cityHostelName.value = '';
	            
	        }
        	
	         function selectOptColOff()
	        {
	          document.getElementById('select1').className = 'HM_optSelectOff';
	          document.getElementById('select2').className = 'HM_optSelectOff';
	          document.getElementById('specific1').className = 'HM_optSelectOn';
	          document.getElementById('specific2').className = 'HM_optSelectOn';
	          var rb1 = document.getElementById('rbSelect');
	          rb1.checked = false;
	          var rb2 = document.getElementById('rbSpecfic');
	          rb2.checked = true;
	          
	          // set default selection values..
	          // country value 
	          var ddlCountry = document.getElementById('ddlCountry');
	          if(ddlCountry)
	            ddlCountry.selectedIndex = 0;
	          
	          // city value  
	          var ddlCity = document.getElementById('ddlCity');
	          if(ddlCity)
	          {
	            ddlCity.options.length = 0;
	            ddlCity.options.length ++;
	            ddlCity.options[0].value = "";
                ddlCity.options[0].text = "-select country first-";                
	          }
	        }
        	
	        // Validate default options:
	        function ValidateSearchOptions(ObjCountryName,ObjCityName,ObjArrivalDate,ObjHostelCityName)
	        {
	            // check for which is selected Country / city or Hotel name
        
                // country city selection	            
	            if(document.getElementById("SelectDestination").style.display == "" || document.getElementById("SelectDestination").style.display == "block")
	            {
                    // country selection 
                    var country = document.getElementById(ObjCountryName);
                    if(country)
                    {
                        if(country.value == '')
                        {
                            alert('Please select country for hostel search !!');
                            return false;
                        }	                        
                    }
                    // city selection 
                    var city = document.getElementById(ObjCityName);
                    if(city)
                    {
                        if(city.value == '')
                        {
                            alert('Please select city name for hostel search!!');
                            return false;
                        }	                        
                    }
                }
                else if(document.getElementById("TypeDestination").style.display == "" || document.getElementById("TypeDestination").style.display == "block")
                {
                    var hostel = document.getElementById(ObjHostelCityName);
                    if(hostel)
                    {
                        if(hostel.value == 'Know the city /hostel name?' || hostel.value == '')
                        {
                            alert('Please specify City / Hostel name for hostel search!!');
                            return false;	                        
                        }
                    }
                }
                
                // date validation...
                var arrivalDate = document.getElementById(ObjArrivalDate);
                if(arrivalDate)
                {
                    if(arrivalDate.value =='')
                    {
                        alert('Please select / enter the arrival date !!');
                        return false;
                    }
                    // should be greater than todays date.
                    var todayDate = document.getElementById('todayDate');
                    if(todayDate)
                    {
                        var tomorrow = todayDate.value;
                        var clientArrivalDate = arrivalDate.value;
                        if(tomorrow!='' && clientArrivalDate!= '')
                        {	                
                           // compare dates
                           var val = compareDates(arrivalDate.value ,'dd/MM/y',tomorrow,'dd/MM/y');
                           
                           if(val <1)
                           {		                
                                alert('Please select arrival date, which is greater than todays date');
                                return false;
                           }		       		       
                        }
                    }
                }
                return true;
	         }
	         
	        // Validate default options:
	        function ValidateSearchOptionsHostelResults(ObjCountryName,ObjCityName,ObjArrivalDate,ObjHostelCityName)
	        {
	            // check for which is selected Country / city or Hotel name
        
                // country city selection	            
	            if(document.getElementById("searchselect").style.display == "" || document.getElementById("searchselect").style.display == "block")
	            {
                    // country selection 
                    var country = document.getElementById(ObjCountryName);
                    if(country)
                    {
                        if(country.value == '')
                        {
                            alert('Please select country for hostel search !!');
                            return false;
                        }	                        
                    }
                    // city selection 
                    var city = document.getElementById(ObjCityName);
                    if(city)
                    {
                        if(city.value == '')
                        {
                            alert('Please select city name for hostel search!!');
                            return false;
                        }	                        
                    }
                }
                else if(document.getElementById("searchtype").style.display == "" || document.getElementById("searchtype").style.display == "block")
                {
                    var hostel = document.getElementById(ObjHostelCityName);
                    if(hostel)
                    {
                        if(hostel.value == 'Know the city /hostel name?' || hostel.value == '')
                        {
                            alert('Please specify City / Hostel name for hostel search!!');
                            return false;	                        
                        }
                    }
                }
                
                // date validation...
                var arrivalDate = document.getElementById(ObjArrivalDate);
                if(arrivalDate)
                {
                    if(arrivalDate.value =='')
                    {
                        alert('Please select / enter the arrival date !!');
                        return false;
                    }
                    // should be greater than todays date.
                    var todayDate = document.getElementById('todayDate');
                    if(todayDate)
                    {
                        var tomorrow = todayDate.value;
                        var clientArrivalDate = arrivalDate.value;
                        if(tomorrow!='' && clientArrivalDate!= '')
                        {	                
                           // compare dates
                           var val = compareDates(arrivalDate.value ,'dd/MM/y',tomorrow,'dd/MM/y');
                           
                           if(val <1)
                           {		                
                                alert('Please select arrival date, which is greater than todays date');
                                return false;
                           }		       		       
                        }
                    }
                }
                return true;
	         }

	         // from query string default values setting ......
	         function SetDefaultSearchValues()
	         {
	         
	            hu = window.location.search.substring(1);
	            if(hu.length >0)
	            {
	                // country value setting ...
	                SetDefaultCountryValue();
	                
	                // city or hostel name ...
	                SetDefaultCityHostelName();
	                
	                // arrival date, nights, guest
	                SetDefaultParameters();
	            }	            
	         }
	         
	         // setting from the query string values to country list 
	         function SetDefaultCountryValue()
	         {
	              // check for country city search or  
	                var selectedCountryId = queryString('ContId') 
	                if(selectedCountryId)
	                {
	                    if(selectedCountryId.length>0)
	                    {
	                        var ddlCountry = document.getElementById('ddlCountry');
	                        if(ddlCountry)
                            {
                                // load default countries
                                loadDefaultCountries();
                                if(ddlCountry.length>0)
                                {           
                                    // loops through the array adding item text/value
                                    for(var i=0;i<ddlCountry.length;i++)
                                    {
                                        if(ddlCountry.options[i].value ==selectedCountryId)
                                         { 
                                             ddlCountry.selectedIndex = i;
                                             // load default cities
                                             SetDefaultCityValue();
                                             break;
                                         }                                            
                                    }
                                 }
                                 // set radio button selection
                               var rb1 = document.getElementById('rbSelect');
                               if(rb1)
                                rb1.checked = true;
                                
                               var rb2 = document.getElementById('rbSpecfic');
                               if(rb2)
                                rb2.checked = false;
                            }	                    
	                    }
	                }
	         
	         }
	         // setting value from the substring city value
	         function SetDefaultCityValue()
	         {	         
                var selectedCityId = queryString('CityID')
                if(selectedCityId.length>0)
                {
                    // city id 
                    var ddlCity  = document.getElementById('ddlCity');
                    if(ddlCity)
                    {
                        // load the cities based on country id                         
                        loadCitiesByCountry()
                        // check now 
                        if(ddlCity.length>0)
                        {           
                            // loops through the array adding item text/value
                            for(var i=0;i<ddlCity.length;i++)
                            {   
                                if(ddlCity.options[i].value ==selectedCityId)
                                 {   
                                     ddlCity.selectedIndex = i;
                                     break;
                                 }                                
                            }
                         }
                    }
                }
	         }
	         // city hostel name
	         function SetDefaultCityHostelName()
	         {
	            var cityHostelName = document.getElementById('txtHostelCityName');
	            if(cityHostelName)
	            {
	                var selectedCityId = queryString('CityHostel')
	                if(selectedCityId)
	                {
                        if(selectedCityId.length>0)                    
                        {
                           cityHostelName.value = selectedCityId;	                
                           // set radio button selection
                           var rb1 = document.getElementById('rbSelect');
                           if(rb1)
                            rb1.checked = false;
                            
                           var rb2 = document.getElementById('rbSpecfic');
                           if(rb2)
                            rb2.checked = true;
                        }
                    }
	            }	            
	         }
	         // default parameters date, nights, 
	         function SetDefaultParameters()
	         {
	            // arrival date 
	            var arrivalDate = document.getElementById('txtArrivalDate');
	            if(arrivalDate)
	            {
	                var selectedArrivalDate = queryString('ArrDt');
	                
	                if(selectedArrivalDate)
	                    if(selectedArrivalDate.length>0)
	                        arrivalDate.value = selectedArrivalDate;
	            }
	            
	            // nights..
	            var ddlNights = document.getElementById('ddlNights');
	            if(ddlNights)
	            {
	                var selectedNights = queryString('Nights');
	                
	                if(selectedNights)
	                {
                        if(selectedNights.length>0)  	                
                        {                        
                            if(ddlNights.length>0)
                            {           
                                // loops through the array adding item text/value
                                for(var i=0;i<ddlNights.length;i++)
                                {   
                                    if(ddlNights.options[i].value ==selectedNights)
                                     {   
                                         ddlNights.selectedIndex = i;
                                         break;
                                     }                                
                                }
                             }                        
                        }
                    }
	            }
	            	            
	            // no of guests..
	            var ddlGuests = document.getElementById('ddlGuests');
	            if(ddlGuests)
	            {
	                var selectedGuests = queryString('Guest')
	                if(selectedGuests)
	                {
                        if(selectedGuests.length>0)  	                
                        {
                            if(ddlGuests.length>0)
                            {           
                                // loops through the array adding item text/value
                                for(var i=0;i<ddlGuests.length;i++)
                                {   
                                    if(ddlGuests.options[i].value ==selectedGuests)
                                     {   
                                         ddlGuests.selectedIndex = i;
                                         break;
                                     }                                
                                }
                             }                        
                        }
                    }
	            }
	            
	            
	         }
	         // query string 
	         function queryString(ji) 
	         {
                hu = window.location.search.substring(1);
                gy = hu.split("&");
                for (i=0;i<gy.length;i++) 
                {
                    ft = gy[i].split("=");
                        if (ft[0] == ji) 
                        {
                            return ft[1];
                        }
                }
            }
