RESULT_PAGE_PHP = 'result.php';			// 腟??????若?梧；腓?HP
CREATE_IMAGE_PHP = 'create_image.php';	// ?糸?????PHP
RESULT_TEXT_ID = 'result';				// 腟?????絖?茵?ず?贋??ID(HTML?у?臂?
CODE_IMG = 'code';						// ?潟?若??茵?ずIMG?帥?違??D

// ???????吟?????ｃ??mlHttpRequest??bject???????????? 
function getXmlHttpRequestObject() {
	if (window.XMLHttpRequest) {
 		// Mozilla, Safari???
		return new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		// IE
		return new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		// ??絲上?
		alert("???????吟??XmlHttpRequest???綽????????障????鐚?鐚?");
	}
}

// ?????吾?с????????
var receiveReq = getXmlHttpRequestObject();

// ???????鴻??????
function makeRequest(url, param) {
	// ??篆≦?篋????障??open?＜?純???????若?喝?冴????????????
	if (receiveReq.readyState == 4 || receiveReq.readyState == 0) {
		// ?泣?若????????篆＜????紮?
		receiveReq.open("POST", url, true);
		// ?泣?若???若???????膈???????????絎?臂??腟????????若?吾?吾?????鐚?
		receiveReq.onreadystatechange = updatePage; 

		// ???????弱?臂
		receiveReq.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		receiveReq.setRequestHeader("Content-length", param.length);
		receiveReq.setRequestHeader("Connection", "close");

		// ??篆
		receiveReq.send(param);
	}   
}

// ?泣?若???若???????膈?????????
function updatePage() {
	// ??篆＜??絎?篋???????????絎?茵?
	if (receiveReq.readyState == 4) {
		// 荐??????ID?悟??????????絖??????祉????
		document.getElementById(RESULT_TEXT_ID).innerHTML = receiveReq.responseText;
		// ?潟?若???糸???紊?????????
		img = document.getElementById(CODE_IMG); 
		// ???ｃ???激?ャ?????帥?????????????潟???????ゃ???ゃ????
		img.src = CREATE_IMAGE_PHP + '?' + Math.random();
	}
}

// 茯?荐弱????絎?茵?
function auth(forms) {
	var postData = forms.input_data.name + "=" + encodeURIComponent( forms.input_data.value );
	// ???????鴻??絎?茵?
	makeRequest(RESULT_PAGE_PHP, postData);
}
