/* bonds component, write logic of bonds module in this class */
var bonds = new Component("positionDetail/bonds");
app.registerComponent(bonds);
bonds.on("load", function(){
	var self = this;
	url = "asset/position/" + app.selectBpKey + "?asOfDate=" + app.selectDateValue + "&assetClass1=Bonds";
	return bonds.render(
			"template/positionDetail_bonds.html", 
    		"mainContent", 
    		url).done( function(template, data) {
				self.buttonEvent();
				//set the height of tableScrollDiv adjust the window's height
				setPositionDetailPageScrollHeight();
				
				self.switchNotesLang();
				
				var count = 0;
				$.each(data.data.result.assetPosition, function(portfolioNo, value){
					//set the netAssetValue
					getNetAssetValue(app.selectBpKey, portfolioNo, count);
					count++;
				});
				trackAction("BondsPosition - View");
    		}); 
});

bonds.buttonEvent = function() {
	$("#bondsSelectId").val(app.selectDateValue);
	$("#bondsSelectId").die();
	$("#bondsSelectId").live("change",function(){
		 app.trigger("changeAsOfDate", "positionDetail/bonds", $("option:selected", this).html());
//		app.selectDateValue = $("option:selected", this).html();
//		bonds.trigger("load");
		 trackAction("BondsPosition - ChangeDate");
	});
};

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

