﻿
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$   Calender  Start New jquery $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
function LoadCheckInDate(dateChkIn, inst)
{   
    if(dateChkIn=='')
    {
        var CheckInDate=GetE("ddlchkinmonth").value+"/"+GetE("ddlchkindate").value+"/"+GetE("ddlchkinyear").value;
        GetE("CheckIn").value=CheckInDate;
        dateChkIn=CheckInDate;
    }
    
    ClientDateSelectionChangedCheckIn_sp(dateChkIn);
    
    GetE("CheckOut").value=GetE("ddlchkoutmonth").value+"/"+GetE("ddlchkoutdate").value+"/"+GetE("ddlchkoutyear").value;  
    
}
function LoadCheckOutDate(dateChkOut, inst)
{     
    var CheckInDate=GetE("ddlchkinmonth").value+"/"+GetE("ddlchkindate").value+"/"+GetE("ddlchkinyear").value;
    GetE("CheckIn").value=CheckInDate;
    
    if(dateChkOut=='')
    {
        var CheckOutDate=GetE("ddlchkoutmonth").value+"/"+GetE("ddlchkoutdate").value+"/"+GetE("ddlchkoutyear").value;
        GetE("CheckOut").value=CheckOutDate;
        dateChkOut=CheckOutDate;
    }  
    
    ClientDateSelectionChangedCheckOut_sp(dateChkOut);
}

// Refine Search
function LoadCheckInDateRefineSearch(dateChkIn, inst)
{   
    if(dateChkIn=='')
    {
        var CheckInDate=GetE("ddlchkinmonth").value+"/"+GetE("ddlchkindate").value+"/"+GetE("ddlchkinyear").value;
        GetE("CheckIn").value=CheckInDate;
        dateChkIn=CheckInDate;
    }
    
    ClientDateSelectionChanged_sp(dateChkIn);        
}

//Group Booking
function LoadCheckInDateGroupBooking(dateChkIn, inst)
{   
    if(dateChkIn=='')
    {
        var CheckInDate=GetE("ddlchkinmonth").value+"/"+GetE("ddlchkindate").value+"/"+GetE("ddlchkinyear").value;
        GetE("CheckIn").value=CheckInDate;
        dateChkIn=CheckInDate;
    }
    
    ClientDateSelectionChangedCheckIn_sp(dateChkIn);
    SetNoofNights_sp();
    
    GetE("CheckOut").value=GetE("ddlchkoutmonth").value+"/"+GetE("ddlchkoutdate").value+"/"+GetE("ddlchkoutyear").value;   
    
}

function LoadCheckOutDateGroupBooking(dateChkOut, inst)
{     
    var CheckInDate=GetE("ddlchkinmonth").value+"/"+GetE("ddlchkindate").value+"/"+GetE("ddlchkinyear").value;
    GetE("CheckIn").value=CheckInDate;
    
    if(dateChkOut=='')
    {
        var CheckOutDate=GetE("ddlchkoutmonth").value+"/"+GetE("ddlchkoutdate").value+"/"+GetE("ddlchkoutyear").value;
        GetE("CheckOut").value=CheckOutDate;
        dateChkOut=CheckOutDate;
    }  
    
    ClientDateSelectionChangedCheckOut_sp(dateChkOut);
    SetNoofNights_sp();
}

//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$   Calender  Start New  $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

function calendarPicker(DateInOut)
{
    var day =""; 
    var month = "";  
    var year = "";
    
    if(DateInOut=="1" || DateInOut=="3" || DateInOut=="4") // CheckIn
    {    
         day = document.getElementById("ddlchkindate").value;
         month = document.getElementById("ddlchkinmonth").value;
         year = document.getElementById("ddlchkinyear").value; 
    }
    else  if(DateInOut=="2" || DateInOut=="5") // CheckOut
    {    
          day = document.getElementById("ddlchkoutdate").value;
          month = document.getElementById("ddlchkoutmonth").value;
          year = document.getElementById("ddlchkoutyear").value;  
    }       
    var strTxtRef = month +"/"+day+"/"+year;
    
    window.open('Calendar.aspx?field=' + strTxtRef + '&InOut='+DateInOut+'&Id='+get_random()+'','calendarPopup','titlebar=no,addressbar=no,left=470,top=100,' + 
      'width=270,height=230,resizable=no');   
}  

function calendarPicker_sp(DateInOut)
{
    var day =""; 
    var month = "";  
    var year = "";
    
    if(DateInOut=="1" || DateInOut=="3") // CheckIn
    {    
         day = document.getElementById("ddlchkindate").value;
         month = document.getElementById("ddlchkinmonth").value;
         year = document.getElementById("ddlchkinyear").value; 
    }
    else  if(DateInOut=="2") // CheckOut
    {    
          day = document.getElementById("ddlchkoutdate").value;
          month = document.getElementById("ddlchkoutmonth").value;
          year = document.getElementById("ddlchkoutyear").value;  
    }       
    var strTxtRef = month +"/"+day+"/"+year;
    
    window.open('http://www.wonderlandhotels.com/Calendar.aspx?field=' + strTxtRef + '&InOut='+DateInOut+'&Id='+get_random()+'','calendarPopup','titlebar=no,addressbar=no,left=470,top=100,' +  'width=270,height=230,resizable=no');   
    //window.open('http://Localhost/Wonderland/Calendar.aspx?field=' + strTxtRef + '&InOut='+DateInOut+'&Id='+get_random()+'','calendarPopup','titlebar=no,addressbar=no,left=470,top=100,' +  'width=270,height=230,resizable=no');   
}  

