// JavaGlobal.js
//

var whitespace = " \t\n\r";
var defaultEmptyOK = false

function isEmpty(s) {
     return ((s == null) || (s.length == 0)) 
}

function isWhitespace(s) {
     var i;
     var whitespace = " \t\n\r";
     if (isEmpty(s)) {
          return true; }
     for (i = 0; i < s.length; i++) {   
          var c = s.charAt(i)
          if (whitespace.indexOf(c) == -1) {
               return false; }
     }
     return true;
}

function isEmail(s) {
     if (isEmpty(s)) {
          if (isEmail.arguments.length == 1) {
               return defaultEmptyOK; }
          else {
          return (isEmail.arguments[1] == true); }
     }
   
     if (isWhitespace(s)) {
          return false; }

     var i = 1;
     var sLength = s.length;
     while ((i < sLength) && (s.charAt(i) != "@")) {
           i++ }
     if ((i >= sLength) || (s.charAt(i) != "@")) {
          return false; }
     else {
          i += 2; }

     while ((i < sLength) && (s.charAt(i) != ".")) {
           i++ }
     if ((i >= sLength - 1) || (s.charAt(i) != ".")) {
          return false; }
     else {
          return true; }
}

function isDate(theDate) {
  // dd-mm-yy format; leading zeros required
  var len = theDate.length;
  if(len != 8) {
    return false;
  } 
  var strday = theDate.substr(0, 2);
  var strmonth = theDate.substr(3, 2);
  var stryear = theDate.substr(6, 2);
  var strt1 = theDate.substr(2,1);
  var strt2 = theDate.substr(5,1);

  if( isNaN(strday) || (strday < 0) || isNaN(strmonth) || (strmonth < 0) || isNaN(stryear) || (stryear < 0) ) {
     return false; } 

  // Ensure valid month and set maximum days for that month...
  if( (strmonth == "01") || (strmonth == "03") || (strmonth == "05") || 
     (strmonth == "07") || (strmonth == "08") || (strmonth == "10") || 
     (strmonth == "12") )
     { monthdays = 31 }
  else if( (strmonth == "04") || (strmonth == "06") || (strmonth == "09") || (strmonth == "11") ) 
     { monthdays = 30 }
  else if(strmonth == "02") { 
     monthdays = ( (stryear % 4) == 0) ? 29 : 28;  }
  else {
     return false; }

  if(strday > monthdays) {
     return false; }

  if( (strt1 != "/") || (strt2 != "/") ){
     return false; }

  return true;
}

function isTime(strTime) {
     var strTime3 = /^(\d{1,2})(\:)(\d{1,2})$/;				//hh:mm- 15:48
     var strFormat3 = strTime.match(strTime3);

     if (strFormat3 == null) {
          return false;
     }

     else if (strFormat3 !== null) {
     // Validate for this format: 15:48
          if (strFormat3[1] > 23 || strFormat3[1] < 00) {
               return false;
          }
          if (strFormat3[3] > 59 || strFormat3[3] < 00) {
               return false;	
          }
     }
     return true;
}



function sendForm() {
     document.frmLogin.submit()
 }

function fnOpen(page){
   var theURL = "http://" + page
   msgWindow = window.open(theURL,"Terms","scrollbars=yes,location=no,width=800");
}

function fnMainFrame(url, page)    {
     var d, s, m;
     d = new Date();
     s = d.getSeconds();
     m = d.getMilliseconds();
     theURL = url + page + s + m;
     top.frames.mainframe.location = theURL; return true;
     }
function fnThisFrame(url, page)    {
     var d, s, m;
     d = new Date();
     s = d.getSeconds();
     m = d.getMilliseconds();
     theURL = url + page + s + m;
     this.location = theURL; return true;
     }

