	var http_request = false;
	function loadXMLDoc(url, parameters, callback, mime)
	{
		if( window.XMLHttpRequest )
		{
			//for non Microsoft browsers
			http_request = new XMLHttpRequest();
			if( http_request.overrrideMimeType )
				http_request.overrideMimeType( mime );
		}
		else if( window.ActiveXObject )
		{
			//for IE
			try
			{
				http_request = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch(e)
			{
				try
				{
					http_request = new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch(e)
				{
					onFail("Your browser does not support this operation");
					return false;
				}
			}
		}
		
		if( !http_request )
		{
			onFail("Your browser does not support this operation");
			return false;
		}
		
		http_request.onreadystatechange = callback;
		http_request.open( 'POST', url, true );
		http_request.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded" );
		http_request.setRequestHeader( "Content-length", parameters.length );
		http_request.setRequestHeader( "Connection", "close" );
		http_request.send( parameters );
		
	}
		
	function alertContents()
	{
		var processedOutput = 0;
		
		if( http_request.readyState == 4 )
		{
			if( http_request.status == 200 )
			{
				if( http_request.responseXML != null )
				{
					var rsCntr = http_request.responseXML.getElementsByTagName("response")[0];
                    var status = parseInt( rsCntr.getElementsByTagName("result")[0].childNodes[0].nodeValue.toString() );
                    var statusTxt = rsCntr.getElementsByTagName("text")[0].childNodes[0].nodeValue.toString();
															
					processedOutput = 1;
					
					if( status == 1 )
					{
						// Generate a random number so that the page gets reloaded by the browser
						var randomnumber = Math.floor(Math.random()*10001)
						window.location = "/guestbook/1/" + randomnumber;
					}
					else
					{
						onFail( statusTxt );
					}
				}
				else
				{
					onFail("Sorry! Unable to communicate with server.");
				}
			}
			else
			{
				onFail( http_request.statusText );
			}
		}
		else
		{
			switch( http_request.readyState )
			{
				case 1:
					progressUpdate("Loading...");
					break;
				case 2:
					progressUpdate("Loaded...");
					break;
				default:
					break;	
			}
		}
		
	}
	
	// Here we begin the comments input ajax scripts ---------------------------->
	function onSuccess( statusTxt, cmt, pagenav )
	{
		/* we close the comment input and then display the status text. It will be in
			display anyway because of progress updates.  Then we start the timer to 
			close the status text */
					
		toggleCommentInputVisibility();
		
		clearCommentFields();
		
		if( isStatusTextVisible() == false )						
			toggleStatusTextVisibility();
		document.getElementById('ajaxstatustext').innerHTML = statusTxt;
		document.getElementById('viewcommentstext').innerHTML = cmt;
		document.getElementById('commentsnavigation').innerHTML = pagenav;
		setTimeout('clearStatusText()', 4000);
	}
	
	function onFail( statusTxt )
	{
		/* On failure, we don't close the comment input.  But we'll just set the 
			status text */
		if( isStatusTextVisible() == false )	
			toggleStatusTextVisibility();
		document.getElementById('ajaxstatustext').innerHTML = statusTxt;
		setTimeout('clearStatusText()', 4000);
	}
	
	function isStatusTextVisible()
	{
		if( document.getElementById('ajaxstatustext').style.display == 'none' )
			return false;
		else
			return true;
	}
	
	function progressUpdate( statusTxt )
	{
		if( isStatusTextVisible() == false )
			toggleStatusTextVisibility();
		document.getElementById('ajaxstatustext').innerHTML = statusTxt;
		
	}
	
	function toggleStatusTextVisibility()
	{
		var objContainer = document.getElementById('ajaxstatus');
		var objText = document.getElementById('ajaxstatustext');
		
		/* the master container div's display needs to be manipulated in order
			IE to work properly.  Otherwise it leaves a space */
			
		if( objText.style.display != 'none' )
		{
			
			//objContainer.style.display = 'none';
			//objContainer.style.visibility = 'hidden';
			
			objText.style.visibility = 'hidden';
			objText.style.display = 'none';
		}
		else
		{
			//objContainer.style.display = 'block';
			//objContainer.style.visibility = 'visible';
			
			objText.style.visibility = 'visible';
			objText.style.display = 'inline';
		}
	}
	
	function toggleCommentInputVisibility()
	{
		var obj = document.getElementById('commentcontainer');
		if( obj.style.display != 'none' )
		{
			obj.style.display = 'none';
			obj.style.visibility = 'hidden';
			document.getElementById('comments').style.height = 25 + 'px';
		}
		else
		{
			obj.style.display = 'block';
			obj.style.visibility = 'visible';
		}
		
		
	}
	function clearStatusText()
	{
		if( isStatusTextVisible() == true )
			toggleStatusTextVisibility();
	}
	
	function clearCommentFields()
	{
		clearFields(document.commentform.name);
		clearFields(document.commentform.email);
		clearFields(document.commentform.comments);
	}
	
	function clearFields( fieldname )
	{
		fieldname.value = "";
	}
	
	 function displayComments()
	 {
		var obj = document.getElementById('commentcontainer');
		document.location = "#";
		if( obj.style.visibility != 'visible' )
			toggleCommentInputVisibility();
		document.commentform.name.focus();
		
     }
	 
	 function discardCommentsInputView()
	 {
	 	toggleCommentInputVisibility();
	 }
	 
	 function processComments()
	 {
	 	if(document.getElementById)
		{
	 		var formObj = document.getElementById('commentform');
			var poststr = "name=" + encodeURI( document.getElementById('name').value ) +
			              "&email=" + encodeURI( document.getElementById('email').value ) +
						  "&locate=" + encodeURI( document.getElementById('locate').value ) +
						  "&comments=" + encodeURI( document.getElementById('comments').value );
			loadXMLDoc('/addguestbookentry', poststr, alertContents, 'text/xml');
							 
		}
	 }
	 
	 var clearedField = 0;
	 
	 function clearTextField( fieldName )
	 {
	 	if( clearedField == 0 )
		{
	 		fieldName.value = "";
			clearedField = 1;
		}
		if( fieldName == document.commentform.comments )
		{
			document.getElementById('comments').style.height = 200 + 'px';
		}
	 }
	 
	 function clipTextField( field )
	 {
	 	maxLimit = 50;
		if( field.value.length > maxLimit )
			field.value = field.value.substring( 0, maxLimit );
	 }
	 
	 // Here we begin the comments view ajax scripts ----------------
	 
	 function initPage()
	 {
	 	 // comment input
		 	 
		 obj = document.getElementById('ajaxstatustext');
		 obj.style.display = 'none';
		 obj.style.visibility = 'hidden';
		 
		 var obj = document.getElementById('commentcontainer');
		 obj.style.display = 'none';
		 obj.style.visibility = 'hidden';
			     
	 }
	 
