function trimChars(what, limit) {
	document.getElementById('charsLeft').innerHTML = "You have <span>" + (limit - what.value.length) + "</span> characters left.";
	if (what.value.length>=limit)
	{
		what.value = what.value.substring(0,limit);
	document.getElementById('charsLeft').innerHTML = "You have <span>" + (limit - what.value.length) + "</span> characters left.";
	}
}

function resetChars(limit) {
	document.getElementById('charsLeft').innerHTML = "You have <span>" + limit + "</span> characters left."
}

function toRedBorder(e) {
	if (!e) var e = window.event;
	var element;
	if (!e.srcElement) {element = e.target} else {element = e.srcElement}
	element.style.border="2px inset #CC0000";
	element.select();
}


function toNormalBorder(e) {
	if (!e) var e = window.event;
	var element;
	if (!e.srcElement) {element = e.target} else {element = e.srcElement}
		element.style.border="2px inset #E0E0E0";
}


function validator(theForm) {
	if (theForm.btnSubmit == "Submit") {
		var isValid = true;
		var errString;
		
		//reset text field styles
		theForm.user_name.onfocus = null;
		theForm.user_name.onblur = null;
		theForm.user_name.className = theForm.user_name.className.replace(/ hlite/,'');
		
		theForm.user_email.onfocus = null;
		theForm.user_email.onblur = null;
		theForm.user_email.className = theForm.user_email.className.replace(/ hlite/,'');
		
		theForm.user_text.onfocus = null;
		theForm.user_text.onblur = null;	
		theForm.user_text.className = theForm.user_text.className.replace(/ hlite/,'');
		
		//begin constructing error list
		errString = "<div class='errorlist'><img src='/Images/Icons/alert.gif' alt='graphic:alert' width='16' height='16' class='icons'/>Please review the following:<ul>";
		
		//Check for empty name field
		if (theForm.user_name.value == "")
		{
			errString += "<li>Please include at least your first <label for='user_name' class='alookalike'>Name</label>.</li>";
			theForm.user_name.onfocus = toRedBorder;
			theForm.user_name.onblur = toNormalBorder;
			theForm.user_name.className += theForm.user_name.className?' hlite':'hlite';
			isValid = false;
		}
		
		//Check for empty email field
		if (theForm.user_email.value == "")
		{
			errString += "<li>Please enter an <label for='user_email' class='alookalike'>E-mail</label> address.</li>";
			theForm.user_email.onfocus = toRedBorder;
			theForm.user_email.onblur = toNormalBorder;
			theForm.user_email.className += theForm.user_email.className?' hlite':'hlite';
			isValid = false;
		}
		
		//Check for emtpy question field
		if (theForm.user_text.value == "")
		{
			errString += "<li>Please enter a <label for='user_text' class='alookalike'>Message</label>.</li>";
			theForm.user_text.onfocus = toRedBorder;
			theForm.user_text.onblur = toNormalBorder;
			theForm.user_text.className += theForm.user_text.className?' hlite':'hlite';
			isValid = false;
		}
		
		//Check for too full question field
		if (theForm.user_text.value.length > 500)
		{
			errString += "<li><label for='user_text' class='alookalike'>Message</label> must be less than 500 characters.</li>";
			theForm.user_text.onfocus = toRedBorder;
			theForm.user_text.onblur = toNormalBorder;
			theForm.user_text.className += theForm.user_text.className?' hlite':'hlite';
			isValid = false;
		}
		
		//finish error list
		errString += "</ul></div>";
		
		//if invalid submission, display the error list
		if(!isValid) {
			document.getElementById('errors').innerHTML = errString;
		}
		return isValid;
	}
}
