var locatorFlag = "false";
var locatorHomeFlag = "false";
var searchFlag = "false";
var quickfinderFlag = "false";

var mynodes = new Array("solutions","products","library","support")

function swapNav(whichNode) {
	for (var i=0; i<mynodes.length; i++) {
		if(document.getElementById(mynodes[i]  + '-active') != undefined) {
			if(document.getElementById(mynodes[i]  + '-active').style.display != 'none') {
				document.getElementById(mynodes[i]  + '-active').style.display = "none";
			}
			
		}
		if(document.getElementById(mynodes[i]) != undefined) {
		
			if((document.getElementById(mynodes[i]).style.display != 'block') && (document.getElementById(mynodes[i]).style.display != '')) {
				document.getElementById(mynodes[i]).style.display = "block";
			}
		}
	}
	if(document.getElementById(whichNode) != undefined) {
		document.getElementById(whichNode).style.display = "none";
	}
	if(document.getElementById(whichNode + '-active') != undefined) {
		document.getElementById(whichNode + '-active').style.display = "block";
	}
}

function spiffOver(whichSpiff) {
	document.getElementById(whichSpiff + '-active').style.display = 'block'
	document.getElementById(whichSpiff).style.display = 'none'
}

function spiffOut(whichSpiff) {
	document.getElementById(whichSpiff + '-active').style.display = 'none'
	document.getElementById(whichSpiff).style.display = 'block'
}

function sfNavRollover(target) {
	target.style.backgroundColor = '#1990f5';
	target.style.backgroundImage = 'url("/common/images/spacer.gif")'
}

function sfNavRollout(target) {
	target.style.backgroundColor = 'transparent';
	target.style.backgroundImage = 'url("/common/images/section-front-left-nav-node.png")'
}

function navRollover(target) {
	target.style.backgroundColor = '#1990f5';
	target.style.color = '#FFFFFF';
}

function navRolloutSection(target) {
	target.style.backgroundColor = 'transparent';
	target.style.color = '#FFFFFF';
}

function navRolloutSub(target) {
	target.style.backgroundColor = '#8f918e';
	target.style.color = '#FFFFFF';
}

function navRolloutTert(target) {
	target.style.backgroundColor = '#FFFFFF';
	target.style.color = '#1990f5';
}

var currentTarget;
function toolsOver(target) {
    if((target=="search" && searchFlag == "false") || (target=="locators" && locatorFlag == "false") || (target=="locatorHome" && locatorHomeFlag == "false")) {
        if (currentTarget != null && target != currentTarget && currentTarget != "quickfinder") {
            removeFlag(currentTarget);
            toolsOut(currentTarget);
        }
        currentTarget = target;
        document.getElementById(target).className=target + '-over';
		if(document.getElementById('quickfinder') != undefined  && quickfinderFlag == "false") {
			document.getElementById('quickfinder').className='quickfinder';
		}
    }
	if(target=="quickfinder" && quickfinderFlag == "false") {
        if (currentTarget != null && target != currentTarget && currentTarget != "quickfinder") {
            removeFlag(currentTarget);
            toolsOut(currentTarget);
        }
        currentTarget = target;
        document.getElementById(target).className=target + '-over';
	}
}

function toolsOut(target) {
    if((target=="search" && searchFlag == "false") || (target=="locators" && locatorFlag == "false") || (target=="locatorHome" && locatorHomeFlag == "false") || (target=="quickfinder" && quickfinderFlag == "false")) {
		if (document.getElementById(target) != null) {
            document.getElementById(target).className=target;
        }
    }
}

function toolsReset() {
	if(document.getElementById('locators') != undefined) {
		if (locatorFlag == "false") {
			document.getElementById('locators').className="locators";
		}
	}
	if(document.getElementById('locatorHome') != undefined) {
		if (locatorHomeFlag == "false") {
			document.getElementById('locatorHome').className="locatorHome";
		}
	}
	if (searchFlag == "false") {
		document.getElementById('search').className="search";
	}
	if(document.getElementById('quickfinder') != undefined) {
		if (quickfinderFlag == "false") {
			document.getElementById('quickfinder').className="quickfinder";
			flushFilters();
		}
	}
}

function clearDefault(field) {
	if ((field.value == ' City, State or Zip') || (field.value == ' Enter Keyword or Model') || (field.value == ' To send to multiple addresses, separate with a comma.') || (field.value == 'Type your comments here')) {
		field.value = '';
	}
}

