var fBrw=(navigator.userAgent.indexOf('MSIE')!= -1 && navigator.userAgent.indexOf('Windows')!= -1);
var RefBanner = new Array();
var RefAdLogo = new Array();
var RefAdLBox = new Array();
var RefAdStay = 0;
var RefAdIcon = new Array();
var SkpFolder = true;
var CurBanner = 0;

function setCookie(Name, Path, Expires, Value)
{
	var cstr = Name.concat('=').concat(Value);
	
	if (Path=='')
		path='/';

	cstr=cstr.concat(';path=').concat(Path);


	if (Expires=='')
		Expires=(new Date(2020, 11, 14)).toGMTString();

	document.cookie=cstr.concat(';expires=').concat(Expires);
}

function getCookie(Name, Default)
{
	var search = Name.concat('=');

	if (document.cookie.length > 0)
	{
		offset = document.cookie.indexOf(search);
		if (offset != -1)
		{
			offset+= search.length;
			end = document.cookie.indexOf(';', offset);
			if (end == -1) 
				end = document.cookie.length;

			return unescape(document.cookie.substring(offset, end));
		} 
	}
	return Default;
}

function ReplaceChar(iStr)
{
	var	r1=/&/g;
	var	r2=/ /g;
	var	r3=/"/g;

	iStr	=iStr.replace(r1, '%26');
	iStr	=iStr.replace(r2, '%20');
	iStr	=iStr.replace(r3, '%22');

	return iStr;
}

function CharReplace(iStr)
{
	var	r1=/%26/g;
	var	r2=/%20/g;
	var	r3=/%22/g;

	iStr	=iStr.replace(r1, '&');
	iStr	=iStr.replace(r2, ' ');
	iStr	=iStr.replace(r3, '"');

	return iStr;
}

function GetPostVariable(vName, vDef)
{
	var	str=location.href;
	var	pos=str.indexOf('?'.concat(vName).concat('='));

	if (pos==-1)
	{
		pos=str.indexOf('&'.concat(vName).concat('='));
		if (pos==-1) return vDef;
	}
	
	str=str.substring(pos + vName.length + 2);
	pos=str.indexOf('&');

	if (pos==-1)
	{
		pos=str.length;
	}	

	if (pos > 0)
	{
		str=str.substring(0, pos);
	}

	return (typeof(vDef)=='number') ? parseInt(str) : CharReplace(str);
}

function GoNothing()
{
}

function ChangeBanner()
{
	if (RefBanner.length==0)
		return;

	CurBanner++;
	if (CurBanner >= RefBanner.length)
	{
		CurBanner=0;
	}
	TopBanner_Pict.src =RefBanner[CurBanner][0];
	if (RefBanner[CurBanner][1]=='')
	{
		RefBanner[CurBanner][1] = 'JavaScript:GoNothing()';
	}
	TopBanner_Link.href= RefBanner[CurBanner][1];
	setTimeout('ChangeBanner()', 5000);
}

function DisplayBanner()
{
	if (RefBanner.length==0)
		return;

	CurBanner=Math.floor(Math.random()*12321) % RefBanner.length;
	if (RefBanner[CurBanner][1]=='')
	{
		RefBanner[CurBanner][1] = 'JavaScript:GoNothing()';
	}
	document.writeln('<a ID="TopBanner_Link" href="', RefBanner[CurBanner][1], '"><img ID="TopBanner_Pict" src="', RefBanner[CurBanner][0], '" width=468 height=60 border=0></a>');
	if (fBrw)
	{
		setTimeout('ChangeBanner()', 3000);
	}
}

function AddBreakSpace(Pixel)
{
	if (typeof(Pixel)=='undefined')
	{
		Pixel=3;
	}
	document.writeln('<table cellspacing=0 cellpadding=0 border=0 width="100%"><tr><td height=', Pixel, '><img="/Images/White.gif" border=0></td></tr></table>');
}

