var g_psyma_navi_clicked = null;

// var g_timeout = -1;
var g_timeout = 1;
/* var g_timeoutTime = 80; */
var g_timeoutTime = 250; 
var g_openZoom = 0;
var g_openKnowledgeBase = 0;
var g_imageNr = 1;
var g_req;
var g_is_home = false;

var g_pageWidth = 839;
var g_initHome = false;
var g_timeoutHide1 = 0;
var g_timeoutHide2 = 0;
var g_timeoutHide3 = 0;
var g_timeoutHide4 = 0;
var g_timeoutHead = 0;
var g_currentNav1 = "";
var g_currentNav2 = "";
var g_currentNav3 = "";
var g_currentNav4 = "";

var g_currentHi1 = "";
var g_currentHi2 = "";
var g_currentHi3 = "";
var g_currentHi4 = "";

var g_blackValue = 0;
var g_blackTimeout = 0;
var g_navShadeMax = .35;

var g_currentModelLink = '';
var g_echoCount = 0;
var g_is_opera = false;
var g_is_ie = false;
var g_is_ie5 = false;
var g_is_ie5_5 = false;
var g_is_safari = false;
var g_is_mac = true;

var g_contextDebug = "";
var g_fallbackImage = "";

window.onload = function ()
{
    initAll();
};

function initAll()
{
    var sClass = "";
    if (document.body.className) {
        sClass = document.body.className;
    }
    else {
        sClass = document.body.getAttribute("class");
    }
    if (sClass != undefined) {
        g_is_home = sClass.indexOf("home") >= 1;
    }
    else {
        g_is_home = false;
    }
    
    positionFooter();    

    var noteConflict = false;
    sniffAll();
    if (document.getElementById) {
        g_canHandleTransparency = !g_is_ie5;
    }
    else if (noteConflict) {
        gotoUrl("/browser.htm");
    }
    if (g_is_home) {
        initHome();
    }

    HideIfLoggedIn("ifLoggedOut");
    ShowIfLoggedIn("ifLoggedIn");
    
    initGallerySubtitles();
}

function fitFrameFromParent(iHeight)
{
    addContextDebug("iHeight", iHeight);

    var elm = document.getElementById("mainframe");
    var footer = document.getElementById("footer");
    var search = document.getElementById("search");

    if (elm) {
        addContextDebug("enteredElm", true);
        elm.style.height = (iHeight + 40 + 140) + "px";
        if (search) { search.style.display = "none"; }
        footer.style.bottom = "-1px";
        if (search) { search.style.display = "block"; }
        addContextDebug("finishedElm", true);
    }
}

function addContextDebug(sName, sValue)
{
    g_contextDebug += sName + "=" + sValue + "\r\n";
}

function showContextDebug()
{
    if (g_contextDebug != "") {
        alert(g_contextDebug);
    }
}

function positionFooter()
{
    var footer = document.getElementById("footer");
    var search = document.getElementById("search");
    
    if (!g_is_home) setDocumentSize();

    if (footer) { footer.style.bottom = "-1px"; }
    if (search) { search.style.bottom = "-1px"; }
}

function setDocumentSize() {
	var size = 350; //160 + 105 + 85;

	var elm = document.getElementsByTagName("a");
	
	if (elm) {
		for (i = 0; i < elm.length; i++){
			var className = elm[i].className;
			
			switch (true) {
				case containsStr(className, "navigationBelowHome"):
					size += 24;
				break;
				case containsStr(className, "subNavigationChapter"):
				case containsStr(className, "subSubNavigation"):
				case containsStr(className, "subSubNavigationActive"):								
					size += 20; // 1 line: 16, 2 lines: 31;					
				break;		
			}
		}
	}		

	var elm = document.getElementsByTagName("div");
	
	if (elm) {
		for (i = 0; i < elm.length; i++){
			if (elm[i].className == "content") {
				//elm[i].style.border = "1px solid red";
				elm[i].style.minHeight = size + "px";
				elm[i].style.height = size + "px";
				break;			
			}
		}
	}
}

function containsStr(s, find) {
	return (s.indexOf(find) != -1);
}

function overHome()
{
    if (g_openKnowledgeBase == 0 && !g_is_safari) {
        if (g_timeout != -1) { clearTimeout(g_timeout); }
        showNavHomeSub();
    }
}

function outHome()
{
    if (g_openKnowledgeBase == 0 && !g_is_safari) {
        g_timeout = setTimeout("hideNavHomeSub()", g_timeoutTime);
    }
}

function overNavHomeSub()
{
    if (g_timeout != -1) { clearTimeout(g_timeout); }
}

function outNavHomeSub()
{
    if (g_timeout != -1) { clearTimeout(g_timeout); }
    g_timeout = setTimeout("hideNavHomeSub()", g_timeoutTime);
}

function showNavHomeSub()
{
    showLr("navigationHomeSub");
    showLr("navigationShade");
    setBackground("navigationHome", "rgb(242,242,242)");
}

function hideNavHomeSub()
{
    hideLr("navigationHomeSub");
    hideLr("navigationShade");
    setBackground("navigationHome", "#000000");
}

function setBackground(id, sBack)
{
    var elm = document.getElementById(id);
    elm.style.backgroundColor = sBack;
}

/* DIV Popup */
g_divPopupOpen = 0;
g_divPopupShadeborder = 8;
g_divPopupContentBorder = 15;
g_divPopupNaviSpace = 30;
g_divPopupHasCloseButton = false;

function openDivPopup(sUrl, imgWidth, imgHeight)
{
  if (g_divPopupOpen == 0)
  {
    g_divPopupHasCloseButton = true;
    // magic numbers follow, do not try at home
    var divHeight = imgHeight + (g_divPopupContentBorder * 2) + g_divPopupNaviSpace;
    var divWidth = imgWidth + (g_divPopupContentBorder * 2);
    var shadeHeight = imgHeight + (g_divPopupContentBorder * 2) + (g_divPopupShadeborder * 2) + g_divPopupNaviSpace + 2;
    var shadeWidth = imgWidth + (g_divPopupContentBorder * 2) + (g_divPopupShadeborder * 2) + 2;

    var elmShade = document.getElementById("divPopupShade");
    var elmDivPop = document.getElementById("divPopup");
    elmShade.className = 'bannerlibShade';
    elmDivPop.className = 'bannerlib';

    var imgX = g_pageWidth / 2 - imgWidth / 2;
    var imgY = Math.round( (viewportGetHeight() - imgHeight)/2 ) + viewportGetScrollY();

    if (imgY < 0) { imgY = 0; }
    if (imgX < 0) { imgX = 0; }

    elmShade.style.left = (imgX - g_divPopupShadeborder) + "px";
    elmShade.style.top = (imgY - g_divPopupShadeborder) + "px";
    elmShade.style.width = shadeWidth + "px";
    elmShade.style.height = shadeHeight + "px";

    elmDivPop.style.left = imgX + "px";
    elmDivPop.style.top = imgY + "px";
    elmDivPop.style.height = divHeight + "px";
    elmDivPop.style.width = divWidth + "px";

    var elmCloseButton = document.getElementById("closeButtonDivPopup");
    if (elmCloseButton) {
      elmCloseButton.style.left = (imgWidth - 19) + "px";
    }

    g_divPopupOpen = sUrl;

    prepareFillDivPopup(sUrl);
  }
}

