//get out of frame, if page is shown in frame
if(parent.frames.length > 0) parent.location.replace(window.location.href);

var g_adminPath = "";
var g_mainPath = "";
var isPopup = false;
/*
var g_timeout = -1;
var g_timeoutTime = 80;
*/

// var g_timeout = -1;
var g_timeout = 1;
/* var g_timeoutTime = 80; */
var g_timeoutTime = 250; 

var g_openZoom = 0;
var g_is_home = false;
var g_req;
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_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 = false;
var g_is_gecko = false;
var g_isQuirks = false;

var g_contextDebug = "";
var g_fallbackImage = "";


window.onload = function ()
{
    initAll();
};

function initAll()
{
	//g_adminPath = backLeftStr(backLeftStr(leftStr(window.location.href, ".nsf"), "/"), "/") + "/pc_admin.nsf/";
	//g_mainPath = backLeftStr(leftStr(window.location.href, ".nsf"), "/") + "/pc_main.nsf/";
	g_adminPath = "imgs/";
	g_mainPath = "imgs/";
		
    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") >= 0;
    }
    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();
    }   
}



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 overHome()
{
    if (!g_is_safari) {
        if (g_timeout != -1) { clearTimeout(g_timeout); }
        showNavHomeSub();
    }
}

function outHome()
{
    if (!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");
    showLr("navigationIFrame");
    setBackground("navigationHome", "rgb(242,242,242)");
}

function hideNavHomeSub()
{
    hideLr("navigationHomeSub");
    hideLr("navigationShade");
    hideLr("navigationIFrame");
    setBackground("navigationHome", "rgb(255,255,255)");
}

function setBackground(id, sBack)
{
    var elm = document.getElementById(id);
    elm.style.backgroundColor = sBack;
}





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 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;
}



/* Windows module */

function gotoUrlNewWinSimple(s)
{
    newWin = window.open(s, "newWin" + getRandomInt(10000));
}

function gotoUrlNewWin(s)
{
    sWidth = 826;
    sHeight = 610;

    sWidth += 20;
    sHeight += 25;
    newWin = window.open(s, "newWin" + getRandomInt(10000), "width=" + sWidth + ",height=" + sHeight + ",left=40,top=40,dependent=yes,location=no,resizable=no,scrollbars=no,status=no");
}

function gotoUrlNewWinSize(s, sWidth, sHeight)
{
    sWidth += 20;
    sHeight += 25;
    newWin = window.open(s, "newWin" + getRandomInt(10000), "width=" + sWidth + ",height=" + sHeight + ",left=40,top=40,dependent=yes,location=no,resizable=no,scrollbars=no,status=no");
}

function gotoUrlNewWinSizeScrollable(s, sWidth, sHeight)
{
    sWidth += 20;
    sHeight += 25;
    newWin = window.open(s, "newWin" + getRandomInt(10000), "width=" + sWidth + ",height=" + sHeight + ",left=40,top=40,dependent=yes,location=no,resizable=no,scrollbars=yes,status=no");
}

function gotoUrlNewWinSizeCenteredScrollable(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=yes,status=no");
}


function gotoUrlNewWinSizeScrollableWithMenu(s, sWidth, sHeight)
{
    sWidth += 20;
    sHeight += 50;
    newWin = window.open(s, "newWin" + getRandomInt(10000), "width=" + sWidth + ",height=" + sHeight + ",left=40,top=40,dependent=yes,location=yes,menubar=yes,toolbar=yes,resizable=no,scrollbars=yes,status=yes");
}


function gotoUrlNewWinDefaultSize(s)
{
    sWidth = 570;
    sHeight = 610;

    sWidth += 20;
    sHeight += 25;
    newWin = window.open(s, "newWin" + getRandomInt(10000), "width=" + sWidth + ",height=" + sHeight + ",left=40,top=40,dependent=yes,location=no,resizable=no,scrollbars=no,status=no");
}

function gotoUrlNewWinSizeCentered(s, iWidth, iHeight)
{
    iWidth += 20;
    iHeight += 25;    
    iLeft = Math.round((screen.width - iWidth) / 2);
    iTop = Math.round((screen.height - iHeight) / 2);
    newWin = window.open(s, "newWin" + getRandomInt(10000), "width=" + iWidth + ",height=" + iHeight + ",left=" + iLeft + ",top=" + iTop + ",dependent=yes,location=no,resizable=no,scrollbars=no,status=no");
}

