function selectCode(a)
{
   var e = a.parentNode.parentNode.getElementsByTagName('CODE')[0];
   if (window.getSelection)
   {
      var s = window.getSelection();
       if (s.setBaseAndExtent)
      {
         s.setBaseAndExtent(e, 0, e, e.innerText.length - 1);
      }
      else
      {
         var r = document.createRange();
         r.selectNodeContents(e);
         s.removeAllRanges();
         s.addRange(r);
      }
   }
   else if (document.getSelection)
   {
      var s = document.getSelection();
      var r = document.createRange();
      r.selectNodeContents(e);
      s.removeAllRanges();
      s.addRange(r);
   }
   else if (document.selection)
   {
      var r = document.body.createTextRange();
      r.moveToElementText(e);
      r.select();
   }
}
vietvbb = new vB_AJAX_Handler(true);
function whodownloaded(attachmentid)
{
	window.open
	("whodownloaded.php?s=$session[sessionhash]&attachmentid=" + attachmentid, "whodownloaded", "toolbar=no, scrollbars=yes, resizable=no, width=240, height=300, top=50, left=50");
}
function vietvbb_response()
{
	if (vietvbb.handler.readyState == 4 && vietvbb.handler.status == 200 && vietvbb.handler.responseText)
	{
		switch(vietvbb.handler.responseText)
		{
			case 'installed':
				if (script == 'showthread')
				{
					bottomDiv.innerHTML = 'Thank you for supporting this modification -&gt; Click to <a href="javascript: vietvbb_doinstall(' + threadid + ',false)">Mark As Uninstalled</a>.';
					sideDiv.innerHTML = '<a href="hackdb.php?do=uninstall&amp;hackid=' + threadid + '" onclick="javascript: vietvbb_doinstall(' + threadid + ',false); return false;" title="Install This Hack" onmouseover="window.status=\"Uninstall this hack!\"; return true">Mark As Uninstalled</a>';
					installDiv.innerHTML = parseFloat(installDiv.innerHTML) + 1;
				} else {
					threadInstalled.innerHTML = '<a style="color:#008800;" href="javascript: vietvbb_doinstall(' + threadSave + ', false)">Installed:</a>';
					threadInstallCount.className = 'highlight';
					threadInstallCount.innerHTML = parseFloat(threadInstallCount.innerHTML) + 1;
				}				
				break;
			case 'uninstalled':	
				if (script == 'showthread')
				{
					bottomDiv.innerHTML = 'To receive notifications regarding updates -&gt; Click to <a href="javascript: vietvbb_doinstall(' + threadid + ',true)">Mark As Installed</a>.';
					sideDiv.innerHTML = '<a href="hackdb.php?do=install&amp;hackid=' + threadid + '" onclick="javascript: vietvbb_doinstall(' + threadid + ',true); return false;" title="Install This Hack" onmouseover="window.status=\"Install this hack!\"; return true">Mark As Installed</a>' ;
					installDiv.innerHTML = parseFloat(installDiv.innerHTML) - 1;
				} else {
					threadInstalled.innerHTML = '<a style="color:#999999;" href="javascript: vietvbb_doinstall(' + threadSave + ', true)">UnInstalled:</a>';;
					threadInstallCount.className = 'smallfont';
					threadInstallCount.innerHTML = parseFloat(threadInstallCount.innerHTML) - 1;
				}	
				break;
		    case 'nominated':
				nombottomDiv.innerHTML = 'Thank you for supporting this ' + nomname + '  -&gt; Click to <a href="javascript: vietvbb_donominate(' + threadid + ', false)"><b>Clear Nomination</b></a> from ' + nomname + '  of the Month.';
				nomsideDiv.innerHTML = '<a href="hackdb.php?do=unnominate&amp;hackid=' + threadid + '" onclick="javascript: vietvbb_donominate(' + threadid + ', false);return false;">Clear ' + nomchar + 'OTM Nomination</a>' ;
				document.getElementById('nominated').style.display='block';				
				break;
			case 'unnominated':
				nombottomDiv.innerHTML = 'If you like this ' + nomname + ' -&gt; Click to <a href="javascript: vietvbb_donominate(' + threadid + ', true)"><b>Nominate</b></a> for ' + nomname + ' of the Month.';
				nomsideDiv.innerHTML = '<a href="hackdb.php?do=nominate&amp;hackid=' + threadid + '" onclick="javascript: vietvbb_donominate(' + threadid + ', true);return false;">Nominate for ' + nomchar + 'OTM</a>';
				document.getElementById('nominated').style.display='none';
				break;	
			case 'notnominate':
				alert('You have not nominated this mod yet');break;
			case 'hasnominated':
				alert('You already nominated this '+nomname+' before');break;
			case 'reachedmax':
				alert('You has reached max nominations at this month');break;

			case 'tagged':
				tagDiv.style.display = 'inline';
				tagsideDiv.innerHTML = '<a href="hackdb.php?do=untagmod&hackid='+threadid+'" onclick="javascript: vietvbb_dotag('+threadid+', false);return false;">Untag Modification</a>';
				break;
			case 'untagged':
				tagDiv.style.display = 'none';
				tagsideDiv.innerHTML = '<a href="hackdb.php?do=tagmod&hackid='+threadid+'" onclick="javascript: vietvbb_dotag('+threadid+', true);return false;">Tag Modification</a>' ;
				break;

			default:
				break;
		}
	}
}

// Sends request to install a modification
function vietvbb_doinstall(threadid, install)
{
//	threadid = PHP.urlencode(threadid);
	threadSave = threadid;
	if (script == 'showthread')
	{
		bottomDiv = fetch_object('hack_install_div');
	    sideDiv = fetch_object('hack_install_sidebar');
		installDiv = fetch_object('hack_install_count');
	}
	else
	{
		threadInstalled = fetch_object('thread_installed_' + threadid);
		threadInstallCount = fetch_object('thread_installcount_' + threadid);
	}

	vietvbb.onreadystatechange(vietvbb_response);
	if(install)
	{
	vietvbb.send('hackdb.php', 'do=install&ajax=1&hackid='+threadid);
	} else { 
	vietvbb.send('hackdb.php', 'do=uninstall&ajax=1&hackid='+threadid);
	}		
}

// Sends request to nominate a modification
function vietvbb_donominate(threadid, nominate)
{
	//threadid = PHP.urlencode(threadid);
	
	nombottomDiv = fetch_object('hack_nominate_div');
    nomsideDiv = fetch_object('hack_nominate_sidebar');
	vietvbb.onreadystatechange(vietvbb_response);
	//send the request to php script...
	dostring = (nominate) ? 'nominate' : 'unnominate';
	vietvbb.send('hackdb.php','do=' + dostring + '&ajax=1&hackid=' + threadid);	
	//send response		
}
// Sends request to tag a modification
function vietvbb_dotag(threadid, tag)
{
	//threadid = PHP.urlencode(threadid);
	
	tagDiv = fetch_object('tagged_div');
    tagsideDiv = fetch_object('hack_tag_sidebar');
	
	//send the request to php script...
	dostring = (tag) ? 'tagmod' : 'untagmod';
	//vietvbb_handle = new vB_AJAX_Handler(true);
	vietvbb.onreadystatechange(vietvbb_response);
	vietvbb.send('hackdb.php','do=' + dostring + '&ajax=1&hackid=' + threadid);	//send response	
}	
function changeLang(lang)	{	var	id = (lang=='English')? 1 : 3;window.location='misc.php?do=changelanguage&langid='+id;}
function changeFrame() { vietvbbframe.location = 'http://www.vietvbb.vn/up/Link.php';}
//}