<!--
//=======================================================
//== CheckNull    - Check if object value is blank.
//== CheckNumeric - Check if object value is numeric.
//== CheckEmail   - Check if the entered value is email format.
//== CheckDate    - Check if the entered value is date.
//== CheckDateRange - Check if To Date is earlier than From Date.
//== TrimBack   - Trim trailing spaces.
//== TrimFront    - Trim leading spaces.
//== Trim     - Call TrimBack & TrimFront to trim leading & trailing spaces.
//== CheckSelected - Check if object is dropbox
//== CheckPositiveValue - Check if object value is positive number
//== CheckZip -- Check valid zip

//=======================================================
//== Check if the object value is blank.
//== Parameters : oObject = Checked object.
//==      : sFieldName = Object name.
function CheckNull(oObject, sFieldName) {
  var s=oObject.value;
  for(var i =0; i<s.length;i++)
  {
    var c = s.charAt(i);
    if(!(/\s/.test(c))) return false;
  }
  return true;
}

//=======================================================
//== Check if object value is numeric.
//== Parameters : oObject = Checked object.
function CheckNumeric(oObject) {
  var ch=/\D/;
  var sString;

  sString = Trim(oObject.value);
  if (ch.test(sString)){
    return true;
  }
  return false;
}

//=======================================================
//== Trim trailing spaces.
//== Parameters : sString = Checked string.
function TrimBack(sString){
  var i;
  var ch;

  for (i=sString.length; i>=1; i--){
    ch = sString.substring(i-1,i);
    if (ch != ' '){
      return sString.substring(0,i);
      break;
    }
  }
  return sString.substring(0,0);
}

//=======================================================
//== Trim leading spaces.
//== Parameters : sString = Checked string.
function TrimFront(sString){
  var i;
  var ch;

  for (i=1; i<= sString.length ;i++){
    ch = sString.substring(i-1, i);
    if (ch != ' '){
      return sString.substring(i-1, sString.length);
    }
  }

  return sString.substring(0,0);
}

//=======================================================
//== Trim leading & trailing spaces.
//== Parameters : sString = Checked string.
function Trim(sString){
  return TrimFront(TrimBack(sString));
}

//=======================================================
//== Check if the entered value is date. This include CheckNull feature.
//== Parameters : oYear = Year value object.
//==      : oMonth = Month value object.
//==      : oDay = Day value object.
function CheckDate(oYear, oMonth, oDay) {
  var oDate;
  var lDay;
  var lMth;
  var lYear;
  var lCentury;

  lDay = oDay;
  lMth = oMonth- 1;   //0=January, 11=December.
  lYear = oYear;
  if ((lYear >= 1900) && (lYear <= 1999)) lCentury = 1900;
  if ((lYear < 1900) || (lYear > 1999)) lCentury =0;

  oDate = new Date(lYear, lMth, lDay);

  if ((oDate.getMonth()+1) != oMonth) {
    return true;
  }
  else
    if (oDate.getDate() != lDay) {
      return true;
    }
    else
      if(((oDate.getYear()+lCentury) != lYear) || (oYear.length != 4)) {
        return true;
      }
  return false;
}

function CheckEmail (emailStr) {
/* The following pattern is used to check if the entered e-mail address
   fits the user@domain format.  It also is used to separate the username
   from the domain. */
var emailPat=/^(.+)@(.+)$/
/* The following string represents the pattern for matching all special
   characters.  We don't want to allow special characters in the address.
   These characters include ( ) < > @ , ; : \ " . [ ]    */
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
/* The following string represents the range of characters allowed in a
   username or domainname.  It really states which chars aren't allowed. */
var validChars="\[^\\s" + specialChars + "\]"
/* The following pattern applies if the "user" is a quoted string (in
   which case, there are no rules about which characters are allowed
   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
   is a legal e-mail address. */
var quotedUser="(\"[^\"]*\")"
/* The following pattern applies for domains that are IP addresses,
   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
   e-mail address. NOTE: The square brackets are required. */
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
/* The following string represents an atom (basically a series of
   non-special characters.) */
var atom=validChars + '+'
/* The following string represents one word in the typical username.
   For example, in john.doe@somewhere.com, john and doe are words.
   Basically, a word is either an atom or quoted string. */
var word="(" + atom + "|" + quotedUser + ")"
// The following pattern describes the structure of the user
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
/* The following pattern describes the structure of a normal symbolic
   domain, as opposed to ipDomainPat, shown above. */
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")


/* Finally, let's start trying to figure out if the supplied address is
   valid. */

/* Begin with the coarse pattern to simply break up user@domain into
   different pieces that are easy to analyze. */
var matchArray=emailStr.match(emailPat)
if (matchArray==null) {
  /* Too many/few @'s or something; basically, this address doesn't
     even fit the general mould of a valid e-mail address. */
  return "Email address seems incorrect (check @ and .'s)"

}
var user=matchArray[1]
var domain=matchArray[2]

// See if "user" is valid
if (user.match(userPat)==null) {
    // user is not valid
    return "The username doesn't seem to be valid."

}

/* if the e-mail address is at an IP address (as opposed to a symbolic
   host name) make sure the IP address is valid. */
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
    // this is an IP address
    for (var i=1;i<=4;i++) {
      if (IPArray[i]>255) {
          return "Destination IP address is invalid!"

      }
    }
    return ""
}

// Domain is symbolic name
var domainArray=domain.match(domainPat)
if (domainArray==null) {
  return "The domain name doesn't seem to be valid."

}

/* domain name seems valid, but now make sure that it ends in a
   three-letter word (like com, edu, gov) or a two-letter word,
   representing country (uk, nl), and that there's a hostname preceding
   the domain or country. */

/* Now we need to break up the domain to get a count of how many atoms
   it consists of. */
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 ||
    domArr[domArr.length-1].length>3) {
   // the address must end in a two letter or three letter word.
   return "The address must end in a three-letter domain, or two letter country."

}

// Make sure there's a host name preceding the domain.
if (len<2) {
   var errStr="This address is missing a hostname!"
   return errStr

}

// If we've gotten this far, everything's valid!
return "";
}

function isValidDate(dateStr) {
// Date validation function courtesty of
// Sandeep V. Tamhankar (stamhankar@hotmail.com) -->

// Checks for the following valid date formats:
// YYYY/MM/DD   YYYY/MM/DD   YYYY-MM-DD

var datePat = /^(\d{4})(-)(\d{1,2})\2(\d{1,2})$/; // requires 4 digit year

var matchArray = dateStr.match(datePat); // is the format ok?
  if (matchArray == null) {
    return false;
  }
  month = matchArray[3]; // parse date into variables
  day = matchArray[4];
  year = matchArray[1];
  if (month < 1 || month > 12) { // check month range
    return true;
  }
  if (day < 1 || day > 31) {
    return true;
  }
  if ((month==4 || month==6 || month==9 || month==11) && day==31) {
    return true;
  }
  if (month == 2) { // check for february 29th
    var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
    if (day>29 || (day==29 && !isleap)) {
      return true;
      }
  }
  return false;
}

function CheckSelected(oObject, sFieldName) {

  if (oObject.options[oObject.selectedIndex].value==0 || oObject.options[oObject.selectedIndex].value==-1){
    return true;
  }
  return false;
}

function CheckRadio(oObject , oText)
{
  var i=oObject.length;
  if ((typeof i)=='undefined'){
    return (!oObject.checked);
  }
  for (var j=0;j<i;j++) {
          if (oObject[j].checked)
          {
            return false;
          }
  }
  return true;
}
//-->