/* Last updated: 07/21/2009 */
function bn_isNotEmpty(name) {
	return (name != null) && (name != "");
}

function bn_showObserver() {	
	bn_customerId = "campbells";	
	bn_code = "kitchen";
	var bn_locHref = window.location.href;
	if (bn_locHref.indexOf("https://") == 0) {
		baynote_tag.server = "https://" + bn_customerId + "-" + bn_code + ".baynote.net";
	} else {
		baynote_tag.server = "http://" + bn_customerId + "-" + bn_code + ".baynote.net";
	}
	
	baynote_tag.customerId = bn_customerId;
	baynote_tag.code = bn_code;
	baynote_tag.type = "baynoteObserver";
	if(bn_locHref.search("^https?://(www.)?campbellkitchen.com/.*", "i") >= 0){
		baynote_globals.cookieDomain = "campbellkitchen.com";
	}else{
		baynote_globals.cookieDomain = "campbellskitchen.com";
	}
	baynote_setAttrs();
	baynote_tag.exitConfirmation = bn_onClickHandler;
	baynote_tag.show();
}

function baynote_setAttrs() {
	/*alert('setAttrs');*/
	var metas = document.getElementsByTagName("meta");
	if (!metas) return;
	
	for (var i = 0; i < metas.length; i++) {
		if (!metas[i]) return;
			if (metas[i].name == "bn_title") {
				var tempMetaContent = metas[i].content;
				if(bn_isNotEmpty(tempMetaContent)) {
					baynote_tag.docAttrs.recipeTitle = tempMetaContent;
				}
			} else if (metas[i].name == "bn_id") {
				var tempMetaContent = metas[i].content;
				if(bn_isNotEmpty(tempMetaContent)) {
					baynote_tag.docAttrs.recipeId = tempMetaContent;
				}
			} else if (metas[i].name == "bn_description") {
				var tempMetaContent = metas[i].content;
				if(bn_isNotEmpty(tempMetaContent)) {
					baynote_tag.docAttrs.recipeDescription = tempMetaContent;
				}
			} else if (metas[i].name == "bn_thumbnail") {
				var tempMetaContent = metas[i].content;
				if(bn_isNotEmpty(tempMetaContent)) {
					baynote_tag.docAttrs.thumbnail = tempMetaContent;
				}
			}
	}
}

function bn_onClickHandler(clickedElement, exitInfo) {
	if(typeof(bnObserver) != 'undefined' && typeof(bnObserver.defaultExitConfirmation) != 'undefined') {
		exitResult = bnObserver.defaultExitConfirmation(clickedElement,exitInfo);
	}
	

	if(clickedElement) {
		if(exitInfo != null && typeof(exitInfo.attrs) == "undefined") {
            exitInfo.attrs = new Object();
         }
		if (bn_isNotEmpty(clickedElement.tagName)){
			var tn = clickedElement.tagName + "";
			var idName = clickedElement.id + "";
			if(tn=="IMG"){
				var altStr = clickedElement.alt + "";
				if(altStr == "Send to a Friend"){
					exitInfo.attrs.sendToFriend = '1';
				}else if(altStr == 'Print Recipe' || altStr =='Recipe with Photo' || altStr == 'Text Only Recipe' || altStr =='Recipe Card Format' || altStr =='Recipe Keepsake Format'){
					exitInfo.attrs.printRecipe = '1';
				}
			}else if(idName.match('AddToRecipeBox') != "null" ){
				if(tn == "INPUT"){
					exitInfo.attrs.recipeBoxPage = '1';					
				}else{
					exitInfo.attrs.recipeBoxSearch = '1';
				}
				exitResult = true;
			}
		}
	}
	return exitResult;
}
if (typeof(baynote_tag)!="undefined") {
	bn_showObserver();
}

