// Developed for HorizonHobby, Last Updated: Jun 26, 2008
// Javascript code to capture Observations 

baynote_globals.cookieDomain="horizonhobby.com";
var bn_location_href = window.location.href;
if (bn_location_href.indexOf("https://") == 0)
{
   baynote_tag.server = "https://horizonhobby-www.baynote.net";
} else {
   baynote_tag.server = "http://horizonhobby-www.baynote.net";
}
baynote_tag.customerId = "horizonhobby";
baynote_tag.code="www";
baynote_tag.type="baynoteObserver";

// Get purchase information if any 

if (baynote_isOrderPage())
  baynote_capturePurchaseData();

baynote_tag.show();


// capture purchase data from Google Analytics object.
function baynote_capturePurchaseData() 
{
	if(typeof(pageTracker) == 'object' && pageTracker.j && pageTracker.j.la && pageTracker.j.la.length == 1) {
		var bn_transObj = pageTracker.j.la[0];
		var bn_orderId = bn_transObj.v;
		var bn_orderTotal = bn_transObj.bc;
		if(baynote_isDefined(bn_orderId) && baynote_isDefined(bn_orderTotal)) {
			baynote_tag.attrs.purchaseId = bn_orderId;
			baynote_tag.attrs.totalPurchases = bn_orderTotal;
		}
	}
}

function baynote_isOrderPage()
{
	var pageUrl = baynote_getPageUrl();
    return (pageUrl.indexOf("https://checkout") == 0) &&
           (pageUrl.indexOf("Cart/Receipt.aspx") != -1); 
}

//Helper function to get current page url 
function baynote_getPageUrl() {
	var pageUrl = baynote_tag.url; 
	if ( !baynote_isDefined(pageUrl) )
	  pageUrl = window.location.href;
	return pageUrl;
}

// Utility method to test whether a param is defined or not. 
function baynote_isDefined(param) 
{
   return (typeof(param) != "undefined") && (param != null) && (param != ""); 
}

// Trim all white spaces from left and right. 
function baynote_trim(str)
{
	for(var k = 0; k < str.length && baynote_isWhitespace(str.charAt(k)); k++);
	for(var j=str.length-1; j>=0 && baynote_isWhitespace(str.charAt(j)) ; j--);
	return str.substring(k,j+1);
}
// Is the given character a white space? 
function baynote_isWhitespace(ch) {
	var whitespaceChars = " \t\n\r\f";
	return (whitespaceChars.indexOf(ch) != -1);
}

