/* 
 * This file contains functions used by the Image Editor 
 */


//this function helps to show
function module_showEditModuleForm(input)
{  //alert(input);
    var delim =',';
    var module_id=parseInt(getTokenAt(input,0,delim,3));
    var btn_edit_module_id=getTokenAt(input,1,delim,3);
    var div_edit_module_box_id=getTokenAt(input,2,delim,3);

   var action_file_path = "module/index.php";
   var actioncmd = "?edit_module_request=1"+
                     "&&module_id="+module_id+
                     "&&div_edit_new_module_box="+div_edit_module_box_id;

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

       $(function()
       {
		// a workaround for a flaw in the demo system (http://dev.jqueryui.com/ticket/4375), ignore!
		$( "#dialog:ui-dialog" ).dialog( "destroy" );

		$( "#"+div_edit_module_box_id).dialog({
			autoOpen: false,
			height: 550,
			width: 550,
			modal: true,
                        draggable: false,
                        resizable:false
		});

		$( "#"+btn_edit_module_id )
                .click(function(e)
                {  // alert(module_id);
                        e.preventDefault();
                        $( "#"+div_edit_module_box_id).dialog( "open" );

                      $.ajax({
                                method: "get",url:url,data: "page",
                                beforeSend: function()
                                {
                                  showSpinner(div_edit_module_box_id);
                                },
                                complete: function()
                                {},
                                success: function(html)
                                {
                                  $("#"+div_edit_module_box_id).html(html);
                                }
                     }); //close $.ajax()
                });
	});
}//module_showEditModuleForm()


 //this function coordinate the saving of an module info which has just been
   //edited
      function module_editModuleDetails(input)
      { //alert(input);
        var delim =',';
        var missing_fields = 0;

        var module_id = parseInt(getTokenAt(input,0,delim,3));
        var txt_editor_module_descrip_id=getTokenAt(input,1,delim,3);
        var div_edit_module_box_update=getTokenAt(input,2,delim,3);

        var module_descrip = tinyMCE.get(txt_editor_module_descrip_id).getContent();
        if(!module_descrip)
         {       
            missing_fields = 1;
         }

        if(missing_fields!=0)
            {
                alert("Please provide all the details ");
                return;
            }

        var action_file_path = "module/index.php";
        var actioncmd;

         actioncmd = "?edit_module_submit=1"+
         "&&module_id="+module_id;

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

           // alert(url);

           $.post(url, {module_descrip: module_descrip},
           function(link)
           {
             alert(link);
              $("#"+div_edit_module_box_update).html(link);
           }
          );

      }//module_editModuleDetails()


//site_manager_tabbed_pane is the tabbed pane instance created
function module_showModules()
 {
       var home_tabpanel = tabController.findTab("Modules");

      //put a div in the panel to contain the content
       home_tabpanel.innerHTML = "<div id='div_show_modules_id'></div>";

        var action_file_path = "module/index.php";
        var actioncmd = "?show_modules_request=1";

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

        $.ajax({
            method: "get",url:url,data: "page",
            beforeSend: function()
            {
               showSpinner('div_show_modules_id');
            },
            complete: function()
            {
            },
            success: function(html)
            {
                $("#div_show_modules_id").html(html);
            }
     });
 }//module_showModules()



 
function  module_setCompanyModuleUsageValue(input)
{ 
    var delim =',';
    var module_usage_value;

    var company_id=parseInt(getTokenAt(input,0,delim,4));
    var module_name=getTokenAt(input,1,delim,4);
    var module_usage_status_checkbox_id=getTokenAt(input,2,delim,4);
    var div_update_company_module_usage=getTokenAt(input,3,delim,4);

  var tour_chk = document.getElementById(module_usage_status_checkbox_id);
  if(tour_chk.checked)
      {
           //alert("Check");
           module_usage_value = 'Y';
      }
   else
       {
           //alert("Uncheck");
           module_usage_value = 'N';
       }       

      //alert(module_usage_value);

    var action_file_path = "module/index.php";
    var actioncmd = "?update_company_module_usage_value_request=1"+
                    "&&module_name="+module_name+
                    "&&company_id="+company_id+
                    "&&module_usage_value="+module_usage_value;

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

      // alert(url);

        $.ajax(
        {
            method: "get",url:url,data: "page",
            beforeSend: function()
            {
             showSpinner(div_update_company_module_usage);
            },
            complete: function()
            {
            },
            success: function(html)
            {
            $("#"+div_update_company_module_usage).html(html);
            }
     });
 }//module_setCompanyModuleUsageValue()


//When this function is called it sends the command for the system to
//autocreate all modules
function module_autoCreateAllModules()
 {
        var action_file_path = "config/index.php";
        var actioncmd = "?create_module_company_request=1";

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

       $(function()
       {
		$( "#btn_auto_create_all_modules")
                .click(function(e)
                {  // alert(module_id);
                      e.preventDefault();
                      $.ajax({
                                method: "get",url:url,data: "page",
                                beforeSend: function()
                                {
                                  showSpinner('div_show_modules_id');
                                },
                                complete: function()
                                {},
                                success: function(html)
                                {
                                  $("#div_show_modules_id").html(html);
                                }
                     }); //close $.ajax()
                });
	});

 }//module_autoCreateAllModules()



