var httpRequest=false;

function makeGETRequest(url,responseGET) {
	httpRequest=false;
	if (window.XMLHttpRequest) {
		httpRequest = new XMLHttpRequest();
		httpRequest.onreadystatechange = responseGET;
		httpRequest.open("GET", url, true);
		httpRequest.setRequestHeader("Connection","close");
		httpRequest.send(null);
	// branch for IE/Windows ActiveX version
	} else if (window.ActiveXObject) {
		httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
		if (httpRequest) {
			httpRequest.onreadystatechange = responseGET;
			httpRequest.open("GET", url, true);
			httpRequest.send();
		}
	}
}

function makePOSTRequest(postData,url,responsePOST) {
	if (window.XMLHttpRequest) {
		httpRequest = new XMLHttpRequest();
		httpRequest.onreadystatechange = responsePOST;
		httpRequest.open("POST", url, true);
		httpRequest.setRequestHeader("Method", "POST " + url + " HTTP/1.1");
		httpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		httpRequest.send(postData);
	// branch for IE/Windows ActiveX version
	} else if (window.ActiveXObject) {
		httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
		if (httpRequest) {
			httpRequest.onreadystatechange = responsePOST;
			httpRequest.open("POST", url, true);
			httpRequest.setRequestHeader("Method", "POST " + url + " HTTP/1.1");
			httpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			httpRequest.send(postData);
		}
	}
}

function responeFUNC(outID) {
	if (httpRequest.readyState == 4) {
		if (httpRequest.status == 200) {
			document.getElementById(outID).innerHTML	 = httpRequest.responseText;
		} else {
			alert("There was a problem" + httpRequest.statusText);
		}
	}
}

function subInfoCat(url) {
	makeGETRequest(url,resp_subInfoCat);
}
function resp_subInfoCat() {
	responeFUNC("subInfoCat");
}

function ajaxDistrict(url) {
	makeGETRequest(url,resp_District);
}

function resp_District() {
	responeFUNC("district");
}

function ajaxCCDistrict(url) {
	makeGETRequest(url,resp_CCDistrict);
}

function resp_CCDistrict() {
	responeFUNC("cc_district");
}

function ajaxAgencyDistrict(url) {
	makeGETRequest(url,resp_AgencyDistrict);
}

function resp_AgencyDistrict() {
	responeFUNC("agency_district");
}

function ajaxCarType(url) {
	makeGETRequest(url,resp_CarType);
}

function resp_CarType() {
	responeFUNC("cartype");
}

function ajaxDistrict(url) {
	makeGETRequest(url,resp_District);
}

function resp_District() {
	responeFUNC("district");
}

function ajaxSavenews(postdata, url) {
	makePOSTRequest(postdata,url,resp_Savenews);
}

function resp_Savenews() {
	if (httpRequest.readyState == 4) {
		if (httpRequest.status == 200) {
			alert('Ðã lưu tin này !!!');
		} else {
			alert("There was a problem" + httpRequest.statusText);
		}
	}	
}

function ajaxAMDIN_MC(url) {
	makeGETRequest(url,resp_AMDIN_MC);
}

function resp_AMDIN_MC() {
	responeFUNC("MerchandiseCat");
}
