function isInteger (s)
{
   var i;

   if (isEmpty(s))
   if (isInteger.arguments.length == 1) return 0;
   else return (isInteger.arguments[1] == true);

   for (i = 0; i < s.length; i++)
   {
      var c = s.charAt(i);
      if (!isDigit(c)) return false;
   }
   return true;
}

function isEmpty(s)
{
   return ((s == null) || (s.length == 0))
}

function isDigit (c)
{
   return ((c >= "0") && (c <= "9"))
}

function defined(v) {
  var undefined;
  return (v!=undefined);
}

function empty(v) {
  return (v=="" || v==null || !defined(v));
}

function emptyText(obj) {
  return empty(obj.value);
}

function lengthText(obj) {
  return obj.value.length;
}

function emptyTextArea(obj) {
  return empty(obj.value);
}

function emptyPassword(obj) {
  return empty(obj.value);
}

function emptyFileUpload(obj) {
  return empty(obj.value);
}

function emptyCheckbox(obj) {
  var isEmpty=true;
  if (defined(obj.length)) {
    var index=0;
    while (isEmpty && index<obj.length) {
      isEmpty=!obj[index++].checked;
    }
  } else {
    isEmpty=!obj.checked;
  }
  return isEmpty;
}

function emptyRadio(obj) {
  // Radio() objects have exactly the same properties as Checkbox() objects...
  return emptyCheckbox(obj);
}

function emptySelect(obj) {
  switch (obj.type) {
    case "select-one":
      var v=obj.options[obj.selectedIndex].value.toLowerCase();
      return (v=="null" || empty(v));
      break;
    case "select-multiple":
      var index=0;
      var isEmpty=true;
      while (isEmpty && index<obj.length) {
        if (obj.options[index].selected) {
          var v=obj.options[index].value;
          isEmpty=(v=="null" || empty(v));
        }
        index++;
      }
      return isEmpty;
      break;
    default:
      window.alert("unknown <select> type");
  }
  return false;
}

function getSelectValue(obj) {
  switch (obj.type) {
    case "select-one":
      return obj.options[obj.selectedIndex].value;
      break;
    default:
      window.alert("getSelectValue: ERROR: not a Select object");
  }
  return null;
}

function validEmail(s) {
  return s.match(/^[\w\-\.]+@[\w\-]+(\.[\w\-]+)+/);
}

function validCreditCard(s) {
  var ccn="";

  // Clean the number
  for (var c=0; c<s.length; c++) {
    if (parseInt(s.charAt(c)).toString()==s.charAt(c)) {
      ccn+=s.charAt(c);
    }
  }

  // Simple length checks (a credit card number cannot be shorter than 7 digits
  // not can it be longer than 19). 
  if (ccn.length < 7 || ccn.length > 19) {
    return null;
  }

  // Perform Luhn check
  var sum=0;
  var doubleIt=false;
  for (offset=ccn.length-1; offset>=0; offset--) {
    var n=parseInt(ccn.charAt(offset));
    if (doubleIt) {
      n*=2;
      if (n>9) { n-=9; }
    }
    sum+=n;
    doubleIt=!doubleIt;
  }

  if ((sum%10)==0) {
    return ccn;
  } else {
    return null;
  }
}

function validPostCode(s) {
  var valid="";
  s=s.toUpperCase().replace(/[^A-Z0-9]/g,"");

  // Not particularly efficient, but it works...
  if (!valid) { valid=s.match(/^\w\d\d\w\w$/); }
  if (!valid) { valid=s.match(/^\w\d\d\d\w\w$/); }
  if (!valid) { valid=s.match(/^\w\w\d\d\w\w$/); }
  if (!valid) { valid=s.match(/^\w\w\d\d\d\w\w$/); }
  if (!valid) { valid=s.match(/^\w\d\w\d\w\w$/); }
  if (!valid) { valid=s.match(/^\w\w\d\w\d\w\w$/); }
  if (!valid) { valid=s.match(/^GIR0AA$/); }

  if (valid) {
    valid=valid.toString();
    var outward=valid.substring(0,valid.length-3);
    var inward=valid.substring(valid.length-3);
    return outward + " " + inward;
  } else {
    return null;
  }
}


/**
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;


function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		return false
	}
return true
}

function ValidateForm(){
	var dt=document.frmSample.txtDate
	if (isDate(dt.value)==false){
		dt.focus()
		return false
	}
    return true
 }