function setFlag(whichFlag) {
	if(whichFlag == "search") {
		searchFlag = "true";
		locatorFlag = "false";
		quickfinderFlag = "false";
	} else if(whichFlag == "quickfinder") {
		searchFlag = "false";
		locatorFlag = "false";
		locatorHomeFlag = "false";
		quickfinderFlag = "true";
	} else if(whichFlag == "locatorHome") {
		searchFlag = "false";
		locatorFlag = "false";
		locatorHomeFlag = "true";
		quickfinderFlag = "false";
	} else if(whichFlag == "locators") {
		searchFlag = "false";
		locatorFlag = "true";
		locatorHomeFlag = "false";
		quickfinderFlag = "false";
	} else {
        searchFlag = "false";
		locatorFlag = "false";
		locatorHomeFlag = "false";
		quickfinderFlag = "false";
    }
	toolsReset();
}

function removeFlag(whichFlag) {
	if(whichFlag == "search") {
		searchFlag = "false";
		document.getElementById('search').className='search';
	} else if(whichFlag == "locatorHome") {
		locatorHomeFlag = "false";
		document.getElementById('locatorHome').className='locatorHome';
	} else if(whichFlag == "locators") {
		locatorFlag = "false";
		document.getElementById('locators').className='locators';
	} else if(whichFlag == "quickfinder") {
		quickfinderFlag = "false";
		document.getElementById('quickfinder').className='quickfinder';
		flushFilters();
	}
}

function popupPrivacy() {
    window.open("http://www.kohler.com/corp/privacy.html", "", "left=0,top=0,width=730,height=500,scrollbars");
}
function popupLegal() {
    window.open("http://www.kohler.com/corp/legal.html", "", "left=0,top=0,width=730,height=500,scrollbars");
}

function emailToFriend() {
    window.open("/industrial/emailtofriend.htm", "", "left=0,top=0,width=382,height=620,scrollbars");
}

function openWindow(theURL,windowName,features) {
    window.open(theURL,windowName,features);
}

function downloadZip(directory, productNumber) {
    document.getElementById("downloadZip").src = "/"+directory+"/downloadzip.htm?prodnum="+productNumber;
}

function saveDefault(customerNumber,name,phone,tollfree,fax,canadaFlag,internationalFlag,country) {
    var today = new Date();
    var value = customerNumber+"|"+name+"|"+phone+"|"+tollfree+"|"+fax+"|"+canadaFlag+"|"+internationalFlag+"|"+country+"|"+today;
    var locname = "defaultLocation";
    var days = "365";
    createCookie(locname,value,days);
    getDefaultLocation();
}

function createCookie(name,value,days) {
    var expires = "";
    if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		expires = "; expires="+date.toGMTString();
	}
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
    getDefaultLocation();
}

function deleteLocation() {
    eraseCookie("defaultLocation");
    document.getElementById("default-location").style.display = 'none';
}

function getDefaultLocation() {
    var name = "defaultLocation";
    var value = readCookie(name);
    var today = new Date();
    var cookieDate;
    var timeSpan;
    var customerNumber;
    var companyName;
    var phone;
    var tollfree;
    var fax;
    var canadaFlag;
    var internationalFlag;
    var country;                 
    var sectionNumber;

    if(value!='undefined' && value != null) {
        var valueArray = value.split("|");
        customerNumber = valueArray[0];
        companyName = valueArray[1];
        phone = valueArray[2];
        tollfree = valueArray[3];
        fax = valueArray[4];
        canadaFlag = valueArray[5];
        internationalFlag = valueArray[6];
        country = valueArray[7];
        if(valueArray[8]!='undefined' && valueArray[8]!='') {
            cookieDate = new Date(valueArray[8]);
            timeSpan = Math.round((((today-cookieDate)/1000)/60/60/24));
        }
        if(timeSpan>29) {
            refreshCookie(customerNumber,canadaFlag,internationalFlag,country,companyName);
        } else {
        document.getElementById("default-location").style.display = 'block';
        }
        document.getElementById("defaultCompanyName").innerHTML = companyName+"<br />";
        if(phone!='undefined' && phone!='') {
            document.getElementById("defaultPhone").innerHTML = "Phone: "+phone+"<br />";
        }
        if(tollfree!='undefined' && tollfree!='') {
            document.getElementById("defaultTollfree").innerHTML = "Toll Free: "+tollfree+"<br />";
        }
        if(fax!='undefined' && fax!='') {
            document.getElementById("defaultFax").innerHTML = "Fax: "+fax+"<br />";
        }
        sectionNumber = document.getElementById("sectionNumber").value;
        document.getElementById("viewLocHref").href = "/"+ document.getElementById("directory").value +
                  "/salesservicelocator.htm?customerNumber="+customerNumber+"&internationalFlag="+internationalFlag +
                  "&canadaFlag="+canadaFlag+"&country="+country+"&name="+companyName+"&view=true" +
                  "&sectionNumber="+sectionNumber;
    }
}

