
		
		var startDate;
		var endDate;
		var callbacks = 0;

		var dte =  new Date();
        var exCode= document.getElementById('EXCode').value;
        
        if(exCode=='bookadmin')currdatex = dte.getDate();
        else currdatex = dte.getDate()+2;
        
		currmonthx = dte.getMonth();
		curryearx = dte.getFullYear();
		if(currdatex < 10)
			currdatex = '0'+currdatex;
		if(currmonthx < 10)
			currmonthx = '0'+currmonthx;
		var dteStart = new Date(curryearx,currmonthx,currdatex);
		startDate = dteStart;
		var ONEDAY = 3600 * 24;

		function resetDates() {
			startDate = endDate = null;
			Zapatec.Utils.writeCookie(window.location.href + "--" + "date_img",value="",null, '/');
			Zapatec.Utils.writeCookie(window.location.href + "--" + "date_img1",value="",null, '/');
		}
		/*
		 * Given two dates (in seconds) find out if date1 is bigger, date2 is bigger or
		 * they're the same, taking only the dates, not the time into account.
		 * In other words, different times on the same date returns equal.
		 * returns -1 for date1 bigger, 1 for date2 is bigger 0 for equal
		 */

		function compareDatesOnly(date1, date2) {
			var year1 = date1.getYear();
			var year2 = date2.getYear();
			var month1 = date1.getMonth();
			var month2 = date2.getMonth();
			var day1 = date1.getDate();
			var day2 = date2.getDate();

			if (year1 > year2) {
				return -1;
			}
			if (year2 > year1) {
				return 1;
			}

			//years are equal
			if (month1 > month2) {
				return -1;
			}
			if (month2 > month1) {
				return 1;
			}

			//years and months are equal
			if (day1 > day2) {
				return -1;
			}
			if (day2 > day1) {
				return 1;
			}

			//days are equal
			return 0;

			/* Can't do this because of timezone issues
			var days1 = Math.floor(date1.getTime()/Date.DAY);
			var days2 = Math.floor(date2.getTime()/Date.DAY);
			return (days1 - days2);
			*/
		}

		function filterDates1(cal) {
			startDate = cal.config.date;
			/* If they haven't chosen an
			end date before we'll set it to the same date as the start date This
			way if the user scrolls in the start date 5 months forward, they don't
			need to do it again for the end date.
			*/

			
			var docForm=document.Search_Accom_Form;
			/* If they haven't chosen an 
			end date before we'll set it to the same date as the start date This
			way if the user scrolls in the start date 5 months forward, they don't
			need to do it again for the end date.
			*/
			var nights = docForm.nights.options[docForm.nights.selectedIndex].value;
			//alert(nights);
			var currdate = startDate.getDate()+ parseInt(nights);
			var currmonth = startDate.getMonth();
			var curryear = startDate.getFullYear();
			var dteNow = new Date(curryear,currmonth,currdate);
			
			currdate = dteNow.getDate();
			currmonth = dteNow.getMonth()+1;
			curryear = dteNow.getFullYear();
			if(currdate < 10)
				currdate = '0'+currdate;
			if(currmonth < 10)
				currmonth = '0'+currmonth;
			var currdates = currdate+'/'+currmonth+'/'+curryear;
			
			document.getElementById("RepDate").value=currdates;
		}

		function filterDates2(cal) {
			endDate = cal.config.date;
			CheckInChange2();
		}

		/*
		* Both functions disable and hilight dates.
		*/

		/*
		* Can't choose days after the
		* end date if it is choosen, hilights start and end dates with one style and dates between them with another
		*/
		function dateInRange1(date) {			

			//disable days prior to today
			var today = dteStart;
			var compareToday = compareDatesOnly(date, today);
			if (compareToday > 0) {
				return(true);
			}

			//all other days are enabled
			return false;
			//alert(ret + " " + today + ":" + date + ":" + compareToday + ":" + days1 + ":" + days2);
			return(ret);
		}

		/*
		* Can't choose days before the
		* start date if it is choosen, hilights start and end dates with one style and dates between them with another
		*/
		function dateInRange2(date) {
			if (startDate != null) {
				// Disable dates before start date
				var compareDays = compareDatesOnly(startDate, date);
				if  (compareDays < 0) {
					return (true);
				}

				// Hilight end date with "edges" style
				if  (compareDays == 0) {
					{return "edges";}
				}

				// Hilight inner dates with "between" style
				if ((endDate != null) && (date > startDate) && (date < endDate)) {
					return "between";
				}
			}

			var now = new Date();
			if (compareDatesOnly(now, date) < 0) {
				return (true);
			}

			//all other days are enabled
			return false;
		}
		
	
		var cal = new Zapatec.Calendar({
		
			inputField     :    "DepDate",   // id of the input field
			button         :    "date_img",  // What will trigger the popup of the calendar
			ifFormat       :    "%d/%m/%Y",
			align             : "CR",
			themeSize         : "small",
			electric       :     false,			
			numberMonths   :    2,
			weekNumbers    :    false,
			noHelp		   :    true,			
			dateStatusFunc :    dateInRange1, //the function to call
			onUpdate       :    filterDates1,			
			theme          :    "aqua"

		});
		
		
		var cal1 = new Zapatec.Calendar({
			
			inputField     :    "RepDate",   // id of the input field
			button         :    "date_img1",  // What will trigger the popup of the calendar
			ifFormat       :    "%d/%m/%Y", 			
			electric       :     false,
			numberMonths   :    2,
			align             : "CR",
			themeSize         : "small",
			weekNumbers    :    false,
			noHelp		   :    true,
			dateStatusFunc :    dateInRange2, //the function to call
			onUpdate       :    filterDates2,
			
			theme          :    "aqua"

			});

		SetRooms();
		function GetSecondOption()
		{
			var docForm=document.Search_Accom_Form;
			docForm.Resort.options.length=resortsCodes[docForm.Country.selectedIndex].length;
			for(i=0;i<resortsCodes[docForm.Country.selectedIndex].length;i++)
			{
				docForm.Resort.options[i].value=resortsCodes[docForm.Country.selectedIndex][i];
				docForm.Resort.options[i].text=resortsNames[docForm.Country.selectedIndex][i];
			}
		}
		
		function SetRooms()
		{	
			
			var Child1=Search_Accom_Form.elements['Child1'].options[Search_Accom_Form.elements['Child1'].selectedIndex].value;
			if(Child1==0)
			{
				Search_Accom_Form.elements['Child1Age1'].disabled=1;
			}
			if(Child1==0 || Child1==1)
			{
				Search_Accom_Form.elements['Child1Age2'].disabled=1;
			}
			var Child2=Search_Accom_Form.elements['Child2'].options[Search_Accom_Form.elements['Child2'].selectedIndex].value;
			if(Child2==0)
			{
				Search_Accom_Form.elements['Child2Age1'].disabled=1;
			}
			if(Child2==0 || Child2==1)
			{
				Search_Accom_Form.elements['Child2Age2'].disabled=1;
			}
			var Child3=Search_Accom_Form.elements['Child3'].options[Search_Accom_Form.elements['Child3'].selectedIndex].value;
			if(Child3==0)
			{
				Search_Accom_Form.elements['Child3Age1'].disabled=1;
			}
			if(Child3==0 || Child3==1)
			{
				Search_Accom_Form.elements['Child3Age2'].disabled=1;
			}
			
			try
			{
				for(var i=0;i<3;i++)
				{
					if(i<(Search_Accom_Form.rooms.selectedIndex+1))
					{
						Search_Accom_Form.elements['Adult'+(i+1)].disabled=0;
						Search_Accom_Form.elements['Child'+(i+1)].disabled=0;	
						if(i>0)
						document.getElementById('room'+(i+1)).style.display="";						
						
					}
					else
					{
						Search_Accom_Form.elements['Adult'+(i+1)].disabled=1;
						Search_Accom_Form.elements['Child'+(i+1)].disabled=1;
						if(i>0)
							document.getElementById('room'+(i+1)).style.display="none";	
						
					}
				}
			}
			catch(e)
			{}
			
		}
		
		function CalculateChildInRoom(room)
		{
			var Adult=Search_Accom_Form.elements['Adult'+room].options[Search_Accom_Form.elements['Adult'+room].selectedIndex].value;
			Search_Accom_Form.elements['Child'+room].options.length=7-Adult;
			for(var i=1;i<(7-Adult);i++)
			{
				Search_Accom_Form.elements['Child'+room].options[i].text=i;
				Search_Accom_Form.elements['Child'+room].options[i].value=i;
			}
		}
		function CalculateAdultInRoom(room)
		{
			var Child=Search_Accom_Form.elements['Child'+room].options[Search_Accom_Form.elements['Child'+room].selectedIndex].value;
			
			
			if(Child==1)
			{
				Search_Accom_Form.elements['Child'+room+'Age1'].disabled=0;
				Search_Accom_Form.elements['Child'+room+'Age2'].disabled=1;
			}
			if(Child>=2)
			{
				Search_Accom_Form.elements['Child'+room+'Age1'].disabled=0;
				Search_Accom_Form.elements['Child'+room+'Age2'].disabled=0;
			}
			if(Child==0)
			{
				Search_Accom_Form.elements['Child'+room+'Age1'].disabled=1;
				Search_Accom_Form.elements['Child'+room+'Age2'].disabled=1;
			}
		}
		function AddDays(strDate,iDays){
			return new Date(strDate.valueOf() + iDays*(24 * 60 * 60 * 1000));
		};
		function CheckInChange1()
		{
			var CheckIn=document.getElementById('DepDate');
			var nights = document.Search_Accom_Form.nights.options[document.Search_Accom_Form.nights.selectedIndex].value;
		
			var currdate = CheckIn.value.substr(0,2);
			var currmonth = CheckIn.value.substr(3,2)-1;
			var curryear = CheckIn.value.substr(6,4);
			var dteNow = new Date(curryear,currmonth,currdate);	
            
            currdate = dteNow.getDate()+ parseInt(nights);
			currmonth = dteNow.getMonth();
			curryear = dteNow.getFullYear();
			dteNow = new Date(curryear,currmonth,currdate);
			newDate = dteNow; 
			
			//newDate = AddDays(dteNow, nights);
			
			currdate = newDate.getDate();
			currmonth = newDate.getMonth()+1;
			if(currdate < 10)
				currdate = '0'+currdate;
			if(currmonth < 10)
				currmonth = '0'+currmonth;
			curryear = newDate.getFullYear();
			
			if (curryear == newDate.getFullYear())
			{
			
				var currdates = currdate+'/'+currmonth+'/'+curryear;
				//alert(currdates);			
				document.getElementById("RepDate").value=currdates;
				
			}
			else 
			{
				alert('Invalid date format');
		        return(false);

			}

		}
		
		function CheckInChange2()
		{
			var CheckIn=document.getElementById('DepDate');
			var CheckOut=document.getElementById('RepDate');
			
			//var nights = document.Search_Accom_Form.nights.options[document.Search_Accom_Form.nights.selectedIndex].value;
		
			var currdate = (CheckIn.value.substr(0,2));
			var currmonth = (CheckIn.value.substr(3,2))-1;
			var curryear = (CheckIn.value.substr(6,4));
			var dteNow = new Date(curryear,currmonth,currdate);

			var currdate2 = (CheckOut.value.substr(0,2));
			var currmonth2 = (CheckOut.value.substr(3,2))-1;
			var curryear2 = (CheckOut.value.substr(6,4));
			var dteNow2 = new Date(curryear2,currmonth2,currdate2);

			
			var one_day=1000*60*60*24;

			//Calculate difference btw the two dates, and convert to days
			var calNights= Math.ceil((dteNow2.getTime()-dteNow.getTime())/(one_day));
			if(calNights > 28)
			{ 
				alert('Your period of stay should not be longer than 28 nights if you wish to book more than 28 nights,\n please send us an e-mail at customerservices@bookandpack.com');
				CheckInChange1();
			}
			else document.getElementById('nights').value=calNights;
		}				
		
	
	
    
