var symbolTbl = new Array;

function Symbol(clas, symbol, mrgn, name, engname) {
	this.nx2           = arguments.length == 5;
	this.clas          = clas;
	this.symbol        = symbol;
	this.mrgn          = this.nx2 ? mrgn    : 'N'; // Y, N
	this.name          = this.nx2 ? name    : mrgn;
	this.engname       = this.nx2 ? engname : name;
	this.getLangName   = function() { return menuLang=='vn' ? this.name : (this.engname==null || this.engname=='' || this.engname==' ' || this.symbol.trim() == this.engname.trim() ? this.name : this.engname); }
	this.getMarketType = function() { return this.clas == null ? '0' : this.clas.charAt(0); }
	this.getStockType  = function() { return this.clas == null ? '0' : this.clas.charAt(1); }
	this.isHH          = function() { var m = this.getMarketType(); return m == '0' || m == '1'; }
	this.isUpcom       = function() { return this.getMarketType() == '3'; }
	this.isMrgn        = function() { return this.mrgn == 'Y'; }
	this.getMarketDsp  = function() { switch(this.getMarketType()) { case '0' : return '<font color="red">HOSE</font>'; case '1' : return '<font color="blue">HNX</font>'; case '3' : return '<font color="green">UPCOM</font>'; default : return ' '; } }
}

function getSymbol(symbol) {
	for(var i=0; i<symbolTbl.length; i++)
		if(symbolTbl[i].symbol == symbol) return symbolTbl[i];
	return null;
}

function getSymbolLangName(symbol) {
	var sym = getSymbol(symbol);
	return sym ? sym.getLangName() : '';
}

function getSymbolName(symbol) {
	var sym = getSymbol(symbol);
	return sym ? sym.name : '';
}

function getSymbolGroups() {
	var res = [];
	for(var i=0; i< symbolTbl.length; i++) {
		var ss = symbolTbl[i];
		if (ss.clas == '80') res.push(ss);
	}
	return res;
}

function getMarketType(symbol, type) {
	var i = 0;
	var clas = "01";

	for (i = 0; i < symbolTbl.length; i++) {
		if (symbolTbl[i].symbol == symbol) {
			clas = symbolTbl[i].clas;
			break;
		}
	}

	if (type == null || type == "") {
		return clas.substring(0,1);
	}
	else {
		return clas;
	}
}

function getMarketTypeNameCode(type) {
	try {
		switch( type.charAt(0) ) {
			case '0' : return 'HOSE';
			case '1' : return 'HNX';
			case '3' : return 'UPCoM';
			default  : return '';
		}
	} catch(e) {
		return '';
	}
}
