<!--
//=======================================================
//== 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(oObject){
  //modified by tony on 4/6/2008
  var mailreg=/^[a-zA-Z0-9][\w\-\.]*@[\w\-]+(\.[\w\-]+){1,4}$/;  //check general format of a email address (max 5 parts after '@')
  var mailreg1=/[\@\.]{2}/;  //check 2 special characters come together, not allowed
  var mailreg2=/[\-\_]$/;  //check the tail of email address should not be special character, not allowed

  var mail=oObject.value;

  if (mailreg.test(mail)&&!mailreg1.test(mail)&&!mailreg2.test(mail))
    return false;         //false represent this email ok
  else
	return true;		  //true represent this email not ok
}

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 CheckPositiveValue(oObject,sFieldName) {
  if (isNaN(oObject.value)){
    return true;
  }else{
    if (parseInt(oObject.value)<0) {
      return true;
    }
  }
  return false;
}

function CheckZip(oObject,sFieldName){
  var chk_reg=/\D/;  //chk_reg.test(oObject.value) ||
  if ( oObject.value.length<4){
    //alert("Invalid input "+sFieldName+"!\n");
    oObject.focus();
    oObject.select();
    return true;
  }
  return false;
}

function CheckYearMonth( ymstr )
{
  var datePat = /^(\d{4})(-)(\d{1,2})$/; // requires 4 digit year
  var matchArray = ymstr.match(datePat); // is the format ok?
  if (matchArray == null) {
    return false;
  }
  month = matchArray[3]; // parse date into variables
  year = matchArray[1];
  if (month < 1 || month > 12) { // check month range
    return false;
  }
  return true;
}

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;
}

//-->
