LogPageEvent();

function LogAPIFormEvent(formName,formField){
	var btmBISVisitor = readCookie("btmBISVisitor");
	var btmBISSession = readCookie("btmBISSession");

	var SessionStarted

	if(btmBISVisitor==null){
	    
		var visitorGUID = generateGuid();
		createCookie("btmBISVisitor",visitorGUID,"99");
	    
	}
	else
	{
		var visitorGUID = btmBISVisitor;
	}
	if(btmBISSession==null){
	    
		var sessionGUID = generateGuid();
		createCookie("btmBISSession",sessionGUID,"");
		SessionStarted = 1;
	}
	else
	{
		var sessionGUID = btmBISSession;
	}
	var logdata='';
	logdata += 'lh=' + location.host;
	logdata += '&cn=' + navigator.appCodeName;
	logdata += '&an=' + navigator.appName;
	logdata += '&ua=' + escape(navigator.userAgent);
	logdata += '&av=' + escape(navigator.appVersion);
	logdata += '&p=' + navigator.platform;
	logdata += '&r=' + escape(document.referrer);
	logdata += '&pn=' + location.pathname ;
	logdata += '&w=' + screen.width;
	logdata += '&h=' + screen.height;
	logdata += '&vg=' + visitorGUID;
	logdata += '&sg=' + sessionGUID;
	logdata += '&qs=' + escape(location.search);
	
	logdata += '&c1=FormTracker';
	if (formName != ""){logdata += "&c2="+ escape(cleanup(formName));}
	if (formField != ""){logdata += "&c3="+ escape(cleanup(formField));}

	var csLoc = new String(window.parent.document.location);
	if(csLoc.indexOf("https://")!=-1){csHttpPrefix="https://";}else{csHttpPrefix="http://";}
	
	//var xmlhttp = new XMLHttpRequest();
	//xmlhttp.open ('POST', csHttpPrefix+'stats.madfishanalytics.com/LogAction.aspx?' + logdata, false);
	
	//xmlhttp.onreadystatechange = function() {
	
    //if (xmlhttp.readyState == 4) {
        // Your callback code goes here
	//	}
	var imgtag = document.getElementById("MadFishTrackingImage")
    if (imgtag){
    imgtag.src=csHttpPrefix +"stats.madfishstats.com/LogAction.aspx?" + logdata
    }
    
	
	//xmlhttp.send('');
	//document.writeln("<div style='display:none'><img src='" + csHttpPrefix +"stats.madfishstats.com/LogAction.aspx?" + logdata +"' /></div>");
	
	//
//document.writeln("<sc" + "ript language=javascript type=text/JavaScript src='" + csHttpPrefix +"stats.madfishstats.com/LogAction.aspx?" + logdata +"'></sc" + "ript>");

}
function LogPageEvent(){
	var btmBISVisitor = readCookie("btmBISVisitor");
	var btmBISSession = readCookie("btmBISSession");

	var SessionStarted

	if(btmBISVisitor==null){
	    
		var visitorGUID = generateGuid();
		createCookie("btmBISVisitor",visitorGUID,"99");
	    
	}
	else
	{
		var visitorGUID = btmBISVisitor;
	}
	if(btmBISSession==null){
	    
		var sessionGUID = generateGuid();
		createCookie("btmBISSession",sessionGUID,"");
		SessionStarted = 1;
	}
	else
	{
		var sessionGUID = btmBISSession;
	}
	var logdata='';
	logdata += 'lh=' + location.host;
	logdata += '&cn=' + navigator.appCodeName;
	logdata += '&an=' + navigator.appName;
	logdata += '&ua=' + navigator.userAgent;
	logdata += '&av=' + navigator.appVersion;
	logdata += '&p=' + navigator.platform;
	logdata += '&r=' + escape(document.referrer);
	logdata += '&pn=' + location.pathname ;
	logdata += '&w=' + screen.width;
	logdata += '&h=' + screen.height;
	logdata += '&vg=' + visitorGUID;
	logdata += '&sg=' + sessionGUID;
	logdata += '&qs=' + escape(location.search);

	// Create a new QueryString object
	var myQuery = new QueryString();
	// Read query string from browser into the new QueryString object, name myQuery
	myQuery.read();
	// Check the status, to make sure it read the query string
	// Then write out the query string arguments
	if(myQuery.getStatus())
	{	var sHtml = "<table border='1'>";
		sHtml += "<caption>Query String Data</caption>";
		sHtml += "<thead><tr><th>Name</th><th>Value</th></tr></thead>";
		var aQueryData = myQuery.getAll();
		for(var n in aQueryData)
		{	
		if( n=='ls' ){logdata += 'ls='+aQueryData[n]}
		}
	}

	if (document.getElementById("mfs_OrderNumber") && document.getElementById("mfs_OrderNumber").innerHTML != ""){logdata += "&on="+ escape(cleanup(document.getElementById("mfs_OrderNumber").innerHTML));}
	if (document.getElementById("mfs_OrderTotal") && document.getElementById("mfs_OrderTotal").innerHTML != ""){logdata += "&ot="+ escape(cleanup(document.getElementById("mfs_OrderTotal").innerHTML));}
	if (document.getElementById("mfs_OrderState") && document.getElementById("mfs_OrderState").innerHTML != ""){logdata += "&os="+ escape(cleanup(document.getElementById("mfs_OrderState").innerHTML));}
	if (document.getElementById("mfs_OrderCountry") && document.getElementById("mfs_OrderCountry").innerHTML != ""){logdata += "&oc="+ escape(cleanup(document.getElementById("mfs_OrderCountry").innerHTML));}
	if (document.getElementById("mfs_OrderShipping") && document.getElementById("mfs_OrderShipping").innerHTML != ""){logdata += "&op="+ escape(cleanup(document.getElementById("mfs_OrderShipping").innerHTML));}
	if (document.getElementById("mfs_OrderTax") && document.getElementById("mfs_OrderTax").innerHTML != ""){logdata += "&ox="+ escape(cleanup(document.getElementById("mfs_OrderTax").innerHTML));}
	if (document.getElementById("mfs_OrderDiscounts") && document.getElementById("mfs_OrderDiscounts").innerHTML != ""){logdata += "&od="+ escape(cleanup(document.getElementById("mfs_OrderDiscounts").innerHTML));}
	if (document.getElementById("mfs_OrderGrandTotal") && document.getElementById("mfs_OrderGrandTotal").innerHTML != ""){logdata += "&og="+ escape(cleanup(document.getElementById("mfs_OrderGrandTotal").innerHTML));}
	if (document.getElementById("mfs_OrderItems") && document.getElementById("mfs_OrderItems").innerHTML != ""){logdata += "&oi="+ escape(cleanup(document.getElementById("mfs_OrderItems").innerHTML));}
	if (document.getElementById("mfs_CheckOutStep") && document.getElementById("mfs_CheckOutStep").innerHTML != ""){logdata += "&cs="+ escape(cleanup(document.getElementById("mfs_CheckOutStep").innerHTML));}
	if (document.getElementById("mfs_CategoryID") && document.getElementById("mfs_CategoryID").innerHTML != ""){logdata += "&ci="+ escape(cleanup(document.getElementById("mfs_CategoryID").innerHTML));}
	if (document.getElementById("mfs_CategoryName") && document.getElementById("mfs_CategoryName").innerHTML != ""){logdata += "&ca="+ escape(cleanup(document.getElementById("mfs_CategoryName").innerHTML));}
	if (document.getElementById("mfs_ProductID") && document.getElementById("mfs_ProductID").innerHTML != ""){logdata += "&pi="+ escape(cleanup(document.getElementById("mfs_ProductID").innerHTML));}
	if (document.getElementById("mfs_ProductName") && document.getElementById("mfs_ProductName").innerHTML != ""){logdata += "&pr="+ escape(cleanup(document.getElementById("mfs_ProductName").innerHTML));}


	if (SessionStarted == 1){logdata += '&ss=1';}
	 
	if (document.getElementById("mfs_Action") && document.getElementById("mfs_Action").innerHTML != ""){logdata += "&ac="+ escape(cleanup(document.getElementById("mfs_Action").innerHTML));}

	if (document.getElementById("mfs_CustomData1") && document.getElementById("mfs_CustomData1").innerHTML != ""){logdata += "&c1="+ escape(cleanup(document.getElementById("mfs_CustomData1").innerHTML));}
	if (document.getElementById("mfs_CustomData2") && document.getElementById("mfs_CustomData2").innerHTML != ""){logdata += "&c2="+ escape(cleanup(document.getElementById("mfs_CustomData2").innerHTML));}
	if (document.getElementById("mfs_CustomData3") && document.getElementById("mfs_CustomData3").innerHTML != ""){logdata += "&c3="+ escape(cleanup(document.getElementById("mfs_CustomData3").innerHTML));}
	if (document.getElementById("mfs_CustomData4") && document.getElementById("mfs_CustomData4").innerHTML != ""){logdata += "&c4="+ escape(cleanup(document.getElementById("mfs_CustomData4").innerHTML));}
	if (document.getElementById("mfs_CustomData5") && document.getElementById("mfs_CustomData5").innerHTML != ""){logdata += "&c5="+ escape(cleanup(document.getElementById("mfs_CustomData5").innerHTML));}

	if (document.getElementById("mfs_SiteVersion") && document.getElementById("mfs_SiteVersion").innerHTML != ""){logdata += "&sv="+ escape(cleanup(document.getElementById("mfs_SiteVersion").innerHTML));}
	if (document.getElementById("mfs_PageVersion") && document.getElementById("mfs_PageVersion").innerHTML != ""){logdata += "&pv="+ escape(cleanup(document.getElementById("mfs_PageVersion").innerHTML));}

	if (document.getElementById("mfs_SearchedKeywords") && document.getElementById("mfs_SearchedKeywords").innerHTML != ""){logdata += "&kw="+ escape(cleanup(document.getElementById("mfs_SearchedKeywords").innerHTML));}

	var csLoc = new String(window.parent.document.location);
	if(csLoc.indexOf("https://")!=-1){csHttpPrefix="https://";}else{csHttpPrefix="http://";}
	document.writeln("<sc" + "ript language=javascript type=text/JavaScript src='" + csHttpPrefix +"stats.madfishstats.com/LogAction.aspx?" + logdata +"'></sc" + "ript>");
    document.writeln("<div style='display:none'><img id='MadFishTrackingImage' src='' /></div>");
}

