var timeout=null;
function ajaxTimeout()
{
	if(xmlHTTP.readyState==1)
	{
		xmlHTTP.abort();
		alert("ไม่มีการตอบสนองจาก server");
		window.location = window.location.href;
	}
	clearTimeout(timeout);
}
function ajaxLoad(method,url,data,displayId,divLoad)
{
	timeout=setTimeout("ajaxTimeout()",10000);
	document.getElementById(divLoad).style.display = "block";
	//document.getElementById(displayId).style.display = "none";

	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)
		{
			document.getElementById(divLoad).style.display = "none";
			var var_msg = xmlHTTP.responseText;
			//alert(var_msg);
			//document.getElementById(displayId).style.display = "block";
			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);
	//alert(event.clientX);
	//alert(event.clientY);
	//alert(div_tooltip.offsetWidth);
	//alert(div_tooltip.offsetHeight); 
	
	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 search_within_company(event,div_id)
{
	mouse_position(event,div_id);
	var bus_id=document.getElementById("business_type").value;
	var keyword=document.getElementById("keyword_cpn").value;
	if(keyword == "--ป้อนคำค้นหา--")
	{
		keyword ="";
	}
	bus_id=encodeURI(bus_id);
	keyword=encodeURI(keyword);
	var today = new Date();
	today.setTime( today.getTime() );
	var url = "company-all-search.php?td="+today;
	var data = "";
	var data = "&bus_id="+bus_id+"&keyword="+keyword;
	ajaxLoad("POST",url,data,'div_dis','div_load');
}

