function processReqField() {
	// parameters should be processReqField(FieldID as str,FieldValueType as str,ErrorMessage as str,[minCharLength as int])
	// FieldValueType possibilities are 
	var fieldID = arguments[0];
	var valType = arguments[1];
	var msg = arguments[2];
	var charLength = (arguments[3]) ? arguments[3] : 0;
	var returnVal = "";
	var theField = document.getElementById(fieldID);
	theField.className='nonErrorStyle';
	switch(valType) {
		case 'text':
			if( (theField.value == "") || (theField.value.length < charLength)) { 
				returnVal = msg + "<br>"; 
				theField.className='errorStyle';
			}
			break;
		case 'email':
			if( theField.value == "" || !isEmail( theField.value ) ) {
				returnVal = msg + "<br>"; 
				theField.className='errorStyle';
			}
			break;
		case 'phone':
			if( theField.value == "" || !isPhoneNumber( theField.value ) ) {
				returnVal = msg + "<br>"; 
				theField.className='errorStyle';
			}
			break;
		case 'ddl':
			if( theField[theField.selectedIndex].value == "" ) {
				returnVal = msg + "<br>"; 
				theField.className='errorStyle';
			}
			break;
		case 'zip':
			if(!isPostalCode( theField.value ) && !isZip( theField.value ) ) {
				returnVal = msg + "<br>"; 
				theField.className='errorStyle';
			}
			break;
	}
	return returnVal;
}



//Validation Functions//
function isEmail(string) {
    if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
        return true;
    else
        return false;
}
function isPhone(string) {
    if (string.search(/^\d{10}/) != -1)
        return true;
    else
        return false;
}
function isPhoneNumber(string) {
    if (string.search(/^(1\s*[-\/\.]?)?(\((\d{3})\)|(\d{3}))\s*[-\/\.]?\s*(\d{3})\s*[-\/\.]?\s*(\d{4})\s*(([xX]|[eE][xX][tT])\.?\s*(\d+))*$/) != -1)
        return true;
    else
        return false;
}
function isZip(string) {
    if (string.search(/^\d{5}/) != -1)
        return true;
    else
        return false;
}
function isArea(string) {
    if (string.search(/^\d{3}/) != -1)
        return true;
    else
        return false;
}
function isTwoLetters(string) {
    if (string.length > 1)
        return true;
    else
        return false;
}
function isPhoneSeven(string) {
    if (string.search(/^(\((\d{3})\)|(\d{3}))\s*[-\/\.]?\s*(\d{4})\s*(([xX]|[eE][xX][tT])\.?\s*(\d+))*$/) != -1)
        return true;
    else
        return false;
}
function isFourLetters(string) {
    if (string.length > 3)
        return true;
    else
        return false;
}
function isPostalCode(string) {
    if (string.search(/^\s*[a-ceghj-npr-tvxy]\d[a-ceghj-npr-tv-z](\s)?\d[a-ceghj-npr-tv-z]\d\s*$/i) != -1) {
        return true;
	} else {
        return false;
	}
}
function correctPhoneNumber (string) {
	 phoneNumber = string.replace(/ /g,"");
	 phoneNumber = phoneNumber.replace(/\(/g,"");
	 phoneNumber = phoneNumber.replace(/\)/g,"");
	 phoneNumber = phoneNumber.replace(/-/g,"");
	 phoneNumber = phoneNumber.replace(/\./g,"");
	 return phoneNumber;
}



//utility functions//
function trim(str){
	while(''+str.charAt(0)==' ')
	str=str.substring(1,str.length);
	while(''+str.charAt(str.length-1)==' ')
	str=str.substring(0,str.length-1);
	return str;
}