function DisplayAdIcon()
{
	var	CurAdIcon=Math.floor(Math.random()*12311) % RefAdIcon.length;

	document.writeln('<table border=0 width="100%" cellspacing=2 cellpadding=3>');
	document.writeln('<tr>');

	for (var i=CurAdIcon; i < RefAdIcon.length; i++)
	{
		document.writeln('<td valign=middle align=center><a href="', RefAdIcon[i][1], '"><img src="', RefAdIcon[i][0], '" border=0 align=center></a></td>');
	}

	for (var i=0; i < CurAdIcon; i++)
	{
		document.writeln('<td valign=middle align=center><a href="', RefAdIcon[i][1], '"><img src="', RefAdIcon[i][0], '" border=0 align=center></a></td>');
	}
	
	document.writeln('</tr>');
	document.writeln('</table>');
}

function DisplayCopyright(showType)
{
	if (typeof(showType)=='undefined')
	{
		showType=1;
	}

	document.writeln('<table cellspacing=0 cellpadding=2 border=0>');
	document.writeln('<tr><td width=1 class=Symbol><b>&#169;</b></td><td class=Copyright nowrap><b><font color=#000000>Copyright 1999-2003 CoiThienThai.Com</font></b>, All rights reserved. <a href="mailto:webmaster@CoiThienThai.Com">Contact us</a><td></tr>');
	if (showType)
	{
		document.writeln('<tr><td width=1 class=Symbol><b>&#174;</b></td><td class=Copyright nowrap>Y&#234;u c&#7847;u m&#7885;i t&#7893; ch&#7913;c khi s&#7917; d&#7909;ng th&#244;ng tin c&#7911;a CoiThienThai.Com ph&#7843;i ghi r&#245; ngu&#7891;n tin.</td></tr>');
	}
	document.writeln('</table>');
}

function AddHeader(Name, Header, Buttons)
{
	var Status=getCookie('FLD_'.concat(Name), 0);

	document.writeln('<div ID="IDF_', Name, '">');
	document.writeln('<table width="100%" border=0 cellspacing=0 cellpadding=0 bgcolor="#003366"><tr><td>');

	if (Header!='')
	{
		document.writeln('<table width="100%" border=0 cellspacing=0 cellpadding=0>');
		document.writeln('<tr>');
		document.writeln('<td height=20 width="100%" align=left class=BoxHeader>&nbsp;', Header, '</td>');

		if ((Buttons & 1) && fBrw)
		{
			document.write('<td width=15 align=right>');
			document.write('<a href="JavaScript:ItemMinimize(\x27', Name, '\x27)">');
			document.write('<img src="/Images/', ((Status==1) ? 'max' : 'min'), '.gif" ID="IDI_', Name, '" border=0 alt="Minimize | Maximize">');
			document.write('</a></td>');
		}

		document.writeln('</td></tr></table>');
	}

	document.writeln('<div ID="IDM_', Name, '"', ((Status==1) ? ' style="display:none"' : ''), '>');
	document.writeln('<table align=center width="100%" cellspacing=0 cellpadding=0 border=1>');
	return true;
}

function AddFooter()
{
	document.writeln('</table></div></td></tr></table></div>');
}

function ItemMinimize(Name)
{
	var MItem=document.all('IDM_'.concat(Name));
	var Image=document.all('IDI_'.concat(Name));

	if (MItem.style.display=='')
	{
		MItem.style.display='none';
		Image.src='/Images/max.gif';
		setCookie('IDM_'.concat(Name), '/', '', 1);
	}
	else
	{
		MItem.style.display='';
		Image.src='/Images/min.gif';
		setCookie('IDM_'.concat(Name), '/', '', 0);
	}
}

function ItemClose(Name)
{
	var FItem=document.all('IDF_'.concat(Name));
	FItem.style.display='none';
	setCookie('FLD_'.concat(Name), '/', '', 2);
}

function FolderMinimize(Name)
{
	var MItem=document.all('FDM_'.concat(Name));
	var Image=document.all('FDI_'.concat(Name));

	if (MItem.style.display=='')
	{
		MItem.style.display='none';
		Image.src='/Images/max.gif';
		setCookie('FDM_'.concat(Name), '/', '', 1);
	}
	else
	{
		MItem.style.display='';
		Image.src='/Images/min.gif';
		setCookie('FDM_'.concat(Name), '/', '', 0);
	}
}

