<!--

//---------------------------------
// Disables Form Submit and Reset Buttons after the initial Request to transmit to server
//--------------------------------

function DisableForm(theform) 
{
  if (document.all || document.getElementById) 
   {
    for (i = 0; i < theform.length; i++) 
     {
      var tempobj = theform.elements[i];
      tempobj.disabled = (tempobj.type.toLowerCase() == "submit" || tempobj.type.toLowerCase() == "reset") ? true:false;
     }
    return true;
   }
  else return false;
}

//---------------------------------
// String to number Converter 
//--------------------------------

function ConvertToNumber(s_anyval)
{
 return eval(s_anyval);
}

//---------------------------------
// Checks to see if String is empty 
//--------------------------------

function isEmpty(s)
{
   return ((s == null) || (s.length == 0))
}

//-------------------------------------------------
// Check entered number within permissible range. 
// Display error message if required
//-------------------------------------------------

function CheckWithinRange(anyval,minrange,maxrange,b_msg)
{
 var b_result = ((anyval >=minrange) && (anyval <=maxrange)) ? true : false;
 if (b_msg && !b_result ) alert('Warning: the value "' + anyval+ '" is not between the expected range of values (' + minrange + ' to ' + maxrange+ ').');
 return b_result;
}


//------------------------------------------------
// Check to see if string is a number or integer according to s_mode
// Display error message if required
//------------------------------------------------

function TrimDecimals (s_anyval,i_ndp)
{
 var s_int = "";
 var s_dec = "";
 var i_dec = 0;
 var s_val = TrimSpaces(s_anyval);
 if (!isEmpty(s_val) && CheckIsNumber(s_val,"real",true))
  {
   if (s_val.indexOf('.') == -1) s_val+= ".";
   s_int = s_val.substring(0, s_val.indexOf('.'));
   s_dec = s_val.substring(s_val.indexOf('.')+1, s_val.length);
   if (isEmpty(s_dec)) s_dec="0";
   if (s_dec.length > i_ndp) 
     {
      var i_dec =  eval(s_dec.substring(0,i_ndp))
      if (eval(s_dec.substring(i_ndp+1,1)) > 5) i_dec ++;
      s_dec = i_dec + "";
     }
   return s_int +"." +  s_dec;
  }
 else return "";
}


//------------------------------------------------
// Check to see if string is a number or integer according to s_mode
// Display error message if required
//------------------------------------------------
function CheckIsNumber(s_anyval,s_mode,b_msg) 
{ 
  var s_valid  = "0123456789.";
  var b_result = false;
  var i =0;
  var s_input = s_anyval;
  if (s_input.length > 0)
   {
    b_result = (s_mode =="int") ? ((s_input.indexOf('.')==-1) ? true: false):true ; 
    if      ("" + s_input.substring(i, i+1) =='-') i++;
    else if ("" + s_input.substring(i, i+1) =='+') i++;
    while ((i <s_input.length) && b_result)  
      {
       b_result = (s_valid.indexOf(s_input.substring(i, i+1)) == -1) ? false : true ;
       i++;
      }
    if (b_msg && !b_result) 
     {
      if  (s_mode =="int")      alert('Warning: the value "' + s_input + '" is not a whole number.');
      else if (s_mode =="real") alert('Warning: the value "' + s_input + '" is not a number.');
     }
   }  
  else
   {
     if (b_msg) alert('You must enter a value. You cannot leave this field empty.');
   }
  return b_result;
} 


//-------------------------------------------------
// Check to see if string is an integer.
// Check to see if it lies within permitted range
// Display error message as required
//-------------------------------------------------
function CheckIntegerWithinRange(s_anyval,i_min,i_max,b_msg)
{
 return (CheckIsNumber(TrimSpaces(s_anyval),"int",b_msg)) ?  (CheckWithinRange(ConvertToNumber(s_anyval),i_min,i_max,b_msg)) : false;
}


//-------------------------------------------------
// Check to see if string is a number
// Check to see if it lies within permitted range
// Display error message as required
//-------------------------------------------------
function CheckNumberWithinRange(s_anyval,i_min,i_max,b_msg)
{
 
 return (CheckIsNumber(TrimSpaces(s_anyval),"real",b_msg)) ?  (CheckWithinRange(ConvertToNumber(s_anyval),i_min,i_max,b_msg)) : false;
}


//-------------------------------------------------
// Check to see if string is a number
// Check to see if it has max decimal places permitted 
// Display error message as required
//-------------------------------------------------
function CheckDecimals(s_anyval,i_ndp,b_msg)
{
 var b_result = false;
 var s_val = TrimSpaces(s_anyval)
 if ((s_val!="") && CheckIsNumber(s_val,"real",b_msg))
  {
   if (s_val.indexOf('.') == -1) s_val+= ".";
   var s_dectext = s_val.substring(s_val.indexOf('.')+1, s_val.length);
   b_result = (s_dectext.length <= i_ndp) ? true :false;
  }
  if (b_msg && !b_result) alert('Please enter value "'+ s_val+' " to no more than '+ i_ndp+' decimal places.');
  return b_result;
}

//-------------------------------------------------------------------
// String Related functions
//-------------------------------------------------------------------