function gotoUrlNewWinSizeByName(s, sWidth, sHeight, sName)
{
    sWidth += 20;
    sHeight += 25;
    newWin = window.open(s, sName, "width=" + sWidth + ",height=" + sHeight + ",left=40,top=40,dependent=yes,location=no,resizable=no,scrollbars=no,status=no");
}

function openLeanWin(sUrl, sWidth, sHeight)
{
    sWidth += 20;
    sHeight += 25;
    newWin = window.open(sUrl, "newWin" + getRandomInt(10000), "width=" + sWidth + ",height=" + sHeight + ",left=140,top=140,dependent=yes,location=no,resizable=no,scrollbars=no,status=no,menubar=no,toolbar=no");
}

function gotoUrlNewWinSizeCenteredScrollableResizable(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", "width=" + iWidth + ",height=" + iHeight + ",left=" + iLeft + ",top=" + iTop + ",dependent=yes,location=no,resizable=yes,scrollbars=yes,status=no");
}


function openAgentWin(sUrl)
{
    newWin = window.open(sUrl, "newWin" + getRandomInt(10000), "width=10,height=10,left=10,top=10,dependent=yes,location=no,resizable=no,scrollbars=no,status=no,menubar=no,toolbar=no");
}

function getRandomInt(max)
{
    return Math.round( Math.random() * (max-1) );
}


/* Home module */

function initHome()
{
    if (document.getElementById) {
        g_initHome = true;
        
    		if (g_is_safari) {
    		//	document.getElementById("homeNavigationShade").style.visibility = "hidden";
    		}
    }
}

