﻿
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$   On Change Country --> Load City   $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

function SelectCountry_Change()
{
    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/GetCityListArrayByCountryId",
            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));
                     });
                     
            },
            error       : function(xhr, msg){
                alert(e);
            }
        });
        
        $('#ddlCity' ).append($('<option></option>').val("0").html("Please Select ..."));
    }
    
}

function SelectCountry_Change1()
{
    var IsSelectedCountry = false;
    var selectedCountryid ='';
    var lbCountry = document.getElementById("ddlCountryBD");
    
    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)
    {
        $("#ddlCityBD" + "> option").remove();
        
        var CountryId = selectedCountryid;
        $.ajax({
            type        : "POST",
            url         : "AutoComplete.asmx/GetCityListArrayByCountryId",
            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) {
                        $('#ddlCityBD' ).append($('<option></option>').val(this.CityId).html(this.city));
                     });
                     
            },
            error       : function(xhr, msg){
                alert(e);
            }
        });
        
        $('#ddlCityBD' ).append($('<option></option>').val("0").html("Please Select ..."));
    }
}




//$$$$$$$$$$$$$$$$$$$$$$$$$$   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)
    
    document.getElementById("spNoofNights").innerHTML = Math.ceil((checkoutday.getTime()-checkinday.getTime())/one_day);    
}


//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

function onkeypressText(txt,maxLen)
{
    if(txt.value.length > (maxLen-1))
    {
        txt.value = txt.value.substring(0,maxLen);
        alert("Max "+maxLen+" char allowed");
        return false;
    }
}

function validatePasteText(txt,maxLen)
{
    var content =window.clipboardData.getData("Text");
    if(content.length > (maxLen))
    {
        txt.value = window.clipboardData.getData("Text").substring(0,maxLen);
        alert("Max "+maxLen+" char allowed");
        return false;
    }
}


function GroupBookingValidate()
{
    var FirstName  = document.getElementById("txtFirstName");
    if(trim(FirstName.value)=="")
    {
         alert("Please Enter First Name");		
		 FirstName.focus();
		 return false;
	} 
	
	var LastName  = document.getElementById("txtLastName");
    if(trim(LastName.value)=="")
    {
         alert("Please Enter Last Name");		
		 LastName.focus();
		 return false;
	} 

    var EMail  = document.getElementById("txtEMail");
    if(EMail.value=="")
    {
         alert("Please Enter E-mail ID");		
		 EMail.focus();
		 return false;
	} 
		 
	var regexp6 = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/
    if(EMail.value != "")
	 {
		if(EMail.value.search(regexp6)==-1)
		{
		    alert("Please Enter A Valid E-mail ID");				 
			 EMail.focus();
			 return false;
	    }		
	} 
	
	var PhoneNumber  = document.getElementById("txtPhone");
     if(trim(PhoneNumber.value) != "")
     {
        if (isNaN(PhoneNumber.value))
		{
			alert("Please Specify valid Phone Number ");
			PhoneNumber.value = "";
			PhoneNumber.focus();
			return false;
		} 
     }
     
     var txtFax  = document.getElementById("txtFax");
     if(trim(txtFax.value) != "")
     {
        if (isNaN(txtFax.value))
		{
			alert("Please Specify valid Fax Number ");
			txtFax.value = "";
			txtFax.focus();
			return false;
		} 
     }
     var ddlCountry  = document.getElementById("ddlCountryBD");
     if(ddlCountry.value=="0")
        {alert("Please select Booking Details Country");		
		 ddlCountry.focus();
		 return false;}	
		 
    var ddlCity  = document.getElementById("ddlCityBD");
     if(ddlCity.value=="0")
        {alert("Please select Booking Details City");		
		 ddlCity.focus();
		 return false;}	
    
     var ddlLocation  = document.getElementById("ddlLocation");
     if(ddlLocation.value=="0")
        {alert("Please select Booking Details Location");		
		 ddlLocation.focus();
		 return false;}	
		 
     var txtTtlCost  = document.getElementById("txtTtlCost");
     if(trim(txtTtlCost.value) == "")
     {        
		alert("Please specify total cost.");		
		txtTtlCost.focus();
		return false;		
     }
//     if(trim(txtTtlCost.value) != "")
//     {
//        if (!ValidAmt(trim(txtTtlCost.value)))
//		{
//			alert("Please specify valid total cost.");			
//			txtTtlCost.focus();
//			return false;
//		} 
//     }
     var txtPricePerPerson  = document.getElementById("txtPricePerPerson");
     if(trim(txtPricePerPerson.value) == "")
     {        
		alert("Please specify price per person.");		
		txtPricePerPerson.focus();
		return false;		
     }
//     if(trim(txtPricePerPerson.value) != "")
//     {
//        if (!ValidAmt(trim(txtPricePerPerson.value)))
//		{
//			alert("Please specify valid price per person.");			
//			txtPricePerPerson.focus();
//			return false;
//		} 
//     }
    return true;
}
function ValidAmt(str) {   
    return /^[0-9]+(\.[0-9]+)?$/.test(str);
}

// This function is for stripping leading and trailing spaces
function trim(str)
{ 
    if (str != null)
    {
        var i; 
        for (i=0; i<str.length; i++)
        { 
            if (str.charAt(i)!=" ")
            {
                str=str.substring(i,str.length);
                break; 
            }  
        }  

        for (i=str.length-1; i>=0; i--)
        {  
            if (str.charAt(i)!=" ")
            {   
                str=str.substring(0,i+1);  
                break;     
            }   
        }     

        if (str.charAt(0)==" ")
        {  
           return "";         
        } 
        else
        {     
            return str; 
        }    
    }
} 
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$   On Change City --> Load  Location  $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