function openDivPopupTemplate(sUrl, sType)
{
    if (g_divPopupOpen == 0)
    {
        g_divPopupHasCloseButton = true;
        var cssClassName = sType;
        switch(sType)
        {
          case 'bannerlib':
            var imgWidth = 758;
            var imgHeight = 640;
            break;
          case 'bannerlibsky':
            var imgWidth = 192;
            var imgHeight = 670;
            break;
          case 'bannerlibfull':
            var imgWidth = 498;
            var imgHeight = 126;
            break;
          case 'bannerlibhalf':
            var imgWidth = 264;
            var imgHeight = 126;
            break;
          case 'bannerlibrect':
            var imgWidth = 210;
            var imgHeight = 216;
            break;
          case 'bannerlibmrect':
            var imgWidth = 330;
            var imgHeight = 316;
            break;
          case 'bannerlibpopuph':
            var imgWidth = 230;
            var imgHeight = 366;
            break;
          case 'bannerlibpopupr':
            var imgWidth = 280;
            var imgHeight = 316;
            break;
        }
        // magic numbers follow, do not try at home
        var divHeight = imgHeight;
        var divWidth = imgWidth;
        var shadeHeight = imgHeight + (g_divPopupShadeborder * 2) + 2;
        var shadeWidth = imgWidth + (g_divPopupShadeborder * 2) + 2;

        var elmShade = document.getElementById("divPopupShade");
        var elmDivPop = document.getElementById("divPopup");
        elmShade.className = cssClassName + 'Shade';
        elmDivPop.className = cssClassName;

        var imgX = g_pageWidth / 2 - imgWidth / 2;
        var imgY = Math.round( (viewportGetHeight() - imgHeight)/2 ) + viewportGetScrollY();

        if (imgY < 0) { imgY = 0; }
        if (imgX < 0) { imgX = 0; }

        elmShade.style.left = (imgX - g_divPopupShadeborder) + "px";
        elmShade.style.top = (imgY - g_divPopupShadeborder) + "px";
        elmShade.style.width = shadeWidth + "px";
        elmShade.style.height = shadeHeight + "px";

        elmDivPop.style.left = imgX + "px";
        elmDivPop.style.top = imgY + "px";
        elmDivPop.style.height = divHeight + "px";
        elmDivPop.style.width = divWidth + "px";

        var elmCloseButton = document.getElementById("closeButtonDivPopup");
        if (elmCloseButton) {
            elmCloseButton.style.left = (imgWidth - 19) + "px";
        }

        g_divPopupOpen = sUrl;

        prepareFillDivPopup(sUrl);
    }
}

function closeDivPopup()
{
    var elm = document.getElementById("divPopup");
    elm.innerHTML = "<p>&nbsp;</p>";
    elm.style.display = "none";

    hideLr("divPopupShade");
    g_divPopupOpen = 0;

    if (g_is_safari) {
        var introElm = document.getElementById("introImage");
        if (introElm) {
            introElm.style.visibility = "visible";
        }
    }
}

function prepareFillDivPopup(sUrl)
{
    sUrl += getCachePrevent();
    if (window.XMLHttpRequest) {
        g_req = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) {
        g_req = new ActiveXObject("Microsoft.XMLHTTP");
    }
    g_req.onreadystatechange = fillDivPopup;
    g_req.open("GET", sUrl, true);
    g_req.send(null);
}

function fillDivPopup()
{
    if (g_req.readyState == 4)
    {
        if (g_req.status == 200)
        {
            if (g_is_safari) {
                var introElm = document.getElementById("introImage");
                if (introElm) {
                    introElm.style.visibility = "hidden";
                }
            }

            var s = "";
        
            var elmKB = document.getElementById("divPopup");
            var divPopWidth = elmKB.style.width;
            divPopWidth = divPopWidth.replace(/px/,'');
            var divPopHeight = elmKB.style.height;
            divPopHeight = divPopHeight.replace(/px/,'');

            divPopPageHeight = divPopHeight - (2 * g_divPopupContentBorder)
            divPopPageWidth = divPopWidth - (2 * g_divPopupContentBorder)

            divPopWidth-=17;
            divPopHeight-=17;

            s += "";
            if(g_divPopupHasCloseButton == true)
            {
              s += "<div style=\"left:" + divPopWidth + "px;\" class=\"closeButton\" id=\"closeButtonDivPopup\" onclick=\"closeDivPopup();\"><img src=\"/Images/close-button.gif\" alt=\"[X]\" title=\"Close\" /></div>";
            }            
            s += g_req.responseText;
            s = replStr(s, "<content>", "");
            s = replStr(s, "</content>", "");

            var sRun = getTextBetween(s, "// <![CDATA[", "// ]]>");
            sRun = replStr(sRun, ",wmode=opaque", ",");

            elmKB.innerHTML = s;

            var elmShade = document.getElementById("divPopupShade");
            var elmKB = document.getElementById("divPopup");

            if (screen.width <= 800) {
                var imgHeight = 350;
                var elmWrapper = document.getElementById("divPopupWrapper");
                elmWrapper.style.height = (imgHeight - 80) + "px";
            }

            g_maxDivPage = getMaxDivPage('page');
            for(i=1;i<=g_maxDivPage;i++)
            {
              pageElm = document.getElementById('page' + i);
              if(pageElm)
              {
                pageElm.style.width = divPopPageWidth + 'px';
                pageElm.style.height = divPopPageHeight + 'px';
              }
            }
            naviElm = document.getElementById('divPopupNavi');
            if(naviElm)
            {
              naviElm.style.top = divPopPageHeight + 'px';
              naviElm.style.left = g_divPopupContentBorder + (divPopPageWidth/2 - 90/2) + 'px';
            }

            elmKB.style.display = "block";
            elmShade.style.display = "block";

            if (sRun != "") { eval(sRun); }
        }
        else
        {
            alert("Can't retrieve XML: " + g_req.statusText);
        }
    }
}

function getMaxDivPage(sName)
{
    var max = 0;
    var testElm = null;

    do
    {
      max++;
      testElm = document.getElementById(sName + max);
    }
    while(testElm != null)
    max--;
    return max;
}

g_currentDivPage = 1;
g_maxDivPage = 0;
function prevDivPage(sName)
{
    if(g_maxDivPage == 0)
    {
      g_maxDivPage = getMaxDivPage(sName);
    }
    var n = g_currentDivPage;
    n--;
    if (n <= 0){ n = g_maxDivPage;}

    if(n != g_currentDivPage)
    {
      showLr(sName + n);
      hideLr(sName + g_currentDivPage);
    }
    g_currentDivPage = n;
    return false;
}

function nextDivPage(sName)
{
    if(g_maxDivPage == 0)
    {
      g_maxDivPage = getMaxDivPage(sName);
    }
    var n = g_currentDivPage;
    n++;
    if (n > g_maxDivPage){ n = 1; }

    if(n != g_currentDivPage && g_maxDivPage > 1)
    {
      showLr(sName + n);
      hideLr(sName + g_currentDivPage);
    }
    g_currentDivPage = n;
    return false;
}

