function cloader(){
  if (document.getElementById){
    document.getElementById('loading').style.visibility='hidden';
  }else{
    if (document.layers){ //NS4
      document.loading.visibility = 'hidden';
    }
    else { //IE4
      document.all.loading.style.visibility = 'hidden';
    }
  }
}

function oloader(){
  if (document.getElementById){
    document.getElementById('loading').style.visibility='visible';
  }else{
    if (document.layers){ //NS4
      document.loading.visibility = 'visible';
    }
    else { //IE4
      document.all.loading.style.visibility = 'visible';
    }
  }
}

function ff() {
  var aForm = (document.forms[0]) ? document.forms[0] : null;
  if(aForm) {
    if(aForm.elements[0]!=null) {
      var i;
      var max=aForm.length;
      for(i=0;i<max;i++) {
        if(aForm.elements[ i ].type != 'hidden' &&
        !aForm.elements[ i ].disabled &&
        !aForm.elements[ i ].readOnly ) {
          aForm.elements[ i ].focus();
          break;
        }
      }
    }
  }
}

function valid_time(field){
  //var KEY = String.fromCharCode(event.keyCode)
  var feedback = true;
  var val = field.value;
  var length = val.length;
  var valids = ":0123456789";
  if(valids.indexOf(KEY) < 0){
    status = 'Format: HH:MM. Denying key: '+KEY+'.';
    feedback = false;
  } else {
    // Check we've only got one ':'
    var tarr = new Array();
    var newstring = val + KEY;
    tarr = newstring.split(':');
    if (tarr.length > 2){
      feedback = false;
      status = 'Format: HH:MM. Denying key: '+KEY+'.';
    } else {
      // Check that the time has a ':'
      if(val.length > 4){
        status = 'Format: HH:MM';
        feedback = false;
      } else {
        // The following now assumes a ':' exists in the date
        if(tarr.length > 1){
          // Check for length of both sections
          if(tarr[0].length > 2){
            status = 'Format: HH:MM';
            feedback = false;
          } else {
            if(tarr[1].length > 2){
              status = 'Format: HH:MM';
              feedback = false;
            }
          }
        }
      }
    }
  }
  if(feedback != false){
    status = 'Permitting '+KEY+'.';
  }
  return feedback;
}

function valid_date(field){
  alert('Checking date');
  var pos;
  var err;
  var val=field.value;
  var darr;
  var seps = new Array('-',' ','/','.');
  var monthdays = new Array(0,31,28,31,30,31,30,31,31,30,31,30,31);
  var strDay;
  var strMonth;
  var strYear;
  var leap;
  for(pos = 0; pos < seps.length; pos++){
    if(val.indexOf(seps[pos]) != -1) {
      darr = val.split(seps[pos]);
      if(darr.length != 3){
        alert('Invalid Date');
        err = 1;
        break;
      } else {
        strDay = darr[0];
        strMonth = darr[1];
        strYear = darr[2];
        // Check the day
        if(isNaN(strDay) || strDay < 1 || strDay > 31){
          alert('Invalid number of days in the month');
          err = 1;
          break;
        }
        // Check the month
        if(isNaN(strMonth) || strMonth < 1 || strMonth > 12){
          alert('Invalid Month');
          err = 1;
          break;
        }
        // Check the year
        if(isNaN(strYear)){
          alert('Invalid Year');
          err = 1;
          break;
        }
        // Test for leapyear
        if(strYear % 100 == 0 && strYear % 400 == 0){
          leap = 1;
        } else {
          if(strYear % 4 == 0){
            leap = 1;
          }
        }
        // Check for days of month
        //alert('Checking to see if '+strDay+' is less than '+monthdays[strMonth]);
        if(strDay > monthdays[strMonth]){
          // We might have a leap year - check feb
          //alert('Ooh, see if its february in a leap year...');
          if(strDay == 29 && strMonth == 2 && leap == 1){
          } else {
            alert('Invalid number of days in the month');
            err = 1;
            break;
          }
        }
        // All checks have been passed - do reformatting
        while(strDay.length < 2){
         strDay = '0'+strDay;
        }
        while(strMonth.length < 2){
         strMonth = '0'+strMonth;
        }
        if(strYear.length < 2){
          strYear = '0'+strYear;
        }
        if(strYear.length < 3){
          if(strYear < 50){
            strYear = '20'+strYear;
          } else {
            strYear = '19'+strYear;
          }
        }
      }
    }
  }
  if(val != '' && strDay == null){
    alert('Invalid Date');
    err = 1;
  }
  if(err == 1){
    return false;
    field.focus();
    field.select();
  } else {
    field.value = strDay+'/'+strMonth+'/'+strYear;
  }
} // End of valid_date function