function refreshCookie(customerNumber,canadaFlag,internationalFlag,country,name) {
    if(customerNumber!='undefined' && customerNumber!='') {
    	url = "/locator/salesservicelocatorvalues.htm?customerNumber="+customerNumber;
    } else if (canadaFlag!='undefined'&& canadaFlag!='' && country!='undefined'&&country!='') {
        url = "/locator/salesservicelocatorvalues.htm?country="+country+"&canadaFlag="+canadaFlag+"&company="+name;
    } else if (internationalFlag!='undefined'&& internationalFlag!='' && country!='undefined'&&country!='') {
        url = "/locator/salesservicelocatorvalues.htm?country="+country+"&internationalFlag="+internationalFlag+"&company="+name;
    }

        new Ajax.Request(
		url,
		{ method:'get',
			onSuccess: function(transport){
				resp =  transport.responseText.replace(/^("(\\.|[^"\\\n\r])*?"|[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t])+?$/, " ");
				try {
                eval(" dlr = {" +resp + "}"); //put it in object
                } catch(e) { ; }
                saveDefault(dlr.defaultLocation.customerNumber,
                            dlr.defaultLocation.name,
                            dlr.defaultLocation.phone,
                            dlr.defaultLocation.tollfree,
                            dlr.defaultLocation.fax,
                            dlr.defaultLocation.canadaFlag,
                            dlr.defaultLocation.internationalFlag,
                            dlr.defaultLocation.country);
            }
        }
    )

}

function contactUsStepOne() {
    var value = document.getElementById("stepOne").options[document.getElementById("stepOne").selectedIndex].value;
    var displayType = 'none';
    if(value != "") {
        displayType = 'block';
    } else {
        document.getElementById("sales").style.display = "none";
        document.getElementById("service").style.display = "none";
        document.getElementById("submitButton").style.display = "none";
    }
    if(value == "13261") {
        document.getElementById("sectionNumber").value = "13261";
    }
    if(value == "13561") {
        document.getElementById("sectionNumber").value = "13561";
    }
    if(value == "13461") {
        document.getElementById("sectionNumber").value = "13461";
    }
    if(value == "13361") {
        document.getElementById("sectionNumber").value = "13361";
    }
    if(value == "28161") {
        document.getElementById("sectionNumber").value = "28161";
        document.getElementById("stepTwoServiceP").style.display = "none";
    } else {
        document.getElementById("stepTwoServiceP").style.display = "block";
    }
    document.getElementById("step2").style.display = displayType;
}

function contactUsStepTwo() {
    var value = "none";
    if(document.getElementById("stepTwoService").checked) {
        value = "service";
    } else if(document.getElementById("stepTwoSales").checked || document.getElementById("stepTwoSalesUs").checked) {
        value="sales";
    }
    if(value == "service") {
        document.getElementById("service").style.display = "block";
        document.getElementById("sales").style.display = "none";
        document.getElementById("submitButton").style.display = "block";
    } else if(value == "sales"){
        document.getElementById("service").style.display = "none";
        document.getElementById("sales").style.display = "block";
        document.getElementById("submitButton").style.display = "block";
    } else {
        document.getElementById("service").style.display = "none";
        document.getElementById("sales").style.display = "none";
        document.getElementById("submitButton").style.display = "none";
    }
}