function clickKnowledgebase(sUrl)
{
    if (g_openKnowledgeBase == 0)
    {
        var shadeborder = 8;

        var imgWidth = 656;
        var imgHeight = 535;
        // magic numbers follow, do not try at home
        var kbHeight = imgHeight - 60;
        var shadeHeight = imgHeight + 18;

        if (screen.width <= 800) {
            imgHeight = 300;
            kbHeight = 276;
            shadeHeight = 353;
        }

        var elmShade = document.getElementById("knowledgeBaseShade");
        var elmKB = document.getElementById("knowledgeBase");

        var imgX = g_pageWidth / 2 - imgWidth / 2;
        var imgY = Math.round( (viewportGetHeight() - imgHeight)/2 ) + viewportGetScrollY();

        if (imgY < 0) { imgY = 0; }
        if (imgX < 0) { imgX = 0; }

        elmShade.style.left = (imgX - shadeborder) + "px";
        elmShade.style.top = (imgY - shadeborder) + "px";
        elmShade.style.height = shadeHeight + "px";

        elmKB.style.left = imgX + "px";
        elmKB.style.top = imgY + "px";
        elmKB.style.height = kbHeight + "px";

        var elmCloseButton = document.getElementById("closeButtonKbase");
        if (elmCloseButton) {
            elmCloseButton.style.left = (imgWidth - 19) + "px";
        }

        g_openKnowledgeBase = sUrl;

        prepareFillKbase(sUrl);
    }
}

function closeKnowledgebase()
{
    var elm = document.getElementById("knowledgeBase");
    elm.innerHTML = "<p>&nbsp;</p>";
    elm.style.display = "none";

    hideLr("knowledgeBaseShade");
    g_openKnowledgeBase = 0;

    if (g_is_safari) {
        var introElm = document.getElementById("introImage");
        if (introElm) {
            introElm.style.visibility = "visible";
        }
    }
}

function prepareFillKbase(sUrl)
{
    sUrl += getCachePrevent();
    if (window.XMLHttpRequest) {
        g_req = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) {
        g_req = new ActiveXObject("Microsoft.XMLHTTP");
    }
    g_req.onreadystatechange = fillKbase;
    g_req.open("GET", sUrl, true);
    g_req.send(null);
}

function getCachePrevent()
{
    return "?rand=" + escape( Math.round( Math.random() * 10000 ) );
}

function fillKbase()
{
    if (g_req.readyState == 4)
    {
        if (g_req.status == 200)
        {
            if (g_is_safari) {
                var introElm = document.getElementById("introImage");
                if (introElm) {
                    introElm.style.visibility = "hidden";
                }
            }

            var s = "";
        
            var elmKB = document.getElementById("knowledgeBase");

            s += "";
            s += "<div class=\"closeButton\" id=\"closeButtonKbase\" onclick=\"closeKnowledgebase()\"><img src=\"/Images/close-button.gif\" alt=\"[X]\" title=\"Close\" /></div>";
            s += g_req.responseText;
            s = replStr(s, "<content>", "");
            s = replStr(s, "</content>", "");

            var sRun = getTextBetween(s, "// <![CDATA[", "// ]]>");
            sRun = replStr(sRun, ",wmode=opaque", ",");

            elmKB.innerHTML = s;

            var elmShade = document.getElementById("knowledgeBaseShade");
            var elmKB = document.getElementById("knowledgeBase");

            if (screen.width <= 800) {
                var imgHeight = 350;
                var elmWrapper = document.getElementById("knowledgebaseWrapper");
                elmWrapper.style.height = (imgHeight - 80) + "px";
            }

            elmKB.style.display = "block";
            elmShade.style.display = "block";

            if (sRun != "") { eval(sRun); }
        }
        else
        {
            alert("Can't retrieve XML: " + g_req.statusText);
        }
    }
}

function getTextBetween(sAll, sStart, sEnd)
{
    var sPart = "";
    var posStart = sAll.indexOf(sStart);
    var posEnd = sAll.indexOf(sEnd);
    if (posStart >= 0 && posEnd >= 0 && posEnd > posStart) {
        sPart = sAll.substring(posStart + sStart.length, posEnd);
    }
    return sPart;
}

function clickZoomable(id, imgWidth, imgHeight)
{
    if (g_openZoom == 0)
    {
        var shadeborder = 8;

        var elmShade = document.getElementById("zoomImageShade");
        var elmImage = document.getElementById("zoomImage" + id);
        var elmCloseButton = document.getElementById("closeButton" + id);

        var imgX = g_pageWidth / 2 - imgWidth / 2;
        var imgY = Math.round( (viewportGetHeight() - imgHeight)/2 ) + viewportGetScrollY();

        if (imgY < 0) { imgY = 0; }
        // if (imgX < 0) { imgX = 0; }

        elmShade.style.left = (imgX - shadeborder) + "px";
        elmShade.style.width = (imgWidth + shadeborder * 2) + "px";
        elmShade.style.top = (imgY - shadeborder) + "px";
        elmShade.style.height = (imgHeight + shadeborder * 2) + "px";

        elmImage.style.left = imgX + "px";
        elmImage.style.top = imgY + "px";
        if (elmCloseButton) {
            elmCloseButton.style.left = (imgWidth - 19) + "px";
        }

        elmImage.style.display = "block";
        elmShade.style.display = "block";

        g_openZoom = id;
    }
}

function clickZoomed()
{
    hideLr("zoomImageShade");
    hideLr("zoomImage" + g_openZoom);
    g_openZoom = 0;
}

function showLr(id)
{
    var elm = document.getElementById(id);
    if (elm) {
        elm.style.display = "block";
    }
}

function hideLr(id)
{
    var elm = document.getElementById(id);
    if (elm) {
        elm.style.display = "none";
    }
}


/* Expandable module */

function expandCollapse(id)
{
    var elm = document.getElementById("expandable_" + id);

    if (elm)
    {
        /* Hack alert -- footer will be hidden temporarily
        to recalculate bottom position correctly.
        */

        var footer = document.getElementById("footer");
        footer.style.display = "none";

        if (elm.style.height != "auto")
        {
            collapseAllElements();
            showElement(id);        
        }
        else
        {
            collapseElement(id);
        }

        positionFooter();
        footer.style.display = "block";
    }
}

function showElement(id) {
    var elm = document.getElementById("expandable_" + id);
    elm.style.height = "auto";

    var h3 = document.getElementById("expandableHead_" + id);
    if (h3) {                
        h3.style.backgroundColor = "rgb(102,102,102)";                 
        h3.style.color = "rgb(0,0,0)";              
        h3.style.backgroundImage = "url(images/arrow-lightgray-down.gif)";            
        h3.style.backgroundPosition = "9px 9px";
    }
}

function collapseElement(id) {
    var elm = document.getElementById("expandable_" + id);
    elm.style.height = "19px";

    var h3 = document.getElementById("expandableHead_" + id);
    if (h3) {
        h3.style.backgroundColor = "rgb(204,204,204)";                
        h3.style.color = "#000000";
        h3.style.backgroundImage = "url(images/arrow-gray.gif)";          
        h3.style.backgroundPosition = "11px 7px";
    }
}

function collapseAllElements() {
    var i=1;
    do {
        var elm = document.getElementById("expandable_" + i);
        if (elm) collapseElement(i);
        i++;
    } while(elm);
}

