/* Behavior for Fenner */

window.onload = function() {
	if (window.attachEvent) window.attachEvent("onload", sfHover);
//	if (window.attachEvent) window.attachEvent("onload", cfHover);	
	subNavHover();
	subNavHoverEng();
	bookmarkPage();
	printPage();
}

/* -- checker function - checks to see if variables in each function exist -- */

function checkVars(e) {
	var x = e.split(",");
	var pass = true;
	checkerInvalid = new Array;

	for(i=0; i<x.length; i++) {
		
		if(!eval(x[i])) {
		pass = false; 
		checkerInvalid[checkerInvalid.length] = x[i];
		}
		
	}
	
	return pass;

}


/* Code to let IE see the Product dropdown menu */
sfHover = function() {
	var sfEls = document.getElementById("left-nav").getElementsByTagName("LI");
	
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
			/*alert("hello");*/
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}

/* Code to let IE see the Custom Features dropdown menu
cfHover = function() {
	var sfEls = document.getElementById("body-nav").getElementsByTagName("LI");
	
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
			alert("hello");
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}*/

/* Code dictates mouseover/mouseout color states for engineering dropdown */
/* See next function down for mouseover/mouseout states for color states when engineering pages are active */
function subNavHover() {
					
	if(!checkVars('document.getElementById("engsub"), document.getElementById("eng")')) {
		return;
	}
	
	var eng_sub = document.getElementById("engsub");
	var eng = document.getElementById("eng");
	
	eng_sub.onmouseover = function() {
		eng.style.color = "#ffffff";
		eng.style.backgroundImage = "url(../images/body-nav-li-hvr-bg.gif)";
	}
	
	eng.onmouseout = function() {
		eng.style.color = "#004679";
		eng.style.backgroundImage = "url(../images/body-nav-li-bg.gif)";
	}
	
	eng_sub.onmouseout = function() {
		eng.style.color = "#004679";
		eng.style.backgroundImage = "url(../images/body-nav-li-bg.gif)";
	}
	
	eng.onmouseover = function() {
		eng.style.color = "#ffffff";
		eng.style.backgroundImage = "url(../images/body-nav-li-hvr-bg.gif)";
	}
}

/* Code dictates mouseover/mouseout color states for engineering dropdown when engineeering pages are active */
function subNavHoverEng() {
	
	
	if(!checkVars('document.getElementById("engsub"), document.getElementById("eng-active")')) {
		return;
	}
				
	var eng_sub = document.getElementById("engsub");
	var eng_active = document.getElementById("eng-active");
	
	eng_sub.onmouseover = function() {
		eng_active.style.color = "#ffffff";
		eng_active.style.backgroundImage = "url(../images/body-nav-li-hvr-bg.gif)";
	}
	
	eng_active.onmouseout = function() {
		eng_active.style.color = "#ffffff";
		eng_active.style.backgroundImage = "url(../images/body-nav-li-hvr-bg.gif)";
	}
	
	eng_sub.onmouseout = function() {
		eng_active.style.color = "#ffffff";
		eng_active.style.backgroundImage = "url(../images/body-nav-li-hvr-bg.gif)";
	}
	
	eng_active.onmouseover = function() {
		eng_active.style.color = "#ffffff";
		eng_active.style.backgroundImage = "url(../images/body-nav-li-hvr-bg.gif)";
	}
}


function bookmarkPage() {

	if(!document.getElementById("bookmark-link")) {
		return;
	}
	
	var title = document.title;
	var url = window.location.href;
	var bookmark = document.getElementById("bookmark-link");
	
	bookmark.onclick = function() {
		
		if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
		} 
		
		else if( window.external ) { // IE Favorite
		window.external.AddFavorite( url, title);
		}
		
		else if(window.opera && window.print) { // Opera Hotlist
		return true;
		}
	}
}

function printPage() {
	
	if(!document.getElementById("print-link")) {
		return;
	}
	
	var print_link = document.getElementById("print-link");
	
	print_link.onclick = function() {
		window.print();
	}
}

function mailpage()
{
mail_str = "mailto:?subject=A friend recommends the following page on the Fenner Precision website ";
mail_str += "&body=I thought you might be interested in the following page on the Fenner Precision website ";
mail_str += ". You can view it at, " + location.href; 
location.href = mail_str;
}