function valid_date(d1) {
	var rtn = true;
	dt1 = new Date();
	tmp = d1.split("\/");
	if (tmp.length != 3)
		rtn = false;
	else if (tmp[2].length != 4)
		rtn = false;
	else {
		dt1.setTime(Date.parse(d1));
		//window.alert("date 1: " + dt1.toLocaleString());
		if ((dt1.toLocaleString() == "NaN") ||
			(tmp[0] != (dt1.getMonth() + 1)))
			rtn = false;
		if (parseInt(tmp[2]) < 1900)
			rtn = false;
	}
	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 valid_email(val) {
	var rtn, t1, t2;

	rtn = true;

	if (val.length < 5)
		rtn = false;
	else {
		t1 = val.split("@");
		if (t1.length != 2)
			rtn = false;
		else {
			t2 = t1[1].split("\.");
			if (t2.length < 2)
				rtn = false;
			else if (t2[t2.length-1].length < 2)
				rtn = false;
		}
	}

	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);
}

function show_help(hfile) {
	var ht = 400;
	var wd = 350;
	var top = (screen.height/2)-ht;
	var left = (screen.width/2)-wd;

	window.open(hfile, "rms_help",
		"width=" + wd + ",height=" + ht + ",scrollbars=yes,status=no,resizable=no,top=" + top + ",left=" + left);
}

function encrypt_val(val) {
	var rtn, i;
	rtn = "";
	for (i = 0; i < val.length; i++) {
		if (rtn != "")
			rtn += ":";
		rtn += val.charCodeAt(i);
	}
	return(rtn);
}

