var check;
var mayHideTab=true;
var layerRef;
var styleSwitch;
var what;
var timer;
var detailImageSrc='';

function getcookie(cookiename) {
    var cookiestring=""+document.cookie;
    var index1=cookiestring.indexOf(cookiename);
    if (index1==-1 || cookiename=="") return "";
    var index2=cookiestring.indexOf(';',index1);
    if (index2==-1) index2=cookiestring.length;
    return unescape(cookiestring.substring(index1+cookiename.length+1,index2));
}

function isLoggedIn() {
    public_keuser = "";
    if (document.cookie) {
        var keuser = getcookie("KEID");
        if (keuser != "") {
            public_keuser=keuser.substring(0,keuser.indexOf("|"));
        }
    }
}

var placement=0;
var keepgoing = "true";

function scrollMe(eyeD, ext)
 {
    timer=setInterval(function() { document.getElementById(eyeD).scrollLeft += ext },1);
 }

function scrollMeSafari(eyeD, ext, numitems)
 {
    var itemswidth=0;
    itemswidth=(numitems-3)*(-188)-1;
    placement += ext;
    if (placement > 0) {
    document.getElementById(eyeD).style.left = 0;
    placement=0;
    } else if (placement < itemswidth) {
    placement=itemswidth;
    } else {
    document.getElementById(eyeD).style.left = placement;
    }
    if (document.getElementById("keepgoing").value == "true") {
    scrollMe(eyeD, ext);
    }
 }

function isNoFlash() {
    if (document.cookie) { return getcookie("noflash") != ""; }
    return false;
}

function init() {
    if(document.getElementById) {
        layerRef="document.getElementById";
        styleSwitch=".style";
        what="dom1";
    }
    else if (document.layers) {
        layerRef="document.layers";
        styleSwitch="";
        what ="ns4";
    }
    else if(document.all) {
        layerRef="document.all";
        styleSwitch=".style";
        what ="ie4";
    }
    else {
        what="none";
        newbrowser = false;
    }
    check = true;
}

function isDefined(property) {
  return (typeof property != 'undefined');
}


