// JavaScript Document
function edit_comment(comment_id)
{
	var ourBox = document.getElementById('edit_comment_box_'+comment_id);
	
	if (ourBox.style.display == 'none')
		ourBox.style.display = 'block';
	else
		ourBox.style.display = 'none';
}

// ------------------------------------
//  Handles the AJAX Requests
// -------------------------------------    

function submit_edited_comment(comment_id)
{
	try
	{
		XMLHttp = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch (e)
	{
		try
		{
			XMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (e2)
		{
			XMLHttp = null;
		}
	}
	
	if( ! XMLHttp && typeof XMLHttpRequest != "undefined")
	{
		XMLHttp = new XMLHttpRequest();
	}
	
	if ( ! XMLHttp)
	{
		alert('Browser Not Support'); return false;
	}
	
	var bleah = document.getElementById('edit_comment_box_'+comment_id);
	
	var content = bleah.getElementsByTagName('textarea')[0].value;
	
	var data =  "comment_id=" + encodeURIComponent(comment_id) + 
				"&comment=" + encodeURIComponent(content);
	
	XMLHttp.onreadystatechange = function () { result_of_comment_edit(comment_id); }
	XMLHttp.open("POST", "http://www.hawaii-guide.com/index.php/includes/edit_comment/", true);
	XMLHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	XMLHttp.setRequestHeader("Connection", "close");
	XMLHttp.send(data);
}


function result_of_comment_edit(comment_id)
{
	if (XMLHttp.readyState == 4)
	{
		document.getElementById('edit_comment_box_'+comment_id).style.display = 'none';
	
		if (XMLHttp.status != 200) 
		{
			alert("An error was encountered: " + XMLHttp.status);
			return;
		}
		
		var response = XMLHttp.responseText;
		
		if (response == 'null')
		{
			alert('Invalid Comment Edit');
			return;
		}
		
		document.getElementById('comment_box_' + comment_id).innerHTML = response;
	}
}
