function handleHttpResponse() {
    if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
        var xmlDoc = xmlHttp.responseXML;
        if (xmlDoc.documentElement) {
            var chk    = xmlDoc.getElementsByTagName('chk').item(0).firstChild;
            if (chk    != null) {
				if( chk.data == 1 ) {
					document.getElementById('alert1').innerHTML = 'サブドメインエラー';
					document.getElementById('alert2').innerHTML = 'ご入力された文字列はサブドメインとしてご利用出来ません。';
				} else {
					document.getElementById('alert1').innerHTML = 'サブドメインご利用可能';
					document.getElementById('alert2').innerHTML = 'ご入力された文字列はサブドメインとしてご利用可能です。';
				}
			}
        } else {
			document.getElementById('alert1').innerHTML = 'サブドメインがご利用可能か表示されます。';
			document.getElementById('alert2').innerHTML = '';
        }
    }
}

function chkSubDomain() {
    var sub_domain = document.getElementById('sub_domain').value;

	if(sub_domain.length < 3){
		document.getElementById('alert1').innerHTML = 'サブドメインがご利用可能か表示されます。';
		document.getElementById('alert2').innerHTML = '';
		return;
	}
	if(sub_domain.match(/[^0-9a-zA-Z-]+/) || sub_domain.substring( 0 , 1 ) == "-" || sub_domain.substring( sub_domain.length - 1 ) == "-" || sub_domain.length > 16){
		document.getElementById('alert1').innerHTML = 'サブドメインエラー';
		document.getElementById('alert2').innerHTML = 'ご入力された文字列はサブドメインとして指定出来ません。';
		return;
	}

    xmlHttp.open('GET', 'http://www.my-website.jp/trial_order/ajaxsubdomain.php?s=' + escape(sub_domain) , true);
    xmlHttp.onreadystatechange = handleHttpResponse;
    xmlHttp.send(null);
}

function getXmlHttpObject() {
    var xmlhttp;
    /*@cc_on
    @if (@_jscript_version >= 5)
        try {
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (E) {
                xmlhttp = false;
            }
        }
    @else
        xmlhttp = false;
    @end @*/
    if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
        try {
            xmlhttp = new XMLHttpRequest();
            xmlhttp.overrideMimeType("text/xml"); 
        } catch (e) {
            xmlhttp = false;
        }
    }
    return xmlhttp;
}

var xmlHttp = getXmlHttpObject();
