/**
 * common javascript for reddress microsite
 */

//called from Flash for any event that somebody wants tracked...
//for DKO WebTrends and SearchRev "search pixels" and SMG Floodlight tags and...
function trackEvent(eventid)
{
	try
	{
		if (eventid)
		{
			//call internal (for DKO) WebTrends tracking
			dcsMultiTrack("DCS.dcssip", DCS.dcssip, "DCS.dcsuri", window.location.pathname+eventid, "WT.ti", eventid);
		}
	}
	catch(err0) 
	{
		try
		{
			if ( console )
			{
				console.error("EVENT:=" + eventid + "FAILED!!! - " + err0);
			}
		}
		catch(err0a) {}
	}
	
	try
	{
		if ( console )
		{
			console.log("EVENT:=" + eventid);
		}
	}
	catch(err1) {}
	
	
}


function getFile(url) 
{
	if (window.XMLHttpRequest) {
		AJAX=new XMLHttpRequest();
	} else {
		AJAX=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (AJAX) {
		AJAX.open("GET", url, false);
		AJAX.send(null);	
		return AJAX.responseText;
	} else {
		return false;  
	}
}


function flashLink(pageCode)
{
	if (pageCode)
	{
		var flashLinkPage = "#";
		var bNewWindow = false;
		var eventCode = "/event/flash";
		switch(pageCode)
		{
			case 'SS':  //================================================================= SS  = Style Series
					flashLinkPage = '/styleseries/?ref=rd';
					eventCode += '/callout/TO/styleseries';
					break;
			case 'SL':  //================================================================= SL  = Show Your Love
					flashLinkPage = '/reddress/get-involved/show-your-love.jsp';
					eventCode += '/can/TO/showlove';
					break;
			case 'SW':  //================================================================= SW  = Spread the Word
					flashLinkPage = '/reddress/get-involved/spread-the-word.jsp';
					eventCode += '/can/TO/spreadword';
					break;
			case 'MCR': //================================================================= MCR = My Coke Rewards
					bNewWindow = true;
					flashLinkPage = DKO.mcrdkolbe;
					eventCode += '/heart/TO/supportCampaign';
					break;
			case 'CS':  //================================================================= CS  = Charmed Sweeps
					flashLinkPage = '/reddress/sweepstakes/';
					eventCode += '/can/TO/charmsweeps';
					break;
		}
		
		trackEvent(eventCode);
		
		if (bNewWindow) {
			window.open(flashLinkPage);
		} else {	
			location.href = flashLinkPage;
		}
	}
		
}

$(document).ready(function () 
{

	//BEGIN - initialize click tracking (this JS was originally in footer include)
	$('#homeDown a').click( function(evt) {
		trackEvent('/event/html/callout/TO/' + $(this).attr('id'));
	});
	$('#sitefooter a').click( function(evt) {
		trackEvent('/event/html/footer/TO/' + $(this).attr('id'));
	});
	$('#navigation a').click( function(evt) {
		trackEvent('/event/html/navigation/TO/' + $(this).attr('id'));
	});
	/* now handled by more generic code in DKO.common.js
	$('#content a').click( function(evt) {
		var evtType = ($(this).hasClass('reimg') ? 'button' : ($(this).hasClass('callout') ? 'callout' : 'link') );
		var targId = $(this).attr('id');
		if ( targId )
		{
			trackEvent('/event/html/' + evtType + '/TO/' + targId);
		}
	}); */
	//E=N=D - initialize click tracking

}); 
