//FC_ChartUpdated method is called when user has changed pointer value.
//Here, we track down the chage in year Selector Liner Gauge on top of the page
function FC_ChartUpdated(DOMId){
  //Check if DOMId is that of the chart we want i.e. year selection linear gauge
  if (DOMId.toLowerCase()=="fg_yearselector"){
	 //Get reference to the chart
	var FGRef = getChartFromId(DOMId);
	//Get the selected value/year
	var year = Math.round(FGRef.getData(1)); 
	
	//updating YearSelectionChart to go to the centre of year's value
	FGRef = getChartFromId("FG_YearSelector");
	FGRef.setData(1, year);

	//Reload data if year value has chaged
	if(year!=globalYear){
		//sets the current year to changed selected year
		globalYear=year;
		//submitYear function loads data for the year passed as parameter
		submitYear(year);
	}
  }
} 


//this function live-updates all charts on the page using setDataURL/setDataXML method
function submitYear(year){
	var dataURL, FGRef
	var arr_setObj=new Array();
	//this array stores the DOMiDs of all the charts/gauges used in the appliaction
	//id - refers to the DomIDs and QS refer tot the DataURL's QueryString value
	//that needs to be passed to get data as per querystring values.
	//we pass this QS to "Datagen.{extn}" file that will return the XML as dataURL for the charts.
	arr_setObj.push({id:"FG_AvgRev",QS:"?op=buildXMLAvgRev&year="+year});
	arr_setObj.push({id:"FG_AvgQuan",QS:"?op=buildXMLAvgQuan&year="+year});
	arr_setObj.push({id:"FG_MonthlyRev",QS:"?op=buildXMLMonthlyRev&year="+year});
	arr_setObj.push({id:"FG_MonthlyQuan",QS:"?op=buildXMLMonthlyQuan&year="+year});
	arr_setObj.push({id:"FG_TopCountries",QS:"?op=buildXMLTopCountries&year="+year});
	arr_setObj.push({id:"FG_TopEmployees",QS:"?op=buildXMLTopEmployees&year="+year});
	arr_setObj.push({id:"FC_TopCustomers",QS:"?op=buildXMLTopCustomers&year="+year});
	//the last element is for 5 cylinder charts showing Inventry of top 5 products
	//For these 5 charts we use a comman name to be followed by the rank number of the product(1-5)
	//we also pass rank of the product as QS value.
	arr_setObj.push({id:"FG_PI",QS:"?op=buildXMLEachInventories&year="+year+"&rank="});
	
	// loop through the above array to get each DOMiD & QS
	for(var i in arr_setObj){
		if(arr_setObj[i].id!="FG_PI"){
			//Get reference to the chart having the domID
			FGRef = getChartFromId(arr_setObj[i].id);
			//construct proepr DataURL
			dataURL = escape("DataGen."+extn+arr_setObj[i].QS);
			//setData URL for each chart
			FGRef.setDataURL(dataURL);
		}
		else{
			//this loop is to pass dataURL for 5 best products's inventory cylinder charts
			for(var j=1;j<=5;j++){
				//j refers to the rank of the charts
				// we add j to the common id to get the real DomID of each cylinder chart
				//Get reference to the chart having the domID
				FGRef = getChartFromId(arr_setObj[i].id+j);
				//We construct dataURL to each chart
    		    dataURL = escape("DataGen."+extn+arr_setObj[i].QS+j);
				//set dataURL of each cylinder chart
 				FGRef.setDataURL(dataURL);
			}
		}
	}
	
}

