var MyHistoryLength = 0;
var MyDataNew="editpage.aspx";
var MyDataEdit="editpage.aspx";
var MyDataCopy="editpage.aspx";
var MyDataDrop="editpage.aspx";
var MyDataView="detail.aspx";
var MyDataMode="28";
var MyTable="";
var MyCatalog="";
var MyRecord="";
var MyReferTable="";
var MyReferRecord="";
var MyFunction=null;
var alertRecord=function(){window.alert("Данная операция в настоящий момент не доступна \nили у Вас нет соответствующих прав доступа!");return;};
var newRecord=function(){alertRecord();};
var editRecord=function(){alertRecord();};
var saveRecord=function(){alertRecord();};
var copyRecord=function(){alertRecord();};
var moveRecord=function(){alertRecord();};
var dropRecord=function(){alertRecord();};
var showRecords=function(){alertRecord();};
var recorddialog=null;
if(typeof(dialog)!='undefined'){var dialog=null;}

function __Alert(){
  MyFunction=1;
}

function __ShowRecord(){
  var v="";
  if(arguments.length>0){ v=arguments[0]; }
  if(dialog==null){
    if(v.length>0){
      if(v.indexOf(MyDataView) < 0){
        if(v.indexOf("?") < 0){
          v=MyDataView+"?"+v;
        }else{
          v=MyDataView+v;
        }
      }
      if(typeof(DWin)!='undefined'){
        if(DWin!=null){
          if(recorddialog==null){
            if(typeof(dialog)!='undefined'){recorddialog=dialog;}
            dialog=DWin.open('Dialog', 'iframe', v, 'Просмотр информации', 'width=700px,height=520px,resize=1,scrolling=1,center=1,minButton=0,closeButton=1');
            dialog.onclose=function(){if(typeof(dialog)!='undefined'){dialog=recorddialog;}recorddialog=null;return true;};
          }
        }
      }
    }
  }
}

function __NewRecord(){
  var v=""; var ok=false;
  var arg1=""; var arg2=""; var arg3=""; var arg4=""; var arg5="";
  if(arguments.length>0){ arg1=arguments[0]; }
  if(arguments.length>1){ arg2=arguments[1]; }
  if(arguments.length>2){ arg3=arguments[2]; }
  if(arguments.length>3){ arg4=arguments[3]; }
  if(arguments.length>4){ arg5=arguments[4]; }
  if(dialog==null){
    if(arg1.length > 0){
      v="d="+arg1; ok=true;
    }
    if(arg2.length > 0){
      if(v.length > 0){ v=v+"&"; }
      v=v+"dc="+arg2;
    }
    if(arg3.length > 0){
      if(v.length > 0){ v=v+"&"; }
      v=v+"dr="+arg3;
    }
    if(arg4.length > 0){
      if(v.length > 0){ v=v+"&"; }
      v=v+"rfd="+arg4;
    }
    if(arg5.length > 0){
      if(v.length > 0){ v=v+"&"; }
      v=v+"rfdr="+arg5;
    }
    if(v.length<=0){
      if(MyTable.length > 0){
        if(__GetElement(MyTable)!=null){
          if(__GetElement(MyTable).value.length > 0){
            v="d="+__GetElement(MyTable).value; ok=true;
          }
        }
      }
      if(MyCatalog.length > 0){
        if(__GetElement(MyCatalog)!=null){
          if(__GetElement(MyCatalog).value.length > 0){
            if(v.length > 0){ v=v+"&"; }
            v=v+"dc="+__GetElement(MyCatalog).value;
          }
        }
      }
      if(MyRecord.length > 0){
        if(__GetElement(MyRecord)!=null){
          if(__GetElement(MyRecord).value.length > 0){
            if(v.length > 0){ v=v+"&"; }
            v=v+"dr="+__GetElement(MyRecord).value;
          }
        }
      }
      if(MyReferTable.length > 0){
        if(__GetElement(MyReferTable)!=null){
          if(__GetElement(MyReferTable).value.length > 0){
            if(v.length > 0){ v=v+"&"; }
            v=v+"rfd="+__GetElement(MyReferTable).value;
          }
        }
      }
      if(MyReferRecord.length > 0){
        if(__GetElement(MyReferRecord)!=null){
          if(__GetElement(MyReferRecord).value.length > 0){
            if(v.length > 0){ v=v+"&"; }
            v=v+"rfdr="+__GetElement(MyReferRecord).value;
          }
        }
      }
    }
    if((v.length>0)&&(ok)){
      v=MyDataNew+"?"+v+"&a=1&mode="+MyDataMode;
      if(typeof(DWin)!='undefined'){
        if(DWin!=null){
          if(recorddialog==null){
            if(typeof(dialog)!='undefined'){recorddialog=dialog;}
            if(MyDataNew.indexOf("protocol_s.aspx",0)>=0){
              MyFunction=null;
              dialog=DWin.open('Dialog', 'iframe', v, 'Добавление записи в базу данных/каталог', 'width=640px,height=520px,resize=1,scrolling=1,center=1,minButton=0,closeButton=1', null, 
                [ { title:"Создать", click:__Alert },
                { title:"Отмена", click:function(evt){dialog.close();} } ]);
            }else{
              dialog=DWin.open('Dialog', 'iframe', v, 'Добавление записи в базу данных/каталог', 'width=640px,height=520px,resize=1,scrolling=1,center=1,minButton=0,closeButton=1');
            }
            dialog.onclose=function(){if(typeof(dialog)!='undefined'){dialog=recorddialog;}MyFunction=null;recorddialog=null;return true;};
          }
        }
      }
    }else{ alert("Добавдение записи не доступно!"); }
  }else{ alert("Перед добавлением закройте диалоговое окно!"); }
}

