﻿var xmldocResult = Sarissa.getDomDocument();
var _strNa_Name = "";
var _strLocation1Id = "";
var _strLocation2Id = "";
var _strPgSize = "10000";
var _strPg = "1";
var _strTotalCnt = "0";
var _strList = "";
var _strReq_State = "";
var _strSrcType1 = "";
var _strCi_sort = "";
var _strCi_h_type = "";
var _strNa_code = "";
var Na_code;
var Ci_Name;
var _strIfrm = "";

function changeLocation(_strSrcType, _strReqPg, _strReq_St, _strCi_h_type, _strNa_code, _strCi_sort, _strIfrmType)
{
    var sch_rst_list;    
    var hidLocation2;
    var Na_code1;    
    var Site_Lang;
    var Site_Code;
    var _strNation = "국가선택";
    var _strCity = "도시선택";
    var _strState = "지역선택";
    
    if(_strIfrm != null)
        _strIfrm = _strIfrmType;

    if(_strIfrm != null && _strIfrm == "1")
    {
        if(_strSrcType == "State2" || _strSrcType == "City1" || _strSrcType == "Category" || _strSrcType == "City1_Std")
        {
            _strLocation1Id = parent.document.getElementById("location3");
            _strLocation2Id = parent.document.getElementById("location4");
        }
        
        else if(_strSrcType == "State3" || _strSrcType == "List1" || _strSrcType == "City2_Std" || _strSrcType == "List_No_Location1")
        {
            _strLocation1Id = parent.document.getElementById("location5");
            _strLocation2Id = parent.document.getElementById("location6");
        }
        
        else
        {
            _strLocation1Id = parent.document.getElementById("location1");
            _strLocation2Id = parent.document.getElementById("location2");
        }
        
        sch_rst_list = document.getElementById("sch_rst_list");      
        hidLocation2 = parent.document.getElementById("hidLocation2");        
        Na_code1 = parent.document.getElementById("Na_code1");
        Na_code = parent.document.getElementById("Na_code");
        Site_Lang = parent.document.getElementById("Site_Lang");
        Site_Code = parent.document.getElementById("Site_Code");
        Ci_Name = parent.document.getElementById("ci_name");
    }
    else
    {
        if(_strSrcType == "State2" || _strSrcType == "City1" || _strSrcType == "Category" || _strSrcType == "City1_Std")
        {
            _strLocation1Id = document.getElementById("location3");
            _strLocation2Id = document.getElementById("location4");
        }
        
        else if(_strSrcType == "State3" || _strSrcType == "List1" || _strSrcType == "City2_Std" || _strSrcType == "List_No_Location1")
        {
            _strLocation1Id = document.getElementById("location5");
            _strLocation2Id = document.getElementById("location6");
        }
        
        else
        {
            _strLocation1Id = document.getElementById("location1");
            _strLocation2Id = document.getElementById("location2");
        }
        
        sch_rst_list = document.getElementById("sch_rst_list");
        hidLocation2 = document.getElementById("hidLocation2");
        Na_code1 = document.getElementById("Na_code1");
        Na_code = document.getElementById("Na_code");
        Site_Lang = document.getElementById("Site_Lang");
        Site_Code = document.getElementById("Site_Code");
        Ci_Name = document.getElementById("ci_name");
    }
    
    var srcNa_code = document.getElementById("srcNa_code");
    var ci_src_name = document.getElementById("ci_src_name");
    var sch_rst_loading = document.getElementById("sch_rst_loading");
    
    _strSrcType1 = _strSrcType;

    if(_strReqPg != null)
        _strPg = _strReqPg;
    
    if(_strCi_sort == null)    
        _strCi_sort = "";

    if(srcNa_code != null && srcNa_code.value != "")
        _strNa_code = srcNa_code.value;
        
    else if(Na_code1 != null && _strNa_code == "-1")
        _strNa_code = Na_code1.value;
        
    else if((_strNa_code == null && Na_code != null) || _strNa_code == "0")
        _strNa_code = Na_code.value;
        
    var _strCi_code = _strLocation1Id.value;
    var _strLang = Site_Lang.value;
    var _strSi_code = Site_Code.value;
    
    var _strCi_Name = "";
    _strReq_State = _strReq_St;
    
    if(_strCi_h_type == null)
        _strCi_h_type = "";
        
    if(Site_Lang != null && Site_Lang.value == "en")
    {
        _strNation = "Nation Select";
        _strCity = "City Select";
        _strState = "Area Select";
    }
    else if(Site_Lang != null && Site_Lang.value == "ja")
    {
        _strNation = "国を選択";
        _strCity = "都市を選択";
        _strState = "地域の選択";
    }
    else if(Site_Lang != null && Site_Lang.value == "zh")
    {
        _strNation = "國家選擇";
        _strCity = "城市選擇";
        _strState = "地區選擇";
    }
    else if(Site_Lang != null && Site_Lang.value == "zh-cn")
    {
        _strNation = "国家选择";
        _strCity = "城市选择";
        _strState = "地区选择";
    }
    

    //지역 초기화
    if(_strLocation2Id != null)
    {
        for ( i = _strLocation2Id.length-1 ; i > -1 ; i--) 
        { 
           _strLocation2Id.options[i].value = null; 
           _strLocation2Id.options[i] = null; 
        }

    
        _strLocation2Id[0] = new Option("Loading...",1);
        _strLocation2Id[0].value = "";
        _strLocation2Id.selectedIndex = 0;
    }    

    if(srcNa_code != null)
        _strNa_Name = srcNa_code[srcNa_code.selectedIndex].innerText

    if(_strSrcType == "Category")
    {
        //도시 초기화
        for ( i = _strLocation1Id.length-1 ; i > -1 ; i--) 
        { 
            _strLocation1Id.options[i].value = null; 
	        _strLocation1Id.options[i] = null; 
        } 
        
        //_strLocation1Id[0].value = null;
        //_strLocation1Id[0] = null;        

        _strLocation1Id[0] = new Option("테마선택",1);
        _strLocation1Id[0].value = "";
        _strLocation1Id.selectedIndex = 0;

        BicoTS.Slns.Regen.MiscWeb.Svcs.Prev.If.IntExtIf.WebSvcs.LocationSearchWs.GetSeach_Category(_strNa_code, _strLang, ReturnCategorySearch);
    }
   
    if(_strSrcType == "City_Std" || _strSrcType == "City1_Std" || _strSrcType == "City2_Std")
    {
        if(_strPg == "" || _strPg == "1")
        {
            //도시 초기화
            for ( i = _strLocation1Id.length - 1 ; i > -1 ; i--) 
            { 
                _strLocation1Id.options[i].value = null; 
	            _strLocation1Id.options[i] = null; 
            } 
            
            //_strLocation1Id[0].value = null;
            //_strLocation1Id[0] = null;
            
            _strLocation1Id[0] = new Option(_strCity,1);
            _strLocation1Id[0].value = "";
            _strLocation1Id.selectedIndex = 0;
        }

        BicoTS.Slns.Regen.MiscWeb.Svcs.Prev.If.IntExtIf.WebSvcs.LocationSearchWs.GetCitySeach(_strSi_code, _strNa_code, _strCi_Name, _strLang, _strPg, _strPgSize, _strCi_h_type, _strCi_sort, ReturnCiity_StdCode_Search);
    }
    
    else if(_strSrcType == "City" || _strSrcType == "City1")
    {
        if(_strPg == "" || _strPg == "1")
        {
            //도시 초기화
            for ( i = _strLocation1Id.length - 1 ; i > -1 ; i--) 
            { 
                _strLocation1Id.options[i].value = null; 
	            _strLocation1Id.options[i] = null; 
            } 
            
            //_strLocation1Id[0].value = null;
            //_strLocation1Id[0] = null;
            
            _strLocation1Id[0] = new Option(_strCity,1);
            _strLocation1Id[0].value = "";
            _strLocation1Id.selectedIndex = 0;
        }

        BicoTS.Slns.Regen.MiscWeb.Svcs.Prev.If.IntExtIf.WebSvcs.LocationSearchWs.GetCitySeach(_strSi_code, _strNa_code, _strCi_Name, _strLang, _strPg, _strPgSize, _strCi_h_type, _strCi_sort, ReturnCiitySearch);
    }
    
    else if(_strSrcType == "List_No_Location" || _strSrcType == "List_No_Location1")
    {
        sch_rst_list.style.display = "none";
        sch_rst_loading.style.display = "";
        _strCi_Name = ci_src_name.value;
        BicoTS.Slns.Regen.MiscWeb.Svcs.Prev.If.IntExtIf.WebSvcs.LocationSearchWs.GetCitySeach(_strSi_code, _strNa_code, _strCi_Name, _strLang, _strPg, _strPgSize, _strCi_h_type, _strCi_sort, ReturnCiity_StdCode_Search_List_No_Location);
    }
    
    else if(_strSrcType == "List" || _strSrcType == "List1")
    {
        sch_rst_list.style.display = "none";
        sch_rst_loading.style.display = "";
        _strCi_Name = ci_src_name.value;
        BicoTS.Slns.Regen.MiscWeb.Svcs.Prev.If.IntExtIf.WebSvcs.LocationSearchWs.GetCitySeach(_strSi_code, _strNa_code, _strCi_Name, _strLang, _strPg, _strPgSize, _strCi_h_type, _strCi_sort, ReturnCiity_StdCode_Search_List);
    }
    else if(_strCi_code != "")
        BicoTS.Slns.Regen.MiscWeb.Svcs.Prev.If.IntExtIf.WebSvcs.LocationSearchWs.GetStateSeach(_strCi_code, _strLang, ReturnStateSearch);
    
    if (_strLocation2Id != null && hidLocation2!= null)
    {    
        _strLocation2Id[0] = new Option(hidLocation2.value,1);
        _strLocation2Id[0].value = "";
    }
}