function SelectedDateCalender(strSelectedDate,DateInOut)
{
    if(strSelectedDate == "")
    {
        alert('Please select a date');
        return false;
    }
    else if(strSelectedDate != "")
    {
        if(DateInOut=="1") // CheckIn
        {
            ClientDateSelectionChangedCheckIn_sp(strSelectedDate)
        }
        else if(DateInOut=="2") // CheckOut
        { 
            ClientDateSelectionChangedCheckOut_sp(strSelectedDate);
        }
        else if(DateInOut=="3") // CheckOut Refine Search
        {
            ClientDateSelectionChanged_sp(strSelectedDate);
        }
        else if(DateInOut=="4") // CheckIn Group Booking
        {
            ClientDateSelectionChangedCheckIn_sp(strSelectedDate)
            SetNoofNights_sp();
        }
        else if(DateInOut=="5") // CheckOut Group Booking
        {
            ClientDateSelectionChangedCheckOut_sp(strSelectedDate);
            SetNoofNights_sp();
        }
                        
        window.close();
    }    
        
    return true;
} 

function ClientDateSelectionChangedCheckIn_sp(date)
{  
   SetArrDateDropdowns_sp(date);
   
   ChangeChkOutDate_sp();   
}

function ClientDateSelectionChangedCheckOut_sp(date)
{    
    SetDepDateDropDowns_sp(date) ;
    
    ChangeChkInDate_sp();
}

function ClientDateSelectionChanged_sp(date)
{      
   SetArrDateDropdowns_sp(date);   
   ChangeDepDate_sp(); 
   
   if(document.getElementById("divSorting") != null)
        document.getElementById("divSorting").style.display = "";  
}

function ChangeDepDate_sp() // [BPS]
{
    var ArrDay = parseInt(document.getElementById("ddlchkindate").value,10)
    var ArrMonth = (document.getElementById("ddlchkinmonth").value)
    var ArrYear = parseInt(document.getElementById("ddlchkinyear").value,10)
    var DaysToAdd = parseInt(document.getElementById("ddlNts").value,10);
    
    var DepDate = new Date(ArrYear,ArrMonth-1,(ArrDay+DaysToAdd))
    document.getElementById("spChechOutDate").innerHTML = getMonthString(DepDate.getMonth()) + " " + DepDate.getDate() + ", " + DepDate.getFullYear();  
}

function ChangeChkOutDate_sp()
{
    var ArrDay = parseInt(document.getElementById("ddlchkindate").value,10)
    var ArrMonth = (document.getElementById("ddlchkinmonth").value)
    var ArrYear = parseInt(document.getElementById("ddlchkinyear").value,10)   
    var DepDate = new Date(ArrYear,ArrMonth-1,(ArrDay+1))
    var strNextDate = (DepDate.getMonth() + 1) + '/' + (DepDate.getDate()) + '/' + (DepDate.getFullYear())
    SetDepDateDropDowns_sp(strNextDate)
    GetDepdays_sp()
    GetArrdays_sp()
        
}
function SetDepDateDropDowns_sp(DateToShow)
{
    var positionFirstSlash = DateToShow.indexOf("/")  
	var positionLastSlash  = DateToShow.lastIndexOf("/") 
	var Month = DateToShow.substr(0,positionFirstSlash)
	if   (Month < 10)
		Month = "0" + Month
	var Day   = DateToShow.substring(positionFirstSlash+1,positionLastSlash)
	if (Day < 10)
		Day = "0" + Day  
	var Year  = DateToShow.slice(positionLastSlash+1)   
	document.getElementById("ddlchkoutmonth").options[Month-1].selected = true
    document.getElementById("ddlchkoutdate").options[Day-1].selected = true
    for(i=0;i<3;i++) 
		{
			if (document.getElementById("ddlchkoutyear").options[i].text == Year)
				document.getElementById("ddlchkoutyear").options[i].selected = true
		} 
}
function GetDepdays_sp()
{
    var DepDay = parseInt(document.getElementById("ddlchkoutdate").value,10)
    var DepMonth = (document.getElementById("ddlchkoutmonth").value)
    var DepYear = parseInt(document.getElementById("ddlchkoutyear").value,10)
    var DepDate = new Date(DepYear,DepMonth-1,DepDay)
    var Depdays = document.getElementById("lblchkoutday")
    switch(DepDate.getDay())
    {
        case 0:	Depdays.innerHTML="Sun" 
		break;
		case 1: Depdays.innerHTML="Mon"
		break;
		case 2:	Depdays.innerHTML="Tue"
		break;
		case 3:	Depdays.innerHTML="Wed"
		break;
		case 4:	Depdays.innerHTML="Thu"
		break;
		case 5:	Depdays.innerHTML="Fri"
		break;
		case 6:	Depdays.innerHTML="Sat"
		break;		
    }
}
function GetArrdays_sp()
{
    var ArrDay = parseInt(document.getElementById("ddlchkindate").value,10)
    var ArrMonth = (document.getElementById("ddlchkoutmonth").value)
    var ArrYear = parseInt(document.getElementById("ddlchkoutyear").value,10)
    var ArrDate = new Date(ArrYear,ArrMonth-1,ArrDay)
    var Arrdays = document.getElementById("lblchkinday")
    switch(ArrDate.getDay())
    {
        case 0:	Arrdays.innerHTML="Sun" 
		break;
		case 1: Arrdays.innerHTML="Mon"
		break;
		case 2:	Arrdays.innerHTML="Tue"
		break;
		case 3:	Arrdays.innerHTML="Wed"
		break;
		case 4:	Arrdays.innerHTML ="Thu"
		break;
		case 5:	Arrdays.innerHTML="Fri"
		break;
		case 6:	Arrdays.innerHTML="Sat"
		break;		
    }
}
function ChangeChkInDate_sp()
{
    var DepDate  = parseInt(document.getElementById("ddlchkoutdate").value,10)
	var DepMonth = (document.getElementById("ddlchkoutmonth").value)
	var DepYear  = parseInt(document.getElementById("ddlchkoutyear").value,10)
	var one_day  = 1000*60*60*24
	var depday   = new Date(DepYear,DepMonth,DepDate)
	var ArrDate  = parseInt(document.getElementById("ddlchkindate").value,10)
	var ArrMonth = (document.getElementById("ddlchkinmonth").value)
	var ArrYear  = parseInt(document.getElementById("ddlchkinyear").value,10)
	var Arrday	 = new Date(ArrYear,ArrMonth,ArrDate)	  

	GetArrdays_sp()
    GetDepdays_sp()   
}

