/**
	A static class for passing along tracking information to the appropriate
	classes and functions.
	
	Customize this class if necessary to accomodate other tracking agencies (coremetrics and avenueA are currently implemented).
		
	@class Tracker		
	
	@access static
	
	@author R/GA
	@author noel@rga.com
*/
var Tracker = new Object();


/**
	@method track
		
*/
Tracker.track = function(actionTag) {

	var aveADebugText = "";
	var omnitureText = "" ;

	actionTag = clearEncoding(actionTag) ;

	if( shouldTrackOmniture == true ) {
		s_pageName = actionTag ;
		s_gs(s_account) ;
		omnitureText = "<br><br><b>Omniture: track page</b><br>" + s_pageName + "<br><br>";
	}

	if( shouldTrackAvenueA ) {
		aveADebugText = AvenueA.track(actionTag);
	}
	if ( aveADebugText == null ) aveADebugText = "";
	
	
	if( Tracker.inDebugMode() ) {

		var debug_str = actionTag + "</br>" + aveADebugText + omnitureText ;
		
		
		Tracker.displayDebug(debug_str) ;

	}

}


Tracker.trackClick = function(actionTag) {

	var cmDebugText = "" ;
	var aveADebugText = "";
	var omnitureText = "" ;


	actionTag = clearEncoding(actionTag) ;


	if( shouldTrackOmniture == true ) {
		s_pageName = actionTag ;
		s_gs(s_account) ;
		omnitureText = "<br><br><b>Omniture: track click: </b><br>" + s_pageName + "<br><br>";
	}


	if( Tracker.inDebugMode() ) {

		var debug_str = actionTag + "</br>" + aveADebugText + omnitureText ;
		
		// added for hitbox / cg
		Tracker.displayDebug(debug_str) ;

	}

}


/**

	@method trackProductView
	
	@param site_name
	@param category_name
	@param product_name
		
*/

Tracker.trackProductView = function(site_name, category_name, product_name) {

	// Function used for tracking Omniture product views	
	if( shouldTrackOmniture == true ) {

		
		var cmDebugText = "" ;
		var aveADebugText = "" ;
		var omnitureText = "" ;

		if( !site_name || site_name == null ) {
			site_name = "" ;
		}
		if( !category_name || category_name == null ) {
			category_name = "" ;
		}
		if( !product_name || product_name == null ) {
			product_name = "" ;
		}

		product_name = site_name ;
		site_name = "nikeidflash" ;
		category_name = "nikeid" ;

		var products_string = (site_name+":"+category_name+";"+product_name) ;

		// Set the Omniture global variables
		s_pageName = product_name ;
		s_events = "prodView" ;
		s_products = products_string ;
		s_gs(s_account) ;


		omnitureText = "<br><br><b>Omniture:</b><br><br>ProductView:<br><br>" + products_string + "<br><br>";

		if( Tracker.inDebugMode() ) {
			var debug_str = actionTag + "</br>" + aveADebugText + omnitureText ;
			Tracker.displayDebug(debug_str) ;
		}

	}

}


/**

	@method trackProductAddToCart
	
	@param site_name
	@param category_name
	@param product_name
		
*/

Tracker.trackProductAddToCart = function(site_name, category_name, product_name) {

	// Function used for tracking Omniture product views	
	if( shouldTrackOmniture == true ) {

		var cmDebugText = "" ;
		var aveADebugText = "" ;
		var omnitureText = "" ;

		if( !site_name || site_name == null ) {
			site_name = "" ;
		}
		if( !category_name || category_name == null ) {
			category_name = "" ;
		}
		if( !product_name || product_name == null ) {
			product_name = "" ;
		}

		product_name = site_name ;
		site_name = "nikeidflash" ;
		category_name = "nikeid" ;

		var products_string = (site_name+":"+category_name+";"+product_name) ;

		// Set the Omniture global variables
		s_pageName = product_name ;
		s_events = "prodView" ;
		s_products = products_string ;
		s_gs(s_account) ;
		omnitureText = "<br><br><b>Omniture:</b><br><br>AddToCart:<br><br>" + products_string + "<br><br>";

		if( Tracker.inDebugMode() ) {
			var debug_str = actionTag + "</br>" + + aveADebugText + omnitureText ;
			Tracker.displayDebug(debug_str) ;
		}

	}

}


