(function(){

if (typeof window.XWiki == "undefined") {
   window.XWiki = {};
}

XWiki = window.XWiki;
XWiki.WebDAV = {};

XWiki.WebDAV.displayDavLinks = function(domNode) {
    // un-hide Dav links only if the browser is going to support it
    if(window.ActiveXObject || window.InstallTrigger) {
       domNode.select(".attachment").each(displayDavLink);
    }
}

function displayDavLink(node) {
     node.down("a[class*='editlink']").removeClassName("hidden");
}


XWiki.WebDAV.davEdit = function(davURL) {
  if (window.ActiveXObject) {
    var editor;
    try {
      editor = new ActiveXObject("SharePoint.OpenDocuments");
    } catch (err) {
      window.alert("Could not initialize a required ActiveX object.");
      return;
    }
    if (editor) {
      editor.EditDocument(davURL);
    } else {
      window.alert("Error while initializing the share point editor.");
      return;
    }
  } else if (window.InstallTrigger) {		
    if ("createEvent" in document) {
      var element = document.createElement("FoXWikiDomEventData");
      element.setAttribute("davURL", davURL);
      element.setAttribute("foxwiki", "false");
      document.documentElement.appendChild(element);
      var evt = document.createEvent("Events");
      evt.initEvent("FoXWikiDomEvent", true, false);
      element.dispatchEvent(evt);
      if (element.getAttribute("foxwiki") == "false") {
        if (window.confirm("A Firefox extension is required to perform this action, install it?")) {
	  InstallTrigger.install( {"FoXWiki" :"https://addons.mozilla.org/en-US/firefox/downloads/file/39674/foxwiki-1.0b-fx.xpi"});
	}
      }
    } else {
      alert("Ooops! Something went wrong... Please try again.");
    }			
  } else {
    window.alert("Sorry, to use this feature you need either Firefox or Internet Explorer.");
  }
}

})();

