// JavaScript Document


//@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 AjaxSubmitMessage(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");
	}
	loader.onreadystatechange=function(){
		if(loader.readyState == 0){
			container.innerHTML = "Sending Request...";
		}
		if(loader.readyState == 1){
			container.innerHTML = "Loading Response...";
		}
		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){
				result=loader.responseText;
				container.innerHTML=result;
				
				AutoRection();
				/*
				if(result=="code"){
					container.innerHTML=error_msg("-3001","");
				}else if(result=="uid"){
					container.innerHTML=error_msg("-3002","");
				}else if(result=="pwd"){
					container.innerHTML=error_msg("-3003","");
				}else if(result=="passed"){
					//result login success
					window.location.href="/";
				}
				*/
			}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);
}
