function validemail(txt) {
	var str = txt.value; // email string
	var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
	var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid
	if (!reg1.test(str) && reg2.test(str)) { // if syntax is valid
		return true;
	}
	return false;
}

function emailCheck(txt) {
	if (!validemail(txt)) {
		alert("Please provide a valid email address.");
		txt.focus();
		return false;
	}
	return true;
}

function txtCheck(txt) {
    var trimmed = txt.value.replace(/^\s+|\s+$/g, '') ;
    if (trimmed == "") {
        alert("Please provide all required fields.");
        txt.focus();
        return false;
    }
    return true;
}

function checkFloat(txt) {
	var t;
	t = parseFloat(txt.value);
	if (isNaN(t)) {
		alert("Please provide positive numeric values.");
		txt.focus();
		return false;		
	} else {
		if (t < 0) {
			alert("Please provide positive numeric values.");
			txt.focus();
			return false;
		}
	}
	return true;
}

function checkInt(txt) {
	var t;
	t = parseInt(txt.value);
	if (isNaN(t)) {
		alert("Please provide positive numeric values.");
		txt.focus();
		return false;		
	} else {
		if (t < 0) {
			alert("Please provide positive numeric values.");
			txt.focus();
			return false;
		} else {
			txt.value = t;
		}
	}
	return true;
}

function checkMaxLen(txt,length)
{
	if (txt.value.length >= length) {
		alert("Please shorten: only "+length+" characters allowed");
		txt.focus();
		return false;
		
	} else {
		return true;
	}
}

function checkMinLen(txt,length)
{
	if (txt.value.length < length) {
		alert("Please note that at least "+length+" characters are required.");
		txt.focus();
		return false;
	}
	return true;
}


