//
// All scripts here are written for hn4u.com by Nguyen Hai Nam
// Leave this line, if you want to use it
//

/*
	HOW TO ADD A QUICK REPLY BOX
	1. Add this in your page, where you want to put it
	<iframe name="quickreply" width="482" height="289" frameborder="0" style="display:none" margin="0"></iframe>
	2. Add a button to turn on this box
	<span id="u_qr"><a href="javascript:forum_quickreply('post_url')">Quick reply</a></span>
	3. Be sure to load editor.js before, as this script waits for editor.js first, then it shows itself
*/
function forum_quickreply(url)
{
//	if (typeof(locked)=='undefined')
	{
		html = "<html><head><meta charset='utf-8'><link rel='stylesheet' href='/skin/vn.css'/></head>"
		html += "<script>inEditor=1</script>"
		html += "<body><form action='"+url+"' target='_parent' method='post' name='post' onsubmit='return checkForm(this)'>"
		html += "<table width='480' class='box' style='border-width:2px' cellspacing='1' cellpadding='1'>"
		html += "<tr><th>Tr&#7843; l&#7901;i nhanh</th></tr>"
		html += "<tr><td class='row2' align='center'><div id='editor_control'></div>"
		html += "<textarea tabindex='70' name='message' rows='10' cols='35' wrap='soft' style='width:450px' class='post' onselect='storeCaret(this)' onclick='storeCaret(this)' onkeyup='storeCaret(this)'></textarea>"
		html += "</td></tr><tr><td class='bottom' align='center'>"
		html += "<input type='submit' class='bold' name='submit' value='Send'/> "
		html += "<input type='submit' class='bold' name='preview' value='Preview'/>"
		html += "</td></tr></table></form></body>"
		html += "<script src='/js/editor.js'></script>"
		html += "<script src='/js/keyboard.js'></script>"
		html += "<script src='/js/effects.js'></script>"
		html += "<script>function init() {if (inEditor<2) {setTimeout('init()', 500);return}var editor = new Editor();editor.instantiate();parent.document.getElementById('iframe_qr').style.display=''}init()</script>"
		html += "</html>"
		w = window.open('', 'quickreply')
		w.document.write(html)
		w.close()
	}
	document.getElementById('u_qr').style.display = 'none'
}

/*
	TABLE OF CONTENT generator
	only work with IE5+
*/
function buildTOC()
{
	var coll = document.all;
	insHTML = "<html><head><link rel=stylesheet href='/skin/vn.css'>"
			+ "<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>"
			+ "<title>&#272;&#7873; m&#7909;c b&#224;i vi&#7871;t</title>"
			+ "<style>ul{margin:2px 0 0 10px;padding:0px;text-indent:-5px;text-align:left} a {font:11px Verdana;color:#000080} a:hover{color:#FF3300}</style>"
			+ "<base target=main></head><body style='background:#FFFFF0;margin:10px 0px 10px 0px'>"
			+ "</head><script src='/js/effects.js'></script><body margin=0 onload='visual_effects()'><div class=subject style='margin-top:0'>";
	for (i=document.body.sourceIndex+1; i<coll.length; i++)
	{
		switch (coll[i].tagName)
		{
			case "H1":insHTML = insHTML + coll[i].innerText+"</div>";break;
			case "H2":level = 0;break;
			case "H3":level = 1;break;
			case "H4":level = 2;break;
			case "H5":level = 3;break;
			case "H6":level = 4;break;
			default:level = -1;
		}
		if (level!=-1)
		{
			id = i;
			toc_setAnchor(coll[i++], id);
			toc_setLink(coll[i++], level, id);
			i++;
		}
	}
	insHTML += "<br><center><img src='/images/buttons/close.png' class='alpha' style='cursor:hand' onclick='self.close()'></center></body></html>";
	myTOC=window.open("","TOC","width=350,height=400,toolbar=no,menubar=no,scrollbars=yes,top=156,left=420");
	myTOC.document.write(insHTML);
	myTOC.document.close();
}

function toc_setAnchor(el, id)
{
	el.insertAdjacentHTML("BeforeBegin", "<a name='" + id + "'>");
	el.insertAdjacentHTML("AfterEnd", "</a>");
}

function toc_setLink(el, level, id)
{
	var s1 = "<ul>";
	var s2 = "</ul>";
	for (j=0; j < level; j++)
	{
		s1 = s1 + "<ul>";
		s2 = s2 + "</ul>";
	}
	insHTML += s1 + "<a href='#" + id + "'>" + el.innerText + "</a>" + s2;
}
function listen(songurl)
{
	if (songurl.match('\.(ram|ra|rm)$'))
	{
		type = 'audio/x-pn-realaudio-plugin';
		pluginspace = 'http://www.real.com';
	}
	else
	{
		type = 'application/x-mplayer2';
		pluginspace = 'http://www.microsoft.com/Windows/Downloads/Contents/Products/MediaPlayer/';
	}
	if (songurl.match('\.(asx|asf|wmv|avi|mpg|mpeg)$'))
	{
		height = '198';
	}
	else
	{
		height = '45';
	}

	if (ie || ns6)
	{
		var itmp = document.createElement('img');
		itmp.setAttribute('src', songurl+'.gif');

		var o=document.createElement('embed');
		o.setAttribute('width', '204');
		o.setAttribute('height', height);
		o.setAttribute('autostart', 'true');
		o.setAttribute('type', type);
		o.setAttribute('pluginspage', pluginspace);
		o.setAttribute('src', songurl);
		o.setAttribute('filename', songurl);
	
		var playlist = document.getElementById('playlist');
		while (playlist.hasChildNodes()) playlist.removeChild(playlist.lastChild);
		playlist.appendChild(o);
	}
}
function dicedit(url, word, dic)
{
	if (parseInt(navigator.appVersion)<5 && navigator.appVersion.indexOf["MSIE 5"]==-1) return;
	editObj = document.createElement('form');
	document.body.appendChild(editObj);

	editObj.action = url;
	editObj.method = 'post';

	objKeyword = document.createElement('input');
	objKeyword.name = 'keyword';
	objKeyword.value = word;
	editObj.appendChild(objKeyword);

	objDic = document.createElement('input');
	objDic.name = 'dic';
	objDic.value = dic;
	editObj.appendChild(objDic);

	editObj.submit();
}
function previewsubmit(url, target, names)
{
	quickview = window.open('about:blank', target, 'status=0,toolbar=0,scrollbars=1,width=480,height=360');
	quickview.focus();
	myform = document.createElement('form');
	myform.setAttribute('method', 'post');
	myform.setAttribute('target', target);
	myform.setAttribute('action', url);
	for (i=0; i<names.length; i++)
	{
		sInput = document.createElement('input');
		sInput.setAttribute('type', 'hidden');
		sInput.setAttribute('name', names[i]);
		sInput.setAttribute('value', eval('document.post.'+names[i]+'.value'));
		myform.appendChild(sInput);
	}
	document.body.appendChild(myform);
	myform.style.visibility = 'hidden';
	myform.submit();
}