function SetArrDateDropdowns_sp(DateToShow)
{
    var positionFirstSlash = DateToShow.indexOf("/")  
	var positionLastSlash  = DateToShow.lastIndexOf("/") 
	var Month = DateToShow.substr(0,positionFirstSlash)
	if   (Month < 10)
		Month = "0" + Month
	var Day   = DateToShow.substring(positionFirstSlash+1,positionLastSlash)
	if (Day < 10)
		Day = "0" + Day  
	var Year  = DateToShow.slice(positionLastSlash+1)   	
    document.getElementById("ddlchkinmonth").options[Month-1].selected = true
    document.getElementById("ddlchkindate").options[Day-1].selected = true
    for(i=0;i<3;i++) 
		{
			if (document.getElementById("ddlchkinyear").options[i].text == Year)
				document.getElementById("ddlchkinyear").options[i].selected = true
		} 		
}
function SetChkOutDate_sp()
{
     var len = 0;
        var i;
        var day = 0;
        var selDate  = parseInt(document.getElementById("ddlchkoutdate").value,10)
        var len = document.getElementById("ddlchkoutdate").length;
        for(i=0; i<len; i++)
        {
            //document.getElementById("ddlchkoutdate").options.remove(i)// 17June10
            document.getElementById("ddlchkoutdate").remove(i);
        }
     
        selDate = selDate - 1;
        var selMonth = document.getElementById("ddlchkoutmonth").value;
        var strMn = getMonthString(selMonth-1);
        var dayCount ;
        var i;
         if(strMn == 'Jan' || strMn == 'Mar' || strMn == 'May' || strMn == 'Jul' || strMn == 'Aug' || strMn == 'Oct' || strMn == 'Dec')
         {
	        dayCount = 0;
	        for( i=1; i<32; i++)
	        {
		        day = i;
		        if(day < 10 )
		        {day = "0"+day;}
			    document.getElementById("ddlchkoutdate")[dayCount] = new Option(day,i,true)
		        dayCount = dayCount + 1;
	        }        	
		    document.getElementById("ddlchkoutdate").options[selDate].selected = true
		   
          }
 
         if(strMn == 'Apr' || strMn == 'Jun' || strMn == 'Sep' || strMn == 'Nov')
         {
            dayCount = 0;
            for( i=1; i<31; i++)
            {
	            day = i;
	            if(day < 10 )
	            {day = "0"+day;}
	            document.getElementById("ddlchkoutdate")[dayCount] = new Option(day,i,true)
	            dayCount = dayCount + 1;
            }
        	
	        if(selDate == 31 || selDate == 30)
	        {
		        document.getElementById("ddlchkoutdate").options[29].selected = true
	        }
	        else
	        {
		        document.getElementById("ddlchkoutdate").options[selDate].selected = true
	        }
	
           }
     if(strMn == 'Feb')
     {
        var leap;
        leap = selMonth[1]%4;
    	
        dayCount = 0;
        if(leap == 0)
        {
	        for( i=1; i<30; i++)
	        {
		        day = i;
		        if(day < 10 )
		        {day = "0"+day;}
		        document.getElementById("ddlchkoutdate")[dayCount] = new Option(day,i,true)
		        dayCount = dayCount + 1;
	        }
    		
	        if(selDate == 31 || selDate == 30 || selDate == 29)
	        {
		        document.getElementById("ddlchkoutdate").options[28].selected = true
    		}
	        else
	        {
		        document.getElementById("ddlchkoutdate").options[selDate].selected = true
	        }
        }
        else
        {
	        for( i=1; i<29; i++)
	        {
		        day = i;
		        if(day < 10 )
		        {day = "0"+day;}
			    document.getElementById("ddlchkoutdate")[dayCount] = new Option(day,i,true)
		        dayCount = dayCount + 1;
	        }
	        if(selDate == 31 || selDate == 30 || selDate == 29 || selDate == 28)
	        {
		        document.getElementById("ddlchkoutdate").options[27].selected = true
	        }
	        else
	        {
		        document.getElementById("ddlchkoutdate").options[selDate].selected = true
	        }
        }
  }  
}
function SetChkInDate_sp()
{
        var len = 0;
        var i;
        var day = 0;
        var selDate  = parseInt(document.getElementById("ddlchkindate").value,10)
        var len = document.getElementById("ddlchkindate").length;
        for(i=0; i<len; i++)
        {
            //document.getElementById("ddlchkindate").options.remove(i)// 17June10
            document.getElementById("ddlchkindate").remove(i);
        }
     
        selDate = selDate - 1;
        var selMonth = document.getElementById("ddlchkinmonth").value;
        var strMn = getMonthString(selMonth-1);
        var dayCount ;
        var i;
         if(strMn == 'Jan' || strMn == 'Mar' || strMn == 'May' || strMn == 'Jul' || strMn == 'Aug' || strMn == 'Oct' || strMn == 'Dec')
         {
	        dayCount = 0;
	        for( i=1; i<32; i++)
	        {
		        day = i;
		        if(day < 10 )
		        {day = "0"+day;}
			    document.getElementById("ddlchkindate")[dayCount] = new Option(day,i,true)
		        dayCount = dayCount + 1;
	        }        	
		    document.getElementById("ddlchkindate").options[selDate].selected = true
		   
          }
 
         if(strMn == 'Apr' || strMn == 'Jun' || strMn == 'Sep' || strMn == 'Nov')
         {
            dayCount = 0;
            for( i=1; i<31; i++)
            {
	            day = i;
	            if(day < 10 )
	            {day = "0"+day;}
	            document.getElementById("ddlchkindate")[dayCount] = new Option(day,i,true)
	            dayCount = dayCount + 1;
            }
        	
	        if(selDate == 31 || selDate == 30)
	        {
		        document.getElementById("ddlchkindate").options[29].selected = true
	        }
	        else
	        {
		        document.getElementById("ddlchkindate").options[selDate].selected = true
	        }
	
           }
     if(strMn == 'Feb')
     {
        var leap;
        leap = selMonth[1]%4;
    	
        dayCount = 0;
        if(leap == 0)
        {
	        for( i=1; i<30; i++)
	        {
		        day = i;
		        if(day < 10 )
		        {day = "0"+day;}
		        document.getElementById("ddlchkindate")[dayCount] = new Option(day,i,true)
		        dayCount = dayCount + 1;
	        }
    		
	        if(selDate == 31 || selDate == 30 || selDate == 29)
	        {
		        document.getElementById("ddlchkindate").options[28].selected = true
    		}
	        else
	        {
		        document.getElementById("ddlchkindate").options[selDate].selected = true
	        }
        }
        else
        {
	        for( i=1; i<29; i++)
	        {
		        day = i;
		        if(day < 10 )
		        {day = "0"+day;}
			    document.getElementById("ddlchkindate")[dayCount] = new Option(day,i,true)
		        dayCount = dayCount + 1;
	        }
	        if(selDate == 31 || selDate == 30 || selDate == 29 || selDate == 28)
	        {
		        document.getElementById("ddlchkindate").options[27].selected = true
	        }
	        else
	        {
		        document.getElementById("ddlchkindate").options[selDate].selected = true
	        }
        }
  }         
}


