
function validURL(url,format) {

  if (format=="HTTPFTP") {
    res = url.match (
     "^(http|https|ftp)://"+ //  protocol
     "(.+\:.+@)?"+                                                // [login/pwd]
     "([A-Za-z0-9][\-A-Za-z0-9\.]*\.[\-A-Za-z]{2,5})"+            //  domain
     "(:[0-9]{1,5})?"+                                            // [port]
     "(/.*)?$");                                                  //  page
  }
  else if (format=="HTTP") {
    res = url.match (
     "^(http|https|ftp)://"+ //  protocol
     "(.+\:.+@)?"+                                                // [login/pwd]
     "([A-Za-z0-9][\-A-Za-z0-9\.]*\.[\-A-Za-z]{2,5})"+            //  domain
     "(:[0-9]{1,5})?"+                                            // [port]
     "(/.*)?$");                                                  //  page
  }
  else return false;

  return res;
}

function validDateTime(dt) {
  res = dt.match('^([0-9]{4}-[0-9]{2}-[0-9]{2}) ([0-9]{2}:[0-9]{2})(:[0-9]{2})?$');
  ms=RegExp.$2 + RegExp.$3;

  return validDate(RegExp.$1,"YYYY-MM-DD") && 
           (validTime(ms,"HH:MM") || validTime(ms,"HH:MM:SS"));
}

function validDate(d,format) {

//
// this function checks if the date string is valid against the format
// specified
//
// recognized format strings: 
// "YYYY-MM-DD"  "MM-DD-YYYY"  "DD-MM-YYYY"
//
// - day and month might be 1 or 2 chars long
// - the separator must be the - sign
// - function checks the followings also:
//   (1000 <= year <= 9999, 1 <= month <=12, 1 <= days <= days_in_month
//
// - valid examples:	2002-01-2,  2002-1-1, 1951-12-31, 2000-02-29
// - invalid examples:	2002-02-29, 2000-0-1, 200-0-1,	  2000-abc

  daysOfMonth = new Array(31,28,31,30,31,30,31,31,30,31,30,31);

  if (format=='YYYY-MM-DD') {
    res = d.match("^([0-9]{4})([-])([0-9]{1,2})([-])([0-9]{1,2})$");
    year  = RegExp.$1; month = RegExp.$3; days	= RegExp.$5;
    sep1  = RegExp.$2; sep2  = RegExp.$4; 
  }    
  else if (format=='MM-DD-YYYY') {
    res = d.match("^([0-9]{1,2})([-])([0-9]{1,2})([-])([0-9]{4})$");
    year  = RegExp.$5; month = RegExp.$1; days	= RegExp.$3;
    sep1  = RegExp.$2; sep2  = RegExp.$4; 
  }
  else if (format=='DD-MM-YYYY') {
    res = d.match("^([0-9]{1,2})([-])([0-9]{1,2})([-])([0-9]{4})$");
    year  = RegExp.$5; month = RegExp.$3; days	= RegExp.$1;
    sep1  = RegExp.$2; sep2  = RegExp.$4; 
  }
  else return false; // format not supported
  if (!res) { return false; }

  if (sep1 != sep2)				{ return false; } 
  if ((year % 4) == 0)				{ daysOfMonth[1]=29; }
  if ((month <= 0) || (month>12))		{ return false; }
  if ((days<=0) || (days>daysOfMonth[month-1])) { return false; }

  return true;
}

function validTime(time, format) {

// this function checks the time against the format specified  
// known format string: HH:MM and HH:MM:SS
// HH:MM	-> 0:00    ... 23:59	or 00:00 ... 23:59
// HH:MM:SS	-> 0:00:00 ... 23:59:59 or 00:00 ... 23:59:59
//
// (MM and SS has to be exactly two characters long)

  if (format=='HH:MM') {
    res = time.match("^([0-9]{1,2}):([0-9]{2})$");
    hour = RegExp.$1; min = RegExp.$2; 
  }
  else if (format=='HH:MM:SS') {
    res = time.match("^([0-9]{1,2}):([0-9]{2}):([0-9]{2})$"); 
    hour = RegExp.$1; min = RegExp.$2; sec = RegExp.$3;
    if ((sec<0) || (sec>59)) { return false; }
  }  
  else return false; // format not supported

  if (!res) { return false; }

  if ((hour<0) || (hour>23)) { return false; }
  if ((min<0) || (min>59)) { return false; }

  return true; 
}

function validNumber(value) {
  return value.match('^[0-9]+$')==value;
}

function validUSAlpha(value) {
  return value.match('^[A-Za-z]+$')==value;
}

function validCEAlpha(value) {
  // Hungarian accented characters recognized as alpha characters
  return value.match('^[A-Za-zÁÉÍÓÚÖÜÕÛáéíóúöüõû]+$')==value;
}

function validEmail(v_emailaddress) {
  return v_emailaddress.match('^[\._0-9a-z-]+@[0-9a-z][-0-9a-z\.]*\.[a-z]{2,3}$')
         == v_emailaddress;
}
