﻿<!--
// mozila에서도 selectNodes/selectSingleNode 사용하기위해 기본 셋팅
// mozXPath [http://km0ti0n.blunted.co.uk/mozxpath/] km0ti0n@gmail.com
// Code licensed under Creative Commons Attribution-ShareAlike License 
// http://creativecommons.org/licenses/by-sa/2.5/
if( document.implementation.hasFeature("XPath", "3.0") )
{
	XMLDocument.prototype.selectNodes = function(cXPathString, xNode)
	{
		if( !xNode ) { xNode = this; } 

			var oNSResolver = this.createNSResolver(this.documentElement)
			var aItems = this.evaluate(cXPathString, xNode, oNSResolver, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)
			var aResult = [];
			for( var i = 0; i < aItems.snapshotLength; i++)
			{
				aResult[i] =  aItems.snapshotItem(i);
			}
  
			return aResult;
	}
	
	XMLDocument.prototype.selectSingleNode = function(cXPathString, xNode)
	{
		if( !xNode ) { xNode = this; } 

			var xItems = this.selectNodes(cXPathString, xNode);
			if( xItems.length > 0 )
			{
				return xItems[0];
			}
			else
			{
				return null;
			}
	}

	Element.prototype.selectNodes = function(cXPathString)
	{
		if(this.ownerDocument.selectNodes)
		{
			return this.ownerDocument.selectNodes(cXPathString, this);
		}
			else{throw "For XML Elements Only";}
	}

	Element.prototype.selectSingleNode = function(cXPathString)
	{ 
		if(this.ownerDocument.selectSingleNode)
		{
			return this.ownerDocument.selectSingleNode(cXPathString, this);
		}
		else{throw "For XML Elements Only";}
	}

}


function getNavigatorType() {
	if ( navigator.appName == "Microsoft Internet Explorer" )
		return 1;  
	else if ( navigator.appName == "Netscape" )
		return 2;	
	else 
		return 0;
}


//xml string 읽기
function loadXML(strXml){
	if(window.ActiveXObject){
//		var xmlParse = new ActiveXObject('Microsoft.XMLDOM');
		var xmlParse = new ActiveXObject("Msxml2.DOMDocument.3.0");

		xmlParse.async = false;
//		xmlParse.preserveWhiteSpace = true;
		xmlParse.loadXML(strXml);

		if (xmlParse.parseError.errorCode != 0) {
		   var myErr = xmlParse.parseError;
//		   alert("You have error " + myErr.reason);
		} else {
			//alert(xmlParse.xml);
		   return xmlParse;
		}



//		return xmlParse.documentElement;
	}else{
		var domParser = new DOMParser();
		var xmlDoc = domParser.parseFromString(strXml, 'application/xml');
		parseError = checkForParseError(xmlDoc);
		if(parseError.errorCode == 0){
			return xmlDoc;
		}else{
			return null;
			alert(parseError.reason);
		}
	}
}

	
function load(file){
//load xml file
// code for IE
	if (window.ActiveXObject)
	{
		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async=false;
		xmlDoc.load(file);
		return xmlDoc;
	}
	// code for Mozilla, etc.
	else if (document.implementation && document.implementation.createDocument)
	{
		xmlDoc= document.implementation.createDocument("","",null);
		xmlDoc.load(file);
//		xmlDoc.onload=getmessage
		return xmlDoc;
	}
	else
	{
		return null;
		alert('Your browser cannot handle this script');
	}
}


function checkForParseError (xmlDocument) {
	var errorNamespace =
	'http://www.mozilla.org/newlayout/xml/parsererror.xml';
	var documentElement = xmlDocument.documentElement;
	var parseError = { errorCode : 0 };
	if (documentElement.nodeName == 'parsererror' && documentElement.namespaceURI == errorNamespace) {
		parseError.errorCode = 1;
		var sourceText =
		documentElement.getElementsByTagNameNS(errorNamespace, 'sourcetext')[0];
		if (sourceText != null) {
			parseError.srcText = sourceText.firstChild.data
		}
		parseError.reason = documentElement.firstChild.data;
	}
	return parseError;
}