function ReturnCategorySearch(result)
{
	xmldocResult = (new DOMParser()).parseFromString(result.d, "text/xml");
	
    try
    {	
        var selectEl = _strLocation1Id;
        
        for(i=0; i<xmldocResult.selectNodes("//CategoryInfos/CategoryInfo").length; i++)
        {
            // option 노드를 동적으로 생성
            var optionEl = document.createElement("option");
            
            
            optionEl.value = xmldocResult.selectSingleNode("//CategoryInfos/CategoryInfo[" + (i + 1) + "]/category_code").firstChild.nodeValue;
            // 생성된 option 노드에 텍스트 추가
            if(xmldocResult.selectSingleNode("//CategoryInfos/CategoryInfo[" + (i + 1) + "]/category_name").firstChild != null)
                optionEl.appendChild(document.createTextNode(xmldocResult.selectSingleNode("//CategoryInfos/CategoryInfo[" + (i + 1) + "]/category_name").firstChild.nodeValue));
            // select 노드에 option 노드를 자식 노드로 추가
            selectEl.appendChild(optionEl);
        }
    }
    catch(e)
    {
        //alert(e);
    }
}

function ReturnCiitySearch(result)
{
	xmldocResult = (new DOMParser()).parseFromString(result.d, "text/xml");
	
    try
    {	
        var selectEl = _strLocation1Id;
        
        for(i=0; i<xmldocResult.selectNodes("//CityInfos/CityInfo").length; i++)
        {
            // option 노드를 동적으로 생성
            var optionEl = document.createElement("option");
            
            
            optionEl.value = xmldocResult.selectSingleNode("//CityInfos/CityInfo[" + (i + 1) + "]/ci_code").firstChild.nodeValue;
            // 생성된 option 노드에 텍스트 추가
            if(xmldocResult.selectSingleNode("//CityInfos/CityInfo[" + (i + 1) + "]/ci_name").firstChild != null)
                optionEl.appendChild(document.createTextNode(xmldocResult.selectSingleNode("//CityInfos/CityInfo[" + (i + 1) + "]/ci_name").firstChild.nodeValue));
                
            if(xmldocResult.selectSingleNode("//CityInfos/CityInfo[" + (i + 1) + "]/ci_sort").firstChild.nodeValue < 51)
                optionEl.style.background= "#E2DECF";
                
            // select 노드에 option 노드를 자식 노드로 추가
            selectEl.appendChild(optionEl);
        }
        
        if(parseInt(_strTotalCnt) > parseInt(_strPgSize) * parseInt(_strPg))
            changeLocation(_strSrcType1, (parseInt(_strPg) + 1));
            
        else
        {
            _strPg = "1";
            _strTotalCnt = "0";
            _strList = ""; 
            _strSrcType1 = ""; 
            _strCi_h_type = "";  
            _strNa_code = "";
            _strCi_sort = "";        
        }
    }
    catch(e)
    {
        //alert(e);
    }
}