function SetParameter(pFile, pName, pVal)
{
	if ((cPost=pFile.indexOf('&'.concat(pName).concat('=')))==-1)
		cPost=pFile.indexOf('?'.concat(pName).concat('='));

	if (cPost >= 0)
	{
		if ((pPost=pFile.indexOf('&', cPost + 1))==-1)
		{
			pFile=pFile.substring(0, cPost + pName.length + 2).concat(pVal);
		}
		else
		{
			pFile=pFile.substring(0, cPost + pName.length + 2).concat(pVal).concat(pFile.substr(pPost));
		}
	}
	else
	{
		if (pFile.indexOf('?')==-1)
		{
			pFile=pFile.concat('?').concat(pName).concat('=').concat(pVal);
		}
		else
		{
			pFile=pFile.concat('&').concat(pName).concat('=').concat(pVal);
		}
	}

	return pFile;
}

function ReverseFolderByDate()
{
	location.replace(CurrentFolder.concat('/default.asp?d=').concat(document.Reverse.fYear.options[document.Reverse.fYear.selectedIndex].value).concat('/').concat(document.Reverse.fMonth.options[document.Reverse.fMonth.selectedIndex].value).concat('/').concat(document.Reverse.fDay.options[document.Reverse.fDay.selectedIndex].value).concat(' 23:59:59'));
}

function ShowNextFolderItem(LastDate)
{
	location.href = CurrentFolder.concat('/default.asp?d=').concat(LastDate);
}

function UnderConst()
{
	alert('Sorry!\nThis Page is under construction!\nPlease try latter!');
}

function openMe(url, inNew, winDef)
{
	if (url == '')
		return;

	if (typeof(inNew)=='undefined')
		inNew = 0;

	if (typeof(winDef)=='undefined')
		winDef = 'scrollbars=yes,status=yes,toolbar=yes,location=yes,menubar=yes,resizable=yes,height=300,width=400,top='.concat((screen.height - 400)/2).concat(',left=0');

	if (inNew)
	{
		open(url, 'Advertising', winDef);
	}
	else
	{
		location.href = url;
	}
}

function openMeExt(url, vStatus, vResizeable, vScrollbars, vToolbar, vLocation, vFullscreen, vTitlebar, vCentered, vHeight, vWidth, vTop, vLeft)
{
	winDef = '';
	winDef = winDef.concat('status=').concat((vStatus) ? 'yes' : 'no').concat(',');
	winDef = winDef.concat('resizable=').concat((vResizeable) ? 'yes' : 'no').concat(',');
	winDef = winDef.concat('scrollbars=').concat((vScrollbars) ? 'yes' : 'no').concat(',');
	winDef = winDef.concat('toolbar=').concat((vToolbar) ? 'yes' : 'no').concat(',');
	winDef = winDef.concat('location=').concat((vLocation) ? 'yes' : 'no').concat(',');
	winDef = winDef.concat('fullscreen=').concat((vFullscreen) ? 'yes' : 'no').concat(',');
	winDef = winDef.concat('titlebar=').concat((vTitlebar) ? 'yes' : 'no').concat(',');
	winDef = winDef.concat('height=').concat(vHeight).concat(',');
	winDef = winDef.concat('width=').concat(vWidth).concat(',');

	if (vCentered)
	{
		winDef = winDef.concat('top=').concat((screen.height - vHeight)/2).concat(',');
		winDef = winDef.concat('left=').concat((screen.width - vWidth)/2);
	}
	else
	{
		winDef = winDef.concat('top=').concat(vTop).concat(',');
		winDef = winDef.concat('left=').concat(vLeft);
	}

	open(url, '_blank', winDef);
}

function openImage(url, vHeight, vWidth)
{
	winDef = 'status=no,resizable=no,scrollbars=no,toolbar=no,location=no,fullscreen=no,titlebar=yes,height='.concat(vHeight).concat(',').concat('width=').concat(vWidth).concat(',');
	winDef = winDef.concat('top=').concat((screen.height - vHeight)/2).concat(',');
	winDef = winDef.concat('left=').concat((screen.width - vWidth)/2);
	newwin = open('', '_blank', winDef);
	newwin.document.writeln('<body topmargin="0" leftmargin="0" marginheight="0" marginwidth="0">');
	newwin.document.writeln('<a href="JavaScript:window.close()"><img src="', url, '" alt="&#272;&#243;ng l&#7841;i" border=0></a>');
	newwin.document.writeln('</body>');
}