function viewportGetHeight()
{
    var retval = 0;

    if (window.innerHeight)
        retval = window.innerHeight - 18;
    else if (document.documentElement && document.documentElement.clientHeight) 
        retval = document.documentElement.clientHeight;
    else if (document.body && document.body.clientHeight) 
        retval = document.body.clientHeight;

    return retval;    
}

function viewportGetWidth()
{
    var retval = 0;

    if (window.innerWidth)
        retval = window.innerWidth - 18;
    else if (document.documentElement && document.documentElement.clientWidth) 
        retval = document.documentElement.clientWidth;
    else if (document.body && document.body.clientWidth) 
        retval = document.body.clientWidth;

    return retval;    
}

function viewportGetScrollY()
{
    var retval = 0;

    if (typeof window.pageYOffset == "number")
        retval = window.pageYOffset;
    else if (document.documentElement && document.documentElement.scrollTop)
        retval = document.documentElement.scrollTop;
    else if (document.body && document.body.scrollTop) 
        retval = document.body.scrollTop; 
    else if (window.scrollY)
        retval = window.scrollY;

    return retval;
}

function showGalleryFlash(pool, movieFolder, bandwidth, flashParams)
{
    var elmImg = document.getElementById("galleryImage");
    if (elmImg) {
        g_fallbackImage = elmImg.src;
    }

    var url = "/all/media/flash/videoplayer.swf";
    showFlash(url, "galleryContent", "595", "317", "7", "#FFFFFF",
            "loop=true,menu=true,quality=high,wmode=opaque",
            "pool=" + pool + ",id=" + movieFolder + ",bandwidth=" + bandwidth + ",eventhandler=flashEnded," + flashParams);
}

function flashEnded()
{
    if (g_fallbackImage != "") {
        var elmContent = document.getElementById("galleryContent");
        elmContent.innerHTML = "<img src=\"" + g_fallbackImage + "\" alt=\"\" id=\"galleryImage\" />";
    }
}

function showFlash(url, id, width, height, version, bgcolor, playerparamstr, flashparamstr) {

    if (! (g_is_home && g_is_safari) ) {
        var fo = new FlashObject(url, id + "_flash", width, height, version, bgcolor);
        
        if (playerparamstr != undefined) {    
            var playerparams = playerparamstr.split(",");
            for (var i=0; i < playerparams.length; i++ ){
                var param = playerparams[i].split("=");
                fo.addParam(param[0], param[1]);
            }
        }
        
        if (flashparamstr != undefined) {
            var flashparams = flashparamstr.split(",");
            for (var i=0; i < flashparams.length; i++ ){
                var param = flashparams[i].split("=");
                fo.addVariable(param[0], param[1]);
            }
        }
        
        fo.write(id);
    }
}


/* Gallery module */

var g_lastNumber = 1;

function setImage(elm, n)
{
    if (g_lastNumber != n)
    {
        var lastElm = document.getElementById("thumbnail" + g_lastNumber);
        lastElm.className = "";
        lastElm.style.border = "1px solid #ccc";

        var thisElm = document.getElementById("thumbnail" + n);
        thisElm.className = "selected";
        thisElm.style.border = "1px solid rgb(204,0,0)";

        g_lastNumber = n;

        sHref = elm.href;
        document.getElementById("galleryImage").src = sHref;
        
        showGallerySubtitle(n);
        showGalleryClaim(n);
    }
    return false;
}

function setThumbnail(elm, n)
{
    if (g_lastNumber != n)
    {
        var lastElm = document.getElementById("thumbnail" + g_lastNumber);
        lastElm.className = "";
        lastElm.style.border = "1px solid #ccc";

        var thisElm = document.getElementById("thumbnail" + n);
        thisElm.className = "selected";
        thisElm.style.border = "1px solid rgb(204,0,0)";

        g_lastNumber = n;
    }

    return false;
}

function prevgalleryImage(img, imgMax)
{
    var lastElm = document.getElementById("thumbnail" + g_lastNumber);
    if (lastElm) {    
    	lastElm.className = "";
    	lastElm.style.border = "1px solid #ccc";
    }

    var n = --g_lastNumber;
    if (n < 1) { n = getMaxNumberGallery(); }

    var thisElm = document.getElementById("thumbnail" + n);
    if (thisElm) {     
	    thisElm.className = "selected";
	    thisElm.style.border = "1px solid rgb(204,0,0)";
	}

    var elm = document.getElementById("href" + n);
    sHref = elm.href;
    document.getElementById("galleryImage").src = sHref;

    g_lastNumber = n;
    
    showGallerySubtitle(n);
	showGalleryClaim(n);
	
    return false;
}

function nextgalleryImage()
{
    var lastElm = document.getElementById("thumbnail" + g_lastNumber);
    if (lastElm) {
	    lastElm.className = "";
	    lastElm.style.border = "1px solid #ccc";
    }

    var n = ++g_lastNumber;
    var max = getMaxNumberGallery();
    if (n > max) { n = 1; }

    var thisElm = document.getElementById("thumbnail" + n);
    if (thisElm) {    
	    thisElm.className = "selected";
	    thisElm.style.border = "1px solid rgb(204,0,0)";
	}

    var elm = document.getElementById("href" + n);
    sHref = elm.href;
    document.getElementById("galleryImage").src = sHref;

    g_lastNumber = n;
    
    showGallerySubtitle(n);
    showGalleryClaim(n);

    return false;
}

function initGallerySubtitles()
{
    var subtitles = document.getElementById("gallerySubtitles")
    var claims = document.getElementById("galleryClaims")
           	
    if (subtitles) {
        var tab = getGallerySubtitleTab();
           
        if (tab) {
            tab.style.display = "block";
            
            showGallerySubtitle(1);
        }
    }

    if (claims) {

        var claim = getGalleryClaimTab();
		var n = getGalleryItemNo();
		if (n == -1) n=1;
	        if (claim) {
	    	    claim.style.display = "block";
	            showGalleryClaim(n);
	        }
    }


}


function getGalleryItemNo() 
{
    var no = -1;
    
    var regex = /itemindex=(\d)/;
    var result = regex.exec(document.URL);
    
    if (result != null) { 
        no = result[1]
    }            
    
    return no;          
}

function showGallerySubtitle(n)
{
    var subtitles = document.getElementById("gallerySubtitles");

	
    if (subtitles) {    	
        var tab = getGallerySubtitleTab();
  
               
        if (tab != null) {
            var tabSubtitles 	= tab.getElementsByTagName("div");
            
            if (tabSubtitles) {            
                for (var i = 0; i < tabSubtitles.length; i++) {
                    tabSubtitles[i].style.display = (i == n - 1) ? "block" : "none";
                }
            }
            
          
        }   	
    }
}


function showGalleryClaim(n) {
    var claim = document.getElementById("galleryClaims");	
   
    if (claim) {    	
        var tab = getGalleryClaimTab();
              
        if (tab != null) {
            var tabClaims = claim.getElementsByTagName("img");
            
            if (tabClaims) {            
                for (var i = 0; i < tabClaims.length; i++) {
                    tabClaims[i].style.display = (i == n - 1) ? "block" : "none";
                }
            }
            
        }   	
    }    
}


function getGalleryClaimTab()
{
    var no = getGallerySubtitleTabNo();
    var claim = document.getElementById("galleryClaimsTab" + no);

	return claim;	
}