function __EditRecord(){
  var v=""; var ok=false;
  var arg1=""; var arg2=""; var arg3=""; var arg4=""; var arg5="";
  if(arguments.length>0){ arg1=arguments[0]; }
  if(arguments.length>1){ arg2=arguments[1]; }
  if(arguments.length>2){ arg3=arguments[2]; }
  if(arguments.length>3){ arg4=arguments[3]; }
  if(arguments.length>4){ arg5=arguments[4]; }
  if(dialog==null){
    if(arg1.length > 0){
      v="d="+arg1; ok=true;
    }
    if(arg2.length > 0){
      if(v.length > 0){ v=v+"&"; }
      v=v+"dc="+arg2;
    }
    if(arg3.length > 0){
      if(v.length > 0){ v=v+"&"; }
      v=v+"dr="+arg3;
    }else{ ok=false; }
    if(arg4.length > 0){
      if(v.length > 0){ v=v+"&"; }
      v=v+"rfd="+arg4;
    }
    if(arg5.length > 0){
      if(v.length > 0){ v=v+"&"; }
      v=v+"rfdr="+arg5;
    }
    if(v.length<=0){
     if(MyTable.length > 0){
        if(__GetElement(MyTable)!=null){
          if(__GetElement(MyTable).value.length > 0){
            v="d="+__GetElement(MyTable).value; ok=true;
          }
        }
      }
      if(MyCatalog.length > 0){
        if(__GetElement(MyCatalog)!=null){
          if(__GetElement(MyCatalog).value.length > 0){
            if(v.length > 0){ v=v+"&"; }
            v=v+"dc="+__GetElement(MyCatalog).value;
          }
        }
      }
      if(MyRecord.length > 0){
        if(__GetElement(MyRecord)!=null){
          if(__GetElement(MyRecord).value.length > 0){
            if(v.length > 0){ v=v+"&"; }
            v=v+"dr="+__GetElement(MyRecord).value;
          }else{ ok=false; }
        }else{ ok=false; }
      }else{ ok=false; }
      if(MyReferTable.length > 0){
        if(__GetElement(MyReferTable)!=null){
          if(__GetElement(MyReferTable).value.length > 0){
            if(v.length > 0){ v=v+"&"; }
            v=v+"rfd="+__GetElement(MyReferTable).value;
          }
        }
      }
      if(MyReferRecord.length > 0){
        if(__GetElement(MyReferRecord)!=null){
          if(__GetElement(MyReferRecord).value.length > 0){
            if(v.length > 0){ v=v+"&"; }
            v=v+"rfdr="+__GetElement(MyReferRecord).value;
          }
        }
      }
    }
    if((v.length>0)&&(ok)){
      v=MyDataEdit+"?"+v+"&a=2&mode="+MyDataMode;
      if(typeof(DWin)!='undefined'){
        if(DWin!=null){
          if(recorddialog==null){
            if(typeof(dialog)!='undefined'){recorddialog=dialog;}
            if(MyDataEdit.indexOf("protocol_s.aspx",0)>=0){
              MyFunction=null;
              dialog=DWin.open('Dialog', 'iframe', v, 'Редактирование записи в базе данных/каталоге', 'width=640px,height=520px,resize=1,scrolling=1,center=1,minButton=0,closeButton=1', null, 
                [ { title:"Сохранить", click:__Alert },
                { title:"Отмена", click:function(evt){dialog.close();} } ]);
            }else{
              dialog=DWin.open('Dialog', 'iframe', v, 'Редактирование записи в базе данных/каталоге', 'width=640px,height=520px,resize=1,scrolling=1,center=1,minButton=0,closeButton=1');
            }
            dialog.onclose=function(){if(typeof(dialog)!='undefined'){dialog=recorddialog;}MyFunction=null;recorddialog=null;return true;};
          }
        }
      }
    }else{ alert("Выбирите запись для редактирования!"); }
  }else{ alert("Перед редактированием закройте диалоговое окно!"); }
}

