/*****
 * BSkyB Daily Specific Comments Report Abuse
 * Requires: Pluck SiteLife, Sky Daily comments
 * Dependencies: pluckBlogComments.js, skydailyBlogComments.js
 * About: sky daily specific stylistic and structural blog post comments report abuse HTML
 *****/

var skydailyReportAbuse = {};

//called from comments JS to populate the reported/report abuse links
skydailyReportAbuse.addReportAbuseLink = function(type, key, reported) {
	var reportHtml = "";
	if (reported == "False"){
	  	reportHtml += "<div class='articleTools'><div class='articleToolsLeftLinks'>";
			reportHtml += "<div id='reportAb'><a href='#none' onclick='skydailyReportAbuse.getReportAbuseForm(arguments[0], \"" + key + "\")'>Report this "+ type +"</a></div>";
			reportHtml += "</div></div>";
		 } else {
			reportHtml = "<span id='report-"+ key +"' class='reported'>Reported</span>";
		}		
	return reportHtml;
};

skydailyReportAbuse.submitReportAbuse = function() {
	var reason = document.getElementById("reportAbuseReason").value;
	var details = document.getElementById("reportAbuseDetails").value;
	var reportKey = "report-"+ itemKey;
	
	if (details === '') { details = ' ';} 
 	
 	var reportAbuse = new ReportAbuseAction(skydailyReportAbuse.getReportKeyType(itemKey), reason, details);
	var requestBatch = new RequestBatch();
 	requestBatch.AddToRequest(reportAbuse);
	requestBatch.BeginRequest(serverUrl, skydailyReportAbuse.reportAbuseCallback);
};

skydailyReportAbuse.getReportAbuseForm = function(e, key) {
	itemKey = key;
	Lightbox.init();
	Lightbox.showBoxByID('reportAbuseForm', 350, 340);
	document.getElementById('reportAbuseForm').style.display = '';
	document.getElementById('reportAbuseReason').focus();
	//cancel lightbox
	var reportAbuseCancel = document.getElementById('reportAbuseCancel');
	pluckUtils.addMyEvent("click", reportAbuseCancel, skydailyReportAbuse.reportAbuseHide);
	//report abuse
	var reportAbuse = document.getElementById('reportAbuse');
	pluckUtils.addMyEvent("click",reportAbuse, skydailyReportAbuse.submitReportAbuse);
	pluckUtils.overrideLinkEvent(e);
};

skydailyReportAbuse.getReportKeyType = function(key) {
	var keyType = key.split(':')[0];
	key = key.split(':')[1];
	var reportKey = null;
	if (keyType == 'CommentKey') {
 		reportKey = new CommentKey(key);
 	} else if (keyType == 'ArticleKey'){ 
		reportKey = new ArticleKey(key);
 	} else if (keyType == 'BlogPostKey'){ 
		reportKey = new BlogPostKey(key);
 	} else if (keyType == 'ReviewKey'){ 
		reportKey = new ReviewKey(key);
 	} else {
		alert('Invalid Key');
 	}
 	return reportKey;	
};

skydailyReportAbuse.reportAbuseCallback = function(responseBatch) {
	if (responseBatch.Messages[0].Message == 'ok') {
		pluckBlogComments.getBlogPostComments(false, 1, true);
		skydailyReportAbuse.reportAbuseHide();
	}
};

skydailyReportAbuse.reportAbuseHide = function() {
	document.getElementById('reportAbuseForm').reset();
	Lightbox.hideBox();
};