function Is() {
         var  agent     = navigator.userAgent.toLowerCase();
         this.agent     = agent;
         this.version   = parseInt(navigator.appVersion);
         this.versExact = parseFloat(navigator.appVersion);
         this.opera     = agent.indexOf('opera')!= -1;
         this.opera5    = agent.indexOf('opera 5')!= -1;
         this.opera4    = this.opera && this.version == 4 && !this.opera5;
         this.ns        = agent.indexOf('mozilla')!= -1 &&
                          agent.indexOf('spoofer')== -1 &&
                          agent.indexOf('compatible')== -1 &&
                          !this.opera;
         this.ns4       = this.ns && this.version >= 4 && this.version < 5 && !(this.versExact < 4.08);
         this.ns5up     = this.ns && this.version >= 5;
         this.ns4up     = this.ns4 || this.ns5up;
         this.ie        = agent.indexOf("msie") != -1 && agent.indexOf("mac") < 0 && !this.opera;
         this.ie4up     = this.ie && this.version >= 4;
         this.ie55      = this.ie4up && agent.indexOf('msie 5.5') != -1;
         this.ie6       = this.ie4up && agent.indexOf('msie 6.0') != -1;
         this.ie7		= this.ie4up && agent.indexOf('msie 7.0') != -1;
         this.ie6up		= this.ie6 || this.ie7;
         this.ie55up    = this.ie55 || this.ie6up;
         this.ie5       = this.ie4up && agent.indexOf('msie 5') != -1 && !this.ie55;
         this.ie4       = this.ie4up && !this.ie5 && !this.ie55;
         this.w3c       = document.documentElement;
         this.dhtml     = (this.ie4up || this.ns4up || this.w3c) && agent.indexOf("aol") < 0;
}
is = new Is();

function addDeepLinkToFavorites(link) {
    if (is.ie55up) {
        var completeLink = 'http://'+ window.location.host +'/'+ link;
        try {
            window.external.addFavorite(completeLink, link);
        } catch (exception) {
                alert("Browser-Version unterstuetzt diese Funktion nicht");
        }
    }
}

var mouseX = -500;
var mouseY = -500;
var infoOffsetX = 5;
var infoOffsetY = 7;
function handlerMouseMove(e) {
        mouseX = e ? is.opera ? e.clientX
                              : e.pageX
                   : (is.ie6up ? document.documentElement.scrollLeft
                               : document.body.scrollLeft) +
                     event.clientX;
        mouseY = e ? is.opera ? e.clientY
                              : e.pageY
                   : (is.ie6up ? document.documentElement.scrollTop
                               : document.body.scrollTop) +
                     event.clientY;
        flag = 1;
        if (on) moveToMousePosSmart("infoX", infoOffsetX, infoOffsetY);
}
if (document.captureEvents) document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = handlerMouseMove;

function getObject(id, parentID) {
    if ((is.w3c || is.opera5) && document.getElementById(eval("'" + id + "'")))
        return document.getElementById(id);
    if (is.ie4up && document.all[id]) {
        if (typeof document.all[id] == 'undefined')
            return null;
        return document.all[id];
    }
    if (is.ns4) {
        if (parentID && document.layers[parentID] && document.layers[parentID].document.layers[id])
            return document.layers[parentID].document.layers[id];
        if (document.layers[id])
            return document.layers[id];
    }
    return null;
}

function getStyleObject(id, parentID) {
    if ((is.ie4up || is.w3c || is.opera5) && getObject(id))
        return getObject(id).style;
    if (is.ns4)
        return getObject(id, parentID);
    return null;
}

function switchLayer(id, visibility, parentID) {
    if (getStyleObject(id, parentID))
        getStyleObject(id, parentID).visibility = (visibility ? "visible" : "hidden");
}

function toggle(id, imgName, imgOpen, imgClose) {
    if (getStyleObject(id)) {
        var display = null;
        if (getStyleObject(id).display == "none") {
            display = "";//"inline";
            swap(imgName, imgClose);
        } else {                                             
            display = "none";
            swap(imgName, imgOpen);
        }
        getStyleObject(id).display = display;
    }
}

