/* 01-21-2005 */

/**
	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 trackerdebug = getValue(location.search,"trackerdebug") ;
if( !trackerdebug || trackerdebug == null || trackerdebug == "" ) {
	trackerdebug = "no" ;
}



var Tracker = new Object();



/**
	@method track
	
		
*/
Tracker.track = function(actionTag,site_section,site_section_2) {
	
	var trackerdebugText = "" ;
	var aveADebugText = "";
	var omnitureText = "";
	var tagReported = false;
	var s_section = site_section ;
	var s_section_2 = site_section_2 ;
	if( !s_section || s_section==null ) {
		s_section = "" ;
	}


	if( !s_section_2 || s_section_2==null ) {
		s_section_2 = "" ;
	}
	
	actionTag = clearEncoding(actionTag) ;
	
	if( shouldTrackOmniture ) {			
		s_pageName = actionTag ;
		s_prop5=s_section ;
		s_prop6=s_section_2 ;

		s_gs(s_account);
		omnitureText = "<b>Omniture tag name</b></br>track: " + s_pageName + "<br><br>";
		tagReported = true;

		/* Special tracking code to clear the evar6 */
		s_eVar6="" ;

	}

	if( shouldTrackAvenueA ) {
		if( (g_aveAHash[actionTag]) && (g_aveAHash[actionTag] != null) &&
                (g_aveAHash[actionTag]!="") ) {
			aveADebugText = AvenueA.track(g_aveAHash[actionTag]);
		}
	}


	if( Tracker.inDebugMode() && tagReported ) {

		if( actionTag != "USWONT_header_storelocator" ) {
			var debug_str =  omnitureText +  aveADebugText ;
			
			Tracker.displayDebug(debug_str) ;
		}

	}

}


