/**
* This file is loaded after the initial external data.
*/
insertInitialScriptResources();//cannot be moved to action, as the insert is then not yet visible for action-script for modification

/**
* Inserting the initial external script-tags.
*/
function insertInitialScriptResources(){
	/*Don't load external data when in CMS or under https*/
	if(window.location.href.indexOf("previewId")!=-1
		||window.location.href.indexOf("-cms.eumetsat.int")!=-1
		||window.location.href.indexOf("https")!=-1
	) return;
	for(var i=0; i< metSatIdOrder.length; i++)
	{
			var sat = metSatIdOrder[i];
			var url = indicatorMETA[sat]['dataURL'];
	    document.writeln('<div id="scriptmet'+sat+'" ><script type="text/javascript" src="'+url+'"></script></div>');
	}
}

/**
* Used to override the SMART data coming from OIS.
*
* Use this
*/
function manualOverrides(){

	for(var i=0; i< metSatIdOrder.length; i++)
	{
			var sat = metSatIdOrder[i];
			var overrideStatus 	 = indicatorMETA[sat]['overrideStatus'];
			var overrideDeadline = indicatorMETA[sat]['overrideDeadline'];
			if(overrideStatus && overrideDeadline.getTime() > (new Date()).getTime())
			{
		    setSatColorManually(sat, overrideStatus);
		  }
	}
}

/**
* Method to override the SMART data coming from OIS.
*
* Overwrites previously lloaded external javascript meta-data currentMETStatus[]
*
*@param sat satellite number (1,2,3,4,....)
*@param status DEFINED_LEVEL_GOOD, DEFINED_LEVEL_PROBLEMS, DEFINED_LEVEL_FAIL, DEFINED_LEVEL_NA
*/
function setSatColorManually(sat, status)
{
  var d="";
  for(var i=1;i<=metCycles[sat];i++)
  {
		currentMETStatus["met"+sat][i] = new Array();
		currentMETStatus["met"+sat][i]['debit'] = "100";//placeholder, value don't matter
		currentMETStatus["met"+sat][i]['is'] = "100";
		if(status==DEFINED_LEVEL_GOOD)
			currentMETStatus["met"+sat][i]['is'] = "100";
		else if(status==DEFINED_LEVEL_FAIL)
			currentMETStatus["met"+sat][i]['is'] = "0";
		else if(status==DEFINED_LEVEL_NA)
			currentMETStatus["met"+sat][i]['is'] = "X";

		else if(status==DEFINED_LEVEL_PROBLEMS) {
			if(i==1)
				currentMETStatus["met"+sat][i]['is'] = "0";
			else //if(i > 1 && i <= metCycles[sat])
				currentMETStatus["met"+sat][i]['is'] = "100";
		}
		d+=(sat+". ["+i+"]: "+currentMETStatus["met"+sat][i]['is']+"<br>n");
	}
}