function requestQuoteStepOne() {
    var value = document.getElementById("sectionNumber").value;
    if(value == "28161") {
		document.getElementById("step2").style.display = 'block';
        document.getElementById("step2andahalf").style.display = 'block';
        document.getElementById("step3").style.display = 'block';
        document.getElementById("step3-residential").style.display = 'none';
        document.getElementById("step3-marine").style.display = 'none';
        document.getElementById("step4").style.display = 'none';
        document.getElementById("submitButton").style.display = "block";
        document.getElementById("sectionNumber").value = "28161";
    } else if(value == "13361") {
		document.getElementById("step2").style.display = 'block';	
        document.getElementById("step2andahalf").style.display = 'none';
        document.getElementById("step3").style.display = 'block';
        document.getElementById("step3-residential").style.display = 'none';
        document.getElementById("step3-marine").style.display = 'none';
        document.getElementById("step4").style.display = 'none';
        document.getElementById("submitButton").style.display = "block";
        document.getElementById("sectionNumber").value = "13361";
    } else if(value == "13561") {
		document.getElementById("step2").style.display = 'block';	
        document.getElementById("step2andahalf").style.display = 'none';
        document.getElementById("step3-residential").style.display = 'block';
        document.getElementById("step4").style.display = 'block';
        document.getElementById("step3").style.display = 'none';
        document.getElementById("step3-marine").style.display = 'none';
        document.getElementById("submitButton").style.display = "block";
        document.getElementById("sectionNumber").value = "13561";
    } else if(value == "13461") {
		document.getElementById("step2").style.display = 'block';	
        document.getElementById("step2andahalf").style.display = 'none';
        document.getElementById("step3-marine").style.display = 'block';
        document.getElementById("step4").style.display = 'block';
        document.getElementById("step3-residential").style.display = 'none';
        document.getElementById("step3").style.display = 'none';
        document.getElementById("submitButton").style.display = "block";
        document.getElementById("sectionNumber").value = "13461";
    } else if(value == "13261") {
		document.getElementById("step2").style.display = 'block';	
        document.getElementById("step2andahalf").style.display = 'none';
        document.getElementById("step3").style.display = 'none';
        document.getElementById("step4").style.display = 'none';
        document.getElementById("step3-residential").style.display = 'none';
        document.getElementById("step3-marine").style.display = 'none';
        document.getElementById("submitButton").style.display = "block";
        document.getElementById("sectionNumber").value = "13261";        
    } else {
        document.getElementById("step2").style.display = 'none';
        document.getElementById("step2andahalf").style.display = 'none';
        document.getElementById("step3").style.display = 'none';
        document.getElementById("step4").style.display = 'none';
        document.getElementById("step3-residential").style.display = 'none';
        document.getElementById("step3-marine").style.display = 'none';
        document.getElementById("submitButton").style.display = "none";
    }
}

function addProduct() {
    var currentProducts = document.getElementById("productReg").innerHTML;
    var currentProductCount = document.getElementById("totalProducts").value;
    var rowClass = "bg-results-row";
    currentProductCount++;
    document.getElementById("totalProducts").value = currentProductCount;
    if(currentProductCount%2!=0) {
        currentProducts += '<tr>';
    } else {
        currentProducts += '<tr class="'+rowClass+'">';
    }
    currentProducts += '<td><span class="label">Model Number</span><br />';
    currentProducts += '<input type="text" name="modelNumber_'+currentProductCount+'" value=""></td>';
    currentProducts += '<td rowspan="3"><img src="/common/images/spacer.gif" width="22" height="1" alt="" border="0" /></td>';
    currentProducts += '<td><span class="label">Spec Number</span><br />';
    currentProducts += '<input type="text" name="specNumber_'+currentProductCount+'"></td>';
    currentProducts += '</tr>';
    if(currentProductCount%2!=0) {
        currentProducts += '<tr>';
    } else {
        currentProducts += '<tr class="'+rowClass+'">';
    }
    currentProducts += '<td><span class="label">Serial Number</span><br />';
    currentProducts += '<input type="text" name="serialNumber_'+currentProductCount+'"></td>';
    currentProducts += '<td><span class="label">Date of Purchase</span><br />';
    currentProducts += '<input type="text" name="dateOfPurchase_'+currentProductCount+'" value="mm/dd/yyyy" /></td>';
    currentProducts += '</tr>';
    if(currentProductCount%2!=0) {
        currentProducts += '<tr>';
    } else {
        currentProducts += '<tr class="'+rowClass+'">';
    }
    currentProducts += '<td><span class="label">Place of Purchase</span><br />';
    currentProducts += '<input type="text" name="placeOfPurchase_'+currentProductCount+'"></td>';
    currentProducts += '<td></td>';
    currentProducts += '</tr>';

    document.getElementById("productReg").innerHTML = currentProducts;
}

function addEvent(elm, evType, fn, useCapture) {
	try {
		var oldevent = eval("elm.on"+evType);
		if(typeof(oldevent) != 'function') {
			eval("elm.on"+evType+"=fn;") ;
		} else {
			eval("elm.on"+evType+"=function(){oldevent();fn();}");
		}
	} catch(e) {
			return; 
	}
	return;
}

function  downloadZip(productNumber) {
    window.open('/verify.htm?final=/industrial/downloadzip.htm:prodnum='+productNumber,'userChallenge','width=400,height=200');
}
function  downloadPdf(final1) {
    window.open('/verify.htm?final='+final1,'userChallenge','width=400,height=200');
}