	//Removes all characters but numbers
	function leaveNumbersOnly(obj){
		obj.value = obj.value.replace(/\D/g,"");
	}

	//Formats the postal or zip code
	function formatPostal(obj,e){
		var cur_val = obj.value;
		var regExp = new RegExp;
		var regExpZip = new RegExp;
		var regExpPostal = new RegExp;
		var regExpAllowed = new RegExp;
		regExp = /^[A-Z]|^\d/i;
		regExpZip = /^\d+$/;
		regExpPostal = /^[a-z]\d[a-z]\s\d[a-z]\d$/i
		regExpAllowed = /[a-z0-9]/i;
		cur_val =  cur_val.replace(/[^a-z0-9]/gi,"");
		if(regExpAllowed.test(String.fromCharCode(e.keyCode))){
			if (regExp.test(cur_val)){
				if (!regExpZip.test(cur_val)){
					if (cur_val.length > 4){
						cur_val = cur_val.substr(0,3) + " " + cur_val.substr(3,3);
					}
					if (cur_val.length == 7 && !regExpPostal.test(cur_val)){
						alert("It appears that you have entered an invalid postal code.");
					}
				}
			}
			else{
				cur_val = "";
			}
		}
		if (obj.value != cur_val){
			obj.value = cur_val.toUpperCase();
		}
	}

	//Formats the phone number as the user is typing it in.
	function formatPhone(obj,e){
		var cur_val = obj.value;
		var regExp = new RegExp;
		var regExp2 = new RegExp;
		regExp = /^\(?\d{3}\)?\s?\d{3}\-?\d{4}$/;
		regExp2 = /^\d+$/;
		cur_val =  cur_val.replace(/\D/gi,"");
		if (regExp2.test(cur_val)){
			if (cur_val.length < 4){
				cur_val = "(" + cur_val.substr(0,3);
			}
			else if(cur_val.length < 7){
				cur_val = "(" + cur_val.substr(0,3) + ") " + cur_val.substr(3,3);
			}
			else if(cur_val.length < 11){
				cur_val = "(" + cur_val.substr(0,3) + ") " + cur_val.substr(3,3) + "-" + cur_val.substr(6,4);
			}
		}
		if (cur_val.length <= 14){
			obj.value =  cur_val;
		}
	}

	//Changes the first character to upper case
	function uCaseFirst(obj,doRst){
		var t_val = obj.value.substr(0,1);
		t_val = t_val.toUpperCase();
		if (doRst){
			t_val = t_val + obj.value.substr(1,obj.value.length - 1).toLowerCase();
		}
		else{
			t_val = t_val + obj.value.substr(1,obj.value.length - 1);
		}
		obj.value = t_val;
	}

	//Resets the class name of a particular element on a form
	function resetFormElement(obj){
		obj.className = "SmallText";
		obj.style.backgroundColor = "";
	}

	//Resets the form to it's original state
	function resetForm(clr){
		var styleObject = document.getElementById('sendinfo').elements;
		var nameRegExp = new RegExp;
		RegExpName = /^pid$|^submit$|^clear$|^preview$/i;
		if (styleObject != null){
			for(var i = 0; i < styleObject.length; i++){
				if (!RegExpName.test(styleObject[i].name)){
					styleObject[i].className = "SmallText";
					styleObject[i].style.backgroundColor = "";
					if (clr){
						styleObject[i].value = "";
					}
				}
			}
		}
	}

	//Displays the remaining number of characters that a user is allowed to enter in a field
	//Doesn't get called for Backspace or Delete for some reason
	function countChar(obj){
		var storyMax = 2048;
		var briefMax = 500;
		var max = 0;
		var len = obj.value.length;
		var left = 0;
		var styleObject;
		if (obj.name == "story"){
			styleObject = document.getElementById("storyChar");
			max = storyMax;
		}
		else{
			styleObject = document.getElementById("briefChar");
			max = briefMax;
		}
		left = max - len;
		if (left < 0){
			alert("You have entered the maximum number of characters allowed in this field.");
			left = 0;
		}
		if (styleObject != null){
			styleObject.innerHTML="# of characters remaining: " + left;
		}
		obj.value = obj.value.substr(0,max)
	}

	//Highlights the value currently in a field if it matches the value passed in
	function highlightField(obj,match){
		if (obj.value == match){
			if (document.selection){
				var sel = document.selection.createRange();
				sel.moveStart('character',0);
				sel.moveEnd('character',obj.value.length);
				sel.select();
			}
			else{
				obj.setSelectionRange(0,obj.value.length);
			}
		}
	}

	//Formats the date be entered into the text box
	function formatDate(obj,e,frmt){
		var origVal = obj.value;
		var tmpVal = "";
		var tmpChr = "";
		var tmpChr2 = "";
		var valDate = new RegExp;
		var keyMap = new RegExp;
		keyMap = /^8$|^08|^13$|^33$|^34$^35$|^36$|^37$|^39$|^46$/;
		if (!keyMap.test(e.keyCode)){
			if (frmt == 'mm/dd/yyyy'){
				valDate = /^(0[1-9]|1[0-2])([0-2]{1}[1-9]{1}|[1-2]{1}[0-9]{1}|3[0-1]{1})20\d\d$/;
				tmpChr = obj.value.substr(1,1);
				tmpChr2 = obj.value.substr(4,1);
				leaveNumbersOnly(obj);
				if (obj.value < 2){
					tmpVal= obj.value
				}
				else if (tmpChr == "/" || obj.value.substr(0,1) > 1){
					tmpVal="0" + obj.value.substr(0,1) + "/";
				}
				else if(obj.value.length < 4 && obj.value.length > 1){
					tmpVal = obj.value.substr(0,2) + "/" ;
					if (tmpChr2 == "/" || parseInt(obj.value.substr(2,1)) > 3){
						tmpVal = tmpVal + "0"; 
					}
					tmpVal = tmpVal + obj.value.substr(2,2);
				}
				else if (obj.value.length > 3 && obj.value.length < 8){
					tmpVal = obj.value.substr(0,2) + "/" + obj.value.substr(2,2) + "/" + obj.value.substr(4,4);
				}
				else if (!valDate.test(obj.value)){
					tmpVal = "";
					alert('It appears that you have entered an invalid date.  The format of the date is mm/dd/yyyy');
				}
				else if (!isLeapYear(obj.value.substr(obj.value.length - 4, 4)) && obj.value.substr(0,4) == "0229"){
					tmpVal = "";
					alert('It appears that you have entered an invalid date.  This is not a leap year, so there are only 28 days in February.');					
				}
				else{
					tmpVal = origVal;
				}
			}
			else{
				tmpVal = obj.value;
			}
			obj.value = tmpVal;
		}
	}

	//Checks to see if the current year is a leap year
	function isLeapYear(cYR) {
		return new Date(cYR,1,29).getDate() == 29;
	}

	//Checks to make sure a proper id is being entered
	function checkIDs(obj,e, sep){
		if (sep == 0) {
			leaveNumbersOnly(obj);
		}
		else{
			obj.value=obj.value.replace(/[A-Z\s]/gi,"");
			var regExpIDs = new RegExp;
			regExpIDs = /^[\d+\,*]+$/;
			if (!regExpIDs.test(obj.value) && obj.value != ""){
				alert('It appears that you are trying to enter an invalid client id.  If multiple client ids are required seperate them with commas.');
				return false;
			}
		}
	}


