	
	
	// Adding comments ----------------------------------------------------------------------------------------
	
	var httpSubmit = createRequestObject();
	
	function addComment()
	{
  		str = getFormValues(document.form1);
		httpSubmit.open('post', 'ajaxScripts/addComment.php');
		httpSubmit.onreadystatechange = handleCommentResponse;
		httpSubmit.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=ISO-8859-1");
		httpSubmit.send(str);
		document.getElementById("responseContent").setAttribute("class","loading");
		showResponseLayer();
	}
	
	function handleCommentResponse()
	{
		if(httpSubmit.readyState == 4)
		{
			var response = httpSubmit.responseXML;
			
			switch(response.getElementsByTagName("exitCode")[0].firstChild.nodeValue)
       		{           				
				case '0':
					var content = response.getElementsByTagName("content")[0].firstChild.nodeValue;
					document.getElementById("responseContent").setAttribute("class","responses");
					document.getElementById("responseContent").innerHTML = content;
					setTimeout("updateCommentsTable()", 1000);
           			break;
						
				case '7':
       			case '-1':
       			default:
					var content = response.getElementsByTagName("content")[0].firstChild.nodeValue;
					document.getElementById("responseContent").setAttribute("class","error");
					document.getElementById("responseContent").innerHTML = content;
           			break;
			}
		}
		else
		{
			document.getElementById("responseContent").innerHTML = "Processing data...";
		}
	}
	
	// Adding comments ----------------------------------------------------------------------------------------
	

	// Updating comments table --------------------------------------------------------------------------------
	
	var httpUpdateTable = createRequestObject();
	
	function updateCommentsTable()
	{
		hideResponseLayer();
		httpUpdateTable.open('get', 'ajaxScripts/updateCommentsTable.php?cI='+document.getElementById("imageId").value);
		httpUpdateTable.onreadystatechange = handleUpdateCommentsTableResponse;
		httpUpdateTable.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=ISO-8859-1");
		httpUpdateTable.send(null);
		document.getElementById("commentsTable").innerHTML = "";
		showElement("loadingRow");
		document.getElementById("loading").setAttribute("class","loading");
	}
	
	function handleUpdateCommentsTableResponse()
	{
		if(httpUpdateTable.readyState == 4)
		{
			hideElement("loadingRow");
			var response = httpUpdateTable.responseXML;
			
			switch(response.getElementsByTagName("exitCode")[0].firstChild.nodeValue)
       		{           				
				case '0':
					var content = response.getElementsByTagName("content")[0].firstChild.nodeValue;
					document.getElementById("commentsTable").innerHTML = content;
					hideResponseLayer();
					document.form1.reset();
           			break;
           			
				case '7':
       			case '-1':
       			default:
					var content = response.getElementsByTagName("content")[0].firstChild.nodeValue;
					document.getElementById("commentsTable").innerHTML = content;
					showResponseLayer();
           			break;
			}
		}
		else
		{
			document.getElementById("loading").innerHTML = "Reloading table...";
		}
		
		clearInsertionForm();
	}
	
	// Updating comments table --------------------------------------------------------------------------------
	
	
	// Deleting comments --------------------------------------------------------------------------------------
	
	var httpDelete = createRequestObject();
	
	function deleteComment(id)
	{
		httpDelete.open('get', 'ajaxScripts/deleteComment.php?id='+id);
		httpDelete.onreadystatechange = handleDeleteResponse;
		httpDelete.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=ISO-8859-1");
		httpDelete.send(null);
	}
	
	function handleDeleteResponse()
	{
		if(httpDelete.readyState == 4)
		{
			var response = httpDelete.responseXML;
			
			switch(response.getElementsByTagName("exitCode")[0].firstChild.nodeValue)
       		{           				
				case '0':
					updateCommentsTable();
           			break;
           			
				case '7':
       			case '-1':
       			default:
					updateCommentsTable();
           			break;
			}
		}
		else
		{
			return;
		}
	}
	
	// Deleting comments --------------------------------------------------------------------------------------
	
	
	
	function askBefore(id)
	{
		if(confirm("Sei sicuro di voler cancellare questo commento?"))
		{
			deleteComment(id);
		}
	}
	
	
	function replyToThis(id)
	{
		document.getElementById("subject").value = "Re: "+document.getElementById(id+"subject").innerHTML;
		document.getElementById("replyto").value = id;
		if(document.body.scrollHeight)
		{ 
  			window.scrollTo(0, document.body.scrollHeight); 
		} 
		elseif(screen.height)
		{ // IE5 
  			window.scrollTo(0, screen.height); 
		}
	}
	
	function clearInsertionForm()
	{
		document.getElementById("replyto").value = "";
		document.getElementById("subject").value = "";
		document.getElementById("testo").value = "";
	}
	
	function showHideReplies(id)
	{
		if(document.getElementById(id+"replies").style.display=="none")
		{
			if(whichBrs()=="Internet Explorer")
			{
				document.getElementById(id+"replies").style.display="block";
			}
			else
			{
				document.getElementById(id+"replies").style.display="table";
			}
			document.getElementById(id+"_img").src="images/minus.gif";
		}
		else
		{
			document.getElementById(id+"replies").style.display="none";
			document.getElementById(id+"_img").src="images/plus.gif";
		}
	}
	
	function notReplyingTo()
	{
		document.getElementById("replyto").value = "";
	}
	