//xmlHttp 요청
var xmlRequest;
function initXML(url, functionName, strParam, strAsync){
	if(window.XMLHttpRequest){
		xmlRequest = new XMLHttpRequest();
		xmlRequest.overrideMimeType('text/xml');
	}
	else if(window.ActiveXObject){
		try{
			xmlRequest = new ActiveObject("Msxml2.XMLHTTP");
		}catch(e){
			xmlRequest = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
		var Async = true;
		(strAsync!='undefined') ? ( Async = strAsync ) : (Async = true);
		xmlRequest.open("post",url , Async);
		if (Async){
			xmlRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded")
			xmlRequest.onreadystatechange = eval(functionName);	//function ;
		}
		xmlRequest.send(strParam);
}


function xmlHttp(url, functionName, strParam, strAsync, returnType, strDocName){
	var xmlReq = null;
	if(window.XMLHttpRequest){
		xmlReq =  new XMLHttpRequest();
	}
	else if(window.ActiveXObject){
		try{
			xmlReq = new ActiveObject("Msxml2.XMLHTTP");
		}catch(e){
			xmlReq = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
																//alert("http 생성 완료");

	var Async = true;
	(strAsync!='undefined') ? ( Async = strAsync ) : (Async = true);
	xmlReq.open("post",url , Async);
	if (Async){
		xmlReq.setRequestHeader("Content-Type","application/x-www-form-urlencoded")
		xmlReq.onreadystatechange = function(){
															if(xmlReq.readyState==4)		//완료상태
															{
																if(document.getElementById("search_msg")) document.getElementById("search_msg").style.display = 'none';

																//alert("http 요청 완료");
																if(xmlReq.status == 200)		//정상
																{
//																	alert(strDocName);
//																	alert(xmlReq.responseText);
																		var xmlDoc = null
																		if(document.domain){
																				xmlDoc = loadXML(xmlReq.responseText);
																		}else{
																				xmlDoc = xmlReq.responseXML
																		}

																		if(returnType=='return'){
																			//결과 돌려주기
																			return xmlDoc;
																		}else{
																			//결과 셋팅
																			if(strDocName=='bunji'){
																				xmlDom_bunji = xmlDoc;
																			}else if(strDocName=="apt"){
																				xmlDom_apt = xmlDoc;
																			}else if(strDocName=="gu"){
																				xmlDom = xmlDoc;
																			}
																			if(functionName!='undefined')	 eval(functionName);
																		}
																}else{
																	//alert(xmlReq.status + ' : '+url);
																	var xmlDoc;
																	xmlDoc = xmlReq.status
																	if(functionName!='undefined')	 eval(functionName);
																}
															}else{
																if(document.getElementById("search_msg")){
																	document.getElementById("search_msg").style.left = (screen.width / 2) - 200;
																	document.getElementById("search_msg").style.top = (screen.height / 2) - 200;
																	document.getElementById("search_msg").style.display = '';
																}
															}
														}

	}
	xmlReq.send(strParam);
}

//요청된 xml에서 구/동 값 배열로 정리
function getAddr(xml , loc, si, gu, dong, aptcode, goodCat2_code, mcode){
	this.dataLen = 0;			//data 유무
	if(xml)
	{
		this.text = new Array();
		this.value = new Array();
		this.zipaddr1 = new Array();
		this.zipaddr2 = new Array();
		this.bunjiaddr1 = new Array();
		this.bunjiaddr2 = new Array();
		this.zipseq = new Array();
		this.zipcode = new Array();
		this.mcode = new Array();
		this.extpilji = new Array();
		this.ismount = new Array();
		this.map_x = new Array();
		this.map_y = new Array();
		this.isvisual = new Array();

		if(loc=="gu")
		{
			var xmlGu = xml.selectNodes("serve/si[@name='"+si+"']/gu");
			if(xmlGu)
			{
				for(var i=0; i < xmlGu.length; i++)
				{
					this.text[i] = getNodeValue(xmlGu[i], "@name");
					this.value[i] = xmlGu[i].selectNodes("dong[0]/@mcode").nodeValue;
				}
				this.dataLen = i;
			}
		}
		else if(loc=="dong")
		{
			var xmlDong = xml.selectNodes("serve/si[@name='"+si+"']/gu[@name='"+gu+"']/dong");
			if(xmlDong)
			{
//alert(si +"-"+gu+"-"+xmlDong.length);
				for(var i=0 ; i < xmlDong.length ; i++)
				{
					this.text[i] = getNodeValue(xmlDong[i], "@name");
					this.value[i] = getNodeValue(xmlDong[i] ,"@mcode");
				}
				this.dataLen = i;
			}
		}
		else if(loc=="bunji")
		{
			var xmlBunji = xml.selectNodes("serve/si[@name='"+si+"']/gu[@name='"+gu+"']/dong[@name='"+dong+"']/bunji");
			if(xmlBunji)
			{
//				alert(xmlBunji.length);
				for(var i=0 ; i<xmlBunji.length ; i++)
				{
					this.text[i] = getNodeValue(xmlBunji[i], "../@name") +' '+getNodeValue(xmlBunji[i],"bunji_detail");
					this.value[i] = getNodeValue(xmlBunji[i],"@zipseq");
					this.zipaddr1[i] = si +' '+gu+' '+dong +' '+getNodeValue(xmlBunji[i], "ri");
					this.zipaddr2[i] = '';
					this.bunjiaddr1[i] = '';
					this.bunjiaddr2[i] = '';
					this.zipseq[i] = getNodeValue(xmlBunji[i],"@zipseq");
					this.zipcode[i] = getNodeValue(xmlBunji[i],"@zipcode");
					this.mcode[i] = getNodeValue(xmlBunji[i],"../@mcode");
					this.extpilji[i] = getNodeValue(xmlBunji[i],"extpilji");
					this.ismount[i] = 0;
					this.map_x[i] = getNodeValue(xmlBunji[i],"map_x");
					this.map_y[i] = getNodeValue(xmlBunji[i],"map_y");
					this.isvisual[i] = getNodeValue(xmlBunji[i], "@isvisual");
				}
				this.dataLen = i;
			}
		}
		else if(loc=="danji" || loc=="redevelope" || loc=="house")
		{
			this.aptcode = new Array();
			this.resaletype = new Array(); 
			if(goodCat2_code==8100){
				this.step = new Array();
				this.newbuildcompany = new Array();
				this.newfamilycnt = new Array();
				this.traffic = new Array();
				this.school = new Array();
				this.welfare = new Array();
			}
			var xmlDanji = xml.selectNodes("serve/si[@name='"+si+"']/gu[@name='"+gu+"']/dong[@name='"+dong+"']/danji");
			if(xmlDanji)
			{
				for(var i=0 ; i<xmlDanji.length ; i++)
				{
					this.text[i] = getNodeValue(xmlDanji[i], "danji_name");
					this.value[i] = getNodeValue(xmlDanji[i], "@aptcode");
					this.aptcode[i] = getNodeValue(xmlDanji[i], "@aptcode");
					this.zipaddr1[i] = si +' '+gu+' '+dong +' '+getNodeValue(xmlDanji[i], "ri");	//getNodeValue(xmlDanji[i], "zipaddr1");
					this.zipaddr2[i] = getNodeValue(xmlDanji[i], "zipaddr2");
					this.bunjiaddr1[i] = getNodeValue(xmlDanji[i], "bunji/@b1");
					this.bunjiaddr2[i] = getNodeValue(xmlDanji[i], "bunji/@b2");
					this.zipseq[i] = getNodeValue(xmlDanji[i], "@zipseq");
					this.zipcode[i] = getNodeValue(xmlDanji[i], "@zipcode");
					this.mcode[i] = getNodeValue(xmlDanji[i], "../@mcode");
					this.extpilji[i] = getNodeValue(xmlDanji[i], "extpilji");
					this.ismount[i] = getNodeValue(xmlDanji[i], "bunji/@ismount");
					this.map_x[i] = getNodeValue(xmlDanji[i], "map/@x");
					this.map_y[i] = getNodeValue(xmlDanji[i], "map/@y");
					this.isvisual[i] = getNodeValue(xmlDanji[i], "@isvisual");
					if(goodCat2_code==8100){
						this.step[i] = getNodeValue(xmlDanji[i], "step");
						this.newbuildcompany[i] = getNodeValue(xmlDanji[i], "newbuildcompany");
						this.newfamilycnt[i] = getNodeValue(xmlDanji[i], "newfamilycnt");
						this.traffic[i] = getNodeValue(xmlDanji[i], "traffic");
						this.school[i] = getNodeValue(xmlDanji[i], "school");
						this.welfare[i] = getNodeValue(xmlDanji[i], "welfare");
					}
					
				}
				this.dataLen = i;
			}
		}
		else if(loc=="space")
		{
			this.space = new Array();
			this.spacetype = new Array();
			var xmlSpace = xml.selectNodes("serve/si[@name='"+si+"']/gu[@name='"+gu+"']/dong[@name='"+dong+"']/danji[@aptcode='"+aptcode+"']/space");
			if(xmlSpace)
			{
				for(var i=0 ; i<xmlSpace.length ; i++)
				{
					this.text[i] = getNodeValue(xmlSpace[i],"@space") +' '+getNodeValue(xmlSpace[i],"@spacetype");
					this.value[i] = this.text[i];
					this.space[i] = getNodeValue(xmlSpace[i],"@space");
					this.spacetype[i] = getNodeValue(xmlSpace[i],"@spacetype");				
				}
				this.dataLen = i;
			}
		}
		else if(loc=="apt")
		{
			if(aptcode){
				this.space = new Array();
				this.spacetype = new Array();
				this.homecnt = new Array();
				this.floor = new Array();
				this.madedate = new Array();
				this.company = new Array();
				this.heat = new Array();
				this.fuel = new Array();
				this.enterdate = new Array();
				this.elevator = new Array();
				this.officeteltype = new Array();
				this.sindosi = new Array();
				this.subway_line_code = new Array();
				this.subway_line = new Array();
				this.subway_station_code = new Array();
				this.subway_station = new Array();
				this.subway_method = new Array();
				this.subway_time = new Array();
				this.traffic = new Array();
				this.school = new Array();
				this.welfare = new Array();
				this.leisure = new Array();
				this.etc = new Array();
				this.homecnt = new Array();
				this.realspace = new Array();
				this.room = new Array();
				this.bath = new Array();
				this.fronttype = new Array();
				this.lotprice = new Array();

				if (goodCat2_code==1300){
					this.step = new Array();
					this.newbuildcompany = new Array();
					this.newfamilycnt = new Array();
					this.buildspace = new Array();
					this.landspacelot = new Array();
					this.interest = new Array();
					this.nointerest = new Array();
				}

				var xmlApt = xml.selectNodes("serve/si[@name='"+si+"']/gu[@name='"+gu+"']/dong[@name='"+dong+"']/danji[@aptcode='"+aptcode+"']/space");
				if(xmlApt){
					for(var i=0 ; i < xmlApt.length ; i++ )
					{
						this.space[i] = getNodeValue(xmlApt[i],"@space");
						this.spacetype[i] = getNodeValue(xmlApt[i],"@spacetype");				
						this.homecnt[i] = getNodeValue(xmlApt[i], "../homecnt/@cnt");
						this.floor[i] = getNodeValue(xmlApt[i], "../floor");
						this.madedate[i] = getNodeValue(xmlApt[i], "../madedate");
						this.company[i] = getNodeValue(xmlApt[i], "../company");
						this.heat[i] = getNodeValue(xmlApt[i], "../heat");
						this.fuel[i] = getNodeValue(xmlApt[i], "../fuel");
						this.enterdate[i] = getNodeValue(xmlApt[i], "../enterdate");
						this.elevator[i] = getNodeValue(xmlApt[i], "../elevator");
						this.officeteltype[i] = getNodeValue(xmlApt[i], "../officeteltype");
						this.sindosi[i] = getNodeValue(xmlApt[i], "../sindosi");
						this.subway_line_code[i] = getNodeValue(xmlApt[i], "../subway/line/@code");
						this.subway_line[i] = getNodeValue(xmlApt[i], "../subway/line");
						this.subway_station_code[i] = getNodeValue(xmlApt[i], "../subway/station/@code");
						this.subway_station[i] = getNodeValue(xmlApt[i], "../subway/station");
						this.subway_method[i] = getNodeValue(xmlApt[i], "../subway/method");
						this.subway_time[i] = getNodeValue(xmlApt[i], "../subway/time");
						this.traffic[i] = getNodeValue(xmlApt[i], "../traffic");
						this.school[i] = getNodeValue(xmlApt[i], "../school");
						this.welfare[i] = getNodeValue(xmlApt[i], "../welfare");
						this.leisure[i] = getNodeValue(xmlApt[i], "../leisure");
						this.etc[i]= getNodeValue(xmlApt[i], "../etc");
						this.realspace[i] = getNodeValue(xmlApt[i],"realspace");
						this.room[i] = getNodeValue(xmlApt[i],"room");
						this.bath[i] = getNodeValue(xmlApt[i],"bath");
						this.fronttype[i] = getNodeValue(xmlApt[i],"fronttype");
						this.lotprice[i] = getNodeValue(xmlApt[i],"lotprice");

						if (goodCat2_code==1300){
							this.step[i] = getNodeValue(xmlApt[i], "../step");
							this.newbuildcompany[i] = getNodeValue(xmlApt[i], "../newbuildcompany");
							this.newfamilycnt[i] = getNodeValue(xmlApt[i], "../newfamilycnt");
							this.buildspace[i] = getNodeValue(xmlApt[i], "../buildspace");

							this.landspacelot[i] = getNodeValue(xmlApt[i],"landspacelot");
							this.interest[i] = getNodeValue(xmlApt[i],"interest");
							this.nointerest[i] = getNodeValue(xmlApt[i],"nointerest");
						}
					}
					this.dataLen = i;

				}
			}
		}
	}
}

function getNodeValue(xml, nodeName){
	if(xml){
		try{
		if(xml.selectSingleNode(nodeName).hasChildNodes()){
				return xml.selectSingleNode(nodeName).firstChild.nodeValue;
		}else{
			return '';
		}
	}catch(e){
//		alert(nodeName);
//		alert(e.message);
	}
	}
}



function formData2QueryString(docForm) {

	var strSubmitContent = '';
	var formElem;
	var strLastElemName = '';
	
	for (i = 0; i < docForm.elements.length; i++) {
		
		formElem = docForm.elements[i];
		switch (formElem.type) {
			// Text fields, hidden form elements
			case 'text':
			case 'hidden':
			case 'password':
			case 'textarea':
			case 'select-one':
				strSubmitContent += formElem.name + '=' + escape(formElem.value) + '&'
				break;
				
			// Radio buttons
			case 'radio':
				if (formElem.checked) {
					strSubmitContent += formElem.name + '=' + escape(formElem.value) + '&'
				}
				break;
				
			// Checkboxes
			case 'checkbox':
				if (formElem.checked) {
					// Continuing multiple, same-name checkboxes
					if (formElem.name == strLastElemName) {
						// Strip of end ampersand if there is one
						if (strSubmitContent.lastIndexOf('&') == strSubmitContent.length-1) {
							strSubmitContent = strSubmitContent.substr(0, strSubmitContent.length - 1);
						}
						// Append value as comma-delimited string
						strSubmitContent += ',' + escape(formElem.value);
					}
					else {
						strSubmitContent += formElem.name + '=' + escape(formElem.value);
					}
					strSubmitContent += '&';
					strLastElemName = formElem.name;
				}
				break;
				
		}
	}
	
	// Remove trailing separator
	strSubmitContent = strSubmitContent.substr(0, strSubmitContent.length - 1);
	return strSubmitContent;
}

-->