//**********   Site Navigation functions   *******************//

function changeBackground(id,id2,mousemovement,subMenu) {
	    var generalTD = document.getElementById(id);
		var generalTDA = document.getElementById(id2);
	
	    if (mousemovement == 'over') {
		  generalTD.style.background='url(/images/gray.jpg)';
		  generalTDA.style.background='url(/images/gray.jpg)';
		 // generalTDA.style.color='#FFFFFF';
		  if (subMenu != -1) MenuToggle(subMenu);
		  else ClearAllMenus();
         }
		else {
          generalTD.style.background='url(/images/white.jpg)';
		  generalTDA.style.background='url(/images/white.jpg)';
          if (subMenu != -1) {
			SetMenuInactive(subMenu);
			ClearMenu(subMenu);
		  }
		//  generalTDA.style.color='#6E1E2B';
		}

} // end of changeBackground

function imageError() {
	if (document.images) {
  	  for (var i = 0; i < document.images.length; i++)
		if (document.images[i].name == 'mbImage') {
	  	  if (document.images[i].complete == false) {
			document.images[i].src = '/shared/images/ko_websmall/not_available_120.gif';
		  } // end of if complete
		} // end of if name
	 } // end of if document.images
} // end of function imageError

function shWin() {
   window.open("/productcatalog/showhouse_popup.cfm" , "ShowHouseStory", "menubar=no, toolbar=no, scrollbars=yes, resizable=yes, left=30, top=30, width=300, height=375");
}
   function internationalSubmit(){
		   menuNum = document.finternational.x.selectedIndex;
		   if (menuNum == null) return;  
		   if (menuNum > (document.finternational.x.length-1) ) {
		     menuNum = menuNum - 1;
			 document.finternational.x.options[menuNum].selected = true;
			}
		    urlValue = document.finternational.x.options[menuNum].value;

            document.finternational.action=urlValue;
            document.finternational.submit();
   } // end of internationalSubmit();

//**********   Product Details Tab functions   *******************//
   
//** Tab Content script- © Dynamic Drive DHTML code library (http://www.dynamicdrive.com)
//** Last updated: Nov 8th, 06

var enabletabpersistence=0 //enable tab persistence via session only cookies, so selected tab is remembered?

////NO NEED TO EDIT BELOW////////////////////////
var tabcontentIDs=new Object()

function expandcontent(linkobj){
var ulid=linkobj.parentNode.parentNode.id //id of UL element
var ullist=document.getElementById(ulid).getElementsByTagName("li") //get list of LIs corresponding to the tab contents
for (var i=0; i<ullist.length; i++){
ullist[i].className=""  //deselect all tabs
if (typeof tabcontentIDs[ulid][i]!="undefined") //if tab content within this array index exists (exception: More tabs than there are tab contents)
document.getElementById(tabcontentIDs[ulid][i]).style.display="none" //hide all tab contents
}
linkobj.parentNode.className="selected"  //highlight currently clicked on tab
document.getElementById(linkobj.getAttribute("rel")).style.display="block" //expand corresponding tab content

/* 5/21/2008 No W2B Tab
var w2btab = document.getElementById('w2btab')
var w2btab2 = document.getElementById('w2btab2')
w2btab.style.background='transparent url(/images/Wtb-Left.jpg) no-repeat left top;'
w2btab.style.display = 'block'
w2btab.style.float = 'left'
//w2btab.style.color = 'white'
//w2btab.style.padding = '0px 0px 0px 0px'
//w2btab.style.margin = '0px 0px 0px 0px'
w2btab2.style.background='transparent url(/images/Wtb-Main.jpg) no-repeat right top;'
w2btab2.style.display = 'block'
w2btab2.style.float = 'left'
//w2btab2.style.color = 'white'
//w2btab2.style.padding = '1px 0px 0px 1px'
//w2btab2.style.margin = '20px 0px 0px 4px'
5/21/2008 No W2B Tab */
saveselectedtabcontentid(ulid, linkobj.getAttribute("rel"))
}

function expandtab(tabcontentid, tabnumber){ //interface for selecting a tab (plus expand corresponding content)
var thetab=document.getElementById(tabcontentid).getElementsByTagName("a")[tabnumber]
if (thetab.getAttribute("rel"))
expandcontent(thetab)
}

