
	
	function screenHeight() {
		// handle IE 6
		if ($.browser.msie && $.browser.version < 7) {
			var scrollHeight = Math.max(
				document.documentElement.scrollHeight,
				document.body.scrollHeight
			);
			var offsetHeight = Math.max(
				document.documentElement.offsetHeight,
				document.body.offsetHeight
			);

			if (scrollHeight < offsetHeight) {
				return $(window).height() + 'px';
			} else {
				return scrollHeight + 'px';
			}
		// handle "good" browsers
		} else {
			return $(document).height() + 'px';
		}
	}

	function screenWidth() {
		// handle IE 6
		if ($.browser.msie && $.browser.version < 7) {
			var scrollWidth = Math.max(
				document.documentElement.scrollWidth,
				document.body.scrollWidth
			);
			var offsetWidth = Math.max(
				document.documentElement.offsetWidth,
				document.body.offsetWidth
			);

			if (scrollWidth < offsetWidth) {
				return $(window).width() + 'px';
			} else {
				return scrollWidth + 'px';
			}
		// handle "good" browsers
		} else {
			return $(document).width() + 'px';
		}
	}
	
	

	
	function autoGrow(minHeight,maxHeight) {
		var minHgt = minHeight ? minHeight:15;
		var maxHgt = maxHeight ? maxHeight:150;
	
		if ($('#textarea_holder')) {
			$('#textarea_holder').css('width',($('#comments').width()-5) + 'px');
			var html = $('#comments').val(); /*.replace(/(<|>)/g, '');*/
			html = html.replace(/\n/g, '<br>');
			$('#textarea_holder').html(html);
			if (html == '') {
				$('#comments').css('height',minHgt+ 'px');
			} else {
				
				var textHeight = $('#textarea_holder').height()+15;
				if (textHeight < minHgt) { textHeight = minHgt; }
				if (textHeight > maxHgt) { textHeight = maxHgt; $('#comments').css('overflow','auto'); } else { $('#comments').css('overflow','hidden'); }
				if (textHeight != $('#comments').height()) { $('#comments').animate({ height:(textHeight)+ 'px' }, 300 ); }
			}
		}
	}
	
	function postComment(type) {
		var errors = false;
		var errorList = '';
				
		if ($('#email').val() != '' && valEmail($('#email').val()) == false) {
			$('#email').css('border-color','#cc0000');
			errors = true;
			errorList = errorList + '<li>Please enter a valid email address.</li>';
		} else { $('#email').css('border-color',''); }
	
		if (trim($('#username').val()) == '') {
			$('#username').css('border-color','#cc0000');
			errors = true;
			errorList = errorList + '<li>Please enter your name.</li>';
		} else { $('#username').css('border-color',''); }
		
		if (trim($('#comments').val()) == '') {
			$('#comments').css('border-color','#cc0000');
			errors = true;
			errorList = errorList + '<li>Please enter a comment.</li>';
		} else { $('#comments').css('border-color','');}
	
		// Return errors
		if (errors == true) {
			$('#errorBox').html(errorList);
		} else {
			$('#postingComment').css('height',$('#commentInput').height() + 'px');
			$('#commentInput').css('display','none');
			$('#postingComment').css('display','');
			$('#errorBox').html('');
			
			// Post comment to server.
			$.post('/includes/blog.cfm?' + Math.random() * 999999, { comments: 'add', aid: $('#aid').val(), name: $('#username').val(), email: $('#email').val(), comment: $('#comments').val()	}, function (data, textStatus) { 
				$('#postingComment').before(data);
				$('#postingComment').css('display','none');
				$('#commentInput').css('display','');
				$('#comments').val('');
				autoGrow(30,300);
			});
	
		} //end if else
	}
	
	
	function showAllComments() {
		$('#showMoreComments').animate('opacity:0,filter:alpha(opacity=0)', 0.3, function() { 
				$('#showMoreComments').style.overflow = 'hidden';
				$('#showMoreComments').animate('height:1px', 0.2 ,function() { $('#showMoreComments').style.display ='none'; });
			}
		);
		$('#hiddenCommentsWrapper').animate('height:' + $('#hiddenComments').height() + 'px', 0.5, 
			function() { 
				$('#hiddenCommentsWrapper').style.height=''; 		
			}
		);
	}
	
	
	function valEmail(email) {
		invalidChars = " /:,;"
		if (email == "Required") {
			return false
		}
		for (i=0; i<invalidChars.length; i++) {
			badChar = invalidChars.charAt(i)
			if (email.indexOf(badChar,0) != -1) {
				return false
			}
		}
		atPos = email.indexOf("@",1)
		if (atPos == -1) {
			return false
		}
		if (email.indexOf("@",atPos+1) != -1) {
			return false
		}
		periodPos = email.indexOf(".",atPos)
		if (periodPos == -1) {
			return false
		}
		if (periodPos+3 > email.length)	{
			return false
		}
	
		return true
	}
	
	
	function ltrim(str) {
		while (1) {
			if (str.substring(0, 1) != " " && str.substring(0, 1) != "\n" && str.substring(0, 1) != "\r")
			break;
			str = str.substring(1, str.length);
		} //end while
		
		return str;
	} //end function
	
	
	function rtrim(str) {
		while (1) {
			if (str.substring(str.length - 1, str.length) != " " && str.substring(str.length - 1, str.length) != "\n" && str.substring(str.length - 1, str.length) != "\r")
			break;
			str = str.substring(0, str.length - 1);
		} //end while
		
		return str;
	} //end function
	
	
	function trim(str) {
		return ltrim(rtrim(str));
	} //end function	
	
	