{* Smarty *}

{literal}
<script type="text/javascript">
//<![CDATA[
function OrganizAdd(){
  $.ajax({
    async: false,
    timeout: 3000,
    type: 'GET',
    url: "{/literal}{$MS_SP->Sp_PathTop}{$MS_SP->Sp_PathToSite}/AjaxServer/OrganizEdit.ajax.php{literal}",
    success: function(answ){
      DialogStandartOpen('OrganizEditFrm', answ, "{/literal}{$MS_SP->Sp_LangMessage.message.MessRecordAdd}{literal}");
    }
  });
}

function OrganizEdit(){
  var VarCountSelectedRows = $("#GridOrganiz").jqGrid('getGridParam','selarrrow').length;
  if(0 == VarCountSelectedRows){
    DialogStandartMessageOpen('error', "{/literal}{$MS_SP->Sp_LangMessage.warning.WarnShouldSelectRecord}{literal}");
  }
  else if(1 == VarCountSelectedRows){
    var VarId = $("#GridOrganiz").jqGrid('getGridParam','selrow');
    $.ajax({
      async: false,
      timeout: 3000,
      type: 'GET',
      url: "{/literal}{$MS_SP->Sp_PathTop}{$MS_SP->Sp_PathToSite}/AjaxServer/OrganizEdit.ajax.php{literal}",
      data: {
        "organiz_id": VarId
      },
      success: function(answ){
        DialogStandartOpen('OrganizEditFrm', answ, "{/literal}{$MS_SP->Sp_LangMessage.message.MessRecordEdit}{literal}");
      }
    });
  }
  else{
    DialogStandartMessageOpen('error', "{/literal}{$MS_SP->Sp_LangMessage.warning.WarnShouldSelectOnlyOneRecord}{literal}");
  }
}

function OrganizDel(){
  var VarId = $("#GridOrganiz").jqGrid('getGridParam','selarrrow');
  var VarCountSelectedRows = VarId.length;
  if(0 == VarCountSelectedRows){
    DialogStandartMessageOpen('error', "{/literal}{$MS_SP->Sp_LangMessage.warning.WarnShouldSelectRecord}{literal}");
  }
  else if(1 <= VarCountSelectedRows){
    $(function() {
      CreateDivForMessage("DialogConfirmMessage");
      $("#DialogConfirmMessageText").html("{/literal}{$MS_SP->Sp_LangMessage.message.MessAreYouSureDelete}{literal}");
      $("#DialogConfirmMessage").dialog({
        title: "{/literal}{$MS_SP->Sp_LangMessage.label.GridDelete}{literal}",
        resizable: false,
        height:180,
        modal: true,
        buttons: {
          "{/literal}{$MS_SP->Sp_LangMessage.label.GridDeleteYes}{literal}": function() {
            $.ajax({
              async: false,
              timeout: 3000,
              type: "GET",
              url: "{/literal}{$MS_SP->Sp_PathTop}{$MS_SP->Sp_PathToSite}/AjaxServer/OrganizDel.ajax.php{literal}",
              data: {
                organiz_id: VarId
              },
              success: function(answ){
                if("undefined" == typeof(answ["error"])){
                  $("#GridOrganiz").trigger("reloadGrid");
                  DialogStandartMessageOpen('message', answ["message"]);
                }
                else{
                  DialogStandartMessageOpen('error', answ["error"]);
                }
              }
            });
            $(this).dialog("close");
          },
          "{/literal}{$MS_SP->Sp_LangMessage.label.GridDeleteNo}{literal}": function() {
            $(this).dialog("close");
          }
        }
      });
    });
  }
  else{
    DialogStandartMessageOpen('error', "{/literal}{$MS_SP->Sp_LangMessage.error.ErrUnknownError}{literal}");
  }
}