function moveTo(id, x, y, parentID) {
    if (y != null && getStyleObject(id, parentID))
        is.opera5 ? getStyleObject(id).pixelTop = y
                  : getStyleObject(id, parentID).top  = is.ns4
                        ? y
                        : y + "px";
    if (x != null && getStyleObject(id, parentID))
        is.opera5 ? getStyleObject(id).pixelLeft = x
                  : getStyleObject(id, parentID).left = is.ns4
                        ? x
                        : x + "px";
}

function moveToMousePos(id, offsetX, offsetY, parentID) {
    moveTo(id, mouseX + offsetX, mouseY + offsetY, parentID);
}

function moveToMousePosSmart(id, offsetX, offsetY, parentID) {
    var height    = getHeight(id, parentID);
    var width     = getWidth(id, parentID);
    var winWidth  = getWindowWidth();
    var winHeight = getWindowHeight();
    x = mouseX + width + offsetX >= winWidth - 9 ? width * 2 < winWidth ? winWidth -width -21 -mouseX
                                                                        : winWidth -width -5 -mouseX
                                                 : offsetX;
    y = mouseY - height < 1 ? height * 2 > winHeight ? offsetY -mouseY
                                                     : offsetY
                            : -height -offsetY;

    moveToMousePos(id, x, y, parentID);
}

function moveToRightBorder(id, offsetX, parentID) {
    if (getStyleObject(id, parentID))
        getStyleObject(id, parentID).left  = getWindowWidth(window) - offsetX - getWidth(id);
}

function setContent(text, id, parentID) {
    if (is.ns4 && getObject(id, parentID)) {
        getObject(id, parentID).document.open();
        getObject(id, parentID).document.write(text);
        getObject(id, parentID).document.close();
    }
    else
        getObject(id).innerHTML = text;
}

function getHeight(id, parentID) {
    return getObject(id, parentID)
               ? is.opera
                     ? getStyleObject(id).pixelHeight
                     : is.ns4 ? getObject(id, parentID).clip.height
                              : getObject(id).offsetHeight
               : 0;
}

function getWidth(id, parentID) {
    return getObject(id, parentID)
               ? is.opera
                     ? getStyleObject(id).pixelWidth
                     : is.ns4 ? getObject(id, parentID).clip.width
                              : getObject(id).offsetWidth
               : 0;
}

function killMouseDown(id, parentID) {
    if (getObject(id, parentID)) {
        if (getObject(id, parentID).captureEvents)
            getObject(id, parentID).captureEvents(Event.MOUSEDOWN);

        getObject(id, parentID).onmousedown = function (e) {
            if (is.ie4up)
                event.cancelBubble = true;
            if (e && !is.ns4)
                e.stopPropagation();
            return true;
        };
    }
}

var infoInited      = false;
var infoOn          = false;
function initInfoX() {
    if (is.dhtml) {
        document.write('<div id="infoX" class="infoX" style="position: absolute; top:0px; left:0px; visibility: hidden; z-index: 999;"></div>');
        setTimeout("infoInited = true", 60);
    }
}
var on = false;
function showInfo(text, delay, imgName, imgSrc, imgName2, imgSrc2, parentLayerID, offsetX, offsetY, noAutoOff) {
    if (imgName && imgName.length > 0) {
            hover(imgName, imgSrc);
    }
    if (!delay) delay = 123;
    window.status = is.dhtml ? text.replace(/<[br]*[li]*>/g,"   ").replace(/<[^>]*>/g,"") : text;
    if (is.dhtml && !is.opera && getStyleObject("infoX")) {
        var width = text.length < 16
                        ? 60
                        : text.length < 77
                              ? 123
                              : 234;
        if (width > getWindowWidth())
            width = getWindowWidth() - 5;
        getStyleObject("infoX").width = width + 'px';
        if (is.ns4) text = text.replace(/<.?b>/g,"");
        setContent(text, "infoX");

        on = true;
        if (!offsetX) offsetX = 7;
        if (!offsetY) offsetY = 5;
        infoOffsetX = offsetX;
        infoOffsetY = offsetY;
        moveToMousePosSmart("infoX", offsetX, offsetY);
        infoOn  = setTimeout("switchLayer('infoX', 1)", delay);
        infoOff = setTimeout("switchLayer('infoX', 0)", noAutoOff ? 99999 : (1800 + delay));
    }
}

