/**
 * Codestars inappropriate content management
 * @author Floris Weijenburg (http://www.florisweijenburg.nl)
 * @copyright (c) 2008 Floris Weijenburg
 */ 

CS.kernel.inappropriate = function(itemId, itemType) 
{
	this.Url = CS.kernel.replies.prototype.GetUrlVars();
	this.ajaxRequestHandler = config.rootFolder + 'ajax/ajaxDataHandler.php';
	this.itemId = itemId;
	this.itemType = itemType;

	this.Init(itemType);
}

CS.kernel.inappropriate.prototype.Init = function(itemType)
{
	CS.DOM.tools.ShowDialog
	(
		"Ongepast " + itemType + " melden", 
		config.rootFolder + "includes/templates/inappropriateContent.tpl", 
		"external"
	);
		
	// Add inappropriate submit button onclick event
	YAHOO.util.Event.onDOMReady(function() 
	{
		var btn = $('submitComplaint');
		YAHOO.util.Event.purgeElement(btn); 
		YAHOO.util.Event.addListener(btn, "click", this.SubmitComplaint, this); 
	}
	.bind(this));
}

CS.kernel.inappropriate.prototype.SubmitComplaint = function(e, obj)
{
	var reasonArea = document.getElementById('reason');
	var dataObject = { userSessId : config.userSessId, itemId : obj.itemId, itemType : obj.itemType, itemUrl: window.location.href, reason : reasonArea.value };  
	var jsonString = Object.toJSON(dataObject);
	var missingReason = 'Geef a.u.b een reden op.';
	var form = this.parentNode; 
	
	if(trim(reasonArea.value) != "" && trim(reasonArea.value) != missingReason)
	{
		if(config.userId !=null || config.userId != "")
		{
			new Ajax.Request(  
			obj.ajaxRequestHandler, 
			{ 
			  	method: 'get',
			  	parameters: 
			  	{
				  	cmd: 'SubmitInappropriateContent', 
				  	value: jsonString
				}
			});
		} 
		
		// Message has been submitted successfully
		form.innerHTML = 'Je melding is verzonden, bedankt voor je hulp!';
	}
	else
	// No reason has been supplied! Notify the user about it...
	{ reasonArea.value =  missingReason; }
}