/************************************/
/* Erweiterung für JD Power 2008/03 */
/* -> Mouseovers konfiguriertbar    */
/* -> hl = "hilite"                 */
/* -> ll = "lolite"                 */
/************************************/



var g_homemenu_hl_fontcolor = "rgb(204, 0, 0)";
var g_homemenu_hl_background_color = "rgb(255,255,255)";
var g_homemenu_hl_background_color_Level5 = "rgb(255,255,255)";
var g_homemenu_ll_fontcolor_level0 = "rgb(255,255,255)";
var g_homemenu_ll_fontcolor_level1 = "rgb(0, 0, 0)";
var g_homemenu_ll_background_color = "transparent";
var g_homemenu_ll_background_image_level0 = "url(/Images/arrow-white.gif)";
var g_homemenu_ll_background_image_level1 = "url(/Images/arrow-gray.gif)";
var g_jdpowerphase = "none";

var g_kabseLinkCurrentPosition = -1; // STV, 2007.10.25: für vor/zurück im KBaseLayer
var g_refresh = false;

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_MAXSUBLAYERS = 16;

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_ie6 = false;
var g_is_safari = false;
// var g_is_macmoz = false; // mozilla on mac has flash problems on the homepage.
var g_is_mac = false;
var g_is_linux = false;
var g_contextDebug = "";
var g_fallbackImage = "";

var g_newWinFocus;



/****************************************/
//global control variables for flash homepage.
// turns flash on homepage on/off globally.
var g_useFlashHomepage;
// load flash hp configuration in the following xml object; 
var g_xmlFlashHPConfig;
// also, copy the [pool].jpg into the fallback images directory.
var g_flashHPFallbackOverride;
/****************************************/




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;
    if (document.getElementById) {
        g_canHandleTransparency = !g_is_ie5;
    }
    else if (noteConflict) {
        gotoUrl("http://www.porsche.com/browser.htm");
    }
    if (g_is_home) {
        initHome();
    }
}

function isInteger (s)
{
    var i;

    if ((s == null) || (s.length == 0))
    if (isInteger.arguments.length == 1) return 0;
    else return (isInteger.arguments[1] == true);

    for (i = 0; i < s.length; i++)
    {
        var c = s.charAt(i);

        if (!isDigit(c)) return false;
    }

    return true;
}


function isDigit (c)
{
    return ((c >= "0") && (c <= "9"))
}





function setIntroImageBorder() {
	var elm = document.getElementById('introImage');
	if (elm) {
		elm.style.borderBottom = 'solid 1px #CECECE';
		elm.style.width = '615px';
	}
}



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;

	if (getPoolName() == "usa") {
	    var navi = document.getElementById("sitenavigation");
	    if (navi) {
	        //alert(navi.offsetHeight);
	        size = 128 + navi.offsetHeight + 24 + 20; /* = Wappen + Navi + Mindestabstand zum Footer + Hoehe Footer*/
	        if(g_is_ie6)
	           size += 40;
	    }
	}
	else {
	    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) {
	if(s)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 toggleMilkyBackground(onOff)
{
    var milkyBG = document.getElementById("kbaseMilkyBG");

    if (onOff == "on")    
    {
        if (milkyBG) return;
        // insert semi-transparent milky background
        var transbg = document.createElement("div");
        var trbgstyle = document.createAttribute("id");
        trbgstyle.nodeValue = "kbaseMilkyBG";
        transbg.setAttributeNode(trbgstyle);
        var kBaseLayer = document.getElementById("knowledgeBase");
        if (kBaseLayer && kBaseLayer.parentNode)
        {
            kBaseLayer.parentNode.appendChild(transbg, kBaseLayer);
            //kBaseLayer.parentNode.insertBefore(transbg, kBaseLayer);
        }
            
    }
    else
    {
        if (milkyBG)
        {   
            milkyBG.style.display = "none";
            if (document.removeChild)
                milkyBG.parentNode.removeChild(milkyBG);
        }
    }
}

function clickKnowledgebase(sUrl)
{

    if ((g_openKnowledgeBase == 0) || g_refresh)
    {       
        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");

        if (getPoolName() == 'usa') 
        {
            g_pageWidth = 1063;
        }
        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()
{
    toggleMilkyBackground("off");
    
	// 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 += addKnowledgebasePrevNextButtons(); // STV
            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;
            
            //addKnowledgebasePrevNextButtons(elmKB) // STV

            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); }
         
            if(getPoolName() == 'usa')
                toggleMilkyBackground("on");

            moveKbButtons(); // STV
            
            
        }
        else
        {
            alert("Can't retrieve XML: " + g_req.statusText);
        }
    }
}

