/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
//this function shows the spinner
function showPlainTinyMCE(text_editor_id,text_editor_width,tiny_mce_default_value)
{
	$().ready(function()
        { 
            $('textarea.'+text_editor_id).tinymce({

            // Location of TinyMCE script
            script_url : 'texteditor/jscripts/tiny_mce/tiny_mce.js',

            // General options
            mode : "textareas",
            theme : "advanced",
            plugins : "autoresize",
            convert_urls : false,
            paste_text_sticky : true, //removes all formating
            theme_advanced_path : false,
            width:text_editor_width,
            
            readonly :false,
            setup : function(ed)
            {        
                ed.onInit.add(function(ed)
               {
                   //setting the height and width of the editor
                   var e = tinymce.DOM.get(ed.id+'_tbl'),ifr = tinymce.DOM.get(ed.id + '_ifr'),
                   w = ed.getWin(),dh;

                   var h = 0; //new height of edit area
                   dh = e.clientHeight - ifr.clientHeight;

                   //get the height of the tool bars
                   //ed.theme.resizeTo(w.clientWidth, h+dh);
                   ed.theme.resizeTo(text_editor_width, h+dh);
                   ///////////////////////////////////////////////////
                    // set the focus
                    var loaded_content = ed.getContent();

                    //if there was no content preloaded with the editor
                    //then we'll show a default text
                    if(""==loaded_content)
                    {
                     ed.setContent(tiny_mce_default_value);
                    // ed.selection.select(ed.dom.select('p')[0]);
                    }
                    
                     ed.focus();
                    
                });

                ed.onKeyUp.add(function(ed)
               {
                    var loaded_content = ed.getContent();
                    // get the current content
                    // cut off <p> and </p> to comply with XHTML strict
                    // these can't be part of the default_value
                    var slen = loaded_content.length;
                    loaded_content = loaded_content.substring(3,slen-4);

                   //alert(tiny_mce_default_value.length);
                   //alert(loaded_content.length);

                    if(tiny_mce_default_value==loaded_content)
                    {
                        ed.setContent("");
                    }

                    ed.focus();

                });

            //todo! need an observer to check when the focus moves away from the


            // Adds an observer to the onClick event using tinyMCE.init
                ed.onClick.add(function(ed, e)
                {
                    var loaded_content = ed.getContent();
                    // get the current content
                    // cut off <p> and </p> to comply with XHTML strict
                    // these can't be part of the default_value
                    var slen = loaded_content.length;
                    loaded_content = loaded_content.substring(3,slen-4);

                   //alert(tiny_mce_default_value.length);
                   //alert(loaded_content.length);
                    
                    if(tiny_mce_default_value==loaded_content)
                    {
                        ed.setContent("");
                    }
                    
                    ed.focus();

                });

               },
                // Theme options
                theme_advanced_buttons1 : "bold,italic,underline,|,bullist,numlist,|,link,preview,sub,sup,|,charmap,iespell,fullscreen",
                theme_advanced_buttons2 : "",
                theme_advanced_buttons3 : "",
                theme_advanced_buttons4 : "",
                theme_advanced_toolbar_location : "",
                theme_advanced_toolbar_align : "",
                theme_advanced_statusbar_location : "",
                theme_advanced_resizing : true,

                // Example content CSS (should be your site CSS)
                content_css : "theme/texteditor.css?tid="+Math.random()
		});
	});
}//showPlainTinyMCE


