
/*
   -----------------------------------------------------
   郵便番号で住所の入力補助をする
   Ver. 1.0.1
   update 2011.10.18
   Copyright (C) WEB-JOZU  URL:http://www.web-jozu.com/
   -----------------------------------------------------
*/



/* ---------- 設定領域 start ---------- */

//フォームのname属性を設定
formNm = "test";

//県（select）のname属性を設定
prefNm = "prefnum";

//住所（input）のname属性を設定
prefNm2 = "pref";

/* ---------- 設定領域 end ---------- */


var prefList;dataSt = "off";errorMess = "該当する住所はありませんでした。";half = "0123456789-----";full = "０１２３４５６７８９ー―−‐−";function chgMessHalf(DATA){messIn = DATA;messOut = "";for(i=0; i<messIn.length; i++){oneStr = messIn.charAt(i);num = full.indexOf(oneStr,0);oneStr = num >= 0 ? half.charAt(num) : oneStr;messOut += oneStr;}return messOut;}function toNum(DATA){if(DATA.indexOf("-") != -1){DATA = DATA.split("-");messOut = DATA[0] + DATA[1];}else{messOut = DATA;}return messOut;}function require(NAME) {prefList = "";var script = document.createElement('script');script.type = 'text/javascript';script.src = 'zip_input/data/' + NAME + '.js';var objHead = document.getElementsByTagName('head')[0];objHead.appendChild(script);}function fileNm(){formObj = this['document'][formNm];zipObj = toNum(formObj.zip.value);if(zipObj.match(/^0(0|[4-9])/)){jsfile ="01hokkai";}else if(zipObj.match(/^03/)){jsfile ="02aomori";}else if(zipObj.match(/^02/)){jsfile ="03iwate";}else if(zipObj.match(/^98/)){jsfile ="04miyagi";}else if(zipObj.match(/^01/)){jsfile ="05akita";}else if(zipObj.match(/^99/)){jsfile ="06yamaga";}else if(zipObj.match(/^9[6-7]/)){jsfile ="07fukush";}else if(zipObj.match(/^3[0-1]/)){jsfile ="08ibarak";}else if(zipObj.match(/^32/)){jsfile ="09tochig";}else if(zipObj.match(/^37/)){jsfile ="10gumma";}else if(zipObj.match(/^3[3-6]/)){jsfile ="11saitam";}else if(zipObj.match(/^2[6-9]/)){jsfile ="12chiba";}else if(zipObj.match(/^1/) || zipObj.match(/^20/)){jsfile ="13tokyo";}else if(zipObj.match(/^2[1-5]/)){jsfile ="14kanaga";}else if(zipObj.match(/^9[4-5]/)){jsfile ="15niigat";}else if(zipObj.match(/^93/)){jsfile ="16toyama";}else if(zipObj.match(/^92/)){jsfile ="17ishika";}else if(zipObj.match(/^91/)){jsfile ="18fukui";}else if(zipObj.match(/^99/)){jsfile ="19yamana";}else if(zipObj.match(/^3[8-9]/)){jsfile ="20nagano";}else if(zipObj.match(/^50/)){jsfile ="21gifu";}else if(zipObj.match(/^4[1-3]/)){jsfile ="22shizuo";}else if(zipObj.match(/^4[4-9]/) && zipObj.match(/^49808/) == 0){jsfile ="23aichi";}else if(zipObj.match(/^51/) || zipObj.match(/^49808/)){jsfile ="24mie";}else if(zipObj.match(/^52/)){jsfile ="25shiga";}else if(zipObj.match(/^6[0-2]/) || zipObj.match(/^61800[7-9]/)){jsfile ="26kyouto";}else if(zipObj.match(/^5[3-9]/) || zipObj.match(/^618/)){jsfile ="27osaka";}else if(zipObj.match(/^6[5-7]/)){jsfile ="28hyogo";}else if(zipObj.match(/^63/)){jsfile ="29nara";}else if(zipObj.match(/^64/)){jsfile ="30wakaya";}else if(zipObj.match(/^68/)){jsfile ="31tottor";}else if(zipObj.match(/^69/)){jsfile ="32shiman";}else if(zipObj.match(/^7[0-1]/)){jsfile ="33okayam";}else if(zipObj.match(/^7[2-3]/)){jsfile ="34hirosh";}else if(zipObj.match(/^7[4-5]/)){jsfile ="35yamagu";}else if(zipObj.match(/^77/)){jsfile ="36tokush";}else if(zipObj.match(/^76/)){jsfile ="37kagawa";}else if(zipObj.match(/^79/)){jsfile ="38ehime";}else if(zipObj.match(/^78/)){jsfile ="39kochi";}else if(zipObj.match(/^8[0-3]/) || zipObj.match(/^8710[8-9]/)){jsfile ="40fukuok";}else if(zipObj.match(/^84/)){jsfile ="41saga";}else if(zipObj.match(/^85/)){jsfile ="42nagasa";}else if(zipObj.match(/^86/)){jsfile ="43kumamo";}else if(zipObj.match(/^87/) || zipObj.match(/^871/)){jsfile ="44oita";}else if(zipObj.match(/^88/)){jsfile ="45miyaza";}else if(zipObj.match(/^89/)){jsfile ="46kagosh";}else if(zipObj.match(/^90/)){jsfile ="47okinaw";}else{jsfile ="error";}require(jsfile);}function dataSc(){document.getElementById("errorpref").childNodes[0].nodeValue = "";jsfile = "";dataSt = "off";formObj = this['document'][formNm];zipObj = formObj.zip.value;zipObj = formObj.zip.value = chgMessHalf(zipObj);fileNm();if(jsfile != "error"){timerID = setTimeout("checkDt()", 1000);}else{document.getElementById("errorpref").childNodes[0].nodeValue = errorMess;}}function checkDt(){if(prefList != ""){clearTimeout(timerID);viewDt();}else{timerID = setTimeout("checkDt()", 1000);}}function viewDt(){formObj = this['document'][formNm];zipObj = toNum(formObj.zip.value);dataNum = prefList.length;for(i=0; i<dataNum; i++){if(prefList[i][0] == zipObj){formObj[prefNm].options[Number(jsfile.substring(0,2))].selected = true;formObj[prefNm2].value = prefList[i][2] + prefList[i][3];dataSt = "on";}}if(dataSt == "off"){document.getElementById("errorpref").childNodes[0].nodeValue = errorMess;}}