function ReturnCiity_StdCode_Search(result)
{
	xmldocResult = (new DOMParser()).parseFromString(result.d, "text/xml");
	_strTotalCnt = xmldocResult.selectSingleNode("//ReturnMSG").firstChild.nodeValue;
      try
      {	
        var selectEl = _strLocation1Id;
        
        for(i=0; i<xmldocResult.selectNodes("//CityInfos/CityInfo").length; i++)
        {
        
            if(i > 2 && (xmldocResult.selectSingleNode("//CityInfos/CityInfo[" + (i + 1) + "]/ci_sort").firstChild.nodeValue - xmldocResult.selectSingleNode("//CityInfos/CityInfo[" + i + "]/ci_sort").firstChild.nodeValue) >= 50)
            {
                var optionEl_Blank = document.createElement("option");
                optionEl_Blank.appendChild(document.createTextNode(""));
                optionEl_Blank.value = "";
                selectEl.appendChild(optionEl_Blank);
            }
            
            // option 노드를 동적으로 생성
            var optionEl = document.createElement("option");
            
            
            optionEl.value = xmldocResult.selectSingleNode("//CityInfos/CityInfo[" + (i + 1) + "]/ci_std_code").firstChild.nodeValue;
            // 생성된 option 노드에 텍스트 추가
//            if(xmldocResult.selectSingleNode("//CityInfos/CityInfo[" + (i + 1) + "]/ci_name").firstChild != null && xmldocResult.selectSingleNode("//CityInfos/CityInfo[" + (i + 1) + "]/ci_sort").firstChild.nodeValue < 51)
//                optionEl.appendChild(document.createTextNode(xmldocResult.selectSingleNode("//CityInfos/CityInfo[" + (i + 1) + "]/ci_name").firstChild.nodeValue));
//                
//            else if(xmldocResult.selectSingleNode("//CityInfos/CityInfo[" + (i + 1) + "]/ci_name").firstChild != null)
            
            var rstNa_Code = xmldocResult.selectSingleNode("//CityInfos/CityInfo[" + (i + 1) + "]/na_code").firstChild.nodeValue;
                
            if(xmldocResult.selectSingleNode("//CityInfos/CityInfo[" + (i + 1) + "]/ci_sort").firstChild.nodeValue < 51)
            {
                optionEl.appendChild(document.createTextNode(xmldocResult.selectSingleNode("//CityInfos/CityInfo[" + (i + 1) + "]/ci_name").firstChild.nodeValue));
                optionEl.style.background= "#E2DECF";
            }
                
//            else if(rstNa_Code == "3" || rstNa_Code == "5" || rstNa_Code == "8")
//                optionEl.appendChild(document.createTextNode(xmldocResult.selectSingleNode("//CityInfos/CityInfo[" + (i + 1) + "]/ci_name").firstChild.nodeValue));
                
            else
                optionEl.appendChild(document.createTextNode(xmldocResult.selectSingleNode("//CityInfos/CityInfo[" + (i + 1) + "]/ci_en_name").firstChild.nodeValue));
               
            // select 노드에 option 노드를 자식 노드로 추가
            selectEl.appendChild(optionEl);
        }
        if(parseInt(_strTotalCnt) > parseInt(_strPgSize) * parseInt(_strPg))
            changeLocation(_strSrcType1, (parseInt(_strPg) + 1));
            
        else
        {
            _strPg = "1";
            _strTotalCnt = "0";
            _strList = ""; 
            _strSrcType1 = ""; 
            _strCi_h_type = "";  
            _strNa_code = "";
            _strCi_sort = "";        
        }
      }
      catch(e)
      {
          //alert(e);
      }
}

