/* funds component, write logic of funds module in this class */
var funds = new Component("positionDetail/funds");
app.registerComponent(funds);
funds.on( "load", function(){
	var self = this;
	url = "asset/position/" + app.selectBpKey + "?asOfDate=" + app.selectDateValue + "&assetClass1=Funds";
	return funds.render(
			"template/positionDetail_funds.html", 
    		"mainContent", 
    		url).done(function(template, data) {
				self.buttonEvent();

				var count = 0;
				$.each(data.data.result.assetPosition, function(portfolioNo, value){
					//set the netAssetValue
					getNetAssetValue(app.selectBpKey, portfolioNo, count);
					count++;
				});
				
				self.switchNotesLang();
				//set the height of tableScrollDiv adjust the window's height
				setPositionDetailPageScrollHeight();
				
				trackAction("FundsPosition - View");
    		}); 
	
});

funds.buttonEvent = function() {
	var self = this;
	$("#fundsSelectId").val(app.selectDateValue);
	$("#fundsSelectId").die();
	$("#fundsSelectId").live("change",function(){
//		app.selectDateValue = $("option:selected", this).html();
//		funds.trigger("load");
		app.trigger("changeAsOfDate", self.id, $("option:selected", this).html());
		trackAction("FundsPosition - ChangeDate");
	});
};

funds.switchNotesLang = function(){
	//set Notes
	var notes = lang.messages.notes_funds;
	$("#notes").html(notes.replaceAll("\n", "<br>"));
};

