// Baynote Observer for biz-toolkit
//Last updated: Oct 14, 2009 

function bn_getMetaById(id) {
	var metas = document.getElementsByTagName("meta");
	
	for (var i = 0; i < metas.length; i++) {
		if (metas[i].id == id) {
			return metas[i].content;
		}
	}
	return null;
}

function bn_getTitleById(id) {
	var title = document.getElementsByTagName("img");
	
	for (var i = 0; i < title.length; i++) {
		if (title[i].id == id) {
			return title[i].title;
		}
	}
	return null;
}

function bn_getDescById(id) {
	var desc = document.getElementsByTagName("div");
	
	for (var i = 0; i < desc.length; i++) {
		if (desc[i].className == id) {
			return desc[i].innerHTML;
		}
	}
	return null;
}

function bn_isNotEmpty(name) {
	return (name != null) && (name != "");
}
function bn_getOrderInfo() {
	if (typeof(bnOrderId) != "undefined" && bn_isNotEmpty(bnOrderId))
		baynote_tag.attrs.purchaseId = bnOrderId;
	if (typeof(bnOrderTotal) != "undefined" && bn_isNotEmpty(bnOrderTotal))
		baynote_tag.attrs.totalPurchases = parseFloat(bnOrderTotal);
	if (typeof(bnOrderDetails) != "undefined" && bn_isNotEmpty(bnOrderDetails))
		baynote_tag.attrs.purchaseDetails = bnOrderDetails;
}
function bn_getMediaInfo() {
	if (typeof(bnMediaDuration) != "undefined" && bn_isNotEmpty(bnMediaDuration)) {
		baynote_tag.attrs.expectedDuration = bnMediaDuration;
	}	
}
function bn_onClickHandler(clickedElement, exitInfo) {
    if(typeof(bnObserver) != 'undefined' && typeof(bnObserver.defaultExitConfirmation) != 'undefined') {
        exitResult = bnObserver.defaultExitConfirmation(clickedElement,exitInfo);
    }
    if(clickedElement) {
        if (bn_isNotEmpty(clickedElement.tagName)) {
            if (clickedElement.parentNode == "li" && clickedElement.parentNode.tagName == "A"){
                var linkHref = clickedElement.href; 
                
                if(bn_isNotEmpty(linkHref)) {
		            var clickUrl = linkHref;
                }
            }
       
           if(exitInfo != null && typeof(exitInfo.attrs) == "undefined") {
                exitInfo.attrs = new Object();
            }
        
            exitInfo.attrs.action = "AddToCart";
            exitInfo.attrs.target = clickUrl;
            exitResult = true;
        }
    }
   return exitResult;
}
function bn_showObserver() {
	bn_customerId = "biz";
	bn_code = "toolkit";
	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";
	baynote_globals.cookieDomain = "toolkit.com";
	bn_getOrderInfo();
	bn_getMediaInfo();
	var metaDescription = bn_getMetaById("metaDescription");
	var productTitle = bn_getTitleById("ctl00_ContentPlaceHolder1_imgItem");
	var productPrice = bn_getDescById("priceDescOpen");
	
	if (metaDescription != null) {
	    baynote_tag.docAttrs.articleDescription = metaDescription;
	}
	if (productTitle != null) {
	    baynote_tag.docAttrs.itemTitle = productTitle;
	}
	if (productPrice != null) {
	    baynote_tag.docAttrs.itemPrice = productPrice;
	}
	baynote_tag.exitConfirmation = bn_onClickHandler;
	baynote_tag.show();
}
if (typeof(baynote_tag)!="undefined") {
	bn_showObserver();
}