function moveKbButtons()
{
    var naviKB = document.getElementById('kbNavi');
    var elmKB = document.getElementById("knowledgeBase");
    if(elmKB && naviKB)
    {
        var kbaseHeading = elmKB.getElementsByTagName('h2')
        if(kbaseHeading)
        {
            kbaseHeading[0].appendChild(naviKB);
        }
    }
    g_refresh = false;
}
function clickNext()
{
    var nextKBLink = document.getElementById('kbaseLink' + (g_kabseLinkCurrentPosition + 1));
    if(nextKBLink)
    {
        //alert(nextKBLink.href.replace('javascript:', ''));
        g_refresh = true;
        eval(nextKBLink.href);
    }
}
function clickPrevious()
{
    var previousKBLink = document.getElementById('kbaseLink' + (g_kabseLinkCurrentPosition - 1));
    if(previousKBLink)
    {
        g_refresh = true;
        eval(previousKBLink.href);
    }
}
function addKnowledgebasePrevNextButtons()
{
    if(g_kabseLinkCurrentPosition == -1)
        return '';

    var linkButtons = '';
    var renderPrevButton = document.getElementById('kbaseLink' + (g_kabseLinkCurrentPosition - 1));
    var renderNextButton = document.getElementById('kbaseLink' + (g_kabseLinkCurrentPosition + 1));
    linkButtons += '<div id="kbNavi">'

    if (getPoolName() == 'usa') {
        if (renderPrevButton)
            linkButtons += '<a id="kbPrev" title="Previous Topic: ' + renderPrevButton.title + '" href="javascript: clickPrevious();"><img src="/images/jdp_layer_previous.gif" /></a>';
        //if (renderPrevButton && renderNextButton)
            //linkButtons += '<img src="/images/kbasenavi-line.gif" />'
        if (renderNextButton)
            linkButtons += '<a id="kbNext" title="Next Topic: ' + renderNextButton.title + '"  href="javascript: clickNext();"><img src="/images/jdp_layer_next.gif" /></a>';
    }
    else {
        if (renderPrevButton)
            linkButtons += '<a id="kbPrev" title="Previous Topic: ' + renderPrevButton.title + '" href="javascript: clickPrevious();"><img src="/images/kbasenavi-previous.gif" /></a>';
        if (renderPrevButton && renderNextButton)
            linkButtons += '<img src="../images/kbasenavi-line.gif" />'
        if (renderNextButton)
            linkButtons += '<a id="kbNext" title="Next Topic: ' + renderNextButton.title + '"  href="javascript: clickNext();"><img src="/images/kbasenavi-next.gif" /></a>';
    }
    
    linkButtons += '</div>'

    return linkButtons;    
}

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";
    }
}

function toggleLr(id)
{
    var elm = document.getElementById(id);
    if (!elm) return;
    
    if (elm.style.display != "block") showLr(id);
    else hideLr(id);
}



