//**********   Site Navigation functions   *******************//

function changeBackground(id,id2,mousemovement) {
	    var generalTD = document.getElementById(id);
		var generalTDA = document.getElementById(id2);
	
	    if (mousemovement == 'over') {
          generalTD.style.background='url(http://en.moen.cn/images/white.jpg)';
		  generalTDA.style.color='#264f86';
        }
		else {
		  generalTD.style.background='url(http://en.moen.cn/images/white.jpg)';
		  generalTDA.style.color='#264f86';
		}

} // 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 = 'http://en.moen.cn/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("http://www.moen.cn/enzh/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
var w2btab = document.getElementById('w2btab')
var w2btab2 = document.getElementById('w2btab2')
w2btab.style.background='transparent url(http://en.moen.cn/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(http://en.moen.cn/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'

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("\u8bf7\u8f93\u5165\u60a8\u7684\u90ae\u653f\u7f16\u7801\u3002")
			//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("\u8bf7\u9009\u62e9\u4e00\u4e2a\u6216\u591a\u4e2a\u7279\u5b9a\u5730\u5740\u3002")
			/* <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("\u8bf7\u8f93\u5165\u60a8\u7684\u90ae\u653f\u7f16\u7801\u3002")
			//f.Zipcode.focus()
			return false
		}
		
		if((cont == true) && (f.Zipcode.value.length == 0)) {
			alert("\u8bf7\u8f93\u5165\u60a8\u7684\u90ae\u653f\u7f16\u7801\u3002")
			//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("\u8bf7\u8f93\u5165\u6709\u6548\u7684\u90ae\u653f\u533a\u53f7\u3002")
			//f.Zipcode.focus()
			return false
		}
		
		var formaction = f.action;
		//alert (formaction);
		f.action = createUrlString(f.action);
		//alert (f.action);
		return true; 
		
	}

/********************  Home page animator **************************/

/* this variable will keep the number of the image displayed notice that it is global so that different functions can change and see it */
var count = 0;

// these are the dynamic targets (changed depending on picture displayed)
var targ = new Array(3);
targ[0] = "http://www.moen.cn/enzh/bathroom/icon";
targ[1] = "http://www.moen.cn/enzh/kitchen/vestige";
targ[2] = "http://www.moen.cn/enzh/categories/rain-forest-showers";

// preload your images
var images = new Array(3);  // image array (again, assuming three pictures)
for (var i = 0; i < 3; i++)
{
        images[i] = new Image();
        images[i].src = "images/homebanner" + i + ".jpg";
        /* this assums you named your images picture0.gif, picture1.gif, and
picture2.gif
        // and put them in the "images" directory */
}

function do_animation() // this will animate your picture
{
    count++; // increment the counter
    if (count==3) count = 0;  // reset the counter if it gets to the last picture
	
    document.animation.src = images[count].src;  // changes your picture appropriately
	document.getElementById('animation-link').href = targ[count]; // change href 
    setTimeout("do_animation()", 5000); // delay before the next switch
    // make the number higher for a longer pause between switching
}




