

if (!String.prototype.parseInt2) {

	String.prototype.parseInt2 = function () {

		var i = parseInt(this.replace(/[^\d]*(\d+).*/m, '$1'));

		if (isNaN(i)) return 0;

		return i;

	}

}





// ----------------------------------------------------------------------------

function trim(sText)
{
	return sText.replace(/^\s+|\s+$/g,'');
}

function validate_text(field, alerttxt) {

	with (field) {

		if (value == null || trim(value) == "") {

			alert(alerttxt);

			field.focus();

			return false;

		}

		return true;

	}

}





// ----------------------------------------------------------------------------

function validate_email(field, alerttxt) {

	var emailfilter = /^.+@.+$/i;



	with (field) {

		var returnval = emailfilter.test(value);



		if (!returnval) {

			alert(alerttxt);

			return false;

		}

		return true;

	}

}





// ----------------------------------------------------------------------------

function validate_date(field, alerttxt) {

	var v = field.value;

	var a = v.match(/(\d+)\/(\d+)\/(\d+)/);

	if (a) {

		var d = new Date(0);

		d.setFullYear(a[3], a[2] - 1, a[1]);

		// this will test for impossible dates

		// and will do the right thing with leading zeros

		if (d.getFullYear() == a[3]

		   && (d.getMonth() + 1) == a[2]

		   && d.getDate() == a[1])

			return true;

	}

	alert(alerttxt);

	field.focus();

	return false;

}





// ----------------------------------------------------------------------------

function validate_radio (field, alerttxt) {

	for (var i = field.length; i > -1; i--) {

		if (field[i] && field[i].checked) return true;

	}

	alert(alerttxt);

	field[0].focus();

	return false;

}





// ----------------------------------------------------------------------------

function validate_emailConfirm(field1, field2, alerttxt) {

	if (field1.value != field2.value) {

		alert(alerttxt);

		return false;

	}

	return true;

}