function hideInfo(imgName, imgSrc, imgName2, imgSrc2, parentLayerID) {
    if (imgName && imgName.length > 0) {
            off(imgName, imgSrc);
    }
    window.status = '';
    if (infoOn && !is.opera) {
        clearTimeout(infoOn);
        clearTimeout(infoOff);
        setTimeout("switchLayer('infoX', 0)", 99);
        on = false;
    }
}

function showLexiTip(text) {
    showInfo(text, 123, "", "", "", "", "", 7, 5, true);
}

function hideLexiTip() {
    hideInfo();
}

function swap(img, imgSrc) {
   if (document[img] != null) {  
       document[img].src = eval( imgSrc + '.src' );
   } else if (img.src != null) {  
       img.src = eval( imgSrc + '.src' );
   } 
}

function preload() {
    var imgs = preload.arguments;
    if (imgs == null || imgs < 1) {
        return;
    }
    if (document.images) {
       for (i = 0; i < imgs.length; i++) {
           var dot = imgs[i].lastIndexOf(".");
           if (dot > -1) {
               eval("img" + i + "= new Image();"   + "img" + i + ".src ='"  + imgs[i] + "'");
               if (imgs[i].indexOf('<%= BasePortlet.ICON_OPEN %>')  > -1
                   ||
                   imgs[i].indexOf('<%= BasePortlet.ICON_CLOSE %>') > -1 )
               {
                   continue;
               }
               var hover = imgs[i].substring(0, dot) + "_hover" + imgs[i].substring(dot, imgs[i].length);
               eval("img" + i + "_ = new Image();" + "img" + i + "_.src ='" + hover   + "'");
           }
       }
    }
}

function hover(imgName, imgSrc) {
   if (document.images && document[imgName]) {
              document[imgName].src = eval( imgSrc + '_hover.src' );
   }
}

function off(imgName, imgSrc) {
   if (document.images && document[imgName]) {
      document[imgName].src = eval( imgSrc + '.src' );
   }
}

shopWindow = top;
shopWindow.name = "shopWindow";

var helpWindow = null;
function getHelpWindow(url) {
    if (!helpWindow || helpWindow.closed) {
        helpWinFormat = "width=600,height=600,toolbar=no,location=no,scrollbars=yes,status=0,resizable=yes,left=5,top=5,screenX=5,screenY=5";
        helpWindow = window.open(url, "helpWindow", helpWinFormat);
    }
    if (helpWindow) helpWindow.focus();
}

function getWindowWidth(fenster) {
    if (!fenster) fenster = self;

    if (is.ns4 || is.ns5up || is.opera)
        return fenster.innerWidth;
    if (is.ie4up)
        return fenster.document.body.clientWidth;
    return 800;
}

function getWindowHeight(fenster) {
    if (!fenster) fenster = self;

    if (is.ns4 || is.ns5up || is.opera)
        return fenster.innerHeight;
    if (is.ie4up)
        return fenster.document.body.clientHeight;
    return 600;
}

function getShopWindowWidth() {
    return getWindowWidth(shopWindow);
}

function getShopWindowHeight() {
    return getWindowHeight(shopWindow);
}

function submitForm(name) {
    eval('document.' + name + '.submit()');
}

