//dim appIcon as string ="http://static.teamwiki.net/img/icons/oxygen/text-html.png"

//alert("*** scriptLib03.js ***")
/*
window.SJAX_getFileContent=function(url) {
  if (window.XMLHttpRequest) {
    var AJAX = new XMLHttpRequest();
  } else {
    var AJAX = new ActiveXObject("Microsoft.XMLHTTP");
  }
  alert(AJAX)
  if (AJAX) {
     AJAX.open("GET", url, false);
     alert(222)
     AJAX.send(null);
     alert(333)
     return AJAX.responseText;
  } else {
     return false;
  }
}*/

window.SJAX_getFileContent=function(url) {
    if (window.XMLHttpRequest) {
        var AJAX = new XMLHttpRequest();
    } else {
        var AJAX = new ActiveXObject("Microsoft.XMLHTTP");
    }
    if (AJAX) {
        AJAX.open("GET", url, false);
        AJAX.send(null);
        return AJAX.responseText;
    } else {
        return false;
    }
}

function isNumber(n) {
  return !isNaN(parseFloat(n)) && isFinite(n);
}

window.macro_insertsubmenulinks=function(mDATA) {
  var place=mDATA.place
  var macroName=mDATA.macroName
  var allParams=mDATA.allParams
  var params=allParams.split(",");
  var wikifier=mDATA.wikifier
  if (isNumber(params[0]) == false) params[0] = "1"
  //alert(params[0])
  var url="/php/labs/macro_helper.php?c=get_submenu_links"
  url += "&user=" + window.qqTW.pageInfo.user
  url += "&start_line=" + window.qqTW.pageInfo.act_menu_line
  url += "&levels=" + params[0]
  var RESULT = SJAX_getFileContent(url)
  
  var ul = [place,place,place,place,place]
  var LINES = RESULT.split("\n");
  for(var i = 0; i<LINES.length; i++) {
      if (LINES[i] == "") continue;
      //alert(LINES[i]);
      var data = LINES[i].split("\t");
      
      var fileName = data[4];
      fileName = fileName.replace(/\.html?$/g, ".htm");
      
      ul[data[0]]=document.createElement("LI");
      ul[data[0]].innerHTML = "<a href=\"/"+fileName+"\">"+data[2]+"</a>";
      if (ul[data[0]-1] == null || ul[data[0]-1] == place || ul[data[0]-1].tagName=="LI") {
          ul[data[0]-1] = document.createElement("UL");
          ul[data[0]-2].appendChild(ul[data[0]-1])
      }
      ul[data[0]-1].appendChild(ul[data[0]])
  }
  
  return;
}

window.macro_chm_index=function(mDATA) {
  var place=mDATA.place
  var macroName=mDATA.macroName
  var allParams=mDATA.allParams
  var params=allParams.split(",");
  var wikifier=mDATA.wikifier
  
  if (!params[1]) params[1]="";
  
  var el=document.createElement("a");
  el.setAttribute("chmkeyword", params[0]);
  el.setAttribute("name", params[1]);
  
  place.appendChild(el)
  return;
  
  
}//endFunction





var suchStartTime;

window.delComment = function(id) {
  window.open("/php/send_wikimail.php?del_comment=" + id, "delcomwin", "width=460,height=180");
}


