
	/***********************************************************
	 * Validates the blog entry.
	 ***********************************************************/
	function validateEntry() {
		if(document.form.theTitle.value == "") {
			alert("The blog cannot be published without a Title.");
			return false;
		}
		if(document.form.theText.value == "") {
			alert("The blog cannot be published without text.");
			return false;
		}
		document.form.theText.value = replaceNewLinesChars(document.form.theText, "<br />");
		return true;
	}

	/************************************************************************
	 * Validate the reply comments textarea
	 ************************************************************************/	
	function validateReply() {
		
		// Check to make sure a name was entered
		if(trim(document.form.theName.value) == "") {
			alert("Please enter your name or nick name.");
			return false;
		}
		
		// Check the link field for a valid email address or url
		if(!isValidEmailAddress(document.form.theLink.value)) {
			if(!isValidUrl(document.form.theLink.value)) {
				alert("Please enter a valid email address or URL.");
				return false;
			}
		}
		
		// Remove new lines and leading and trailing white space
		document.form.theComment.value = replaceNewLinesChars(document.form.theComment, "<br />");
		
		// Make sure the comment field is not empty or does not have too much text
		var theText = document.form.theComment.value;
		if(theText.length <= 0) {
			alert("Please enter a reply.");
			return false;
		}
		if(theText.length >= 2000) {
			alert("Sorry. There is a maximum number of 2000 characters allowed in the Reply field. " + theText.length + " were found.");
			return false;
		}
		
		return true;
	}
	
	/***********************************************************
	 * Replaces all new line/ carriage return characters 
	 * with html br tags in a textarea
	 ***********************************************************/
	function replaceNewLinesChars(textareaObj, replaceWith) {
		textareaObj.value = escape(textareaObj.value);
		for(i=0; i<textareaObj.value.length; i++) {
			if(textareaObj.value.indexOf("%0D%0A") != -1) {
				//Windows encodes returns as \r\n hex
				textareaObj.value = textareaObj.value.replace("%0D%0A", replaceWith);
			}
			else if(textareaObj.value.indexOf("%0A") != -1) {
				//Unix encodes returns as \n hex
				textareaObj.value = textareaObj.value.replace("%0A", replaceWith);
			}
			else if(textareaObj.value.indexOf("%0D") != -1) {
				//Macintosh encodes returns as \r hex
				textareaObj.value = textareaObj.value.replace("%0D", replaceWith);
			}

		}
		textareaObj.value = unescape(textareaObj.value);
		return textareaObj.value;
	}
	
	/************************************************************************
	 * Replaces all new line characters with br tags
	 ************************************************************************/
	function removeNewLines(theText) {
		for(var i=0; i<theText.length; i++) {
			if(theText.charAt(i).charCodeAt(0) == 10) {
				//theText = theText.substring(0, theText.indexOf(i)) + "<br />" + theText.substring(theText.indexOf(i), theText.length-1);
			}
		}		
		return theText;
	}


	/************************************************************************
	 * "Trims" whitespace from the beginning and the end of a string.
	 ************************************************************************/
	 function trim(str) {
	 	while(str.charAt(0) == ' ') {
	 		str = str.substring(1);
	 	}
	 	while(str.charAt(str.length -1) == ' ') {
	 		str = str.substring(0, str.length -1);
	 	}
	 	return str;
	 }

	/************************************************************************
	 * Validates an email address
	 ************************************************************************/	
	function isValidEmailAddress(emailAddress) {
		var isValid = false;
		if(emailAddress != "") {
			if(emailAddress.indexOf("://") == -1) {
				if(emailAddress.indexOf("@") != -1 && emailAddress.length > 5 && emailAddress.indexOf(".") != -1) {
					isValid = true;
				}
			}
		}
		return isValid;
	}

	/************************************************************************
	 * Validates a URL
	 ************************************************************************/	
	function isValidUrl(theUrl) {
		var isValid = false;
		if(theUrl != "") {
			if(theUrl.length > 5 && theUrl.indexOf(".") != -1) {
				isValid = true;
			}
		}
		return isValid;
	}
		
	/******************************************************
	 * Open the email client with the address filled in.
	 ******************************************************/
	function openEmailClient(theName, theDomainName, theDomainType) {
		window.location = "mailto:" + theName + "@" + theDomainName + "." + theDomainType;
	}
	
	/******************************************************
	 * Return the email address string.
	 ******************************************************/
	function getEmailAddress(theName, theDomainName, theDomainType) {
		return theName + "@" + theDomainName + "." + theDomainType;
	}

	/***********************************************************
	 * Replaces all new line/ carriage return characters 
	 * with html br tags.
	 ***********************************************************/
	function escapeVal(textareaObj, replaceWith) {
		textareaObj.value = escape(textareaObj.value);
		for(i=0; i<textareaObj.value.length; i++) {
			if(textareaObj.value.indexOf("%0D%0A") != -1) {
				//Windows encodes returns as \r\n hex
				textareaObj.value = textareaObj.value.replace("%0D%0A", replaceWith);
			}
			else if(textareaObj.value.indexOf("%0A") != -1) {
				//Unix encodes returns as \n hex
				textareaObj.value = textareaObj.value.replace("%0A", replaceWith);
			}
			else if(textareaObj.value.indexOf("%0D") != -1) {
				//Macintosh encodes returns as \r hex
				textareaObj.value = textareaObj.value.replace("%0D", replaceWith);
			}

		}
		textareaObj.value = unescape(textareaObj.value);
	}		