function savetabcontentids(ulid, relattribute){// save ids of tab content divs
if (typeof tabcontentIDs[ulid]=="undefined") //if this array doesn't exist yet
tabcontentIDs[ulid]=new Array()
tabcontentIDs[ulid][tabcontentIDs[ulid].length]=relattribute
}

function saveselectedtabcontentid(ulid, selectedtabid){ //set id of clicked on tab as selected tab id & enter into cookie
if (enabletabpersistence==1) //if persistence feature turned on
setCookie(ulid, selectedtabid)
}

function getullistlinkbyId(ulid, tabcontentid){ //returns a tab link based on the ID of the associated tab content
var ullist=document.getElementById(ulid).getElementsByTagName("li")
for (var i=0; i<ullist.length; i++){
if (ullist[i].getElementsByTagName("a")[0].getAttribute("rel")==tabcontentid){
return ullist[i].getElementsByTagName("a")[0]
break
}
}
}

function initializetabcontent(){
for (var i=0; i<arguments.length; i++){ //loop through passed UL ids
if (enabletabpersistence==0 && getCookie(arguments[i])!="") //clean up cookie if persist=off
setCookie(arguments[i], "")
var clickedontab=getCookie(arguments[i]) //retrieve ID of last clicked on tab from cookie, if any
var ulobj=document.getElementById(arguments[i])
var ulist=ulobj.getElementsByTagName("li") //array containing the LI elements within UL
for (var x=0; x<ulist.length; x++){ //loop through each LI element
var ulistlink=ulist[x].getElementsByTagName("a")[0]
if (ulistlink.getAttribute("rel")){
savetabcontentids(arguments[i], ulistlink.getAttribute("rel")) //save id of each tab content as loop runs
ulistlink.onclick=function(){
expandcontent(this)
return false
}
if (ulist[x].className=="selected" && clickedontab=="") //if a tab is set to be selected by default
expandcontent(ulistlink) //auto load currenly selected tab content
}
} //end inner for loop
if (clickedontab!=""){ //if a tab has been previously clicked on per the cookie value
var culistlink=getullistlinkbyId(arguments[i], clickedontab)
if (typeof culistlink!="undefined") //if match found between tabcontent id and rel attribute value
expandcontent(culistlink) //auto load currenly selected tab content
else //else if no match found between tabcontent id and rel attribute value (cookie mis-association)
expandcontent(ulist[0].getElementsByTagName("a")[0]) //just auto load first tab instead
}
} //end outer for loop
}


function getCookie(Name){ 
var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
if (document.cookie.match(re)) //if cookie found
return document.cookie.match(re)[0].split("=")[1] //return its value
return ""
}

function setCookie(name, value){
document.cookie = name+"="+value //cookie value is domain wide (path=/)
}

function bluemouse(thislink) {
thislink.style.color = '00599E'
	}
	
function whitemouse(thislink) {
thislink.style.color = 'white'
	}
	

//**********   W2B Javascript functions   *******************//


	/*W2B Javascript -- moved from w2b_js.cfm in shared /*
/* 
<cfparam name="attributes.byWholesaleSkus" default="">
<cfparam name="attributes.byRetailSkus" default="">
<cfparam name="attributes.showHomeDepotOption" default="">
<cfparam name="attributes.showLowesOption" default="">
<cfparam name="attributes.showLowes7BOption" default="">
<cfparam name="attributes.showMenardsOption" default="">
<cfparam name="attributes.aShowHouseSKU" default="">
*/

/*<script type="text/javascript">*/



