function isIntegerInRange (s, a, b) {   
    var num = parseInt (s);
    return ((num >= a) && (num <= b));
}


function isMonth (s){   
    return isIntegerInRange (s, 1, 12);
}

function isDay (s) {   
    return isIntegerInRange (s, 1, 31);
}

function isYear (s) {   
    if (!(isIntegerInRange (s, 1920, 2047))) {
	alert ("Not valid year format: yyyy");
	return false;
    }	return true;
}

function makeArray(n) {
   for (var i = 1; i <= n; i++) {
      this[i] = 0
   } 
   return this
}

var daysInMonth = makeArray(12);
daysInMonth[1] = 31;
daysInMonth[2] = 29;   // must programmatically check this
daysInMonth[3] = 31;
daysInMonth[4] = 30;
daysInMonth[5] = 31;
daysInMonth[6] = 30;
daysInMonth[7] = 31;
daysInMonth[8] = 31;
daysInMonth[9] = 30;
daysInMonth[10] = 31;
daysInMonth[11] = 30;
daysInMonth[12] = 31;

function daysInFebruary (year){
    return (  ((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0) ) ) ? 29 : 28 );
}

function checkdate (month, day, year) {   
    // Explicitly change type to integer to make code work in both
    // JavaScript 1.1 and JavaScript 1.2.
    var intYear = parseInt(year);
    var intMonth = parseInt(month);
    var intDay = parseInt(day);

    // catch invalid days, except for February
    if (! (isYear(intYear) && isMonth(intMonth) && isDay(intDay))) return false;
    if (intDay > daysInMonth[intMonth]) return false; 
    if ((intMonth == 2) && (intDay > daysInFebruary(intYear))) return false;
    return true;
}

function isdate(tfield) {
	re = /(\d+)[-\/](\d+)[-\/](\d+)/;
	if (!(re.test(tfield.value))) {
		alert ("Not valid date format: mm/dd/yyyy");
		return false;
	}
	a = re.exec(tfield.value);
	rep = /^0/;
	for (i=1; i<= a.length; i++) {
		if (rep.test(a[i])) a[i]=a[i].replace(rep,"");
	}
	if (checkdate(a[1],a[2],a[3])){
		return true;
	} else {
		return false;
	}
}

