var check;
var mayHideTab=true;
var layerRef;
var styleSwitch;
var what;
var timer;

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('design').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('design-button').src='/common/images/nav-inthedesign.gif';
                if(commercialFlag !="1")    document.getElementById('commercial-button').src='/common/images/nav-commercialuse.gif';
            } else if (sectionName=="design") {
                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('design-button').src='/common/images/nav-inthedesign-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 k = 0;
            var layerTab;
            var layerNav;
            if (section == "commercial") {
            k = 1;
            }
            for (var i = k; ; i++) {

                layerTab = document.getElementById(section + i);
                layerNav = document.getElementById(section + i + '-a');
                if (layerNav == null) break;
                if (layerNav.style.display!='none') {
                    layerNav.style.display='none';
                }
                if (layerTab.style.display=='none') {
                    layerTab.style.display='block';
                }
            }
			try {
              document.getElementById(section + navNode).style.display='none';
              document.getElementById(section + navNode + '-a').style.display='block';
			} 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) 
{
    document.getElementById('pn_tab0').style.display= "none";
    document.getElementById('pn_tab1').style.display= "none";
    document.getElementById('pn_tab2').style.display= "none";
    document.getElementById(div).style.display= "block";
}

function showProductTabWide(div) 
{
    document.getElementById('pn_tab0').style.display= "none";
    document.getElementById('pn_tab1').style.display= "none";
    document.getElementById(div).style.display= "block";
}


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';
    }
}


var active = 2;
function whichAct(active2, section) {
    active=active2;
	document.getElementById('tab' + active2).style.color='#000000';
	document.getElementById('tab' + active2).style.textDecoration='none';	
    if (active2 == 0) {
        document.getElementById('tab0').style.backgroundImage='url(../common/images/tab-on.gif)';
        document.getElementById('tab1').style.backgroundImage='url(../common/images/tab-brd-off-' + section + '.gif)';
        document.getElementById('tab2').style.backgroundImage='url(../common/images/tab-brd-off-' + section + '.gif)';
    } else if (active2 == 1) {
        document.getElementById('tab0').style.backgroundImage='url(../common/images/tab-off-' + section + '.gif)';
        document.getElementById('tab1').style.backgroundImage='url(../common/images/tab-brd-on.gif)';
        document.getElementById('tab2').style.backgroundImage='url(../common/images/tab-brd-off-' + section + '.gif)';
    } else if (active2 == 2 ) {
        document.getElementById('tab0').style.backgroundImage='url(../common/images/tab-off-' + section + '.gif)';
        document.getElementById('tab1').style.backgroundImage='url(../common/images/tab-brd-off-' + section + '.gif)';
        document.getElementById('tab2').style.backgroundImage='url(../common/images/tab-brd-on.gif)';
    }
}

var active3 = 0;
function whichActWide(active4, section) {
    active3=active4;
	document.getElementById('tab' + active4 + '-wide').style.color='#000000';
	document.getElementById('tab' + active4 + '-wide').style.textDecoration='none';	
    if (active4 == 0) {
        document.getElementById('tab0-wide').style.backgroundImage='url(../common/images/tab-on-wide.gif)';
        document.getElementById('tab1-wide').style.backgroundImage='url(../common/images/tab-brd-off-' + section + '-wide.gif)';
    } else if (active4 == 1) {
        document.getElementById('tab0-wide').style.backgroundImage='url(../common/images/tab-off-' + section + '-wide.gif)';
        document.getElementById('tab1-wide').style.backgroundImage='url(../common/images/tab-brd-on-wide.gif)';
    }
}

function rollover(whichtab, section) {
    if (active!=whichtab) {
		document.getElementById('tab' + whichtab).style.color='#990000';
		document.getElementById('tab' + whichtab).style.textDecoration='underline';
        if (whichtab==0) {
            document.getElementById('tab' + whichtab).style.backgroundImage='url(../common/images/tab-over-' + section + '.gif)';
        } else {
            document.getElementById('tab' + whichtab).style.backgroundImage='url(../common/images/tab-brd-over-' + section + '.gif)';
        }
    }
}

function rolloverWide(whichtab3, section) {
    if (active3!=whichtab3) {
		document.getElementById('tab' + whichtab3 + '-wide').style.color='#990000';
		document.getElementById('tab' + whichtab3 + '-wide').style.textDecoration='underline';
        if (whichtab3==0) {
            document.getElementById('tab' + whichtab3 + '-wide').style.backgroundImage='url(../common/images/tab-over-' + section +  '-wide.gif)';
        } else {
            document.getElementById('tab' + whichtab3 + '-wide').style.backgroundImage='url(../common/images/tab-brd-over-' + section +  '-wide.gif)';
        }
    }
}

function rollout(whichtab2, section) {
    if (active!=whichtab2) {
		document.getElementById('tab' + whichtab2).style.color='#000000';
		document.getElementById('tab' + whichtab2).style.textDecoration='none';	
        if (whichtab2==0) {
            document.getElementById('tab' + whichtab2).style.backgroundImage='url(../common/images/tab-off-' + section + '.gif)';
        } else { 
            document.getElementById('tab' + whichtab2).style.backgroundImage='url(../common/images/tab-brd-off-' + section + '.gif)';
        }
    }
}

function rolloutWide(whichtab4, section) {
    if (active3!=whichtab4) {
		document.getElementById('tab' + whichtab4 + '-wide').style.color='#000000';
		document.getElementById('tab' + whichtab4 + '-wide').style.textDecoration='none';	
        if (whichtab4==0) {
            document.getElementById('tab' + whichtab4 + '-wide').style.backgroundImage='url(../common/images/tab-off-' + section +  '-wide.gif)';
        } else { 
            document.getElementById('tab' + whichtab4 + '-wide').style.backgroundImage='url(../common/images/tab-brd-off-' + section + '-wide.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();
    }
}

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");
}


/*** START WRITE FLASH CODE ***/
function writeFlashMovie(version,url,width,height,bgcolor,wmode)
{
    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 + '>');
    document.write(' <PARAM NAME=movie VALUE="' + url + '"> <PARAM NAME=quality VALUE=high> <PARAM NAME=bgcolor VALUE=' + bgcolor + '>');
    if (wmode.length>0) document.write(' <param name="wmode" value="'+wmode+'" />');
    document.write(' <EMBED src="' + url + '" quality=high bgcolor=' + bgcolor + ' ');
    document.write(' swLiveConnect=FALSE WIDTH=' + width + ' HEIGHT=' + height);
    if (wmode.length>0) document.write(' wmode="'+wmode+'" ');
    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 ***/
