// JavaScript Document

function addLoadEvent( func ) {
	var oldonload = window.onload;
	if ( typeof window.onload != 'function' ) { window.onload = func; } 
	else {
		window.onload = function() {
			if (oldonload) { oldonload(); }
			func();
		}
	}
}


sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
} 
	
if (window.attachEvent) window.attachEvent("onload", sfHover); 


String.prototype.trim = function () {
    return this.replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1");
}; 


// attach event to mail a friend button
addLoadEvent( 
	function() {
		if ( document.getElementById && document.getElementById('emailFriend') ) {
			document.getElementById('emailFriend').onclick = emailForm;
		} 
	}
);

// attach event to footer newsletter signup
addLoadEvent( 
	function() {
		if ( document.getElementById && document.getElementById('newsfooter') ) {
			document.getElementById('newsfooter').onclick = newsForm;
		} 
	}
);

// attach event to right side newsletter signup
addLoadEvent( 
	function() {
		if ( document.getElementById && document.getElementById('newsright') ) {
			document.getElementById('newsright').onclick = newsForm;
		} 
	}
);

// attach event to right side newsletter signup (in the copy)
addLoadEvent( 
	function() {
		if ( document.getElementById && document.getElementById('newsright2') ) {
			document.getElementById('newsright2').onclick = newsForm;
		} 
	}
);

addLoadEvent( 
	function() {
		if ( document.getElementById && document.getElementById('signupNav') ) {
			document.getElementById('signupNav').onclick = newsForm;
		} 
	}
);


// mail a friend pop up window
function emailForm() {
	var url = document.getElementById('emailFriend').href;
	window.open( url, 'emailWindow', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=400,height=450');
	return false;
}

// newsletter signup pop up window
function newsForm() {
	window.open( 'https://app.e2ma.net/app/view:Join/signupId:30188', 'newsWindow', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=540,height=480');
	return false;
}

function exitToShop( destination ) {
	if ( confirm( "You are about to leave the Yum-o! website to go to Cooking.com, an online store that carries our products and other great tools for your kitchen. When you shop at Cooking.com through this special link, a portion of the proceeds of your entire purchase will support Yum-o!'s mission to empower kids and their families to develop healthy relationships with food and cooking." ) ) {
		window.location = destination;
	}
}

function exitToAuctions( destination ) {
	if ( confirm( 'You have clicked on an external link, and are about to leave this site.' ) ) {
		window.location = destination;
	}
}
