// JavaScript Document

function displayTab(id1, id2){
	myElement = document.getElementById(id2);
	//close all tabs first
	document.getElementById("type-options").className = "closed";
	document.getElementById("type-options2").className = "closed";	
	document.getElementById("type-options3").className = "closed";	
	
	myElement.className = "clearfix";
	if(id1 == "res_bath"){
		document.getElementById("res_bath").className = "here";
		document.getElementById("res_kitchen").className = "";
		document.getElementById("comm_bath").className = "last";
	}else if(id1 == "res_kitchen"){
		document.getElementById("res_bath").className = "";
		document.getElementById("res_kitchen").className = "here";
		document.getElementById("comm_bath").className = "last";
	}else if(id1 == "comm_bath"){
		document.getElementById("res_bath").className = "";
		document.getElementById("res_kitchen").className = "";
		document.getElementById("comm_bath").className = "here last";
	}
	
}

// Copyright 2006,2007 Bontrager Connection, LLC
// http://bontragerconnection.com/ and http://www.willmaster.com/
// Version: July 28, 2007
var cX = 0; var cY = 0; var rX = 0; var rY = 0;

function UpdateCursorPosition(e){ 
	cX = e.pageX; 
	cY = e.pageY;
}
function UpdateCursorPositionDocAll(e){ 
	cX = event.clientX; cY = event.clientY;
}

if(document.all) { 
	document.onmousemove = UpdateCursorPositionDocAll; 
} else { 
	document.onmousemove = UpdateCursorPosition;
}

function AssignPosition(d, id, isNewProducts) {
	if(self.pageYOffset) {
		rX = self.pageXOffset;
		rY = self.pageYOffset;
	} else if(document.documentElement && document.documentElement.scrollTop) {
		rX = document.documentElement.scrollLeft;
		rY = document.documentElement.scrollTop;
	} else if(document.body) {
		rX = document.body.scrollLeft;
		rY = document.body.scrollTop;
	}
	if(document.all) {
		cX += rX; 
		cY += rY;
	}
	
	var winW
    if (self.innerWidth) {
        winW = self.innerWidth;
    } else if (document.documentElement && document.documentElement.clientWidth) {
        winW = document.documentElement.clientWidth;
    } else if (document.body) {
        winW = document.body.clientWidth;
    }


	if(id == "email_n"){
		if(cY < 130){
			popY = 480;
		}else{
			popY = cY;
		}

        if (isNewProducts != undefined && isNewProducts) {
            d.style.left = (515) + "px";
            d.style.top = (450) + "px";
        } else {
            if (cX > 630 && cX <1000){
                d.style.left = (515) + "px";
                d.style.top = (popY) + "px";
            } else if (cX > 430 && cX <629){
                d.style.left = (406) + "px";
                d.style.top = (popY) + "px";
            } else if (cX > 230 && cX <429){
                d.style.left = (211) + "px";
                d.style.top = (popY) + "px";
            } else if (cX > 0 && cX < 229){
                d.style.left = (15) + "px";
                d.style.top = (popY) + "px";
            }
        }
    }else if (id == "popup_forgot"){
		d.style.left = (cX) + "px";
		d.style.top = (cY) + "px";
		forgotX = cX;
		forgotY = cY;
	}else if (id == "popup_er" || id == "popup_good"){
//		d.style.left = (cX) + "px";
		d.style.left = (forgotX) + "px";
//		d.style.top = (cY) + "px";
		d.style.top = (forgotY) + "px";
		
	}else {
		if(cY < 130){
			popY = 280;
		}else{
			popY = cY;
		}

        if (isNewProducts != undefined && isNewProducts) {
            d.style.left = (515) + "px";
            d.style.top = (450) + "px";
        } else {
            if (cX > 750 && cX <900){
                d.style.left = (770) + "px";
                d.style.top = (popY) + "px";
            } else if (cX > 630 && cX <749){
                d.style.left = (603) + "px";
                d.style.top = (popY) + "px";
            } else if (cX > 430 && cX <629){
                d.style.left = (405) + "px";
                d.style.top = (popY) + "px";
            } else if (cX > 230 && cX <429){
                d.style.left = (210) + "px";
                d.style.top = (popY) + "px";
            } else if (cX > 0 && cX < 229){
                d.style.left = (15) + "px";
                d.style.top = (popY) + "px";
            }
        }
    }
}