function ReturnCiity_StdCode_Search_List_No_Location(result)
{
	xmldocResult = (new DOMParser()).parseFromString(result.d, "text/xml");
	_strTotalCnt = xmldocResult.selectSingleNode("//ReturnMSG").firstChild.nodeValue;
	
    try
    {
        var selectEl = _strLocation1Id;
        
        if(xmldocResult.selectNodes("//CityInfos/CityInfo").length > 0)
        {            
            for(i=0; i<xmldocResult.selectNodes("//CityInfos/CityInfo").length; i++)
            {                
                var _strCi_std_code = xmldocResult.selectSingleNode("//CityInfos/CityInfo[" + (i + 1) + "]/ci_new_code").firstChild.nodeValue;
                var _strNa_code = xmldocResult.selectSingleNode("//CityInfos/CityInfo[" + (i + 1) + "]/na_code").firstChild.nodeValue;
                
                var _strCi_name_Total = "";
                
                if(xmldocResult.selectSingleNode("//CityInfos/CityInfo[" + (i + 1) + "]/ci_name").firstChild != null)
                    _strCi_name = xmldocResult.selectSingleNode("//CityInfos/CityInfo[" + (i + 1) + "]/ci_name").firstChild.nodeValue;
                    
                _strCi_name_Total = _strCi_name;
                    
                _strCi_name_Total += "(" + xmldocResult.selectSingleNode("//CityInfos/CityInfo[" + (i + 1) + "]/ci_en_name").firstChild.nodeValue + ")";

                if(xmldocResult.selectSingleNode("//CityInfos/CityInfo[" + (i + 1) + "]/ci_sort").firstChild.nodeValue < 51)
                    _strCi_name_Total = "<b>" + _strCi_name_Total +"</b>";
                    
                _strList += "<td><a href='javascript:setCi_Code_Location(\"" + _strCi_std_code + "\", \"" + _strNa_code + "\",\"" + _strSrcType1 + "\",\"" + _strIfrm + "\",\"" + _strCi_name + "\")'>" + _strCi_name_Total + "</a></td>";
                
//                if((i+1) % 2 == 0)
                    _strList += "</tr><tr>"
                
            }
        }
//        else
//        {
//            _strList += "결과 값이 없습니다.";
//        }
        
        if(parseInt(_strTotalCnt) > parseInt(_strPgSize) * (parseInt(_strPg) + 1))
            changeLocation(_strSrcType1, (parseInt(_strPg) + 1), '', _strCi_h_type, _strNa_code, _strCi_sort, _strIfrm);
        
        else
        {
            _strList = "<table><colgroup><col width='50%' /><col width='50%' /></colgroup><tr>" + _strList
            _strList += "</tr></table>";
            
            document.getElementById("sch_rst_list").style.display = "";
            document.getElementById("sch_rst_loading").style.display = "none";
            document.getElementById("sch_rst_list").innerHTML = _strList;
            document.getElementById("sch_rst_nation").innerHTML = "<strong>" + _strNa_Name + "</strong>";
            
            _strPg = "1";
            _strTotalCnt = "0";
            _strList = ""; 
            _strSrcType1 = ""; 
            _strCi_h_type = "";  
            _strNa_code = "";
            _strCi_sort = "";        
        }
    }
    catch(e)
    {
        //alert(e);
    }
}

