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", "rgb(255,255,255)");
}

function setBackground(id, sBack)
{
    var elm = document.getElementById(id);
    if(elm)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)
{
    if(sUrl.indexOf('?') > -1)sUrl += "&" + getCachePrevent();
    else 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()
{
	// IE Hack for dropdowns
	ieToggleDropDowns(getListIEDropDowns(), false);
	
    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)
{
    if(sUrl.indexOf('?') > -1)sUrl += "&" + getCachePrevent();
    else 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)
    {
        // IE hack to prevent dropdowns to stay in view (which will then be visible within the popup layer).
        ieToggleDropDowns(getListIEDropDowns(), true);
    	
        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.width = imgWidth + 'px';
		elmImage.style.height = imgHeight + '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 imgZoom(el,imgs)
{
	var index = el.getAttribute("curr");
	var imgHeight = 480;
	var imgWidth = 640;
	
	var shadeborder = 8;
	var elmShade = document.getElementById("zoomImageShade");
	var elmImage = document.getElementById("zoomImage");
	
	var elmNext = document.getElementById("nextBtn");
	var elmPrev = document.getElementById("prevBtn");
	var elmCloseButton = document.getElementById("closeBtn");

	elmNext.style.lineHeight = imgHeight + 'px';
	elmNext.setAttribute('goto',eval(index) + 1 >= imgs.length ? 0 : eval(index) + 1);
	
	elmPrev.style.lineHeight = imgHeight + 'px';
	elmPrev.setAttribute('goto',eval(index) - 1 < 0 ? imgs.length - 1 : eval(index) - 1);

	elmCloseButton.style.lineHeight = imgHeight + 'px';
	elmCloseButton.style.width = (imgWidth - 100) + 'px';

	var imgX = g_pageWidth / 2 - imgWidth / 2;
	var imgY = Math.round( (viewportGetHeight() - imgHeight)/2 ) + viewportGetScrollY();
	
	elmImage.style.backgroundImage = "url("+imgs[index]+"&width=640)";
	elmImage.style.backgroundRepeat = 'no-repeat';
	elmImage.style.backgroundPosition = 'center';
	elmImage.style.width = imgWidth + 'px';
	elmImage.style.height = imgHeight + 'px';
	
	if (imgY < 0) { imgY = 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";

	elmImage.style.display = "block";
	elmShade.style.display = "block";	
}
function gotoImgZoom(el,imgs)
{
	var goto = el.getAttribute('goto');
	var img = document.getElementById('image'+goto);
	imgZoom(img,imgs);
}
function closeImgZoom()
{
	hideLr("zoomImageShade");
    hideLr("zoomImage");
}
function previewZoom(el,imgs)
{
	var index = el.getAttribute('curr');
	var pEl = document.getElementById('previewImage');
	pEl.childNodes[0].setAttribute('src',imgs[index]+'&width=320');
	pEl.setAttribute('curr',index);
}
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";
    }
}
var tm;
function scrollImages(el,inc){
	var elem = document.getElementById(el);
	var olds = elem.scrollLeft;
	var selR = document.getElementById('scrollRight');
	var selL = document.getElementById('scrollLeft');

	if(inc > 0){
		var stop = eval(selR.getAttribute('stop'));
		var step = eval(selR.getAttribute('step'));
		var stopCond = eval(elem.scrollLeft >= stop);
	}
	else{
		var stop = eval(selL.getAttribute('stop'));
		var step = eval(selL.getAttribute('step'));
		var stopCond = eval(elem.scrollLeft <= stop);
	}
		
	elem.scrollLeft += inc;
	if(stopCond || elem.scrollLeft == olds){
		window.clearTimeout(tm);
		selR.setAttribute('stop',(inc > 0 && elem.scrollLeft == olds) ? olds : (stop + step));
		selL.setAttribute('stop',(inc < 0 && elem.scrollLeft == olds) ? 0 : (stop - step));
	}
	else{
		tm = window.setTimeout('scrollImages(\''+el+'\','+inc+')', 10);
	}
	
}

/* 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(255,255,255)";              
        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 = "rgb(0,0,0)";
        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 = "/scripts/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 showGalleryPanoramaFlash(url, flashParams)
{
    var elmImg = document.getElementById("galleryImage");
    if (elmImg) {
        g_fallbackImage = elmImg.src;
    }
   
    showFlash(url, "galleryContent", "595", "317", "7", "#FFFFFF","loop=true,menu=true,quality=high,wmode=opaque","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) {

/* AKAMAI-HACK */
/*
if (url.indexOf('/') == 0)
{
  url = 'http://files.porsche.com' + url;

  if (flashparamstr.indexOf('xmlurl=/') > -1)
  {
    flashparamstr = flashparamstr.replace('xmlurl=/','xmlurl=http://files.porsche.com/');
  }
  else if (flashparamstr.indexOf('flashfolder') < 0)
  {
     flashparamstr += ',flashfolder=http://files.porsche.com/all/media/flash/';
  }
  
  if (flashparamstr.indexOf('basefolder') < 0)
  {
     flashparamstr += ',basefolder=http://files.porsche.com';
  }

}
*/



    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 n = getGalleryItemNo();
	if (n == -1) n=1;
		
    var subtitles = document.getElementById("gallerySubtitles")               	
    if (subtitles) {
        subtitles.style.display = "block";
        showGallerySubtitle(n);
    }

	var claims = document.getElementById("galleryClaims")
    if (claims) {        
			        
	    claims.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 tabSubtitles = subtitles.getElementsByTagName("div");
		 	        		
		var tab = document.getElementById("gallerySubtitlesTab" + getGallerySubtitleTabNo());
		if (tab) 
		{
			tabSubtitles = tab.getElementsByTagName("div");	
			tab.style.display = "block";				
		}
						
		if (tabSubtitles) 
		{            
			for (var i = 0; i < tabSubtitles.length; i++) {
				tabSubtitles[i].style.display = (i == n - 1) ? "block" : "none";				
			}
		}
    }
}


