/***************************************************************************
 *
 * Javascript file which defines the objects and functions used to send
 * site usage statistics to the tracking service like hitbox or Omniture.
 *
 * This basically acts as wrapper to the tracking service so that any changes
 * to the tracking service code need not be replicated in every page but in
 * one single page.
 *
 * Author: Santhosh Kumar
 * Modified By : Hariharan Visvanathan
 ***************************************************************************/
// Include s_code.js file
document.write('<script type="text/javascript" src="js/s_code.js"></script>');


/***************************************************
 *
 *This function defines the category values as 
 * reported to site catalyst
 *
 ****************************************************/
function SearchCategories(){
	this.technicalSolution = 'TS';
	this.communities = 'CO';
	this.learningResources='LR';
	this.productHelp = 'PH';
	this.dataDownload = 'DD';
	this.serviceRequest = 'SR';
}



/****************************
*
* Result link Click function ; called from simple and Advanced 
* search result pages
* This function in turns calls the SiteCatalyst function
*
*************************/
function resultLinkClicked(oThis,category,linkText, id){
	waResultsClick(oThis,category,linkText,id);
}


/*******************************************
* Main Tracking object
*******************************************/

function TrackingInfo() {
	//Collects user info
	this.user = new UserInfo();
	//Collects Search info
	this.search = new SearchInfo();
	//Collects Page info
	this.page = new PageInfo();
	//Collects Solution info
	this.doc = new DocumentInfo();

	//alert("In Tracking Info end");	
}

/***************************************************************************
 *
 * Object collects user information
 *
 * Application should set all the appropriate values.  If value is not availabe
 * to a particular attribute, it should be set to javascript literal null rather
 * than string 'null'
 ***************************************************************************/
function UserInfo() {
	//The CSN associated with the logged in user.
	this.csn = null;

	//The GUID associated with the logged in user.
	this.guid = null;

	//The type of the logged in user. For ex., Partner, Subscriber, Public etc.
	this.role = null;

	//The language from the user's profile. For ex., English, French, Italian etc.
	this.language = null;

	//The county as documented in user's profile.
	this.country = null;

	// Products for which the User is entitled to.....populated only for subscription user
	this.entitledProducts = null;

}

/***************************************************************************
 *
 * Object collects user information
 *
 * Application should set all the appropriate values.  If value is not availabe
 * to a particular attribute, it should be set to javascript literal null rather
 * than string 'null'
 ***************************************************************************/
function SearchInfo() {
	//The keyword used for advacned or simple search.
	this.queryString = null;

	//The list of products selected while performing the search. Each selected
	//product must be delimited by :
	//
	//For ex., "AutoCAD:AutoCAD LT:AutoCAD Map 2000i Release 4:AutoSketch"
	this.products = null;

	//The language selected while performing the search.
	this.languages = null;

	
	// Intended Categories to be Searched-array
	this.searchCategories = null;


	// Fetched Categories of the results-array
	this.resultCategories = null;
	
	
	// Quanty of results fetched-array;corresponds to the value in resultCategories
	this.categoryResultQty = null;
	
	
	// Current Page Result Range . eg. 10-20 or 30-40
	this.resultsShown=null;
}


/***************************************************************************
 *
 * Object collects Solution information
 *
 * Application should set all the appropriate values.  If value is not availabe
 * to a particular attribute, it should be set to javascript literal null rather
 * than string 'null'
 ***************************************************************************/
function DocumentInfo() {

	//The uniquely identifiable adsk internal id associated with page. For ex.,
	//solution id while viewing a solution page.
	this.docId = null;


	// Solution Title Brief
	this.title = null;

	// Language of the Solution Content
	this.language = null;

	// Name of the Solution Creator
	this.creator = null;


	// Products Pertaining to this Solution
	this.products = null;

	//The repository, which the page is displaying the content from.
	//For ex., Solution page belongs to Technical Solutions repository
	this.repository = null; // Need to check whether this is required or not.

	//The page rating number as specified by customer while submitting the page
	//feedback.
	this.rating = null;

	//The page rating comments as entered by the customer while submitting the
	//page feedback.
	this.ratingComments = null;
}


/***************************************************************************
 *
 * Object collects page information
 *
 * Application should set all the appropriate values.  If value is not availabe
 * to a particular attribute, it should be set to javascript literal null rather
 * than string 'null'
 ***************************************************************************/
function PageInfo() {

	//The name of the page. For ex., "Basic Search Results", or "View Solution" etc.
	this.name = null;

	//The section of group to which this section belongs to.
	this.siteSection = null;

}



/***************************************************************************
 *
 * Copy the attribues from application tracking object to tracker's
 * attributes (which always looks very cyptic, I don't know why).
 *
 ***************************************************************************/
function copyTrackingProperties(stat) {

	// Vijay I have added this section as per your the latest design document.
	// Enable it when you get s_code and wa object definitio

	//copy page related info

	
	wa.siteSection = stat.page.siteSection;
	
	wa.pageTemplate = stat.page.name;
	
	//copy user info
	
	wa.customerType = stat.user.role;
	
	wa.profileLanguage = stat.user.language;
	
	wa.profileCountry = stat.user.country;
	// CSN no longer needed
	//wa.csn = stat.user.csn;

	wa.guid = stat.user.guid;

	// copy search info

	wa.resultsNumberShown = stat.search.resultsShown;

	wa.productSelected = stat.search.products;
	
	wa.contentCatResults = stat.search.resultCategories;
	
	wa.contentCatResultsQty = stat.search.categoryResultQty;
	
	wa.contentCatSelected = stat.search.searchCategories;
	
	wa.searchTerm = stat.search.queryString;
	
	wa.languageSelected = stat.search.languages;

	//copy solution info
	
	wa.solutionID = stat.doc.docId;
	
	wa.solutionTitle = stat.doc.title;
	
	wa.solutionLanguage = stat.doc.language;
	
	wa.solutionCreator = stat.doc.creator;
	
	wa.solutionProducts = stat.doc.products;
	
	wa.feedbackRating = stat.doc.rating;
	
	wa.feedbackComments = stat.doc.ratingComments;

}

/***************************************************************************
 *
 * Initializes the tracking code.
 *
 ***************************************************************************/
function initTracking(stat) {

	copyTrackingProperties (stat);
	
//	alert("wa.customerType: "+wa.customerType);
//	alert("wa.contentCatSelected: "+wa.contentCatSelected);
//	alert("wa.productSelected: "+wa.productSelected);
//	alert("wa.languageSelected:  "+wa.languageSelected);

//	alert("about to make Omniture call");

	//alert("wa.feedbackRating: "+wa.feedbackRating);
	//alert("wa.feedbackComments: "+wa.feedbackComments);
   	//alert("wa.solutionID: "+wa.solutionID);
   	//alert("wa.solutionProducts: " +wa.solutionProducts);
	var s_code=s.t();
	if(s_code) {
		document.write(s_code);
	}
}