function ReturnCiity_StdCode_Search_List(result)
{
	xmldocResult = (new DOMParser()).parseFromString(result.d, "text/xml");
	_strTotalCnt = xmldocResult.selectSingleNode("//ReturnMSG").firstChild.nodeValue;
	
    try
    {	
        var selectEl = _strLocation1Id;
        
        if(xmldocResult.selectNodes("//CityInfos/CityInfo").length > 0)
        {
            _strList = "<table><colgroup><col width='50%' /><col width='50%' /></colgroup><tr>"
            
            for(i=0; i<xmldocResult.selectNodes("//CityInfos/CityInfo").length; i++)
            {                
                var _strCi_std_code = xmldocResult.selectSingleNode("//CityInfos/CityInfo[" + (i + 1) + "]/ci_new_code").firstChild.nodeValue;
                var _strCi_name = "";
                
                if(xmldocResult.selectSingleNode("//CityInfos/CityInfo[" + (i + 1) + "]/ci_name").firstChild != null)
                    _strCi_name = xmldocResult.selectSingleNode("//CityInfos/CityInfo[" + (i + 1) + "]/ci_name").firstChild.nodeValue;
                    
                var _strCi_en_name = xmldocResult.selectSingleNode("//CityInfos/CityInfo[" + (i + 1) + "]/ci_en_name").firstChild.nodeValue;

                _strList += "<td><a href='javascript:setCi_Code(\"" + _strCi_std_code + "\", \"" + _strCi_name + "\",\"" + _strIfrm + "\")'>" + _strCi_name + "(" + _strCi_en_name + ")</a></td>";
                
                if((i+1) % 2 == 0)
                    _strList += "</tr><tr>"
                
            }
            _strList += "</tr></table>";
        }
//        else
//        {
//            _strList += "결과 값이 없습니다.";
//        }
        
        
        if(parseInt(_strTotalCnt) > parseInt(_strPgSize) * (parseInt(_strPg) + 1))
            changeLocation("List", (parseInt(_strPg) + 1), '', _strCi_h_type, _strNa_code, _strCi_sort, _strIfrm);
                    
        else
        {
            document.getElementById("sch_rst_list").style.display = "";
            document.getElementById("sch_rst_loading").style.display = "none";
            document.getElementById("sch_rst_list").innerHTML = _strList;
            document.getElementById("sch_rst_nation").innerHTML = "<strong>" + _strNa_Name + "</strong>";
            _strPg = "1";
            _strTotalCnt = "0";
            _strList = "";            
        }
    }
    catch(e)
    {
        //alert(e);
    }
}