function getGallerySubtitleTab()
{
    var no = getGallerySubtitleTabNo();
    var tab = document.getElementById("gallerySubtitlesTab" + no);
    
    return tab;          
}


function getGallerySubtitleTabNo()
{
    var no = 1;
    
    var regex = /tabindex=(\d)/;
    var result = regex.exec(document.URL);
    
    if (result != null) { 
        no = result[1]
    }            
    
    return no;          
}

function getMaxNumberGallery()
{
    var max = 0;
    for (var i = 15; i >= 1 && max == 0; i--) {
        var testElm = document.getElementById("thumbnail" + i);
        if (testElm) {
            max = i;
            break;
        }
    }

    return max;
}

function showWallpaper(img, iWidth, iHeight)
{
    gotoUrlNewWin(img);
}


/* Open Selection Shop item in a window */

function openSelectionShopItem(dept_id, pf_id)
{
	gotoUrlNewWinSizeScrollableWithMenu('http://shop.eu.porsche.com/germany/product2.asp?dept_id=' + dept_id + '&pf_id=' + pf_id + '&comefrom=teq911', 870, 700)
}


/* Windows module */

function configureCar(marketId)
{
    switch (marketId) {
        case "de":
            gotoUrlNewWinSizeByName("http://cc.porsche.de/pva/ui/pva/index.jsp?sprache=de&modelRange=null", 960, 652, "PVA");
            break;

        case "us":
            gotoUrlNewWinSizeByName("http://cc.porsche.com/pva/ui/pva/index.jsp?sprache=us&modelRange=null", 960, 652, "PVA");
            break;

        case "fr":
            gotoUrlNewWinSizeByName("http://cc.porsche.de/pva/ui/pva/index.jsp?sprache=fr&modelRange=null", 960, 652, "PVA");
            break;

        case "it":
            gotoUrlNewWinSizeByName("http://cc.porsche.de/pva/ui/pva/index.jsp?sprache=it&modelRange=null", 960, 652, "PVA");
            break;

        case "en":
            gotoUrlNewWinSizeByName("http://cc.porsche.de/pva/ui/pva/index.jsp?sprache=en&modelRange=null", 960, 652, "PVA");
            break;

        case "sp":
            gotoUrlNewWinSizeByName("http://cc.porsche.de/pva/ui/pva/index.jsp?sprache=sp&modelRange=null", 960, 652, "PVA");
            break;

        case "ae":
            gotoUrlNewWinSizeByName("http://cc.porsche.de/pva/ui/pva/index.jsp?sprache=ae&modelRange=null", 960, 652, "PVA");
            break;
            
        case "mx":
            gotoUrlNewWinSizeByName("http://cc.porsche.de/pva/ui/pva/index.jsp?sprache=mx&modelRange=null", 960, 652, "PVA");
            break;
            
        case "sg":
            gotoUrlNewWinSizeByName("http://cc.porsche.de/pva/ui/pva/index.jsp?sprache=sg&modelRange=null", 960, 652, "PVA");
            break;
    }
}

function gotoUrlNewWinSimple(s)
{
    newWin = window.open(s, "newWin" + getRandomInt(10000));
}

function gotoUrlNewWin(s)
{
    sWidth = 826;
    sHeight = 610;

    sWidth += 20;
    sHeight += 25;
    newWin = window.open(s, "newWin" + getRandomInt(10000), "width=" + sWidth + ",height=" + sHeight + ",left=40,top=40,dependent=yes,location=no,resizable=no,scrollbars=no,status=no");
}

function gotoUrlNewWinSize(s, sWidth, sHeight)
{
    sWidth += 20;
    sHeight += 25;
    newWin = window.open(s, "newWin" + getRandomInt(10000), "width=" + sWidth + ",height=" + sHeight + ",left=40,top=40,dependent=yes,location=no,resizable=no,scrollbars=no,status=no");
}

function gotoUrlNewWinSizeScrollable(s, sWidth, sHeight)
{
    sWidth += 20;
    sHeight += 25;
    newWin = window.open(s, "newWin" + getRandomInt(10000), "width=" + sWidth + ",height=" + sHeight + ",left=40,top=40,dependent=yes,location=no,resizable=no,scrollbars=yes,status=no");
}


function gotoUrlNewWinSizeScrollableWithMenu(s, sWidth, sHeight)
{
    sWidth += 20;
    sHeight += 50;

    if (screen.height < 768) {
        if (sHeight > 450) sHeight = 430;
        if (sWidth > 783) sWidth = 790;
        sOffset = 0;
    }
    else if (screen.height < 1024) {
        if (sHeight > 550) sHeight = 550;
        sOffset = 10;
    }
    else {
        sOffset = 40;
    }
        
    newWin = window.open(s, "newWin" + getRandomInt(10000), "width=" + sWidth + ",height=" + sHeight + ",left=" + sOffset + ",top=" + sOffset + ",dependent=yes,location=yes,menubar=yes,toolbar=yes,resizable=no,scrollbars=yes,status=yes");
}


function gotoUrlNewWinDefaultSize(s)
{
    sWidth = 570;
    sHeight = 610;

    sWidth += 20;
    sHeight += 25;
    newWin = window.open(s, "newWin" + getRandomInt(10000), "width=" + sWidth + ",height=" + sHeight + ",left=40,top=40,dependent=yes,location=no,resizable=no,scrollbars=no,status=no");
}

function gotoUrlNewWinSizeCentered(s, iWidth, iHeight)
{
    iWidth += 20;
    iHeight += 25;    
    iLeft = Math.round((screen.width - iWidth) / 2);
    iTop = Math.round((screen.height - iHeight) / 2);
    newWin = window.open(s, "newWin" + getRandomInt(10000), "width=" + iWidth + ",height=" + iHeight + ",left=" + iLeft + ",top=" + iTop + ",dependent=yes,location=no,resizable=no,scrollbars=no,status=no");
}

function gotoUrlNewWinSizeByName(s, sWidth, sHeight, sName)
{
    sWidth += 20;
    sHeight += 25;
    newWin = window.open(s, sName, "width=" + sWidth + ",height=" + sHeight + ",left=40,top=40,dependent=yes,location=no,resizable=no,scrollbars=no,status=no");
}

function openLeanWin(sUrl, sWidth, sHeight)
{
    sWidth += 20;
    sHeight += 25;
    newWin = window.open(sUrl, "newWin" + getRandomInt(10000), "width=" + sWidth + ",height=" + sHeight + ",left=140,top=140,dependent=yes,location=no,resizable=no,scrollbars=no,status=no,menubar=no,toolbar=no");
}

function getRandomInt(max)
{
    return Math.round( Math.random() * (max-1) );
}


/* Ad-Tracker module */

function getAdTrackerNumber()
{
    var axel = Math.random() + "";
    var a = axel * 10000000000000;
    return a;
}



/* Home module */

function initHome()
{
    if (document.getElementById) {
        g_initHome = true;
    }
}

function bannerLinkToHi(sId)
{

    if (g_initHome)
    {
        var elm = document.getElementById(sId);
        if (elm)
        {
            elm.style.color = "#c00";
            elm.style.backgroundImage = "url(/Images/arrow-red.gif)";
        }
    }

}

function bannerLinkToLo(sId)
{

    if (g_initHome)
    {
        var elm = document.getElementById(sId);
        if (elm)
        {
            elm.style.color = "rgb(102,102,102)";
            elm.style.backgroundImage = "url(images/arrow-gray.gif)";
        }
    }
}

