var buttonStatus = "hidden";
var element;
var elementLayerItem;

function hideButton(){

  if(element){
    if(buttonStatus == 'hidden'){

      element.style.display = 'none';
    }
    else{
      element.style.display = 'block';
    }
  }
}

function hideAppendButton(){

  if(element){
    if(buttonStatus == 'hidden'){
      element.style.display = 'none';
      wToggleLayerElementsToAppend(elementLayerItem);
    }
    else{
      element.style.display = 'block';
    }
  }
}

function wEditPageBe(path, sourcePath, target, redirectEndEdit, referrer){




  var url = '/weblication/grid/scripts/wFilemanager.php?action=startedit&target=be&path=' + path + '&referrer=' + referrer + '&redirectEndEdit=' + redirectEndEdit;
  var target = '_blank';

  try{
    if(top.frames['wInnerMain']){
      top.frames['wInnerMain'].showPage(url, path, 'icons/button_edit.gif');
      return;
    }  
  } 
  catch(e){
  }  

  if(target == '_blank'){
    var winHeight = screen.availHeight - 64;
    var winWidth  = screen.availWidth  - 36;
    if(typeof wOpenWindowX == 'function'){ 
      wOpenWindowX(url, path, 'width=' + winWidth + ',height=' + winHeight + ',resizable=yes');
    }

    else if(typeof wOpenWindow == 'function'){
      wOpenWindow(url, path, winWidth, winHeight, 'resizable=yes');
    }
  }
  else{
    location.href = url;
  }
}

function wEditNavigationBe(path, sourcePath, target, redirectEndEdit, referrer){




  var url = '/weblication/grid/scripts/wFilemanager.php?action=startedit&target=be&path=' + path + '&referrer=' + referrer + '&redirectEndEdit=' + redirectEndEdit;

  var winHeight = 640;
  var winWidth  = 720;
  
  wOpenWindowX(url, path, 'width=' + winWidth + ',height=' + winHeight + ',resizable=yes');

}

function wEditCategoryBe(path, sourcePath, target, redirectEndEdit, referrer){




  var url = '/weblication/grid/scripts/wFilemanager.php?action=startedit&target=be&path=' + path + '&referrer=' + referrer + '&redirectEndEdit=' + redirectEndEdit;

  var winHeight = 640;
  var winWidth  = 720;
  
  wOpenWindowX(url, path, 'width=' + winWidth + ',height=' + winHeight + ',resizable=yes');

}

function wInsertURLNavigationBe(path, referrer, redirectEndEdit){




  var url = '/weblication/grid/scripts/wFilemanager.php?action=startedit&target=be&path=' + path + '&referrer=' + referrer + '&redirectEndEdit=' + redirectEndEdit + '&linkUrl=' + encodeURIComponent(referrer);
  var winHeight = 640;
  var winWidth  = 720;
  wOpenWindowX(url, path, 'width=' + winWidth + ',height=' + winHeight + ',resizable=yes');

}

function wLogoutSystemBe(redirectURL){

  if(!redirectURL){
    redirectURL = location.href;
  }
  
  var url = '/weblication/grid/scripts/wSystem.php?action=logout&redirect=' + escape(redirectURL);
  
  location.href = url;
}

function wLoginSystemBe(){




  var url = '/weblication/grid/scripts/wSystem.php';
  wOpenWindowX(url, 'wGridBackend', 'resizable=yes');
}

function wCreatePageBe(destDir, destName, template){




  var url = '/weblication/grid/scripts/wFilecreator.php?action=showmaskcreatedocument&destDir=' + destDir + '&destName=' + destName + '&template=' + template;
  url = url.replace(/amp;/g, '');
  var winHeight = 440;
  var winWidth  = 644;
  wOpenWindowX(url, '', 'width=' + winWidth + ',height=' + winHeight + ',resizable=no');
}

function wShowAdmin(weblicPath){

  var url = weblicPath + '/wScripts/index.php?script=admin';
  url = url.replace(/amp;/g, '');
  var winHeight = 640;
  var winWidth  = 800;
  wOpenWindowX(url, '', 'width=' + winWidth + ',height=' + winHeight + ',resizable=no');
}

function wShowVersionsPageBe(path, sourcePath, target, redirectEndEdit, referrer){

  var url = '/weblication/grid/scripts/wFilemanager.php?action=showversions&repository=&path=' + path + '&referrer=' + referrer + '&redirectEndEdit=' + redirectEndEdit;
  url = url.replace(/amp;/g, '');

  var winHeight = 420;
  var winWidth  = 720;
  wOpenWindowX(url, path, 'width=' + winWidth + ',height=' + winHeight + ',resizable=yes');
}

function wShowLayoutWizardBe(project, redirectEndEdit, referrer){

  var url = '/weblication/grid/scripts/wLayoutmanager.php?action=showlayoutwizardbe&repository=&project=' + project + '&referrer=' + referrer + '&redirectEndEdit=' + redirectEndEdit;
  url = url.replace(/amp;/g, '');

  var winHeight = 470;
  var winWidth  = 460;
  wOpenWindowX(url, '', 'width=' + winWidth + ',height=' + winHeight + ',resizable=yes');
}