function get_random()
{
    var ranNum= Math.floor(Math.random()*500000);
    return ranNum;
}

//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ end Calender New  $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$   Calender   Start  $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

/*function ClientShowing_CheckIn()
{
    var day = document.getElementById("ddlchkindate").value;
    var month = document.getElementById("ddlchkinmonth").value;
    var year = document.getElementById("ddlchkinyear").value;    
    var date = month +"/"+day+"/"+year;
    document.getElementById("txtCheckInDate").value = date;   
    
    if(document.getElementById("divSorting") != null)
        document.getElementById("divSorting").style.display = "none";  
  
}*/
/*function ClientShowing_CheckOut()
{
    var day = document.getElementById("ddlchkoutdate").value;
    var month = document.getElementById("ddlchkoutmonth").value;
    var year = document.getElementById("ddlchkoutyear").value;    
    var date = month +"/"+day+"/"+year;
    document.getElementById("txtCheckOutDate").value = date;     
  
}*/

/*function ClientDateSelectionChangedCheckIn()
{
   var date = document.getElementById("txtCheckInDate").value;   
   SetArrDateDropdowns(date);
   
   ChangeChkOutDate();   
}*/

/*function ClientDateSelectionChangedCheckOut()
{
    var date = document.getElementById("txtCheckOutDate").value;   
    SetDepDateDropDowns(date) ;
    
    ChangeChkInDate();
}*/