function showGalleryClaim(n) {
    var claims = document.getElementById("galleryClaims");	   
    if (claims) 
    {    	
        var tabClaims = claims.getElementsByTagName("div");  
        
        var tab = document.getElementById("galleryClaimsTab" + getGallerySubtitleTabNo());
		if (tab) 
		{
			// zuerst nach Div suchen
			tabClaims = tab.getElementsByTagName("div");
			// 15.03.2006 by BU + MIP 
			// wenn kein <Div> vorhanden dann <Img> nehmen
			if (tabClaims.length == 0) {
				tabClaims = tab.getElementsByTagName("img");
			}
			tab.style.display = "block";				
		}
		          
        if (tabClaims) {            
            for (var i = 0; i < tabClaims.length; i++) {
                tabClaims[i].style.display = (i == n - 1) ? "block" : "none";                
            }
        }
    }    
}


function getGalleryClaimTab()
{   
    var claim = document.getElementById("galleryClaims");
	return claim;	
}


function getGallerySubtitleTab()
{    
    var tab = document.getElementById("gallerySubtitles");    
    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 = 32; 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)
{
    /* For new CC inner size is important, but gotoUrlNewWinSizeByName() calcs outer size */
    var sWidth = 980;
    var sHeight = 680;
    sWidth -= g_is_ie ? 15 : 20;
    sHeight -= 25;
	
	/* R.W. Anpassung fŸr den Intranet Server, um unterschiedliche CC URL's auszuliefern.*/
	var HostName = "";
	if (window.location.hostname == "intranet.porsche.com") {
		HostName = "http://cc.intranet.porsche.com";
	} else {
		HostName = "http://cc.porsche.com";
	}
		
    switch (marketId) {
        case "de":
            gotoUrlNewWinSizeByName(HostName + "/icc_euro/ui/pva/index.jsp?sprache=de&modelRange=null", sWidth, sHeight, "PVA");
            break;

        case "us":
            gotoUrlNewWinSizeByName(HostName + "/pva_new/ui/pva/index.jsp?sprache=us&modelRange=null", sWidth, sHeight, "PVA");
            break;

        case "ca":
            gotoUrlNewWinSizeByName(HostName + "/pva_new/ui/pva/index.jsp?sprache=ca&modelRange=null", sWidth, sHeight, "PVA");
            break;

        case "fr":
            gotoUrlNewWinSizeByName(HostName + "/icc_euro/ui/pva/index.jsp?sprache=fr&modelRange=null", sWidth, sHeight, "PVA");
            break;

        case "it":
            gotoUrlNewWinSizeByName(HostName + "/icc_euro/ui/pva/index.jsp?sprache=it&modelRange=null", sWidth, sHeight, "PVA");
            break;

        case "en":
            gotoUrlNewWinSizeByName(HostName + "/icc_euro/ui/pva/index.jsp?sprache=en&modelRange=null", sWidth, sHeight, "PVA");
            break;

        case "sp":
            gotoUrlNewWinSizeByName(HostName + "/icc_euro/ui/pva/index.jsp?sprache=sp&modelRange=null", sWidth, sHeight, "PVA");
            break;

        case "me":
            gotoUrlNewWinSizeByName('/all/transitional/middle-east/models/countryselector/default.htm', sWidth, sHeight, 'PVA');
            break;
		
        case "jp":
            gotoUrlNewWinSizeByName(HostName + "/icc_euro/ui/pva/index.jsp?sprache=pj&modelRange=null", sWidth, sHeight, "PVA");
            break;

        default:
            gotoUrlNewWinSizeByName(HostName + "/icc_euro/ui/pva/index.jsp?sprache=" + marketId + "&modelRange=null", sWidth, sHeight, "PVA");
            break;

    }
}

