function valid_date(d1) {
	var rtn = "";
	//window.alert("check dt: " + d1);
	dt1 = new Date();
	tmp = d1.split("\/");
	dt1.setTime(Date.parse(d1));
	//window.alert("date 1: " + dt1.toLocaleString());
	if ((dt1.toLocaleString() == "NaN") ||
		(tmp[0] != (dt1.getMonth() + 1)))
		rtn = "Date is invalid.";

	return(rtn);
}

function same_date(d1, d2) {
	dt1 = new Date();
	dt2 = new Date();
	dt1.setTime(Date.parse(d1));
	dt2.setTime(Date.parse(d2));
	if (dt1.toLocaleString() == dt2.toLocaleString())
		return(true);
	else
		return(false);
}

function higher_date(d1, d2) {
	dt1 = new Date();
	dt2 = new Date();
	dt1.setTime(Date.parse(d1));
	dt2.setTime(Date.parse(d2));
	if (dt1.valueOf() > dt2.valueOf())
		return(true);
	else
		return(false);
}

function valid_num(val) {
	var rtn;

	if (val.length == 0) 
		rtn = false;
	else if (isNaN(val))
		rtn = false;
	else
		rtn = true;

	return(rtn);
}

function format_number(val, dec) {
	var tmp1, tmp2, tmp3;
	var dec_loc, commas, idx, rtn;
	var i, a, b;
	var isneg;
/*
 * Convert to a string and add a leading zero if appropriate.
 */
	tmp1 = val.toString();
	if (tmp1.substr(0, 1) == "-") {
		tmp1 = tmp1.substr(1);
		isneg = true;
	}
	else
		isneg = false;
	if (tmp1.substr(0, 1) == ".")
		tmp1 = "0" + tmp1;
/*
 * Find the location of the decimal and add it if appropriate.
 */
	dec_loc = tmp1.indexOf("\.");
	if (dec_loc < 0) {
		tmp1 = tmp1 + ".";
		dec_loc = tmp1.indexOf("\.");
	}
/*
 * Now, set the fractional part.
 */
	if (dec > 0) {
		for (i = 0; i <= dec; i++)
			tmp1 = tmp1 + "0";
		tmp2 = tmp1.substr(0, (dec_loc + dec + 1));
	}
	else
		tmp2 = tmp1.substr(0, (dec_loc - 1));
/*
 * Finally, put commas in the whole number part.
 */
	tmp3 = tmp2;
	dec_loc = tmp3.indexOf("\.");
	if (dec_loc < 0)
		dec_loc = tmp3.length();
	if (dec_loc > 3) {
		commas = Math.floor((dec_loc-1) / 3);
		if ((dec_loc % 3) == 0)
			idx = 3;
		else
			idx = dec_loc % 3;
		for (i = 0; i < commas; i++) {
			a = tmp3.substr(0, idx);
			b = tmp3.substr(idx);
			tmp3 = a + "," + b;
			idx += 4;
		}
	}
/*
 * Add back the negative sign if appropriate.
 */
	if (isneg)
		tmp3 = "-" + tmp3;
/*
 * Return the formatted string.
 */
	rtn = tmp3;
	//window.alert("[" + tmp1 + "] [" + tmp2 + "] [" + tmp3 + "] [" + rtn + "]");
	return(rtn);
}