/* 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 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 JSONify(str) {
    
    //alert("JSONify ing: " + str);
    if (str == undefined || str == null) return "{}";
    var json = "{";
    var trap = false;
    var params = str.split(",");
    for (var i = 0; i < params.length; i++) {
        var param = params[i].split("=");
        if (param[0] == undefined || param[0] == null || param[0] == "") {
            trap = true;
            continue;
        }
        else {
            if (i > 0 && !trap) {
                json += ",";
                trap = false;
            }
            json += param[0] + ":\"" + param[1] + "\"";
        }
    }
    json += "}";
    return eval('(' + json + ')');
   
}


function swfIsVideoPlayer(url) {
    var retVal = false;
    var FILENAME = 'videoplayer.html';
    var foundSWF = url.substr(url.lastIndexOf('http://www.porsche.com/') + 1);

    if (foundSWF && (foundSWF.toLowerCase() == FILENAME))
        retVal = true;

    return retVal;
}



/* 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) {
        showGallerySubtitle(n);
        subtitles.style.display = "block";
    }

	var claims = document.getElementById("galleryClaims")
    if (claims) {
	    showGalleryClaim(n);	        
        claims.style.display = "block";
    }
}


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";				
		}

		/************************/
		/* STV: JDPower 2008-11 */
		var currentPool = getPoolName();
		var gallerySubtitleDisplayStyle = "block";
		if (currentPool == "usa")
		    gallerySubtitleDisplayStyle = "inline";
		/************************/

		if (tabSubtitles) 
		{            
			for (var i = 0; i < tabSubtitles.length; i++) {
			    tabSubtitles[i].style.display = (i == n - 1) ? gallerySubtitleDisplayStyle : "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";				
		}

        /************************/
        /* STV: JDPower 2008-11 */
		var currentPool = getPoolName();
		var galleryClaimDisplayStyle = "block";
		if (currentPool == "usa")
		    galleryClaimDisplayStyle = "inline";
		/************************/
		
        if (tabClaims) {            
            for (var i = 0; i < tabClaims.length; i++) {
                tabClaims[i].style.display = (i == n - 1) ? galleryClaimDisplayStyle : "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 = 50; 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)
}

function openPDDSShop(poolId) {
	switch (poolId) {
		case "germany":
			gotoUrlNewWinSizeScrollableWithMenuR('http://shop.porsche.com/germany/',870,700);
			break;
		
		case "usa":
			openPDDSPopup('http://shop.porsche.com/usa/',false);
			break;
		
		case "uk":
			openPDDSPopup('http://shop.porsche.com/uk/', false);
			break;
		
		case "france":
			openPDDSPopup('http://shop.porsche.com/france/', false);
			break;

		case "italy":
			openPDDSPopup('http://shop.porsche.com/italy/', false);
			break;

		case "australia":
			openPDDSPopup('http://shop.porsche.com/australia/', false);
			break;
	}
}

function openPDDSPopup(s, isRedesign) {
	var sWidth
	var sHeight;
	var sOffset;
	
	var resizable = 'no';
	var locationbar = 'no';
	var toolbar = 'no';
	var menubar = 'no';

	if (isRedesign) {
		sWidth = 890;
		sHeight = 750;
		resizable = 'yes';
		locationbar = 'yes';
		toolbar = 'yes';
		menubar = 'yes';
	}
	else {
		sWidth = 890;
		sHeight = 725;
	}
		
	
    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=40,top=40,dependent=yes,location=" + locationbar + ",menubar=" + menubar + ",toolbar=" + toolbar + ",resizable=" + resizable + ",scrollbars=yes,status=no");
}


// sMarket = Language / market version e.g. 'us' for PCNA market
// sModel = The Model typecode e.g. '987110'
// sMode = '2D', '3D' or null
function openCC(sMarketId, sModel, sMode, blnOpenWindow)
{
    var sWidth = 980;
    var sHeight = 680;
    sWidth -= g_is_ie ? 15 : 20;
    sHeight -= 25;
    var sUrl = '';
    var sHostName = '';
    var sOriginHostName = '';
    var sLang = '';
    var iViewMode=0;
    if(blnOpenWindow == null)blnOpenWindow = true;
    if(g_is_mac == true && sMode != null)sMode='2D';
	
	  switch(window.location.hostname) {
	      case "intranet.porsche.com":
		      sHostName = "http://cc.web.porsche.de/";
		      sOriginHostName = "http://cc.web.porsche.de/";
		      break;
        case "preview.porsche.com":
		      sHostName = "http://testarea-cc.porsche.com/";
		      sOriginHostName = "http://testarea-cc.porsche.com/";
		      break;
        default:
		      sHostName = "http://cc.porsche.com/";
		      OriginHostName = "http://origin-cc.porsche.com/";
		      break;
	  }

    if(sMode == null) {
      if(sModel == null) {
        sUrl = sHostName + "/pva_new/ui/pva/index.jsp?sprache={LANG}&modelRange=null";
      }
      else {
        sUrl = sHostName + "/pva_new/colorConfigurator.do?userID={USER}&lang={LANG}&PARAM={PARAM}&ORDERTYPE={MODEL}";
      }
    }
    else {
      if(sMode == '2D')iViewMode=2;
      if(sMode == '3D')iViewMode=4;
      if(sModel == null) {
        sUrl = sHostName + "/pva_new/preConfiguration.do?userID={USER}&lang={LANG}&PARAM={PARAM}&PRECONFIG_ID=default&vLevel={MODE}";
      }
      else {
        sUrl = sHostName + "/pva_new/preConfiguration.do?userID={USER}&lang={LANG}&PARAM={PARAM}&PRECONFIG_ID=default&vLevel={MODE}";
      }
    }

    switch (sMarketId) {
        case "us":
            sUser = "US";
            sLang = "us"
            sParam = "parameter_internet_us"
            break;
            
        default:
            sUrl = sHostName + "/pva_new/colorConfigurator.do?userID=US&lang=us&PARAM=parameter_internet_us&ORDERTYPE=" + sModel;
            break;
    }
    if(sUrl != '') {
      sUrl = sUrl.replace(/{USER}/g, sUser);
      sUrl = sUrl.replace(/{LANG}/g, sLang);
      sUrl = sUrl.replace(/{PARAM}/g, sParam);
      sUrl = sUrl.replace(/{MODEL}/g, sModel);
      sUrl = sUrl.replace(/{MODE}/g, iViewMode);
      
    var screenParam = getScreenXYUrlParam();
    
    // CC Down Hack
    //sUrl = sHostName + "/maintenance/CC_down.html";
    if (sUrl && sUrl.length > 0)
        sUrl += screenParam;
      
      
      if(blnOpenWindow)gotoUrlNewWinSizeByName(sUrl, sWidth, sHeight, "PVA");
      else window.location.href=sUrl;
    }
}


/* 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.web.porsche.de/";
		OriginHostName = "http://cc.web.porsche.de/";
	} else if (window.location.hostname == "preview.porsche.com") {
		HostName = "http://testarea-cc.porsche.com/";
		OriginHostName = "http://testarea-cc.porsche.com/";
	} else {
		HostName = "http://cc.porsche.com/";
		OriginHostName = "http://origin-cc.porsche.com/";
	}
		
    var sUrl = '';
    switch (marketId) {
        case "de":
            sUrl = HostName + "/icc_euro/ui/pva/index.jsp?sprache=de&modelRange=null";
            break;

        case "us":
            /* JDPower Test */
            sUrl = "http://www.porsche.com/all/usa/startcc/default.htm?t=";
            //sUrl = HostName + "/pva_new/ui/pva/index.jsp?sprache=us&modelRange=null";
            break;

        case "ca":
            sUrl = HostName + "/pva_new/ui/pva/index.jsp?sprache=ca&modelRange=null";
            break;

        case "fr":
            sUrl = HostName + "/icc_euro/ui/pva/index.jsp?sprache=fr&modelRange=null";
            break;

        case "it":
            sUrl = HostName + "/icc_euro/ui/pva/index.jsp?sprache=it&modelRange=null";
            break;

        case "en":
            sUrl = HostName + "/icc_euro/ui/pva/index.jsp?sprache=en&modelRange=null";
            break;

        case "sp":
            sUrl = HostName + "/icc_euro/ui/pva/index.jsp?sprache=sp&modelRange=null";
            break;

        case "mx":
            sUrl = HostName + "/icc_euro/ui/pva/index.jsp?sprache=mx&modelRange=null";
            break;
            
        case "hk":
            sUrl = HostName + "/icc_euro/ui/pva/index.jsp?sprache=hk&modelRange=null";
            break;
		
        case "me":
            sUrl = "http://www.porsche.com/all/transitional/middle-east/models/countryselector/default.htm?t=";
            break;
		
        case "jp":
            sUrl = HostName + "/icc_euro/ui/pva/index.jsp?sprache=pj&modelRange=null";
            break;

        case "zh":
            sUrl = HostName + "/icc_euro/ui/pva/index.jsp?sprache=cn";
            break;
        case "ce":
            sUrl = HostName + "/icc_euro/ui/pva/index.jsp?sprache=ce&market=PACCE";
            break;
        case "ba":
            sUrl = HostName + "/icc_euro/ui/pva/index.jsp?market=PDB&sprache=ba";
            break;
        case "va":
            sUrl = HostName + "/icc_euro/ui/pva/index.jsp?market=PDD&sprache=va";
            break;
        case "kw":
            sUrl = HostName + "/icc_euro/ui/pva/index.jsp?market=PDK&sprache=kw";
            break;
        case "oa":
            sUrl = HostName + "/icc_euro/ui/pva/index.jsp?market=PDO&sprache=oa";
            break;
        case "qu":
            sUrl = HostName + "/icc_euro/ui/pva/index.jsp?market=PDT&sprache=qu";
            break;
        case "ks":
            sUrl = HostName + "/icc_euro/ui/pva/index.jsp?market=PDS&sprache=ks";
            break;
        case "cur":
            sUrl = HostName + "/icc_euro/ui/pva/index.jsp?sprache=cc&customID=cur";
            break;
        case "pap":
            sUrl = HostName + "/icc_euro/ui/pva/index.jsp?sprache=cc&customID=pap";
            break;
        case "bru":
            sUrl = HostName + "/icc_euro/ui/pva/index.jsp?sprache=cc&customID=bru";
            break;
        case "ind":
            sUrl = HostName + "/icc_euro/ui/pva/index.jsp?sprache=cc&customID=ind";
            break;
        case "mal":
            sUrl = HostName + "/icc_euro/ui/pva/index.jsp?sprache=cc&customID=mal";
            break;
        case "nca":
            sUrl = HostName + "/icc_euro/ui/pva/index.jsp?sprache=cc&customID=nca";
            break;
        case "sri":
            sUrl = HostName + "/icc_euro/ui/pva/index.jsp?sprache=cc&customID=sri";
            break;
        case "phi":
            sUrl = HostName + "/icc_euro/ui/pva/index.jsp?sprache=cc&customID=phi";
            break;
        case "du":
            sUrl = HostName + "/icc_euro/ui/pva/index.jsp?sprache=du&market=PDA";
            break;
        case "sa":
            sUrl = HostName + "/icc_euro/ui/pva/index.jsp?sprache=sa&market=PDR";
            break;
		case "prt":
			sUrl = HostName + "/icc_euro/ui/pva/index.jsp?sprache=po";
			break;
		case "swiss-de":
			sUrl = HostName + "/icc_euro/ui/pva/index.jsp?market=CHSD&sprache=sd";
			break;
		case "swiss-fr":
			sUrl = HostName + "/icc_euro/ui/pva/index.jsp?market=CHSF&sprache=sf";
			break;
		case "swiss-it":
			sUrl = HostName + "/icc_euro/ui/pva/index.jsp?market=CHSI&sprache=si";
			break;
	
        default:
            sUrl = HostName + "/icc_euro/ui/pva/index.jsp?sprache=" + marketId + "&modelRange=null";
            break;
    }
    
    var screenParam = getScreenXYUrlParam();
    
    if (sUrl && sUrl.length > 0)
        sUrl += screenParam;

    // CC Down Hack
    //sUrl = HostName + "/maintenance/CC_down.html";
    gotoUrlNewWinSizeByName(sUrl, sWidth, sHeight, "PVA");
        
}


