/********************************************************
	The openHelp function will open a controlled size help
	window.
	
	Usage: <input type='button' onkeypress='return noenter()'>

	Returns: false if the key is Enter, true otherwise

*********************************************************/
var helpWindowRef = null;
function openHelp(strUrl)
{
	//debugger
	var currentPage = new String(document.location.href);
	if ( currentPage.toUpperCase().indexOf("HELP.ASPX") >0 ||
		currentPage.toUpperCase().indexOf("DEFINITION.ASPX") >0  )
	{
		return true;
	}
		
	helpWindowRef = window.open(strUrl, "help", "height=275,width=350,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes");	
	window.setTimeout('focusHelpWindow()', 200);
	return false;
}


/********************************************************
	The openHelp function will set the focus to an open
	help window if possible.
	
	Returns: void

*********************************************************/
function focusHelpWindow()
{
	if (helpWindowRef != null && !helpWindowRef.closed)
	{
		helpWindowRef.focus();
	}
}


/********************************************************
	The following code captures the keypress events
	on the site and disables enter key events.  This
	is meant to disable submitting the page if the
	enter key is pressed.
*********************************************************/
/* JX: EV10143. They want to be able to user enter key to submit
var nav = window.Event ? true : false;
if (nav) {
   window.captureEvents(Event.KEYDOWN);
   window.onkeydown = NetscapeEventHandler_KeyDown;
} else {
   document.onkeydown = MicrosoftEventHandler_KeyDown;
}

function NetscapeEventHandler_KeyDown(e) {
  if (e.which == 13 && e.target.type != 'textarea' && e.target.type != 'submit') { return false; }
  return true;
}

function MicrosoftEventHandler_KeyDown() {
  if (event.keyCode == 13 && event.srcElement.type != 'textarea' && event.srcElement.type != 'submit')
    return false;
  return true;
}
*/
function getMonthLength(month,year,julianFlag)
{
   var ml;
   if(month==1 || month==3 || month==5 || month==7 || month==8 || month==10||month==12)
      {ml = 31;}
   else {
       if(month==2) {
          ml = 28;
          if(!(year%4) && (julianFlag==1 || year%100 || !(year%400)))
             ml++;
       }
       else
          {ml = 30;}
   }
   return ml;    
}

/*
function computeAge(yd,md,dd,yb,mb,db)
{
	//alert (yd + "/" + md + "/" + dd + " -- " + yb + "/" + mb + "/" + db);

	// difference in years
	var age = yd - yb;
		
	// subtract another year if we're before the birth day in the current 
	if (md < mb || (md == mb && dd > db))
	{
		age--;
		//alert('date has not passed this year so age is ' + age);
	}
	
	return age;
}
*/

function checkNumber(input, min, max)
{
    //msg = msg + " field has invalid data: " + input.value;

    var str = input;
    for (var i = 0; i < str.length; i++) {
        var ch = str.substring(i, i + 1)
        if ((ch < "0" || "9" < ch) && ch != '.') {
            //alert(msg);
	    return false;
        }
    }
    var num = 0 + str;
    if (num < min || max < num) {
        //alert(msg + " not in range [" + min + ".." + max + "]");
        return false;
    }
    input.value = str;
    return true;
}

function getMonthLength(month,year,julianFlag)
{
   var ml;
   if(month==1 || month==3 || month==5 || month==7 || month==8 || month==10||month==12)
      {ml = 31;}
   else {
       if(month==2) {
          ml = 28;
          if(!(year%4) && (julianFlag==1 || year%100 || !(year%400)))
             ml++;
       }
       else
          {ml = 30;}
   }
   return ml;    
}