window.parseOptionString = function(h) {
  var l = this;
  if(!h) return {};
  
  var g = [], e, c = /`([^`]*?)`/g;
  c.lastIndex = 0;
  while((e = c.exec(h))) {
    g.push(e[1]);
  }
  if(g.length) h = h.replace(c, "``");
  h = h.replace(/\s*[:=]\s*/g,":");
  h = h.replace(/\s*[;&]\s*/g," ");
  h = h.replace(/^\s+|\s+$/g,"");
  h = h.replace(/(:\d+)px\b/gi,function(i,m){return m});
  
  var b = {}, f = h.split(" "), d = f.length;
  while(d--) {
    var k = f[d].split(":"), a = k[0], j = k[1];
    if (typeof j === "string") {
      if (!isNaN(j)) {
        j =+ j
      } else {
        if (j === "true") j = true
        else if(j === "false") j = false
      }
    }
    if(j === "``") {
      j = g.pop() || ""
    }
    b[a] = j
  }
  return b;
}


//-->

window.showMyDocs=function() {
  //window.open("http://secure.teamwiki.net/mydocs2?view=mini", "myDocs", "width=900,height=700,resizable=yes");
  //showUrlPopup("http://secure.teamwiki.net/mydocs2?view=mini#"+qqTW.pageInfo.user, "Eigene Dateien", "myDocs");
  wzOpenWindow("mydocs");
}

window.showPageProperties=function() {
  /*showUrlPopup('/php/page_action_dlg.php?m=rights&id='+qqTW.pageInfo.id,
               'Eigenschaften von '+qqTW.pageInfo.title,
               'pageProperties', 545, 580);*/
  wzOpenWindow("page_properties");
}

//diese Funktion wird überschrieben, wenn die Datei geladen ist
window.wzOpenWindow=function(navigateTo) {
  window.wzCallPara_navigateTo=navigateTo
  tWiki_loadScriptOnDemand("http://static.teamwiki.net/js/wzMain.js");
  
}

window.showWikiProperties=function() { 
  wzOpenWindow("wiki_properties");
  
  return
  
  var id="wikiProperties"
  
  var q=new Object
  q.id=id
  q.title="Eigenschaften von Wiki "+qqTW.pageInfo.user
  q.left=111         // ...center fehlt noch
  q.top=111
  q.width=900
  q.height=666
  q.onresize = onWikiPropertiesResize;//onWikiPropertiesResize
  
  var hwnd=domWin_create(q)   // ...domWindow erzeugen

  hwnd.innerDiv.style.borderWidth="2px"
  hwnd.innerDiv.style.borderColor="#efefef"
  hwnd.innerDiv.style.borderStyle="solid"
  hwnd.background.style.backgroundColor="#efefef"
  hwnd.clientArea.style.padding="0px"
  hwnd.clientArea.style.overflow="hidden"
  var LF=String.fromCharCode(10); var q=''
  q+=LF+'<div id="mySidebar_|ID|" class="buttonListBar" style="width:100px; height:600px; float:left; border-width:0px; position: relative; ">'
  q+=LF+'<div mode="wiki/pagerights" class="buttonListBarItem"><div style="background-image:url(http://mw.teamwiki.net/docs/img/win-icons/shdocvw_103-32.png)">Berechtigungen</div></div>'
  q+=LF+'<div mode="wiki/config" class="buttonListBarItem"><div style="background-image:url(http://mw.teamwiki.net/docs/img/win-icons/Setupwiz_IDI_CONFIG-32.png)">Einstellungen</div></div>'
  q+=LF+'<div mode="wiki/sidebar" class="buttonListBarItem"><div style="background-image:url(http://mw.teamwiki.net/docs/img/win-icons/sidebar.png)">Sidebar</div></div>'
  q+=LF+'<div mode="wiki/locksite" class="buttonListBarItem"><div style="background-image:url(http://mw.teamwiki.net/docs/img/win-icons/sprt0407_13060-32.png)">Sperren</div></div>'
  q+=LF+'<div mode="wiki/imprint" class="buttonListBarItem"><div style="background-image:url(http://mw.teamwiki.net/docs/img/win-icons/OUTLLIBR_9602-32.png)">Impressum</div></div>'
  q+=LF+'<div mode="wiki/design/wizard" class="buttonListBarItem"><div style="background-image:url(http://mw.teamwiki.net/docs/img/win-icons/shimgvw_3-32.png)">Design</div></div>'
  q+=LF+'<div mode="wiki/design/css" class="buttonListBarItem"><div style="background-image:url(http://mw.teamwiki.net/docs/img/win-icons/shell32_151-32.png)">CSS bearbeiten</div></div>'
  q+=LF+'<div mode="wiki/design/htmltemplate" class="buttonListBarItem"><div style="background-image:url(http://mw.teamwiki.net/docs/img/win-icons/shell32_151-32.png)">Template bearbeiten</div></div>'
  q+=LF+'<div mode="wiki/script" class="buttonListBarItem"><div style="background-image:url(http://mw.teamwiki.net/docs/img/win-icons/wscript_100-32.png)">JavaScript</div></div>'
  q+=LF+'<div mode="wiki/orphaned" class="buttonListBarItem"><div style="background-image:url(http://mw.teamwiki.net/docs/img/win-icons/OUTLLIBR_119-32.png)">Verwaiste Seiten</div></div>'
  
  q+=LF+'</div> '
  q+=LF+'<iframe id="myIframe_|ID|" style="width:780px; height:600px; border-width:0px; position: relative; '
  q+=LF+'      left:0px; top:0px;  margin:0px; padding:0px ; background-color:#fff; " '  //position:absolute;
  q+=LF+'      src="about:blank" '
  q+=LF+'     > '
  q+=LF+'</iframe> '
  q=replaceAll(q, '|APO|', '"')
  q=replaceAll(q, '|ID|', id)
  // alert(q)
  hwnd.viewer.innerHTML=q
  // alert("-->"+id+"<--")
  
  window.WikiPropertiesSidebarLastSelected=null;
  findById("mySidebar_"+id).onclick=onWikiPropertiesButtonClicked;
  
  onDomWinResize(id)
  
}//endFunction

window.onWikiPropertiesButtonClicked=function(e) {
  if(!e)e=window.event;
  var target=resolveTarget(e);
  
  
  
  var el=findElementByAttribute(target,"mode");
  if (el) {
    if (window.WikiPropertiesSidebarLastSelected) {
      window.WikiPropertiesSidebarLastSelected.className="buttonListBarItem"
    }
    window.WikiPropertiesSidebarLastSelected = el
    el.className = "buttonListBarItem active"
    var mod = el.getAttribute("mode")
    var url="http://secure.teamwiki.net/"+mod+"?view=mini&s_u="+qqTW.pageInfo.user;
    findById("myIframe_wikiProperties").src=url
  }
}

window.onWikiPropertiesResize=function(id) {
  //  alert(id)
  var win = window.domWindowPARA[id]
  var iframe = findById("myIframe_"+id)
  iframe.style.width = parseInt(win.outerDiv.style.width)-110 + "px"
  
  var sidebar = findById("mySidebar_"+id)
  iframe.style.height = win.clientArea.style.height-80 + "px"
  
  
}

//-->
//--> privatMenu (hover auf Username)


window.showPrivatMenu = function() {
  var el=findById("privatMenu")
  if (!el) createPrivatMenu();
  
  el=findById("privatMenu")
  var link = findById("privatmenuLink")
  el.style.left = findPosX(link)-40 + "px"
  el.style.top = findPosY(link)-2 + "px"
  el.style.display="block"
}


window.privatMenuOver=function(){
  if(window.privatMenuHideTimeoutID)window.clearTimeout(privatMenuHideTimeoutID)
}
window.privatMenuOut=function(){
  privatMenuHideTimeoutID=window.setTimeout(hidePrivatMenu, 888)
}
window.hidePrivatMenu = function() {
  
  var el=findById("privatMenu")
  if (el) el.style.display="none"
}

function findPosX(obj) {
  var curleft = 0;
  if(obj.offsetParent)
    while(1) {
      curleft += obj.offsetLeft;
      if(!obj.offsetParent) break;
      obj = obj.offsetParent;
    }
  else if(obj.x)
    curleft += obj.x;
  return curleft;
}
function findPosY(obj) {
  var curtop = 0;
  if(obj.offsetParent)
    while(1) {
      curtop += obj.offsetTop;
      if(!obj.offsetParent) break;
      obj = obj.offsetParent;
    }
  else if(obj.y)
    curtop += obj.y;
  return curtop;
}


window.createPrivatMenu = function() {
  var LF=String.fromCharCode(10); var q=''; var height = 235;
  q+=LF+'  <ul> '
  q+=LF+'        <li><strong>__FULLNAME__</strong></li> '
  q+=LF+'         '
  q+=LF+'         <li class="trenn"></li>'
  q+=LF+'        <li><a class="item" href="http://__USERNAME__.teamwiki.net/profile/" title="Meine Profilseite anzeigen"> <img alt="[]" '
  q+=LF+'        src="http://mw.teamwiki.net/docs/img/icons/User.png" /> Profilseite</a> '
  q+=LF+'        </li> '
  q+=LF+'         '
  q+=LF+'        <li><a class="item" href="http://__USERNAME__.teamwiki.net" title="Homepage"> <img alt="[]" '
  q+=LF+'        src="http://static.teamwiki.net/img/icons/tango/16x16/actions/go-home.png" /> Homepage</a> '
  q+=LF+'        </li> '
  q+=LF+'         '
  q+=LF+'         <li class="trenn"></li>'//http://secure.teamwiki.net/account/data/
  q+=LF+'        <li><a class="item" href="#" onclick="wzOpenWindow(\'ua_general\')" title="Benutzerprofil bearbeiten"> <img alt="[]" '
  q+=LF+'        src="http://start.teamwiki.net/docs/img/oxygen_info_16.png" /> Mein Account</a> '
  q+=LF+'        </li> '
  q+=LF+'         '
  q+=LF+'        <li><a class="item" href="#" onclick="showMyDocs();" title="Eigene Dateien"> <img alt="[]" '
//  q+=LF+'        <li><a class="item" href="http://secure.teamwiki.net/mydocs2/" title="Eigene Dateien"> <img alt="[]" '
  q+=LF+'        src="http://mw.teamwiki.net/docs/img/win-icons/shell32_173-16.png" height=16 width=16 /> Eigene Dateien</a> '
  q+=LF+'        </li> '
  q+=LF+'         '
  q+=LF+'        <li><a class="item" id="wikimail-link" href="http://secure.teamwiki.net/wikimail/"> <img alt="[]" '
  q+=LF+'        src="http://mw.teamwiki.net/docs/img/win-icons/explorer_254-16.png" /> WikiMail __MAIL_COUNT__</a> '
  q+=LF+'        </li> '
  q+=LF+'         '//http://secure.teamwiki.net/contacts/
  q+=LF+'        <li><a class="item" href="#" onclick="wzOpenWindow(\'ua_contacts\')" title="Kontaktliste"> <img alt="[]" '
  q+=LF+'        src="http://start.teamwiki.net/docs/img/address-book_16.png" /> Meine Kontakte</a> '
  q+=LF+'        </li> '
  q+=LF+'         '//http://secure.teamwiki.net/team/myteams/
  q+=LF+'        <li><a class="item" href="#" onclick="wzOpenWindow(\'ua_teams\')" title="Team-Verwaltung"> <img alt="[]" '
  q+=LF+'        src="http://mw.teamwiki.net/docs/img/win-icons/shell32_269-16.png" /> Meine Teams</a> '
  q+=LF+'        </li> '
  q+=LF+'         '
  /*if (qqTW.pageInfo && qqTW.pageInfo.canedit == "true") {
    q+=LF+'        <li><a href="http://secure.teamwiki.net/wiki/manager/?s_u=__PAGEOWNER__" title="WikiManager"> <img alt="[]" '
    q+=LF+'        src="http://mw.teamwiki.net/docs/img/win-icons/WinHex_4-16.png" height=16 width=16 /> WikiManager</a> '
    q+=LF+'        </li> '
    height+=20
  }*/
  q+=LF+'         '
  q+=LF+'         '
  q+=LF+'         <li class="trenn"></li>'
  q+=LF+'        <li><a class="item" href="http://secure.teamwiki.net/LogOut"><img alt="[]" '
  q+=LF+'        src="http://static.teamwiki.net/img/icons/tango/16x16/actions/system-log-out.png" /> Logout</a> '
  q+=LF+'        </li> '
  q+=LF+'        </ul> '
  q=replaceAll(q, '_|APO|_', "'")
  q=replaceAll(q, '__USERNAME__', qqTW.login.username)
  if (qqTW.pageInfo)q=replaceAll(q, '__PAGEOWNER__', qqTW.pageInfo.user)
  q=replaceAll(q, '__FULLNAME__', qqTW.login.fullname)
  var mailCount = "";
  if (qqTW.newMails) mailCount = "(" + qqTW.newMails + " neue)"
  q=replaceAll(q, '__MAIL_COUNT__', mailCount)
  
  var container;
  //container = findById("header")
  container = document.body
  
  var div = document.createElement("DIV");
  div.className="twMiniMenu"; div.id="privatMenu";
  div.style.height = height+"px";
  addEvent(div, 'mouseover', privatMenuOver);
  addEvent(div, 'mouseout', privatMenuOut);
  
  //div.onmouseout = hidePrivatMenu;
  
  div.innerHTML = q
  
  container.appendChild(div)
  
}

window.createMiniMenu = function(elements, width) {
  var div = document.createElement("DIV");
  div.className="twMiniMenu"
  
  for (var i in elements) {
    var info = elements[i];
    var li=document.createElement("LI");
    var a=document.createElement("A");
    a.innerHTML = "<img src='" + info.imgUrl + "' alt='icon' /> "+ info.text
    a.href = info.linkUrl
    if (info.clickHandler) a.onclick = info.clickHandler;
    li.appendChild(a)
    div.appendChild(li)
  }
  
}


/*
window.openCommentForm = function() {
  var el = findById('send_comment');
  if (el.style.display=='block') {
    el.style.display='none';
  } else {
    el.style.display='block';
  }
  
  //findById('send_comment_btn').disabled='disabled';
  //findById('send_comment_btn2').disabled='disabled';
  location.hash = '#comments';
}

window.replyToComment = function(sender, rep_id, rep_num, rep_title) {
  
  document.forms.addcommentform.in_reply_to.value = rep_id;
  findById('in_reply_to2').value = "[ " + rep_num + " ]   "+ rep_title;
  findById('comment-title').value = "RE: "+ rep_title;
  findById('reply_to_block').style.display = 'block';
}

window.submitCommentForm = function() {
  var tx = findById("comment-textbox");
  var txwiki = findById("comment-wikified");
  
  var wikitext = wikifyEx( tx.value);
  txwiki.value = wikitext;
  
  var form = findById("add-comment-form");
  form.submit();
}
*/









//-->
//--> bookmarksMenu

window.bookmarksMenu_toggle = function() {
  var div = findById('bookmarkMenuDiv');
  if (!div) {bookmarksMenu_show(); return;}
  if (div.style.display="none")bookmarksMenu_show();
  else bookmarksMenu_hide();
}

window.bookmarksMenu_hide = function() {
  var el=findById("bookmarkMenuDiv")
  if (el) el.style.display="none"
  var link = findById('bookmarksLink');
  link.className = 'bookmarksLink_none';
}
window.bookmarksWindow=null;

window.bookmarksMenu_show = function() {
  //var div = findById('bookmarkMenuDiv');
  var link = findById('bookmarksLink');
  if (window.bookmarksWindow) {
    //div.style.display = 'block';
    bookmarksWindow.outerDiv.style.display='block'
    link.className = 'bookmarksLink_'+bookmarksWindow.outerDiv.style.display
    
    return
  }
  
  var q=new Object
  q.id="bookmarkMenuDiv"
  var qq=""
  qq += '  '
  qq += ' <a class="edit" href="#" onclick=\'wzOpenWindow("ua_usermenu");return false;\'><img src="http://es.teamwiki.net/docs/icons/configure_shortcuts.png" title="Bearbeiten" /> '
  qq += ' Bearbeiten</a> '
  qq += 'Bookmarks ...'
  //qq += ' <img src="http://static.teamwiki.net/img/icons/tango/16x16/apps/help-browser.png" title="Hilfe" onclick="location=\'http://secure.teamwiki.net/accout/qmenu/?info=1\'" /> '
  //qq += ' <img src="http://es.teamwiki.net/docs/icon24/stock_calc-cancel.png" title="Schließen" onclick="bookmarksMenu_hide();" /> '
  qq += '  '
  q.title=qq
  q.left=600//findPosY(link)+18
  q.top=60
  q.width=280
  q.height=400
  q.hideOnClose=true
  bookmarksWindow=domWin_create(q)   // ...domWindow erzeugen
  /*
  var div = document.createElement('DIV');
  div.id = 'bookmarkMenuDiv';
  /*addEvent(div, 'mouseover', bookmarksMenuOver);
  addEvent(div, 'mouseout', bookmarksMenuOut);
  addEvent(div, 'mouseout', bookmarksMenuOut);* /
  div.innerHTML = "<strong>Loading ...</strong>";
  div.style.top=(findPosY(link)+18)+"px"
  document.body.appendChild(div);
  */
  bookmarksWindow.viewer.innerHTML = "<strong>Loading ...</strong>";
  //div.style.top=(findPosY(link)+18)+"px"
  //document.body.appendChild(div);
  

  
  var url="http://teamwiki.net/php/searchservice.php?"
  url = url + "&m="  + "get_usermenu"
  url = url + "&jscallback=" + "jsRequest_bookmarksMenu";
  
  link.className = 'bookmarksLink_block';
  
  // prompt("url", url)
  jsRequest_callService(url)
}
window.jsRequest_bookmarksMenu = function(HEADER, CONTENT) {
  //var div=findById("bookmarkMenuDiv");
  
  var qq = '';
  
  var menu = CONTENT.menu;
  for (var i in menu) {
    var it = menu[i];
    var txt = specialUnmask(it.text); var url = specialUnmask(it.url); 
    var color=""
    if (it.indent == 0) {
      if (txt.substr(0,1)=="#") { color="background:"+txt.substr(0,7); txt=txt.substr(7); }
      qq += "<strong class='usermenu_title' style='"+color+"'>" + txt + "</strong>";
    } else {
      qq += " <a href='" + url + "'>" + txt + "</a> ";
    }
  }
  //div.innerHTML = qq;
  bookmarksWindow.viewer.innerHTML = qq
}
/*
window.bookmarksMenuOver=function(){
  if(window.bookmarksHideTimeoutID)window.clearTimeout(bookmarksHideTimeoutID)
  showUserMenu();
}
window.bookmarksMenuOut=function(){
  bookmarksHideTimeoutID=window.setTimeout(hideBookmarksMenu, 666)
}
*/







//-->
//--> suche

window.prepareSearchResultArea = function(txt) {
  /*var pcont = findById("pagecontent");
  var col1 = findById("col1");
  var col3 = findById("col3");
  
  col1.style.display = 'none' //Randspalte entfernen
  col3.style.marginLeft = '0' //Randspalte entfernen
  pcont.style.display = 'none';
  scont.style.display = 'block';*/
  document.body.className = 'searchresultsview';
  var scont = findById("extracontent");
  scont.innerHTML = txt;
}

window.closeSearchArea = function() {
  document.body.className = '';
}
window.startSuche = function(such, user, offset, targetID) {
  suchStartTime=new Date();
  if(!isNaN(parseInt(such))) {location.href="http://teamwiki.net/index.php?p="+such;return;}
  if (!targetID) {  //zum direkteinbinden in eine Seite
    var qq = "";
    qq += "<img src='http://static.teamwiki.net/img/icons/darkglass_kview.png' style='float:left;margin-right:20px;' alt='Suche' />" + "\n"
    qq += "<a style='float:right' href='#' onclick='closeSearchArea();'>Suchergebnisse schließen</a>" + "\n"
    if (such == '') {
      qq += "<h2>Letzte Änderungen</h2>" + "\n"
    } else {
      qq += "<h3>Suchergebnisse für '"+such+"'</h3>" + "\n"
    }
    qq += "<br />" + "\n"
    qq += "<div id='searchresults'>E I L E &nbsp; M I T &nbsp; W E I L E -- Suche wird ausgeführt ...</div>" + "\n"
    
    prepareSearchResultArea(qq);
    
    location.hash = "such&"+such+"&"+user+"&"+offset
    
    targetID = "searchresults"
  }
  
  //alert("such:"+such)
  var url="http://teamwiki.net/php/searchservice.php?" 
  url = url + "&targetId=" + targetID
  url = url + "&m="  + "search"
  url = url + "&s="  + such
  url = url + "&user="  + user
  url = url + "&offset="  + offset
  url = url + "&jscallback=" + "jsRequest_searchDone";
  
  // prompt("url", url)
  jsRequest_callService(url)
  
}

window.jsRequest_searchDone = function(HEADER, CONTENT) {
  var res = CONTENT.searchres;
  var count = CONTENT.cnt;
  var offset = parseInt(HEADER.p_offset);
  var q = "";
  
  var targetID = specialUnmask(HEADER.p_targetId)
  
  var intLimit = parseInt(CONTENT.limit);
  
  // Anzahl Treffer + benötigte zeit
  var time = new Date() - suchStartTime;
  q += "<p><b>Anzahl Treffer:</b> "+ CONTENT.cnt +" gefunden in "+ (time/1000) +" sek <br />";
  
  if (targetID=="searchresults") {
    //Suchbereich ausgeben
    if (HEADER.p_user=="") {
      q += "<b>Suchbereich:</b> alle Benutzer/Teams</p>";
    } else {
      q += "<b>Suchbereich:</b> User '"+HEADER.p_user+"' <a href='#' onclick='startSuche(\""+HEADER.p_s+"\", \"\", 0);return false;'>[x]</a></p>";
    }
  }
  
  // Seitenzahlen
  var qSeiten = "";
  qSeiten += "<p><b>Seiten</b>  "
  var pagecount = Math.ceil(count / intLimit); // ceil = aufrunden
  for (var i=0; i<pagecount; i++) {
    if (i>20) { qSeiten += " | ...<br /><b>Zu viele Treffer</b> -- bitte Suche weiter eingrenzen ..."; break; }
    
    //var upper = Math.min(i*20+19, count);
    // wie mache ich diese Zeile besser ???
    qSeiten += '| <a href="#" onclick="startSuche(\''+HEADER.p_s+'\', \''+HEADER.p_user+'\', '+i*intLimit+', \''+targetID+'\');return false;">'
    //q += i*20 + ' - ' + upper + '</a>]  ';
    if (i*intLimit == offset) qSeiten += '<span class="highlight">' + (i+1) + '</span></a>  ';
    else  qSeiten += (i+1) + '</a>  ';
    
  }
  q += qSeiten + "</p>";
  q += "<br><table style='width:100%;'>";
  q += "<tr><th>Nr.</th><th>User</th><th>Title</th><th>Tags</th> "
  q += "<th>Geändert am | von</th><th>Art der Änderung</th></tr>";
  
  var dat;
  for(var i in res) {
    dat = res[i];
    var url = "http://" + dat.user + ".teamwiki.net" + specialUnmask(dat.filespec);
    if (dat.pagetype == 5) url = "http://" + dat.user + ".teamwiki.net/blog/?navItemID=" + dat.id
    var title = specialUnmask(dat.title);
    //if (!title) title = "[kein Titel vorhanden "+dat.id + "]"
    q += "<tr onclick='location.href=\"" + url + "\"'>";
    q += "<th title='" + dat.id + "'>" + (offset+parseInt(i)+1) + ".</th>"
    q += "<td>" + dat.user + ":</td>"
    q += "<td><a href='" + url + "'>" + title + "</a></td>";
    q += "<td><small>" + specialUnmask(dat.keywords) + "</small></td>";
    q += "<td><small>" + format_mysqldate(dat.lastmodified) + " ";
    q += " ~" + dat.lastmodified_by + "</small></td>"
    var thru = dat.lastmodified_thru
    q += "<td class='lmthru-"+thru+"'>"
    q += "<img src='" + getChangeTypeIcon(thru) + "' alt='typ' title='EDIT_THRU: "+thru+"' /> "
    q += " "+ specialUnmask(dat.lastmodified_text) + "</td>"
    q += "</tr>";
  }
  q += "</table>";
  
  q += "<p>" + qSeiten + "</p>";
  
  //q += "<pre>";
  //q += specialUnmask(CONTENT.q1) + "\n\n\n";
  //q += specialUnmask(CONTENT.q2);
  //q += "</pre>";
  
  var div = findById(targetID);
  div.innerHTML = q;
  
  
  
}


window.format_mysqldate = function(mysqldate) {
	// example mysql date: 2008-01-27 20:41:25
	// we need to replace the dashes with slashes
	var date = String(mysqldate).replace(/\-/g, '/');
	return format_date(date);
}
window.format_date = function(date) {
	// date can be in msec or in a format recognized by Date.parse()
	var d = new Date(date); 
	
	var days_of_week = Array('So','Mo','Di','Mi','Do','Fr','Sa');
	var day_of_week = days_of_week[d.getDay()];
	
	//var year = d.getFullYear();
	var months = Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
	var month = months[d.getMonth()];
	//var day = d.getDate();
	
	var hour = d.getHours();
	var minute = d.getMinutes();
/*var am_pm = 'am';

	if(hour == 0) { 
		hour = 12; 
	} else if (hour == 12) { 
		am_pm = 'pm'; 
	} else if (hour > 12) { 
		hour -= 12; 
		am_pm = 'pm';
	}*/
	if(minute < 10) { minute = "0"+minute; }
	if(hour < 10) { hour = "0"+hour; }
	
	//var date_formatted = day_of_week+' '+month+' '+day+' '+year+' '+hour+':'+minute+am_pm;
	var date_formatted = day_of_week+' '+hour+':'+minute;
	return date_formatted;
}



window.jumpUser = function(such) {
  
  //alert("such:"+such)
  var url="http://teamwiki.net/php/searchservice.php?" 
  url = url + "&targetId=searchresults"
  url = url + "&m="  + "jump_user"
  url = url + "&s="  + such
  url = url + "&jscallback=" + "jsRequest_jumpUserFound";
  
  // prompt("url", url)
  jsRequest_callService(url)
  
}

window.jsRequest_jumpUserFound = function(HEADER,CONTENT) {
  var box = findById("searchinput");
  box.blur();
  
  if (CONTENT.count == 0) {
    alert("keine User gefunden!");
    return
  }
  
  if (CONTENT.count == 1) {
    if (confirm("navigiere zu user "+ CONTENT.res[0].username +" ?")==false) return
    location.href = 'http://' + CONTENT.res[0].username + '.teamwiki.net'
    return
  }
  
  var qq = "";
  qq += "<img src='http://static.teamwiki.net/img/icons/search_user.png' style='float:left;margin-right:20px;' alt='Suche' />"
  qq += "<br /><a style='float:right' href='#' onclick='closeSearchArea();'>Suchergebnisse schließen</a>" + "\n"
  qq += '<h3>UserQuickJump -- mehrere Möglichkeiten gefunden für "' + HEADER.p_s + '"</h3>'
  qq += "<br />"
  qq += "<div id='searchresults'>";
  qq += "<table>";
  qq += "<tr><th>nr</th><th>Username</th><th>Fullname</th></tr>";
  for(var i in CONTENT.res) {
    var url = 'http://' + CONTENT.res[i].username + '.teamwiki.net'
    qq += "<tr>";
    qq += "<td>"+CONTENT.res[i].id+"</td>";
    qq += "<td><a href='"+url+"'>"+CONTENT.res[i].username+"</a></td>";
    qq += "<td>"+CONTENT.res[i].fullname+"</td>";
    
    qq += "</tr>";
  }
  
  qq += "</table>";
  qq += "</div>";
  
  prepareSearchResultArea(qq);
  
}

window.getChangeTypeIcon=function(typ) {
  switch(typ) {
    case '10': return "http://static.teamwiki.net/img/icons/tango/16x16/apps/accessories-text-editor.png";
    case '11': return "http://static.teamwiki.net/img/icons/tango/16x16/actions/document-new.png";
    case '12': return "http://static.teamwiki.net/img/icons/rename.png";
    case '13': return "http://static.teamwiki.net/img/icons/plain_ext/16-16/file-remove-16.png";
    case '20': return "http://static.teamwiki.net/img/icons/tango/16x16/apps/internet-group-chat.png";
    case '21': return "http://static.teamwiki.net/img/icons/tango/16x16/actions/list-add.png";
    case '23': return "http://static.teamwiki.net/img/icons/tango/16x16/actions/edit-delete.png";
    
  }
  
  return "http://static.teamwiki.net/img/icons/tango/16x16/apps/help-browser.png";
  
}

window.onSearchBoxKeydown = function(e) {
  if (e.keyCode == 13) {
    //if(!window.qqTW.login.username) { alert('...nur für eingeloggte User!'); return; }
    var box = findById("searchinput");
    var such = box.value;
    if (such == '?') {
      location.href = 'http://devnet.teamwiki.net/suchbox_help.html';
    } else if (such.substring(0,1) == '.') {
      jumpUser(such.substring(1));
      
    } else if (such.substring(0,2) == 'g ') {
      location.href='http://www.google.de/search?q='+such.substring(2);
      
    } else if (such.substring(0,1) == '#') {
      startSuche(such.substring(1), window.qqTW.pageInfo["user"], "0");
      
    } else if (e.ctrlKey) {
      startSuche(such, window.qqTW.pageInfo["user"], "0");
      
    } else {
      startSuche(such, "", "0");
    }
  }
  
}
/*
window.onEditMenuButtonClick = function(e) {
  if (e.button == 2) {
    cancelEvent(e);
    location.href = "http://secure.teamwiki.net/page_rights.t?s_u=" + qqTW.pageInfo.user;
    return false;
  } else {
    editMenu();
  }
}*/






//-->
//--> iFrameWindow

window.iFrameWindow_show = function(url,bg) {
  if (!findById('iFrameWindow')) iFrameWindow_create();
  
  if (!url) url = "http://secure.teamwiki.net/SignIn?check_cookie=1";
  findById('iFrameWindow_if').src = url;
  if (bg) {
    var s=findById('iFrameWindow').style;
		s.background="transparent url(http://mw.teamwiki.net/docs/img/popup_bg_lso.png) no-repeat";
    s.padding = '30px';
    s.width = '385px'; s.height = '300px';
  }
	if (bg==2) {
    var s=findById('iFrameWindow').style;
		s.background="transparent";
    s.padding = '0px';
    s.width = '445px'; s.height = '360px';
  }
  
  findById('iFrameWindow').style.display = "block";
  findById('iFrameWindow_dim').style.display = "block";
  findById('iFrameWindow_close').style.display = "block";
}

window.iFrameWindow_create = function() {
  var greyoutBox = document.createElement("div");
  var s = greyoutBox.style; greyoutBox.id = 'iFrameWindow_dim';
  s.backgroundColor = '#000'; s.MozOpacity = '0.7'; s.opacity = '0.7'; s.filter = 'alpha(opacity = 70)';
  s.position = getPosFixed();
  s.left = '0'; s.top = '0';
  s.width = '100%'; s.height = '100%';
  //greyoutBox.onclick = iFrameWindow_hide;
  document.body.appendChild(greyoutBox);
  
  var innerXX=getInnerWidth()
  var innerYY=getInnerHeight()
  
  
  var iframeBox = document.createElement("div");
  var s = iframeBox.style; iframeBox.id = 'iFrameWindow';
  s.backgroundColor = '#99f'; s.MozOpacity = '0.9';
  s.position = getPosFixed();
  s.width = '430px'; s.height = '320px';
  s.left = (innerXX/2-405/2)+"px";
  s.top = (innerYY/2-320/2)+"px";
  iframeBox.innerHTML = '<iframe src="" id="iFrameWindow_if" scrolling="no" FRAMEBORDER="no" style="overflow:hidden;height:100%;width:100%;border-width:0px;background:transparent;"></iframe>';
  document.body.appendChild(iframeBox);
  
  var closeBox = document.createElement("img");
  closeBox.src = "http://static.teamwiki.net/img/icons/tango/22x22/emblems/emblem-unreadable.png";
  //closeBox.innerHTML = '&nbsp; [ x ]';
  closeBox.id = "iFrameWindow_close"
  var s = closeBox.style;
  s.position=getPosFixed();
  s.color='white';
  s.left=(innerXX/2+199)+"px";
  s.top=(innerYY/2-144)+"px";
  closeBox.onclick = iFrameWindow_hide;
  document.body.appendChild(closeBox);
}

window.iFrameWindow_hide = function() {
  findById('iFrameWindow').style.display = "none";
  findById('iFrameWindow_dim').style.display = "none";
  findById('iFrameWindow_close').style.display = "none";
}


//http://yura.thinkweb2.com/cft/#IS_POSITION_FIXED_SUPPORTED
function isPositionFixedSupported(){
  if(window.c_isPositionFixedSupported)return window.v_isPositionFixedSupported;
  var isSupported = null;
  if (document.createElement) {
    var el = document.createElement('div');
    if (el && el.style) {
      el.style.position = 'fixed';
      el.style.top = '10px';
      var root = document.body;
      if (root && 
          root.appendChild && 
          root.removeChild) {
        root.appendChild(el);
        isSupported = (el.offsetTop === 10);
        root.removeChild(el);
      }
    }
  }
  window.c_isPositionFixedSupported=true;window.v_isPositionFixedSupported=isSupported;
  return isSupported;
}
function getPosFixed() {
  return isPositionFixedSupported()?"fixed":"absolute";
}




//-->
//--> countDown



function initCountDown(id){
  var Jetzt = new Date();
  var Countdown = new Date($("#"+id).attr("countdowntargetdate"));//CountdownJahr, CountdownMonat-1, CountdownTag, CountdownStunde, CountdownMinute, CountdownSekunde);
  var MillisekundenBisCountdown = Countdown.getTime()-Jetzt.getTime();
  var Rest = Math.floor(MillisekundenBisCountdown/1000);
  var CountdownText = "";

  // Jahre sollen nicht getrennt ausgegeben werden
  // if(Rest >= 31536000) {
  //   var Jahre = Math.floor(Rest/31536000);
  //   Rest = Rest-Jahre*31536000;
  //   if(Jahre > 1 || Jahre == 0){
  //     CountdownText += Jahre + " Jahre ";
  //   }else if(Jahre == 1){
  //      CountdownText += Jahre + " Jahr ";
  //   }
  // }

  var Tage = Math.floor(Rest/86400);
  var Rest2 = Rest-Tage*86400;
  var Stunden = Math.floor(Rest2/3600);
  var Rest2 = Rest2-Stunden*3600;
  var Minuten = Math.floor(Rest2/60);
  var Sekunden = Rest2-Minuten*60;

  if(Rest >= 86400*2) {  
    countdown_refresh(id,Tage,"Tage")
    return
  }

  if(Rest >= 3600){
    var Stunden = Math.floor(Rest/3600);
    Rest = Rest-Stunden*3600;
    var Minuten = Math.floor(Rest/60);
    if(Stunden > 1 || Stunden == 0){
      countdown_refresh(id,Stunden + ":" + formatNumber(Minuten), "Stunden ["+formatNumber(Sekunden)+"]")
      return 
    }else if(Stunden == 1){
      countdown_refresh(id,Stunden + ":" + formatNumber(Minuten), "Stunde ["+formatNumber(Sekunden)+"]")
      return 
    }
  }

  if(Rest >= 0){
    var Minuten = Math.floor(Rest/60);
    Rest = Rest-Minuten*60;
    if(Minuten > 1) {
      countdown_refresh(id,formatNumber(Minuten) + ":" + formatNumber(Rest), "Minuten")
      return 
    }else if(Minuten == 1){
      countdown_refresh(id,formatNumber(Minuten) + ":" + formatNumber(Rest), "Minute")
      return 
    }else if(Minuten == 0){
       countdown_refresh(id,formatNumber(Minuten) + ":" + formatNumber(Rest), "Sekunden")
      return 
    }
  }
  // ZielDatum erreicht...
  countdown_refresh(id,"OK" , "", "clear")
}//endFunction


window.countdown_refresh=function(id,timeBig,label,preLabel){
  $("#"+id+" .countdown_number").html(timeBig);
  $("#"+id+" .countdown_label").html(label);
  if (preLabel)$("#"+id+" .countdown_preLabel").html();
  window.setTimeout(initCountDown, 1000, id);
  // CountdownAnzeigen()
}//endFunction


window.formatNumber=function(para){
  var result=para.toString(); 
  if (result.length == 1) result="0"+result
  return result
}//endFunction







//-->
//--> Aktionen ...

var el
el = findById("searchinput")
if (el) {
  addEvent(el, "keydown", onSearchBoxKeydown);
  el.value = "suche ..."
}
/*
el = findById("edit_menu_button")
if (el) {
  addEvent(el, "mouseup", onEditMenuButtonClick);
}*/

if (location.hash && location.hash.substr(0,6)=='#such&') {
  var parts = location.hash.split('&');
  startSuche(parts[1], parts[2], parts[3]);
}

if (window.qqTW.mainHostLoggedin == true && window.qqTW.login.username == "") {
  var url="http://teamwiki.net/php/labs/session_transfer.php?host="+location.host+"&return_to="+escape(location.href);
  var frm = document.createElement("IFRAME");
  frm.src=url
  document.body.appendChild(frm)
  //location.href=url;
}


//Overlays aktivieren

$("img[rel]").overlay({mask: '#000',effect:"apple"});

//tWiki_loadScriptOnDemand("http://static.teamwiki.net/js/domWin2.js")