function showDialogBoxTinyMCE(text_editor_id,text_editor_width,tiny_mce_default_value)
{
	$().ready(function()
        {
		$('textarea.'+text_editor_id).tinymce({
			// Location of TinyMCE script
			script_url : 'texteditor/jscripts/tiny_mce/tiny_mce.js',

                        // General options
                        mode : "textareas",
                        theme : "advanced",
                        plugins : "autoresize,wordcount,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,wordcount,advlist,autosave",
                        convert_urls : false,
                        paste_text_sticky : true, //removes all formating
                        theme_advanced_path : false,
                        width:text_editor_width,
                        theme_advanced_resizing_max_width :450,
                        theme_advanced_resizing_min_width :450,

                        setup : function(ed)
                        {
                ed.onInit.add(function(ed)
               {

                   //setting the height and width of the editor
                   var e = tinymce.DOM.get(ed.id+'_tbl'),ifr = tinymce.DOM.get(ed.id + '_ifr'),
                   w = ed.getWin(),dh;

                   var h = 0; //new height of edit area
                   dh = e.clientHeight - ifr.clientHeight;

                   //get the height of the tool bars
                   //ed.theme.resizeTo(w.clientWidth, h+dh);
                   ed.theme.resizeTo(text_editor_width, h+dh);
                   ///////////////////////////////////////////////////
                   //
                    // set the focus
                    var loaded_content = ed.getContent();

                    //if there was no content preloaded with the editor
                    //then we'll show a default text
                    if(""==loaded_content)
                    {
                     ed.setContent(tiny_mce_default_value);
                    // ed.selection.select(ed.dom.select('p')[0]);
                    }

                     ed.focus();

                });

            //todo! need an observer to check when the focus moves away from the


            // Adds an observer to the onClick event using tinyMCE.init
                ed.onClick.add(function(ed, e)
                {
                    var loaded_content = ed.getContent();
                    // get the current content
                    // cut off <p> and </p> to comply with XHTML strict
                    // these can't be part of the default_value
                    var slen = loaded_content.length;
                    loaded_content = loaded_content.substring(3,slen-4);

                   //alert(tiny_mce_default_value.length);
                   //alert(loaded_content.length);

                    if(tiny_mce_default_value==loaded_content)
                    {
                        ed.setContent("");
                    }

                    ed.focus();

                });

                ed.onKeyUp.add(function(ed)
               {
                    var loaded_content = ed.getContent();
                    // get the current content
                    // cut off <p> and </p> to comply with XHTML strict
                    // these can't be part of the default_value
                    var slen = loaded_content.length;
                    loaded_content = loaded_content.substring(3,slen-4);

                   //alert(tiny_mce_default_value.length);
                   //alert(loaded_content.length);

                    if(tiny_mce_default_value==loaded_content)
                    {
                        ed.setContent("");
                    }

                    ed.focus();

                });

                       },
                        // Theme options
                        theme_advanced_buttons1 : "bold,italic,underline,|,bullist,numlist,|,link,preview,sub,sup,|,charmap,iespell,fullscreen",
                        theme_advanced_buttons2 : "",
                        theme_advanced_buttons3 : "",
                        theme_advanced_buttons4 : "",
                        theme_advanced_toolbar_location : "",
                        theme_advanced_toolbar_align : "",
                        theme_advanced_statusbar_location : "",
                        theme_advanced_resizing : false,


                        // Example content CSS (should be your site CSS)
                        content_css : "theme/texteditor.css?tid="+Math.random()
		});
	});
}//showDialogBoxTinyMCE


