﻿
Base.Post = Class.create();
Base.Post.fixAvatar = function(img)
{
   img.className += 'none';
   img.src = '/images/base/space.gif';
}

Base.Post.validateReply = function(editorid, butan)
{
   if(Sd.Common.Browser.ie == false) stardockEditor.updateOutput(editorid);
	if(stardockEditor.getContents(editorid).trim() == '')
	{
		alert("Sorry, but you cannot submit a blank comment!");
		return false;
	}

	if(!butan) return true;
	
   butan.style.display = 'none';
   var statusbutan = $id('_SubmittingStatus');

   if(statusbutan)
   {
      statusbutan.disabled = true;
      statusbutan.value = 'Submitting Reply...';
      statusbutan.style.display = '';
   }

	return true;
}

Base.Post.deleteReply = function()
{
   return confirm('Are you sure you wish to delete this reply?');
}

Base.Post.quotePost = function()
{
   Base.Post.quoteBody('_PostBody');
}

Base.Post.quoteReply = function(replyId)
{
   Base.Post.quoteBody(replyId);
}

Base.Post.quoteBody = function(elemId)
{
   var editorId = stardockEditor.editorId;
   var text;
   var target;
   var config = $id(editorId).config;
   
   text = Sd.UI.getSelection(); //Base.getSelection();
   if(!text || text.trim() == '')
   {
      if(elemId) target = $id(elemId);
      if(target) text = target.innerHTML;
   }
   if(!text) text = '';
   text = text.trim();
   
   //if(config.basic == false) text = Base.replaceBreaks(text);
   text = Base.removeHtml(text);
   if(config.basic == false) text = Base.replaceNewLines(text);     
   text = text.trim();

   text = "[quote]" + text + "[/quote]" + '\r\r';

   if(config.basic == false)
      stardockEditor.insertHtml(editorId, text);
   else
   {
      if(Sd.Common.Browser.ie == true)
         stardockEditor.insertHtml(editorId, text);
      else
         stardockEditor.formatSelection(editorId, text, true);
   }

   return;
}

Base.Post.validate = function(butan)
{
   var message = '';
   
   if(Sd.Validate.requireValue($id('_ListCategory', null, 'select')) == false)
      message += '\nPlease select a Category.';

   if(Sd.Validate.requireValue($id('_TextTitle', null, 'input')) == false)
      message += '\nPlease enter a Title.';

   var reason = $id('_TextReason', null, 'textarea');
   if(reason && Sd.Validate.requireValue(reason) == false)
      message += '\nPlease enter a reason for the Edit.';

   if(Sd.Common.Browser.ie == false) stardockEditor.updateOutput(stardockEditor.editorId);
	if(stardockEditor.getContents(stardockEditor.editorId).trim() == '')
      message += '\nPlease enter a Message before submitting the post.';
      
   if(message.length > 0)
   {
      alert('Post Error!\n' + message);
      return false;
   }      
	
   if(!butan) return true;

   butan.style.display = 'none';
   var statusbutan = $id('_SubmittingStatus');
   
   if(statusbutan)
   {
      statusbutan.disabled = true;
      statusbutan.value = 'Submitting Reply...';
      statusbutan.style.display = '';
   }
	return true;
}