function HideContent(d) {
	if(d.length < 1) { return; }
	document.getElementById(d).style.display = "none";
}

function ShowProjContent(d) {
	if(d.length < 1) { return; }
	
	// close any other open containers first
	if (d != "email_n"){
		p1 = document.getElementById("email_n").style.display;
		if(p1 == "block")
			document.getElementById("email_n").style.display = "none";
	}
	if (d != "popup_add"){
		p2 = document.getElementById("popup_add").style.display;
		if(p2 == "block")
			document.getElementById("popup_add").style.display = "none";
	}
	if (d != "popup_rn"){
		p3 = document.getElementById("popup_rn").style.display;
		if(p3 == "block")
			document.getElementById("popup_rn").style.display = "none";
	}
	if (d != "popup_sanf"){
		p4 = document.getElementById("popup_sanf").style.display;
		if(p4 == "block")
			document.getElementById("popup_sanf").style.display = "none";
	}
	if (d != "popup_pnt"){
		p4 = document.getElementById("popup_pnt").style.display;
		if(p4 == "block")
			document.getElementById("popup_pnt").style.display = "none";
	}
	if (d != "popup_del"){
		p4 = document.getElementById("popup_del").style.display;
		if(p4 == "block")
			document.getElementById("popup_del").style.display = "none";
	}

	// open requested container	
	var dd = document.getElementById(d);
	AssignPosition(dd, d);
	dd.style.display = "block";
}

function ShowContent(d, isNewProducts) {
	if(d.length < 1) { return; }
	
	// close any other open containers first
	if (d != "email_n" && document.getElementById("email_n")){
		p1 = document.getElementById("email_n").style.display;
		if(p1 == "block")
			document.getElementById("email_n").style.display = "none";
	}
	if (d != "popup_n" && document.getElementById("popup_n")){
		p5 = document.getElementById("popup_n").style.display;
		if(p5 == "block")
			document.getElementById("popup_n").style.display = "none";
	}

	// open requested container	
	var dd = document.getElementById(d);
	AssignPosition(dd, d, isNewProducts);
	dd.style.display = "block";
}

function forgotPW(d) {
	if(d.length < 1) { return; }
	
	// close any other open containers first
	if (d != "popup_forgot"){
		p1 = document.getElementById("popup_forgot").style.display;
		if(p1 == "block")
			document.getElementById("popup_forgot").style.display = "none";
	}
	if (d != "popup_er"){
		p1 = document.getElementById("popup_er").style.display;
		if(p1 == "block")
			document.getElementById("popup_er").style.display = "none";
	}
	if (d != "popup_good"){
		p1 = document.getElementById("popup_good").style.display;
		if(p1 == "block")
			document.getElementById("popup_good").style.display = "none";
	}

	// open requested container	
	var dd = document.getElementById(d);
	AssignPosition(dd, d);
	dd.style.display = "block";
}

function ShowProjFldContent(d) {
	if(d.length < 1) { return; }
	// close any other open containers first
	if (d != "email_n"){
		p1 = document.getElementById("email_n").style.display;
		if(p1 == "block")
			document.getElementById("email_n").style.display = "none";
	}
	if (d != "popup_addfld"){
		p1 = document.getElementById("popup_addfld").style.display;
		if(p1 == "block")
			document.getElementById("popup_addfld").style.display = "none";
	}
	if (d != "popup_pnt"){
		p1 = document.getElementById("popup_pnt").style.display;
		if(p1 == "block")
			document.getElementById("popup_pnt").style.display = "none";
	}
	if (d != "popup_del"){
		p1 = document.getElementById("popup_del").style.display;
		if(p1 == "block")
			document.getElementById("popup_del").style.display = "none";
	}

	// open requested container	
	var dd = document.getElementById(d);
	AssignPosition(dd, d);
	dd.style.display = "block";
}

