/**

 * handles the onclick popup when CarFax icon is clicked

 * @param sandbox

 */

Cobalt.Website.Common.OnStarModule = function(sandbox)

{

	

	var getNewVehicleUrl = function()

	{

		return "http://www.onstar.com/web/portal/home";

	};

	

	var getUsedVehicleUrl = function()

	{

		return "http://www.onstar.com/web/portal/remarketing";

	};



	var getUsedCadillacUrl = function()

	{

		return "http://www.onstar.com/web/portal/remarketing";

	};



	var getNewText = function()

	{

		return "NEW";

	};



	var getUsedText = function()

	{

		return "PREOWNED";

	};



	var getCertifiedText = function()

	{

		return "CERTIFIED";

	};



	var getMakeText = function()

	{

		return "cadillac";

	};

	

	var getPageLabel = function()

	{

		return "GM_onstar_linkout&cs:lo=GM_onstar_linkout";

	};

	

	var getEventName = function()

	{

		return "com.cobaltgroup.ws.action.click.onStar";

	};

	

	var getPixelData = function()

	{

		var eventName = getEventName();

		var pageLabel = getPageLabel();

		return {

			eventName: eventName,

			pageLabel: pageLabel

		};

	};



	return {

	

		linkoutText: null,

		

		component: null,

		

		init: function(data)

		{

			if(!data) data = {};

			this.setLinkoutText(data);

		},

		

		handleClickEvent: function(e)

		{

			this.setComponent(e);

			this.setLinkoutUrl();

			this.linkOut();

		},

		

		setLinkoutText: function(data)

		{

			this.linkoutText = {

				newVehicleUrl: (data.newVehicleUrl) ? data.newVehicleUrl : getNewVehicleUrl(),

				usedVehicleUrl: (data.usedVehicleUrl) ? data.usedVehicleUrl : getUsedVehicleUrl(),

				usedCadillacUrl: (data.usedCadillacUrl) ? data.usedCadillacUrl : getUsedCadillacUrl(),

				newText: (data.newText) ? data.newText : getNewText(),

				usedText: (data.usedText) ? data.usedText : getUsedText(),

				certifiedText: (data.certifiedText) ? data.certifiedText : getCertifiedText(),

				makeText: (data.makeText) ? data.makeText : getMakeText()

			}

		},	

		

		setComponent: function(data)

		{

			this.component = data;

		},

		

		getLinkoutText: function()

		{

			return this.linkoutText;

		},

		

		getComponent: function()

		{

			return this.component;

		},



		getComponentData: function()

		{

			var component = this.getComponent();

			var componentId = sandbox.dom(component).attr("id");

			componentId = componentId.split(":");

			return {

				make: componentId[0], 

				dealerCode: componentId[1], 

				category: componentId[2]

			}

		},

		

		setLinkoutUrl: function()

		{

			var data = this.getComponentData();

			var linkoutText = this.getLinkoutText();

			var url;

			

			switch(data.category)			

			{

				case linkoutText.newText:				

					url = linkoutText.newVehicleUrl + "?make=" + data.make + "&model=homepage&deepLink=overview&custom=lmg&bac=" + data.dealerCode;					

					break;



				case linkoutText.certifiedText:					

					if(data.make === linkoutText.makeText) url = linkoutText.usedCadillacUrl + "?cmp=DLR_PREOWNED_CAD&bac=" + data.dealerCode; 			

					else url = linkoutText.usedVehicleUrl + "?bac=" + data.dealerCode;					

					break;

					

				case linkoutText.usedText:

					if(data.make === linkoutText.makeText) url = linkoutText.usedVehicleUrl + "?cmp=DLR_PREOWNED_CAD&bac=" + data.dealerCode;					

					else url = linkoutText.usedVehicleUrl + "?bac=" + data.dealerCode;			

					break;

					

				default:

					throw new Error("Please mention a Category name");

					

			}



			this.linkoutUrl = url;



		},

		

		getLinkoutUrl: function()

		{

			return this.linkoutUrl;

		},		

		

		linkOut: function()

		{

			var url = this.getLinkoutUrl();

			window.open(url,"CbltOnStarWindow","scrollbars=yes,width=897,height=595");

			return false;

		},

		

		firePixelTag: function()

		{

			var pixelData = getPixelData();

			sandbox.firePixelTag(pixelData);

		}

	};

	

};
