function trim(str) {
	var len, b, e, result;
	str=""+str;				// convert to string
	b=0;
	len=str.length;
	e=len-1;
	if (len>=0) {
		while (str.charAt(b)==' ' && b<len) b++;
		if (b<len) while (str.charAt(e)==' ') e--;
	} else e=0;
	if (b<len) result = str.substring(b,e+1);
	else result="";
	return result;		
}

function emptystr( str ) {
	var result;
	result = (str==null) || (trim(str).length==0);
	return result;
}

function activate(obj) {
	obj.select()
	obj.focus()
}

function msgEmpty(title) {
	alert(title)
}

function isEmail(email) {
	re=/(\w|-)+(\.(\w|-)+)*@(\w|-)+(\.(\w|-)+)*\.[A-Za-z][A-Za-z][A-Za-z]?[A-Za-z]?$/i
	return(re.test(email))
}

function isDate(mydate) {
	re=/\d\d?(\-)\d\d?(\-)\d\d(\d\d)?$/
	return(re.test(mydate))
}

function isPostcode(postcode) {
	re=/\d\d\d\d\ ?[A-Za-z][A-Za-z]$/
	return(re.test(postcode))
}

function validateSelect(name, title) {
	if (document.frm[name].selectedIndex<=0) {
		msgEmpty(title)
		document.frm[name].focus()
		return(false)
	} else return(true)
}

function validateTextInput(name, title) {
	if (document.frm[name].value=="") {
		msgEmpty(title)
		activate(document.frm[name])
		return(false)
	} else return(true)
}

function validateRadioInput(name, title) {
	var checked
	for (i=0; i<document.frm[name].length; i++) {if (document.frm[name][i].checked) {checked=true; break}}
	if (!checked) {
		msgEmpty(title)
		document.frm[name][0].focus()
		return(false)
	} else return(true)
}

function validateEmailInput(name, title) {
	if (document.frm[name].value=="" || !isEmail(document.frm[name].value)) {
		msgEmpty(title)
		activate(document.frm[name])
		return(false)
	} else return(true)
}

function validatePostcodeInput(name, title) {
	if (document.frm[name].value=="" || !isPostcode(document.frm[name].value)) {
		msgEmpty(title)
		activate(document.frm[name])
		return(false)
	} else return(true)
}