/**
	@method trackRegistration
		
*/
Tracker.trackRegistration = function(newsletter_name, subscribed, cust_id, zip) {

	var cmDebugText = "" ;
	var aveADebugText = "" ;
	var omnitureText = "" ;

	//if( shouldTrackCoremetrics == true ) {
	//	cmDebugText = cmCreateRegistrationTag(newsletter_name, subscribed, cust_id, zip);
	//}

	if( shouldTrackOmniture == true ) {
		s_pageName = "BASKETBALL_USA_REGISTRATION_COMPLETE" ;
		s_gs(s_account) ;
		omnitureText = "<br><br><b>Omniture:</b><br>" + s_pageName + "<br><br>";
	}

	if( shouldTrackAvenueA ) {
		aveADebugText = AvenueA.track("registration");
	}
	if( Tracker.inDebugMode() ) {

		alert("nn " + newsletter_name + " subscr " + subscribed + " cust_id " +
             cust_id + " zip " + zip) ;

		var debug_str = cmDebugText + aveADebugText + omnitureText ;
		Tracker.displayDebug(debug_str) ;

	}


	
}


/**
	@method trackProduct
	
	@param cat_name
	@param cat_id
	@param prod_name
	@param prod_id
		
*/
Tracker.trackProduct = function(cat_name, cat_id, prod_name, prod_id) {

	var cmDebugText = "" ;
	var aveADebugText = "" ;
	var omnitureText = "" ;

	prod_name = clearEncoding(prod_name) ;


	if( shouldTrackCoremetrics == true ) {
		cmDebugText = cmCreateProductTag(cat_name, cat_id, prod_name, prod_id);
	}

	if( shouldTrackOmniture == true ) {
		actionTag = prod_name ;
		s_pageName = actionTag ;
		s_gs(s_account) ;
		omnitureText = "<br><br><b>Omniture:</b><br>" + actionTag + "<br><br>";
	}

	if( shouldTrackAvenueA ) {
		aveADebugText =	AvenueA.track(prod_id);
	}
	
	if( Tracker.inDebugMode() ) {
		var debug_str = cmDebugText + aveADebugText + omnitureText ;
		Tracker.displayDebug(debug_str) ;
	}


}


/**
	@method trackError
	@param actionTag String
		
*/
Tracker.trackError = function(actionTag) {
	cmCreateErrorTag();
}

/**

	This method probably belongs somewhere else, but it works fine for now here.
	
	Essentially, it allows you to track something and execute any javascript function you want.
	
	@method trackAndExecute
	
	@param actionTag
	@param functionName
	@param... the params to be be passed to functionName
		
*/
Tracker.trackAndExecute = function(actionTag, functionName) {

		
	this.track(actionTag);
	
	var action = unescape(functionName) + "("
	
	for (var i=2; i < arguments.length; i++) {		
		action += "'"+unescape(arguments[i])+"'";
		if (i < arguments.length-1) action += ",";
	}
	action += ");";

	eval( action);
	
}

/**

	Used to determine if the application is in tracking
      debug mode.
	
	@method inDebugMode
	
		
*/

Tracker.inDebugMode = function() {

	var in_debug_mode = false ;
	if( (cmdebug && cmdebug != null && cmdebug.indexOf("yes") > -1) ||
          (parent && parent.cmdebug && parent.cmdebug != null && parent.cmdebug.indexOf("yes") > -1) ) {
	     in_debug_mode = true ;	
	}
	
	return in_debug_mode ;
}


/**

	This method is used to display debug information in a popup
      window	
	
	@method displayDebug
	
	@param textToDisplay
	@param... the params to be be passed to functionName
		
*/
Tracker.displayDebug = function( textToDisplay )
{
	var displayScrollbar = "yes" ;
	var displayTitlebar  = "no" ;
	var winWidth	   = "450" ;
	var winHeight        = "450" ;
	var winDisplayPositionText = "" ;	 	
	var debugWindow = null, browser = null ; 
	var winFeatures = "" ;

	// Determine browser type
	browser = new Object();
	browser.isNetscape = false ;
	browser.isMicrosoft = false ;
	if(navigator.appName.indexOf("Netscape") != -1)	{	
		browser.isNetscape = true ;
	}
	else if ( navigator.appName.indexOf("Microsoft") != -1) {	
		browser.isMicrosoft = true;
	}
	
	// Based on browser type, determine the window display position text
	if( browser.isNetscape ) { 	
		winDisplayPositionText = ",screenX=0,screenY=0" ;
	}
	else {			
		winDisplayPositionText = ",left=0,top=0" ;
	}	

      // Set the window features	
   	windowFeatures = "width="+winWidth+",height="+winHeight+
                       winDisplayPositionText+",scrollbars="+displayScrollbar ;

	//open debug window
	debugWindow = window.open("","debugw",windowFeatures);
	debugWindow.focus() ;
	debugWindow.document.open() ;
	debugWindow.document.write('<html><head><title>debug</title><head><body bgcolor=gray>') ;
	debugWindow.document.write('<font size=-1 face=Arial,Helvetica>') ;
	debugWindow.document.write(textToDisplay) ;
	debugWindow.document.write('</font></body></html>') ;
	debugWindow.document.close() ;

}




