var xhr1;
var xhr2;

	function fRequest(method, action, param, async, func)
	{
		var xhr;
		if(window.XMLHttpRequest)
		{
			xhr = new XMLHttpRequest();
		}
		else if(window.ActiveXObject)
		{
			xhr = new ActiveXObject("Microsoft.XMLHTTP");
		}

		if(method=="get")
		{
			xhr.open("GET", action+"?"+param, async);
			if(async == true) xhr.onreadystatechange = function(){func(xhr);};
			xhr.send(null);
			if(async == false) func(xhr);
		}
		else if(method=="post")
		{
			xhr.open("POST", action, async);
			xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			if(async == true) xhr.onreadystatechange = function(){func(xhr);};
			xhr.send(param);
			if(async == false) func(xhr);
		}
		return xhr;
	}


var fTab = function(tab_buttons, button_class, button_class_sel, tab_content, tab_loader, files)
{
	var self = this;
	this.xhr = null;
	this.tab_buttons = tab_buttons;
	this.button_class = button_class;
	this.button_class_sel = button_class_sel;
	this.tab_content = tab_content;
	this.tab_loader = tab_loader;
	this.files = files;
	i=0;
	this.b = document.getElementById(this.tab_buttons).getElementsByTagName('div');

	for(i=0; i<this.b.length; i++)
	{
		this.b[i].onclick = (function(num){return function(){fOnClick(num);}}) (i);
	}

	function fOnClick(num)
	{
		for(i=0; i<self.b.length; i++)
			if(num==i) self.b[i].className = self.button_class_sel;
			else self.b[i].className = self.button_class;

		document.getElementById(self.tab_loader).style.display='block';
		document.getElementById(self.tab_content).style.display='none';

		self.xhr = fRequest
		(
		'post', self.files[num], '', true,
		function(xhr)
		{
			if(xhr.readyState==4 && xhr.status==200)
			{
				document.getElementById(self.tab_content).innerHTML = xhr.responseText;
				document.getElementById(self.tab_loader).style.display='none';
				document.getElementById(self.tab_content).style.display='block';
			}
		}
		);
	}
}