//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$   Calender   End  $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

function ChangeChkOutDate()
{
    var ArrDay = parseInt(document.getElementById("ddlchkindate").value,10)
    var ArrMonth = (document.getElementById("ddlchkinmonth").value)
    var ArrYear = parseInt(document.getElementById("ddlchkinyear").value,10)      
    var DepDate = new Date(ArrYear,ArrMonth-1,ArrDay)
    
    var today = new Date();    
    if((DepDate < today) && (ArrMonth == "12"))
    {
        ArrYear = ArrYear+1;
        for(i=0;i<3;i++) 
		{
			if (document.getElementById("ddlchkinyear").options[i].text == ArrYear)
				document.getElementById("ddlchkinyear").options[i].selected = true
		}
    }  
       
    DepDate = new Date(ArrYear,ArrMonth-1,(ArrDay+3))

    var strNextDate = (DepDate.getMonth() + 1) + '/' + (DepDate.getDate()) + '/' + (DepDate.getFullYear())
    
    SetChkOutDays(DepDate.getMonth()+1);
    
    SetDepDateDropDowns(strNextDate)
    GetDepdays()
    GetArrdays()
    
    // set CheckIn Date & CheckOut Date
    GetE("CheckIn").value=GetE("ddlchkinmonth").value+"/"+GetE("ddlchkindate").value+"/"+GetE("ddlchkinyear").value;
    GetE("CheckOut").value=GetE("ddlchkoutmonth").value+"/"+GetE("ddlchkoutdate").value+"/"+GetE("ddlchkoutyear").value;
    
    
//    // set CheckIn Date
//    var day = document.getElementById("ddlchkindate").value;
//    var month = document.getElementById("ddlchkinmonth").value;
//    var year = document.getElementById("ddlchkinyear").value;    
//    var date = month +"/"+day+"/"+year;
//    document.getElementById("txtCheckInDate").value = date;   
//    // end  CheckIn Date
    
}
function SetDepDateDropDowns(DateToShow)
{
    var positionFirstSlash = DateToShow.indexOf("/")  
	var positionLastSlash  = DateToShow.lastIndexOf("/") 
	var Month = DateToShow.substr(0,positionFirstSlash)
	if   (Month < 10)
		Month = "0" + Month
	var Day   = DateToShow.substring(positionFirstSlash+1,positionLastSlash)
	if (Day < 10)
		Day = "0" + Day  
	var Year  = DateToShow.slice(positionLastSlash+1)   
	document.getElementById("ddlchkoutmonth").options[Month-1].selected = true
    document.getElementById("ddlchkoutdate").options[Day-1].selected = true
    for(i=0;i<3;i++) 
		{
			if (document.getElementById("ddlchkoutyear").options[i].text == Year)
				document.getElementById("ddlchkoutyear").options[i].selected = true
		} 
}
function GetDepdays()
{
    var DepDay = parseInt(document.getElementById("ddlchkoutdate").value,10)
    var DepMonth = (document.getElementById("ddlchkoutmonth").value)
    var DepYear = parseInt(document.getElementById("ddlchkoutyear").value,10)
    var DepDate = new Date(DepYear,DepMonth-1,DepDay)
    var Depdays = document.getElementById("lblchkoutday")
    switch(DepDate.getDay())
    {
        case 0:	Depdays.innerHTML="Sun" 
		break;
		case 1: Depdays.innerHTML="Mon"
		break;
		case 2:	Depdays.innerHTML="Tue"
		break;
		case 3:	Depdays.innerHTML="Wed"
		break;
		case 4:	Depdays.innerHTML="Thu"
		break;
		case 5:	Depdays.innerHTML="Fri"
		break;
		case 6:	Depdays.innerHTML="Sat"
		break;		
    }
}
function GetArrdays()
{
    var ArrDay = parseInt(document.getElementById("ddlchkindate").value,10)
    var ArrMonth = (document.getElementById("ddlchkinmonth").value)
    var ArrYear = parseInt(document.getElementById("ddlchkinyear").value,10)
    var ArrDate = new Date(ArrYear,ArrMonth-1,ArrDay)
    var Arrdays = document.getElementById("lblchkinday")
    switch(ArrDate.getDay())
    {
        case 0:	Arrdays.innerHTML="Sun" 
		break;
		case 1: Arrdays.innerHTML="Mon"
		break;
		case 2:	Arrdays.innerHTML="Tue"
		break;
		case 3:	Arrdays.innerHTML="Wed"
		break;
		case 4:	Arrdays.innerHTML ="Thu"
		break;
		case 5:	Arrdays.innerHTML="Fri"
		break;
		case 6:	Arrdays.innerHTML="Sat"
		break;		
    }
}
function ChangeChkInDate()
{
    var DepDate  = parseInt(document.getElementById("ddlchkoutdate").value,10)
	var DepMonth = (document.getElementById("ddlchkoutmonth").value)
	var DepYear  = parseInt(document.getElementById("ddlchkoutyear").value,10)
	var one_day  = 1000*60*60*24
	var depday   = new Date(DepYear,DepMonth,DepDate)
	var ArrDate  = parseInt(document.getElementById("ddlchkindate").value,10)
	var ArrMonth = (document.getElementById("ddlchkinmonth").value)
	var ArrYear  = parseInt(document.getElementById("ddlchkinyear").value,10)
	var Arrday	 = new Date(ArrYear,ArrMonth,ArrDate)	  

	GetArrdays()
    GetDepdays()
    
    // set CheckIn Date & CheckOut Date
    GetE("CheckIn").value=GetE("ddlchkinmonth").value+"/"+GetE("ddlchkindate").value+"/"+GetE("ddlchkinyear").value;
    GetE("CheckOut").value=GetE("ddlchkoutmonth").value+"/"+GetE("ddlchkoutdate").value+"/"+GetE("ddlchkoutyear").value;
    
    
//    // Set ChechOut Date 
//    var day = document.getElementById("ddlchkoutdate").value;
//    var month = document.getElementById("ddlchkoutmonth").value;
//    var year = document.getElementById("ddlchkoutyear").value;    
//    var date = month +"/"+day+"/"+year;
//    document.getElementById("txtCheckOutDate").value = date;
//    // end CheckOut Date
    
}

