var checkflag = "true";
var timeout=null;
function check() 
{	
    var myCheckbox = document.form_all['check_all[]'];
	if( myCheckbox )
	{
		for(i=0; i<myCheckbox.length; i++)
		{
			myCheckbox[i].checked = checkflag;
		}
			checkflag = !checkflag;
	}

}
function get_param(param)
{
	var param2=param.split("@");
	var qstr="";
	for(i=0;i<param2.length;i++)
	{
		qstr += "&para[]="+param2[i];
	}
	return qstr;
	
}
function ajaxTimeout()
{
	if(xmlHTTP.readyState==1)
	{
		xmlHTTP.abort();
		alert("ไม่มีการตอบสนองจาก server");
		window.location = window.location.href;
	}
	clearTimeout(timeout);
}
function ajaxLoad2(url)
{
	var today = new Date();
	today.setTime( today.getTime() );
	url += "&td="+today;
	xmlHTTP = createXMLHttpRequest();
	xmlHTTP.open("GET", url, false);
	xmlHTTP.send('');
	var var_msg = xmlHTTP.responseText;
	return var_msg;
}
function ajaxLoad1(method,url,data,displayId,divLoad,actionDis)
{
	timeout=setTimeout("ajaxTimeout()",20000);
	var today = new Date();
	today.setTime( today.getTime() );
	url += "&td="+today;
	
	/*
		action=1 คือ ทำการเปิด div loading และปิดการแสดงของ content แล้วจึงนำค่าที่ได้จาก server มาแสดง
		action=2 คือ ทำการเปิด div loading(อาจจะอยู่กลางหน้าจอแล้วแต่กำหนด) และ content ก็ยังแสดงอยู่และนำค่าที่ได้จาก server มาแสดง
	*/
	if(actionDis==1)  
	{
		document.getElementById(divLoad).style.display = "block";
		document.getElementById(displayId).style.display = "none";
	}
	else if(actionDis==2)
	{
		document.getElementById(divLoad).style.visibility = "visible";
	}

	xmlHTTP = createXMLHttpRequest();
	xmlHTTP.open(method, url, true);
	if(method=="POST")
	{
		xmlHTTP.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	}
	xmlHTTP.onreadystatechange=function()
	{
		if(xmlHTTP.readyState == 4 && xmlHTTP.status ==200)
		{
			if(var_msg == "redirect")
			{
				window.location = HOST_PATH;
			}
			else
			{
				var var_msg = xmlHTTP.responseText;
				//alert(var_msg); // test ค่า ที่ return
				if(actionDis==1)
				{	
					document.getElementById(divLoad).style.display = "none";
					document.getElementById(displayId).style.display = "block";
				}
				else if(actionDis==2)
				{
					document.getElementById(divLoad).style.visibility = "hidden";
				}
				
				document.getElementById(displayId).innerHTML = var_msg;
				clearTimeout(timeout);
			}
		}
	};
	if(method=="POST")
	{
		xmlHTTP.send(data);
	}
	else
	{
		xmlHTTP.send('');
	}
}
function mouse_position(event,div_id)
{
	var div=document.getElementById(div_id);
	var left = event.clientX+5;
	if((left + div.offsetWidth) > document.body.clientWidth)
	{
		left -= (div.offsetWidth + 10);
	}
	var top = event.clientY;
	if((top + div.offsetHeight) > document.body.clientHeight)
	{
		top -= (div.offsetHeight +10);
	}
	top += document.documentElement.scrollTop;
	div.style.top = top + "px";
	div.style.left = left + "px";
}
function set_position_center(div_id)
{
	var div=document.getElementById(div_id);
	div.style.left= (document.documentElement.clientWidth/2)-(div.clientWidth/2)+"px";
	div.style.top = (document.documentElement.clientHeight/2)-(div.clientHeight/2)+used_scrollHeight()+"px";
	
}
function used_scrollHeight()
{
	var myScroll;
	if(typeof(window.innerHeight)=='undefined')  //is IE6+..............................
	{
		myScroll = document.documentElement.scrollTop;
	}
	else if(navigator.appName=="Netscape" || navigator.appName=="Opera")   //is firefox,safari,google chrome..............................
	{
		myScroll = window.pageYOffset;
	}
	return myScroll;
}