function showEmailTinyMCE(text_editor_id,text_editor_width,tiny_mce_default_value)
{
	$().ready(function()
        {
		$('textarea.'+text_editor_id).tinymce({
			// Location of TinyMCE script
			script_url : 'texteditor/jscripts/tiny_mce/tiny_mce.js',

                        // General options
                        mode : "textareas",
                        theme : "advanced",
                        plugins : "autoresize,wordcount,paste",
                        convert_urls : false,
                        paste_text_sticky : true,
                        theme_advanced_path : false,
                        width:text_editor_width,
                        theme_advanced_resizing_max_width :900,

                        setup : function(ed)
                        {

                ed.onInit.add(function(ed)
               {
                   //setting the height and width of the editor
                   var e = tinymce.DOM.get(ed.id+'_tbl'),ifr = tinymce.DOM.get(ed.id + '_ifr'),
                   w = ed.getWin(),dh;

                   var h = 0; //new height of edit area
                   dh = e.clientHeight - ifr.clientHeight;

                   //get the height of the tool bars
                   //ed.theme.resizeTo(w.clientWidth, h+dh);
                   ed.theme.resizeTo(text_editor_width, h+dh);
                   ///////////////////////////////////////////////////

                    // set the focus
                    var loaded_content = ed.getContent();

                    //if there was no content preloaded with the editor
                    //then we'll show a default text
                    if(""==loaded_content)
                    {
                     ed.setContent(tiny_mce_default_value);
                    // ed.selection.select(ed.dom.select('p')[0]);
                    }

                     ed.focus();

                });

            //todo! need an observer to check when the focus moves away from the


            // Adds an observer to the onClick event using tinyMCE.init
                ed.onClick.add(function(ed, e)
                {
                    var loaded_content = ed.getContent();
                    // get the current content
                    // cut off <p> and </p> to comply with XHTML strict
                    // these can't be part of the default_value
                    var slen = loaded_content.length;
                    loaded_content = loaded_content.substring(3,slen-4);

                   //alert(tiny_mce_default_value.length);
                   //alert(loaded_content.length);

                    if(tiny_mce_default_value==loaded_content)
                    {
                        ed.setContent("");
                    }

                    ed.focus();

                });

                ed.onKeyUp.add(function(ed)
               {
                    var loaded_content = ed.getContent();
                    // get the current content
                    // cut off <p> and </p> to comply with XHTML strict
                    // these can't be part of the default_value
                    var slen = loaded_content.length;
                    loaded_content = loaded_content.substring(3,slen-4);

                   //alert(tiny_mce_default_value.length);
                   //alert(loaded_content.length);

                    if(tiny_mce_default_value==loaded_content)
                    {
                        ed.setContent("");
                    }

                    ed.focus();

                });

                       },
                        // Theme options
                        theme_advanced_buttons1 : "",
                        //theme_advanced_buttons1 : "bold,italic,underline,|,bullist,numlist,|,link,preview,sub,sup,|,charmap,iespell,fullscreen",
                        theme_advanced_buttons2 : "",
                        theme_advanced_buttons3 : "",
                        theme_advanced_buttons4 : "",
                        theme_advanced_toolbar_location : "",
                        theme_advanced_toolbar_align : "",
                        theme_advanced_statusbar_location : "",
                        theme_advanced_resizing : true,

                        // Example content CSS (should be your site CSS)
                        content_css : "theme/texteditor.css?tid="+Math.random()
		});
	});
}//showEmailTinyMCE

function showCommentTinyMCE(text_editor_id,text_editor_width,tiny_mce_default_value)
{
	$().ready(function()
        {
		$('textarea.'+text_editor_id).tinymce({
			// Location of TinyMCE script
                        script_url :
                       'texteditor/jscripts/tiny_mce/tiny_mce.js?tid="+Math.random()',

                        // General options
                        mode : "textareas",
                        theme : "advanced",
                        //plugins : "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,wordcount,advlist,autosave",
                        plugins : "autoresize,wordcount,paste",
                        convert_urls : false,
                        paste_text_sticky : true,
                        theme_advanced_path : false,
                        width :text_editor_width,

                        setup : function(ed)
                        {
                ed.onInit.add(function(ed)
               {
                   //setting the height and width of the editor
                   var e = tinymce.DOM.get(ed.id+'_tbl'),ifr = tinymce.DOM.get(ed.id + '_ifr'),
                   w = ed.getWin(),dh;

                   var h = 0; //new height of edit area
                   dh = e.clientHeight - ifr.clientHeight;

                   //get the height of the tool bars
                   //ed.theme.resizeTo(w.clientWidth, h+dh);
                   ed.theme.resizeTo(text_editor_width, h+dh);
                   ///////////////////////////////////////////////////
                   
                    // set the focus
                    var loaded_content = ed.getContent();

                    //if there was no content preloaded with the editor
                    //then we'll show a default text
                    if(""==loaded_content)
                    {
                     ed.setContent(tiny_mce_default_value);
                    // ed.selection.select(ed.dom.select('p')[0]);
                    }

                     ed.focus();

                });

            //todo! need an observer to check when the focus moves away from the


            // Adds an observer to the onClick event using tinyMCE.init
                ed.onClick.add(function(ed, e)
                {

                    var loaded_content = ed.getContent();
                    // get the current content
                    // cut off <p> and </p> to comply with XHTML strict
                    // these can't be part of the default_value
                    var slen = loaded_content.length;
                    loaded_content = loaded_content.substring(3,slen-4);

                   //alert(tiny_mce_default_value.length);
                   //alert(loaded_content.length);

                    if(tiny_mce_default_value==loaded_content)
                    {
                        ed.setContent("");
                    }

                    ed.focus();

                });

                ed.onKeyUp.add(function(ed)
               {
                    var loaded_content = ed.getContent();
                    // get the current content
                    // cut off <p> and </p> to comply with XHTML strict
                    // these can't be part of the default_value
                    var slen = loaded_content.length;
                    loaded_content = loaded_content.substring(3,slen-4);

                   //alert(tiny_mce_default_value.length);
                   //alert(loaded_content.length);

                    if(tiny_mce_default_value==loaded_content)
                    {
                        ed.setContent("");
                    }

                    ed.focus();

                });


                    },
                        // Theme options
                        theme_advanced_buttons1 : "",
                        //theme_advanced_buttons1 : "bold,italic,underline,|,bullist,numlist,|,link,preview,sub,sup,|,charmap,iespell,fullscreen",
                        theme_advanced_buttons2 : "",
                        theme_advanced_buttons3 : "",
                        theme_advanced_buttons4 : "",
                        theme_advanced_toolbar_location : "",
                        theme_advanced_toolbar_align : "",
                        theme_advanced_statusbar_location : "",
                        theme_advanced_resizing : true,

                        // Example content CSS (should be your site CSS)
                        content_css : "theme/texteditor.css?tid="+Math.random()
		});
	});
}//showCommentTinyMCE



