// To use all these functions. You have to name your form option 
// for  year: StartYear
// for month: StartMonth
// for day  : StartDay

//------------------------------- Start of Global Variables -----------------------------


   var CurrentDate=new Date();
   var CurrentYear=CurrentDate.getFullYear();   
   var CurrentYearStatic=CurrentYear;   
   var CurrentDay=CurrentDate.getDate();
   var CurrentDayStatic=CurrentDay; 
   var CurrentMonth=CurrentDate.getMonth(); //return 0..11 (0=Jan, and 11=dec)
   var CurrentMonthStatic=CurrentMonth;       
   var ArrayOfMonth= new Array("JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC");       
   var ArrayOfMonth_Value= new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
   var ArrayOfMonth_f= new Array("Jan","Fév","Mar","Avr","Mai","Juin","Juil","Août","Sept","Oct","Nov","Déc");   



   // -------------------------- End of Global variable -----------------------------
   


// ----------------------------- Function to upddate time  ---------------------
//   function to update the time when loading page 
   
function UpdateTime(Form){
// function to populate the list of Year available for data
   


var TempYear;
   // Set time to show yesterday date..
    // we want to initially set the date range to yesterday date....
    Today = new Date();                   // get today's date
    //YesterdayDate = Today.getDate() -1 ; // get yesterday date
	YesterdayDate = Today.getDate() ; // get today date
    Today.setDate( YesterdayDate );
    
	
	// to test if browser can use Javascript 1.2 and higher
    if(window.screen)

	{
    YesterdayYear=Today.getFullYear();
	
	}
    else{
       YesterdayYear=Today.getYear();  // for nestcape 3.0 and under
	  
    }



    Yesterday=Today.getDate();
    YesterdayMonth=Today.getMonth();   
   

	


   // to erase months that is ahead of the current month ..so preventing user from choosing later month

    		
   		for(j=11;j>=YesterdayMonth+1;j--){
      		Form.StartMonth.options[j]=null;
   		}

 // to erase day that is ahead of the current day
 
 
    for(j=31;j>=Yesterday;j--){
       Form.StartDay.options[j]=null; 
	   
	}
	
    Form.StartYear.options[0]=new Option(YesterdayYear); 
    Form.StartYear[0].selected=true; 
    Form.StartDay[Yesterday-1].selected=true;    
    Form.StartMonth[YesterdayMonth].selected=true;
   

   



}// end function

// ------------------------------ End of Function Update Time -------------------------

function AddRightNumberOfDay(YearOptionName,MonthOptionName,DayOptionName,DayValue) {
// This function adds the right number of days depending of the user choices of month
   
   //var MonthSelected=MonthOptionName.options[MonthOptionName.selectedIndex].text;

   var MonthSelected=MonthOptionName.options[MonthOptionName.selectedIndex].value;
   DayOptionName.options.length=0; //remove all options
  
   //alert(DayValue);
   //alert(MonthSelected);
   // for months that are ending with 31 days
   if((MonthSelected=="Jan")|(MonthSelected=="Mar")|(MonthSelected=="May")|(MonthSelected=="Jul")|(MonthSelected=="Aug")|(MonthSelected=="Oct")|(MonthSelected=="Dec")){
        var iNumberOfDay=31;
       	// YearOptionName.selectedIndex=0..mean ..the current year was selected
	    // so day can't go beyond today date.
	
	   if((CurrentMonthStatic==MonthOptionName.selectedIndex)&&(YearOptionName.selectedIndex==0)){
	    
	       iNumberOfDay=CurrentDayStatic;
	   }

       //alert(iNumberOfDay);
       for(i=0;i<iNumberOfDay;i++){
	       var str2digit;
		   if(i<9)
		   str2digit="0"+(i+1);
		   else str2digit=i+1;
		   
          DayOptionName.options[i]=new Option(str2digit);
          
       }


	   if(DayOptionName.options.length >= DayValue){
	    
		   
		    //since month can have 30,31,28,29 days

		      DayOptionName.options[DayValue-1].selected=true;
		  
		  
		  
		} else DayOptionName.options[0].selected=true;

 

   }// end for adding days for month that have 31 days

   else if((MonthSelected=="Apr")|(MonthSelected=="Jun")|(MonthSelected=="Sep")|(MonthSelected=="Nov")){

      
        var iNumberOfDay=30;
       	// YearOptionName.selectedIndex=0..mean ..the current year was selected
	    // so day can't go beyond today date.
	
	   if((CurrentMonthStatic==MonthOptionName.selectedIndex)&&(YearOptionName.selectedIndex==0)){
	    
	    iNumberOfDay=CurrentDayStatic;
	  }

       for(j=0;j<iNumberOfDay;j++){

	       var str2digit;
		   if(j<9)
		   str2digit="0"+(j+1);
		   else str2digit=j+1;	   

		   DayOptionName.options[j]=new Option(str2digit);
         
       }
	   
	   //alert(DayOptionName.options.length); 
	       
	   	if(DayOptionName.options.length >= DayValue){
	    
		   
		    //since month can have 30,31,28,29 days

   			    DayOptionName.options[DayValue-1].selected=true;
		  
		  
		  
		} else DayOptionName.options[0].selected=true;

       


   }// end for adding days for month that have 30 days

   else { // for the special case of the month of February

	   var iNumberOfDay=0;
	   var iYear=eval(YearOptionName.options[YearOptionName.selectedIndex].text);
	   if(iYear%4==0) // % is the modulus operator
		  iNumberOfDay=29;
	   else iNumberOfDay=28;

	


	// YearOptionName.selectedIndex=0..mean ..the current year was selected
	// so day can't go beyond today date.
	
	if((CurrentMonthStatic==MonthOptionName.selectedIndex)&&(YearOptionName.selectedIndex==0)){
	   
	  iNumberOfDay=CurrentDayStatic;
	  }
	  

    for(k=0;k<iNumberOfDay;k++){
   
	       var str2digit;
		   if(k<9)
		   str2digit="0"+(k+1);
		   else str2digit=k+1;	    
          DayOptionName.options[k]=new Option(str2digit);
      
     }


	   if(DayOptionName.options.length >= DayValue){
	    
		   
		    //since month can have 30,31,28,29 days
			
		
     		     DayOptionName.options[DayValue-1].selected=true;
		  
		  
		  
		} else DayOptionName.options[0].selected=true;
       
     
  } 

}// end of Function