/*
Function compareModels
Description: 
	Wrapper for compareModelMulti with empty model parameters. Is mainly used to open the CM Popup from the shopping buttons.
Input: 
	marketId: name of the market to be loaded in compare models.
Output: void
*/
function compareModels(marketId) {
	compareModelMulti(marketId, '', '', '', true);
}

/*
Function compareModelWith
Description:
	Wrapper for compareModelMulti to Open compare models tool (select page) with the given market name and two models to be compared to each other. 
Input:
	marketId: market name
	model1: First model's id.
	model2: Second model's id.	
Output: void.	
*/
function compareModelWith(marketId, model1, model2) {
	compareModelMulti(marketId, model1, model2, '', false);
}


/*
Function compareModelMulti
Description:
	Opens a popup window of variable size. 
	to load the compare models page for a given market, and three model IDs.
	The size can be adjusted for each market (pool) by setting the oneSizeFitsAll to false 
	and defining windowSizeX and windowSizeY for each pool.
Input:
	marketId: market (pool) name to be opened in the compare models tool.
	model1: First model's id.
	model2: Second model's id.	
	model3: Third model's id.
	openSelect: true if Select page is to be opened, false if compare page.
	(If further models are to be added, make the necessary changes in the url "cmUrl" and the window sizes.)
Output: void.	
*/
function compareModelMulti(marketId, model1, model2, model3, openSelect) {
	windowSizeX = 975;
	windowSizeY = 625;
	oneSizeFitsAll = true;

	if (openSelect) 
		cmPage = "Select"
	else
		cmPage = "Compare";
		
	// make the window sizes pool dependent, if desired.
	if (!oneSizeFitsAll)
		switch (marketId) {
			case "usa":
				windowSizeX = 975;
				windowSizeY = 625;
				break;
			case "canada":
				windowSizeX = 975;
				windowSizeY = 625;
				break;
		}
	// create the window and load the url.
	cmUrl = "http://www.porsche.com/all/comparemodels/" +cmPage + ".aspx?pool=" + marketId + "&model1=" + model1 + "&model2=" + model2 + "&model3=" + model3 + "";
	//gotoUrlNewWinSize(cmUrl, windowSizeX, windowSizeY);
	gotoUrlNewWinSizeByName(cmUrl, windowSizeX, windowSizeY, "compareModels");
}


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=yes");
}


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 gotoUrlNewWinSizeScrollableWithMenuR(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=yes,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 gotoUrlNewWinSizeScrollableResizeable(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=yes,scrollbars=yes,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");
            g_timeoutHide1 = setTimeout("hideNav(1,\"" + g_currentNav1 + "\",\"" + g_currentHi1 + "\")", g_timeoutTime);      
        }
        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/arrow-red.gif)";
            }
        }
        else
        {
            elem.style.color = "rgb(204, 0, 0)";

            if (! (elem.className.indexOf("final") >= 0) )
            {
                elem.style.backgroundImage = "url(/images/arrow-red.gif)";
            }

            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(255,255,255)";
            elem.style.backgroundColor = "transparent";
            if (! (elem.className.indexOf("final") >= 0) )
            {
                elem.style.backgroundImage = "url(/images/arrow-white.gif)";
            }
        }
        else
        {
            elem.style.color = "rgb(0, 0, 0)";
            if (! (elem.className.indexOf("final") >= 0) )
            {
                elem.style.backgroundImage = "url(/images/arrow-gray.gif)";
            }

            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 gotoUrlDropDown(e)
{
	if (e.options)
	{
		var url = e.options[e.options.selectedIndex].value;
		gotoUrl(url);			
	}
}

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)
{
    g_psyma_navi_clicked = true;
    if (g_is_ie) {
        gotoUrl(url);
    }
}

