/*
 * Baynote Observer for www.uncommongoods.com
 * Last updated: 5/08/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;
}
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]);
}
function bn_onClickHandler(clickedElement, exitInfo) {
	if(typeof(bnObserver) != 'undefined' && typeof(bnObserver.defaultExitConfirmation) != 'undefined') {
		exitResult = bnObserver.defaultExitConfirmation(clickedElement,exitInfo);
	}
	if(clickedElement) {
		var bn_clicked_url = clickedElement.href; 
		if(!bn_isNotEmpty(bn_clicked_url))
			bn_clicked_url = clickedElement.parentNode.href;
		var bn_guide_source_val = bn_getUrlParam("source", bn_clicked_url);
		if (bn_isNotEmpty(clickedElement.tagName) && bn_guide_source_val== 'related_ug') {
			exitInfo.attrs = new Object();
			exitInfo.attrs.nonBnGuide = 'true';
			exitInfo.baynote_bnrank = "1";
			exitInfo.baynote_guide = "ugGuide";
			exitInfo.baynote_req = "ugGuide";
		}								
	}
		return exitResult;
}
function bn_showObserver() {
	/* 1. set customer id */
	bn_customerId = "uncommongoods";
	/* 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 = "uncommongoods.com";
	/* 4. collect purchase info (optional) */ 
	baynote_tag.exitConfirmation = bn_onClickHandler;
	bn_getOrderInfo();
	baynote_tag.show();
}
if (typeof(baynote_tag)!="undefined") {
	bn_showObserver();
}

