
function validate()
{
	if (!validateText("friend_name", "Your Name")) return false;
	
	if (!validateText("name_first", "Friend First Name")) return false;
	
	if (!validateText("name_last", "Friend Last Name")) return false;
	
	if (!validateText("email", "Friend Email Address")) return false;
	
	var comment = getElem("s_friend_comment");
	if(comment.value.length > 255)
	{
		alert("Your comment has exceeded the 255 character limit.\nPlease reduce the number of characters in your comment.");
		comment.value = comment.value.substring(0,maxL-1);
		comment.focus();
		return false;
	}

	return true;
}

function getElem(name)
{
	return document.getElementById(name);
}


function validateText(name, text)
{
	var pass = true;
	
	var textBox = getElem("s_" + name);
	if (textBox.value == "")
	{
		pass = false;
		alert(text + " is required.");
	}
	
	return pass;
}


maxL = 255;
hasAlerted = false;

function validate255(item)
{
	var keyCount = item.value.length;
	if (keyCount > maxL)
	{
		if (!hasAlerted)
		{
			alert("This has a maximum of 255 characters");
		}
		item.value = item.value.substring(0,maxL-1);
		hasAlerted = true;
	}
}
