/* moneyAccount component, write logic of moneyAccount module in this class */
var others = new Component("positionDetail/others");
app.registerComponent(others);
others.on( "load", function(){
	var self = this;
	url = "asset/position/" + app.selectBpKey + "?asOfDate=" + app.selectDateValue + "&assetClass1=Others";
	return others.render(
			"template/positionDetail_others.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 = function(){
					//set notes
					var notes = "";
					var noteSpan="<span class='noteSpan'>&nbsp</span>"
					if(data.data.result.hasSpecial === true) {
						notes += lang.messages.notes_others_special + "<br>";
					} else {
						notes += lang.messages.notes_others_notes + "<br>";
					}
					if(data.data.result.portfolio.length>1 || data.data.result.hasSpecial===false){
						for(var i=1;i<=3;i++){
							if(data.data.result.hasIPO == true && data.data.result.noOfIPO===i) {
								notes += lang.messages.notes_others_ipo + "<br>";
								notes = notes.replaceAll("{noOfIPO}", "<span class='noteSpan'>"+data.data.result.noOfIPO+".</span>");
								notes = notes.replaceAll("{noteSpan}", noteSpan);
								
							}
							if(data.data.result.hasSP == true && data.data.result.noOfSP===i) {
								notes += lang.messages.notes_others_sp + "<br>";
								notes = notes.replaceAll("{noOfSP}", "<span class='noteSpan'>"+data.data.result.noOfSP+".</span>");
								notes = notes.replaceAll("{noteSpan}", noteSpan);
							}
							if(data.data.result.hasSBLC == true && data.data.result.noOfSBLC===i) {
								notes += lang.messages.notes_others_SBLC + "<br>";
								notes = notes.replaceAll("{noOfSBLC}", "<span class='noteSpan'>"+data.data.result.noOfSBLC+".</span>");
								notes = notes.replaceAll("{noteSpan}", noteSpan);
							}
						}
					}
					notes = notes.replaceAll("\n", "<br>");
					$("#notes").html(notes);
				};
				self.switchNotesLang();
				
				//set the height of tableScrollDiv adjust the window's height
				setPositionDetailPageScrollHeight();
				
				trackAction("OthersPosition - View");
    		}); 
	
});

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