function bannerLinkToHi(sId)
{

    if (g_initHome)
    {
        var elm = document.getElementById(sId);
        if (elm)
        {
            elm.style.color = "#c00";
            elm.style.backgroundImage = "url(" + "imgs/" + "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(" + "imgs/" + "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(" + "imgs/" + "arrow-red.gif)";
            }
        }
        else
        {
            elem.style.color = "rgb(204, 0, 0)";

            if (! (elem.className.indexOf("final") >= 0) )
            {
                elem.style.backgroundImage = "url(" + "imgs/" + "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(" + "imgs/" + "arrow-white.gif)";
            }
        }
        else
        {
            elem.style.color = "rgb(0, 0, 0)";
            if (! (elem.className.indexOf("final") >= 0) )
            {
                elem.style.backgroundImage = "url(" + "imgs/" + "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 gotoUrl(s)
{
    document.location.href = s;
}

function nogo()
{
    //
}


function selectAllInput(elm)
{
    if (elm)
    {
        elm.focus();
        elm.select();
    }
}



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("zoomImageCloseButton");

        var imgX = Math.round((g_pageWidth - 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";       

        elmCloseButton.style.left = (imgX + imgWidth - 18) + "px";
        elmCloseButton.style.top = (imgY + 5) + "px";
   
        elmImage.style.display = "block";
        elmShade.style.display = "block";
        elmCloseButton.style.display = "block";
        
        g_openZoom = id;
    }
}

function clickZoomed()
{
    hideLr("zoomImageShade");
    hideLr("zoomImageCloseButton");
    hideLr("zoomImage" + g_openZoom);
    g_openZoom = 0;
}

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_opera = is_opera;
    g_is_ie = is_ie;
    g_is_ie5 = is_ie5;
    g_is_ie5_5 = is_ie5_5;
    g_is_safari = is_safari;
    g_is_gecko = is_gecko;
    
    //only for some DocTypes
    if(g_is_ie) g_isQuirks = true;
}



// String handling

function trim(str) {
 	return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}

function containsStr(s, find) {
	return (s.indexOf(find) != -1);
}

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 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 middleStr(sAll, sStart, sEnd)
{
    	var sPart = "";
    	var posStart = sAll.indexOf(sStart);
	var posEnd = sAll.indexOf(sEnd, posStart + sStart.length + 1);
 
	if (posStart >= 0 && posEnd >= 0 && posEnd > posStart) {
     	sPart = sAll.substring(posStart + sStart.length, posEnd);
    	}
    	return sPart;
}
function rightStr(sAll, sStart)
{
    	var sPart = "";
    	var posStart = sAll.indexOf(sStart);
	if (posStart >= 0) {
     	sPart = sAll.substring(posStart + sStart.length, sAll.length);
    	}
    	return sPart;
}

function backRightStr(sAll, sStart)
{
    	var sPart = "";
    	var posStart = sAll.lastIndexOf(sStart);
	if (posStart >= 0) {
     	sPart = sAll.substring(posStart + sStart.length, sAll.length);
    	}
    	return sPart;
}

function leftStr(sAll, sStart)
{
    	var sPart = "";
    	var posEnd = sAll.indexOf(sStart);
	if (posEnd >= 0) {
     	sPart = sAll.substring(0, posEnd);
    	}
    	return sPart;
}

function backLeftStr(sAll, sStart)
{
    	var sPart = "";    	  
    	var posEnd = sAll.lastIndexOf(sStart);
	if (posEnd >= 0) {
     	sPart = sAll.substring(0, posEnd);
    	}
    	return sPart;
}

function submitForm() {
	document.forms[0].submit();
}

//select year in events overview
function selectYear() {
	var selYear = document.forms['selyear'].year.value;		
	var href = leftStr(document.location.href + "?OpenDocument", "?OpenDocument");
	if(selYear != "current") href += "?OpenDocument&year=" + selYear;							
	document.location.href = href;						
}

//select cat
function selectViewCat() {
	var selCat = document.forms['selcat'].cat.value;		
	var href = leftStr(document.location.href + "?OpenView", "?OpenView");
	if(selCat == "all") href += "?OpenView";
	else if(selCat == "nothing")  href += "?OpenView&nothing";
	else href += "?OpenView&cat=" + selCat;							
	document.location.href = href;						
}
function selectNavigatorCat() {
	var selCat = document.forms['selcat'].cat.value;		
	var href = leftStr(document.location.href + "?OpenNavigator", "?OpenNavigator");
	if(selCat == "all") href += "?OpenNavigator";
	else if(selCat == "nothing")  href += "?OpenNavigator&nothing";
	else href += "?OpenNavigator&cat=" + selCat;							
	document.location.href = href;						
}


function openHelp(language, key) {
	var pos1 = window.location.href.indexOf('.nsf/');
	var pos2 = window.location.href.indexOf('/', pos1 + 5);
	var helpURL = (pos2 != -1) ? '../../../' : url = '../../';	
	helpURL += "pc_admin.nsf/Help/" + language + key + "?OpenDocument";
	var windowWidth = 750;
	var windowHeight = 550;
	var left = (screen.width - windowWidth) / 2;
	var top = (screen.height - windowHeight) / 2;
	var helpWin = open(helpURL,'helpWindow','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,left=' + left + ',top=' + top+ ',width=' + windowWidth + ',height=' + windowHeight);
	helpWin.focus();	
}


// Action Area
function showEditAdminArea() {
	document.getElementById("showEditAdmin").style.visibility = "hidden";
	document.getElementById("editAdminArea").style.visibility = "visible"
	document.cookie = "showedit=1";
}

function closeEditAdminArea() {
	document.getElementById("showEditAdmin").style.visibility = "visible";
	document.getElementById("editAdminArea").style.visibility = "hidden"
	document.cookie = "showedit=0";
}
function closeFailureShow() {
	document.getElementById("failureShow").style.visibility = "hidden"
}
	


function resizeMoveWindow() {
	//alert(document.images["imgend"].offsetTop);
//	var windowWidth =  width + 30;
//	var windowHeight = height + 130;
	//alert(windowHeight);
	//alert(windowHeight);
	//alert(document.images["imgend"].offsetTop);
	
	/*
	if(document.images["imgend"].offsetTop) {
		while(document.images["imgend"].offsetTop + 50 > windowHeight) {
			windowHeight += 10;
		}
	}
	*/
	alert(window.innerWidth + " " + document.body.offsetWidth);	
alert(window.innerHeight + " " + document.body.offsetHeight);
	
	//alert(windowHeight);
	var windowX = (screen.width - windowWidth) / 2;
	var windowY = (screen.height - windowHeight) / 2;
	window.resizeTo(windowWidth, windowHeight);
	window.moveTo(windowX, windowY);	
}



function openLinkWindow(strUrl) {
	var width = 710;
	var height = 220;
	var left = (screen.availWidth - width) / 2;
	var top = (screen.availHeight - height) / 2;
	var options = "height=" + height + ",width=" + width + ", left=" + left + ",top=" + top + ",location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no";
	window.open('CopyLink?OpenForm&link=' + strUrl, "Link", options);
}

function openDBLinkWindow(strDB, strUrl) {
	var width = 710;
	var height = 220;
	var left = (screen.availWidth - width) / 2;
	var top = (screen.availHeight - height) / 2;
	var options = "height=" + height + ",width=" + width + ", left=" + left + ",top=" + top + ",location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no";
	window.open(strDB + 'CopyLink?OpenForm&link=' + strUrl, "Link", options);
}


function getCachePrevent()
{
    return "&rand=" + escape( Math.round( Math.random() * 10000 ) );
}




//opens wait window
//is called when page is submitted
var waitWindow;
function openWaitWindow() {
	document.getElementsByTagName("body")[0].style.cursor = "wait";
	var windowWidth = 147;
	var windowHeight = 147;

	var windowX;
	var windowY;
	if(!isPopup) {
		windowX = (g_pageWidth - windowWidth) / 2;
	     windowY = Math.round( (viewportGetHeight() - windowHeight)/2 ) + viewportGetScrollY();	
     }
     else {
     	if (window.innerWidth) windowX = (window.innerWidth - windowWidth) / 2;
     	else windowX = (document.body.offsetWidth - windowWidth) / 2;
     	
     	 //if (window.innerHeight) windowY = (window.innerHeight - windowHeight) / 2;
     	//else windowY = (document.body.offsetHeight - windowHeight) / 2;    
     	windowY = Math.round( (viewportGetHeight() - windowHeight)/2 ) + viewportGetScrollY();	
     }
	

	if (document.getElementById("actions")) document.getElementById("actions").style.visibility = "hidden";	
	if (document.getElementById("actionstop")) document.getElementById("actionstop").style.visibility = "hidden";
	if (document.getElementById("actionsbottom")) document.getElementById("actionsbottom").style.visibility = "hidden";
	
	document.getElementById("wait").style.position = "absolute";
	document.getElementById("wait").style.left = windowX + "px";
	document.getElementById("wait").style.top = windowY + "px";
	document.getElementById("wait").style.visibility = "visible";
}














function buttonMouseover(id) {
	if(id) {
		if(document.getElementById(id)) {
			document.getElementById(id).style.backgroundColor = '#FFFFFF';
			document.getElementById(id).style.borderColor = '#FFFFFF';
			document.getElementById(id).style.color = '#5B85AD';
		}
	}
}

function buttonMouseout(id) {
	if(id) {
		if(document.getElementById(id)) {
			document.getElementById(id).style.backgroundColor = '#5B85AD';
			document.getElementById(id).style.borderColor = '#5B85AD';
			document.getElementById(id).style.color = '#FFFFFF';		
		}
	}
}



function strLeft(src, delim) {
	var pos = src.indexOf(delim);
	return  src.substring(0, pos);
}

function strLeftBack(src, delim) {
	var pos = src.lastIndexOf(delim);
	return  src.substring(0, pos);
}
	
function strRight(src, delim) {
	var pos = src.indexOf(delim);
	return  src.substring(pos + delim.length, src.length);
}

function strRightBack(src, delim) {
	var pos = src.LastIndexOf(delim);
	return  src.substring(pos + delim.length, src.length);
}

function cancel() {
	history.back();
}


function openLegalNotice() {
	var windowWidth = 750;
	var windowHeight = 600;
	var left = (screen.width - windowWidth) / 2;
	var top = (screen.height - windowHeight) / 2;
	var legalNoticePage = strLeftBack(strLeft(document.URL, ".nsf"), "/") + "/pc_main.nsf/LegalNotice?OpenPage";
	var wnd = window.open(legalNoticePage, "LegalNotice", "width=" + windowWidth + ",height=" + windowHeight + ",left=" + left + ",top=" + top + ",location=no,toolbar=no,scrollbars=yes");
	wnd.focus();
}

function openFullWindow(url) {
	var window = open(url, 'window');
	window.focus();
}

function openWindow(url) {
	var params = 'location=no,menubar=no,toolbar=no,status=no';
	var window = open(url, 'window', params);
	window.focus();
}

//Opens window before leaving porsche site
var exitWin;
function openExitWin(url) {
	if (exitWin && !exitWin.closed) {
		exitWin.close();
	}
	var hoehe = screen.height;
	hoehe -= 170;
	var breite = screen.width;
	var exitPageURL = g_mainPath + "ExternalLink?OpenNavigator&url=" + url;	
	window.location.href = exitPageURL;
}


function openPrintPage(url, width,  height) { 
	if (printWin) {
		printWin.close();
	}
	var left = (screen.availWidth - width) / 2;
	var top = (screen.availHeight - height) / 2;
	var printWin = window.open( url, 'print', "directories=no,location=no,menubar=no,resizable=no,status=no,scrollbars=yes,toolbar=no,width=" + width + ",height=" + height); 
	printWin.focus();
	printWin.print()
}

function openCenteredWindow(url, width,  height) {	
	var left = (screen.width - width) / 2;
	var top = (screen.height - height) / 2;
	var wnd = window.open(url, "window", "width=" + width + ",height=" + height + ",left=" + left + ",top=" + top + ",location=no,toolbar=no,scrollbars=no");
	wnd.focus();
}





function getBrowserHeight() {
	if (window.innerHeight) {
		return window.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight != 0) {
		return document.documentElement.clientHeight;
	}
	else if (document.body) {
		return document.body.clientHeight;
	}
	
	return 0;
}


function startSearch() {		
	var urlBegin = strLeftBack(strLeftBack(document.location.href, "nsf"), "/") + "/pc_main.nsf/";
	var term = encodeURIComponent(document.forms["searchform"].query.value);
	var action = urlBegin + "SearchResult?OpenNavigator&search=" + term; 
	document.location.href = action;	
}



//Flash


function showFlashFO(url, id, video, width, height) {
	var FO = {	movie:"/PorscheClubs/DevNew/pc_admin.nsf/mediaplayer.swf" ,width:width,height:height,majorversion:"7",build:"0",bgcolor:"#FFFFFF",allowfullscreen:"true",
		flashvars:"file=" + video + "&image=/911_6.jpg" };
	UFO.create(	FO, id);
}

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 (flashparamstr.indexOf('base') > 0)
  {
     flashparamstr = flashparamstr.replace("base=", "base=http://files.porsche.com");
  }
  
}
*/

	var runShowFlash = true;
	
	if (!g_is_home) {
		if (g_is_safari) {
			runShowFlash = false;			
		}
	}
	
    if (runShowFlash) {
        //var fo = new FlashObject(url, id + "_flash", width, height, version, bgcolor);
		var fo = new FlashObject(url, id + "_flash", width, height, version, bgcolor, flashparamstr);
        
        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);
    }
}