function showImageDescripTinyMCE(text_editor_id,text_editor_width,tiny_mce_default_value)
{
	$().ready(function()
        {
            $('textarea.'+text_editor_id).tinymce({
                    
            // Location of TinyMCE script
            script_url : 'texteditor/jscripts/tiny_mce/tiny_mce.js',

            // General options
            mode : "textareas",
            theme : "advanced",
            plugins : "autoresize,wordcount,paste",
            convert_urls : false,
            paste_text_sticky : true,
            theme_advanced_path : false,

            setup : function(ed)
            {
                ed.onInit.add(function(ed)
               {
               //setting the height and width of the editor
               var e = tinymce.DOM.get(ed.id+'_tbl'),ifr = tinymce.DOM.get(ed.id + '_ifr'),
               w = ed.getWin(),dh;

               var h = 0; //new height of edit area
               dh = e.clientHeight - ifr.clientHeight;

               //get the height of the tool bars
               //ed.theme.resizeTo(w.clientWidth, h+dh);
               ed.theme.resizeTo(text_editor_width, h+dh);
               ///////////////////////////////////////////////////
                   //
                // set the focus
                var loaded_content = ed.getContent();

                //if there was no content preloaded with the editor
                //then we'll show a default text
                if(""==loaded_content)
                {
                 ed.setContent(tiny_mce_default_value);
                    // ed.selection.select(ed.dom.select('p')[0]);
                }

                 ed.focus();

                });


            // Adds an observer to the onClick event using tinyMCE.init
                ed.onClick.add(function(ed, e)
                {
                    var loaded_content = ed.getContent();
                    // get the current content
                    // cut off <p> and </p> to comply with XHTML strict
                    // these can't be part of the default_value
                    var slen = loaded_content.length;
                    loaded_content = loaded_content.substring(3,slen-4);

                   //alert(tiny_mce_default_value.length);
                   //alert(loaded_content.length);

                    if(tiny_mce_default_value==loaded_content)
                    {
                        ed.setContent("");
                    }

                    ed.focus();

                });

                ed.onKeyUp.add(function(ed)
               {
                    var loaded_content = ed.getContent();
                    // get the current content
                    // cut off <p> and </p> to comply with XHTML strict
                    // these can't be part of the default_value
                    var slen = loaded_content.length;
                    loaded_content = loaded_content.substring(3,slen-4);

                   //alert(tiny_mce_default_value.length);
                   //alert(loaded_content.length);

                    if(tiny_mce_default_value==loaded_content)
                    {
                        ed.setContent("");
                    }

                    ed.focus();

                });

                },

                        // Theme options
                        theme_advanced_buttons1 : "",
                        theme_advanced_buttons2 : "",
                        theme_advanced_buttons3 : "",
                        theme_advanced_buttons4 : "",
                        theme_advanced_toolbar_location : "",
                        theme_advanced_toolbar_align : "",
                        theme_advanced_statusbar_location : "",
                        theme_advanced_resizing : true,

                        // Example content CSS (should be your site CSS)
                        content_css : "theme/texteditor.css?tid="+Math.random()
		});
	});
}//showImageDescripTinyMCE


