// JavaScript Document
var dspFrmReply = "<form name='frmJavaAddPost' class='frmStandard frmJavaAddPost' action='' method='post'><input type='hidden' name='forumNo' value='' /><input type='hidden' name='postNo' value='' /><input type='hidden' name='threadNo' value='' /><input type='hidden' name='parentPostNo' value='' /><input type='hidden' name='subject' value=''/><div><label for='body'>post:</label><textarea name='body' id='' class='ckEditor'></textarea></div><div class='noLabel'><input type='submit' name='btnSave' value='Save' /><input type='button' name='btnCancel' value='Cancel' /></div></form>";
var dspFrmReportAPost = "<form name='frmReportAPost' class='frmStandard frmJavaAddPost' action='' method='post'><input type='hidden' name='postNo' value='' /><input type='hidden' name='threadNo' value='' /><input type='hidden' name='forumNo' value='' /><div class='textarea'><label for='reason'>reason:</label><textarea name='reason'></textarea></div><div class='noLabel'><input type='submit' name='btnSave' value='Send Report' /><input type='button' name='btnCancel' value='Cancel' /></div></form>";
var ckEditorOptions = {
		width: 470,
        filebrowserWindowWidth : '415',
        filebrowserWindowHeight : '450',
		removeDialogTabs : 'link:advanced;image:advanced',
		resize_enabled : false,
		toolbar:
		[
			['Bold','Italic','Underline'],
			['NumberedList','BulletedList'],['Blockquote'],
			['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
			['Link','Unlink'],
			['Image'],
			['TextColor','BGColor']
		]
	}
$(document).ready( function() {
	$('.globalForumsUtilityMenu a.btnReply,.globalForumsUtilityMenu a.btnQuote,.globalForumsUtilityMenu a.btnEdit').live('click', function(e) {
		e.preventDefault();
		if ($(this).hasClass('active')) {
			$('form.frmJavaAddPost input[name="btnCancel"]').click();
		} else {
			$('.globalForumsUtilityMenu a.active').removeClass('active');
			$(this).addClass('active');
			$('form.frmJavaAddPost').remove();
			$(this).parents('.globalForumsUtilityMenu').after(dspFrmReply);
			_thisForum = $(this).parents('.globalForumsUtilityMenu').next('form[name="frmJavaAddPost"]');
			_thisForum.attr('action',$(this).attr('href'));
			_thisForum.find('input[name="forumNo"]').val($(this).attr('data-forumno'));
			_thisForum.find('input[name="threadNo"]').val($(this).attr('data-threadno'));	
			_thisForum.find('input[name="parentPostNo"]').val($(this).attr('data-parentpostno'));
			_thisForum.find('input[name="subject"]').val($(this).attr('data-subject'));	
			if ($(this).hasClass('btnQuote')) {
				_quotedPost = $('#' + $(this).attr('data-parentpostno')).clone();
				_quotedPost.find('p.flaggedMessage').remove();
				_quotedPost.find('div.video').remove();				
				_thisForum.find('textarea[name="body"]').val("<div class='quote'><p class='by'>Quote " + _quotedPost.find('.displayName').text() + "</p><blockquote cite='" + _quotedPost.find('.displayName').text() + "'>" + _quotedPost.find('.postBody').html() + "</blockquote></div><p></p>");
			}
			if ($(this).hasClass('btnEdit')) {
				_thisForum.find('input[name="postNo"]').val($(this).attr('data-postno'));
				_editPost = $(this).parents('.postDetails').children('.postBody').clone();
				_editPost.find('p.flaggedMessage').remove();
				_editPost.find('div.video').remove();
				_thisForum.find('textarea[name="body"]').val(_editPost.html());
				if ($(this).attr('data-videourl') != "") {
					_thisForum.prepend('<div><label for="videourl">video url:</label><input type="text" name="videourl" value="' + $(this).attr('data-videourl') + '" style="width: 425px;" /></div>');
				}
				if ($(this).attr('data-easeOfUseRating') != "") {
					_thisForum.prepend('<div><label for="easeOfUseRating">ease of use:</label><select name="easeOfUseRating"><option value="1">1 - Poor</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5 - Excellent</option></select></div>');
					_thisForum.find('select[name="easeOfUseRating"]').val($(this).attr('data-easeOfUseRating'));
				}				
				if ($(this).attr('data-reliabilityRating') != "") {
					_thisForum.prepend('<div><label for="reliabilityRating">reliability:</label><select name="reliabilityRating"><option value="1">1 - Poor</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5 - Excellent</option></select></div>');
					_thisForum.find('select[name="reliabilityRating"]').val($(this).attr('data-reliabilityRating'));					
				}
				if ($(this).attr('data-overAllSatisfactionRating') != "") {
					_thisForum.prepend('<div><label for="overAllSatisfactionRating">overall:</label><select name="overAllSatisfactionRating"><option value="1">1 - Poor</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5 - Excellent</option></select></div>');
					_thisForum.find('select[name="overAllSatisfactionRating"]').val($(this).attr('data-overAllSatisfactionRating'));															
				}								
				if ($(this).attr('data-postno') == $(this).attr('data-threadno')) {
					_thisForum.find('input[name="subject"]').remove();
					_thisForum.prepend('<div><label for="subject">subject:</label><input type="text" name="subject" value="' + $(this).attr('data-subject') + '" style="width: 425px;" /></div>');
					
				}
				
				_thisForum.prepend('<input type="hidden" name="editPost" value="True" />');
			}
			_thisForum.find('textarea').attr('id','ckEditBody_' + Date.now());
			_thisForum.find('textarea').ckeditor(ckEditorOptions);
			
		} // close if hasClass('active')
	}) // close a.click()
	$('.globalForumsUtilityMenu a.btnReport').live('click', function(e) {
		e.preventDefault();
		if ($(this).hasClass('active')) {
			$('form.frmJavaAddPost input[name="btnCancel"]').click();
		} else {		
			$('.globalForumsUtilityMenu a.active').removeClass('active');
			$(this).addClass('active');
			$('form.frmJavaAddPost').remove();
			$(this).parents('.globalForumsUtilityMenu').after(dspFrmReportAPost);
			_thisForum = $(this).parents('.globalForumsUtilityMenu').next('form[name="frmReportAPost"]');		
			_thisForum.attr('action',$(this).attr('href'));
			_thisForum.find('input[name="forumNo"]').val($(this).attr('data-forumno'));
			_thisForum.find('input[name="threadNo"]').val($(this).attr('data-threadno'));	
			_thisForum.find('input[name="postNo"]').val($(this).attr('data-postno'));				
		}
	});
	$('form.frmJavaAddPost input[name="btnCancel"]').live('click', function(e) {
		e.preventDefault();
		$('.globalForumsUtilityMenu a.active').removeClass('active');
		$(this).parents('form.frmJavaAddPost').remove();
	});
	
	$('textarea.ckEditor').ckeditor(ckEditorOptions);	
}); // close document.ready
