
function validateFormat(type,string) {
var numRE = /[\d]/;
var alphaRE = /[ a-zA-Z]/;
var alphaNumRE = /^[ 0-9a-zA-Z\/\\\&\-\,\'\!]$/;
var emailRE = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
var urlRE = /^[0-9a-zA-Z]+([\!\.\-\:\?\=\&\#\+\%]*[0-9a-zA-Z])+([\!\.\-\:\?\=\&\#\+\%]*[0-9a-zA-Z])+$/;
var zipcodeRE = /^(\d{9}|\d{5}(-\d{4})?)$/;
var currencyRE = /^\d+(\.\d{2})?$/;
var phoneRE = /^\d{3}\-\d{3}\-\d{4}$/;
var areaCodeRE = /\d{3}/;

if (string.length > 0) {
	for (a=0; a < string.length; a++) {
		if (type == "alpha") {
			if (alphaRE.test(string.charAt(a)) == false) {
				return false;
				}
			}
		
		if (type == "alphanumeric") {
			if ((alphaNumRE.test(string.charAt(a)) == false)) {
				return false;
				}
			}
			
		if (type == "numeric") {
			if (numRE.test(string.charAt(a)) == false) {
				return false;
				}
			}
		}// end for
	if (type == "phone") {
		if (phoneRE.test(string) == false) {
			return false;
			}
		}
	if (type == "currency") {
		if (currencyRE.test(string) == false) {
			return false;
			}
		}
	if (type == "email") {
		if (emailRE.test(string) == false) {
			return false;
			}
		}
	if (type == "URL") {
		if (urlRE.test(string) == false) {
			return false;
			}
		}
	if (type == "zipcode") {
		if (zipcodeRE.test(string) == false) {
			return false;
			}
		}
	if (type == "areacode") {
		if (areaCodeRE.test(string) == false) {
			return false;
			}
		}
	}// end if
}

function leftTrim(str) {
returnStr = "";
strStart = 0;
for (a=0; a < str.length; a++) {
	if (str.charAt(a) != " ") {
		strStart = a;
		break;
		}
	}
returnStr = str.substring(strStart,str.length);
return returnStr;
}

function rightTrim(str) {
returnStr = "";
strEnd = 0;
for (a=str.length-1; a > 0; a--) {
	if (str.charAt(a) != " ") {
		strEnd = a+1;
		break;
		}
	}
returnStr = str.substring(0,strEnd);
return returnStr;
}

function strTrim(str,type) {
returnStr = "";
type = type.toUpperCase();
if (str.length > 0) {
	if (type == "L") {
		returnStr = leftTrim(str);
		}
	if (type == "R") {
		returnStr = rightTrim(str);
		}
	if (type == "LR") {
		returnStr = leftTrim(str);
		returnStr = rightTrim(returnStr);
		}
	}
return returnStr;
}