function closePopupDiv()
{
	// IE Hack for dropdowns
	//ieToggleDropDowns(getListIEDropDowns(), false);
	
	//TODO Stop Movie
	//alert("close");
	document.getElementById("popupDivContent").innerHTML = "<p>&nbsp;</p>";
	hideLr("popupDiv");
    hideLr("popupDivShade");
    g_openpopupDiv = 0;
    
}



function showFlashVideo(videoTitle, videoTitleImg, videoUrlEnd, videoWidth, videoHeight) {
	var flashParams = 'filetype=swf';
	
	//var videoWidth = 352;
	//var videoHeight = 288;
	
	
	var shadeborder = 8;

	 var divWidth = videoWidth + 38;
	var divHeight = videoHeight + 20;
	// magic numbers follow, do not try at home
	//var popupWidth = divWidth;
	//var popupHeight = divHeight - 36;
	var shadeWidth = divWidth + 56;
	var shadeHeight = divHeight + 78;

/*	if (screen.width <= 800) {
     	divHeight = 300;
          popupHeight = 276;
          shadeHeight = 353;
	}*/

	var elmShade = document.getElementById("popupDivShade");
	var elmPopup = document.getElementById("popupDiv");
	var elmContent = document.getElementById("popupDivContent");

	var divX = g_pageWidth / 2 - divWidth / 2;
	var divY = Math.round( (viewportGetHeight() - divHeight)/2 ) + viewportGetScrollY();

	if (divX < 0) { divX = 0; }
	if (divY < 0) { divY = 0; }
	
	elmShade.style.left = (divX - shadeborder) + "px";
	elmShade.style.top = (divY - shadeborder) + "px";
	elmShade.style.width = shadeWidth + "px";
	elmShade.style.height = shadeHeight + "px";

	elmPopup.style.left = divX + "px";
	elmPopup.style.top = divY + "px";
	elmPopup.style.width = divWidth + "px";
	elmPopup.style.height = divHeight + "px";
	elmContent.style.width = videoWidth + "px";
	elmContent.style.height = videoHeight + "px";
	document.getElementById("popupDivTitle").style.width = (divWidth + 25) + "px";
	document.getElementById("closeButtonPopupDiv").style.left = (divWidth +16) + "px";


      //g_openpopupDiv = sUrl;
	
	document.getElementById("popupDivTitle").innerHTML = "<img src=\"" + videoTitleImg + "\" alt=\"" + videoTitle + "\">";
	
	elmPopup.style.display = "block";
	elmShade.style.display = "block";
	elmContent.style.display = "block";

	/*
    	var elmImg = document.getElementById("galleryImage");
    	if (elmImg) {
		g_fallbackImage = elmImg.src;
	}
	*/
	
	var flashWidth = (videoWidth).toString();
	var flashHeight = (videoHeight + 20).toString();
	//var playerUrl = g_adminPath + "FlowPlayer.swf";
	//var playerUrl = g_adminPath + "mediaplayer.swf";
	var playerUrl = g_adminPath + "videoplayer.swf";
	var videoUrl = g_mainPath + "0/" + videoUrlEnd;
	//"videourl=" + videoUrl + ",eventhandler=flashEnded," + flashParams);
	showFlash(playerUrl, "popupDivContent", videoWidth, videoHeight, "7", "#FFFFFF",
            "loop=true,menu=true,quality=high,wmode=opaque",            
            "id=" + videoUrl + ",eventHandler=flashEnded");
	//showFlash(playerUrl, "popupDivContent", videoUrl, videoWidth, videoHeight);            
}