function SetArrDateDropdowns(DateToShow)
{
    var positionFirstSlash = DateToShow.indexOf("/")  
	var positionLastSlash  = DateToShow.lastIndexOf("/") 
	var Month = DateToShow.substr(0,positionFirstSlash)
	if   (Month < 10)
		Month = "0" + Month
	var Day   = DateToShow.substring(positionFirstSlash+1,positionLastSlash)
	if (Day < 10)
		Day = "0" + Day  
	var Year  = DateToShow.slice(positionLastSlash+1)   	
    document.getElementById("ddlchkinmonth").options[Month-1].selected = true
    document.getElementById("ddlchkindate").options[Day-1].selected = true
    for(i=0;i<3;i++) 
		{
			if (document.getElementById("ddlchkinyear").options[i].text == Year)
				document.getElementById("ddlchkinyear").options[i].selected = true
		} 		
}
function SetChkOutDate()
{
     var len = 0;
        var i;
        var day = 0;
        var selDate  = parseInt(document.getElementById("ddlchkoutdate").value,10)
        var len = document.getElementById("ddlchkoutdate").length;
        for(i=0; i<len; i++)
        {
            //document.getElementById("ddlchkoutdate").options.remove(i) // 17June10
            document.getElementById("ddlchkoutdate").remove(i);
        }
     
        selDate = selDate - 1;
        var selMonth = document.getElementById("ddlchkoutmonth").value;
        var strMn = getMonthString(selMonth-1);
        var dayCount ;
        var i;
         if(strMn == 'Jan' || strMn == 'Mar' || strMn == 'May' || strMn == 'Jul' || strMn == 'Aug' || strMn == 'Oct' || strMn == 'Dec')
         {
	        dayCount = 0;
	        for( i=1; i<32; i++)
	        {
		        day = i;
		        if(day < 10 )
		        {day = "0"+day;}
			    document.getElementById("ddlchkoutdate")[dayCount] = new Option(day,i,true)
		        dayCount = dayCount + 1;
	        }        	
		    document.getElementById("ddlchkoutdate").options[selDate].selected = true
		   
          }
 
         if(strMn == 'Apr' || strMn == 'Jun' || strMn == 'Sep' || strMn == 'Nov')
         {
            dayCount = 0;
            for( i=1; i<31; i++)
            {
	            day = i;
	            if(day < 10 )
	            {day = "0"+day;}
	            document.getElementById("ddlchkoutdate")[dayCount] = new Option(day,i,true)
	            dayCount = dayCount + 1;
            }
        	
	        if(selDate == 31 || selDate == 30)
	        {
		        document.getElementById("ddlchkoutdate").options[29].selected = true
	        }
	        else
	        {
		        document.getElementById("ddlchkoutdate").options[selDate].selected = true
	        }
	
           }
     if(strMn == 'Feb')
     {
        var leap;
        leap = selMonth[1]%4;
    	
        dayCount = 0;
        if(leap == 0)
        {
	        for( i=1; i<30; i++)
	        {
		        day = i;
		        if(day < 10 )
		        {day = "0"+day;}
		        document.getElementById("ddlchkoutdate")[dayCount] = new Option(day,i,true)
		        dayCount = dayCount + 1;
	        }
    		
	        if(selDate == 31 || selDate == 30 || selDate == 29)
	        {
		        document.getElementById("ddlchkoutdate").options[28].selected = true
    		}
	        else
	        {
		        document.getElementById("ddlchkoutdate").options[selDate].selected = true
	        }
        }
        else
        {
	        for( i=1; i<29; i++)
	        {
		        day = i;
		        if(day < 10 )
		        {day = "0"+day;}
			    document.getElementById("ddlchkoutdate")[dayCount] = new Option(day,i,true)
		        dayCount = dayCount + 1;
	        }
	        if(selDate == 31 || selDate == 30 || selDate == 29 || selDate == 28)
	        {
		        document.getElementById("ddlchkoutdate").options[27].selected = true
	        }
	        else
	        {
		        document.getElementById("ddlchkoutdate").options[selDate].selected = true
	        }
        }
  }  
}
function SetChkInDate()
{
        var len = 0;
        var i;
        var day = 0;
        var selDate  = parseInt(document.getElementById("ddlchkindate").value,10)
        var len = document.getElementById("ddlchkindate").length;
        for(i=0; i<len; i++)
        {
            //document.getElementById("ddlchkindate").options.remove(i) // 17June10
            document.getElementById("ddlchkindate").remove(i);
        }
     
        selDate = selDate - 1;
        var selMonth = document.getElementById("ddlchkinmonth").value;
        var strMn = getMonthString(selMonth-1);
        var dayCount ;
        var i;
         if(strMn == 'Jan' || strMn == 'Mar' || strMn == 'May' || strMn == 'Jul' || strMn == 'Aug' || strMn == 'Oct' || strMn == 'Dec')
         {
	        dayCount = 0;
	        for( i=1; i<32; i++)
	        {
		        day = i;
		        if(day < 10 )
		        {day = "0"+day;}
			    document.getElementById("ddlchkindate")[dayCount] = new Option(day,i,true)
		        dayCount = dayCount + 1;
	        }        	
		    document.getElementById("ddlchkindate").options[selDate].selected = true
		   
          }
 
         if(strMn == 'Apr' || strMn == 'Jun' || strMn == 'Sep' || strMn == 'Nov')
         {
            dayCount = 0;
            for( i=1; i<31; i++)
            {
	            day = i;
	            if(day < 10 )
	            {day = "0"+day;}
	            document.getElementById("ddlchkindate")[dayCount] = new Option(day,i,true)
	            dayCount = dayCount + 1;
            }
        	
	        if(selDate == 31 || selDate == 30)
	        {
		        document.getElementById("ddlchkindate").options[29].selected = true
	        }
	        else
	        {
		        document.getElementById("ddlchkindate").options[selDate].selected = true
	        }
	
           }
     if(strMn == 'Feb')
     {
        var leap;
        leap = selMonth[1]%4;
    	
        dayCount = 0;
        if(leap == 0)
        {
	        for( i=1; i<30; i++)
	        {
		        day = i;
		        if(day < 10 )
		        {day = "0"+day;}
		        document.getElementById("ddlchkindate")[dayCount] = new Option(day,i,true)
		        dayCount = dayCount + 1;
	        }
    		
	        if(selDate == 31 || selDate == 30 || selDate == 29)
	        {
		        document.getElementById("ddlchkindate").options[28].selected = true
    		}
	        else
	        {
		        document.getElementById("ddlchkindate").options[selDate].selected = true
	        }
        }
        else
        {
	        for( i=1; i<29; i++)
	        {
		        day = i;
		        if(day < 10 )
		        {day = "0"+day;}
			    document.getElementById("ddlchkindate")[dayCount] = new Option(day,i,true)
		        dayCount = dayCount + 1;
	        }
	        if(selDate == 31 || selDate == 30 || selDate == 29 || selDate == 28)
	        {
		        document.getElementById("ddlchkindate").options[27].selected = true
	        }
	        else
	        {
		        document.getElementById("ddlchkindate").options[selDate].selected = true
	        }
        }
  }         
}