function ReverseContentDisplay(d) {
	if(d.length < 1) { return; }
	var dd = document.getElementById(d);
	AssignPosition(dd);
	if(dd.style.display == "none") { dd.style.display = "block"; }
	else { dd.style.display = "none"; }
}

function showhide(id, mynum){
	var myElement = document.getElementById(id);
	var mynum = parseFloat(mynum);
	var browserName=navigator.appName; 
	
	if (browserName=="Microsoft Internet Explorer") { 
		// hide all first
		mycount = myElement.firstChild.childNodes.length;
		for(i=0; i<mycount;i++){
			if(i != mynum){
			myElement.firstChild.childNodes[i].firstChild.nextSibling.nextSibling.className = "closed";
			myElement.firstChild.childNodes[i].firstChild.firstChild.src="/common/images/nav/close.gif"
			}
		}
		// now show the appropriate one
		currState = myElement.firstChild.childNodes[mynum].firstChild.nextSibling.nextSibling.className;
		
		if(currState == "closed"){
			myElement.firstChild.childNodes[mynum].firstChild.nextSibling.nextSibling.className = "open";
			myElement.firstChild.childNodes[mynum].firstChild.firstChild.src="/common/images/nav/open.gif";
		}else{
			myElement.firstChild.childNodes[mynum].firstChild.nextSibling.nextSibling.className = "closed";
			myElement.firstChild.childNodes[mynum].firstChild.firstChild.src="/common/images/nav/close.gif"
		}
	} else { 	
		// hide all first
		mycount = myElement.firstChild.nextSibling.childNodes.length;
		j=0;
		addAmount = mynum + 1;
		mynum = mynum + addAmount;
		for(i=1; i<mycount;i++){
			
			if (i%2 == 0){
				j = i + 1;
			}else{
				j = i;
				if(i != mynum){
					myElement.firstChild.nextSibling.childNodes[j].firstChild.nextSibling.nextSibling.className = "closed";
					myElement.firstChild.nextSibling.childNodes[j].firstChild.firstChild.src="/common/images/nav/close.gif";
				}
			}
		}
		// now show the appropriate one
		currState = myElement.firstChild.nextSibling.childNodes[mynum].firstChild.nextSibling.nextSibling.className;
		
		if(currState == "closed"){
			myElement.firstChild.nextSibling.childNodes[mynum].firstChild.nextSibling.nextSibling.className = "open";
			myElement.firstChild.nextSibling.childNodes[mynum].firstChild.firstChild.src="/common/images/nav/open.gif";
		}else{
			myElement.firstChild.nextSibling.childNodes[mynum].firstChild.nextSibling.nextSibling.className = "closed";
			myElement.firstChild.nextSibling.childNodes[mynum].firstChild.firstChild.src="/common/images/nav/close.gif"
		}
	}
}

function showhide_more(){
	myelement = document.getElementById("more");
	myelementCurClass = myelement.className;
	if(myelementCurClass == "closed"){
		myelement.className = "open";
		document.getElementById("readMore").style.display = "none";
	}else{
		myelement.className = "closed";
		document.getElementById("readMore").style.display = "";
	}
	
}

function enlarge(myimg){
	document.getElementById("enlargeImg").src = myimg;
	document.getElementById("enlargewin").className = "open";
}
function closeEnlarge(){
	document.getElementById("enlargewin").className = "closed";
}