function navShadeIn(level)
{

    if (g_initHome)
    {
        if (level == 1)
        {
            if (g_timeoutHide1 != 0) { clearTimeout(g_timeoutHide1); }
        }
        else if (level == 2)
        {
            if (g_timeoutHide1 != 0) { clearTimeout(g_timeoutHide1); }
            if (g_timeoutHide2 != 0) { clearTimeout(g_timeoutHide2); }
        }
        else if (level == 3)
        {
            if (g_timeoutHide1 != 0) { clearTimeout(g_timeoutHide1); }
            if (g_timeoutHide2 != 0) { clearTimeout(g_timeoutHide2); }
            if (g_timeoutHide3 != 0) { clearTimeout(g_timeoutHide3); }
        }
    }
}

function navShadeOut(level)
{

    if (g_initHome)
    {
        if (level == 1)
        {
            g_timeoutHide1 = setTimeout("hideNav(1,\"" + g_currentNav1 + "\",\"" + g_currentHi1 + "\")", g_timeoutTime);
        }
        else if (level == 2)
        {
            g_timeoutHide1 = setTimeout("hideNav(1,\"" + g_currentNav1 + "\",\"" + g_currentHi1 + "\")", g_timeoutTime);
            g_timeoutHide2 = setTimeout("hideNav(2,\"" + g_currentNav2 + "\",\"" + g_currentHi2 + "\")", g_timeoutTime);
        }
        else if (level == 3)
        {
            g_timeoutHide1 = setTimeout("hideNav(1,\"" + g_currentNav1 + "\",\"" + g_currentHi1 + "\")", g_timeoutTime);
            g_timeoutHide2 = setTimeout("hideNav(2,\"" + g_currentNav2 + "\",\"" + g_currentHi2 + "\")", g_timeoutTime);
            g_timeoutHide3 = setTimeout("hideNav(3,\"" + g_currentNav3 + "\",\"" + g_currentHi3 + "\")", g_timeoutTime);
        }
    }
}

function overNav(level, sName, sSelf)
{
    if (g_initHome)
    {
        if (level == 0 || level == "0")
        {
            echo("level in 0");

            if (g_timeoutHide1 != 0) { clearTimeout(g_timeoutHide1); }

            hideSubLayers(g_currentNav1);
            loliteLr(level, g_currentHi1);

            if (g_currentNav1 != "") { hideSubLayers(g_currentNav1); }
            if (g_currentHi1 != "") { loliteLr(level, g_currentHi1); }

            showNav(level + 1, sName, sSelf);
            g_currentNav1 = sName;
            g_currentHi1 = sSelf;            
        }
        else if (level == 1 || level == "1")
        {
            echo("level in 1");

            if (g_timeoutHide1 != 0) { clearTimeout(g_timeoutHide1); }
            if (g_timeoutHide2 != 0) { clearTimeout(g_timeoutHide2); }

            if (g_currentNav2 != "") { hideSubLayers(g_currentNav2); }
            if (g_currentHi2 != "") { loliteLr(level, g_currentHi2); }

            showNav(level + 1, sName, sSelf);
            g_currentNav2 = sName;
            g_currentHi2 = sSelf;
        }
        else if (level == 2 || level == "2")
        {
            echo("level in 2");

            if (g_timeoutHide1 != 0) { clearTimeout(g_timeoutHide1); }
            if (g_timeoutHide2 != 0) { clearTimeout(g_timeoutHide2); }
            if (g_timeoutHide3 != 0) { clearTimeout(g_timeoutHide3); }

            if (g_currentNav3 != "") { hideSubLayers(g_currentNav3); }
            if (g_currentHi3 != "") { loliteLr(level, g_currentHi3); }

            showNav(level + 1, sName, sSelf);
            g_currentNav3 = sName;
            g_currentHi3 = sSelf;            
        }
        else if (level == 3 || level == "3")
        {
            echo("level in 3");

            if (g_timeoutHide1 != 0) { clearTimeout(g_timeoutHide1); }
            if (g_timeoutHide2 != 0) { clearTimeout(g_timeoutHide2); }
            if (g_timeoutHide3 != 0) { clearTimeout(g_timeoutHide3); }
            if (g_timeoutHide4 != 0) { clearTimeout(g_timeoutHide4); }

            if (g_currentNav4 != "") { hideSubLayers(g_currentNav4); }

            showNav(level + 1, sName, sSelf);
            g_currentNav4 = sName;
        }
    }
}

function loadImage(sName, sUrl)
{ 
    var elem = document.getElementById(sName + "_image");
    if (elem) elem.src = sUrl;
}

function outNav(level)
{
    if (g_initHome)
    {
        if (level == 0 || level == "0")
        {
            echo("level out 0");      
        }
        else if (level == 1 || level == "1")
        {
            echo("level out 1");
            g_timeoutHide1 = setTimeout("hideNav(1,\"" + g_currentNav1 + "\",\"" + g_currentHi1 + "\")", g_timeoutTime);
            g_timeoutHide2 = setTimeout("hideNav(2,\"" + g_currentNav2 + "\",\"" + g_currentHi2 + "\")", g_timeoutTime);
        }
        else if (level == 2 || level == "2")
        {
            echo("level out 2");
            g_timeoutHide1 = setTimeout("hideNav(1,\"" + g_currentNav1 + "\",\"" + g_currentHi1 + "\")", g_timeoutTime);
            g_timeoutHide2 = setTimeout("hideNav(2,\"" + g_currentNav2 + "\",\"" + g_currentHi2 + "\")", g_timeoutTime);
            g_timeoutHide3 = setTimeout("hideNav(3,\"" + g_currentNav3 + "\",\"" + g_currentHi3 + "\")", g_timeoutTime);
        }
        else if (level == 3 || level == "3")
        {
            echo("level out 3");
            g_timeoutHide1 = setTimeout("hideNav(1,\"" + g_currentNav1 + "\",\"" + g_currentHi1 + "\")", g_timeoutTime);
            g_timeoutHide2 = setTimeout("hideNav(2,\"" + g_currentNav2 + "\",\"" + g_currentHi2 + "\")", g_timeoutTime);
            g_timeoutHide3 = setTimeout("hideNav(3,\"" + g_currentNav3 + "\",\"" + g_currentHi3 + "\")", g_timeoutTime);
            g_timeoutHide4 = setTimeout("hideNav(4,\"" + g_currentNav4 + "\",\"" + g_currentHi4 + "\")", g_timeoutTime);
        }
        else
        {
            echo("level out is else: " + level);
        }         
    }
}

function dimHeadline(doOn)
{         
    var elem = document.getElementById("homeHead");
    
    if (elem) {
        if (parseInt(elem.style.top.replace(/px/, ""),10) > 88) {   
            
                if (doOn)
                {
                    elem.style.MozOpacity = ".99";
                    elem.style.filter = "alpha(opacity=100)";
                }
                else
                {
                    elem.style.MozOpacity = ".40";
                    elem.style.filter = "alpha(opacity=40)";
                }
        }
    }
}

