// JavaScript Document
if (!window.XMLHttpRequest) {
   window.XMLHttpRequest=function (){
   	return new ActiveXObject("Microsoft.XMLHTTP");
   }
}
//@desc    load a page(some html) via xmlhttp,and display on a container
//@param   url          the url of the page will load,such as "index.php"
//@param   request      request string to be sent,such as "action=1&name=surfchen"
//@param   method       POST or GET
//@param   container          the container object,the loaded page will display in container.innerHTML
//@usage 
//         ajaxLoadPage('index.php','action=1&name=surfchen','POST',document.getElementById('my_home'))
//         suppose there is a html element of "my_home" id,such as "<span id='my_home'></span>" 
//@author  SurfChen <surfchen@gmail.com>
//@url     http://www.surfchen.org/
//@license http://www.gnu.org/licenses/lgpl.html LGPL
function Gds_Load_Ajax(url,request,method,container)
{
	method=method.toUpperCase();
	var loading_msg='Loading...';//the text shows on the container on loading.
	var loader=new XMLHttpRequest;//require Cross-Browser XMLHttpRequest
	if (method=='GET')
	{
		urls=url.split("?");
		if (urls[1]=='' || typeof urls[1]=='undefined')
		{
			url=urls[0]+"?"+request;
		}
		else
		{
			url=urls[0]+"?"+urls[1]+"&"+request;
		}
		
		request=null;//for GET method,loader should send NULL
	}
	
	loader.open(method,url,true);
	if (method=="POST")
	{
		loader.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	}
	container=document.getElementById(container);
	loader.onreadystatechange=function(){
		if(loader.readyState == 0){
			container.innerHTML = "Sending...";
		}
		if(loader.readyState == 1){
			container.innerHTML = "Loading...";
		}
		if(loader.readyState == 2){
			container.innerHTML = "Response Loaded...";
		}
		if(loader.readyState == 3){
			container.innerHTML = "Response Ready...";
		}
		//if (loader.readyState==1)
		//{
			//container.innerHTML=loader.responseText;
		//}
		if (loader.readyState==4)
		{
			if(loader.status==200){
				var strJSON=loader.responseText;
				var obj = eval( "(" + strJSON + ")" );//
				//var obj=new Function("return" + strJSON)();
				
				try {
					container.innerHTML=eval(obj.content);
				}catch(exception) {
					alert(exception);
				}
				//var rrr=result['content'];
				//var result=(eval(obj.content).toString());
				//container.innerHTML=eval(str).toString();
			}else if(loader.status == 404){
				container.innerHTML = "File not found";// add msg
			}else{
				container.innerHTML = "There was a problem retrieving the XML."; 
			}

		}
	}
	loader.send(request);
}