/* SiteCatalystWrapper */
var SCW = {

	//object containing list of values
	ContentProperties:null
	,EVars:null
	,Props:null
	
	//Flag to activate "flash only" population of the s object
	//if you set this to true, the s object will be populated with
	//all the data collected as usual, BUT it won't execute the s.t();
	//that does the actual tracking.
	//This allows the Flash application to read all the properties of the s
	//object to do the tracking by itself.
	,FlashPage:false
	
	//set to false to disable all the tracking functionalities of SCW
	,Active:true

	//Array of events
	,Events:null

	//Array of js properties that can be set via SCW.AddContent();
	,AllowedJSContent:null

	,Initialize:function(properties) {
	
		SCW.Events = new Array();
		SCW.EVars = {};
		SCW.Props = {};
		
		//these two are optional, you may or may not use them
		//according to the project you are working on
		SCW.ContentProperties = {};		//the CustomSCW will know how to handle them
		SCW.AllowedJSContent = new Array();		//this list the content properties that can be set via js
	}
	
	,Execute:function()
	{
		//get out if not active ;)
		if (!SCW.Active) return;
		
		CustomSCW.Execute();
		if (!SCW.FlashPage) {
			//THIS CODE WAS TAKEN FROM OMNITURE ITSELF
			//					DO NOT CHANGE IT!
			//****************************************
			var s_code=s.t();
			if(s_code)
				document.write(s_code);
			//****************************************
		}
	}

	//The AddContent function works in conjunction with the PageContent and ValidProperties field.
	//The usage of this function is optional.
	,AddContent:function(contentName,contentValue,ignoreCheck)
	{
		if ((ignoreCheck) || (SCW.AllowedJSContent.indexOf(contentName) > -1))
			SCW.ContentProperties[contentName] = contentValue;
	}
	
	,AddEvent:function(name)
	{
		//name: the FULL NAME of the event (eg: "event8", "products", etc.)
		if (SCW.Events.indexOf(name) < 0)
			SCW.Events.push(name);
	}
	
	,GetEventString:function()
	{
		var retVal = "";
		for (var index = 0, len = SCW.Events.length; index < len; ++index) {
			retVal += SCW.Events[index];
			retVal += ",";
		}
		return retVal.substring(0,retVal.length-1);
	}
	
	,AddEVar:function(n,val)
	{
		//n  : the evar NUMBER (eg: "8", "34", etc.)
		//val: the value of the evar (any string)
		SCW.EVars[n] = val;
	}
	
	,AddProp:function(n,val)
	{
		//n  : the prop NUMBER  (eg: "8", "34", etc.)
		//val: the value of the property (any string)
		
		SCW.Props[n] = val;
	}
	
	,TL:function(linkObject,kind,friendlyName,options)
	{
		/*
		 * SAMPLE USAGE:
		 * <a href="someurl.html" 
		 *    onClick="SCW.TL(this,'o','User Did Something',{linkTrackVars:'events',linkTrackEvents:'event7',events='event7'});">
		 *	Click Here
		 * </a>
		 */
		 
 		//get out if not active ;)
		if (!SCW.Active) return;

		if (!options) options = {};
		var stl=s_gi(s_account);
		for (key in options) { stl[key] = options[key]; }
		//debugger;
		stl.tl(linkObject,kind,friendlyName);
	}
	
}