function submitSDSTrainingSearchForm()
{
	var sfsForm = document.getElementById("SDSTrainingSearchForm");
	if (sfsForm.month.options.selectedIndex != 0)
		sfsForm.submit();
}

//
// Function ieToggleDropDowns: 
//
// Description: Toggles dropdown visibility in case of a dynamic layer 
// covering them pops up, and has a z-index higher than these. IE does not handle them correctly.
//
// Input: 
// 		strAttr: String Array, whose elements are the <DIV> id's to toggle. See function: getListIEDropDowns() 
//		boolHide: Boolean toggle. true, if the layer should be made visible, false otherwise.
// Returns : none.
function ieToggleDropDowns(strArr, boolHide) {
	// collection of dropdowns
	
	if (strArr.length > 0) {
		for (i=0; i < strArr.length; i++) {
			dd = document.getElementById(strArr[i]);
			if (dd) 
				if (boolHide) 
				{
					dd.style.visibility = 'hidden'
				}
				else
				{
					dd.style.visibility = 'visible';
				}
		}
	}
}

//
// Function getListIEDropDowns():
//
// Description: Builds an array of Dropdowns whose visibility should be toggled 
// in case of a dynamic layer covering them.
// Input: none.
// Returns: String array of <DIV> id's.
function getListIEDropDowns() {
	return (new Array("monthDropDown"));
}

/*
	Created		: 09.01.2006 by Martin Ibanez
	Last edited	: 10.01.2006 by Martin Ibanez
	Comment		: Wurde fr die Galerie erstellt
*/
function showGalleryQuicktime(src)
{
	var elmImg = document.getElementById("galleryImage");
    if (elmImg) {
        g_fallbackImage = elmImg.src;
    }
    
	showQuicktime(src, 'galleryContent', '595', '317');
}

/*
	Created		: 09.01.2006 by Martin Ibanez
	Last edited	: 28.03.2006 by Stefan Kokemueller
	Comment		: Wurde fr die Galerie erstellt
*/
function showQuicktime(src, layer , width, height)
{
	var elm = document.getElementById(layer);
	
	if (src.indexOf('_fullscreen.mov') > 0)
	{
		showFullscreenQuicktime(src);
	}
    else if (src.indexOf('_object.mov') > 0)
	{
		showFullscreenQuicktimeObject(src);
	}
	else if (elm && haveqt)
	{
		var qtstring = '';
		qtstring += '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" width="'+width+'" height="'+height+'" id="galleryQuicktimeMovie">' 
		qtstring += '<param name="src" value="'+src+'"><embed height='+height+' width='+width+' src="'+src+'" type="video/quicktime" pluginspage="www.apple.com/quicktime/download" enablejavascript="true" name="galleryQuicktimeMovie" />'
		qtstring += '</object>'
		
		elm.innerHTML = qtstring;
	}
}

/*
	Created		: 09.01.2006 by Martin Ibanez
	Last edited	: 10.01.2006 by Martin Ibanez
	Comment		: Wurde fr die Galerie erstellt
*/
function showFullscreenQuicktime(src)
{
	if (haveqt)
	{
		sWidth = window.screen.availWidth;
		sHeight = window.screen.availHeight;
		var doc = window.open("/all/transitional/all/panoramaPopup/panoramaPopup.asp?qt=" + src, "newWin" + getRandomInt(10000), "width=" + sWidth + ",height=" + sHeight + ",left=0,top=0,dependent=yes,location=no,resizable=yes,scrollbars=no,status=no");			
		doc.focus();
	}
}