function ReturnStateSearch(result)
{
	xmldocResult = (new DOMParser()).parseFromString(result.d, "text/xml");

    try
    {	
        var selectEl = _strLocation2Id;
        
        for(i=0; i<xmldocResult.selectNodes("//StateInfos/StateInfo").length; i++)
        {
            // option 노드를 동적으로 생성
            var optionEl = document.createElement("option");
            
            
            optionEl.value = xmldocResult.selectSingleNode("//StateInfos/StateInfo[" + (i + 1) + "]/st_code").firstChild.nodeValue;
            // 생성된 option 노드에 텍스트 추가
            if(xmldocResult.selectSingleNode("//StateInfos/StateInfo[" + (i + 1) + "]/st_name").firstChild != null)
                optionEl.appendChild(document.createTextNode(xmldocResult.selectSingleNode("//StateInfos/StateInfo[" + (i + 1) + "]/st_name").firstChild.nodeValue));
                
            // select 노드에 option 노드를 자식 노드로 추가
            selectEl.appendChild(optionEl);
            
            if(_strReq_State == xmldocResult.selectSingleNode("//StateInfos/StateInfo[" + (i + 1) + "]/st_code").firstChild.nodeValue)
                _strLocation2Id.selectedIndex = i + 1;            
        } 
        
        if(parseInt(_strTotalCnt) > parseInt(_strPgSize) * (parseInt(_strPg) + 1))
            setTimeout("changeLocation('" + _strSrcType1 + "', '" + (parseInt(_strPg) + 1) + "');", 20);
            
        else
        {
            _strPg = "1";
            _strTotalCnt = "0";
            _strReq_State = "";       
        }
    }
    catch(e)
    {
        //alert(e);
    }
}