/*
		Begin functions to display pop-up windows explaining the different  showroom programs for 
		Moen.
	 */
	 
	function SODpopUp(URL,w,h) {
		//Creates a popup window and fills it with the template corresponding to the sent URL
		day = new Date();
		id = day.getTime();
		windowWidth = w;
		windowHeight = h;
		centerWidth	= (screen.width/2)-(windowWidth/2);
		centerHeight = (screen.height/2)-(windowHeight/2);
		
		eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width='+windowWidth+',height='+windowHeight+',left = '+centerWidth+',top = '+centerHeight);");
	}
	
	function SHpopUp(URL,w,h) {
		//Creates a popup window and fills it with the template corresponding to the sent URL
		day = new Date();
		id = day.getTime();
		windowWidth = w;
		windowHeight = h;
		centerWidth	= (screen.width/2)-(windowWidth/2);
		centerHeight = (screen.height/2)-(windowHeight/2);
		
		eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width='+windowWidth+',height='+windowHeight+',left = '+centerWidth+',top = '+centerHeight);");
	}
	
	function KBpopUp(URL,w,h) {
		//Creates a popup window and fills it with the template corresponding to the sent URL
		day = new Date();
		id = day.getTime();
		windowWidth = w;
		windowHeight = h;
		centerWidth	= (screen.width/2)-(windowWidth/2);
		centerHeight = (screen.height/2)-(windowHeight/2);
		
		eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width='+windowWidth+',height='+windowHeight+',left = '+centerWidth+',top = '+centerHeight);");
	}
	
	function RetailerpopUp(URL,w,h) {
		//Creates a popup window and fills it with the template corresponding to the sent URL
		day = new Date();
		id = day.getTime();
		windowWidth = w;
		windowHeight = h;
		centerWidth	= (screen.width/2)-(windowWidth/2);
		centerHeight = (screen.height/2)-(windowHeight/2);
		
		eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width='+windowWidth+',height='+windowHeight+',left = '+centerWidth+',top = '+centerHeight);");
	}
	
	function OnlineRetailerpopUp(URL,w,h) {
		//Creates a popup window and fills it with the template corresponding to the sent URL
		day = new Date();
		id = day.getTime();
		windowWidth = w;
		windowHeight = h;
		centerWidth	= (screen.width/2)-(windowWidth/2);
		centerHeight = (screen.height/2)-(windowHeight/2);
		
		eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width='+windowWidth+',height='+windowHeight+',left = '+centerWidth+',top = '+centerHeight);");
	}
	
	function OnlinepopUp(URL,w,h) {
		//Creates a popup window and fills it with the template corresponding to the sent URL
		day = new Date();
		id = day.getTime();
		windowWidth = w;
		windowHeight = h;
		centerWidth	= (screen.width/2)-(windowWidth/2);
		centerHeight = (screen.height/2)-(windowHeight/2);
		
		eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width='+windowWidth+',height='+windowHeight+',left = '+centerWidth+',top = '+centerHeight);");
	}
 /*
 	End functions to display pop-up windows explaining the different  showroom programs for 
	Moen.
 */


