var Version = "5.9.1";

// -----------------------------------------------------------------------------------------------------
// Returns XmlHttpRequest or null
function CreateXmlHttpRequest(){
if(window.XMLHttpRequest) return new XMLHttpRequest();
if(window.ActiveXObject){ 
   if(window.XmlHttpActiveX) return new ActiveXObject(XmlHttpActiveX);
   var Err, Act = ["Msxml3.XMLHTTP","Msxml2.XMLHTTP","Microsoft.XMLHTTP"];
   for(var i=0;i<Act.length;i++){
      try { 
         var Req = new ActiveXObject(Act[i]); 
         XmlHttpActiveX = Act[i];
         return Req;
         }
      catch(e){ Err = e.message; }
      }
   return Err;
   }
return null;
}
var Req; // One Global XmlHttpRequest

// -----------------------------------------------------------------------------------------------------
// Loads the url by AJAX and displays it in the Body div
var LastUrl = "";
function Load(url){
var lurl = url.replace(/#[^\?]*/,"");
if(lurl=="Index.html"||lurl=="Gantt.html") return;
if(!lurl) lurl = decodeURI(location.href).replace(/#[^\?]*/,""); // Base Index.html
if(LastUrl!=lurl){
   LastUrl = lurl;
   try { 
      if(!Req) Req = CreateXmlHttpRequest(); if(!Req) return;
      
      // --- Loads new content ---
      Req.open("GET",lurl + (lurl.indexOf('?')>=0 ? "" : "?Ver="+Version),false);
      Req.send("");
      var s = Req.responseText;
      if(!s) return;
      var idx = s.indexOf("<!-- BodyStart -->"); if(idx<0) idx = s.indexOf("<body");
      if(idx>=0){ 
         while(s.charAt(idx)!='>') idx++;
         s = s.slice(idx+1);
         }
      var idx = s.indexOf("<!-- BodyEnd -->"); if(idx<0) idx = s.indexOf("</body");
      if(idx>=0) s = s.slice(0,idx);
      if(!url.match(/(^|\.html*|\.aspx*)($|#|\?)/)) s = "<code>"+s.replace(/\&/g,"&amp;").replace(/\</g,"&lt;").replace(/\r\n|\r|\n/g,"<br/>")+"</code>";
      var B = document.getElementById("Body");
   
      // --- Clears the old page ---
      for(var i=0;i<Grids.length;i++) if(Grids[i]) Grids[i].Dispose(); // Deletes all grids
      for(var E in Grids) if(E.indexOf("On")==0) delete Grids[E]; // Deletes all custom events set by the page
      Grids.length = 0;
      Grids.MaxHeight = 0;
      SpecResize = null; SpecStart = null; // Deletes special Resize and Start functions set by page
   
      // --- Updates all link urls ---
      s = s.replace(/\s+href\s*=\s*[\'\"](#[^\:\'\"]*)[\'\"]/gi," href=\""+url.replace(/#[^\?]*$/,"")+"$1\""); // Hash to the same page
      s = s.replace(/\s+href\s*=\s*[\'\"]([^\:\'\"]*)[\'\"]/gi," href=\""+url.replace(/[^\/\\]*$/,"")+"$1\""); // Hash to another page
      s = s.replace(/_Url\s*=\s*[\'\"]([^\:\'\"]*)[\'\"]/gi,"_Url=\""+url.replace(/[^\/\\]*$/,"")+"$1\""); // TreeGrid data url
      s = s.replace(/url\(\s*([^)]*)\)/gi,"url("+url.replace(/[^\/\\]*$/,"")+"$1)"); // style url(...)
      s = s.replace(/GridTutorialReplace[\S\s]*\<\/script\>/,"'><bdo Debug='' Data_Url='"+url.replace(/[^\/\\]*$/,"")+url.replace(/.*#/,"")+"'></bdo>"); // Special for ShowTutorial.html
      s = s.replace(/[\uFFFF\uFFFD]/g,"&nbsp;"); // Kvuli wordu a jeho 0xA0, 0xFFFF je v IE, 0xFFFD je v Mozille
      /*var ss = "";
      for(var i=0;i<s.length;i++){
         if(s.charCodeAt(i)>=128) ss += "["+s.charCodeAt(i)+"]";
         else ss += s.charAt(i);
         }
     s = ss;    */
      
      // --- Sets new content ---
      B.innerHTML = s;
      UpdateLinks();
   
      // --- Runs all scripts on page ---
      var js = s.match(/\<script[\>\s]([^\<]|\<[^\/]|\<\/[^s]|\<\/s[^c]|\<\/sc[^r]|\<\/scr[^i]|\<\/scri[^p]|\<\/script[^\>]|\<\/scrip[^t])*\<\/script\>/gi), scriptcnt = 0;
      if(js) for(var i=0;i<js.length;i++){ 
         try {
            var ss = js[i].replace(/^\<script\s*[^\>]*\>|\<\/script\>$/gi,"");
            if(ss.match(/^\s*$/)){ // external script
               ss = js[i].match(/\ssrc\s*\=\s*[\"\']([^\"\']*)[\"\']/);
               if(ss){ 
                  var D = document.createElement("script");
                  D.src = ss[1]+"?Ver="+Version;
                  scriptcnt++;
                  D.onreadystatechange = function(){ 
                     if(this.readyState=='complete'||this.readyState=="loaded"){ scriptcnt--; this.onreadystatechange = null; this.onload = null; }
                     }
                  D.onload = function(){ scriptcnt--; this.onreadystatechange = null; this.onload = null; }
                  B.appendChild(D);
                  }
               }
            else { 
               if(window.execScript) execScript(ss); // execScript runs the script in global scope in IE
               else if(BSafari){ var D = document.createElement("script"); D.innerHTML = BSafariVer>=5?ss:ss.replace(/&/g,"&amp;").replace(/</g,"&lt;"); B.appendChild(D); }// Safari cannot run eval in global scope, I think this way is better than setTimeout
               else window.eval(ss); // window.eval runs the script in global scope in all other browsers than IE and Safari. The window must be used.
               }
            } 
         catch(e) { }
         }
      
      // --- Styles ---
      // Neresi cesty k obrazkum !!!
      var js = s.match(/\<style[\>\s]([^\<]|\<[^\/]|\<\/[^s]|\<\/s[^t]|\<\/st[^y]|\<\/sty[^l]|\<\/styl[^e]|\<\/style[^\>])*\<\/style\>/g);
      if(js) for(var i=0;i<js.length;i++){ 
         var ss = js[i].replace(/^\<style\s*[^\>]*\>|\<\/style\>$/g,"");
         //var f = ss.replace(/\/[a-zA-z0-9_\?\&\%\=\+\$\.]*$/,""); 
         //if(f) S = S.replace(/url\(([^\)]*)\)/g,"url("+f+"/$1)"); // Musi zmenit vsechny cesty v url()
         var X = document.createElement("div");
         X.innerHTML = "<br/><style type='text/css'>\n"+ss+"\n</style>";
         B.appendChild(X);
         }      
         
      // --- Shows all new grids ---
      function Go(){ 
         if(scriptcnt) setTimeout(Go,50);
         else { Resize(); StartTreeGrid(); if(window.SpecStart) SpecStart(); }
         }
      setTimeout(Go,10);
      Grids.OnLoaded = new Function("setTimeout(Resize,10);");
      }
   catch(e) { /*alert(e.message?e.message:e);*/ return; }
   }
var hash = url.match(/#[^\?]*$/), body = CZoom==1?document.getElementById("BodyScroll"):document.documentElement, ok = 0;
if(hash){
   var A = document.getElementsByName(hash[0].slice(1));
   //var hash = encodeURIComponent(url.replace(/[\/\\]/g,'*').replace(/[\#]/g,"'"));
   var hash = url.replace(/[\/\\]/g,'*').replace(/[\#]/g,"'");
   for(var i=0;i<A.length;i++) if(A[i].tagName.toLowerCase()=="a"){
      var top = ElemToParent(A[i],body)[1]; // Calling GridE.js function
      if(!BIEA||BIE) top += body.scrollTop;
      if(BMozilla || BSafari){ 
         var h = 0;
         for(var r = A[i].firstChild;r;r=r.firstChild) if(h<r.offsetHeight) h = r.offsetHeight;
         h -= A[i].offsetHeight;
         if(h>0) top -= h; // Oriznuti v dokumentaci protoze <a name> je vne tagu s vetsim fontem
         }
      if(BOpera) top += body.scrollTop; // Proc podruhe ???   
      body.scrollTop = top*CZoom;
      ok = 1;
      break;
      }
   }
if(!ok) body.scrollTop = 0;   
return true;
}

// -----------------------------------------------------------------------------------------------------
// Called after click to the link
function ProcessClick(ev,a){
var url = a.href ? decodeURI(a.href) : a, hash = url;

// --- Updates URL to be relative to the actual ---
if(a.hostname==location.hostname && a.protocol==location.protocol){
   var A = a.pathname.split('/'), L = location.pathname.split('/');
   if(!A[0]) A.shift(); if(!L[0]) L.shift();
   for(var i=0;i<L.length-1;i++) if(A[i]!=L[i]) break;
   url = "";
   if(i!=L.length-1 || A.length!=L.length || A[i]!=L[i]){
      for(var j=i;j<L.length-1;j++) url += "../";
      for(var j=i;j<A.length-1;j++) url += A[j]+"/";
      url += A[A.length-1];
      }
   if(a.hash.slice(1)) url += a.hash;
   }
   
// --- Loads the data from url ---   
if(!Load(url)) return;

// --- Updates Hash URL and title ---
//var hash = encodeURIComponent(url.replace(/[\/\\]/g,'*').replace(/\#/g,"'"));
var hash = url.replace(/[\/\\]/g,'*').replace(/\#/g,"'");
if(hash) document.title = "EJS TreeGrid "+hash.replace(/\.[^\/\\\*]*$/,"");
else document.title = "EJS TreeGrid";
if(BSafariMac) { 
   location.hash = hash; // Safari must be without '#'
   Hash = hash;
   SHash = hash;
   }
else {   
   location.hash = "#"+hash; 
   Hash = location.hash.slice(1);
   }
if(BIEA){ 
   Frame.document.open();
   Frame.document.close();
   if(hash) Frame.document.title = "EJS TreeGrid "+hash.replace(/\.[^\/\\\*]*$/,"");
   else Frame.document.title = "EJS TreeGrid";
   Frame.location.hash = "#"+hash;
   }

// --- Cancels opening the link ---
if(ev) {
   if(ev.preventDefault){
      if(ev.cancelable) ev.preventDefault();
   	}
   else ev.returnValue = false;
   }
SendStat(a.href);   
}
// -----------------------------------------------------------------------------------------------------
// Called in interval for check back and forward in history
var Hash = null, SHash = null, Frame;
var BIEA = navigator.appName.search("Microsoft")>=0;
var BIE = BIEA && document.compatMode!="CSS1Compat";
var BSafari = navigator.userAgent.search(/Safari|Konqueror/i)>=0;
var BSafariVer = BSafari?parseFloat(navigator.userAgent.match(/(?:KHTML\D*|VERSION\D*)(\d[\d\.]+)/i)[1]):0;
var BSafariMac = BSafari && navigator.userAgent.search("Windows")<0;
var BMozilla = navigator.appName.search("Netscape")>=0 && !BSafari;
var BOpera = navigator.appName.search("Opera")>=0;
function CheckHistory(){
if(BIEA) UpdateIEZoom();
try {
   var hash = (BIEA?Frame.location.hash:location.hash).slice(1);
   if(BSafariMac){
      if(SHash && SHash!=hash) return; // Safari updates location.hash after a while
      SHash = null;
      }
   if(Hash==hash) return;
   Hash = hash;
   document.title = "EJS TreeGrid"+(hash?" "+hash.replace(/\.[^\/\\\*]*$/,""):"");
   Load(decodeURIComponent(hash.replace(/\*/g,"/").replace(/\'/g,"#")));
   if(BIEA){
      if(hash) location.hash = "#"+hash; 
      else location.href = Frame.location.href;
      }
   } 
catch(e) { }
}
// -----------------------------------------------------------------------------------------------------
// Called on start to load according to hash
function Start() {
Resize();
Hash = location.hash.slice(1);
if(BIEA){
   Frame = document.getElementById('Data').contentWindow;
   Frame.document.open();
   Frame.document.close();
   Frame.location.hash = "#"+Hash;
   Hash = Frame.location.hash.slice(1);
   if(Hash) Frame.document.title = "EJS TreeGrid "+Hash.replace(/\.[^\/\\\*]*$/,"");
   else Frame.document.title = "EJS TreeGrid";
   }  
if(Hash){ 
   document.title = "EJS TreeGrid "+Hash.replace(/\.[^\/\\\*]*$/,"");
   Load(decodeURIComponent(Hash.replace(/\*/g,"/").replace(/\'/g,"#")));
   }
else UpdateLinks();
setTimeout(Resize,10);
setInterval(CheckHistory,50);
SendStat(location.href);
}
// -----------------------------------------------------------------------------------------------------
function UpdateLinks(){
var A = document.links;
//var A = document.body.getElementsByTagName("a");
var F = new Function("ev","ProcessClick(ev?ev:event,this)");
var S = new Function("ev","SendStat(this.href)");
for(var i=0;i<A.length;i++){
   if(!A[i].href || A[i].onclick) continue;
   if(A[i].hostname==location.hostname && A[i].href.search(/\.(htm|html|txt|xml)($|\#|\?)|\/#\w*$/i)>=0) A[i].onclick = F;
   else A[i].onclick = S;
   }
}   
// -----------------------------------------------------------------------------------------------------
// Called for resize height of body and menu
function Resize(){
var MS = document.getElementById('MenuScroll'), MB = document.getElementById('MenuBottom');
var MH = document.getElementById('MenuHeader'), MF = document.getElementById('MenuFooter');
var BS = document.getElementById('BodyScroll'), B = document.getElementById('Body');
if(CZoom!=1){ // Only for IE
   document.body.style.overflow = "visible";
   document.documentElement.style.overflow = "auto";
   MB.style.visibility = "hidden";
   MS.style.overflow = "visible";
   BS.style.overflow = "visible";
   MS.style.height = "";
   BS.style.height = "";
   B.style.height = "";
   BS.style.width = "";
   B.style.width = "";
   }
else {
   document.body.style.overflow = "";
   document.documentElement.style.overflow = "";
   MB.style.visibility = "";
   MS.style.overflow = "";
   BS.style.overflow = "";
   
   var h = MB.offsetTop, hm = (h - MH.offsetHeight - MF.offsetHeight - 100), hb = h - 72;
   if(hm<100) hm = 100;
   if(hb<100) hb = 100;
   MS.style.height = hm+"px";
   BS.style.height = hb+"px";
   if(Grids.MaxHeight&&h>700){ B.style.height = hb+"px"; B.style.overflow = "hidden"; }
   else B.style.overflow = "visible";
   var w = GetWindowSize()[0];
   if(w>10) {
      w-=document.getElementById("MenuAll").offsetWidth;
      BS.style.width = (w-0)+"px";
      if(w<800) w = 800;
      B.style.width = (w-(BIE?17:47))+"px";
      }
   }
if(window.SpecResize) SpecResize();
}
// -----------------------------------------------------------------------------------------------------
// Shows / Hides the left menu
var Hid = 0;
function Hide() {
document.getElementById("MenuHide").className = Hid?"MenuHide":"MenuShow";
document.getElementById("Logo").className = Hid?"TopLogo":"TopLogoShort";
document.getElementById("Menu").style.display = Hid?"":"none";
document.getElementById("MenuBottom").style.width = Hid?"197px":"13px";
document.getElementById("MenuAll").style.width = Hid?"197px":"13px";
Hid = !Hid;
Resize();
}
// -----------------------------------------------------------------------------------------------------
// Expands one menu item
function Expand(E,exp) {
if(exp) E = E.parentNode;
var D = E.nextSibling; while(D.nodeType!=1) D = D.nextSibling;
if((D.className=="LevelHidden"||D.className=="LevelHiddenL")){
   if(!exp){
      D.className = D.className=="LevelHidden" ? "Level" : "LevelL";
      E.className = E.className=="C" ? "E" : "EL";
      }
   }
else {
   D.className = D.className=="Level" ? "LevelHidden" : "LevelHiddenL";
   E.className = E.className=="E" ? "C" : "CL";
   }
//Resize();   
}
// -----------------------------------------------------------------------------------------------------
var Stat,SReq;
function SendStat(url){
return; // Vyrazeno, nebot s tim byly problemy
try { 
   //if(location.hostname.search(/coqsoft\.|treegrid\./i)<0) return; // Stat only on web

   if(!Stat){
      var fv = 0;
      try {
         if(BIEA){
            var plg = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
            if(plg) fv = plg.GetVariable("$version").split(",")[0].split(" ")[1];
            } 
         else if (navigator.plugins && navigator.plugins.length > 0) {
            var plg = navigator.plugins["Shockwave Flash 2.0"];
            if(!plg) plg = navigator.plugins["Shockwave Flash"];
            if(plg) fv = plg.description.split(" ")[2].split(".")[0];
            }
         }
      catch(e) { }   
   
      var r=window.top.document.referrer;

      try {   
         var j=navigator.javaEnabled()?1:0;
         var d=screen.colorDepth;
         if(d==0) d=screen.pixelDepth;
         var x = screen.width;
         var w=BIEA?top.document.body.clientWidth:top.innerWidth; 
         var y=new Date();
         y.setTime(y.getTime()-31536000000);
         document.cookie="nvt=1";
         var c=(document.cookie.indexOf("nvt") != -1)?1:0;
         document.cookie="nvt=1; expires="+y.toGMTString();
         }
      catch(e) { }   
      Stat = "Stat.aspx?site=96476;t=lb14;fv="+fv+";js="+j+";cs="+c+";ref="+escape(r)+";cd="+d+";sx="+x+";wx="+w+";jss=1;r=";
      }
   if(!SReq) SReq = CreateXmlHttpRequest(); if(!SReq) return;
   SReq.open("GET",Stat+Math.random()+"&url="+encodeURIComponent(url));
   SReq.send("");
   }
catch(e) { }   
}
// -----------------------------------------------------------------------------------------------------
function DoSearch(ev){
var I = document.getElementById('Search');
var val = I.value;
if(!val){ CancelEvent(ev); return; }
val = val.replace(/[^a-zA-Z0-9_]+/g," ");
val = val.replace(/^\s+|\s+$/g,"");
I.value = val;
ProcessClick(ev,"Search.aspx?search="+val.replace(/\s/g,"-"));
}
// -----------------------------------------------------------------------------------------------------------
// Zjisti Page zoom pro IE7
// Funguje pouze ve strict mode
var CZoom = 1;
var IEZoomDiv;
function GetIEZoom(){
if(!IEZoomDiv){
   IEZoomDiv = document.createElement("div");
   var s = IEZoomDiv.style;
   s.position = "absolute";
   s.left = "100px";
   s.top = "0px";
   s.width = "0px";
   s.height = "0px";
   s.visibility = "hidden";
   document.body.insertBefore(IEZoomDiv,document.body.firstChild);
   }
CZoom = IEZoomDiv.offsetLeft/100;
if(CZoom>0.95 && CZoom<1.05) CZoom = 1;
return CZoom;
}
// -----------------------------------------------------------------------------------------------------
function UpdateIEZoom(){
var ozoom = CZoom;
GetIEZoom();
if(ozoom == CZoom) return;
Resize();
}
// -----------------------------------------------------------------------------------------------------
                  