// ---------------------------------------------------------------------------|
//                                                                            |
function computeAge(varAsOfDate, varBirthDate)
{

   // Returns array with values in this order:
   // Years, Months, Weeks, Days, Hours, Minutes, Seconds

   var dtAsOfDate;
   var dtBirth;
   var dtAnniversary;
   var intSpan;
   var intYears;
   var intMonths;
   var intWeeks;
   var intDays;
   var intHours;
   var intMinutes;
   var intSeconds;
   
   var returnVals = new Array(7);

   // get born date
   dtBirth = new Date(varBirthDate);
   
   // get as of date
   dtAsOfDate = new Date(varAsOfDate);

   // if as of date is on or after born date
   if ( dtAsOfDate >= dtBirth )
      {

      // get time span between as of time and birth time
      intSpan = ( dtAsOfDate.getUTCHours() * 3600000 +
                  dtAsOfDate.getUTCMinutes() * 60000 +
                  dtAsOfDate.getUTCSeconds() * 1000    ) -
                ( dtBirth.getUTCHours() * 3600000 +
                  dtBirth.getUTCMinutes() * 60000 +
                  dtBirth.getUTCSeconds() * 1000       )

      // start at as of date and look backwards for anniversary 

      // if as of day (date) is after birth day (date) or
      //    as of day (date) is birth day (date) and
      //    as of time is on or after birth time
      if ( dtAsOfDate.getUTCDate() > dtBirth.getUTCDate() ||
           ( dtAsOfDate.getUTCDate() == dtBirth.getUTCDate() && intSpan >= 0 ) )
         {

         // most recent day (date) anniversary is in as of month
         dtAnniversary = 
            new Date( Date.UTC( dtAsOfDate.getUTCFullYear(),
                                dtAsOfDate.getUTCMonth(),
                                dtBirth.getUTCDate(),
                                dtBirth.getUTCHours(),
                                dtBirth.getUTCMinutes(),
                                dtBirth.getUTCSeconds() ) );

         }

      // if as of day (date) is before birth day (date) or
      //    as of day (date) is birth day (date) and
      //    as of time is before birth time
      else
         {

         // most recent day (date) anniversary is in month before as of month
         dtAnniversary = 
            new Date( Date.UTC( dtAsOfDate.getUTCFullYear(),
                                dtAsOfDate.getUTCMonth() - 1,
                                dtBirth.getUTCDate(),
                                dtBirth.getUTCHours(),
                                dtBirth.getUTCMinutes(),
                                dtBirth.getUTCSeconds() ) );

         // get previous month
         intMonths = dtAsOfDate.getUTCMonth() - 1;
         if ( intMonths == -1 )
            intMonths = 11;

         // while month is not what it is supposed to be (it will be higher)
         while ( dtAnniversary.getUTCMonth() != intMonths )

            // move back one day
            dtAnniversary.setUTCDate( dtAnniversary.getUTCDate() - 1 );

         }

      // if anniversary month is on or after birth month
      if ( dtAnniversary.getUTCMonth() >= dtBirth.getUTCMonth() )
         {

         // months elapsed is anniversary month - birth month
         intMonths = dtAnniversary.getUTCMonth() - dtBirth.getUTCMonth();

         // years elapsed is anniversary year - birth year
         intYears = dtAnniversary.getUTCFullYear() - dtBirth.getUTCFullYear();

         }

      // if birth month is after anniversary month
      else
         {

         // months elapsed is months left in birth year + anniversary month
         intMonths = (11 - dtBirth.getUTCMonth()) + dtAnniversary.getUTCMonth() + 1;

         // years elapsed is year before anniversary year - birth year
         intYears = (dtAnniversary.getUTCFullYear() - 1) - dtBirth.getUTCFullYear();

         }

      // to calculate weeks, days, hours, minutes and seconds
      // we can take the difference from anniversary date and as of date

      // get time span between two dates in milliseconds
      intSpan = dtAsOfDate - dtAnniversary;

      // get number of weeks
      intWeeks = Math.floor(intSpan / 604800000);

      // subtract weeks from time span
      intSpan = intSpan - (intWeeks * 604800000);
      
      // get number of days
      intDays = Math.floor(intSpan / 86400000);

      // subtract days from time span
      intSpan = intSpan - (intDays * 86400000);

      // get number of hours
      intHours = Math.floor(intSpan / 3600000);
    
      // subtract hours from time span
      intSpan = intSpan - (intHours * 3600000);

      // get number of minutes
      intMinutes = Math.floor(intSpan / 60000);

      // subtract minutes from time span
      intSpan = intSpan - (intMinutes * 60000);

      // get number of seconds
      intSeconds = Math.floor(intSpan / 1000);

      // Populate the return array
	  returnVals[0] = intYears;
	  returnVals[1] = intMonths;
	  returnVals[2] = intWeeks;
	  returnVals[3] = intDays;           
	  returnVals[4] = intHours;
	  returnVals[5] = intMinutes;
	  returnVals[6] = intSeconds;


      }
   else
   {
		// Not born yet, no action?   
   }

   
   return returnVals;
   
   }   
//                                                                            |
// ---------------------------------------------------------------------------|