/*
	Begin form validation for SKU by Customer searches
*/
	function validate_sbc(f,urlstring)
	{
		// Set default continue program value to false
		cont = false;
		/*alert(f.aShowHouseSKU.value);
		alert(f.byWholesaleSkus.value);
		alert(f.showHomeDepotOption.value);
		alert(f.showLowesOption.value);
		alert(f.showLowes7BOption.value);
		alert(f.showMenardsOption.value);*/
	/* <cfif attributes.aShowHouseSKU EQ "True"> */
	if(f.aShowHouseSKU.value == 'TRUE') {
		if(f.Zipcode.value.length == 0) {
			alert("Please enter your zip code.")
			//f.Zipcode.focus()
			return false
		}
	}
/* <cfelse> */
	else {
	// Check to see if a dealer type was checked
	//alert('else showhouse');
	
	/* <cfif attributes.byWholesaleSkus EQ "true"> */
	if(f.byWholesaleSkus.value == 'TRUE') {
		//alert('byWholeSkus');
		if(f.dealerTypeDS.checked) {
			cont = true
		}

		if(f.dealerTypeOWS.checked) {
			cont = true
		}
	}

	if(f.showHomeDepotOption.value == 'TRUE') {
		//alert('showHomeDepotOption');
		if(f.groupKeyAccountHD.checked) {
			cont = true
		}
	/* </cfif> */
	}

	/* <cfif attributes.showLowesOption EQ "true" OR attributes.showLowes7BOption EQ "true"> */
	if((f.showLowesOption.value == 'TRUE') || (f.showLowes7BOption.value == 'TRUE')) {
		//alert('showLowesOption');
		if(f.groupKeyAccountLN.checked) {
			cont = true
		}
	/* </cfif> */
	}
	/* <cfif attributes.showMenardsOption EQ "true"> */
	if(f.showMenardsOption.value == 'TRUE') {
		//alert('showMenardsOption');
		if(f.groupKeyAccountME.checked) {
			cont = true
		}
	/* </cfif> */
	}

		if(f.dealerTypeOL.checked) {
			olchecked = true
		} else {
			olchecked = false
		}

		if(f.dealerTypeAL.checked) {
			cont = true
		}
		
		if ((cont == false) && (olchecked == false)) {
			alert("Please select one or more specific locations.")
			/* <cfif attributes.byWholesaleSkus EQ "true"> */
			if(f.byWholeSkus == 'True') {
				//alert('byWholeSkus')
				//f.dealerTypeDS.focus()
			}
			/* <cfelse> */
			else {
			
				/* <cfif attributes.showHomeDepotOption EQ "true"> */
				if(f.showHomeDepotOption.value == 'TRUE') {
					//alert('2showHomeDepotOption')
					//f.groupKeyAccountHD.focus()
				}
				/* <cfelseif attributes.showLowesOption EQ "true"> */
				else if(f.showLowesOption.value == 'TRUE') {
					//alert('2showLowesOption')
					//f.groupKeyAccountLN.focus()
				}
				/* <cfelseif attributes.showMenardsOption EQ "true"> */
				else if(f.showMenardsOption.value == 'TRUE') {
					//alert('2showMenardsOption')
					//f.groupKeyAccountME.focus()
				}
				/* <cfelse> */
				else {
					//alert('finalelse')
					//f.dealerTypeOL.focus()
					//return false
				}
				/* </cfif> */
			/* </cfif> */
				//return false
			}
			
			return false
		}

		// Check to see if a zip code was selected
		if((cont == false) && (olchecked != true) && (f.Zipcode.value.length == 0)) {
			alert("Please enter your zip code.")
			//f.Zipcode.focus()
			return false
		}
		
		if((cont == true) && (f.Zipcode.value.length == 0)) {
			alert("Please enter your zip code.")
			//f.Zipcode.focus()
			return false
		}
/* </cfif> */
}
		

		// If a standard zip code was entered, make sure that is a minmum length of 5 (std. Zip) or 8 (Zip + 2) or 10(Zip+4)
		if ((f.Zipcode.value.length > 0) && (f.Zipcode.value.length != 5) && (f.Zipcode.value.length != 8) && (f.Zipcode.value.length != 10)) {
			alert("Please enter a valid Zip code.")
			//f.Zipcode.focus()
			return false
		}
		
		var formaction = f.action;
		//alert (formaction);
		f.action = createUrlString(f.action);
		//alert (f.action);
		return true; 
		
	}

function goto_bannerURL() {
	alert('goto_bannerURL');
}


// Menu navigation functions
var menuArray = new Array(false,false);

function MenuToggle(nMenu) {
	
    SetMenuActive(nMenu);
		
	document.getElementById("dmenu"+nMenu).style.display = "inline"; 
	document.getElementById("dmenu"+nMenu).style.visibility = "visible";
		
	for (i=1;i<=2;i++) {
  	  if (i != nMenu) {
		document.getElementById("dmenu"+i).style.display = "none"; 
		document.getElementById("dmenu"+i).style.visibility = "hidden";
		SetMenuInactive(i);
	  } // end of if
	} // end of for-loop
	setTimeout("ClearMenu("+nMenu+")",2000);
} // end of MenuToggle()
function MainMenuToggle(id1,id2,nMenu) {
    changeBackground(id1,id2,'over',nMenu);	
//	MenuToggle(nMenu);
} // end of MenuToggle()

function ClearAllMenus() {
  for (i=1;i<=2;i++) {
	document.getElementById("dmenu"+i).style.display = "none"; 
	document.getElementById("dmenu"+i).style.visibility = "hidden"; 
	SetMenuInactive(i);
  }
} // end of ClearAllMenus()

function ClearMenu(nMenu) {
	if(!IsMenuActive(nMenu)) {
		document.getElementById("dmenu"+nMenu).style.display = "none"; 
		document.getElementById("dmenu"+nMenu).style.visibility = "hidden"; 
	}
} // end of ClearMenu()

function IsMenuActive(nMenu) {
		return menuArray[nMenu - 1];
} // end of IsMenuActive()

function SetMenuActive(nMenu) {
		menuArray[nMenu - 1] = true;
} // end of SetMenuActive()

function SetMenuInactive(nMenu)	{
		menuArray[nMenu - 1] = false;
} // end of SetMenuInactive()
function SetMainMenuInactive(id1,id2,nMenu)	{
   changeBackground(id1,id2,'out',nMenu);
   SetMenuInactive(nMenu);		
   ClearMenu(nMenu);
} // end of SetMenuInactive()