function SetFont()
{
	if (fBrw)
	{
		rs=window.showModalDialog('http://members.shaw.ca/coithienthai/SetFont.html', '', 'dialogHeight:215px;dialogWidth:385px;status:no;help:no');
		if (typeof(rs)!='undefined')
		{
			if (rs)
			{
				location.reload(true);
			}
		}
	}
	else
	{
		open('http://members.shaw.ca/coithienthai/SetFont.html', 'SetFont', 'toolbar=no,height=190,width=370,top='.concat((screen.height - 162)/2).concat(',left=').concat((screen.width - 370)/2));
	}
}

function PageSet(vPage)
{
	location.replace(SetParameter(location.href, 'p', vPage));
}

function ShowAdBox()
{
	if (RefAdLBox.length==0)
		return;

	document.writeln('<table width="100%" cellspacing=0 cellpadding=0 border=0 bgcolor=red>');
	document.writeln('<tr>');
	document.writeln('<td width=190>');
	if (RefAdLBox[0][1] != '')
	{
		document.writeln('<a href="javascript:openMe(\'', RefAdLBox[0][1], '\', ', RefAdLBox[0][2], ')"><img src="', RefAdLBox[0][0], '" border=0></a>');
	}
	else
	{
		document.writeln('<img src="', RefAdLBox[0][0], '" border=0>');
	}
	document.writeln('</td>');
	document.writeln('<td width=1 bgcolor="#FFFFFF"><img src="/Images/white.gif" border=0></td>');
	document.writeln('<td><img src="/Images/Advertising.gif" border=0></td>');
	document.writeln('</tr>');
	document.writeln('</table>');
}

function ShowAdLogoNew(sType)
{
	if (typeof(sType)=='undefined')
		sType = 2;

	switch (sType)
	{
	case 1:
		ShowAdLogoLeft();
		break;
	case 2:
		ShowAdLogoRight();
		break;
	}
}

function ShowAdLogoLeft()
{
	if (RefAdLogo.length==0)
	{
		return;
	}

	CurAdLogo=RefAdStay + (Math.floor(Math.random()*12311) % (RefAdLogo.length - RefAdStay));

	document.writeln('<table width=130 cellspacing=0 cellpadding=0 border=0 bgcolor="#c0c0c0">');
	document.writeln('<tr><td align=center>');
	document.writeln('<table width="100%" cellspacing=1 cellpadding=2 border=0>');

	for (j=0, i=CurAdLogo; j < RefAdLogo.length; j++)
	{
		document.writeln('<tr><td height=64 align=center valign=middle align=right bgcolor="#FFFFFF">');
		if (RefAdLogo[i][1] != '')
		{
			document.writeln('<a href="javascript:openMe(\'', RefAdLogo[i][1], '\', ', RefAdLogo[i][2], ')"><img src="', RefAdLogo[i][0], '" border=0 width=124 height=60></a>');
		}
		else
		{
			document.writeln('<img src="', RefAdLogo[i][0], '" border=0 width=130 height=60>');
		}
		document.writeln('</td></tr>');

		if (++i >= RefAdLogo.length)
		{
			i = 0;
		}
	}

	document.writeln('</table>');	
	document.writeln('</td></tr>');
	document.writeln('</table>');
}

