var xmlHttp;

function createXMLHttpRequest() {
	if (window.ActiveXObject) {
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else if (window.XMLHttpRequest) {
		xmlHttp = new XMLHttpRequest();
		}
}

function startRequest(){
	url="http://www.ban4u.com/ads/list_select.php";
	createXMLHttpRequest();
	xmlHttp.open("GET", url, true);
	xmlHttp.onreadystatechange = handlestatechange;
	xmlHttp.send(null);        
}

function showList(pMessage) {
	var divStatus = document.getElementById("divPostInfo");
	divStatus.innerHTML =  pMessage;
}

function list(){
	var pForm = document.forms[1];
	var pBody = getRequestBody(pForm); 
	
	createXMLHttpRequest(); 
	xmlHttp.open("post", pForm.action, true);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlHttp.onreadystatechange = handlestatechange;
	xmlHttp.send(pBody);  
}

function getRequestBody(pForm) {
	var nParams = new Array();
            
    for (var i=0 ; i < pForm.elements.length; i++) {
		var pParam = encodeURIComponent(pForm.elements[i].name);
		pParam += "=";
		pParam += encodeURIComponent(pForm.elements[i].value);
		nParams.push(pParam);
	} 
      
	return nParams.join("&");        
}

function add_list(){
	var id_post=document.getElementById("id_post").value;
	var url="http://www.ban4u.com/ads/add_post.php?id_post="+id_post;
	
	createXMLHttpRequest();
	xmlHttp.open("GET", url, true);
	xmlHttp.onreadystatechange = handlestatechange;
	xmlHttp.send(null); 
}

function handlestatechange(){
	if (xmlHttp.readyState == 4) {
		if (xmlHttp.status == 200) {
			//alert(xmlHttp.responseText);
			showList(xmlHttp.responseText);	
		} else {
			alert("¾º¢éÍ¼Ô´¾ÅÒ´ " + xmlHttp.statusText);
		}
	}
}

function logout(){	
	createXMLHttpRequest();
	xmlHttp.open("GET", "http://www.ban4u.com/ads/logout.php", true);
	xmlHttp.onreadystatechange = handlestatechange;
	xmlHttp.send(null); 
}