
	 YAHOO.namespace("example.calendar");
     
	 function handleSelect(type,args,obj) {
					
				var dates = args[0]; 
				var date = dates[0];
				var year = date[0]-1, month = date[1], day = date[2];
				
				var sl_from_month = document.getElementById("sl_from_month");
				var sl_from_day = document.getElementById("sl_from_day");
				var sl_from_year = document.getElementById("sl_from_year");

				//var sl_To_Month = document.getElementById("sl_To_Month");
					var sl_To_Month =document.details.slToMonth;
					//var sl_To_Day = document.getElementById("sl_To_Day");
					var sl_To_Day= document.details.slToDay;
					//var sl_To_Year= document.getElementById("sl_To_Year");
					var sl_To_Year= document.details.slToYear;
					
			     if ((month==4||month==6||month==9||month==11) && (day>23)) 
				 {
				  sl_To_Day.options[30] = new Option('31','31');
				   sl_To_Day.selectedIndex=(day+6)-30;
				   sl_To_Month.selectedIndex= month;
				   sl_from_month.selectedIndex = month-1;
				   sl_from_day.selectedIndex = day-1;
				 }
				 else if ((month==4||month==6||month==9||month==11) && (day<24))
			     {
				   sl_from_day.options[30]=null
				   sl_To_Day.selectedIndex=day+6;
				   sl_To_Month.selectedIndex= month-1;
				   sl_from_month.selectedIndex = month-1;
				   sl_from_day.selectedIndex = day-1;
				 }
				 else if ((month==1||month==3||month==5||month==7||month==8||month==10) && (day>24))
				 {
				   document.getElementById('sl_from_day').options[30] = new Option('31','31');
				   sl_To_Day.options[30] = new Option('31','31');
				   sl_To_Day.selectedIndex=(day+6)-31;
				   sl_To_Month.selectedIndex= month;
				   sl_from_month.selectedIndex = month-1;
				   sl_from_day.selectedIndex = day-1;
				 } 
				 else if ((month==1||month==3||month==5||month==7||month==8||month==10||month==12) && (day<25))
			     {
				   document.getElementById('sl_from_day').options[30] = new Option('31','31');
				   sl_To_Day.options[30] = new Option('31','31');
				   sl_To_Day.selectedIndex=day+6;
				   sl_To_Month.selectedIndex= month-1;
				   sl_from_month.selectedIndex = month-1;
				   sl_from_day.selectedIndex = day-1;
				 }
				 else if ((month==12) && (day>24))
				 {
				  document.getElementById('sl_from_day').options[30] = new Option('31','31');
				  sl_To_Day.options[30] = new Option('31','31');
				  sl_from_month.selectedIndex = month-1;
				  sl_from_day.selectedIndex = day-1;
				  sl_To_Month.selectedIndex = 0;
				  sl_To_Day.selectedIndex = (day+6)-31;
				  sl_To_Year.selectedIndex = 1;
				 }
				 
				 if ( (month==2)&& (day>21))
			    {
				 sl_To_Day.options[28] = new Option('29','29');
				 sl_To_Day.options[29] = new Option('30','30');
				 sl_To_Day.options[30] = new Option('31','31');
				 sl_from_month.selectedIndex = month-1;
				 sl_from_day.selectedIndex = day-1;
				 sl_To_Month.selectedIndex = month;
				 sl_To_Day.selectedIndex = (day+6)-28;	
				}
			    else if ( (month==2)&& (day<22))
				{
				 document.getElementById('sl_from_day').options[30]=null
				 sl_To_Day.options[30]=null
				 sl_from_month.selectedIndex = month-1;
				 sl_from_day.selectedIndex = day-1;
				 sl_To_Month.selectedIndex = month-1;
				 sl_To_Day.selectedIndex = day+6;
				}
				 updateCa2();
				  minimumdate();
								
			    
				 for (var y=0;y<sl_from_year.options.length;y++) {
						if (sl_from_year.options[y].text == year) {
							sl_from_year.selectedIndex = y+1;
							break;
						}
					}
					YAHOO.example.calendar.cal1.hide();
			}
				
				
			function updateCal() {
			
					var sl_from_month = document.getElementById("sl_from_month");
					var sl_from_day = document.getElementById("sl_from_day");
					var sl_from_year = document.getElementById("sl_from_year");
					
					var month = parseInt(sl_from_month.options[sl_from_month.selectedIndex].value);
					var day = parseInt(sl_from_day.options[sl_from_day.selectedIndex].value);
					var year = parseInt(sl_from_year.options[sl_from_year.selectedIndex].value);
					
					if (! isNaN(month) && ! isNaN(day) && ! isNaN(year)) {
						var date = month + "/" + day + "/" + year;

						YAHOO.example.calendar.cal1.select(date);
						YAHOO.example.calendar.cal1.cfg.setProperty("pagedate", month + "/" + year);
						YAHOO.example.calendar.cal1.render();
					}
				}
			
			function handleSelect1(type,args,obj) {
				var dates = args[0]; 
				var date = dates[0];
			    var year = date[0]-1, month = date[1], day = date[2];

					//var sl_To_Month = document.getElementById("sl_To_Month");
					var sl_To_Month =document.details.slToMonth;
					//var sl_To_Day = document.getElementById("sl_To_Day");
					var sl_To_Day= document.details.slToDay;
					//var sl_To_Year= document.getElementById("sl_To_Year");
					var sl_To_Year= document.details.slToYear;
					
	            if (month==1||month==3||month==5||month==7||month==8||month==10||month==12)
			  {
				sl_To_Day.options[30] = new Option('31','31');
				sl_To_Month.selectedIndex = month-1;
				sl_To_Day.selectedIndex = day-1;
			  }
			  else if (month==2||month==4||month==6||month==9||month==11)
			  {
			   sl_To_Day.options[30]=null
			   sl_To_Month.selectedIndex = month-1;
			   sl_To_Day.selectedIndex = day-1;
			  }
			
              for (var y=0;y<sl_To_Year.options.length;y++) {
						if (sl_To_Year.options[y].text == year) {
							sl_To_Year.selectedIndex = y+1;
							break;
						}
					}
					YAHOO.example.calendar.cal2.hide();
				}
			
					function updateCa2() {
						
					//var sl_To_Month = document.getElementById("sl_To_Month");
					var sl_To_Month =document.details.slToMonth;
					//var sl_To_Day = document.getElementById("sl_To_Day");
					var sl_To_Day= document.details.slToDay;
					//var sl_To_Year= document.getElementById("sl_To_Year");
					var sl_To_Year= document.details.slToYear;
					var day = parseInt(sl_To_Day.options[sl_To_Day.selectedIndex].value);
					var month = parseInt(sl_To_Month.options[sl_To_Month.selectedIndex].value);
					var year = parseInt(sl_To_Year.options[sl_To_Year.selectedIndex].value);
					
									
					if (! isNaN(month) && ! isNaN(day) && ! isNaN(year)) {
						var date = month + "/" + day + "/" + year;
						YAHOO.example.calendar.cal2.select(date);
						YAHOO.example.calendar.cal2.cfg.setProperty("pagedate", month + "/" + year);				
						YAHOO.example.calendar.cal2.render();
					}
				}
				
				   function minimumdate() {
			       var sl_from_month = document.getElementById("sl_from_month");
				   var sl_from_day = document.getElementById("sl_from_day");
				   var sl_from_year = document.getElementById("sl_from_year");
					
				   var month = parseInt(sl_from_month.options[sl_from_month.selectedIndex].value);
				   var day = parseInt(sl_from_day.options[sl_from_day.selectedIndex].value);
				   var year = parseInt(sl_from_year.options[sl_from_year.selectedIndex].value);
				
				   if (! isNaN(month) && ! isNaN(day) && ! isNaN(year)) {
						var date = month + "/" + day + "/" + year;
						YAHOO.example.calendar.cal2.cfg.setProperty("mindate", date );
						YAHOO.example.calendar.cal2.render();
						}
				 }

		function init() {
		YAHOO.example.calendar.cal1 = new YAHOO.widget.Calendar("YAHOO.example.calendar.cal1","cal1Container"	, { title:"choose a date:", close:true }  );  
		
	  YAHOO.example.calendar.cal1.cfg.setProperty("mindate", YAHOO.widget.DateMath.add(new Date(), YAHOO.widget.DateMath.DAY, 1));
	  YAHOO.example.calendar.cal1.selectEvent.subscribe(handleSelect, YAHOO.example.calendar.cal1, true);	
	  YAHOO.example.calendar.cal1.render();
	  YAHOO.util.Event.addListener(["sl_from_month","sl_from_day","sl_from_year"], "change", updateCal);
      YAHOO.util.Event.addListener("showup", "click", YAHOO.example.calendar.cal1.show, YAHOO.example.calendar.cal1, true);



	YAHOO.example.calendar.cal2 = new YAHOO.widget.Calendar("YAHOO.example.calendar.cal2","cal2Container"	, { title:"choose a date:", close:true }  );  
	YAHOO.example.calendar.cal2.cfg.setProperty("mindate", YAHOO.widget.DateMath.add(new Date(), YAHOO.widget.DateMath.DAY, 1));

	YAHOO.example.calendar.cal2.selectEvent.subscribe(handleSelect1, YAHOO.example.calendar.cal2, true);
	YAHOO.example.calendar.cal2.render();
	YAHOO.util.Event.addListener(["sl_To_Month","sl_To_Day","sl_To_Year"], "change", updateCa2);
    YAHOO.util.Event.addListener("showup1", "click", YAHOO.example.calendar.cal2.show, YAHOO.example.calendar.cal2, true);
	updateCa2();
		}
		
		
		function showCalendar1() {
			YAHOO.example.calendar.cal2.hide();
		}
		
		function showCalendar2() {
			YAHOO.example.calendar.cal1.hide();
		}
			YAHOO.util.Event.addListener(window, "load", init);
		