function texteditor_showTextEditor(text_editor_content,
                                  object_type,
                                  variable1_name,variable1_value,
                                  variable2_name,variable2_value,
                                  action_filename,actioncmd,
                                  text_editor_type,
                                  text_editor_id,
                                  text_editor_div_id,
                                  text_editor_status)
{ //alert("content :::: "+ text_editor_content);
   // alert("TE ID "+text_editor_id+variable2_name);
     //alert("texteditor_showTextEditor()");
    // alert("Text editor type : "+text_editor_type);
    // document.getElementById(text_editor_status).innerHTML=text_editor_content;
    
                //url
               var action_file_path = "texteditor/index.php";
               var actioncmd_final = "?show_texteditor_request=1"+                             
                               "&&object_type="+object_type+
                               "&&variable1_name="+variable1_name+
                               "&&variable1_value="+variable1_value+
                               "&&variable2_name="+variable2_name+
                               "&&variable2_value="+variable2_value+
                               "&&action_filename="+action_filename+
                               "&&actioncmd="+actioncmd+
                               "&&text_editor_id="+text_editor_id+
                               "&&text_editor_type="+text_editor_type+                            
                               "&&text_editor_status="+text_editor_status;

               var url = action_file_path+actioncmd_final;
               url=url+"&sid="+Math.random();

              // alert("SHow TE: "+url);
               // showSpinner(text_editor_div_id);

         $.post(url, {text_editor_content: text_editor_content},
              
               function(html)
               {
                  // alert(html);
                    $("#"+text_editor_div_id).html(html); //show the html inside .content div
               }
              );

}//showTextEditor()




function onTextEditorSubmit(input)
{     
   //  alert(input);
      var delim = ',';
       var text_editor_default_value =getTokenAt(input,0,delim,10);
       var text_editor_id =getTokenAt(input,1,delim,10);
       var object_type =parseInt(getTokenAt(input,2,delim,10));
       var variable1_name =getTokenAt(input,3,delim,10);
       var variable1_value =parseInt(getTokenAt(input,4,delim,10));
       var variable2_name =getTokenAt(input,5,delim,10);
       var variable2_value =parseInt(getTokenAt(input,6,delim,10));
       var actioncmd =getTokenAt(input,7,delim,10);
       var action_filename =getTokenAt(input,8,delim,10);
       var div_text_editor_update =getTokenAt(input,9,delim,10);

       var txt_editor_content = $('#'+text_editor_id).html();
        
        // get the current content
        // cut off <p> and </p> to comply with XHTML strict
        // these can't be part of the default_value
        var slen = txt_editor_content.length;
        txt_editor_content = txt_editor_content.substring(3,slen-4);

       if((""==txt_editor_content)||(text_editor_default_value==txt_editor_content))
       {
           //there is nothing to save
           $("#"+text_editor_id).html(text_editor_default_value);
           return;
       }

       var url = action_filename+"?"+
        actioncmd+"=1&&"+
        variable1_name+"="+variable1_value+
        "&&"+variable2_name+"="+variable2_value+
        "&&object_type="+object_type;

       // alert(url);
    
        url=url+"&sid="+Math.random();

      $.post(url, {txt_editor_content: txt_editor_content},
      function(result)
      {
        $("#"+div_text_editor_update).html(result);
     });

}//onTextEditorSubmit()