function showNav(level, sName, sSelf)
{
    dimHeadline(false);

    hiliteLr(level - 1, sSelf);
    var foundOne = showSubLayers(sName);
    if (foundOne)
    {
        if (g_canHandleTransparency)
        {
            var elm = document.getElementById("navshade" + level);
            showLr("navshade" + level);
        }
        else
        {
            var elm = document.getElementById("navshadeSimple" + level);
            showLr("navshadeSimple" + level);
        }
    }
    else
    {
        if (g_canHandleTransparency)
        {
            hideLr("navshade" + level);
        }
        else
        {
            hideLr("navshadeSimple" + level);
        }
    }     
}

function hideNav(level, sName, sSelf)
{
    if (level == 1) { g_timeoutHide1 = 0; g_currentNav1 = ""; g_currentSelf1 = ""; dimHeadline(true); }
    if (level == 2) { g_timeoutHide2 = 0; g_currentNav2 = ""; g_currentSelf2 = ""; }
    if (level == 3) { g_timeoutHide3 = 0; g_currentNav3 = ""; g_currentSelf3 = ""; }
    if (level == 4) { g_timeoutHide4 = 0; g_currentNav4 = ""; }

    loliteLr(level - 1, sSelf);

    if (g_canHandleTransparency)
    {
        hideLr("navshade" + level);
    }
    else
    {
        hideLr("navshadeSimple" + level);
    }

    hideSubLayers(sName);
}

function hiliteLr(level, sName)
{
    var elem = document.getElementById(sName);
    if (elem)
    {
        if (level == 0 || level == "0")
        {
            elem.style.color = "rgb(204, 0, 0)";
            elem.style.backgroundColor = "rgb(255,255,255)";	
            if (! (elem.className.indexOf("final") >= 0) )
            {
            elem.style.backgroundImage = "url(images/transparent/white-15.png)";	
			
			  }
        }
        else
        {
            elem.style.color = "rgb(204, 0, 0)";

            if (! (elem.className.indexOf("final") >= 0) )
            {
              elem.style.backgroundImage = "url(images/transparent/white-13.png)";
            }

            elem.style.MozOpacity = ".99"; // hack around weeeiiird bug which causes "1" to break NS7.02
            elem.style.filter = "alpha(opacity=100)";
        }
    }
}

function loliteLr(level, sName)
{
    var elem = document.getElementById(sName);
    if (elem)
    {
        if (level == 0 || level == "0")
        {
            elem.style.color = "rgb(0,0,0)";
          elem.style.backgroundColor = "transparent";
            if (! (elem.className.indexOf("final") >= 0) )
            {
                elem.style.backgroundImage = "url(images/porsche_school_boton_menu.png)";
            }
        }
        else
        {
            elem.style.color = "rgb(0, 0, 0)";
            if (! (elem.className.indexOf("final") >= 0) )
            {
                elem.style.backgroundImage = "url(images/porsche_school_boton_menu.png)";
            }

            elem.style.MozOpacity = ".86";
            elem.style.filter = "alpha(opacity=86)";
        }
    }
}

function showSubLayers(sName)
{
    var i = 0;
    var foundOne = false;

    for (i = 1; i <= 13; i++)
    {
        var s = "nav_" + sName + "_" + i;
        var elem = document.getElementById(s);
        if (elem)
        {
            foundOne = true;
        }
        else
        {
            break;
        }

        showLr(s);
    }

    return foundOne;
}

function hideSubLayers(sName)
{
    var i = 0;
    var foundOne = false;

    for (i = 1; i <= 13; i++)
    {
        var s = "nav_" + sName + "_" + i;
        var elem = document.getElementById(s);
        if (elem)
        {
            foundOne = true;
        }
        else
        {
            break;
        }

        hideLr(s);
    }

    return foundOne;
}

function echo(s)
{
    /*
    var elDebug = document.getElementById("debug");
    elDebug.innerHTML = "<div><span>" + (++g_echoCount) + ".</span> " + s + "</div>" + elDebug.innerHTML;
    */
}

function setModel(s)
{

    if (g_initHome)
    {
        g_currentModelLink = s;
    }
}

function gotoModel()
{

    if (g_initHome)
    {
        if (g_currentModelLink != '')
        {
            gotoUrl(g_currentModelLink);
        }
    }
}

function gotoUrl(s)
{
    g_psyma_navi_clicked = true;
    document.location.href = s;
}

function gotoUrlTimeout(s, timeout)
{
  setTimeout("gotoUrl('" + s + "')", timeout)
}
function nogo()
{
    //
}

function getRandomInt(max)
{
    return Math.round( Math.random() * (max-1) );
}

function selectAllInput(elm)
{
    if (elm)
    {
        elm.focus();
        elm.select();
    }
}

function changedCountry(elmThis)
{
    if (document.getElementById)
    {
        var sUrl = elmThis.value;

        if (sUrl != "")
        {
            document.location.href = sUrl;
        }
    }
}

function sniffAll()
{
    /* JavaScript Browser Sniffer
       Eric Krok, Andy King, Michel Plungjan Jan. 31, 2002
       see http://www.webreference.com/ for more information
       This program is free software */

    var agt=navigator.userAgent.toLowerCase();
    var appVer = navigator.appVersion.toLowerCase();

    var is_minor = parseFloat(appVer);
    var is_major = parseInt(is_minor);

    var is_opera = (agt.indexOf("opera") != -1);

    /*
    var is_opera6 = (agt.indexOf("opera 6") != -1 || agt.indexOf("opera/6") != -1);
    var is_opera7 = (agt.indexOf("opera 7") != -1 || agt.indexOf("opera/7") != -1);
    var is_opera6up = (is_opera && !is_opera2 && !is_opera3 && !is_opera4 && !is_opera5);
    var is_opera7up = (is_opera && !is_opera2 && !is_opera3 && !is_opera4 && !is_opera5 && !is_opera6);
    */

    var iePos  = appVer.indexOf('msie');
    if (iePos !=-1) {
       is_minor = parseFloat(appVer.substring(iePos+5,appVer.indexOf(';',iePos)));
       is_major = parseInt(is_minor);
    }

    var is_konq = false;
    var kqPos   = agt.indexOf('konqueror');
    if (kqPos !=-1) {                 
       is_konq  = true;
       is_minor = parseFloat(agt.substring(kqPos+10,agt.indexOf(';',kqPos)));
       is_major = parseInt(is_minor);
    }

    var is_getElementById   = (document.getElementById) ? "true" : "false";
    var is_getElementsByTagName = (document.getElementsByTagName) ? "true" : "false";
    var is_documentElement = (document.documentElement) ? "true" : "false";

    var is_safari = ((agt.indexOf('safari')!=-1)&&(agt.indexOf('mac')!=-1))?true:false;
    var is_khtml  = (is_safari || is_konq);

    var is_gecko = ((!is_khtml)&&(navigator.product)&&(navigator.product.toLowerCase()=="gecko"))?true:false;
    var is_gver  = 0;
    if (is_gecko) is_gver=navigator.productSub;

    var is_moz   = ((agt.indexOf('mozilla/5')!=-1) && (agt.indexOf('spoofer')==-1) &&
                    (agt.indexOf('compatible')==-1) && (agt.indexOf('opera')==-1)  &&
                    (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1)     &&
                    (is_gecko) && 
                    ((navigator.vendor=="")||(navigator.vendor=="Mozilla")));


    if (is_moz) {
       var is_moz_ver = (navigator.vendorSub)?navigator.vendorSub:0;
       if(!(is_moz_ver)) {
           is_moz_ver = agt.indexOf('rv:');
           is_moz_ver = agt.substring(is_moz_ver+3);
           is_paren   = is_moz_ver.indexOf(')');
           is_moz_ver = is_moz_ver.substring(0,is_paren);
       }
       is_minor = is_moz_ver;
       is_major = parseInt(is_moz_ver);
    }

    var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
                && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
                && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1)
                && (!is_khtml) && (!(is_moz)));

    if ((navigator.vendor)&&
        ((navigator.vendor=="Netscape6")||(navigator.vendor=="Netscape"))&&
        (is_nav)) {
       is_major = parseInt(navigator.vendorSub);
       is_minor = parseFloat(navigator.vendorSub);
    }

    var is_nav2 = (is_nav && (is_major == 2));
    var is_nav3 = (is_nav && (is_major == 3));
    var is_nav4 = (is_nav && (is_major == 4));
    var is_nav4up = (is_nav && is_minor >= 4); 
    var is_navonly  = (is_nav && ((agt.indexOf(";nav") != -1) ||
                          (agt.indexOf("; nav") != -1)) );

    var is_nav6   = (is_nav && is_major==6);
    var is_nav6up = (is_nav && is_minor >= 6);

    var is_nav5   = (is_nav && is_major == 5 && !is_nav6);
    var is_nav5up = (is_nav && is_minor >= 5);

    var is_nav7   = (is_nav && is_major == 7);
    var is_nav7up = (is_nav && is_minor >= 7);

    var is_ie   = ((iePos!=-1) && (!is_opera) && (!is_khtml));
    var is_ie3  = (is_ie && (is_major < 4));

    var is_ie4   = (is_ie && is_major == 4);
    var is_ie4up = (is_ie && is_minor >= 4);
    var is_ie5   = (is_ie && is_major == 5);
    var is_ie5up = (is_ie && is_minor >= 5);
    
    var is_ie5_5  = (is_ie && (agt.indexOf("msie 5.5") !=-1));
    var is_ie5_5up =(is_ie && is_minor >= 5.5);
    
    var is_ie6   = (is_ie && is_major == 6);
    var is_ie6up = (is_ie && is_minor >= 6);

    g_is_ie = is_ie;
    g_is_opera = is_opera;
    g_is_ie5 = is_ie5;
    g_is_ie5_5 = is_ie5_5;
    g_is_safari = is_safari;
}



