var fBrw=(navigator.userAgent.indexOf('MSIE')!= -1 && navigator.userAgent.indexOf('Windows')!= -1);

function MenuItem(id, title, link, parent, root) {
	this.id = id;
	this.title = title;
	this.link = link;
	this.parent = parent;
	this.root = root;
}


function displayMenu(cateId) {
	function getLevel0(title, link, style, selected) {
		var html = '';
		html += '<tr>';
		html += '<td width="100%" height="20" class=' + (selected ? 'MenuLevel0Selected' : 'MenuLevel0' ) + '>&nbsp;';
		html += '<img border="0" src="/images/bullet01.gif">&nbsp;';
		html += '<a href="';
		html += link;
		html += '">';
		html += title;
		html += '</a></td></tr>';
		return html;
	}
	function getLevel1(title, link, style, selected) {
		var html = '';
		html += '<tr>';
		html += '<td width="100%" height="20" class=' + (selected ? 'MenuLevel1Selected' : 'MenuLevel1' ) + '>&nbsp;&nbsp;&nbsp;';
		html += '<b><font face="Arial" color="#c0c0c0">. </font></b>';
		html += '<a href="';
		html += link;
		html += '">';
		html += title;
		html += '</a></td></tr>';
		return html;
	}
	
	if (typeof(cateId) == 'undefined' || cateId == null)
		if (typeof(CurrentCateID) != 'undefined' && CurrentCateID != null)
			cateId = CurrentCateID;
		else
			cateId = 0;

	var html = '';
	
	html += '<table border="0" cellpadding="0" cellspacing="0" width="100%">';
	html += '<tr>';
	html += '<td width="100%">';
	html += '<table border="0" cellpadding="0" cellspacing="1" width="100%">';
	html += '<tr>';
	html += '<td width="100%" bgcolor=#F6F5F5>'; 
	html += '<table border="0" cellpadding="0" cellspacing="0" width="100%">';
	
	// find parent of the current cateId
	var parentCateId = 0;
	for (i=0; i<menuItems.length; i++)
		if (menuItems[i].id == cateId) {
			parentCateId = menuItems[i].parent;
			break;
		}

	for (i=0; i<menuItems.length; i++) {
		if (menuItems[i].root)
			html += getLevel0(menuItems[i].title, menuItems[i].link, menuItems[i].style, (menuItems[i].id == cateId) || (menuItems[i].id == parentCateId));
		else if (menuItems[i].parent == cateId || parentCateId == menuItems[i].parent)
			html += getLevel1(menuItems[i].title, menuItems[i].link, menuItems[i].style, (menuItems[i].id == cateId) || (menuItems[i].id== parentCateId));
	}
	
	
	html += '</table>';
	html += '</td>';
	html += '</tr>';
	html += '</table>';
	html += '</td>';
	html += '</tr>';
	html += '<tr>';
	html += '<td width="100%" height="5">';
	html += '<img border="0" src="images/space.gif" width="1" height="1"></td>';
	html += '</tr>';
	html += '</table>';
	
	document.write(html);
}


function displayDate(dDate) {
	var today;
	if (dDate)
		today = new Date(dDate);
	else
		today = new Date(); 
//	var dow = new Array('CH&#7910; NH&#7852;T','TH&#7912; HAI','TH&#7912; BA','TH&#7912; T&#431;','TH&#7912; N&#258;M','TH&#7912; S&#193;U','TH&#7912; B&#7842;Y');
	var dow = new Array('Ch&#7911; Nh&#7853;t','Th&#7913; Hai','Th&#7913; Ba','Th&#7913; T&#432;','Th&#7913; N&#259;m','Th&#7913; S&#225;u','Th&#7913; B&#7843;y');
	var months = new Array('01','02','03','04','05','06','07','08','09','10','11','12');
	var year = today.getYear();
	year = (year <= 1888) ? (1900 + year) : year;
	document.write(dow[today.getDay()] + ' ng&#224;y ' + today.getDate() + '/' + months[today.getMonth()] + '/' + year); // + ', ' + leadZero(today.getHours(), 2) + 'h' + leadZero(today.getMinutes(), 2) + ' (GMT+7)'
}