// Remove any character in Filter String from input string

function StringFilter (s_input,s_remove) 
{
 var s_filtered   = '';
 for (var i = 0; i < s_input.length; i++) 
  {  
    if (s_remove.indexOf(s_input.charAt(i)) == -1) s_filtered += s_input.charAt(i);
  }
  return s_filtered;
}


//------------------------------------------------
// Remove Trailing Spaces
//------------------------------------------------

function RemoveTrailingSpaces (s_input)
{
 var i_spaces =0;
 if (!isEmpty(s_input))
  {
   while (( s_input.charAt(s_input.length - i_spaces -1)) ==" ") i_spaces++;
  }
 return  s_input.substring(0,s_input.length - i_spaces);
}


function RemoveLeadingSpaces (s_input)
{
 var i_spaces =0;
 if (!isEmpty(s_input))
  {
   while (s_input.charAt(i_spaces) ==" ") i_spaces++;
  }
 return  s_input.substring(i_spaces,s_input.length);
}

function TrimSpaces(s_input)
{
  var s_ret="";
  s_ret=RemoveLeadingSpaces(RemoveTrailingSpaces(s_input));
  return s_ret;
}


function TrimChar(s_input,i_max)
{
 var s_ret=s_input;
 if (s_input.length >= i_max)  
    {
     s_ret = s_input.substring(0,4);
     alert("Entered text of '"+s_input+"' has been clipped to '"+s_ret+"' as it exceeds the maximum number of permitted characters.");
    }
 return s_ret;
}


function ReplaceChars(s_entry,s_replace,s_swap) 
{
 var s_temp = s_entry;
 var pos = s_temp.indexOf(s_replace) ;
 while (pos > -1) 
  {
    s_temp = s_temp.substring(0, pos) + s_swap  + s_temp.substring(pos + s_swap.length,s_temp.length) ; 
    pos = s_temp.indexOf(s_replace) ;
  }
 return s_temp;
}


//------------------------------------------------
// check to see if empty
//------------------------------------------------
function StringEmpty(s_input,b_msg,s_var)
{
  if (!isEmpty(s_input)) return false 
  else 
   {
    if (b_msg) alert ("Form cannot be submitted until you have entered a value for '" + s_var+"'")
    return true;
   }
}


//------------------------------------------------
// daysInFebruary (INTEGER year)
//------------------------------------------------

function daysInFebruary (year)
{   return (  ((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0) ) ) ? 29 : 28 );
}


//------------------------------------------------
// isDate returns true if string arguments year, month, and day 
// form a valid date.
//------------------------------------------------

var daysInMonth = new Array (12);
daysInMonth[1] = 31;
daysInMonth[2] = 29;   // must programmatically check this
daysInMonth[3] = 31;
daysInMonth[4] = 30;
daysInMonth[5] = 31;
daysInMonth[6] = 30;
daysInMonth[7] = 31;
daysInMonth[8] = 31;
daysInMonth[9] = 30;
daysInMonth[10] = 31;
daysInMonth[11] = 30;
daysInMonth[12] = 31;


function isDate(syr,smn,sdy,b_msg)
{
 var status =false;
 if (!isEmpty(syr) && !isEmpty(smn) && !isEmpty(sdy)) 
 {
  if (CheckIntegerWithinRange (smn, 1, 12,false) && CheckIntegerWithinRange (smn, 1, 31,false) )
   {
    var intYear = parseInt(syr);
    var intMonth = parseInt(smn);
    var intDay = parseInt(sdy);
    if (intDay <= daysInMonth[intMonth])
     {
      status=true;
      if ((intMonth == 2) && (intDay > daysInFebruary(intYear))) status=false;
     }
    else if (b_msg) alert("Incorrect day for the entered month."); 
   }
  else if (b_msg) alert ("Either or both the month and the day of the month are incorrect");  
 }
 else if (b_msg) alert ("The date entered is incorrect, check that the year, month and day have been entered");
 return status;
}


function RadioValue(group)
{
  for ( var i=0; i<group.length; i++ )
  {
     if ( group[i].checked == true ) return group[i].value;
  }
}


function ClearRadio(group)
{
  for ( var i=0; i<group.length; i++ )
  {
     if ( group[i].checked == true ) group[i].checked = false;
  }
}


function UnCheckRB(rb)
{
 rb.checked =false;
}


function SetToDefaultRB(rdgrp,defval)
{
  for(var j = 0 ; j < rdgrp.length ; ++j)
   {
    rdgrp[j].checked = false;
    if (rdgrp[j].value==defval) rdgrp[j].checked = true;
   }
}



function checkRadios()
{
 var el = document.forms[0].elements;
 for(var i = 0 ; i < el.length ; ++i)
  {
   if(el[i].type == "radio")
    {
     var radiogroup = el[el[i].name]; // get the whole set of radio buttons.
     var itemchecked = false;
     for(var j = 0 ; j < radiogroup.length ; ++j)
      {
       if(radiogroup[j].checked)
       {
        itemchecked = true;
        break;
       }
      }
     if(!itemchecked)
      {
       alert("Please choose an answer for "+el[i].name+".");
       if(el[i].focus)
       el[i].focus();
       return false;
      }
    }
  }
 return true;
}



-->