// --------------------------------------- End of AddRightNumberOfDay Function -------------------------

function UpdateMonth(YearOptionName,MonthOptionName){
// This function depending on the user choice of year, erase all month that is ahead
// of the user choice of month.

  var IndexOfCurrentMonth=MonthOptionName.selectedIndex;
  var YearSelected=YearOptionName.options[YearOptionName.selectedIndex].text;

  //document.Ftp.StartMonth.options.length=0;// remove all month values
  if(CurrentYearStatic==YearSelected){

    // to erase months that is ahead of the current month ..so preventing user from choosing later month
   for(j=11;j>=CurrentMonth+1;j--){
      MonthOptionName.options[j]=null;
   }
   if(IndexOfCurrentMonth>CurrentMonthStatic){
      MonthOptionName.options[CurrentMonthStatic].selected=true;

	 // Form.EndMonth.options[0]=null;
	  //Form.EndMonth.options[0]=new Option(Form.StartMonth.options[Form.StartMonth.selectedIndex].text );
	   //Form.EndMonth.options[0].text=Form.StartMonth.options[CurrentMonthStatic].text;
	  //Form.EndMonth.options[0].selected=true;

   }
   else{
           MonthOptionName.options[IndexOfCurrentMonth].selected=true;

    }

  }// of test same year

  // here since not the same year, we can have month that is ahead of the user choice of month
  else { // add all month
      for(k=0;k<12;k++){
       MonthOptionName.options[k]=new Option(ArrayOfMonth[k]);
	   MonthOptionName.options[k].value=ArrayOfMonth_Value[k];
      }
      MonthOptionName.options[IndexOfCurrentMonth].selected=true;
  }



}// end of function UpdateMonth

//------------------------------------------------ End of Function UpdateMonth -----------------------------





function UpdateMonth_f(YearOptionName,MonthOptionName){
// This function depending on the user choice of year, erase all month that is ahead
// of the user choice of month. This same as UpdateMonth except for french version

  var IndexOfCurrentMonth=MonthOptionName.selectedIndex;
  var YearSelected=YearOptionName.options[YearOptionName.selectedIndex].text;

  //document.Ftp.StartMonth.options.length=0;// remove all month values
  if(CurrentYearStatic==YearSelected){

    // to erase months that is ahead of the current month ..so preventing user from choosing later month
   for(j=11;j>=CurrentMonth+1;j--){
      MonthOptionName.options[j]=null;
   }
   if(IndexOfCurrentMonth>CurrentMonthStatic){
      MonthOptionName.options[CurrentMonthStatic].selected=true;

	 // document.FtpGUI.EndMonth.options[0]=null;
	  //document.FtpGUI.EndMonth.options[0]=new Option(document.FtpGUI.StartMonth.options[document.FtpGUI.StartMonth.selectedIndex].text );
	   //document.FtpGUI.EndMonth.options[0].text=document.FtpGUI.StartMonth.options[CurrentMonthStatic].text;
	  //document.FtpGUI.EndMonth.options[0].selected=true;

   }
   else{
           MonthOptionName.options[IndexOfCurrentMonth].selected=true;

    }

  }// of test same year

  // here since not the same year, we can have month that is ahead of the user choice of month
  else { // add all month
      for(k=0;k<12;k++){
       MonthOptionName.options[k]=new Option(ArrayOfMonth_f[k]);
	   MonthOptionName.options[k].value=ArrayOfMonth_Value[k];  
      }
      MonthOptionName.options[IndexOfCurrentMonth].selected=true;
  }



}


// ------------------------------------------------ End of UpdateMonth  ----------------------------------








//----------------------------------------------------------------------------------------------
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}