<!--

function LocalSearchOperation(a)//mapClient
{   this.base=MapOperation;
	this.base();
	var _mapClient = a;
	var cEngineURL,dEngineURL;
	var _mapServiceName = "local.MapSearch";//LocalSearchXMLEX
	var _submitType;
	this._Data;
	this.what='';
	this.where='';
	this.objectLayer='All';
	this.radius='';
	this.classSort='';
	this.level='';
	this.classFlag='';
	this.boundFlag='';
	var _rectWhat;
	var _rectResultOrder;
	var _rectQueryflag;
	var _clickSearch;
	this.minRadius=50;
	this.maxRadius=50000;
	this.m=5;
	this.classSearch=function(a,b,c)
	{
		_mapClient.selectTool("DRAWPOINT" , this);
		_mapClient.setCursor("hand","click search");
		_clickSearch=true;
		if (a) this.minRadius=a;
		if (b) this.maxRadius=b;
		if (c) this.m=c;
	}
	this.selectRectTool=function(a,b,c)
	{
		try
		{
			//var a=_mapClient;
			_mapClient.selectTool("DRAWRECT",this);
			_mapClient.setCursor("crosshair","Range search");
			_submitType="drawrect";
			_clickSearch=false;
			
			_rectWhat=this.voidStringParam(a,'');
			_rectResultOrder=this.voidStringParam(b,'10,1');
			_rectQueryflag=this.voidStringParam(c,'1');
			
		}
		catch(e)
		{
			e.description = this.getClassName()+".selectRectTool()::"+e.description;
			throw(e);
		}
	};
	this.mapWindowCallback=function( a,b )
	{
		try
		{
			//alert(b)
			var c=_mapClient;
			var d=c.map.zoomLevel;
			var e=c.map.spec.numZoomLevels;
			
			var f=[],g=[];
			var i;
			var m,n;
			for(i=0;i<b.length;i++)
			{
				m=c.map.divToBitmapCoordinate(b[i].x,b[i].y);
				f.push(m);
				n=c.map.spec.getLatLng(m.x,m.y,d);
				g.push(n)
			}
			if (_clickSearch)
			{
				l=c.map.spec.getLatLng(f[0].x,f[0].y,d);
				c.selectTool("PAN");
				var mpp=c.map.spec.getMeterPerPixel(c.getLevelIndex()).x*80/this.m;
				if (mpp>this.maxRadius) mpp=this.maxRadius;
				if (mpp<this.minRadius) mpp=this.minRadius;
				//alert(mpp)
				var data=''+
				'<Data id="classSearchData">'+
				'	<Feature caption="Range object" id="classSearchFeature" type="R">'+
				'		<Points>'+l.x+','+l.y+'</Points>'+
				'		<Bounds minx="'+(l.x-mpp)+'" miny="'+(l.y-mpp)+'" maxx="'+(l.x+mpp)+'" maxy="'+(l.y+mpp)+'"/>'+
				'		<Style id="R01"/>'+
				'		<Label on="false" style="Label01"/>'+
				'		<Detail>'+
					'			<!--  -->'+
				'		</Detail>'+
				'	</Feature>'+
				'</Data>';
				
				var fe=c.getFeatureById("classSearchFeature");
				if (fe)
				{
					c.map.removeFeature(fe);
				}
				c.map.loadDataXML(data);
				var tt=l.x+' '+l.y
				_clickSearch=false;
				Event.trigger(this,"clickDrawEnd",tt,mpp,d);
				return;
			}
			var bounds = new Bounds();
			var sortns = new Array();
			var nodes = new Array();
			var fnodes = new Array();
			var featureDesc = new FeatureDesc();
			var feature;
			if(g.length<1)
			{
				return;
			}
			if(a=="DRAWOVAL")
			{
				var x=g[1].x-g[0].x;
				var y=g[1].y-g[0].y;
				var r=parseInt(Math.sqrt(x*x+y*y));
				r=(r==0)?200:r;
				featureDesc.setRadius(r);
				bounds.minX = g[0].x-r;
				bounds.minY = g[0].y-r;
				bounds.maxX = g[0].x+r;
				bounds.maxY = g[0].y+r;
				nodes[0]=g[0];
				fnodes[0]=g[0]
			}
			else
			{
				sortns=[].concat(g);
				sortns.sort(function(a,b){return a.x-b.x});
				bounds.minX = sortns[0].x;
				bounds.maxX = sortns[sortns.length-1].x;
				sortns.sort(function(a,b){return a.y-b.y});
				bounds.minY = sortns[0].y;
				bounds.maxY = sortns[sortns.length-1].y;
				if(a=="DRAWRECT")
				{
					nodes[0]=new Point(bounds.minX,bounds.minY);
					nodes[1]=new Point(bounds.minX,bounds.maxY);
					nodes[2]=new Point(bounds.maxX,bounds.maxY);
					nodes[3]=new Point(bounds.maxX,bounds.minY);

					fnodes[0]=new Point(bounds.minX,bounds.minY);
					fnodes[1]=new Point(bounds.maxX,bounds.maxY)
				}
				else
				{
					nodes=g;
					fnodes=g
				}
			}
			var style=StyleLib.getStyleById("R_02");
			if ((bounds.maxX-bounds.minX<=0)&&(bounds.maxY-bounds.minY<=0))
			return;
			feature = new FeatureNode("QueryArea"," ","R",nodes,bounds,style,null,null,[nodes.length]);
			c.map.setQueryArea(feature);
			featureDesc.setFeatureDescAsCoordType( fnodes,"LL" );
			
			Event.trigger(this,"drawend",a,bounds);
			Event.trigger(this,"mapwindowcallback",featureDesc)
		}
		catch(e)
		{
			e.description = this.getClassName()+".mapWindowCallback()::"+e.description;
			throw(e);
		}
	};
	this.submit=function(featureDesc,what,resultOrder,queryFlag,objectLayers,nearOrder,classSort,level,classFlag,boundFlag)
	{
		try
		{	var variant;
			var mq;
			if(resultOrder==null) resultOrder = "10";
			queryFlag=queryFlag?queryFlag:3;
			if( objectLayers==null||objectLayers=="" )
			{
				objectLayers = "ALL";
			}
			variant = new LocalSearchVariant();
			variant.setSPInfo( _mapClient.getSpInfo() );
			variant.setUserInfo( _mapClient.getUserInfo() );
			variant.setAPPID( _mapClient.getAppId() );			
			variant.setFeatureDesc( featureDesc );
			if (what != null && what != "" && what != undefined)
			{
				variant.setWhat(what);
			}
			variant.setObjectLayers(objectLayers);
			variant.setResultOrder( resultOrder );
			variant.setQueryFlag( queryFlag );
			if (classSort)
			{
				variant.setClassSort( classSort );
				this.classSort=classSort;
			}
			if (level)
			{
				variant.setLevel(level);
				this.level=level;
			}
			if (classFlag)
			{
				variant.setClassFlag(classFlag);
				this.classFlag=classFlag;
			}
			if (boundFlag)
			{
				variant.setBoundFlag(boundFlag);
				this.boundFlag=boundFlag;
			}
			mq = new MapRequest(_mapServiceName,variant);
			_mapClient.submit(mq, this,false,this.engine);
			Event.trigger(this,"submit",featureDesc, objectLayers, what,  resultOrder);
		}
		catch(e)
		{
			e.description = this.getClassName()+".submit()::"+e.description;
			throw(e);
		}
	};
	this.nameTypeSubmit=function(a,b,c,d,e,f,g,h,i)
	{	var featureDesc;
		var tmpwhat;
		var tmpwhere;
		var resultOrder,queryFlag,objectLayers,nearOrder,radius,classSort,classFlag;
		var layerNames = new Array();
		try
		{
			if(typeof(a)=="string")
			{
				tmpwhat=a.replace(/[#%&'",;:=!]/g,'');
			}
			else
			{
				return;
			}
			tmpwhere=this.voidStringParam(b,'ALL');
			
			resultOrder=this.voidStringParam(c,'10,1');
			queryFlag=this.voidStringParam(d,'1');
			objectLayers=this.voidStringParam(e,'ALL');
			radius=this.voidStringParam(f,'');
			nearOrder=this.voidStringParam(g,'6');
			classSort=this.voidStringParam(h,'');
			classFlag=this.voidStringParam(i,'');
			layerNames[0] = "ALL";
			this.what=tmpwhat;
			this.where=tmpwhere;
			this.radius=radius;
			this.classFlag=classFlag;
			featureDesc = new FeatureDesc();
			featureDesc.setFeatureDescAsNameType(tmpwhere,layerNames);
			featureDesc.setRadius(radius)
			this.featureDesc = featureDesc;
			this.objectLayer = objectLayers;
			this.submit(featureDesc,tmpwhat,resultOrder,queryFlag,objectLayers,nearOrder,classSort,'',classFlag);
			_submitType="NAME";
		}
		catch(e)
		{
			e.description = this.getClassName()+".nameTypeSubmit()::"+e.description;
			alert(e.description);
		}
	};
	this.uidTypeSubmit=function(a,b,c,d,e,f,g,h,i)
	{
		var featureDesc;
		var tmpwhat;
		var tmpuid;
		var resultOrder,queryFlag,objectLayers,nearOrder,radius,classSort,classFlag;
		var layerNames = new Array();
		try
		{
			if(typeof(a)=="string")
			{
				tmpwhat=a.replace(/[#%&'",;:=!]/g,'');
			}
			else
			{
				return;
			}
			
			tmpuid=this.voidStringParam(b,'ALL');
			resultOrder=this.voidStringParam(c,'10,1');
			queryFlag=this.voidStringParam(d,'1');
			objectLayers=this.voidStringParam(e,'ALL');
			radius=this.voidStringParam(f,'2000');
			classSort=this.voidStringParam(h,'');
			classFlag=this.voidStringParam(i,'');
			layerNames[0] = "ALL";
			this.what=tmpwhat;
			this.where=tmpuid;
			this.radius=radius;
			this.classFlag=classFlag;
			featureDesc = new FeatureDesc();
			featureDesc.setFeatureDescAsUidType([tmpuid]);
			featureDesc.setRadius(radius);
			this.featureDesc = featureDesc;
			this.objectLayer = objectLayers;
			this.submit(featureDesc,tmpwhat,resultOrder,queryFlag,objectLayers,nearOrder,classSort,'',classFlag);
			_submitType="UID";
		}
		catch(e)
		{
			e.description = this.getClassName()+".uidTypeSubmit()::"+e.description;
			alert(e.description);
		}
	};
	this.eyeshotTypeSubmit = function (a,b,c,d,e,f,g,h,i)
	{
		var featureDesc;
		var tmpwhat;
		var tmpuid;
		var resultOrder,queryFlag,objectLayers,nearOrder,radius,classSort,classFlag,boundFlag;
		var layerNames = new Array();
		var fnodes = new Array();
		try
		{
			var nodes = new Array();
			var fnodes = new Array();
			
			if(typeof(a)=="string")
			{
				tmpwhat=a.replace(/[#%&'",;:=!]/g,'');
			}
			else
			{
				return;
			}
			
			resultOrder=this.voidStringParam(c,'10,1');
			queryFlag=this.voidStringParam(d,'1');
			objectLayers=this.voidStringParam(e,'ALL');
			radius=this.voidStringParam(f,'500')
			classSort=this.voidStringParam(g,'');
			classFlag=this.voidStringParam(h,'');
			boundFlag=this.voidStringParam(i,'');
			layerNames[0] = "ALL";
			
			featureDesc = new FeatureDesc();
			if (b == undefined || b== '')
			{
				var bounds = _mapClient.getBounds();
				fnodes.push(new Point(bounds.minX,bounds.minY));
				fnodes.push(new Point(bounds.maxX,bounds.maxY));
				_submitType="EYESHOT";
			}
			else if (typeof(b)=="object")
			{   fnodes.push(new Point(b.minX,b.minY));
				fnodes.push(new Point(b.maxX,b.maxY));
				_submitType="COORD";
			}
			this.what=tmpwhat;
			var c=new Bounds();
			c.minX=fnodes[0].x;
			c.minY=fnodes[0].y
			if (fnodes[1])
			{
				c.maxX=fnodes[1].x;
				c.maxY=fnodes[1].y
			}
			else
			{
				c.maxX=fnodes[0].x;
				c.maxY=fnodes[0].y
			}
			this.where=c;
			featureDesc.setFeatureDescAsCoordType( fnodes,"LL" );
			featureDesc.setRadius(radius);
			
			this.featureDesc = featureDesc;
			this.objectLayer = objectLayers;
			
			this.submit(featureDesc,tmpwhat,resultOrder,queryFlag,objectLayers,nearOrder,classSort,'',classFlag,boundFlag);
			
		}
		catch(e)
		{
			e.description = this.getClassName()+".eyeshotTypeSubmit()::"+e.description;
			alert(e.description);
		}
	}
    this.xyTypeSubmit = function (a,b,c,d,e,f,g,h,i,j)
	{
		var featureDesc;
		var tmpwhat;
		var resultOrder,queryFlag,objectLayers,nearOrder,radius,classSort,level,classFlag,classSearch;
		var layerNames = new Array();
		var fnodes = new Array();
		try
		{   var nodes = new Array();
			var fnodes = new Array();
			if(typeof(a)=="string")
			{
				tmpwhat=a.replace(/[#%&'",;:=!]/g,'');
			}
			if (b!= undefined && b!= '')
			{
				fnodes.push(new Point(b.split(' ')[0],b.split(' ')[1]));
			}
			resultOrder=this.voidStringParam(c,'10,1');
			queryFlag=this.voidStringParam(d,'1');
			objectLayers=this.voidStringParam(e,'ALL');
			radius=this.voidStringParam(f,'500')
			classSort=this.voidStringParam(g,'');
			level=this.voidStringParam(h,'');
			classFlag=this.voidStringParam(i,'');
			classSearch=this.voidStringParam(j,'');
			featureDesc = new FeatureDesc();
			featureDesc.setFeatureDescAsCoordType( fnodes,"LL" );
			featureDesc.setRadius(radius);
			this.what=tmpwhat;
			this.where=fnodes[0].x+" "+fnodes[0].y;
			this.radius=radius;
			this.classFlag=classFlag;
			this.objectLayer = objectLayers;
			this.submit(featureDesc,tmpwhat,resultOrder,queryFlag,objectLayers,nearOrder,classSort,level,classFlag);
			if (level!="")
			{_submitType="classLevel";}
			else if(classSearch)
			{_submitType="classSearch";}
			else{_submitType="XY";}
		}
		catch(e)
		{
			e.description = this.getClassName()+".eyeshotTypeSubmit()::"+e.description;
			alert(e.description);
		}
	}
	
	
	this.voidStringParam=function(a,b)
	{
		var tmp;
		tmp = (a!=""&&a!=undefined&&a!=null)?a:b;
		return tmp;
	}

	this.mapResultCallback=function(a)//mapResultFactory
	{
		try
		{
			var errorMessage = a.getResult("ErrorMessage");
			if (errorMessage != "")
			{
				Event.trigger(this,"errorMessage",errorMessage,_submitType);
				return;
			}
			var aa = a.getResult("Wmsxml");
			if (aa!="")
			{
				aa=(aa.indexOf("<?xml version=")>-1?'':'<?xml version="1.0" encoding="GB2312"?>')+aa;
				var dom = _getDomFromString(aa);
				
				var Response = dom.selectSingleNode("//Response");
				var allcount = Response.getAttribute("allcount")
				if (allcount)
				{
					Event.trigger(this,"allcount",allcount)
				}
				var queryflag =  parseInt(Response.getAttribute("queryflag"));
				this._Data=dom;
				
				if (queryflag==1)
				{
					var redom="";
					var Guide = dom.selectSingleNode("//Guide");
					if (Guide)
					{
						Event.trigger(this,"guide",Guide.childNodes[0]);
					}
					var Match = dom.selectSingleNode("//Match");
					if (Match)
					{
						if (Match.childNodes.length > 0)
						{
							redom+=Match.xml
						}
					}
					var Recommends = dom.selectSingleNode("//Recommends");
					if (Recommends)
					{
						if (Recommends.childNodes.length > 0)
						{
							redom+=Recommends.xml;
						}
					}
					if (redom)
					{
						Event.trigger(this,"recommends",_getDomFromString(redom));
					}

					var Data = dom.selectSingleNode("//Data");
					
					var cNum=Data.childNodes.length
					if (cNum == 0 )
					{	Event.trigger(this,"errorMessage","Search result is null",_submitType)
						return;
					}
				}
				switch (queryflag)
				{
					case 3:
					{
						this.throwDom(dom,3);
						break;
					}
					
					case 2:
					{
						this.throwDom(dom,2);
						break;
					}
					case 1:
					{
						this.throwDom(dom,1);
						break;
					}
					default:
					{
						this.throwDom(dom,queryflag);
						break;
					}
				}
			}
			else{Event.trigger(this,"errorMessage","System error")}
		}
		catch(e)
		{
			e.description = this.getClassName()+".mapResultCallback()::"+e.description;
			throw(e);
		}
	};
	this.throwDom = function(a,b)
	{
		Event.trigger(this,"dom",a,_submitType,b)
		return;
	}
	this.transformNode=function(a,b,c)
	{
		try
		{
			if (typeof(a)=="string")
			{
				a=_getDomFromString(a);
			}
			g=StyleLib.baseURL+b;
			h=XmlStyleSheet.getCached(g);
			if(!h)
			{
				h=XmlStyleSheet.create(_getDomFromFile(g));
				XmlStyleSheet.cache(g,h)
			}
			window.setTimeout(function(){h.transformToHTML(a,c)},1)
		}
		catch(e)
		{
			e.description = this.getClassName()+".transformNode()::"+e.description;
			throw(e);
		}
	}
	this.getLocalSearchData=function()
	{
		return this._Data;
	}
}
function LocalSearchVariant()
{   this.base=WmspVariant;
	this.base();
	this.featureDescType= "MUST_BE_VALIDATED";
	this.featureDesc	= "MUST_BE_VALIDATED";
	this.objectLayers	= "MUST_BE_VALIDATED";
	this.objectName		= "OPTIONAL";
	this.resultOrder	= "OPTIONAL";
	this.nearOrder		= "OPTIONAL";
	this.what			= "OPTIONAL";
	this.queryFlag		= "OPTIONAL";
	this.classSort		= "OPTIONAL";
	this.level			= "OPTIONAL";
	this.classFlag		= "OPTIONAL";
	this.boundFlag		= "OPTIONAL";

	this.setFeatureDesc=function(a)	
	{
		this.featureDescType = a.getFeatureDescType();
		this.featureDesc = a.getFeatureDesc()
	};
	this.setResultOrder=function(a)
	{
		this.verifyString(a,this.getClassName()+".setResultOrder()");
		this.resultOrder = a.toString();

	};
	this.setObjectLayers=function(a)	
	{
		this.objectLayers = a.toString();
	};
	this.setObjectName=function(a)	
	{
		if(a!=null||a!="")
			this.objectName = a;
	}
	
	this.setWhat=function(a)
	{
		this.what = a.toString();
	};
	this.setQueryFlag=function(a)
	{
		this.queryFlag = a;
	}
	this.setClassSort=function(a)
	{
		this.classSort = a;
	}
	this.setLevel=function(a)
	{
		this.level = a;
	}
	this.setClassFlag=function(a)
	{
		this.classFlag = a;
	}
	this.setBoundFlag=function(a)
	{
		this.boundFlag = a;
	}
	
}

//-->