function __CopyRecord(){
  var v=""; var ok=false;
  var arg1=""; var arg2=""; var arg3=""; var arg4=""; var arg5="";
  if(arguments.length>0){ arg1=arguments[0]; }
  if(arguments.length>1){ arg2=arguments[1]; }
  if(arguments.length>2){ arg3=arguments[2]; }
  if(arguments.length>3){ arg4=arguments[3]; }
  if(arguments.length>4){ arg5=arguments[4]; }
  if(dialog==null){
    if(arg1.length > 0){
      v="d="+arg1; ok=true;
    }
    if(arg2.length > 0){
      if(v.length > 0){ v=v+"&"; }
      v=v+"dc="+arg2;
    }
    if(arg3.length > 0){
      if(v.length > 0){ v=v+"&"; }
      v=v+"dr="+arg3;
    }else{ ok=false; }
    if(arg4.length > 0){
      if(v.length > 0){ v=v+"&"; }
      v=v+"rfd="+arg4;
    }
    if(arg5.length > 0){
      if(v.length > 0){ v=v+"&"; }
      v=v+"rfdr="+arg5;
    }
    if(v.length<=0){
      if(MyTable.length > 0){
        if(__GetElement(MyTable)!=null){
          if(__GetElement(MyTable).value.length > 0){
            v="d="+__GetElement(MyTable).value; ok=true;
          }
        }
      }
      if(MyCatalog.length > 0){
        if(__GetElement(MyCatalog)!=null){
          if(__GetElement(MyCatalog).value.length > 0){
            if(v.length > 0){ v=v+"&"; }
            v=v+"dc="+__GetElement(MyCatalog).value;
          }
        }
      }
      if(MyRecord.length > 0){
        if(__GetElement(MyRecord)!=null){
          if(__GetElement(MyRecord).value.length > 0){
            if(v.length > 0){ v=v+"&"; }
            v=v+"dr="+__GetElement(MyRecord).value;
          }else{ ok=false; }
        }else{ ok=false; }
      }else{ ok=false; }
      if(MyReferTable.length > 0){
        if(__GetElement(MyReferTable)!=null){
          if(__GetElement(MyReferTable).value.length > 0){
            if(v.length > 0){ v=v+"&"; }
            v=v+"rfd="+__GetElement(MyReferTable).value;
          }
        }
      }
      if(MyReferRecord.length > 0){
        if(__GetElement(MyReferRecord)!=null){
          if(__GetElement(MyReferRecord).value.length > 0){
            if(v.length > 0){ v=v+"&"; }
            v=v+"rfdr="+__GetElement(MyReferRecord).value;
          }
        }
      }
    }
    if((v.length>0)&&(ok)){
      v=MyDataCopy+"?"+v+"&a=2&mode="+MyDataMode;
      if(typeof(DWin)!='undefined'){
        if(DWin!=null){
          if(recorddialog==null){
            if(typeof(dialog)!='undefined'){recorddialog=dialog;}
            dialog=DWin.open('Dialog', 'iframe', v, 'Дополнительное действие над данными', 'width=640px,height=520px,resize=1,scrolling=1,center=1,minButton=0,closeButton=1');
            dialog.onclose=function(){if(typeof(dialog)!='undefined'){dialog=recorddialog;}recorddialog=null;return true;};
          }
        }
      }
    }else{ alert("Выбирите запись для редактирования!"); }
  }else{ alert("Перед действием закройте диалоговое окно!"); }
}