function closeGallery(){
	document.getElementById("gallerywin").className = "closed";
}
function toggleSaveToMyKohler(myChecked){

	myElement1 = document.getElementById("mykohlerdd");
	myElement2 = document.getElementById("mykolherinputfld");

	if (myChecked == false){
		myElement1.className = "open";
		myElement2.className = "closed";
		
	}else{
		myElement1.className = "closed";
		myElement2.className = "open";
	}

}
function showDiv(id){
	myElement = document.getElementById(id);
	myElement.className = "open";
}
function hideDiv(id){
	myElement = document.getElementById(id);
	myElement.className = "closed";
}
function showhidediv(id){
	myElement = document.getElementById(id);
	currentState = myElement.className;
	if(currentState == "closed"){
		myElement.className = "pad ten clearfix";
	}else{
		myElement.className = "closed";
	}	
}

function navToggle(id){
	menuElement = document.getElementById("menu"+ id);
	containerElement = document.getElementById("fob"+ id);
	
	for(i=1; i<5; i++){
		document.getElementById("menu"+i).className = "notselected";
		document.getElementById("fob"+i).className = "closed";
	}
	menuElement.className = "selected";
	containerElement.className = "pad ten open";
}

function showhide_login(hidethis, showthis){
	h_element = document.getElementById(hidethis);
	s_element = document.getElementById(showthis);
	
	h_element.className = "closed";
	s_element.className = "pad ten clearfix";
	
}
function showdefaults(div1, div2, div3){
	for (var i = 0; i < arguments.length; i++){
		document.getElementById(arguments[i]+"_login").className = "closed";
		document.getElementById(arguments[i]).className = "pad ten clearfix";
	}
}