function wShowLayoutManagerBe(project, redirectEndEdit, referrer){

  var url = '/weblication/grid/scripts/wProjectmanager.php?action=showmasklayouts&project=' + project;

  url = url.replace(/amp;/g, '');

  var winHeight = 441;
  var winWidth  = 643;
  wOpenWindowX(url, '', 'width=' + winWidth + ',height=' + winHeight + ',resizable=yes');
}

function refreshSession(){
  
  if(typeof wGetUrlAjax == 'function'){
    wGetUrlAjax('/weblication/grid/scripts/wSystem.php?action=refreshSession', refreshSessionResponse);
  }
  else{
    getUrl('/weblication/grid/scripts/wSystem.php?action=refreshSession', refreshSessionResponse);
  }  
}

function refreshSessionResponse(responseStr){
}

function wExecWorkflowBe(id, url, options){
  if(id == 'approve'){
    location.href = url;
  }
  else if(id == 'reject'){
    wOpenWindow(url, 'rejectWorkflow', '600', '600');
  }
  else if(id == 'versions'){
    wOpenWindow(url, 'versions', '900', '600');
  }
  else if(id == 'showStatus'){
    wOpenWindow(url, 'status', '900', '600', 'resizable=yes,scrollbars=yes,status=yes');
  }
  else if(id == 'showWorkflowFile'){
    location.href = url;
  }
  else {
    location.href = url;
  }
  
}


function wCreateButton(path, pathType, destName, sourceTemplate, isInEditor){
  globalInEditor = isInEditor;
  if(pathType == 'file'){
    var url = '/weblication/grid/scripts/wFilecreator.php?action=showmaskcreatedocument&destDir='+path+'&destName='+destName+'&template='+sourceTemplate+'&onAfterCreateDocument=onAfterCreateDocument';
    var winHeight = 440;
    var winWidth  = 644;
  }
  else if(pathType == 'dir'){
    var url = 'wDircreator.php?action=showmaskcreatedir&path='+path+'&template='+sourceTemplate;
    var winHeight = 441;
    var winWidth  = 643;
  }
  
  wOpenWindowX(url, '', 'width='+winWidth+',height='+winHeight+'resizable=no');
}

function onAfterCreateDocument(path){
  var url     = '/weblication/grid/scripts/wFilemanager.php?action=startedit&target=be&path=' + path;
  if(globalInEditor == 1){
    url += '&referrer=&redirectEndEdit=javascript:buttonInEditor()';
  }
  var winHeight = screen.availHeight - 64;
  var winWidth  = screen.availWidth  - 36;
  if(typeof wOpenWindowX == 'function'){ 
    wOpenWindowX(url, path, 'width='+winWidth+',height='+winHeight+',resizable=yes');
  }

  else if(typeof wOpenWindow == 'function'){
    wOpenWindow(url, path, winWidth, winHeight, 'resizable=yes');
  }
}

function buttonInEditor(){
  if(typeof(parent.changeContentPreviewDocument) == 'function'){
    parent.changeContentPreviewDocument();
  }
  else if(typeof(top.changeContentPreviewDocument) == 'function'){
    top.changeContentPreviewDocument();
  }
  else{
    location.reload();
  }
}

function wDeleteButton(path, pathType, textPre, textPost){
  var validate = confirm(textPre+path+textPost);
  if(validate == true){
    if(pathType == 'file'){
      var url = '/weblication/grid/scripts/wFilemanager.php?action=movetotrashfile&path=' + path + '&redirectSucc=' + encodeURIComponent(document.location.href);
    }
    else if(pathType == 'dir'){
      var url = '/weblication/grid/scripts/wFilemanager.php?action=movetotrashdir&path=' + path + '&redirectSucc=' + encodeURIComponent(document.location.href);
    }
    location.href = url;
  }
}

function wEditButton(path, pathType, isInEditor){
  globalInEditor = isInEditor;
  if(pathType == 'file'){
    var url = '/weblication/grid/scripts/wFilemanager.php?action=startedit&target=be&path='+path;
  }
  else if(pathType == 'dir'){
    var url = '/weblication/grid/scripts/wFilemanager.php?action=showMaskEditOptionsDir&target=be&path='+path;
  }
  if(isInEditor == 1){
    url += '&referrer=&redirectEndEdit=javascript:buttonInEditor()';
  }
  
  var winHeight = screen.availHeight - 64;
  var winWidth  = screen.availWidth  - 36;
  if(typeof wOpenWindowX == 'function'){ 
    wOpenWindowX(url, path, 'width=' + winWidth + ',height=' + winHeight + ',resizable=yes');
  }

  else if(typeof wOpenWindow == 'function'){
    wOpenWindow(url, path, winWidth, winHeight, 'resizable=yes');
  }
}

function wUploadButton(path){
  var url     = '/weblication/grid/scripts/wUploader.php?action=showmaskuploadfile&uploaddir=' + path;
  var winHeight = '290px';
  var winWidth  = '640px';
  if(typeof wOpenWindowX == 'function'){ 
    wOpenWindowX(url, 'wUploader', 'width=' + winWidth + ',height=' + winHeight + ',resizable=yes');
  }

  else if(typeof wOpenWindow == 'function'){
    wOpenWindow(url, 'wUploader', winWidth, winHeight, 'resizable=yes');
  }
}