/* Module Motorschaubild */

function showDetail(item) {
    getDiagramDetail(item).style.display = "block";
}
    
function hideDetail(item) {
    getDiagramDetail(item).style.display = "none";
}    
    
function getDiagramDetail(item) {
    return document.getElementById("engineDiagramDetail" + item.getAttribute("id").substr(17,2));
}

function switchDiagramPage()
{
   var page1 = document.getElementById("engineDiagramPage1");     
   var page2 = document.getElementById("engineDiagramPage2");
     
   if (page1 && page2) {
        var show2ndPage = ((page1.style.display == "") || (page1.style.display == "block"));
        
        var control = document.getElementById("engineDiagramControl");
                
        if (show2ndPage) {
                page1.style.display = "none";
                page2.style.display = "block";
                control.innerHTML = "<a href=\"javascript:switchDiagramPage();\">&lt; 2/2</a>";
        } else {
                page1.style.display = "block";
                page2.style.display = "none";
                control.innerHTML = "<a href=\"javascript:switchDiagramPage();\">1/2 &gt;</a>";                
        }
   } 
}

  
/* Module Image Switch */

function updateImageSwitch(elm, state)
{
	var elmChild = null;
	
	if (elm.childNodes[0].style != undefined) {
		elmChild = elm.childNodes[0];
	} else {
		elmChild = elm.childNodes[1];
	}

    switch (state) {
        case "active":    

            var i = 1;
            do {
                var elmInactive = document.getElementById("switchImage" + i);
                if (elmInactive != null) {
                    updateImageSwitch(elmInactive, "inactive");
                }
                i++;
            } while (elmInactive != null)
	
            elm.style.color = "rgb(204,0,0)";
            elm.style.background = "white url(/images/arrow-red.gif) no-repeat left 3px";
            elmChild.style.display = "block";                      
            break;
        case "inactive":
            elm.style.color = "rgb(102,102,102)";
            elm.style.background = "white url(/images/arrow-gray.gif) no-repeat left 3px";
            elmChild.style.display = "none";                                      
    }
}

/* Macht ein Redirect zur Value des ausgewählten Elements der angegebenen Select Box */
function RedirectToOptionValue(name)
{
  obj = document.getElementById(name);
  if(obj)
  {
    link = obj.options[obj.selectedIndex].value;
    if(link.length > 0)
    {
      document.location.href = link;
    }
  }
}


/* SSO Cookie Check (to support caching) */

function ShowIfLoggedIn(id)
{
    if ( isLoggedIn() ) {
        var elm = document.getElementById(id);
        if (elm) {
            elm.style.display = "inline";
        }
    }
}

function HideIfLoggedIn(id)
{
    if ( isLoggedIn() ) {
        var elm = document.getElementById(id);
        if (elm) {
            elm.style.display = "none";
        }
    }
}

function isLoggedIn()
{
    var status = getCookie("SSO_LOGIN");
    if (status == null || status=='false') { status = false; }
    return status;
}

function getCookie(name)
{
    var thisCookie = document.cookie;
    var index = thisCookie.indexOf(name + "=");
    if (index == -1) return null;
    index = thisCookie.indexOf("=", index) + 1;
    var endstr = thisCookie.indexOf(";", index);
    if (endstr == -1) endstr = thisCookie.length;
    return unescape(thisCookie.substring(index, endstr));
}

function replStr(str,oldStr,newStr)
{ var strPos=str.indexOf(oldStr);
  return (strPos>=0) ?
    str.substring(0,strPos) + newStr +
       replStr( str.substring(strPos +
       oldStr.length), oldStr, newStr ) :
    str
}

function gotoUrlIE(url)
{
    if (g_is_ie) {
        gotoUrl(url);
    }
}

function splash(url,w,h){
	
	top.consoleRef=window.open('','myconsole',
  'width=' + w + ',height=' + h
   +',menubar=0'
   +',toolbar=0'
   +',status=0'
   +',scrollbars=0'
   +',resizable=1')
 top.consoleRef.document.writeln(
  '<html><head><title>Galeria</title></head>'
   +'<body bgcolor=white onLoad="self.focus()">'
   +'<img src="'+ url.replace("c.","g.") +'"/>'
   +'</body></html>'
 )
 top.consoleRef.document.close()
}

function imageReplace(miPlace,img,pic){
	var uno = img+"";
	document.getElementById(miPlace).src = uno.replace("Ch","Md");
	document.getElementsByClass('selected').className = '';
	pic.className = "selected";
}

function descarga(img){
	window.open(document.getElementById(img).src.replace("Md","Gr"),"Descarga")
}

function getElementsByClass(className,node){
	if(!node) node=document;
	var refTags = document.all ? node.all : document.getElementsByTagName("*");
	var retVal = new Array();
	for(var z=0;z<refTags.length;z++) {
		if(refTags[z].className == className) 
		retVal.push(refTags[z]);
	}
	return retVal; 
}