function displayPopup() {	// check for available popups and show 'em up
	var i;
	if (typeof(AdItems) == 'object') {
		var html = null;
		for (i=0; i<AdItems.length; i++) {
			var ad = new AdWrapper(AdItems[i]);
			if (ad.Type == 4 && ad.isVisible() )	{ // ad type = Popup
				var ppW = (ad.WinWidth==0 ? 130 : ad.WinWidth), ppH = (ad.WinHeight==0 ? 120 : ad.WinHeight);
				var oNewWin = window.open('', 'AD_POPUP', 'left='+ (screen.width-ppW)/2 +',top='+ (screen.height-ppH)/2 +',width=' + ppW + ',height=' + ppH + ',' + ad.WinFeatures);
				sPPSrc = '<html><title>Web Ad - Thanh Nien Online</title><body topmargin=0 leftmargin=0><img alt="' + ad.Link + '" onclick="window.open(\'/Bin/AdClick/?' + ad.ID + '\');self.close();" src="' + ad.ImageSource + '" style=cursor:hand></body></html>';
				try {
					oNewWin.document.write(sPPSrc);
				} catch (e) {
					//alert(e);
				}
			}
		}
	}
}

setTimeout('displayPopup()', 1000);		// check for every page hits

function displayCateTitle(cateId) {
	for (i=0; i<menuItems.length; i++)
		if (menuItems[i].id == cateId) {
			document.write(menuItems[i].title);	//.toUpperCase()
			return;
		}
}

var ppimgNW;
function popupImage(src, note, title, css, border) {
  if (border==null) border = 0;
  if (note==null) note = '';
  if (ppimgNW != null) ppimgNW.close();


	winDef = 'status=no,resizable=no,scrollbars=no,toolbar=no,location=no,fullscreen=no,titlebar=yes,height='.concat(1).concat(',').concat('width=').concat(1).concat(',');
	winDef = winDef.concat('top=').concat((screen.height - 1)/2).concat(',');
	winDef = winDef.concat('left=').concat((screen.width - 1)/2);
	ppimgNW = open('', 'POPUPIMAGE', winDef);

  var doc = ppimgNW.document;
  doc.write('<html>');
  doc.write('<head>');

  if (title!=null) doc.write('<title>'+ title +'</title>');
  doc.write('<style> body {'+css+'} #ppImgText{'+ css +'} #ppImg{cursor:hand}</style></head>');
  doc.write('<body leftmargin="0" topmargin="' + border + '" onload="doResize();">');
  doc.write('<div align="center">');
  doc.write('<img src="' + src + '" id="ppImg" onclick="self.close();" title="Close">');
  doc.write('</div>');
  doc.write('<div style="height:1; width:' + border + '; font-size:4pt;">');
  doc.write('</div>');
  doc.write('<div id="ppImgText" align="center">');
  doc.write(note);
  doc.write('</div>');
  doc.write('</body>');
  doc.write('</html>');

  doc.write('<' + 'script>');
  doc.write('function doResize() {');
  doc.write('  var imgW = ppImg.width, imgH = ppImg.height;');  
  doc.write('  window.moveTo((screen.width - imgW)/2, (screen.height - imgH)/2);');     
  doc.write('  window.resizeTo(imgW + 8 +' + border*2 +', imgH + ppImgText.offsetHeight + 26 + '+ border*2 +');');
  doc.write('  setTimeout(\'doResize();\', 1000); ');
  doc.write('}');
  doc.write('doResize(); '); 
  doc.write('</' + 'script>');


}

function getName(aArgs, sValue) {
	for (i=0; i<aArgs.length-1; i+=2) {
		if (sValue == aArgs[i+1])
			return aArgs[i];
	}
	return null;
}