﻿

//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$   On Change Country --> Load City   $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

function SelectCountry_Change()
{
    var HCurrency ='undefined';

    var IsSelectedCountry = false;
    var selectedCountryid ='';
    var lbCountry = document.getElementById("ddlCountry");
    
    for (var j = 0; j < lbCountry.length; j++)
    {
        if (lbCountry.options[j].selected)
        { 
            selectedCountryid = lbCountry.options[j].value;
            IsSelectedCountry = true;           
            break;
        }
    }
    
    if(IsSelectedCountry == true && selectedCountryid != 0)
    {
        $("#ddlCity" + "> option").remove();
        
        var CountryId = selectedCountryid;
        $.ajax({
            type        : "POST",
            url         : "AutoComplete.asmx/GetSpecialDealsCityByCountryId", 
            data        : "{CountryId : '"+ selectedCountryid +"'}",
            beforeSend  : function(xhr){
                xhr.setRequestHeader("Content-type", "application/json; charset=utf-8");
            },
            contentType : "application/json; charset=utf-8",
            dataType    : "json",
            
            success     : function(msg, status){
            
                 $.each(msg.d, function(index)
                  {
                        $('#ddlCity' ).append($('<option></option>').val(this.CityId).html(this.city));
                        
                        HCurrency = this.HotelCurrency;                  
                        SelectHotelCurrency(HCurrency);
                 });
                     
            },
            error       : function(xhr, msg){
                alert(e);
            }
        });
        
        $('#ddlCity' ).append($('<option></option>').val("0").html("Please Select ..."));        
        
    }
    
}



function SelectCity_Change()
{
    var IsSelectedCity = false;
    var selectedCityid ='';
    var ddlCity = document.getElementById("ddlCity");
    
    for (var j = 0; j < ddlCity.length; j++)
    {
        if (ddlCity.options[j].selected)
        { 
            selectedCityid = ddlCity.options[j].value;
            IsSelectedCity = true;           
            break;
        }
    }
    
    if(IsSelectedCity == true && selectedCityid != 0)
    {
        $("#ddlLocation" + "> option").remove();
        
        var CityId = selectedCityid;
        $.ajax({
            type        : "POST",
            url         : "AutoComplete.asmx/GetLocationListByCityId",
            data        : "{CityId : '"+ selectedCityid +"'}",
            beforeSend  : function(xhr){
                xhr.setRequestHeader("Content-type", "application/json; charset=utf-8");
            },
            contentType : "application/json; charset=utf-8",
            dataType    : "json",
            
            success     : function(msg, status){
            
                 $.each(msg.d, function(index) {
                        $('#ddlLocation' ).append($('<option></option>').val(this.LocationId).html(this.LocationName));
                     });
                     
            },
            error       : function(xhr, msg){
                alert(e);
            }
        });
        
        $('#ddlLocation' ).append($('<option></option>').val("0").html("Please Select ..."));
    }
    
}

function SelectHotelCurrency(HotelCurrency)
{    
    if(HotelCurrency != null && HotelCurrency != "undefined")
    {    
        var ddlCurrency = document.getElementById("ddlCurrency");
	    if(ddlCurrency != null)
	    {
	        for(var count = 0; count < ddlCurrency.options.length; count++)
	        {
	            if(ddlCurrency.options[count].value.split('~')[0] == HotelCurrency)
	            {
	                ddlCurrency.options[count].selected = true;
	                break;
	            }
	        }
	    }
	}
}


//$$$$$$$$$$$$$$$$$$$$$$$$$$   Set No of Nights      $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$4

function SetNoofNights()
{
    var one_day = 1000*60*60*24;
    
    var ArrDay = parseInt(document.getElementById("ddlchkindate").value,10)
    var ArrMonth = (document.getElementById("ddlchkinmonth").value)
    var ArrYear = parseInt(document.getElementById("ddlchkinyear").value,10)   
    var checkinday = new Date(ArrYear,ArrMonth-1,ArrDay)
      
    var DepDay = parseInt(document.getElementById("ddlchkoutdate").value,10)
    var DepMonth = (document.getElementById("ddlchkoutmonth").value)
    var DepYear = parseInt(document.getElementById("ddlchkoutyear").value,10)
    var checkoutday = new Date(DepYear,DepMonth-1,DepDay)
    
    var NoofNights = Math.ceil((checkoutday.getTime()-checkinday.getTime())/one_day);    
    if(NoofNights == 1 || NoofNights == 0)
    {
        document.getElementById("spNoofNights").innerHTML = NoofNights + " Night";
    }
    else
    {
        document.getElementById("spNoofNights").innerHTML = NoofNights + " Nights";
    }
}

function btnSpecialDealsSearch_ClintClick()
{
    if(document.getElementById("ddlCountry").value == "" || document.getElementById("ddlCountry").value == "0")
    {
        alert("Please select country");
        document.getElementById("ddlCountry").focus();
        return false;
    }
    
    if(document.getElementById("ddlCity").value == "" || document.getElementById("ddlCity").value == "0")
    {
        alert("Please select city");
        document.getElementById("ddlCity").focus();
        return false;
    }
    
    var one_day = 1000*60*60*24;
    
    var ArrDay = parseInt(document.getElementById("ddlchkindate").value,10)
    var ArrMonth = (document.getElementById("ddlchkinmonth").value)
    var ArrYear = parseInt(document.getElementById("ddlchkinyear").value,10)   
    var checkinday = new Date(ArrYear,ArrMonth-1,ArrDay)
      
    var DepDay = parseInt(document.getElementById("ddlchkoutdate").value,10)
    var DepMonth = (document.getElementById("ddlchkoutmonth").value)
    var DepYear = parseInt(document.getElementById("ddlchkoutyear").value,10)
    var checkoutday = new Date(DepYear,DepMonth-1,DepDay)
    
    var NoofNights = Math.ceil((checkoutday.getTime()-checkinday.getTime())/one_day);    
    if(NoofNights > 23 || NoofNights < 1)
    {
        alert("Please select length of stay between 1 to 23");
        document.getElementById("ddlchkoutdate").focus();
        return false;
    }

    return true;
}