function showhide_vbp_np(){
	myelement = document.getElementById("vbp_np");
	myelementCurClass = myelement.className;
	if(myelementCurClass == "closed"){
		myelement.className = "pad ten clearfix";
	}else{
		myelement.className = "closed";
	}
}
function showhide_vbp_news(){
	myelement = document.getElementById("vbp_news");
	myelementCurClass = myelement.className;
	if(myelementCurClass == "closed"){
		myelement.className = "pad ten clearfix";
	}else{
		myelement.className = "closed";
	}	
}
function popWin(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function switchtumbs(id, desc, price, img){
	var browserName=navigator.appName; 
	var mynum = 0;
	var itemCount = document.getElementById(id).parentNode.childNodes.length;
	
	if (browserName=="Microsoft Internet Explorer") { 
		for(i=1; i<=itemCount;i++){
			myID = "thumbs_item"+i;
			document.getElementById(myID).firstChild.className = "nothing";
		}
		//update current
		document.getElementById(id).firstChild.className = "here";
		document.getElementById("proddesc").innerHTML = desc + " <strong>"+price+"</strong>";
	}else{
		
		var j=0;
		var addAmount = mynum + 1;
		mynum = mynum + addAmount;
	
		
		for(i=1; i<itemCount;i++){
			myNodeName = document.getElementById(id).parentNode.childNodes[i].nodeName;
			if(myNodeName == "LI"){
				document.getElementById(id).parentNode.childNodes[i].firstChild.nextSibling.className = "nothing";
			}
		}
		//update current
		document.getElementById(id).firstChild.nextSibling.className = "here";			
	}
	
	document.getElementById("proddesc").innerHTML = desc + " <strong>"+price+"</strong>";
	newImg = "/common/images/prod/" + img;
	document.getElementById("prod_photo_img").src = newImg;
}

function resetFld(id, msg){
	if(id.value == "" || id.value == " ")
		id.value = msg;
}

function checkRooms(){
	var fldsAreEmpty = false;
	for (i=1; i<6; i++){
		id = "roomfld" + i;
		currFldVal = document.getElementById(id).value;
		if(currFldVal == "" || currFldVal == " ")
			fldsAreEmpty = true;
	}
	
	if(fldsAreEmpty == true){
		alert("Please enter room names in the fives spaces below before adding more rooms.");
	}else{
		for (i=1; i<6; i++){
			id = "roomfld" + i;
			document.getElementById(id).value = "";
		}
		fldsAreEmpty = true;
		var newRoom = parseInt(document.getElementById("roomNum5").innerHTML) + 1;
		for (i=1; i<6; i++){
			id = "roomNum" + i;
			document.getElementById(id).innerHTML = newRoom;
			newRoom++;
		}
	}
}

function showFldAddRooms(id){
	if(id == true){
		document.getElementById("addFldAddRooms").className = "open";
	} else {
		document.getElementById("addFldAddRooms").className = "closed";
	}
}

function switchthumbs2(id, desc, price, img){
	var browserName=navigator.appName; 
	
	$('#prod_details > ul > li > a').removeClass('here');
	
	if (browserName=="Microsoft Internet Explorer") { 
		document.getElementById(id).firstChild.className = "here";
	}else{
		document.getElementById(id).firstChild.nextSibling.className = "here";
	}
	document.getElementById("proddesc").innerHTML = desc;
    if (price.indexOf('ote') == -1) {
        document.getElementById("proddesc").innerHTML += " <strong>"+price+"</strong>";
    }
	newImg = img;
	document.getElementById("prod_photo_img").src = ""+newImg;
}

function disableSave(id1, id2){
	$(document).ready(function() {
		 $('#saveToMyKohler'+id1).css('background', 'url(/common/images/icons/ico_add_gray.gif) left no-repeat');
		 $('#saveToMyKohler'+id1).css('color', '#CCC');
	});
	if(id2 != "undefined"){
		$(document).ready(function() {
		 $('#saveToMyKohler'+id2).css('background', 'url(/common/images/icons/ico_add_gray.gif) left no-repeat');
		 $('#saveToMyKohler'+id2).css('color', '#CCC');
	});
	}
}

var timer;
var clearMenuTimer = null;

//menuClearTimeout: reset the clock
function menuClearTimeout(){
	if (clearMenuTimer) clearTimeout(clearMenuTimer);
	clearMenuTimer = null;
	menuFlag = false;
}

// menuStartTimeout: begin countdown
function menuStartTimeout(id1, id2){
	menuStart = new Date();
	menuFlag = true;
	//clearMenuTimer = setTimeout("menuDoHide('"+id1+"','"+id2+"')", 100);
	clearMenuTimer = setTimeout("menuDoHide()", 100);
}
// menuDoHide: after timeout, hide sub menu
function menuDoHide(){
	if (!menuFlag) return;
	var elapsed = new Date() - menuStart;
	if (elapsed < 1000) {
		//document.getElementById(id1).className = "closed";
		//document.getElementById(id2).className = "pad ten";
		
		document.getElementById("myBookmarkscontainer_login").className = "closed";
		document.getElementById("mykohlercontainer_login").className = "closed";
		document.getElementById("myfavscontainer_login").className = "closed";
		
		document.getElementById("myBookmarkscontainer").className = "pad ten";
		document.getElementById("mykohlercontainer").className = "pad ten";
		document.getElementById("myfavscontainer").className = "pad ten";

		return;
	}
	menuFlag = false;
}


function ShowProjFldContentFramed(d) {
	if(d.length < 1) { return; }
	// close any other open containers first
	if (d != "email_n"){
		p1 = document.getElementById("email_n").style.display;
		if(p1 == "block")
			document.getElementById("email_n").style.display = "none";
	}
	if (d != "popup_addfld"){
		p1 = document.getElementById("popup_addfld").style.display;
		if(p1 == "block")
			document.getElementById("popup_addfld").style.display = "none";
	}
	if (d != "popup_pnt"){
		p1 = document.getElementById("popup_pnt").style.display;
		if(p1 == "block")
			document.getElementById("popup_pnt").style.display = "none";
	}
	if (d != "popup_del"){
		p1 = document.getElementById("popup_del").style.display;
		if(p1 == "block")
			document.getElementById("popup_del").style.display = "none";
	}

	// open requested container
	var dd = document.getElementById(d);
	AssignPosition(dd, d);

    dd.style.top = 0;
    dd.style.left = 0;

    dd.style.display = "block";
}

