var xmlHttp;
var iTimeout=99;
var aFlag=true;
var arrContent = new Array();
var icount=0;
function stateLoad(obj)
{
	document.getElementById(obj).innerHTML='<div style="float:left"><img border="0" src="style/images/loading.gif"></div><div style="float:left">&nbsp;Loading data...</div>'

}
function loadXMLDoc(url, callbackFunction, desc, QUERY_STRING) {
	aFlag=false;
	//if(desc) window.status = desc;
    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        xmlHttp = new XMLHttpRequest();
		xmlHttp.onreadystatechange =	function(){
										// only if req shows "complete"
										if (xmlHttp.readyState == 4) {
											if(desc) stateLoad(desc);
											eval(callbackFunction);
										}
									}
		if(QUERY_STRING){
		    xmlHttp.open("POST", url, true);
			xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			xmlHttp.send(QUERY_STRING);
		}
        else{
	        xmlHttp.open("GET", url, true);
	        xmlHttp.send(null);
	    }
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        if (xmlHttp) {
        	xmlHttp.onreadystatechange =	function(){
											// only if req shows "complete"
											if (xmlHttp.readyState == 4) {
												if(desc) stateLoad(desc);
												eval(callbackFunction);
											}
										}
			if(QUERY_STRING){
			    xmlHttp.open("POST", url, true);
				xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				xmlHttp.send(QUERY_STRING);
			}
			else{
			    xmlHttp.open("GET", url, true);
			    xmlHttp.send(null);
			}
        }
    }
}

isIE=document.all;
isNN=!document.all&&document.getElementById;
isN4=document.layers;

document.onmousedown=ddInit;
document.onmouseup=Function("ddEnabled=false");

function ddInit(e){
	if (isIE&&event.srcElement.id=="dragbar"||isNN&&e.target.id=="dragbar"){
		offsetx=isIE? event.clientX : e.clientX
		offsety=isIE? event.clientY : e.clientY
		
		tempx=parseInt(crossobj.style.left)
		tempy=parseInt(crossobj.style.top)
		
		ddEnabled=true
		document.onmousemove=drag_drop
	}

}
function ietruebody(){
	return (document.compatMode && document.compatMode!="BackCompat" && !window.opera)? document.documentElement : document.body
}

function getAddForm(){
	xmlDoc = xmlHttp.responseText;
	//window.status="Completed";
	document.getElementById('divAddForm').innerHTML = xmlDoc;
}

function showAddForm(url)
{
	loadXMLDoc(url, 'getAddForm()', 'divAddForm');
	return false;
}

function getNewsInfo(){
	xmlDoc = xmlHttp.responseText;
	//window.status="Completed";
	document.getElementById('divNewsDetail').innerHTML = xmlDoc;
}

function showProdDetail(url)
{
	loadXMLDoc(url, 'getNewsInfo()', 'divNewsDetail');
}

function ajaxNewsDetail(title, strURL, e, position, imgwidth, imgheight){
	if (isIE||isNN){
		crossobj=document.getElementById? document.getElementById("divNewsWindow") : document.all.divNewsWindow
		if (position=="center"){
			pgyoffset=isNN? parseInt(pageYOffset) : parseInt(ietruebody().scrollTop)
			horzpos=isNN? pageXOffset+window.innerWidth/2-imgwidth/2 : ietruebody().scrollLeft+ietruebody().clientWidth/2-imgwidth/2
			vertpos=isNN? pgyoffset+window.innerHeight/2-imgheight/2 : pgyoffset+ietruebody().clientHeight/2-imgheight/2
			if (window.opera && window.innerHeight) //compensate for Opera toolbar
			vertpos=pgyoffset+window.innerHeight/2-imgheight/2
			vertpos=Math.max(pgyoffset, vertpos)
		}
		else{
			var horzpos=isNN? pageXOffset+e.clientX : ietruebody().scrollLeft+event.clientX
			var vertpos=isNN? pageYOffset+e.clientY : ietruebody().scrollTop+event.clientY
		}
		//coded by PhongTran
		crossobj.style.left=horzpos-100+"px"
		crossobj.style.top=vertpos+"px"
		var strHTML = '<table border="2" bordercolor="#006997" cellpadding="0" cellspacing="0" style="border-collapse: collapse" width="'+imgwidth+'">'
		strHTML = strHTML + '<tr>'
		strHTML = strHTML + '<td style="padding:1px">'
		strHTML = strHTML + '<table border="0" cellpadding="0" style="border-collapse: collapse" width="100%" id="table7" bgcolor="#006997">'
		strHTML = strHTML + '	<tr>'
		strHTML = strHTML + '		<td id="dragbar">'+title+'</td>'
		strHTML = strHTML + '		<td width="15" id="btnClose" onClick="closepreview()"><img title="&#272;&#243;ng" src="style/images/win_close.gif"></td>'
		strHTML = strHTML + '	</tr>'
		strHTML = strHTML + '</table>'
		strHTML = strHTML + '</td>'
		strHTML = strHTML + '</tr>'
		strHTML = strHTML + '<tr>'
		strHTML = strHTML + '<td>'
		strHTML = strHTML + '	<div id="divNewsDetail"><img border="0" src="style/images/loading.gif"></div>'
		strHTML = strHTML + '</td>'
		strHTML = strHTML + '</tr>'
		strHTML = strHTML + '</table>'

		crossobj.innerHTML= strHTML
		showProdDetail(strURL);
		crossobj.style.visibility="visible"
		return false
	}
	else //if NOT IE 4+ or NS 6+, simply display image in full browser window
		return true
}

function closepreview(){ //coded by PhongTran
	crossobj.style.visibility="hidden"
}

function drag_drop(e){
	if (isIE&&ddEnabled){
		crossobj.style.left=tempx+event.clientX-offsetx+"px"
		crossobj.style.top=tempy+event.clientY-offsety+"px"
	}
	else if (isNN&&ddEnabled){
		crossobj.style.left=tempx+e.clientX-offsetx+"px"
		crossobj.style.top=tempy+e.clientY-offsety+"px"
	}
	return false
}