/* UefaCom Specific */
var CustomSCW = {
	
	subsectionCount:4
	
	,fillUserDetails:function() {
		var u = new User();
		u.fillOmnitureProperties();
	}
	
	,chainProps:function(ht,count,separator)
	{
	
		if (!separator)
			separator = ":";
			
		var retVal = ht["sec"] + separator;
		
		for (var ix = 1; ix <= count; ix++)
		{
			if (ht["subsec" + ix])
			{
				retVal += ht["subsec" + ix];
				retVal += separator;
			}
		}
		return retVal.substring(0,retVal.length-1);
	}
	
	,fillCommonPageProperties:function(ht)
	{
		s.channel = ht["sec"];
		
		//Add PageType for ErrorPage
		s.pageType = ht["pagetype"];
	
		for (var ix = 1; ix <= CustomSCW.subsectionCount; ix++)
		{
			if (ht["subsec" + ix]) {
				var val = CustomSCW.chainProps(ht, ix);
				val = this.onPropSave(ix, val);
				s["prop" + ix] = val;
			} else {
				break;
			}
		}
	
		s.prop5 = ht["type"];
		
		s.hier1 = CustomSCW.chainProps(ht, CustomSCW.subsectionCount, ",");
		s.hier1 = ANSICharConverter( s.hier1 );
		
		//pageName
		s.pageName = CustomSCW.chainProps(ht, CustomSCW.subsectionCount);
		if (ht["type"])
		{
			s.pageName += ":";
			s.pageName += ht["type"];
		}
		s.pageName = ANSICharConverter( s.pageName );
		
		s.prop11 = ht["lang"];
	}
	
	,Execute:function()
	{
		CustomSCW.fillUserDetails();
		CustomSCW.fillCommonPageProperties(SCW.ContentProperties);
		
		if (SCW.ContentProperties["title"])
		{
			s.prop8 = SCW.ContentProperties["title"];
			s.pageName += ":";
			s.pageName += SCW.ContentProperties["title"];
		}
		if (SCW.ContentProperties["id"])
			s.prop7 = SCW.ContentProperties["id"];
		if (SCW.ContentProperties["author"])
			s.prop9 = SCW.ContentProperties["author"];
		if (SCW.ContentProperties["comp"])
			s.prop13 = SCW.ContentProperties["comp"];
		if (SCW.ContentProperties["round"])
			s.prop17 = SCW.ContentProperties["round"];
		if (SCW.ContentProperties["match"])
			s.prop16 = SCW.ContentProperties["match"];
		if (SCW.ContentProperties["club"])
			s.prop19 = SCW.ContentProperties["club"];
		if (SCW.ContentProperties["season"])
			s.prop14 = SCW.ContentProperties["season"];
		if (SCW.ContentProperties["group"])
			s.prop18 = SCW.ContentProperties["group"];
		if (SCW.ContentProperties["player"])
			s.prop20 = SCW.ContentProperties["player"];
				
		//the event string
		var sEvents = SCW.GetEventString();
		if (sEvents.length > 0) {
			if (s.events) 
				s.events += ","; 
			else 
				s.events = "";
			s.events += sEvents;
		}

		//set all evars and props so far
		//note that with our settings, all EVar and Props set before can be overridden by these ones
		for (key in SCW.EVars) { s["eVar" + key] = SCW.EVars[key]; }
		for (key in SCW.Props) { s["prop" + key] = SCW.Props[key]; }
	}
	
	, onPropSave: function(n, val) {
		if (n == 2) val = ANSICharConverter( val );
		return val;
	}
}

function ANSICharConverter( s ) {
	var charList = new Array(206,238,234,202,158,138,192,193,196,197,229,224,225,227,228,198,230,201,203,200,232,233,235,204,205,207,236,237,239,338,211,214,216,243,246,248,244,220,218,252,250,268,269,199,231,262,263,209,241,353,352,223,221,253,381,382, 351);
	var mappingList = new Array("I","i","e","E","z","S","A","A","A","A","a","a","a","a","a","AE","ae","E","E","E","e","e","e","I","I","I","i","i","i","OE","O","O","O","o","o","o","o","U","U","u","u","C","c","C","c","c","c","N","n","s","S","ss","Y","y","Z","z", "s");
	
	s = '' + s;
	var stringBuilder = '';
	//for (var i=0; i<charList.length; i++) {
//		var sChar = String.fromCharCode( charList[i] );
//		stringBuilder = stringBuilder.replace( sChar, mappingList[i] );
	//}
	
	for (var n = 0; n < s.length; n++) {
	    var c_old = s.charCodeAt(n);
	    var pos = charList.indexOf(c_old);
	    var c_new = String.fromCharCode( c_old );
	    if (pos != -1) c_new = mappingList[ pos ];
	    stringBuilder += c_new;
	}
	return stringBuilder;
}