/** * Zip Api Class * * @copyright Copyright (c) 2008 Global Network Core Co.,Ltd. All rights reserved. * @since 2008/11/10 * @version 1.0.0 */ function ZipApiClass() { this.initialize.apply(this, arguments); }; ZipApiClass.prototype = { initialize:function(){ this._token = "1391ff58"; }, searchByZip:function(zip, callback, office) { office = office == null ? false : office; if(zip.length == 0) { alert("郵便番号を入力して下さい。"); return; } /* if(zip.replace("-", "").length < 7) { alert("郵便番号は7桁の番号で入力してください。"); return; } */ if(zip.replace("-", "").length < 3) { alert("郵便番号は3桁以上で検索可能です。"); return; } var params = "&zip=" + encodeURI(zip); this._openScript(params, callback, office); }, searchByAddress:function(pref, address, callback, office) { office = office == null ? false : office; if(pref.length == 0) { alert("都道府県を入力してください。"); return; } if(address.length == 0) { alert("市区町村を入力してください。"); return; } var params = "&pref=" + encodeURI(pref) + "&address=" + encodeURI(address); this._openScript(params, callback, office); }, _openScript:function(params, callback, office) { if(!callback) { alert("コールバック関数が設定されていません。"); return; } this._callback = callback; var script = document.createElement("script"); script.type = "text/javascript"; script.charset = "UTF-8"; var src = "https://api.nplus-net.jp/zip/index.php?ac=Search" src += office ? "&office=1" : ""; src += "&q=269fac8bed4ef5474bd96630e6bf51cc"; src += "&t=" + this._token + params; script.src = src; document.body.appendChild(script); }, execCallback:function(obj) { this._token = obj.token; this._callback(obj); } } var ZipApi= new ZipApiClass();