// Press Release object
function Press(objName, lang) {
	this.obj = objName;
	this.aNodes = [];
	this.aGroups = [];
	this.lang = lang;
}

function PressNode(name, y, m, d, hyperlink, title) {
	this.name = name;
	this.y = y;
	this.m = m;
	this.d = d;
	this.hyperlink = hyperlink;
	this.title = title;
}

// add new press release
Press.prototype.add = function(y, m, d, hyperlink, title) {
	this.aNodes[this.aNodes.length] = new PressNode(this.obj + '_' + this.aNodes.length, y, m, d, hyperlink, title);
	var found = false;
	for (var i = 0; i < this.aGroups.length; i++) {
		if (this.aGroups[i] == y) {
			found = true;
			break;
		}
	}
	if (!found) this.aGroups[this.aGroups.length] = y;
};

Press.prototype.compareNumbers = function(a, b) {
	return b - a;
}

Press.prototype.displayGroups = function(name, selectedOption) {
	if (!name) return;
	if (this.aGroups.length <= 0) return;
	var r = '';
	if (!selectedOption) selectedOption = this.aGroups[0];
	for (var i = 0; i < this.aGroups.length; i++) {
		if (r != '') r += ' | ';
		if (selectedOption == this.aGroups[i]) {
			r += '<span style="color:#8b2942;font-size:24px;font-weight:bold;">' + this.aGroups[i] + '</span>';
		} else {
			r += '<a href="?' + name + '=' + this.aGroups[i] + '">' + this.aGroups[i] + '</a>';
		}
	}
	document.writeln(r);
}

Press.prototype.displaySelectedGroup = function(selectGroup) {
	if (!selectGroup) selectGroup = this.setYear();
	document.write(selectGroup);
}

Press.prototype.setYear = function() {
	return (this.aGroups.length > 0 ? this.aGroups[0]: '');
}
Press.prototype.displayMonth = function(m) {
	if (m < 1 || m > 12) return '';
	var a = null;
	if (this.lang == 'chi') {
		// a = new Array('一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月');
		return m + '月';
	} else {
		a = new Array('Jan ', 'Feb ', 'Mar ', 'Apr ', 'May ', 'Jun ', 'Jul ', 'Aug ', 'Sep ', 'Oct ', 'Nov ', 'Dec ');
		return a[m - 1];
	}
	return a[m - 1];
}

Press.prototype.displayDay = function(d) {
	if (d < 1 || d > 31) return ' ';
	var a = null;
	if (this.lang == 'chi') {
		// a = new Array('一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二', '十三', '十四', '十五', '十六', '十七', '十八', '十九', '二十', '廿一', '廿二', '廿三', '廿四', '廿五', '廿六', '廿七', '廿八', '廿九', '三十', '卅一');
		// return a[d - 1] + '日';
		return d + '日';
	} else {
		var s = '';
		if (d < 10) s = '0';
		return s + d;
	}
}

// Outputs the press to the page
Press.prototype.displayTitles = function(selectGroup) {
	if (!selectGroup) selectGroup = this.setYear();
	var str = '';
	var e;
	var w1 = (this.lang == 'chi' ? '13%': '10%');
	var w2 = (this.lang == 'chi' ? '84%': '87%');
	for (var iCtr = 0; iCtr < this.aNodes.length; iCtr++) {
		e = this.aNodes[iCtr];
		if (e.y != selectGroup) continue;
		str += '<tr valign="top">';
		str += '<td nowrap="nowrap" width="' + w1 + '" class="arial12bold" valign="top">';
		str += this.displayMonth(e.m);
		str += this.displayDay(e.d);
		str += '</td>';
		str += '<td width="' + w2 + '" class="arial12" background="../../image/common/dots-full.gif">';
		if (e.hyperlink != '') str += '<a href="doc/' + e.hyperlink + '" target="_blank">';
		str += '<span style="background-color:white;">' + e.title + '</span>';
		if (e.hyperlink != '') str += '</a>';
		str += '</td>';
		str += '<td width="3%" align="right" background="../../image/common/dots-full.gif">';
		if (e.hyperlink != '') str += '<a href="doc/' + e.hyperlink + '" target="_blank"><img src="../../image/common/i_view.gif" border="0"></a>';
		str += '</td>';
		str += '</tr>'
		str += '<tr><td colspan="3">&nbsp;</td></tr>';
	}
	document.writeln(str);
};