var xmlhttp = null;

/* POSTによるデータ送信 */
function xmlsub(ad,txt){

    /* XMLHttpRequestオブジェクト作成 */
    if (xmlhttp == null) {
        xmlhttp = createXmlHttp();
    } else {
        /* 既に作成されている場合、通信をキャンセル */
        xmlhttp.abort();
    }
    
    /* レスポンスデータ処理方法の設定 */
    xmlhttp.onreadystatechange = handleHttpEvent;
    
    /* HTTPリクエスト実行 */
    xmlhttp.open("POST", ad , true);
    xmlhttp.setRequestHeader("Content-Type" , "application/x-www-form-urlencoded");
    xmlhttp.send(txt);

    /* レスポンスデータ処理 */
    function handleHttpEvent(){
        if (xmlhttp.readyState == 4) {
            if (xmlhttp.status == 200) {
//                window.alert(decodeURIComponent(xmlhttp.responseText));
				eval(decodeURIComponent(xmlhttp.responseText));
            } else {
                window.alert("1:通信エラーが発生しました。");
    
            }
        }
    }
}

/* POSTによるデータ送信 */
function ajax(ad,txt){

    /* XMLHttpRequestオブジェクト作成 */
    if (xmlhttp == null) {
        xmlhttp = createXmlHttp();
    } else {
        /* 既に作成されている場合、通信をキャンセル */
        xmlhttp.abort();
    }
    
    /* レスポンスデータ処理方法の設定 */
    xmlhttp.onreadystatechange = handleHttpEvent;
    
    /* HTTPリクエスト実行 */
    xmlhttp.open("POST", ad , true);
    xmlhttp.setRequestHeader("Content-Type" , "application/x-www-form-urlencoded");
    xmlhttp.send(txt);

    /* レスポンスデータ処理 */
    function handleHttpEvent(){
        if (xmlhttp.readyState == 4) {
            if (xmlhttp.status == 200) {
//                window.alert(decodeURIComponent(xmlhttp.responseText));
				return decodeURIComponent(xmlhttp.responseText);
            } else {
                window.alert("2:通信エラーが発生しました。");
    
            }
        }
    }
}

/* XMLHttpRequest生成 */
function createXmlHttp(){
    if (window.ActiveXObject) {
		try {
			return new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){
			try{
		        return new ActiveXObject("Microsoft.XMLHTTP");
			}catch(e2){
				return NULL;
			}
		}
    } else if (window.XMLHttpRequest) {
        return new XMLHttpRequest();
    } else {
        return null;
    }
}

function kanma(x) {
    var s = "" + x;
    var p = s.indexOf(".");
    if (p < 0) {
        p = s.length;
    }
    var r = s.substring(p, s.length);
    for (var i = 0; i < p; i++) {
        var c = s.substring(p - 1 - i, p - 1 - i + 1);
        if (c < "0" || c > "9") {
            r = s.substring(0, p - i) + r;
            break;
        }
        if (i > 0 && i % 3 == 0) {
            r = "," + r;
        }
        r = c + r;
    }
    return r;
}
