/**
 * JS for the add content functionality
 */

tinyMCE.init({
mode : "textareas",
editor_selector : "mceEditor",
theme : "advanced",
plugins : "tabfocus",
theme_advanced_buttons1 : "bold,italic,underline,strikethrough,separator,justifyleft,justifycenter,justifyright,justifyfull,separator,bullist,numlist,separator,link,unlink,separator,undo,redo",
theme_advanced_buttons2 : "",
theme_advanced_buttons3 : "",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
//theme_advanced_statusbar_location : "bottom",
tab_focus : ':prev,:next'
});

function askQuestion()
{
	hideAllDialogs();
	
	clearContent();
	
	var formDiv = dojo.byId("formDiv");
	if (formDiv)
	{
		formDiv.style.visibility = "visible";
		formDiv.style.display = "block";
		
		window.location.href = "#formDiv";
	}
}

function askQuestionOnBusinessProfile()
{
	clearContent();
	
	var formDiv = dojo.byId("formDiv");
	if (formDiv)
	{
		formDiv.style.visibility = "visible";
		formDiv.style.display = "block";
		
		//window.location.href = "#formDiv";
	}
}

function saveContent()
{
  var error = false;
	
  var title = dojo.byId("title");
  var titleError = dojo.byId("titleError");
  
  if (title != null)
  {
	  titleError.innerHTML = "&nbsp;";
	  if ( dojo.string.trim(title.value).length == 0 ) 
	  {
	    titleError.innerHTML = "Please provide a title for this post";
	    error = true;
	  }
  
//  var industryError = dojo.byId("industryError");
//  industryError.innerHTML = "&nbsp;";
//  var parent = "";
//  var rootIndustry = dojo.byId("rootIndustry");
//  parent = rootIndustry.value;
//
//  var childIndustries = dojo.byId("childIndustriesContainer");
//  var childOptions = childIndustries.getElementsByTagName("input");
//  
//  var selectedChild = "";
//  for ( j = 0; j < childOptions.length; j++)
//  {
//    var child = childOptions[j];
//    if (child.checked == true)
//      selectedChild = child.value;
//  }
//  child = selectedChild;
//
//  if (parent == null || parent == "")
//  {
//	  industryError.innerHTML = "Please select the associated industry for the post";
//	  error = true;
//  }
  
  //var content = dojo.byId("details");
	  var contentError = dojo.byId("contentError");
	  contentError.innerHTML = "&nbsp;";
	
	  if ( dojo.string.trim(tinyMCE.get("details").getContent()).length == 0 ) 
	  {
	    contentError.innerHTML = "Please provide content for this post";
	    error = true;
	  }
	
	  if (  tinyMCE.get("details").getContent().length > 50000 )
	  {
	    contentError.innerHTML = "Please limit the content for this post to a max of 50k characters";
	    error = true;;
	  }
	
	  if (error)
		  return;
	  
	  document.addContent.submit();
  }
}

function clearContent()
{
	
  var title = dojo.byId("title");
  if (title != null)
  {
	  title.value = "";
	  
	  var titleError = dojo.byId("titleError");
	  titleError.innerHTML = "&nbsp;";
	
//  var rootIndustry = dojo.byId("rootIndustry");
//  rootIndustry.selectedIndex = "";

//  var childIndustries = dojo.byId("childIndustriesContainer");
//  childIndustries.innerHTML = "";

//  var industryError = dojo.byId("industryError");
//  industryError.innerHTML = "&nbsp;";
	    
	  tinyMCE.get("details").setContent("");
	  
	  var contentError = dojo.byId("contentError");
	  contentError.innerHTML = "&nbsp;";
	  
	  var formDiv = dojo.byId("formDiv");
		
	  formDiv.style.visibility = "hidden";
	  formDiv.style.display = "none";
  }
  return;
}