//
// action={hide,show,toggle}
// action=undefined: toggle
//
function showHide(layerName, showHideToggle) {
    if (check) {
        if (what=="none")
            return;

        if (what=="dom1") {
            if (showHideToggle=="show" || (showHideToggle != "hide" && document.getElementById(layerName).style.display != 'block'))
                document.getElementById(layerName).style.display= 'block';
            else document.getElementById(layerName).style.display= 'none';
        } else {
            if (showHideToggle=="show" || (showHideToggle != "hide" && (eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.display')!='block')))
                eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.display="block"');
            else eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.display=""');
        }
    }
}

function showHideTabTimed() {
    //smh 9/13/05: Mantis #923: was:
    // XXXsetTimeout("showHideTab('my-folder-tab-active')",5000);
}

//
// action={hide,show,toggle}
// action=undefined: toggle
//
function showHideTab(layerName, showHideToggle) {
    //smh 9/13/05: Mantis #923:
    return;

    if (check) {
        if (!mayHideTab) return;
        if (what=="none") return;
        else if (what=="dom1")
        {
            if (showHideToggle=="hide" || (showHideToggle != "show" &&
                  document.getElementById(layerName).style.display != 'none'))
            {
                document.getElementById(layerName).style.display='none';
                document.tab.src='/common/images/tab-myfolder.gif';
            } else {
                 document.getElementById(layerName).style.display='block';
                 document.tab.src='/common/images/tab-myfolder-active.gif';
            }
        } else {
            if (showHideToggle=="hide" || (showHideToggle != "show"
                && eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.display')==''))
                eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.display="none"');
            else eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.display=""');
        }
    }
    return;
}

function highlight(icon)    {
    document.getElementById('icon-pulsating').src='/performanceshowers/images/icon-pulsating.gif';
    document.getElementById('icon-fullflow').src='/performanceshowers/images/icon-fullflow.gif';
    document.getElementById('icon-softaerated').src='/performanceshowers/images/icon-softaerated.gif';
    document.getElementById('icon-' + icon).src='/performanceshowers/images/icon-' + icon + '-a.gif';
    document.getElementById('text-default').style.display='none';
    document.getElementById('text-pulsating').style.display='none';
    document.getElementById('text-fullflow').style.display='none';
    document.getElementById('text-softaerated').style.display='none';
    document.getElementById('text-' + icon).style.display='block';
}

/* might need to add back to following js at future dateresult,*/
function showAll(layerName) {
    if (check) {
        if (what=="none") return;
        else if (what=="dom1") {
            for (var i=0; ; i++) {
                layerNelem= document.getElementById(layerName + i);
                if (layerNelem == null) break;
                document.getElementById(layerName + 'arrow' + i).src='/common/images/icon-contract-up.gif';
                if (layerNelem.style.display=='none')
                    layerNelem.style.display='block';
                    //document.getElementById('accessories'+result+'-'+i).src = leftNavEngines1on.src;
            }
        }
    }
    return;
}

function hideAllResults(layerName) {
    if (check) {
        if (what=="none") return;
        else if (what=="dom1") {
            for (var i = 0; ; i++) {
                layerNelem = document.getElementById(layerName + i);
                if (layerNelem == null) break;
                document.getElementById(layerName + 'arrow' + i).src='/common/images/icon-expand-down.gif';
                if (layerNelem.style.display!='none') {
                    layerNelem.style.display='none';
                    //document.getElementById('accessories'+result+'-'+i).src = leftNavEngines1off.src;
                }
            }
        }
    }
    return;
}

function showSection(sectionName,commercialFlag) {
    if (check) {
        if (what =="none") return;
        else if (what=="dom1") {
            if (sectionName=="kitchen") {
                document.getElementById('bathroom').style.display='none';
                if(commercialFlag != "1")
                document.getElementById('commercial').style.display='none';
                document.getElementById('kitchen-button').src='/common/images/nav-inthekitchen-on.gif';
                document.getElementById('bathroom-button').src='/common/images/nav-inthebathroom.gif';
                if(commercialFlag !="1")    document.getElementById('commercial-button').src='/common/images/nav-commercialuse.gif';
            } else if (sectionName=="bathroom") {
                document.getElementById('kitchen').style.display='none';
                if(commercialFlag != "1") { document.getElementById('commercial').style.display='none'; }
                document.getElementById('kitchen-button').src='/common/images/nav-inthekitchen.gif';
                document.getElementById('bathroom-button').src='/common/images/nav-inthebathroom-on.gif';
                if(commercialFlag !="1") document.getElementById('commercial-button').src='/common/images/nav-commercialuse.gif';
            }
            if(commercialFlag != "1") { document.getElementById(sectionName).style.display='block';}
        }
    } return;
}

function swapSubNav(section,navNode)    {
            var layerNav;
            for (var i = 1; ; i++) {
                layerNav = document.getElementById(section + i);
                if (layerNav == null) break;
                if (layerNav.style.display=='block') {
                    layerNav.style.display='none';
                    document.getElementById(section + '-arrow' + i).src='/common/images/nav-arrow.gif';
                }
            }
            try {
            document.getElementById(section + navNode).style.display='block';
            document.getElementById(section + '-arrow' + navNode).src='/common/images/nav-arrow-on.gif';
            } catch(e) {}
}

function divClicked(showHideLayer,swapArrowName,sectionId,swapTab) {
        showHide(showHideLayer);
        swapArrow(swapArrowName);
        swap(swapTab,sectionId);
}

function swap(layerName2,category) {
    if (category=="1") {
        if ((document.getElementById(layerName2).style.backgroundColor.indexOf("241") > 0) ||                               (document.getElementById(layerName2).style.backgroundColor.indexOf("f1e") > 0)) {
            document.getElementById(layerName2).style.backgroundColor='#E8DE95';
        } else {
            document.getElementById(layerName2).style.backgroundColor='#F1ECC7';
        }
    } else if (category=="2") {
        if ((document.getElementById(layerName2).style.backgroundColor.indexOf("220") > 0) ||             (document.getElementById(layerName2).style.backgroundColor.indexOf("dce") > 0)) {
             document.getElementById(layerName2).style.backgroundColor='#BFCED6';
        } else {
            document.getElementById(layerName2).style.backgroundColor='#DCE6EB';
        }
    } else if (category=="3") {
        if ((document.getElementById(layerName2).style.backgroundColor.indexOf("243") > 0) || (document.getElementById(layerName2).style.backgroundColor.indexOf("f3f") > 0)) {
            document.getElementById(layerName2).style.backgroundColor='#E1E1E2';
        } else {
            document.getElementById(layerName2).style.backgroundColor='#F3F3F3';
        }
    }
}

function showProductTab(div)
{
    for (var i=0; ; i++) {
        var el= document.getElementById('pn_tab' + i);
        if (!isDefined (el) || el == null)
            break;

        if (document.getElementById(div) == el)
            el.style.display= "block";
        else el.style.display= "none";
    }
}


// Usage: setActiveTab ([012], section, [012])
//        where tabnum is the tab number, and tabsize is 0,1,2 for normal, wide, or wider
// replaces whichAct[Wide[r]] and showProductTab[Wide[r]] methods
var tabsizes= [ "", "-wide", "-wider" ];
var activeTabNum= 0;
function setActiveTab (tabnum, tabsize, section) {
    activeTabNum= tabnum;

    // loop over all tabs, breaking out when we find one that's undefined
    for (var i=0; ; i++) {
        // Show the current tab
        var pn_el= document.getElementById('pn_tab' + i);
        if (!isDefined (pn_el) || pn_el == null)
            break;

        if (i==tabnum)
            pn_el.style.display= "block";
        else pn_el.style.display= "none";

        // Update the background images, drawing a border around all but the first notetab
        var border= (i == 0) ? '' : '-brd';
        var tab_el= document.getElementById ('tab' + i + tabsizes[tabsize]);

        if (i==tabnum) {
            tab_el.style.backgroundImage='url(../common/images/tab' + border + '-on' + tabsizes[tabsize] + '.gif)';
            tab_el.style.color='#000000';
            tab_el.style.textDecoration='none';
        } else {
            tab_el.style.backgroundImage='url(../common/images/tab' + border + '-off-' + section + tabsizes[tabsize] + '.gif)';
        }
    }
}


// tabnum is the tab number, and tabsize is 0,1,2 for normal, wide, or wider
function rolloverTab (tabnum, tabsize, section) {
    if (activeTabNum != tabnum) {
        var tab_el= document.getElementById('tab' + tabnum + tabsizes[tabsize]);
        var border= (tabnum == 0) ? '' : '-brd';
        tab_el.style.color='#990000';
        tab_el.style.textDecoration='underline';
        tab_el.style.backgroundImage='url(../common/images/tab' + border + '-over-' + section + tabsizes[tabsize] + '.gif)';
    }
}


// tabnum is the tab number, and tabsize is 0,1,2 for normal, wide, or wider
function rolloutTab (tabnum, tabsize, section) {
    if (activeTabNum != tabnum) {
        var tab_el= document.getElementById('tab' + tabnum + tabsizes[tabsize]);
        var border= (tabnum == 0) ? '' : '-brd';
        tab_el.style.color='#000000';
        tab_el.style.textDecoration='none';
        tab_el.style.backgroundImage='url(../common/images/tab' + border + '-off-' + section + tabsizes[tabsize] + '.gif)';
    }
}


function reduceEnlarge (isEnlarge, url) {

    url= url.replace (/&ssm=1/g,"");
    if (isEnlarge) {
        url += "&ssm=1";
    }

    if (detailImageSrc != null && detailImageSrc.length > 0) {
        url= url.replace(/(&|\?)imgcolor=[^&]*/g,"$1");
        url= url.replace(/\?&/,"?");
        url= url.replace(/&$/,"");
        url += "&imgcolor=" + detailImageSrc;
    }

    self.location= url;
}

function swapArrow(imageName) {
    if(document.getElementById(imageName).src.indexOf("down.gif") > 0) {
        document.getElementById(imageName).src='/common/images/icon-contract-up.gif';
    } else {
        document.getElementById(imageName).src='/common/images/icon-expand-down.gif';
    }
}


// Switch out image in imgid for imgsrc.
// In IE, fade from one image to the next (set style on img to "filter:blendTrans(duration=0.5);" )
function changeimage (doc_imgid,imgsrc) {
    if (document.images) {
        if (doc_imgid.filters)
            doc_imgid.filters["blendTrans"].apply();

        doc_imgid.src= imgsrc;

        if (doc_imgid.filters)
            doc_imgid.filters["blendTrans"].play();
    }

    imgsrc= imgsrc.replace (/.*\/(.*)$/,"$1");
    detailImageSrc= imgsrc;
}

function openWindow(theURL,windowName,features) {
    window.open(theURL,windowName,features);
}

function popupPrivacy() {
    window.open("http://www.kohler.com/corp/privacy.html", "", "left=0,top=0,width=730,height=500,location=no,toolbar=no,menubar=no,resizable=no,scrollbars=yes");
}

// Open a brightcove video player popup.
// Pass in the full URL, and 'notabs' if the player uses 'player_library.jsp' (smaller popup)
function vidplayer (url, opts) {
    var w= 1010, h=590;

    if (typeof url == 'undefined' || url == null)
        return false;

    if (typeof opts != 'undefined' && opts == "notabs") {
        w= 929; h= 663;
    }

    window.open(url, "videos", "left=0,top=0,width=" + w + ",height=" + h + ",location=no,toolbar=no,menubar=no,resizable=no,scrollbars=yes");
}

// for the right column trade professionals form
function tradeSelect() {
    f = document.tradeLinks;
    if (f.tradeProfLinks.selectedIndex>0)
        window.location=f.tradeProfLinks[f.tradeProfLinks.selectedIndex].value;
    return false;
}

// #923: Offsite links from header should open in a new browser window
function maybeOpenInNewWindow (sURL) {
    if (sURL.length == 0) return false;
    if (sURL.indexOf("samewindow|") == 0) {
        this.location = sURL.substring(11);
        return false;
    } else {
        window.open(sURL);
        return false;
    }
}
/*** START WRITE FLASH CODE ***/
function writeFlashMovie(version,url,width,height,bgcolor,wmode,access,id)
{
    document.write('<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"');
    document.write('  codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + version + ',0,0,0" ');
    document.write('  WIDTH=' + width + ' HEIGHT=' + height);
    if (id!=undefined && id.length>0) document.write('name="' +  id + '" id="' + id + '"');
    document.write('>');
    document.write(' <PARAM NAME=movie VALUE="' + url + '"> <PARAM NAME=quality VALUE=high> <PARAM NAME=bgcolor VALUE=' + bgcolor + '>');
    if (wmode!=undefined && wmode.length>0) document.write(' <param name="wmode" value="'+wmode+'" />');
    if (access!=undefined && access.length>0) document.write(' <param name="allowScriptAccess" value="'+access+'" />');
    document.write(' <EMBED src="../KOHLER Articles.files/' + url + '" quality=high bgcolor=' + bgcolor + ' ');
    document.write(' swLiveConnect=FALSE WIDTH=' + width + ' HEIGHT=' + height);
    if (wmode!=undefined && wmode.length>0) document.write(' wmode="'+wmode+'" ');
    if (access!=undefined && access.length>0) document.write(' allowScriptAccess="' + access + '" ');
    if (id!=undefined && id.length>0) document.write(' id="' + id + '" name="' + id + '"');
    document.write(' TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">');
    document.write(' </EMBED></OBJECT>');
}
/*** END WRITE FLASH CODE ***/


/** NEW FLASH OUT PUT CAUSED BY OBJECT ISSUE **/

function CreateControl(DivID, WIDTH, HEIGHT, URL)
{
  var d = document.getElementById(DivID);
  d.innerHTML = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="' + WIDTH + '" height="' + HEIGHT + '"><param name="movie" value="../KOHLER Articles.files/' + URL + '"><param name="quality" value="high"><embed src="../KOHLER Articles.files/' + URL + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + WIDTH + '" height="' + HEIGHT + '"></embed></object>';
}