function setCi_Code(_strCi_Code, _strCi_Name, _strIfrm)
{
    Ci_Name.value = _strCi_Name;
    _strLocation1Id.value = _strCi_Code;
    
    for(i=0; i < _strLocation1Id.length; i++)
    {
        if(_strLocation1Id[i].value == _strCi_Code)
        {
            _strLocation1Id.selectedIndex = i;
        }
    }
    
    changeLocation("State");
    //setTimeout('replaceSelects();', 300);
    showIfrmSrc();    
}

function setCi_Code_Location(_strCi_Code, _strNa_Code, _strSrcType, _strIfrm, _strCi_name)
{
    Na_code.value = _strNa_Code;
    
    for(i=0; i < Na_code.length; i++)
    {
        if(Na_code[i].value == _strNa_Code)
        {
            Na_code.selectedIndex = i;
        }
    }

    if(_strIfrm == "1")
    {
        if(_strSrcType != null && _strSrcType == "List_No_Location1")
            parent.changeLocation("City2_Std");
            
        else
            parent.changeLocation("City_Std");
            
        setTimeout("parent.document.getElementById('" + _strLocation1Id.id + "').value = '" + _strCi_Code  +"'", 100);
     }
     else
     {
        if(_strSrcType != null && _strSrcType == "List_No_Location1")
            changeLocation("City2_Std","","","","","",_strIfrm);
            
        else
            changeLocation("City_Std","","","","","",_strIfrm);
            
        setTimeout("document.getElementById('" + _strLocation1Id.id + "').value = '" + _strCi_Code  +"'", 100);
     }  
//    
//    for(i=0; i < _strLocation1Id.length; i++)
//    {
//        if(_strLocation1Id[i].value == _strCi_Code)        
//            _strLocation1Id.selectedIndex = i;
//    }  
    
    _strLocation1Id[0] = new Option(_strCi_name,1);
    _strLocation1Id[0].value = _strCi_Code;
    _strLocation1Id.selectedIndex = 0;
    
//    if(_strLocation2Id != null)
//        setTimeout('changeLocation("State","","","","","",' + _strIfrm + ');', 100);
        
    //setTimeout('replaceSelects();', 400);
        
    Na_code = "";
    _strIfrm = "";
        
    setTimeout("showIfrmSrc();", 500);
}

function Show_Src_div()
{
    if(document.getElementById("location_search_popup").style.display == "none")
    {
		document.getElementById("location_search_popup").style.display = "";
		document.getElementById("ci_src_name").value = "";
		document.getElementById("location_search_popup").focus(); 
		if(location.pathname.indexOf("hotel_search_list.aspx") != -1 && navigator.appVersion.indexOf("MSIE 6.0") != -1)
		{
			var absLeft =	document.getElementById("location_search_popup").style.left;
			document.getElementById("location_search_popup").style.left = parseInt(absLeft.replace("px", "")) + 70 + "px";			
			document.getElementById("location_search_popup").style.top = "245px";
		}
    }
        
    else
   { 
        document.getElementById("location_search_popup").style.display = "none";
        if(location.pathname.indexOf("hotel_search_list.aspx") != -1 && navigator.appVersion.indexOf("MSIE 6.0") != -1)
        {
			var absLeft =	document.getElementById("location_search_popup").style.left;
			var absLeft =	document.getElementById("location_search_popup").style.left = parseInt(absLeft.replace("px", "")) - 70 + "px";
		}
   }
}