$(function BuildGrid(){
  $("#GridOrganiz").jqGrid('jqGridImport',{imptype:"jsonstring", impstring:window.localStorage.getItem("{/literal}{$smarty.session.SessionAuth.id}-GridOrganiz{literal}")});
  $("#GridOrganiz").jqGrid({
    caption:{/literal}'{$MS_SP->Sp_LangMessage.GridsCaptions.Organizations}'{literal},
    datatype: "json",
    url:"{/literal}{$MS_SP->Sp_PathTop}{$MS_SP->Sp_PathToSite}/AjaxServer/OrganizList.ajax.php{literal}",
    colNames:[{/literal}
      '{$MS_SP->Sp_LangMessage.GridsColNames.name}',
      '{$MS_SP->Sp_LangMessage.GridsColNames.address}',
      '{$MS_SP->Sp_LangMessage.GridsColNames.tel}',
      '{$MS_SP->Sp_LangMessage.GridsColNames.fax}',
      '{$MS_SP->Sp_LangMessage.GridsColNames.person_contact}',
      '{$MS_SP->Sp_LangMessage.GridsColNames.person_contact_tel}',
      '{$MS_SP->Sp_LangMessage.GridsColNames.note}'{literal}
    ],
    colModel:[
      {name:'organiz_name', index:'organiz_name', width:110},
      {name:'organiz_address', index:'organiz_address', width:200},
      {name:'organiz_tel', index:'organiz_tel', width:80},
      {name:'organiz_fax', index:'organiz_fax', width:80},
      {name:'organiz_person', index:'organiz_person', width:100},
      {name:'organiz_persontel', index:'organiz_persontel', width:100},
      {name:'organiz_note', index:'organiz_note', width:200, hidden:true}
    ],
    multiselect: true,
    multiboxonly:true,
    rowNum:100,
    rowList:[10,25,100,500],
    pager: '#GridOrganizPager',
    sortname: 'organiz_name',
    sortorder: "asc",
    viewrecords: true,
    rownumbers: true,
    toolbar: [true,"top"],
    shrinkToFit:false, 
    gridview: true,
    autowidth: true,
    height: 290
  });
  $("#GridOrganiz").toolbarButtonAdd("#t_GridOrganiz",{caption:"{/literal}{$MS_SP->Sp_LangMessage.GridsButtons.Print}{literal}",position:"first",title:"{/literal}{$MS_SP->Sp_LangMessage.GridsButtons.Print}{literal}", buttonicon :'ui-icon-print', cursor: "pointer", onClickButton:function(){GridPrintReport('GridOrganiz');}});
  $("#GridOrganiz").toolbarButtonAdd("#t_GridOrganiz",{caption:"{/literal}{$MS_SP->Sp_LangMessage.GridsButtons.Add}{literal}",position:"last",title:"{/literal}{$MS_SP->Sp_LangMessage.GridsButtons.Add}{literal}", buttonicon :'ui-icon-plus', cursor: "pointer", onClickButton:OrganizAdd });
  $("#GridOrganiz").toolbarButtonAdd("#t_GridOrganiz",{caption:"{/literal}{$MS_SP->Sp_LangMessage.GridsButtons.Edit}{literal}",position:"last",title:"{/literal}{$MS_SP->Sp_LangMessage.GridsButtons.Edit}{literal}", buttonicon :'ui-icon-pencil', cursor: "pointer", onClickButton:OrganizEdit });
{/literal}
  {if isset($smarty.session.SessionAuth.SvtAdmin.reg) && 1 eq $smarty.session.SessionAuth.SvtAdmin.reg}
{literal}  
  $("#GridOrganiz").toolbarButtonAdd("#t_GridOrganiz",{caption:"{/literal}{$MS_SP->Sp_LangMessage.GridsButtons.Del}{literal}",position:"last",title:"{/literal}{$MS_SP->Sp_LangMessage.GridsButtons.Del}{literal}", buttonicon :'ui-icon-trash', cursor: "pointer", onClickButton:OrganizDel });
{/literal}
  {/if}
{literal}
  {/literal}
  {if isset($VarOrganizSelect) && 1 eq $VarOrganizSelect}
  {literal}
    $("#GridOrganiz").toolbarButtonAdd("#t_GridOrganiz",{caption:"{/literal}{$MS_SP->Sp_LangMessage.GridsButtons.Select}{literal}",position:"last",title:"{/literal}{$MS_SP->Sp_LangMessage.GridsButtons.Select}{literal}", buttonicon :'ui-icon-check', cursor: "pointer", onClickButton:OrganizSelect });
  {/literal}
  {/if}
  {literal}
$("#GridOrganiz").jqGrid("navButtonAdd","#GridOrganizPager",{
    caption: "",
    title: "{/literal}{$MS_SP->Sp_LangMessage.GridsButtons.Refresh}{literal}",
    buttonicon :'ui-icon-refresh',
    onClickButton : function (){
      $("#GridOrganiz").trigger("reloadGrid");
    }
  });
  $("#GridOrganiz").jqGrid("navButtonAdd","#GridOrganizPager",{
    caption: "",
    title: "{/literal}{$MS_SP->Sp_LangMessage.GridsButtons.ColumnChooser}{literal}",
    buttonicon :'ui-icon-transfer-e-w',
    onClickButton : function (){
      $("#GridOrganiz").jqGrid('columnChooser');
    }
  });
  $("#GridOrganiz").navButtonAdd("#GridOrganizPager",{ 
    caption: "", 
    title: "{/literal}{$MS_SP->Sp_LangMessage.GridsButtons.SaveSettings}{literal}", 
    buttonicon :'ui-icon-disk',
    onClickButton: function () {
      if (typeof window.localStorage !== 'undefined') {
        delete $("#GridOrganiz").jqGrid('getGridParam' ,'postData' )['filters'];
        window.localStorage.setItem("{/literal}{$smarty.session.SessionAuth.id}-GridOrganiz{literal}",$("#GridOrganiz").jqGrid('jqGridExport',{exptype:'jsonstring'}));
        DialogStandartMessageOpen('message', "{/literal}{$MS_SP->Sp_LangMessage.message.MessSettingsSaved}{literal}");
      }
      else{          
        DialogStandartMessageOpen('error', "{/literal}{$MS_SP->Sp_LangMessage.error.ErrNoLocalStorage}{literal}");
      }
    }
  });
  $("#GridOrganiz").navButtonAdd("#GridOrganizPager",{ 
    caption: "", 
    title: "{/literal}{$MS_SP->Sp_LangMessage.GridsButtons.ResetSettings}{literal}", 
    buttonicon :'ui-icon-closethick',
    onClickButton: function () {
      CreateDivForMessage("DialogConfirmMessage");
      $("#DialogConfirmMessageText").html('{/literal}{$MS_SP->Sp_LangMessage.message.MessResetSettConfirm}{literal}');
      $("#DialogConfirmMessage").dialog({
        title: "{/literal}{$MS_SP->Sp_LangMessage.DialogTitles.ResetSettings}{literal}",
        resizable: false,
        height:180,
        modal: true,
        buttons: {
          "{/literal}{$MS_SP->Sp_LangMessage.label.GridDeleteYes}{literal}": function() {
            window.localStorage.removeItem("{/literal}{$smarty.session.SessionAuth.id}-GridOrganiz{literal}");
            $(this).dialog('close');
            $("#GridOrganiz").jqGrid('GridUnload');
            BuildGrid();
            DialogStandartMessageOpen('message', "{/literal}{$MS_SP->Sp_LangMessage.message.MessResetSettSuccess}{literal}");
          },
          "{/literal}{$MS_SP->Sp_LangMessage.label.GridDeleteNo}{literal}": function() {
            $(this).dialog('close');
          }
        }
      });
    }
  });
  $("#GridOrganiz").jqGrid('filterToolbar',{stringResult: true, searchOnEnter : true, defaultSearch:"cnof"});
  UpdateJqGrid("GridOrganiz","GridOrganizWrapper");
});
//]]>
</script>
{/literal}

<div id="GridOrganizWrapper" class="ui-widget-content ui-corner-all">
  <table id="GridOrganiz"><tr><td></td></tr></table>
  <div id="GridOrganizPager"></div>
  <div id="t_toolbar1"></div>
</div>