function ShowAdLogoRight()
{
	if (RefAdLBox.length > 0)
	{
		document.writeln('<table height=178 cellspacing=0 cellpadding=0 border=0>');
		document.writeln('<tr><td valign=top>');

		if (RefAdLBox[0][1] != '')
		{
			document.writeln('<a href="', RefAdLBox[0][1], '"><img src="', RefAdLBox[0][0], '" border=0></a>');
		}
		else
		{
			document.writeln('<img src="', RefAdLBox[0][0], '" border=0>');
		}

		document.writeln('</td></tr>');
		document.writeln('</table>');
	}

	if (RefAdLogo.length==0)
	{
		return;
	}

	CurAdLogo=RefAdStay + (Math.floor(Math.random()*12311) % (RefAdLogo.length - RefAdStay));

	document.writeln('<table width=145 cellspacing=0 cellpadding=0 border=0 bgcolor="#c0c0c0">');
	document.writeln('<tr><td align=center>');
	document.writeln('<table width="100%" cellspacing=1 cellpadding=4 border=0>');

	for (j=0, i=CurAdLogo; j < RefAdLogo.length; j++)
	{
		document.writeln('<tr><td height=64 align=center valign=middle align=right bgcolor="#FFFFFF">');
		if (RefAdLogo[i][1] != '')
		{
			document.writeln('<a href="', RefAdLogo[i][1], '"><img src="', RefAdLogo[i][0], '" border=0 width=130 height=60></a>');
		}
		else
		{
			document.writeln('<img src="', RefAdLogo[i][0], '" border=0 width=130 height=60>');
		}
		document.writeln('</td></tr>');

		if (++i >= RefAdLogo.length)
		{
			i = 0;
		}
	}

	document.writeln('</table>');	
	document.writeln('</td></tr>');
	document.writeln('</table>');
}

function UnicodeSet(iStr)
{
	for (i=0, oStr=''; i < iStr.length; i++)
	{
		j=iStr.charCodeAt(i);
		
		if (j < 32 || j > 127 || j==34 || j==39)
		{
			oStr=oStr.concat('&#').concat(j).concat(';');
		}
		else
		{
			oStr=oStr.concat(iStr.charAt(i)); 
		}
	}
	
	return oStr;
}

function SetUnicode(iStr)
{
	for (i=0, oStr=''; i < iStr.length; )
	{
		if (iStr.charCodeAt(i)==38)
		{
			if (iStr.charCodeAt(i + 1)==35)
			{
				p=iStr.indexOf(';', i  + 2);
				if (p!=-1)
				{
					if (p - i <= 7)
					{
						if (isFinite(iStr.substr(i + 2, p - i - 2)))
						{
							oStr = oStr.concat(String.fromCharCode(iStr.substr(i + 2, p - i - 2)));
							i = p + 1;
							continue;
						}
					}
				}
			}

		}
	
		oStr=oStr.concat(iStr.charAt(i));
		i++;
	}
	
	return oStr;
}

function SearchMe(s, a)
{
	while (s.length > 0 && s.charAt(0) <= ' ')
	{
		s = s.substr(1);
	}

	while ((i=s.length) > 0 && s.charAt(i - 1) <= ' ')
	{
		s = s.substr(0, i - 1);
	}

	if (s=='')
	{
		document.Search.TSearch.value = s;
		return false;
	}
	
	f = GetPostVariable('f', RelatedFolder);
	s = escape(UnicodeSet(s));
	r = '/Search/?p=1&f='.concat(f).concat('&a=').concat(a).concat('&s=').concat(s);

	if (location.pathname.toLowerCase()=='/search/')
	{
		location.replace(r);
	}
	else
	{
		location.href=r;
	}
	return false;
}

function SearchOnFocus(field)
{
	if(field.value=='Search')
	{
		field.value = '';
	}
}

function SearchOnBlur(field)
{
	if(field.value=='')
	{
		field.value='Search';
	}
}

function ShowSearch()
{
	if ((s=GetPostVariable('s', ''))!='')
	{
		s = unescape(s);
	}

	s=SetUnicode(s);

	document.writeln('<table height=30 cellspacing=0 cellpadding=0 border=0>');
	document.writeln('<form method="POST" name="Search" onSubmit="return SearchMe(document.Search.TSearch.value, 1)">');
	document.writeln('<tr>');
	document.writeln('<td class=SubMenu>&nbsp;&nbsp;</td>');
	document.writeln('<td><input type="text" name="TSearch" size=', ((fBrw) ? 15 : 10), ' value="Search" class=SearchBox onfocus="SearchOnFocus(this)" onblur="SearchOnBlur(this)"></td>');
	document.writeln('<td class=SubMenu>&nbsp;</td>');
	document.writeln('<td><a href="javascript:SearchMe(document.Search.TSearch.value, 1)"><img src="/Images/Go.gif" border=0></a></td>');
	document.writeln('</tr>');
	document.writeln('</form>');
	document.writeln('</table>');

	if (s!='')
	{
		document.Search.TSearch.value = s;
	}
}

