function createXMLHttpRequest(){
        var xmlHttp = false;  // Ajax
        if (!xmlHttp && typeof XMLHttpRequest != 'undefined') { // Mozilla
            xmlHttp = new XMLHttpRequest();
        } else if (window.ActiveXObject) { // IE
            try {
                xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
            try {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
        }
    }
        return xmlHttp;
}

    function checkAjax(SN) {
        var URL = "check_sn.jsp?val="+SN;
        xmlHttp = createXMLHttpRequest();
        xmlHttp.onreadystatechange = function(){ handleStateChange() };
        xmlHttp.open("GET", URL,"true");
        xmlHttp.send(true);
    }

    function handleStateChange() {
        var trim_responseText = null;
        if(xmlHttp.readyState == 4) {
            if(xmlHttp.status == 200) {
                trim_responseText = trim(xmlHttp.responseText);
                if ( trim_responseText == "1" ) {
                    // 預防user連續送出
                    document.getElementById('ready').style.display = "none";
                    document.getElementById('send').style.display = "";
                    document.numberForm.submit();
                } else {
                    alert('您的序號不存在,請查明後重新輸入!');
                }
            }
        }
    }
    
    function trim(strvalue) {
        ptntrim = /(^\s*)|(\s*$)/g;
        var val = strvalue.replace(ptntrim,"");
        return val;
    }