var win=null;
function NewWindow(mypage,myname,w,h,pos,infocus){
if(pos=="random"){myleft=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;mytop=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
if(pos=="center"){myleft=(screen.width)?(screen.width-w)/2:100;mytop=(screen.height)?(screen.height-h)/2:100;}
else if((pos!='center' && pos!="random") || pos==null){myleft=0;mytop=20;}
settings="width=" + w + ",height=" + h + ",top=" + mytop + ",left=" + myleft + ",scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no";win=window.open(mypage,myname,settings);
win.focus();
}

var win=null;
function NewWindowScroll(mypage,myname,w,h,pos,infocus){
if(pos=="random"){myleft=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;mytop=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
if(pos=="center"){myleft=(screen.width)?(screen.width-w)/2:100;mytop=(screen.height)?(screen.height-h)/2:100;}
else if((pos!='center' && pos!="random") || pos==null){myleft=0;mytop=20;}
settings="width=" + w + ",height=" + h + ",top=" + mytop + ",left=" + myleft + ",scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no";win=window.open(mypage,myname,settings);
win.focus();
}
function objProp(Objekt) {
   oe = window.open('','oe','height=250,width=160,screenX=5,screenY=5,scrollbars=yes,resizable=yes');
   oe.moveTo(5, 5);
   oe.document.open();
   for (Eigenschaft in Objekt) {
       oe.document.write(Eigenschaft + "::" + Objekt[Eigenschaft] + "<br>");
   }
   oe.document.close();
   oe.focus();
}

var tw = null;
function trace(txt) {
   if (!tw || tw.closed) tw = window.open('','tw','height=500,width=160,screenX=5,screenY=5,scrollbars=yes,resizable=yes');
   tw.moveTo(5, 5);
   tw.document.write(txt + '<br>');
   tw.focus();
}


/*Script zur random div class="randomcontent div1,div2,..."*/
if (document.getElementById)
document.documentElement.className = 'jsclass'; 
var randomcontentdisplay={
                        divholders:new Object(),
                        masterclass: "randomcontent",
						init:function(){
			                if (!document.getElementById)
							return
                            var alldivs=document.getElementsByTagName("div");
							var randomcontentsearch=new RegExp(this.masterclass+"\\s+(div\\d+)", "i");
                            for (var i=0; i<alldivs.length; i++){
	                            if (randomcontentsearch.test(alldivs[i].className)){
 	                               	if (typeof this.divholders[RegExp.$1]=="undefined")
	                               	this.divholders[RegExp.$1]=new Array();
									this.divholders[RegExp.$1].push(alldivs[i]); 
                                }
                        }
                        this.showone();
                        },
                        showone:function(){
	                        for (div in this.divholders){ 
    	                        var chosenOne=Math.floor(Math.random()*this.divholders[div].length); 
	                            this.divholders[div][chosenOne].style.display="block";
                        	}
						}
};


// Asynchroner Ajax Aufruf der eine url holt und 
// das Ergebnis entscheidet darüber ob die
// DIVs sichtbar werden.
function setDisplayByAjaxcall(url, divs) {
    var xmlhttp;
    if (window.XMLHttpRequest) {
        // code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        // code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function() {
      if(xmlhttp.readyState==4) {
    	  var display = xmlhttp.responseText;
		  for (var i = 0; i < divs.length; ++i){
    	  	  document.getElementById(divs[i]).style.display = display;
    	  }
      }
    };
    xmlhttp.open("GET", url, true);
    xmlhttp.send(null);
}

function printAjaxResponse(url, elementId){
	var xmlhttp;
    if (window.XMLHttpRequest) {
        // code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        // code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function() {
      if(xmlhttp.readyState==4) {
    	  //schreibe die antwort in den container mit der id
    	  var resp = xmlhttp.responseText;
     	  document.getElementById(elementId).innerHtml=resp;
      }
    };
    xmlhttp.open("GET", url, true);
    xmlhttp.send(null);
}


function ajaxCall(url, value){
	var xmlhttp;
    if (window.XMLHttpRequest) {
        // code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        // code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.open("GET", url + value, true);
    xmlhttp.send(null);
}

function showDialog(url, title) {
    var elem = jQuery('<div><img src="/images/loading.gif"/></div>');
    elem.dialog({
        bgiframe : true,
        autoOpen : false,
        resizable : false,
        width : 560,
        modal : true
    });
    elem.dialog("option", "title", title);
    elem.dialog("open");
    elem.load(url);
    /**jQuery.get(url , function(data) {
        elem.html(data);
        elem.dialog({
            bgiframe : true,
            autoOpen : false,
            resizable : true,
            width : 560,
            modal : true
        });
        elem.dialog("option", "title", title);
        elem.dialog("open");
    });**/
}


