///////////////////////////////////////////////////////////////////
// Copyright (c) 2001 Nebula Internet Software, LLC
///////////////////////////////////////////////////////////////////

// Define Global variables to be used by multiple functions.
var date, numMonths;

function oscalendar_init(months)
  {
   // Define the number of parameters passed to the JavaScript function.
   var numberOfParameters = oscalendar_init.arguments.length;

   if(numberOfParameters == 1)
     {
      if(isNaN(months))
         numMonths = 2; 			// Defaulted number of months.
      else
         numMonths = months; 			// Specified Number of months.
     }
   else
      numMonths = 2; 				// Defaulted number of months.
  
   date = new Date(); 				// Date.

   date.setDate(1);
		
   var month = date.getMonth();
   var year  = getFullYear(date);
	
   document.formCalendar.startingMonth.selectedIndex = month;
   document.formCalendar.startingYear.value = year;
   document.formCalendar.numberOfMonths.selectedIndex = numMonths-1;  
	
   show();
  }

function show()
  {
   // Diagnostic displays for viewing frame relationships.
   // alert("1 self.location = " + self.location);
   // alert("2 parent.location = " + parent.location);
   // alert("3 top.location = " + top.location);
   // alert("4 parent.View_Calendar.location = " + parent.View_Calendar.location);
   // alert("5 parent.Show_Calendar.location = " + parent.Show_Calendar.location);

   /*  Change the URL of the page that is viewed inside a frame. The context
    *  is: parent.[frame name].location.href = 'pagename.htm';
    *  or: parent.frame[index].location.href = 'pagename.htm';
    * 
    *  parent.frames[1].document.location.href = "First_Class_Horse_Calendar.htm";
    */
   parent.Show_Calendar.document.location.href = "First_Class_Horse_Calendar.htm";
  }

function view()
  {
   if( checkDate() )
     {
      var year = document.formCalendar.startingYear.value;

      date = new Date();

      date.setYear(year);
      date.setDate(1);
      date.setMonth(document.formCalendar.startingMonth.selectedIndex);

      numMonths = document.formCalendar.numberOfMonths.options[document.formCalendar.numberOfMonths.selectedIndex].text;
		
      show();
     }
  }

function getNumMonths()
  {
   return numMonths;
  }

function getFirstDay()
  {
   return date;
  }

function getFullYear(theDate)
  {
   var year = theDate.getYear();

   // Older versions of Netscape and IE 5.0 deal with the millenium differently.
   // This HACK fixes those problems.
   if(year  < 1900)
     {
      year += 1900;
     }

   return year;
  }

function checkDate()
  {
   var year = document.formCalendar.startingYear.value;

   if(isNaN(year) || year < 1900 || year > 3000)
     {
      alert("Year must be a four digit numerical value between 1900 and 3000.");

      /* Place the active cursor in the form's input field and select all text within it.
       *
       * Example using an element id.
       *   document.getElementById("idStartingYear").focus();
       *   document.getElementById("idStartingYear").select();
       *
       * Example using the name of an input type text field.      
       *   document.formCalendar.startingYear.focus();
       *   document.formCalendar.startingYear.select();
       */ 
      document.formCalendar.startingYear.focus();
      document.formCalendar.startingYear.select();

      return false;
     }

   return true;
  }	

