/**
 *
 * Software Technology Group | STG Utah  | www.stgutah.com
 * http://www.stgutah.com
 *
 */

 function showstatus( msg )
 {
	 window.status= msg;

 };

 /** Function to start Shadowbox */
function startShadowbox() {
  Shadowbox.init();
}

/** Function to init TinyMCE editors
 *
 * @param type {string} Type of editor to create
 */
function TinyMCE_init(type) {
  if (typeof type == "undefined") { type = 'skinned'; }
  var params = {
                mode : "textareas", editor_selector : "wysiwyg_sm_min",
                width: "100%", height : "150",
                theme : "advanced", theme_advanced_toolbar_location : "top", theme_advanced_statusbar_location : "bottom",
                theme_advanced_toolbar_align : "left",
                plugins : "paste",
                theme_advanced_buttons1 : "undo,redo,|,bold,italic,bullist,|,cut,copy,paste,pastetext,pasteword,|,link,unlink,hr,|,formatselect",
                theme_advanced_buttons2 : "",
                theme_advanced_buttons3 : "",
                theme_advanced_resizing : true, theme_advanced_resizing_min_height : 250, theme_advanced_resize_horizontal : false
              };

  // Determine optional params
  var types = type.split(" ");
  if (array_search(types,'tables') !== false) {
    params.plugins = addtolist(params.plugins,"paste,table");
    params.theme_advanced_buttons2 = addtolist(params.theme_advanced_buttons2,"justifyleft,justifycenter,justifyright,|,table,row_props,cell_props,delete_row,row_after,|,charmap",true);
    params.table_styles = "Header 1=header1;Header 2=header2;Header 3=header3";
    params.table_cell_styles = "Header 1=header1;Header 2=header2;Header 3=header3;Table Cell=tableCel1";
    params.table_row_styles = "Header 1=header1;Header 2=header2;Header 3=header3;Table Row=tableRow1";
  }
  if (array_search(types,'absurl') !== false) {
    params.convert_urls = false;
  }
  if (array_search(types,'skinned') !== false) {
    params.theme_advanced_blockformats = "p,h1,h2,h3,h4";
    params.content_css = "/css/tinymce_preview.css";
    params.body_class = "wrapper wraptinyMCE";
    params.editor_css = "/css/tinymce.css";
  }
	if (array_search(types,'save') !== false) {
		params.plugins = addtolist(params.plugins,"save");
		params.theme_advanced_buttons2 = addtolist(params.theme_advanced_buttons2,"save,cancel",true);
	}
	if (array_search(types,'fullscreen') !== false) {
		params.plugins = addtolist(params.plugins,"fullscreen");
		params.theme_advanced_buttons2 = addtolist(params.theme_advanced_buttons2,"fullscreen",true);
	}
  // Initialize small tinyMCE editors with minimal controls/plugins
  tinyMCE.init(params);
}

/** Function to search an array for a value - helps TinyMCE_init
 *
 * @param arr {array} Array to search
 * @param val {string} Value to search for
 */
function array_search (array,val) {
  for (var i = 0; i < array.length; i++) {
    if (array[i] == val) {
      return i;
    }
  }
  return false;
};

/** Function to append a string to a TinyMCE parameter - helps TinyMCE_init
 *
 * @param str {string} TinyMCE parameter to modify
 * @param val {string} value to append to str
 * @param sep {bool} Optional flag to add a separator between str and val
 */
function addtolist(str,val,sep) {
  if (typeof sep == "undefined") { sep = false; }
	return str+(str.length > 0 ? (sep?',|,':',') : '')+val;
}