
//This function is called by the flash movie(s) to report an action 
function reportAction(code, idVal, url)
{
	var u = constructFlashTrackingUrl(code, idVal);	

	// make sure tracking pixel request completes & is logged
	makeSyncRequest(u);
	
	updateDebugger(u);

	if(url != null && url != "null" && (url != "")){	   
		window.parent.location = url;		
	
	}
	
}
//This function is called by the flash movie(s) to report an action 
//This function was changed to handle the loading of images due to Digitas throwing the java script error.  
//This function allows java script to fake overloading.
 /*
function reportAction(code, idVal, url)
{
		
		var len = reportAction.length;
		switch(len)
		{
			case 1:
			//TODO: need to handle the error
			break;
		
			case 2:
			//TODO: need to handle the error
				break;
			
			case 3:
				if(reportAction[0] != null && reportAction[1] != null)
					var u = constructFlashTrackingUrl(reportAction[0], reportAction[1]);	
				if(u!=null)
				{
					makeSyncRequest(u);
					updateDebugger(u);
				}
				
				if(reportAction[3] != null && reportAction[3] != "null" && (reportAction[3] != ""))
				{	   
					document.location = reportAction[3];				
				}
				break;
			default:
			//TODO:need to handle the error
				break;
		}
	
}

	 */
//Constructs the URL for tracking
function constructFlashTrackingUrl(code, idVal){
	
	var d = new Date();
	var t = d.getTime();

	var u = "{0}/tracking/trackFlash.gif?ts={1}&code={2}&id={3}";
	u = u.replace("{0}",getUrlBase());
	u = u.replace("{1}",t);
	u = u.replace("{2}",code);
	u = u.replace("{3}",idVal);

   //if there is 
   if(typeof AddAdditionalParameters != "undefined")
   {
      u = AddAdditionalParameters(u);
   }	
	return u;
}

///Example function to add additional parameters.
//would be injected into the page.
//function AddAdditionalParameters(input)
//{
//	var output = input;
//	output += "&test=23";
//	return output;
//}

function makeSyncRequest(url){

	var http_request = getHttpRequest();

	if (!http_request) {
		return false;
	}

	http_request.open('GET', url, false);

	http_request.send(null);
		
	if(http_request.status == 200) {
		return true;
	} else {
		return false;
	}

}

function getHttpRequest(){
	var http_request;
	
	if (window.XMLHttpRequest) // Mozilla, Safari,...
	{ 
		http_request = new XMLHttpRequest();
	
		if (http_request.overrideMimeType) 
		{
			http_request.overrideMimeType('text/xml');
		}
	} 
	else if (window.ActiveXObject)  // IE
	{

		try { http_request = new ActiveXObject("Msxml2.XMLHTTP"); } 

		catch (e) 
		{

			try { http_request = new ActiveXObject("Microsoft.XMLHTTP"); } 
		
			catch (e) {}
			
		}
	
	}
	
	return http_request;
}

function getUrlBase()
{
	var t; 
	
	t = location.protocol;
	t = t + "\/\/";
	var host = location.host;
	if (host == "localhost")
	{
	   host = host + "/mr";
	}
	t = t + host;
		
	return t;
}

function updateDebugger(u){
	if(document.forms[0].feedback)
	{
		document.forms[0].feedback.value = u + "\n" + document.forms[0].feedback.value;
	}
}

