function bn_isNotEmpty(checkVar) {
	return (typeof(checkVar) != "undefined") && (checkVar != null) && (checkVar != "");
}

function bn_getUrlParam(name, url) {
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp(regexS,"i");
	var results = regex.exec(url);
	if(results == null)
		return "";
	else
		return unescape(results[1]);
}

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) {
		if (bn_isNotEmpty(clickedElement.tagName) && clickedElement.tagName == "IMG") {
			if(clickedElement.parentNode && clickedElement.parentNode.tagName == "A") {
				var linkHref = clickedElement.parentNode.href;
				if(bn_isNotEmpty(linkHref) && linkHref.match(/\/cgi-bin\/exe_cart.asp\?productid1\=.*&quantity1\=.*serviceid1\=.*/i)) {
					clickProdId = bn_getUrlParam("ProductID1", linkHref);
				}
			}
		}
		if (bn_isNotEmpty(clickProdId)) {
			clickUrl = "http://artwork.barewalls.com/artwork/product.html?productid="+clickProdId;
			if(exitInfo != null && typeof(exitInfo.attrs) == "undefined") {
				exitInfo.attrs = new Object();
			}
			exitInfo.attrs.action = "AddToCart";
			exitInfo.attrs.target = clickUrl;
			exitResult = true;
		}
	}
	return exitResult;
}

baynote_tag.server="http://barewalls-www.baynote.net";
baynote_tag.customerId="barewalls";
baynote_tag.code="www";
baynote_tag.type="baynoteObserver";
baynote_getProductId();
var baynote_url = window.location.href;
if (baynote_url.indexOf("https") == 0)
	if (baynote_url.indexOf("https://www.barewalls.com/secure/order/thankyou.asp") == 0) {
		baynote_getOrderInfo();
		baynote_tag.server="https://barewalls-www.baynote.net";
		baynote_tag.show();
	} else baynote_tag.noshow();
else {
baynote_tag.exitConfirmation = bn_onClickHandler;
baynote_tag.show();
}

/**
 *
 *	baynote_getOrderInfo
 *	--------------------
 *
 *	Extract the order detail from the "Thank you" page.
 *	The information is currently available from some 
 *	"Clear Saleing" JS.
 *
 **/
function baynote_getOrderInfo() {
	if (!orderNum || !orderTotal) return;
	baynote_tag.attrs.purchaseId = orderNum;
	baynote_tag.attrs.totalPurchases = orderTotal;
}

function baynote_getProductId() {
	var myUrl = window.location.href;
	if (myUrl.indexOf("http://artwork.barewalls.com/artwork/") != 0) return;
	var regex = new RegExp("productid=","i");
	var match = regex.exec(myUrl);
	if (match) return;
	var myInputs = document.getElementsByTagName("input");
	if (!myInputs) return;
	for (var i = 0; i < myInputs.length; i++) {
		if (myInputs[i].getAttribute("name") == "ProductID1") {
			baynote_tag.url = myUrl + "&productid=" + myInputs[i].getAttribute("value");
		}
	}
}