function SetChkOutDays(month)
{
     var len = 0;
        var i;
        var day = 0;
        var selDate  = parseInt(document.getElementById("ddlchkoutdate").value,10)
        var len = document.getElementById("ddlchkoutdate").length;        
        for(i=0; i<len; i++)
        {
            //document.getElementById("ddlchkoutdate").options.remove(i) // 17June10
            document.getElementById("ddlchkoutdate").remove(i);
        }
     
        selDate = selDate - 1;
        //var selMonth = document.getElementById("ddlchkoutmonth").value;
        var selMonth = month;
        
        var strMn = getMonthString(selMonth-1);
        var dayCount ;
        var i;
         if(strMn == 'Jan' || strMn == 'Mar' || strMn == 'May' || strMn == 'Jul' || strMn == 'Aug' || strMn == 'Oct' || strMn == 'Dec')
         {
	        dayCount = 0;
	        for( i=1; i<32; i++)
	        {
		        day = i;
		        if(day < 10 )
		        {day = "0"+day;}
			    document.getElementById("ddlchkoutdate")[dayCount] = new Option(day,i,true)
		        dayCount = dayCount + 1;
	        }        	
		    document.getElementById("ddlchkoutdate").options[selDate].selected = true
		   
          }
 
         if(strMn == 'Apr' || strMn == 'Jun' || strMn == 'Sep' || strMn == 'Nov')
         {
            dayCount = 0;
            for( i=1; i<31; i++)
            {
	            day = i;
	            if(day < 10 )
	            {day = "0"+day;}
	            document.getElementById("ddlchkoutdate")[dayCount] = new Option(day,i,true)
	            dayCount = dayCount + 1;
            }
        	
	        if(selDate == 31 || selDate == 30)
	        {
		        document.getElementById("ddlchkoutdate").options[29].selected = true
	        }
	        else
	        {
		        document.getElementById("ddlchkoutdate").options[selDate].selected = true
	        }
	
           }
     if(strMn == 'Feb')
     {
        var leap;
        leap = selMonth[1]%4;
    	
        dayCount = 0;
        if(leap == 0)
        {
	        for( i=1; i<30; i++)
	        {
		        day = i;
		        if(day < 10 )
		        {day = "0"+day;}
		        document.getElementById("ddlchkoutdate")[dayCount] = new Option(day,i,true)
		        dayCount = dayCount + 1;
	        }
    		
	        if(selDate == 31 || selDate == 30 || selDate == 29)
	        {
		        document.getElementById("ddlchkoutdate").options[28].selected = true
    		}
	        else
	        {
		        document.getElementById("ddlchkoutdate").options[selDate].selected = true
	        }
        }
        else
        {
	        for( i=1; i<29; i++)
	        {
		        day = i;
		        if(day < 10 )
		        {day = "0"+day;}
			    document.getElementById("ddlchkoutdate")[dayCount] = new Option(day,i,true)
		        dayCount = dayCount + 1;
	        }
	        if(selDate == 31 || selDate == 30 || selDate == 29 || selDate == 28)
	        {
		        document.getElementById("ddlchkoutdate").options[27].selected = true
	        }
	        else
	        {
		        document.getElementById("ddlchkoutdate").options[selDate].selected = true
	        }
        }
  }  
}

