	// VKI - Brian Katz 080410
	// All GA on-page tagging specific to www.industrialcontrolsonline.com
	// May only be loaded after GAvkiLib.js has loaded
	// All calls to segmentVisitor are contained below, allowing ga code to load at page end for benefit of autotagging code.
	// The only exceptions are:
		//	- no exceptions yet 

var strAlert = "";
var strLocation = document.location.toString();

	// Testing live pages in production without releasing the code to the users.
	// 1) Set debugging on in the query string and if debugging is on, set a cookie to persist debugging(see +-18 lines down) 
	// 2) Then check if either the query string or the cookies to see if debugging is on
	// 3) even if pages change and debugging cannot be set in the URL, the cookie is set and testing can continue
var strCookies  = unescape(document.cookie);
var bolDebugging = ( (strLocation.indexOf('vki_debugging') >= 0) || (strCookies.indexOf('vki_debugging') >= 0) ); 

function accumulate_alert(strMessage)
{
	strAlert += strMessage + "\n";	
}

function VKIsetCookie(c_name,value,expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

if (bolDebugging) 
{
	
		if (strLocation.indexOf('vki_debugging=1') >= 0)	
		{
			VKIsetCookie('vki_debugging',1,1);			//<< persist debugging
		}
		else if (strLocation.indexOf('vki_debugging=0') >= 0)	// turn off persistent debugging by deleting the cookie
		{
			bolDebugging = false;
			VKIsetCookie('vki_debugging','',0);			//<< delete the cookie
		}
		
		
}
		if (bolDebugging) accumulate_alert('GAvkiIndustrialControls_estore.js is called');

		var strURL = unescape(window.location.toString());
		var divElement = document.getElementById("VKItestDiv");
		var strTrackPageView = "";
		var strSegmentVisitor = "No Action";

		strURL = strURL.toLowerCase();
		
		// Does not have form New_Customer_Content so must be the confirmation page
		if (strURL.indexOf("page=new customer") >= 0 && typeof(document.New_Customer_Content) == "undefined") 
		{
			if (bolDebugging) divElement.innerHTML =  "/New Customer/Thank You/ " + strURL + " " + typeof(document.New_Customer_Content);
			strTrackPageView = "/New Customer/Thank You/";
			strSegmentVisitor = 'New Customer - Never Purchased';
		}
		else if (strURL.indexOf("page=new shopper") >= 0 
					&& typeof(document.New_Shopper_Content) == "undefined"
		   		)   
		{
			if (bolDebugging) divElement.innerHTML =  "/New Shopper/Thank You/" + strURL + " " + typeof(document.New_Customer_Content);
			strTrackPageView = "/New Shopper/Thank You/";
			strSegmentVisitor = 'New Shopper - Never Purchased';
		}
		else if (strURL.indexOf("page=rfq checkout") >= 0) 
				if (typeof(document.forms['RFQ_Checkout_Content']) == "undefined")	// Confirmation page 
				{
					strTrackPageView = "/Request for Quote Submitted/";
					if (bolDebugging) divElement.innerHTML =  strTrackPageView + 
															  strURL + " document.RFQ_Checkout_Content is: " + 
															  typeof(document.forms['RFQ_Checkout_Content']);
					strSegmentVisitor = 'Requested Quote';
				}
				else	// Quote address details form
				{
					strTrackPageView = "/Request for Quote Checkout Address Form/";
					if (bolDebugging) divElement.innerHTML = strTrackPageView + 
															  strURL + " document.RFQ_Checkout_Content is: " + 
															  typeof(document.forms['RFQ_Checkout_Content']);
					strSegmentVisitor = 'Added to Quote';
				}
				

		else if (strURL.indexOf("page=shopping cart") >= 0)   
		{
			if (bolDebugging) divElement.innerHTML =  strURL;
			strTrackPageView = '';
			strSegmentVisitor = 'Added to Cart';
		}

		else if (strURL.indexOf("page=order summary") >= 0)   
		{
			if (bolDebugging) divElement.innerHTML =  strURL;
			strTrackPageView = '';
			strSegmentVisitor = 'Purchased';
		}

		else
		{
			if (bolDebugging) divElement.innerHTML =  "Nothing interesting in URL: " + strURL +  
					"<BR> and New_Customer_Content object is:" + typeof(document.forms['New_Customer_Content']) +  
					"<BR> and New_Shopper_Content object is:" + typeof(document.forms['New_Shopper_Content']) +  
					"<BR> and RFQ_Checkout_Content object is:" + typeof(document.forms['RFQ_Checkout_Content']);
		}
		
		if (bolDebugging) divElement.innerHTML += " strTrackPageView = '" + 
							strTrackPageView + "' and strSegmentVisitor = '" + strSegmentVisitor + "'";
		if (bolDebugging) divElement.innerHTML = "{ " + divElement.innerHTML + " }";
		if (bolDebugging) divElement.innerHTML = divElement.innerHTML + "<BR>" + unescape(document.cookie);

		// Now that all <a> tags will have loaded...
		InvokeAutoTagging();



		var pageTracker = _gat._getTracker("UA-459923-1");
		
		pageTracker._setDomainName("industrialcontrolsonline.com");	// = track root domain and its subdomains
		
		pageTracker._initData();
		
			// document.strTrackPageView would be set on page to specify a virtual pageView
		if (strTrackPageView) 
		{
			if (bolDebugging) 	accumulate_alert(strTrackPageView);
			pageTracker._trackPageview(strTrackPageView);
		}
		else 
		{
			if (bolDebugging) 	accumulate_alert('_trackPageview(No Virtual PageView)');
			pageTracker._trackPageview();
		}
		
		if (strSegmentVisitor)
		{
			if (bolDebugging) 	accumulate_alert(strSegmentVisitor);
			segmentVisitor(strSegmentVisitor);
		}
		else if (strLocation.indexOf('GApage=instaquote') >= 0)
		{
			if (bolDebugging) 	accumulate_alert('Submitted Instaquote');
			segmentVisitor('Submitted Instaquote');
		}
		else if (strLocation.indexOf('GApage') >= 0 && strLocation.indexOf('thankyou') >= 0)
		{
			if (bolDebugging) 	accumulate_alert('Added to Quote');
			segmentVisitor('Added to Quote');
		}
		else
		{
			if (bolDebugging) 	accumulate_alert('No Action');
			segmentVisitor('No Action');
		}
		
		if (bolDebugging) 	alert(strAlert);


	
