	
   var RegionCode = function(){
		this.name = null;
		this.code =	null;
		this.fullName = null;
		this.children = null;
   }

   var CongRegionCodeService = 	function(ctype) {
    	  //this.setProxy("/congsoa/clientproxy.jsp", "http://biz.congnamul.com");
	  this.setProxy("/Web/Map/MapProxy.aspx", "http://biz.congnamul.com");
	  //this.setProxy("/Web/Map/rcode.aspx", "http://biz.congnamul.com");
   	  this.serviceURL = '/congsoa/regioncode/';
   	  this.codetype = ctype;
   	  this.bindedSelection = new Array();
   };
   
   
   CongClass.extend(CongRegionCodeService,CongBasicService);
   CongClass.extend(CongRegionCodeService,CongAjaxClass);
    
    
   CongRegionCodeService.onchangeRegionCode = function(evt) {
			var sel = null;
			if(typeof(evt)=='undefined') {
				sel = window.event.srcElement;
			}
			else {
				sel = evt.target;
			}
			var svc = sel.regionService;
			svc.onchangeRegionCode(sel);
			
   }

	CongRegionCodeService.fillSelection = function(obj,sel,pcode,selectedCode,defname,defval) {
	        sel.length = 0;
			if(typeof(defname)!='undefined' && typeof(defval)!='undefined' && defname!=null && defval!=null) {
				if(typeof(defname)=="string") {
					CongRegionCodeService.appendOption(sel,defname,defval);
				} else {
					for(var i=0; i<defname.length; i++) {
						CongRegionCodeService.appendOption(sel,defname[i],defval[i]);
					}
				}
			}
			var rcode = null;
			if(pcode!=null) {
				rcode  = obj.getChildRegionCode(pcode);				
	    			if(rcode!=null && rcode.children != null && rcode.children.length > 0){
	    				for(var idx=0;idx<rcode.children.length;idx++) {
	    					if(typeof(selectedCode)=='undefined') {
	    						CongRegionCodeService.appendOption(sel,rcode.children[idx].name,rcode.children[idx].code);
	    					} else {
	    						CongRegionCodeService.appendOption(sel,rcode.children[idx].name,rcode.children[idx].code,rcode.children[idx].code==selectedCode);
	    					}
	    				}
	    			}	
			}	
	}
	
	CongRegionCodeService.appendOption =  function(sel,rname,rval,selected) {
			sel.length++;
			sel[sel.length-1].text = rname;
			sel[sel.length-1].value = rval;
			if(typeof(selected)=='undefined') {
				selected = false;
			}
			if(selected) {
				sel[sel.length-1].selected = selected;
				sel.selectedIndex = sel.length-1;
			}
	}

   CongRegionCodeService.prototype.codetype = 'CONG';
   CongRegionCodeService.prototype.onRegionCodeChanded = null;
   CongRegionCodeService.prototype.bindedSelection = null;
   CongRegionCodeService.prototype.onchange = null;

   CongRegionCodeService.prototype.getRegionCodeByCoordinates = function (x,y,inputCoordSystem) {
			var url = this.serviceURL+"getRegionCodeByCoordinates.service";
			var query = new CongQueryString();
			query.add("cx",x);
			query.add("cy",y);
			query.add("inputCoordSystem",inputCoordSystem ? inputCoordSystem : "congnamul");
			
//			return this.getResultAttributes(url, query.toString(), ["code", "name", "fullName", "name1", "name2", "name3"]);
			
			var dom =  this.getDom(url,query.toString());
			return this.parseRegionCodeDocument(dom);
	}

	CongRegionCodeService.prototype.parseRegionCodeDocument = function(dom) {
		var parser = new CongDomParserClass(dom);
		var handler = {
			process : function(pObj,depth,nodeName,node) {
				var regionCode = new RegionCode();
                regionCode.code = node.getAttribute("code");
			    regionCode.name = node.getAttribute("name");
			    regionCode.fullName = node.getAttribute("fullName");
			    if(pObj!=null) {
			        if(pObj.children==null) pObj.children= new Array();
			        pObj.children[pObj.children.length] = regionCode;
				}
				return regionCode;
			}
		}
		return parser.parse(handler);

	}
	
	CongRegionCodeService.prototype.getChildRegionCode = function(code) {
	   	var url = this.serviceURL+"getChildRegionCode.service";
			var query = new CongQueryString(true);
			query.add("type",this.codetype);
			query.add("code",code);
			var dom =  this.getDom(url,query.toString());
			return this.parseRegionCodeDocument(dom);
	};
		
    CongRegionCodeService.prototype.bind = function(selid,pcode,selectedCode,defName,defValue) {
        var sel = selid;
        if(typeof(selid)=='string') {
            sel = document.getElementById(selid);
        }
        if(sel!=null) {
            sel.regionService = this;
            sel.regionDepth   = this.bindedSelection.length;
            sel.regionDefaultName   = defName;
            sel.regionDefaultValue  = defValue;
            this.bindedSelection[this.bindedSelection.length] = sel;
            CongRegionCodeService.fillSelection(this,sel,pcode,selectedCode,defName,defValue);
            sel.onchange = CongRegionCodeService.onchangeRegionCode;
        }
        return sel[sel.selectedIndex].value;
    }
    
    CongRegionCodeService.prototype.onchangeRegionCode = function(sel) {
        var depth = sel.regionDepth;
        if(depth<this.bindedSelection.length-1) {
            var cursel = null;
            var presel = sel;
            var pcode  = null;
            var selectedCode = null;
            var defName = null;
            var defValue = null;
            for(var idx=depth;idx<this.bindedSelection.length-1;idx++) {                               
               presel = this.bindedSelection[idx];               
               cursel = this.bindedSelection[idx+1];
               selectedCode = cursel.regionDefaultValue; 
               defName  = cursel.regionDefaultName;
               defValue = cursel.regionDefaultValue;                   
               if(presel[presel.selectedIndex].value==presel.regionDefaultValue) {
                   pcode = null;
               } else {
                  pcode = presel[presel.selectedIndex].value;
               }              
               CongRegionCodeService.fillSelection(this,cursel,pcode,selectedCode,defName,defValue);
            }
        }
        if(this.onchange!=null) {
            this.onchange(sel);
        }        
    }
	
 
  