/**
* ************************************************
* 업무그룹명 : 공통 자바스크립트
* 서브업무명 : 콤보박스용 ajax 스크립트
* 설명 :
* 작성자 : dkhjmu
* 작성일 : 2007. 7. 31 오후 5:25:55
* *************************************************
*/
// 토지코드
var COMBOLANDCODE = null;
// 시군구에 쓰는 플래그
var AJAX_SGG_CODE = 1;
// 읍면동에 쓰는 플래그
var AJAX_UMD_CODE = 2;
// 에이작스를 사용하고 있는지 등의 상태를 나타내는 플래그
// 1 파싱중
// 0 미사용
var Ajax_Status = 0;
// false 에이작스미사용(작업완료)
// true 에이작스 사용중(작업중)
var Ajax_inUse = false;
// 롤백일 경우를 나타내는 플래그
var Ajax_rollback=false;
// 에이작스 연결을 위한 함수
function initRequest(){
if (window.XMLHttpRequest) {
return new XMLHttpRequest();
} else if (window.ActiveXObject) {
var isIE = true;
return new ActiveXObject("Microsoft.XMLHTTP");
}
}
// 에이작스 연결을하는 함수
// searchkey pnu
// code 읍면동, 시군구 구분
// target 시군구, 읍면동 대상 구분
function doCompletion(searchKey, code, target) {
Ajax_Status = 0;
Ajax_inUse = true;
if (searchKey == "") {
return;
}
//코드를 찾는경우
var url = ContextPath +"/common/landCode.do?service=selectLandCodeComboBox&searchKey=" + searchKey + "&code=" + code;
if(code==0 && usecode!=null){
url = url + "&usecode="+usecode;
}
var req = initRequest();
//요청을 보내고 밥는 부분
req.onreadystatechange = function() {
if (req.readyState == 4) {
if (req.status == 200) {
//결과 값을 파싱하는 부분
parseMessages(req.responseText, code, target);
Ajax_Status = 1;
Ajax_inUse = false;
} else if (req.status == 204) {
alert("204");
}
}
};
req.open("post", url, true);
req.send(null);
}
// 데이터가 불안한 경우 롤백한다.
function rollback(){
Ajax_rollback=true;
document.getElementById("selectLandType_").value = 1;
document.getElementById("sggnm").selectedIndex=0;
document.getElementById("umdnm").selectedIndex=0;
document.getElementById("rinm").selectedIndex=0;
document.getElementById("textfield").value = eliminateZero("0000");
document.getElementById("textfield2").value = eliminateZero("0000");
}
// 데이터를 파싱하는 함수
function parseMessages(responseText, code, target) {
document.getElementById("ri").style.visibility = "hidden";
//대상이 시군구
if (code == 0) {
var resultString = "";
document.getElementById("sgg").innerHTML = resultString;
if(target!="" && target!=null){
document.getElementById("sggnm").value=target;
if(document.getElementById("sggnm").value==""){
rollback();
}
}
}
//대상이 읍면동
if (code == 1) {
var resultString = "";
document.getElementById("umd").innerHTML = resultString;
if(target!="" && target!=null){
document.getElementById("umdnm").value=target;
if(document.getElementById("umdnm").value==""){
rollback();
}
}
}
// 대상이 리
if (code == 2) {
var resultString = "";
// if (resultString.length > 140) { // org bug
if (resultString.length > 130) {
document.getElementById("ri").style.visibility = "visible";
document.getElementById("ri").innerHTML = resultString;
if(target!="" && target!=null){
document.getElementById("rinm").value=target;
if(document.getElementById("rinm").value==""){
rollback();
}
}
}
}
}
// pnu를 만들어어서 url을 합해주는 함수
function sumCode(url) {
var landCode = getLandCode();
if(landCode==null){
return 0;
}
url = url + "&landcode=" + landCode;
if(document.getElementById("scale")!=null){
if(nScaleValue==false){
url=url+"&scale=0";
}else if(document.getElementById("scale").value!=null && document.getElementById("scale").value!=""){
url=url+"&scale="+trimByFront(document.getElementById("scale").value);
}else{
url=url+"&scale=0";
}
}else{
url=url+"&scale=0";
}
if(document.getElementById("gyujae")!=null){
url=url+"&gyujae="+document.getElementById("gyujae").checked;
}
if(document.getElementById("label")!=null){
url=url+"&label_type="+document.getElementById("label_type").value;
}
alert(url);
document.getElementById("sggCDname").action=url;
document.getElementById("sggCDname").method="post";
document.getElementById("sggCDname").submit();
document.getElementById("upLoad").style.visibility = "visible";
}
//pnu만 만들어서 넘기는 함수
function sumCode() {
var landCode = getLandCode();
if(landCode==null){
return 0;
}
var url = sumcodeurl + "&landcode=" + landCode;
if(document.getElementById("scale")!=null){
if(nScaleValue==false){
url=url+"&scale=0";
}else if(document.getElementById("scale").value!=null && document.getElementById("scale").value!=""){
url=url+"&scale="+trimByFront(document.getElementById("scale").value);
}else{
url=url+"&scale=0";
}
}else{
url=url+"&scale=0";
}
if(document.getElementById("gyujae")!=null){
url=url+"&gyujae="+document.getElementById("gyujae").checked;
}
if(document.getElementById("label")!=null){
url=url+"&label_type="+document.getElementById("label_type").value;
}
document.getElementById("sggCDname").action=url;
document.getElementById("sggCDname").submit();
document.getElementById("upLoad").style.visibility = "visible";
}
function sumCode_road(sTransLandCd){
var landCode = sTransLandCd;
if(landCode==null){
return 0;
}
var url = sumcodeurl + "&landcode=" + landCode;
if(document.getElementById("scale")!=null){
if(nScaleValue==false){
url=url+"&scale=0";
}else if(document.getElementById("scale").value!=null && document.getElementById("scale").value!=""){
url=url+"&scale="+trimByFront(document.getElementById("scale").value);
}else{
url=url+"&scale=0";
}
}else{
url=url+"&scale=0";
}
if(document.getElementById("gyujae")!=null){
url=url+"&gyujae="+document.getElementById("gyujae").checked;
}
if(document.getElementById("label")!=null){
url=url+"&label_type="+document.getElementById("label_type").value;
}
//alert("url_road = " + url);
document.getElementById("sggCDname").action=url;
document.getElementById("sggCDname").method="post";
document.getElementById("sggCDname").submit();
document.getElementById("upLoad").style.visibility = "visible";
}
//개별공시지가용 url만드는 함수
function sumCode2(url) {
var landCode = getLandCode();
if(landCode==null){
return;
}
url = url + "&landcode=" + landCode;
if(document.getElementById("scale")!=null){
if(document.getElementById("scale").value!=null && document.getElementById("scale").value!=""){
url=url+"&scale="+trimByFront(document.getElementById("scale").value);
}else{
url=url+"&scale=0";
}
}else{
url=url+"&scale=0";
}
if(document.getElementById("gyujae")!=null){
url=url+"&gyujae="+document.getElementById("gyujae").checked;
}
return url;
}
// pnu를 만드는 공통코드
function getLandCode(){
var sgg=document.getElementById("sggnm").value;
//if(sgg==null||sgg==""){
if(sgg==null || sgg=="" || sgg == "시,군,구"){
alert("시군구 선택해 주세요");
return;
}
var umd = document.getElementById("umdnm").value;
//if(umd==null||umd==""){
if(umd==null || umd=="" || umd == "읍,면,동"){
alert("읍면동을 선택해 주세요");
return;
}
if(document.getElementById("ri").style.visibility=="visible"){
var ri= document.getElementById("rinm").value;
//if(ri==null||ri==""){
if(ri==null || ri=="" || ri == "리"){
alert("리를 선택해 주세요");
return;
}
}
if(document.getElementById("textfield").value==null || document.getElementById("textfield").value==""){
alert("본번을 입력해 주세요");
document.getElementById("textfield").focus();
return;
}
var landCode = umd.substring(0, 8);
/*
landCode = landCode + addZeroCode(document.getElementById("rinm").value.substring(8, 10), 2) + document.getElementById("selectLandType").value;
landCode = landCode + addZeroCode(document.getElementById("textfield").value, 4);
landCode = landCode + addZeroCode(document.getElementById("textfield2").value, 4);
*/
landCode = landCode + addZeroCode(document.getElementById("rinm").value.substring(8, 10), 2) + document.getElementById("selectLandType_").value;
landCode = landCode + addZeroCodeByte(document.getElementById("textfield").value, 4);
landCode = landCode + addZeroCodeByte(document.getElementById("textfield2").value, 4);
var client = function(keyword, spliter){
var agent = navigator.userAgent.toLowerCase();
return agent.indexOf(keyword)>-1 ?
parseFloat(agent.split(spliter || keyword).pop().replace(/^[^\w;]+/, '')) :
null;
};
var ie = client('msie') || client('trident', 'rv:');
if(ie && ie > 9){
// ~ 7 8
landCode = encodeURIComponent(landCode);
}else{
landCode = encodeURI(landCode);
}
return landCode;
}
// 에이작스를 이용해서 선택된 지번을 정해주는 함수
function selectedLandCode(landcode) {
Ajax_rollback=false;
if(landcode=="" || landcode==null||landcode=='null'||landcode=='null00000000'){
doCompletion("0000000000", 0, "");
return;
}
landcode = landcode.toString();
COMBOLANDCODE = landcode;
var sgg = landcode.substring(0, 5);
sgg = sgg + "00000";
doCompletion("0000000000", 0, sgg);
/*
if(landcode.length==19){
var text1 = landcode.substring(11, 15);
var text2 = landcode.substring(15, 20);
document.getElementById("textfield").value = eliminateZero(text1.toString());
document.getElementById("textfield2").value = eliminateZero(text2.toString());
}
*/
if(strlen(landcode)==19){
var text1 = "";
var text2 = "";
var bunji = landcode.substring(11);
var j = 0;
for (var i = 0; i < strlen(bunji); i++) {
if (strlen(bunji.substring(j, j+1)) == 2) {
i++;
}
if (i < 4) {
text1 += bunji.substring(j, j+1);
} else {
text2 += bunji.substring(j, j+1);
}
j++;
}
if (text1.length == 4) {
text1 = eliminateZero(text1);
}
if(Number(text2)){
if (text2.length == 4) {
text2 = eliminateZero(text2);
}
}
document.getElementById("textfield").value = text1;
document.getElementById("textfield2").value = text2;
}
var umd = landcode.substring(0, 8);
var ri = landcode.substring(8, 10);
if(umd.substring(5,8)=="000"){
doCompletion(sgg, 1);
return;
}
// 시간 간격을 두어서 실행한다
setTimeout("invokeAjaxFunction(COMBOLANDCODE.toString(), AJAX_SGG_CODE)", 100);
umd = umd + "00";
if (ri != "00") {
setTimeout("invokeAjaxFunction(COMBOLANDCODE.toString(), AJAX_UMD_CODE)", 2000);
}
var im = landcode.substring(10, 11);
document.getElementById("selectLandType_").value=parseInt(im, 10);
if(document.getElementById("selectLandType_").value==null){
document.getElementById("selectLandType_").value=1;
}
}
function selectedRoadCode(landcode){
//alert(landcode);
}
// 연속으로 수행하게 하는 함수
function invokeAjaxFunction(landcode, runcode) {
if (Ajax_inUse == false && Ajax_rollback==false) {
var search;
var target;
if (runcode == AJAX_SGG_CODE) {
search = landcode.substring(0, 5);
search = search + "00000";
target = landcode.substring(0, 8)+"00";
} else if (runcode == AJAX_UMD_CODE) {
search = landcode.substring(0, 8);
search = search + "00";
target=landcode.substring(0, 10);
}
doCompletion(search, runcode, target);
if (runcode == 1) {
setTimeout("selectComboBox(COMBOLANDCODE.toString(), AJAX_SGG_CODE)", 100);
} else {
setTimeout("selectComboBox(COMBOLANDCODE.toString(), AJAX_UMD_CODE)", 100);
}
} else {
if (runcode == 1) {
setTimeout("invokeAjaxFunction(COMBOLANDCODE.toString(), AJAX_SGG_CODE)", 100);
} else {
setTimeout("invokeAjaxFunction(COMBOLANDCODE.toString(), AJAX_UMD_CODE)", 100);
}
}
}
// 콤보박스를 선택하게 만드는 함수
function selectComboBox(landcode, runcode) {
if (Ajax_Status == 1) {
Ajax_Status = 0;
} else {
if (runcode == 1) {
setTimeout("selectComboBox(COMBOLANDCODE.toString(), AJAX_SGG_CODE)", 100);
} else {
setTimeout("selectComboBox(COMBOLANDCODE.toString(), AJAX_UMD_CODE)", 100);
}
}
}
// url로 요청을 보내고 받는 함수
function doCompletionLandUse(url) {
url= sumCode2(url);
var req = initRequest();
req.onreadystatechange = function() {
if (req.readyState == 4) {
if (req.status == 200) {
parseMessagesLandUse(req.responseXML);
} else if (req.status == 204) {
alert("204");
}
}
};
req.open("post", url, true);
req.send(null);
}
// xml을 파싱하는 함수(미사용)
function parseMessagesLandUse(responseXML){
var landuseinfo=responseXML.getElementsByTagName("landuseinfo")[0];
var vlocation=landuseinfo.getElementsByTagName("vlocation")[0].childNodes[0].nodeValue;
var sublocation=landuseinfo.getElementsByTagName("subLocation")[0].childNodes[0].nodeValue;
var landObj=landuseinfo.getElementsByTagName("landObj")[0].childNodes[0].nodeValue;
var area=landuseinfo.getElementsByTagName("area")[0].childNodes[0].nodeValue;
var part1=landuseinfo.getElementsByTagName("part1")[0].childNodes[0].nodeValue;
var part2=landuseinfo.getElementsByTagName("part2")[0].childNodes[0].nodeValue;
var part3=landuseinfo.getElementsByTagName("part3")[0].childNodes[0].nodeValue;
var part4=landuseinfo.getElementsByTagName("part4")[0].childNodes[0].nodeValue;
var part5=landuseinfo.getElementsByTagName("part5")[0].childNodes[0].nodeValue;
var imageFileName=landuseinfo.getElementsByTagName("imageFileName")[0].childNodes[0].nodeValue;
var remarkImageInfoList=landuseinfo.getElementsByTagName("remarkImageInfoList")[0].childNodes[0].nodeValue;
var strMapScale=landuseinfo.getElementsByTagName("strMapScale")[0].childNodes[0].nodeValue;
document.all.vlocation.innerHTML=vlocation;
document.all.subLocation.innerHTML=sublocation;
document.all.landObj.innerHTML=landObj;
document.all.area.innerHTML=area;
document.all.part1.innerHTML=part1;
document.all.part2.innerHTML=part2;
document.all.part3.innerHTML=part3;
document.all.part4.innerHTML=part4;
document.all.part5.innerHTML=part5;
document.all.imageFileName.innerHTML=imageFileName;
document.all.remarkImageInfoList.innerHTML=remarkImageInfoList;
document.all.scale.value=strMapScale;
}