// JavaScript Document for site admin
function convertFileSizeToString(size)
{
	
	var  bytes = Array("B", "KB", "MB", "GB", "TB", "PB");
	 i = 0;
	while (size >= 1024) { 
		size = size/1024;
		i++;
	}
	if (i > 1) {
		
		return  Math.round(size)+" "+bytes[i];
	} else {
		return Math.round(size) +" "+bytes[i];
	}
}

/**
*
*  Crossbrowser Drag Handler
*  http://www.webtoolkit.info/
*
**/
 
var DragHandler = {
 
 
	// private property.
	_oElem : null,
 
 
	// public method. Attach drag handler to an element.
	attach : function(oElem) {
		oElem.onmousedown = DragHandler._dragBegin;
 
		// callbacks
		oElem.dragBegin = new Function();
		oElem.drag = new Function();
		oElem.dragEnd = new Function();
 
		return oElem;
	},
 
 
	// private method. Begin drag process.
	_dragBegin : function(e) {
		var oElem = DragHandler._oElem = this;
 
		if (isNaN(parseInt(oElem.style.left))) { oElem.style.left = '0px'; }
		if (isNaN(parseInt(oElem.style.top))) { oElem.style.top = '0px'; }
 
		var x = parseInt(oElem.style.left);
		var y = parseInt(oElem.style.top);
 
		e = e ? e : window.event;
		oElem.mouseX = e.clientX;
		oElem.mouseY = e.clientY;
 
		oElem.dragBegin(oElem, x, y);
 
		document.onmousemove = DragHandler._drag;
		document.onmouseup = DragHandler._dragEnd;
		return false;
	},
 
 
	// private method. Drag (move) element.
	_drag : function(e) {
		var oElem = DragHandler._oElem;
 
		var x = parseInt(oElem.style.left);
		var y = parseInt(oElem.style.top);
 
		e = e ? e : window.event;
		oElem.style.left = x + (e.clientX - oElem.mouseX) + 'px';
		oElem.style.top = y + (e.clientY - oElem.mouseY) + 'px';
 
		oElem.mouseX = e.clientX;
		oElem.mouseY = e.clientY;
 
		oElem.drag(oElem, x, y);
 
		return false;
	},
 
 
	// private method. Stop drag process.
	_dragEnd : function() {
		var oElem = DragHandler._oElem;
 
		var x = parseInt(oElem.style.left);
		var y = parseInt(oElem.style.top);
 
		oElem.dragEnd(oElem, x, y);
 
		document.onmousemove = null;
		document.onmouseup = null;
		DragHandler._oElem = null;
	}
 
}
function ajax_alert(url)
{
	//alert(url+param);

	var xmlHttp;
	if (window.XMLHttpRequest)
	{
		
		xmlHttp=new XMLHttpRequest();

	}
	else
	{
		
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlHttp.onreadystatechange=function()
	{
		if (xmlHttp.readyState==4) {
			if (xmlHttp.status == 200) {
				var result=xmlHttp.responseText;
				alert(result);
			//	document.getElementById(param).innerHTML=xmlHttp.responseText;
			}
			else {
				
				alert('Error!!!!');
			}
		}
		else {
			// loading…
		}
	}
   // var url='callbackprocess.php?app=product&view=ajax&number='+document.getElementById('number').value+'&price='+<?=$item->price?>;
	//alert(url);
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function ajax_div(param,url)
{
//	alert(url+param);

	var xmlHttp;
	if (window.XMLHttpRequest)
	{
		
		xmlHttp=new XMLHttpRequest();

	}
	else
	{
		
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlHttp.onreadystatechange=function()
	{
		if (xmlHttp.readyState==4) {
			if (xmlHttp.status == 200) {
				document.getElementById(param).innerHTML=xmlHttp.responseText;
			}
			else {
				
				alert('Error!!!!');
			}
		}
		else {
			// loading…
		}
	}
   // var url='callbackprocess.php?app=product&view=ajax&number='+document.getElementById('number').value+'&price='+<?=$item->price?>;
	//alert(url);
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);

}
function AjaxShow(url, idshow)
{
	//alert(url+idshow);
	 if (window.XMLHttpRequest)
	{
		// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlHttp=new XMLHttpRequest();

	}
	else
	{
		// code for IE6, IE5
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlHttp.onreadystatechange=function()
	{
		if (xmlHttp.readyState==4) {
			if (xmlHttp.status == 200) {
				//document.myForm.hienthi.value=xmlHttp.responseText;
				document.getElementById(idshow).innerHTML=xmlHttp.responseText;
			}
			else {
				// CĂł lá»—i! ThĂ´ng bĂˇo ngay!
				alert('Lá»—i!!!!');
			}
		}
		else {
			// loadingâ€¦
		}
	}
	
	//alert(url);
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);	
}