function flashEnded() {
	/*if (g_fallbackImage != "") {
		var elmContent = document.getElementById("galleryContent");
		elmContent.innerHTML = "<img src=\"" + g_fallbackImage + "\" alt=\"\" id=\"galleryImage\" />";
	}*/
	//alert("flashEnded");
}




//
// 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"));
	return null;
}







//debug
var showDebug = false;
function getDebugDiv() {
	var elem = document.getElementById("debug");
	
	if (!elem) {
		elem = document.createElement("div");
		elem.id = "debug"
		
		var elemStyle = elem.style;
		
		elemStyle.position = "absolute";
		elemStyle.top = "10px";
		elemStyle.left = "10px";		
		elemStyle.width = "980px";
		elemStyle.height = "100px";
		elemStyle.padding = "3px";
		elemStyle.backgroundColor = "#000000";
		elemStyle.border = "1px solid #FF0000";
		elemStyle.color = "#FFFFFF";
		elemStyle.fontFamily = "arial, helvetica, sans-serif";
		elemStyle.fontSize = "12px";
		elemStyle.visibility = showDebug ? "visible" : "hidden";	
		elemStyle.zIndex = "1000000";		
		
		//elemStyle.overflow = "-moz-scrollbars-vertical !important";
	    	elemStyle.overflow = "auto";
	    	elemStyle.overflowY = "auto";
		
		document.getElementsByTagName("body")[0].appendChild(elem);
	}	
	
	return elem;
}

function debug(text) {		
	getDebugDiv().innerHTML = text;
}

function debugAppend(text) {
	var elem = getDebugDiv();
	elem.innerHTML += "<br />" + text;
}

function hideDebug() {
	var elem = getDebugDiv();
	elem.innerHTML = "";
	elem.style.visibility = "hidden";
}