function CheckThisVote(field)
{
	form = field.form;
	if (field.checked)
	{
		form.fvotefor.value = field.value;
	}
	else
	{
		form.fvotefor.value = '';
		return;
	}

	for (i=0; i < form.elements.length - 2; i++)
	{
		if(form.elements[i].type=='checkbox')
			if (form.elements[i] != field)
				if (form.elements[i].checked)
					form.elements[i].checked = false;
	}
}

function SubmitVote(sform, saction)
{
	if (saction==0)
	{
		if (sform.fvotefor.value=='')
		{
			alert('Please select one of items before voting');
			return;
		}
	}

	open('', sform.name, 'scrollbars=yes,resizeable=no,locationbar=no,width=500,height=250,left='.concat((screen.width - 500)/2).concat(',top=').concat((screen.height - 250)/2));
	sform.faction.value = saction;
	sform.action = '/Vote/Submit.Asp';
	sform.submit();
}

function AddVote(SubjectID, PageID, VoteID, Align, VoteTitle, Color, BgColor, Width, NumItem, ItemArray, Description)
{
	document.writeln('<table width="', Width, '" border=0 cellspacing=1 cellpadding=2 bgcolor="', BgColor, '"', (Align=='') ? '' : ' align='.concat(Align), '>');
	if (VoteTitle!='')
	{
		document.writeln('<tr><td class=VoteTitle><font color="', Color, '">', VoteTitle, '</font></td></tr>');
	}

	if (typeof(Description)=='undefined')
	{
		Description = '';
	}

	document.writeln('<tr>');
	document.writeln('<form method="POST" target="Frm_', VoteID, '" name="Frm_', VoteID, '">');
	document.writeln('<td>');
	document.writeln('<table border=0 cellpadding=0 cellspacing=0 width="100%" bgcolor="#FFFFFF">');
    
	document.writeln('<input type="hidden" name="fsubjectid" value=', SubjectID, '>');
	document.writeln('<input type="hidden" name="fpageid" value=', PageID, '>');
	document.writeln('<input type="hidden" name="fvoteid" value=', VoteID, '>');
	document.writeln('<input type="hidden" name="fvotetitle" value="', VoteTitle, '">');
	document.writeln('<input type="hidden" name="fvotefor" value="">');
	document.writeln('<input type="hidden" name="faction" value="0">');
	document.writeln('<input type="hidden" name="fDescription" value="', Description, '">');

	document.writeln('<input type="hidden" name="fnumitem" value=', NumItem, '>');
	document.writeln('<tr><td width="100%" height=5 colspan=2><img src="/Images/White.gif" border=0></td></tr>');
    
	for (i=0; i < NumItem; i++)
	{
		document.writeln('<input type="hidden" name="fT_', i, '" value="', ItemArray[i][0], '">');
		document.writeln('<input type="hidden" name="fI_', i, '" value="', ItemArray[i][1], '">');
		document.writeln('<input type="hidden" name="fN_', i, '" value="', ItemArray[i][2], '">');
		document.writeln('<tr>');
		document.writeln('<td valign=top width=1><input type="checkbox" name="fC_', i, '" value=', ItemArray[i][2], ' class=VoteField onClick="CheckThisVote(this)"></td>');
		document.writeln('<td width="100%" class=VoteItem>', ItemArray[i][0], '</td>');
		document.writeln('</tr>');
	}

	document.writeln('<tr><td width="100%" colspan=2><hr color="#000000" size=1></td></tr>');
	document.writeln('<tr><td width="100%" height=30 colspan=2>&nbsp;<input type="button" value="Bi&#7875;u quy&#7871;t" name="Vote" class=VoteField onClick="SubmitVote(this.form, 0)">&nbsp;<input type="button" value="Xem" name="View" class=VoteField onClick="SubmitVote(this.form, 1)"></td></tr>');
	document.writeln('</table>');
	document.writeln('</td>');
	document.writeln('</form>');
	document.writeln('</tr>');
	document.writeln('</table>');
	document.writeln('<table cellspacing=0 cellpadding=0 border=0><tr><td height=2><img src="/Images/White.gif" border=0></td></tr></table>');
}

function ShowExpand(sobj1, sobj2)
{
	sobj1.style.display = 'none';
	sobj2.style.display = '';
}