function getMonthString(mNo)
{
	var str;
	if(mNo == 0)
	str = "Jan";
	if(mNo == 1)
	str = "Feb";
	if(mNo == 2)
	str = "Mar";
	if(mNo == 3)
	str = "Apr";
	if(mNo == 4)
	str = "May";
	if(mNo == 5)
	str = "Jun";
	if(mNo == 6)
	str = "Jul";
	if(mNo == 7)
	str = "Aug";
	if(mNo == 8)
	str = "Sep";
	if(mNo == 9)
	str = "Oct";
	if(mNo == 10)
	str = "Nov";
	if(mNo == 11)
	str = "Dec";		
	return str;
}


//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

function ChangeDepDate() // [BPS]
{
    var ArrDay = parseInt(document.getElementById("ddlchkindate").value,10)
    var ArrMonth = (document.getElementById("ddlchkinmonth").value)
    var ArrYear = parseInt(document.getElementById("ddlchkinyear").value,10)    
    
    var DepDate = new Date(ArrYear,ArrMonth-1,ArrDay)    
    var today = new Date();    
    if((DepDate < today) && (ArrMonth == "12"))
    {
        ArrYear = ArrYear+1;
        for(i=0;i<3;i++) 
		{
			if (document.getElementById("ddlchkinyear").options[i].text == ArrYear)
				document.getElementById("ddlchkinyear").options[i].selected = true
		}
    }
    
    // set CheckIn Date & CheckOut Date
    GetE("CheckIn").value=GetE("ddlchkinmonth").value+"/"+GetE("ddlchkindate").value+"/"+GetE("ddlchkinyear").value;        
    
    var DaysToAdd = parseInt(document.getElementById("ddlNts").value,10);
    
    DepDate = new Date(ArrYear,ArrMonth-1,(ArrDay+DaysToAdd))
    document.getElementById("spChechOutDate").innerHTML = getMonthString(DepDate.getMonth()) + " " + DepDate.getDate() + ", " + DepDate.getFullYear();  
}

/*function ClientDateSelectionChanged()
{
   var date = document.getElementById("txtCheckInDate").value;   
   SetArrDateDropdowns(date);   
   ChangeDepDate(); 
   
   if(document.getElementById("divSorting") != null)
        document.getElementById("divSorting").style.display = "";  
}*/

/*function ClientHiding_cal()
{
    if(document.getElementById("divSorting") != null)
        document.getElementById("divSorting").style.display = ""; 
}*/



//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$   Set CheckOut date By No of Nights In Amend page  $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

function ChkOutDate_Change()
{
    var ArrDay = parseInt(document.getElementById("ddlchkindate").value,10)
    var ArrMonth = (document.getElementById("ddlchkinmonth").value)
    var ArrYear = parseInt(document.getElementById("ddlchkinyear").value,10)      
    
    var DaysToAdd    = parseInt(document.getElementById("ddlNoofNights").value,10)
    
    var DepDate = new Date(ArrYear,ArrMonth-1,(ArrDay+DaysToAdd))
    var strNextDate = (DepDate.getMonth() + 1) + '/' + (DepDate.getDate()) + '/' + (DepDate.getFullYear())
    SetDepDateDropDowns(strNextDate)
    GetDepdays()
    GetArrdays() 
    
    // set CheckIn Date & CheckOut Date
    GetE("CheckIn").value=GetE("ddlchkinmonth").value+"/"+GetE("ddlchkindate").value+"/"+GetE("ddlchkinyear").value;
    GetE("CheckOut").value=GetE("ddlchkoutmonth").value+"/"+GetE("ddlchkoutdate").value+"/"+GetE("ddlchkoutyear").value;      
}

function SetNoofNights_sp()
{
    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);    
}
