//Ajax zur Automatischen Verlinkunk der Docs
function getDocFinder(link,docname,area,lang) {
         new Ajax.Request('php/ajax/get_docresult.php',
            {
              'parameters':{
                'docname':docname,
                'area':area,
                'lang':lang
              },
              'method':'get',
              'onComplete':function(t){
                if ( (t.responseText=='0') || (t.responseText=='1') ) {
                     document.location.href=link.href;
                   } else {
                     var linkPos = $(link).cumulativeOffset();
                     $('doclinks_popup').innerHTML = t.responseText;
                     $('doclinks_popup').setStyle({
                       display: 'block',
                       left: linkPos[0]+'px',
                       top: (linkPos[1]+15)+'px'
                     });
                   }
              }
            }
         );
}

function isDescendantOf(needle, haystack) {
    var found = false;
    $(haystack).descendants().each( function (descendant) {
        if (descendant == needle) {
            found = true;
            throw $break;
        }
    });
    return found;
}

Event.observe(window,'load',function (){
    if (!$('doclinks_popup')) {
        return;
    }

    Event.observe('doclinks_popup','mouseout',function(e){
        if (!$('doclinks_popup') || !$(e.relatedTarget || event.toElement)) { // fix ie6 bug when returning from opening new window from tooltip
            return;
        }
        
        if ($(e.relatedTarget || event.toElement) == $('doclinks_popup')) {
            return;
        }

        if ( isDescendantOf($(e.relatedTarget || event.toElement), $('doclinks_popup') )) {
            return;
        }

        $('doclinks_popup').setStyle({display: 'none'});
    })
});

//Default
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}


function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
      d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
    }
  if(!(x=d[n])&&d.all) x=d.all[n];
  for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}


function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments;

  document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
  if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


//textScroll
var currentTextPosition = 0;
var stepTextPosition = 367;


function TextMoveTop() {
    if ((document.getElementById('textBoxInside').offsetHeight+currentTextPosition)>=stepTextPosition)
    new Effect.Move('textBoxInside', { x: 0, y: (-1*stepTextPosition), afterFinish: function(e) { currentTextPosition=currentTextPosition-stepTextPosition; }, transition: Effect.Transitions.sinoidal, queue: { position: 'end', scope: 'global', limit: 1 }});
}


function TextMoveDown() {
    if (currentTextPosition<0)
    new Effect.Move('textBoxInside', { x: 0, y: stepTextPosition, afterFinish: function(e) { currentTextPosition=currentTextPosition+stepTextPosition; }, transition: Effect.Transitions.sinoidal, queue: { position: 'end', scope: 'global', limit: 1 }});
}


function TextMove(direction, evt) {
    if (direction=='top')
        TextMoveTop();
    if (direction=='down')
        TextMoveDown();
}


function OpenBrWindow(theURL,winName,w,h,features) {
    var winl = (screen.width - w) / 2;
    var wint = (screen.height - h) / 2;

    window.open(theURL,winName,'height='+h+',width='+w+',top='+wint+',left='+winl+','+features);
}


function ZeigePopup(thePicture,theTitle,w,h) {
    var winl = (screen.width - w) / 2;
    var wint = (screen.height - h) / 2;

    PicWin=window.open('','popup','height='+h+',width='+w+',top='+wint+',left='+winl+','+'scrollbars=no,resizable=no');
    PicWin.document.open();
    PicWin.document.writeln('<html>');
    PicWin.document.writeln('    <head>');
    PicWin.document.writeln('        <title>'+theTitle+'</title>');
    PicWin.document.writeln('    </head>');
    PicWin.document.writeln('    <body style="margin:0;padding:0;background-color:#fff;">');
    PicWin.document.writeln('        <img src="'+thePicture+'" />');
    PicWin.document.writeln('    </body>');
    PicWin.document.writeln('</html>');
    PicWin.document.close();
}