var AddCommentPanel = false;
function addComment()
{	
	function handleSuccess(o){
	  	responseJSON = o.responseText.parseJSON();
	   	if (responseJSON.status){
			alert(responseJSON.msg);
			getElement('addCommentForm').Comment.value = '';
	   	}
	   	else
	   		alert(responseJSON.msg);
	   	AddCommentPanel.hide();
	}	
	YAHOO.util.Connect.setForm('addCommentForm');	
    var urlArray = new Array(baseUrl, 'comments', objectType, objectID);
    var urlStr	= urlArray.join('/');      			
		
    YAHOO.util.Connect.asyncRequest('POST', urlStr, {success:handleSuccess,failure:function(o){alert('Server Error');AddCommentPanel.hide();}});
	
}

function initAddCommentDialog() 
{	
	getElement('addCommentDialog').style.display = "block";
	
	var handleCancel = function() {
		this.cancel();
		getElement('addCommentForm').reset();		
	};
	var handleSuccess = function(o) {		
    	responseJSON = o.responseText.parseJSON();
    	if (responseJSON.status){
    		alert(responseJSON.msg);
    		getElement('addCommentForm').reset();    		    		
    	}	
    	else
    		alert(responseJSON.msg);    	    	
	};
	var handleFailure = function(o) {
		alert('Server Error!');		
	};	
	
	AddCommentPanel	= new YAHOO.widget.Dialog("addCommentDialog", 
							{ width : "35em",
							  fixedcenter : true,
							  visible : false, 
							  constraintoviewport : true,							
							  draggable: false,							  
							  modal:true,							  
							  buttons : [	{ text:"Add Comment",	handler:addComment},
								      		{ text:"Cancel", 		handler:handleCancel } ]
							});
	AddCommentPanel.callback = { success: handleSuccess, failure: handleFailure };
	AddCommentPanel.render();
	YAHOO.util.Event.addListener("AddCommentButton", "click", AddCommentPanel.show, AddCommentPanel, true );
}
YAHOO.util.Event.onDOMReady(initAddCommentDialog);