/*
	Created		: 28.03.2006 by Stefan Kokemueller
	Last edited	: 28.03.2006 by Stefan Kokemueller
	Comment		: Wurde fr die Galerie erstellt
*/
function showFullscreenQuicktimeObject(src)
{
	if (haveqt)
	{
		sWidth = window.screen.availWidth;
		sHeight = window.screen.availHeight;
		var doc = window.open("/all/transitional/all/panoramaPopup/objectPopup.asp?qt=" + src, "newWin" + getRandomInt(10000), "width=" + sWidth + ",height=" + sHeight + ",left=0,top=0,dependent=yes,location=no,resizable=yes,scrollbars=no,status=no");			
		doc.focus();
	}
}
function showPanoramaPopup(pool, id, lang, panoramaversion, width, height, callpath)
{
	sWidth = window.screen.availWidth;
	sHeight = window.screen.availHeight;
	
	if(width && width > 0)
	{
		sWidth = width;		
	}
	
	if(height && height > 0)
	{
		sHeight = height;		
	}
	
	var url = "/panoramaPopup.aspx?Pool=" + pool + "&ID=" + id + "&Lang=" + lang + "&Panoramaversion=" + panoramaversion;	
	if (callpath && callpath.length > 0)
	{
		url += "&callpath=" + callpath;
	}
	
	var doc = window.open(url , "newWin" + getRandomInt(10000), "width=" + sWidth + ",height=" + sHeight + ",left=0,top=0,dependent=yes,location=no,resizable=yes,scrollbars=no,status=no");			
	doc.focus();
}
function writePopupQuicktimeObject(src,width,height)
{	
	if(haveqt)
	{
		var s = '';								
	
		var sWidth = '100%';
		var sHeight = '100%';
	
		var divWidth = "100%";
		var divHeight = "87%";
		
		if (width && width > 0)
		{
			sWidth = width;
			divWidth = width;
		}
		
		if (height && height > 0)
		{			
			sHeight = height + 15;
			divHeight = height + 15;
			
			if ( viewportGetHeight() > (sHeight + 50) )
			{
			  spacerHeight = (viewportGetHeight() - sHeight) * 0.43;					  
			  s += '<div style="height: ' + spacerHeight + 'px; width:100%; font-size:1px;"></div>\n';
			}
			else
			{
			  document.body.style.overflow = 'auto';
			}			
		}	
		
		s += '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" width="'+sWidth+'" height="'+sHeight+'" codebase="http://www.apple.com/qtactivex/qtplugin.cab" id="quicktimePlugin">';
		s += '	<param name="scale" value="tofit"><param name="controller" value="true"><param name="cache" value="false"><param name="bgcolor" value="#E9E9E9"><param name="volume" value="30"><param name="kioskmode" value="false"><param name="moviename" value="spincontrolled">';
		s += '	<param name="src" value="'+src+'">';
		s += '	<embed src="'+src+'" ';
		s += '		width="'+sWidth+'" ';
		s += '		height="'+sHeight+'" ';
		s += '		type="video/quicktime" ';
		s += '		controller="true"';
		s += '		cache="false" ';
		s += '		volume="30"';
		s += '		kioskmode="false"';
		s += '		scale="tofit" ';
		s += '		pluginspage="http://www.apple.com/quicktime/download/" ';
		s += '		bgcolor="#E9E9E9"';
		s += '		moviename="spincontrolled"';
		s += '		/>';
		s += '</object>';
		
		var elm = document.getElementById('panorama');	
		if(elm)
		{
			elm.style.width = divWidth;
			elm.style.height = divHeight;		
			elm.innerHTML = s;
		}			
		
	}
	else
	{
		document.getElementById('noPlugin').style.display = 'block';
		document.getElementById('claim').style.display = 'none';
	}	
}
function myreplace(text,from,to) 
{
	ti = text.indexOf(from);
	text = text.substring(0,ti)+to+text.substr(ti+from.length);
	
	return text;
} 
function writePopupFlashObject(src,width,height)
{	
	if (getFlashVersion() > 6)
	{
		var sWidth = '100%';
		var sHeight = '100%';
		
		var divWidth = '100%';
		var divHeight = '87%';
		
		if (width && width > 0)
		{
			sWidth = width;
			divWidth = width;
		}
		
		if (height && height > 0)
		{
			sHeight = height;
			divHeight = height;
		}

		var elm = document.getElementById('panorama');	
		if(elm)
		{
			elm.style.width = divWidth;
			elm.style.height = divHeight;
		}	
			
		// show flash
		showFlash(src, 'panorama', sWidth, sHeight, 6, '#E9E9E9', 'loop=true,menu=true,quality=high,wmode=opaque', null)
		
	}
	else
	{
		document.getElementById('noPlugin').style.display = 'block';
		document.getElementById('claim').style.display = 'none';
	}	
}
// gehrt zu jeder gescheiten JS-Bibliothek.
function trim(str)
{
 	return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}