function QueryString() {
	// PROPERTIES
	this.arg = new Array;
	this.status = false;
	
	// METHODS
	this.clear = Clear;
	this.get = Get;
	this.getAll = GetAll;
	this.getStatus = GetStatus;
	this.read = Read;
	this.set = Set;
	this.write = Write;
	
	// FUNCTIONS
	
	// Clears the array, this.arg, of all query string data
	function Clear()
	{	this.arg = new Array;
	}
	
	// Returns a named value from the query string
	function Get(sName)
	{	return this.arg[sName];
	}
	
	// Return all data as an associative array
	function GetAll()
	{	return this.arg;
	}
	
	function GetStatus()
	{	return this.status;
	}
	
	// Reads the query string into an array named this.arg
	function Read(sUrl) 
	{	var aArgsTemp, aTemp, sQuery;
		// You can pass in a URL query string
		if(sUrl)
		{	sQuery = sUrl.substr(sUrl.lastIndexOf("?")+1, sUrl.length);
		}
		// Or read it from the browser location
		else
		{	sQuery = window.location.search.substr(1, window.location.search.length);
		}
		// Check that query string exists and contains data
		// If not (length < 1) then return
		if(sQuery.length < 1) {return;}
		// Else set this.status to true and proceed
		else {this.status = true;}
		//
		aArgsTemp = sQuery.split("&");	
		for (var i=0 ; i<aArgsTemp.length; i++)
		{	aTemp = aArgsTemp[i].split("=");
			this.arg[aTemp[0]] = aTemp[1];
		}
	}
	
	// Overwrites an existing named value in the array, this.arg
	// You can also pass null to delete from array
	function Set(sName,sValue)
	{	if (sValue == null) {delete this.arg[sName];}
		else {this.arg[sName] = sValue;}
	}
	
	// Writes out a string from the data in this.arg array
	// This string can be used to pass a new query string to the browser
	// when navigating to the next page. This allows a page
	// to create and pass data to another page via JavaScript.
	function Write()
	{	var sQuery = new String(""); 
		for (var sName in this.arg)
		{	if (sQuery != "") {sQuery += "&";}
			if (this.arg[sName]) {sQuery += sName + "=" + this.arg[sName];}
		}
		if (sQuery.length > 0) {return "?" + sQuery;}
		else {return sQuery;}
	}
}

function generateGuid(){var result, i, j;result = '';for(j=0; j<32; j++){if( j == 8 || j == 12|| j == 16|| j == 20)result = result + '-';i = Math.floor(Math.random()*16).toString(16).toUpperCase();result = result + i;}return result}

function createCookie(cookiename,value,expire) {
	
	if (expire > 0){
		var date = new Date();
		date.setFullYear(date.getFullYear() + 99,date.getMonth(),date.getDate());
		var expires = "; expires="+date.toGMTString();
		}
		else
		{var expires = "";// expires="+date.toGMTString();
		}
		document.cookie = cookiename+"="+value+expires+"; path=/";

}

function readCookie(name) {

	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}
function cleanup(str){str=str.replace(/(<([^>]+)>)/ig," ");str=str.replace(/ $/,"");str=str.replace(/^ /,"");return str;}