/*#########################################################################
#####  [AJAX]VietVBB - Advanced Forum Statistics for vbulletin 4.x.x  #####
#####  Linhnt - VietVBBTeam - www.vietvbb.vn                          #####
###########################################*#############################*/

function addLoadEventV(func)	{
	var oldload = window.onload;
	if (typeof window.onload != 'function')	{
		window.onload = func;
	}
	else	{
		window.onload = function()	{
			oldload();
			func();
			}
	}
}	


function topxInit() {
	var ul = document.getElementById('vietvbb_topstats_t');
	var li = ul.getElementsByTagName('li');
	for (var i=0; i < li.length-1; i++)	{
		li[i].onclick = function()	{
			viewTabV(this);
			}
	}
	
	var select = document.getElementById('vietvbb_topstats_s');
	select.onchange= function()	{
		viewMenuV(this.value);
		}	
	
	var result_menu = document.getElementById('vietvbb_topstats_result');
	if(result_menu)
		result_menu.onchange= function()	{
			topXReload();
			}	
}


function viewTabV(a) {	
	var id = a.id;
	var ul = document.getElementById('vietvbb_topstats_t');
	var li = ul.getElementsByTagName('li');
	for (var i=0; i < li.length-1; i++)	{
		li[i].className='';
	}
	
	a.className='current';	
	
	document.getElementById('vietvbb_topstats_t_loading').style.display = 'inline';	
	top_requestT = new vB_AJAX_Handler(true);
	top_requestT.onreadystatechange(handleResponsesT);
	var url = 'ajax.php?do=gettop&top=' + id + '&ran=' + Math.random();
	var result = document.getElementById('vietvbb_topstats_result');
	if (result)	{		
		url = url + '&result=' + result.value;
	}
	top_requestT.send(url);
}

function handleResponsesT() {
	if (top_requestT.handler.readyState == 4 && top_requestT.handler.status == 200)	{
		document.getElementById('vietvbb_topstats_t_loading').style.display = 'none';				
		document.getElementById('vietvbb_topstats_t_content').innerHTML = top_requestT.handler.responseText;
    }
}


function viewMenuV(a) {
	document.getElementById('vietvbb_topstats_s_loading').style.display = 'inline';		
	top_requestS = new vB_AJAX_Handler(true);
	top_requestS.onreadystatechange(handleResponsesS);
	var url = 'ajax.php?do=gettop&top=' + a + '&menu=1&ran=' + Math.random();
	var result = document.getElementById('vietvbb_topstats_result');
	if (result)	{		
		url = url + '&result=' + result.value;		
	}
	top_requestS.send(url);
}

function handleResponsesS() {
	if (top_requestS.handler.readyState == 4 && top_requestS.handler.status == 200)	{
		document.getElementById('vietvbb_topstats_s_loading').style.display = 'none';				
		document.getElementById('vietvbb_topstats_s_content').innerHTML = top_requestS.handler.responseText;
    }
}

function topXReload()	{
	var ul = document.getElementById('vietvbb_topstats_t');
	var li = ul.getElementsByTagName('li');
	for (var i=0; i < li.length-1; i++)	{
		if (li[i].className == 'current')
			viewTabV(li[i]);
	}	
	var select = document.getElementById('vietvbb_topstats_s');		
	viewMenuV(select.value);
}

function topxTip (content)	{
	Tip(content, PADDING, 1 , BORDERWIDTH, 0, BGCOLOR, '', STICKY, 1, DURATION, 10000, CLICKCLOSE, true);
}


addLoadEventV(topxInit);


/*#########################################################################
#####  [AJAX]VietVBB - Advanced Forum Statistics for vbulletin 4.x.x  #####
#####  Linhnt - VietVBBTeam - www.vietvbb.vn                          #####
###########################################*#############################*/