/**

	
	@method trackAndExecute
	
	@param actionTag
	@param functionName
	@param... the params to be be passed to functionName
		
*/
Tracker.trackAndExecute = function(actionTag, functionName,site_section) {
	
	var s_section = site_section ;
	if( !s_section || s_section==null ) {
		s_section = "" ;
	}

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

Tracker.trackPDP = function(styleNumber, productName) {

	var trackerdebugText = "" ;
	var omnitureText = "";
	var tagReported = false;
	
	if( shouldTrackOmniture ) {			
		var product_string =  productName ;
		s_pageName = product_string ;
		s_events="prodView" ;
		s_products= ";" + product_string ;
		s_gs(s_account) ;
		omnitureText = "<b>Omniture tag name</b></br>trackPDP: " + product_string + "<br><br>";
		tagReported = true;
		
	}

	if( Tracker.inDebugMode() && tagReported ) {

		var debug_str =  omnitureText ;
		Tracker.displayDebug(debug_str) ;
	}

}

Tracker.trackCartOpen = function(actionTag) {

	var trackerdebugText = "" ;
	var omnitureText = "";
	var tagReported = false;
	
	if( shouldTrackOmniture ) {			
		s_events="scView" ;
		s_gs(s_account) ;
		omnitureText = "<b>Omniture tag name</b></br>trackCartOpen: " + actionTag + "<br><br>";
		tagReported = true;
	}

	if( Tracker.inDebugMode() && tagReported ) {
		var debug_str =  omnitureText ;
		Tracker.displayDebug(debug_str) ;
	}

}

Tracker.trackAddToCart = function(styleNumber, productName) {

	var trackerdebugText = "" ;
	var omnitureText = "";
	var tagReported = false;
	
	if( shouldTrackOmniture ) {			
		var product_string = productName ;
		s_pageName = product_string ;
		s_events="scAdd" ;
		s_products= ";" + product_string ;
		s_gs(s_account) ;
		omnitureText = "<b>Omniture tag name</b></br>trackAddToCart: " + product_string + "<br><br>";
		tagReported = true;
		
	}

	if( Tracker.inDebugMode() && tagReported ) {

		var debug_str =  omnitureText ;
		Tracker.displayDebug(debug_str) ;
	}

}

Tracker.trackCheckout = function(styleNumber, productName) {

	var trackerdebugText = "" ;
	var omnitureText = "";
	var tagReported = false;
	
	if( shouldTrackOmniture ) {			
		var product_string =  productName ;
		s_pageName = product_string ;
		s_events="scCheckout" ;
		s_products= ";" + product_string ;
		s_gs(s_account) ;
		omnitureText = "<b>Omniture tag name</b></br>trackCheckout: " + product_string + "<br><br>";
		tagReported = true;
	}

	if( Tracker.inDebugMode() && tagReported ) {

		var debug_str =  omnitureText ;
		Tracker.displayDebug(debug_str) ;
	}

}


/**

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

Tracker.inDebugMode = function() {

	var in_debug_mode = false ;

	if( (trackerdebug && trackerdebug != null && trackerdebug.indexOf("yes")>-1) ||
          (parent && parent.trackerdebug && parent.trackerdebug != null && parent.trackerdebug.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	   = "550" ;
	var winHeight        = "700" ;
	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 ;

	var omnitureVals = "<b>Omniture Vars</b><br/>" ;

	omnitureVals += "s_account="+s_account+"<br />" ;	
	omnitureVals += "s_pageName="+s_pageName+"<br />" ;
	omnitureVals += "s_server="+s_server+"<br />" ;
	omnitureVals += "s_channel="+ s_channel+"<br />" ;
	omnitureVals += "s_pageType="+s_pageType+"<br />" ;
	omnitureVals += "s_referrer="+s_referrer+"<br />" ;

	omnitureVals += "s_prop1="+s_prop1+"<br />" ;
	omnitureVals += "s_prop2="+s_prop2+"<br />" ;
	omnitureVals += "s_prop3="+s_prop3+"<br />" ;
	omnitureVals += "s_prop4="+s_prop4+"<br />" ;
	omnitureVals += "s_prop5="+s_prop5+"<br />" ;
	omnitureVals += "s_prop6="+s_prop6+"<br />" ;
	omnitureVals += "s_prop7="+s_prop7+"<br />" ;
	omnitureVals += "s_prop8="+s_prop8+"<br />" ;
	omnitureVals += "s_prop9="+s_prop9+"<br />" ;
	omnitureVals += "s_prop10="+s_prop10+"<br />" ;
	omnitureVals += "s_prop11="+s_prop11+"<br />" ;
	omnitureVals += "s_prop12="+s_prop12+"<br />" ;
	omnitureVals += "s_prop13="+s_prop13+"<br />" ;
	omnitureVals += "s_prop14="+s_prop14+"<br />" ;
	omnitureVals += "s_prop15="+s_prop15+"<br />" ;
	omnitureVals += "s_prop16="+s_prop16+"<br />" ;
	omnitureVals += "s_prop17="+s_prop17+"<br />" ;
	omnitureVals += "s_prop18="+s_prop18+"<br />" ;
	omnitureVals += "s_prop19="+s_prop19+"<br />" ;
	omnitureVals += "s_prop20="+s_prop20+"<br />" ;
	omnitureVals += "s_campaign="+s_campaign+"<br />" ;
	omnitureVals += "s_state="+s_state+"<br />" ;
	omnitureVals += "s_zip="+s_zip+"<br />" ;
	omnitureVals += "s_events="+s_events+"<br />" ;
	omnitureVals += "s_products="+s_products+"<br />" ;
	omnitureVals += "s_purchaseID="+s_purchaseID+"<br />" ;
	omnitureVals += "s_eVar6="+s_eVar6+"<br />" ;

	var full_url = window.location.href ;

	//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+"<br/><b>source url:</b></br>"+full_url+"<br/><br/><b>sitename: </b>"+site_name+"<br/><br/>"+omnitureVals) ;
	debugWindow.document.write('</font></body></html>') ;
	debugWindow.document.close() ;

}


/**

	@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 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 = "" ;
		}
		var products_string = (site_name+":"+category_name+";"+product_name) ;

		// Set the Omniture global variables
		s_events = "prodView" ;
		s_products = products_string ;

		omnitureText = "<b>Omniture tag name</b></br>trackProductView: " + products_string + "<br><br>";

		if( Tracker.inDebugMode() ) {
			var debug_str = omnitureText  ;
			Tracker.displayDebug(debug_str) ;
		}

	}

}



/**

	@method trackClick
	
	@param click_description
		
*/




Tracker.trackClick = function(click_description) {

	// Function used for tracking Omniture product views	
	if( shouldTrackOmniture == true ) {
		
		var omnitureText = "" ;

		if( !click_description || click_description == null ) {
			click_description = "" ;
		}
		
		// Set the Omniture global variables
		s_linkType="o"; 
		s_lnk=s_co(click_description);
		s_gs(s_account) ;	
	

		omnitureText = "<b>Omniture tag name</b></br>trackClick: " + click_description + "<br><br>";

		if( Tracker.inDebugMode() ) {
			var debug_str = 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 = "" ;
		}
		var products_string = (site_name+":"+category_name+";"+product_name) ;

		// Set the Omniture global variables
		s_events = "scOpen,scAdd" ;
		s_products = products_string ;

		omnitureText = "<b>Omniture tag name</b></br>trackProductAddToCart: " + products_string + "<br><br>";

		if( Tracker.inDebugMode() ) {
			var debug_str = omnitureText ;
			Tracker.displayDebug(debug_str) ;
		}

	}

}


// pass it the queryString and the variable name
// it will return the value of that parameter or it does not exist, null
function getValue ( queryString, parameterName ) {
	if ( queryString.charAt( 0 ) == "?" ) queryString = queryString.substr(1);
	var query_array = queryString.split("&");
	for (var i=0; i< query_array.length; i++ ) {
		query_array[ i ] = query_array[ i ].split("=");
		if ( query_array[ i ][ 0 ] == parameterName ) {
			return query_array[ i ][ 1 ];
			break;
		}
	}
	return null;
}


function clearEncoding( actionTag ) {

	if( actionTag && actionTag != null && actionTag.indexOf("%") > -1 ) {
		actionTag = unescape(actionTag) ;
	}

	if( actionTag && actionTag != null && actionTag.indexOf("%") > -1 ) {
		actionTag = unescape(actionTag) ;
	}
	
	return actionTag ;
}



/** FUNCTIONS BELOW ARE DEPRECATED **/


/**
	@method trackRegistration
		
*/
Tracker.trackRegistration = function(newsletter_name, subscribed, cust_id, zip) {
	
	//var trackerdebugText = "" ;
	//var aveADebugText = "";
	
	//var tagReported = false;
	
	//if( shouldTrackAvenueA ) {
	//	aveADebugText = AvenueA.track("registration");
	//	tagReported = true;
	//}
	if( Tracker.inDebugMode() && tagReported ) {

		var debug_str = "<b>old registration. shouldn't be using this" ;
		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 trackerdebugText = "" ;
	//var aveADebugText = "" ;

	//var tagReported = false;
	
	//prod_name = clearEncoding(prod_name) ;

	//if( shouldTrackAvenueA ) {
		//aveADebugText =	AvenueA.track(prod_id);
		//tagReported = true;
	//}
	
	//if( Tracker.inDebugMode() && tagReported ) {
	//	var debug_str = "<b>old track product. shouldn't be using this" ;
	//	Tracker.displayDebug(trackerdebugText) ;
	//}


}


Tracker.trackHomePage = function(actionTag) {

	Tracker.track(actionTag) ;

}