function getScreenXYUrlParam()
{
    var clientWidth = screen.width;
    var clientHeight = screen.height;
    return  '&screen='+clientWidth+'x'+clientHeight;
}

/*
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 = 1003;
	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 = 1003;
				windowSizeY = 625;
				break;
			case "canada":
				windowSizeX = 975;
				windowSizeY = 625;
				break;
		}
	// create the window and load the url.
	cmUrl = "/all/comparemodels/" +cmPage + ".aspx?pool=" + marketId + "&model1=" + model1 + "&model2=" + model2 + "&model3=" + model3 + "";
	gotoUrlNewWinSize(cmUrl, windowSizeX, windowSizeY);
}


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 gotoUrlNewWinSizeCloseOnBlur(s, sWidth, sHeight)
{
    sWidth += 20;
    sHeight += 25;
    g_newWinFocus = window.open(s, "newWinCloseOnBlur", "width=" + sWidth + ",height=" + sHeight + ",left=40,top=40,location=no,resizable=no,scrollbars=no,status=no");	   	   	
    g_newWinFocus.focus();	    
    
    window.onfocus = function()
    {
    	if (g_newWinFocus)
    	{
    		g_newWinFocus.close()
    		g_newWinFocus = null;	    	
    	}
    }
}		

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 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 += g_is_ie ? 15 : 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 gotoUrlFullscreen(sUrl, bScroll) {
	var width = screen.width;
	var height = screen.height;
	var left = 0;
	var top = 0;
	
	if (screen.width > 1920)
	{
		width = 1920;
		height = 1200;
		left = Math.round((screen.width - width) / 2);
		top = Math.round((screen.height - height) / 2);
	}
	
    var scrollbars = 0;
    if (bScroll) scrollbars = 1;
    
	var sProps = "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=" + scrollbars + ",resizable=0,left=" + left + ",top=" + top + ",width=" + (width - 10) + ",height=" + (height - 55);	
	var site = window.open(sUrl,"porschemicrosite", sProps);
	site.focus();		
}

function gotoUrlFullscreenResizable(sUrl) {
	var width = screen.width;
	var height = screen.height;
	var left = 0;
	var top = 0;
	
	if (screen.width > 1920)
	{
		width = 1920;
		height = 1200;
		left = Math.round((screen.width - width) / 2);
		top = Math.round((screen.height - height) / 2);
	}
	
	var sProps = "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,left=" + left + ",top=" + top + ",width=" + width + ",height=" + height;	
	var site = window.open(sUrl,"porschemicrosite_rs", sProps);
	site.focus();		
}


function openDealerLocator(refForm, sWidth, sHeight, sName, sUrl)
{
	if (!sUrl) sUrl = "";
	
	var topOffset = 40;
	
	if (sHeight > (self.screen.availHeight + topOffset - 40))
	{
		sHeight = self.screen.availHeight - 40;
		topOffset = 0;
	}

    newWin = window.open(sUrl, sName, "width=" + sWidth + ",height=" + sHeight + ",left=40,top=" + topOffset + ",dependent=yes,location=no,resizable=no,scrollbars=no,status=no");

	if (refForm)
	{
		refForm.target=sName;
		return true;
	}
}

function openModelAdvisor(siteId)
{
	var iWidth = 831;
	var iHeight = 503;
	window.open("/all/modeladvisor/" + siteId + ".aspx", "newWin" + getRandomInt(10000) , "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,left=" + Math.round((screen.width - iWidth) / 2) + ",top=" + Math.round((screen.height - iHeight) / 2) + ",,width=" + iWidth + ",height=" + iHeight);
}



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;
}



//hello1



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) {
		// wtf?
        // if (parseInt(elem.style.top.replace(/px/, ""),10) > 88) {   
            
                if (doOn)
                {
                    elem.style.MozOpacity = ".99";
                    elem.style.Opacity = "1.00";
                    elem.style.opacity = "1.00";
                    elem.style.filter = "alpha(opacity=100)";
                }
                else
                {
                    elem.style.MozOpacity = ".40";
                    elem.style.Opacity = ".40";
                    elem.style.opacity = ".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 fadeAllOut(elem)
{
}
function fadeAllIn(elem)
{
}
function hiliteLr(level, sName)
{
    var elem = document.getElementById(sName);
    if (elem)
    {
        if (level == 0 || level == "0")
        {
            //////////////////////
            // JD-Power 2008 03 Mouseover Workaround Hack
            var itemNo = parseInt(sName.substring(sName.length - 1, sName.length));
            if (itemNo >= 5)
            {
                elem.style.backgroundColor = g_homemenu_hl_background_color_Level5;
            }
            else
            {
                elem.style.backgroundColor = g_homemenu_hl_background_color;
            }
            if ((g_jdpowerphase == "200803") && (itemNo <= 4))
            {
                var topNavi = document.getElementById("topnav" + itemNo.toString()); 
                topNavi.style.backgroundImage = "none";
                topNavi.style.backgroundColor = "transparent"; //"#FFFFFF";
                elem.style.backgroundImage = "none";
                /***************************************/
                /* HG Wei?mit 1% Deckkraft, bei 0% löst IE7 sonst das mouseout Event wieder aus */
                elem.style.backgroundColor = "white"; 
                elem.style.MozOpacity = ".01"; 
                elem.style.Opacity = ".01"; 
                elem.style.opacity = ".01"; 
                elem.style.filter = "Alpha(opacity=1, finishopacity=1, style=2)"; /* 1% Deckkraft, bei 0% löst IE7 sonst das mouseout Event wieder aus */
                /***************************************/
            }
            else
            {
                elem.style.color = g_homemenu_hl_fontcolor; 
                if (! (elem.className.indexOf("final") >= 0) )
                {
                    elem.style.backgroundImage = "url(/Images/arrow-red.gif)";
                }
            }
            fadeAllOut(elem);
            //////////////////////
        }
        else
        {
            elem.style.color = g_homemenu_hl_fontcolor; //"rgb(204, 0, 0)";
            elem.style.backgroundColor = "#FFFFFF";
            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.Opacity = "1.00"; 
            elem.style.opacity = "1.00"; 
            elem.style.filter = "alpha(opacity=100)";
        }
    }
}

