/*
 * Baynote Observer for spie.org
 * Last updated: 5/11/09
 */
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;
}

var bn_onClickHandler = function(clickedElement, exitInfo) {
	var clickProdId = "";
	var clickUrl = "";
	var exitResult = false;
	if(typeof(bnObserver) != 'undefined' && typeof(bnObserver.defaultExitConfirmation) != 'undefined') {
		exitResult = bnObserver.defaultExitConfirmation(clickedElement,exitInfo);
	}
	if(clickedElement) {
		try{
			if (bn_isNotEmpty(clickedElement.tagName) && clickedElement.tagName == "INPUT" && clickedElement.id == "go" && clickedElement.value == "Add To Cart") {
				if(exitInfo != null && typeof(exitInfo.attrs) == "undefined") {
					exitInfo.attrs = new Object();
				}
				exitInfo.attrs.action = "AddToCart";
/* 			try{
				if(clickedElement.parentNode.tagName == "A")
					exitInfo.attrs.target = clickedElement.parentNode.href;
				else if (clickedElement.parentNode.parentNode.className == "publication")
					if(clickedElement.parentNode.parentNode.childNodes[1].childNodes[0].childNodes[0].href)
						exitInfo.attrs.target = clickedElement.parentNode.parentNode.childNodes[1].childNodes[0].childNodes[0].href;
				}catch(e){} */

				if (clickedElement.form && clickedElement.form.product_id)
					exitInfo.attrs.target = "http://spie.org/x648.xml?product_id=" + clickedElement.form.product_id.value;
				exitResult = true;
			} else if(clickedElement.alt == "Add To Cart" && clickedElement.parentNode.tagName == "A"){
				if(exitInfo != null && typeof(exitInfo.attrs) == "undefined") {
					exitInfo.attrs = new Object();
				}
					exitInfo.attrs.target = clickedElement.parentNode.href;
					exitInfo.attrs.action = "AddToCart";
					exitResult = true;
			}
		}catch(e){}
	}
	return exitResult;
}

function bn_showObserver() {
	/* 1. set customer id */
	bn_customerId = "spie";
	/* 2. set customer code */
	bn_code = "www";
	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";
	/* 3. set customer domain (optional) */
	baynote_globals.cookieDomain = "spie.org";
	/* 4. collect purchase info (optional) */ 
	bn_getOrderInfo();
	baynote_tag.exitConfirmation = bn_onClickHandler;
	baynote_tag.show();
}
if (typeof(baynote_tag)!="undefined") {
	bn_showObserver();
}



