
function retrieveURL(url,pars) {
	//alert(url);
	if (window.XMLHttpRequest) { // Non-IE browsers
		req = new XMLHttpRequest();
		req.onreadystatechange = processStateChange;
		try {
			req.open("POST", url+'.php'+pars);
			req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		} catch (e) {
			alert(e);
		}
		req.send(pars);
	} else if (window.ActiveXObject) { // IE
		req = new ActiveXObject("Microsoft.XMLHTTP");
		if (req) {
			req.onreadystatechange = processStateChange;
			req.open("POST", url+'.php'+pars);
			req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			req.send(pars);
			//alert();
		}
	}
}

function processStateChange() {
			document.getElementById(Object_show).innerHTML = '<div align="center" style="margin:5px; font-size:8pt;"><img src="img/load.gif" width="16" height="16" alt="" border="0" style="margin:5px;" /><br />Đang tải về...</div>';
			self.status='Đang tải dữ liệu ...';
	if (req.readyState == 4) { // Complete
		if (req.status == 200) { // OK response
			document.getElementById(Object_show).innerHTML = req.responseText;
			tfm_progressBarEnd(tfm_ProgressBar);
			///document.title='';
			self.status='Đã tải xong dữ liệu';
		} else {
			alert("Thông báo lỗi: " + req.statusText);
		}
	}
}

function StatusClick(url,pars,DivMainID){
	//alert(url);
	Object_show = DivMainID;
	retrieveURL(url,pars);
}

//==========================================//
function TFMProgressBar() { //v1.0.0
	this.create = function(container,id,len,width,height,speed,color,border,elementborder,traillength,multiplier) {
		//alert(container);
		this.container = container;
		this.id = id;
		this.len = (len && len != "") ? len : 10;
		this.width = (width && width != "") ? width : 15;
		this.height =(height && height != "") ? height : 16;
		this.speed = (speed && speed != "") ? speed : 100;
		this.color=(color && color != "") ? color : "#00dd66";
		this.border=(border && border != "") ? border : "0";
		this.elementborder = (elementborder && elementborder != "") ? elementborder : "0";
		this.traillength = (traillength && traillength != "") ? traillength : 6;
		this.multiplier = (multiplier && multiplier != "") ? multiplier : 1.05;
		this.counter = 0;
		this.red = parseInt(this.color.substr(1,2),16)/2.56;
		this.green = parseInt(this.color.substr(3,2),16)/2.56;
		this.blue = parseInt(this.color.substr(5,2),16)/2.56;			
	}
	
	this.init = function() {
		
		this.list = document.createElement("span");
		this.list.setAttribute("id", this.id);	
		this.list.speed = this.speed;
		this.list.style.border = this.border;
		this.list.style.margin = "10";
		this.list.style.padding = "10";
		this.list.style.fontSize= this.height + "px";
		for(var i=0;i<this.len;i++)	{
			var baritem = document.createElement("span");
			baritem.style.backgroundColor='transparent';
			baritem.style.padding = "0 " + Math.abs(this.width/2) + "px";
			baritem.style.margin = "0";
			baritem.style.fontSize= this.height + "px";
			baritem.style.textDecoration = 'none';
			baritem.style.borderLeft = this.elementborder;
			baritem.innerHTML = '&nbsp;';
			this.list.appendChild(baritem);
		}
		return this;
	}
	
	this.start = function(){
		this.end();
		this.init();
		if(window.focus)window.focus();
		this.div = document.getElementById(this.container);
		this.div.style.fontSize = this.height;
		this.div.appendChild(this.list);
		if(this.interval)clearInterval(this.interval);
		var theObj = this;	
		theObj.counter = 0;
		theObj.elements = theObj.list.getElementsByTagName('span');
		theObj.elementsLength = theObj.elements.length;
		var TFMProgressBar_Run = function() {
			if (theObj.counter++ >= theObj.elementsLength) theObj.counter = 0;
			var startPos = (theObj.counter-theObj.traillength > 0) ? theObj.counter-theObj.traillength : 0;
			for(var i=0; i<=startPos; i++) {
				theObj.elements[i].style.backgroundColor = '#fff';
			}
			var red = theObj.red;
			var green = theObj.green;
			var blue = theObj.blue;
			for(i=theObj.counter-1;i>=startPos;i--){
				theObj.elements[i].style.backgroundColor = "rgb(" + red + "%," + green + "%," + blue + "%)";
				red = red * theObj.multiplier;
				green = green * theObj.multiplier;
				blue = blue * theObj.multiplier;
			}
			for(i=theObj.counter; i<theObj.elementsLength; i++) {
				theObj.elements[i].style.backgroundColor = '#fff';
			}
		}
		this.interval = setInterval(TFMProgressBar_Run, this.speed);
	}
	
	this.end = function() {
		if(this.div && document.getElementById(this.id)) {		
			this.div.removeChild(this.list);
		}
		if(this.interval)clearInterval(this.interval);	
	}
}



function initProgressBar(url,pars,DivMain,BarLength) { //v1.0.0
	//============ Begin Configution Progress Bar ==============/
		container 	    = "blah";
	id		  	    = "tfm_ProgressBar";
	theBar        	= tfm_ProgressBar;
	//-------------------/
	len		  		= 10;
	width	  		= 50;	
	height    		= 50;
	speed     		= 150;
	color     		= "#69B769";
	border    		= "0px solid #000000";
	elementborder   = "1px solid #ff0000";
	traillength   	= 8;
	multiplier    	= 1.2;

	//============ End Configution Progress Bar ==============/
	
	//theBar.create(container,id,len,width,height,speed,color,border,elementborder,traillength,multiplier);
	//theBar.start(); //Khi nao can thi bo 2 dong nay de hien progressbar

	StatusClick(url,pars,DivMain);	
}

function tfm_progressBarEnd(bar) { //v1.0.0
	bar.end();
}