function loliteLr(level, sName)
{
    var elem = document.getElementById(sName);
    if (elem)
    {
        if (level == 0 || level == "0")
        {

            //////////////////////
            // JD-Power 2008 03 Mouseover Workaround Hack
            var itemNo = parseInt(sName.substring(sName.length - 1, sName.length));
            if (itemNo >= 5)
            {
                elem.style.backgroundColor = g_homemenu_ll_background_color; 
            }
            if ((g_jdpowerphase == "200803") && (itemNo <= 4))
            {
                var topNavi = document.getElementById("topnav" + itemNo.toString()); // NOP
                topNavi.style.backgroundImage = "url(/images/jdpower/200803/hg.jpg)";
                var img = "";
                switch(itemNo)
                {
                    case 1: img = "url(/images/jdpower/200803/01boxster.gif)"; break;
                    case 2: img = "url(/images/jdpower/200803/02cayman.gif)"; break;
                    case 3: img = "url(/images/jdpower/200803/03911.gif)"; break;
                    default: img = "url(/images/jdpower/200803/04cayenne.gif)"; break;
                }
                elem.style.backgroundImage = img;
                elem.style.backgroundColor = "transparent";
                elem.style.MozOpacity = "1.00"; 
                elem.style.Opacity = "1.00"; 
                elem.style.opacity = "1.00"; 
                elem.style.filter = "Alpha(opacity=100, finishopacity=100, style=2)";
            }
            else
            {
                elem.style.color = g_homemenu_ll_fontcolor_level0; 
                elem.style.backgroundColor = g_homemenu_ll_background_color; 
                if (! (elem.className.indexOf("final") >= 0) )
                {
                    elem.style.backgroundImage = g_homemenu_ll_background_image_level0; 
                }
            }
            fadeAllIn(elem);
            //////////////////////
        }
        else
        {
            elem.style.color = g_homemenu_ll_fontcolor_level1;
            elem.style.backgroundColor = "#FFFFFF";
            if (! (elem.className.indexOf("final") >= 0) )
            {
                elem.style.backgroundImage = g_homemenu_ll_background_image_level1;
            }

            elem.style.MozOpacity = ".86";
            elem.style.Opacity = ".86"; 
            elem.style.opacity = ".86"; 
            elem.style.filter = "alpha(opacity=86)";
        }
    }
}

function showSubLayers(sName)
{
    var i = 0;
    var foundOne = false;

    for (i = 1; i <= G_MAXSUBLAYERS; 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 <= G_MAXSUBLAYERS; 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;
}