function chkButton(keynum, btnImg)
{
    if(event.which || event.keyCode)
    {
        if ((event.which == keynum) || (event.keyCode == keynum)) 
        {
            document.getElementById(btnImg).click();
            return false;
        }
    }
    else 
    {
        return true
    }
}

function City_select(ci_std_code, st_code, serch_type, na_code, Id, ci_name)
{
    _strLocation1Id.value = ci_std_code;
    _strReq_State = st_code;
    
    for(i=0; i < Na_code.length; i++)
    {
        if(Na_code[i].value == na_code)
        {
            Na_code.selectedIndex = i;
        }
    }
    
    changeLocation('List');    

    if((na_code == "3" || na_code == "5" || na_code == "8")  && ci_name != null)
        Ci_Name.value = ci_name;
        
    else
        Ci_Name.value = Id.innerText;
        
    Na_code = "";
    _strIfrm = "";
      
    showIfrmSrc();
    
    changeLocation("State", 0, st_code);
    
    setTimeout("set_code('" + st_code + "');", 300);        
}

function set_code(st_code)
{
    for(i=0; i < document.getElementById("location2").length; i++)
    {
        if(document.getElementById("location2")[i].value == st_code)
            document.getElementById("location2").selectedIndex = i;
    }
}

function type_search(Na_code)
{
    var _strSrcType = document.getElementById("ddlsrc_type").value;

    if(_strSrcType == "Category")
    {
        document.getElementById("location3").style.display = "";
        
        if(document.getElementById("location4") != null)
            document.getElementById("location4").style.display = "none";       
    }
    else if(_strSrcType == "Pakage")
    {
        for ( i = document.getElementById("location3").length-6 ; i > -1 ; i--) 
        { 
           document.getElementById("location3").options[i].value = null; 
           document.getElementById("location3").options[i] = null; 
        }

    
        document.getElementById("location3")[0] = new Option("서울",1);
        document.getElementById("location3")[0].value = "112";
        document.getElementById("location3")[1] = new Option("경기",1);
        document.getElementById("location3")[1].value = "305";
        document.getElementById("location3")[2] = new Option("인천",1);
        document.getElementById("location3")[2].value = "307";
        document.getElementById("location3")[3] = new Option("부산",1);
        document.getElementById("location3")[3].value = "314";
        document.getElementById("location3")[4] = new Option("강원",1);
        document.getElementById("location3")[4].value = "313";
        document.getElementById("location3")[5] = new Option("제주",1);
        document.getElementById("location3")[5].value = "119";
        document.getElementById("location3").selectedIndex = 0;
        
        if(document.getElementById("location4") != null)    
            document.getElementById("location4").style.display = "none";  
            
        if(document.getElementById("Na_code1") != null)    
            document.getElementById("Na_code1").style.display = "none";       
    }
    else if(_strSrcType == "City1")
    {
        document.getElementById("location3").style.display = "";    
        
        if(document.getElementById("location4") != null)
            document.getElementById("location4").style.display = "";    
            
        if(document.getElementById("Na_code1") != null)    
            document.getElementById("Na_code1").style.display = "";       
    }
    

    if(_strSrcType != "Pakage")
        changeLocation(_strSrcType, "", "", "", Na_code);
  
    //setTimeout('replaceSelects();', 300);
}

function showIfrmSrc(Type)
{
    if(parent.document.getElementById("divWorldSrc") != null)
    {
        if(parent.document.getElementById("divWorldSrc").style.display == "none")
        {
            parent.document.getElementById("ifrmsrc").src = "../popup/world_search.aspx?type=" + Type;
            parent.document.getElementById("divWorldSrc").style.display = "";
        }
        
        else
            parent.document.getElementById("divWorldSrc").style.display = "none";
    }
    else
    {
        if(document.getElementById("divWorldSrc").style.display == "none")
        {
            document.getElementById("ifrmsrc").src = "../popup/world_search.aspx?type=" + Type;
            document.getElementById("divWorldSrc").style.display = "";
        }
        
        else
            parent.document.getElementById("divWorldSrc").style.display = "none";
    }
    
    

}