function __DropRecord(){
  var v=""; var ok=false;
  var arg1=""; var arg2=""; var arg3=""; var arg4=""; var arg5="";
  if(arguments.length>0){ arg1=arguments[0]; }
  if(arguments.length>1){ arg2=arguments[1]; }
  if(arguments.length>2){ arg3=arguments[2]; }
  if(arguments.length>3){ arg4=arguments[3]; }
  if(arguments.length>4){ arg5=arguments[4]; }
  if(dialog==null){
    if(arg1.length > 0){
      v="d="+arg1; ok=true;
    }
    if(arg2.length > 0){
      if(v.length > 0){ v=v+"&"; }
      v=v+"dc="+arg2;
    }
    if(arg3.length > 0){
      if(v.length > 0){ v=v+"&"; }
      v=v+"dr="+arg3;
    }else{ ok=false; }
    if(arg4.length > 0){
      if(v.length > 0){ v=v+"&"; }
      v=v+"rfd="+arg4;
    }
    if(arg5.length > 0){
      if(v.length > 0){ v=v+"&"; }
      v=v+"rfdr="+arg5;
    }
    if(v.length<=0){
      if(MyTable.length > 0){
        if(__GetElement(MyTable)!=null){
          if(__GetElement(MyTable).value.length > 0){
            v="d="+__GetElement(MyTable).value; ok=true;
          }
        }
      }
      if(MyCatalog.length > 0){
        if(__GetElement(MyCatalog)!=null){
          if(__GetElement(MyCatalog).value.length > 0){
            if(v.length > 0){ v=v+"&"; }
            v=v+"dc="+__GetElement(MyCatalog).value;
          }
        }
      }
      if(MyRecord.length > 0){
        if(__GetElement(MyRecord)!=null){
          if(__GetElement(MyRecord).value.length > 0){
            if(v.length > 0){ v=v+"&"; }
            v=v+"dr="+__GetElement(MyRecord).value;
          }else{ ok=false; }
        }else{ ok=false; }
      }else{ ok=false; }
      if(MyReferTable.length > 0){
        if(__GetElement(MyReferTable)!=null){
          if(__GetElement(MyReferTable).value.length > 0){
            if(v.length > 0){ v=v+"&"; }
            v=v+"rfd="+__GetElement(MyReferTable).value;
          }
        }
      }
      if(MyReferRecord.length > 0){
        if(__GetElement(MyReferRecord)!=null){
          if(__GetElement(MyReferRecord).value.length > 0){
            if(v.length > 0){ v=v+"&"; }
            v=v+"rfdr="+__GetElement(MyReferRecord).value;
          }
        }
      }
    }
    if((v.length>0)&&(ok)){
      v=MyDataDrop+"?"+v+"&a=3&mode="+MyDataMode;
      if(typeof(DWin)!='undefined'){
        if(DWin!=null){
          if(recorddialog==null){
            if(typeof(dialog)!='undefined'){recorddialog=dialog;}
            dialog=DWin.open('Dialog', 'iframe', v, 'Удаление записи из базы данных/каталога', 'width=640px,height=320px,resize=1,scrolling=1,center=1,minButton=0,closeButton=1');
            dialog.onclose=function(){if(typeof(dialog)!='undefined'){dialog=recorddialog;}recorddialog=null;return true;};
          }
        }
      }
    }else{ alert("Выбирите запись для удаления!"); }
  }else{ alert("Перед удалением закройте диалоговое окно!"); }
}

function __GetElement(id){
	  var ret=null;
    if(typeof(document.getElementById)=='undefined'){
      if(typeof(document.all)!='undefined'){
        if(document.all!=null){ret=document.all[id];}
      }
    }else{
      if(document.getElementById==null){
        if(typeof(document.all)!='undefined'){
          if(document.all!=null){ret=document.all[id];}
        }
      }else{
    		ret=document.getElementById(id);
      }
    }
		return ret;
}

function GotoBack(){
  var l=MyHistoryLength-window.history.length-1;
  window.history.go(l);
}

function ToPrint(){
  var s=window.location.href;
  if(s.indexOf("?",0)<0){
    s=s+"?prn=1";
  }else{
    s=s+"&prn=1";
  }
  window.open(s);
}

