var searchTolerance=0.01;
var queryStartRecord=0;
if (imsQueryURL=="")
	imsQueryURL= imsURL + "&CustomService=Query";
var canQuery=true;
var newSelectCount=0;
var last_property_str="";
var kx="";
var ly="";

function identify(e) {
	var theX = mouseX;
	var theY = mouseY;
	f71(theX,theY);
	kx=mapX;
	ky=mapY;

	searchTolerance = (xDistance/iWidth) * pixelTolerance;
	var tempWest = mapX - searchTolerance;
	var tempNorth = mapY + searchTolerance;
	var tempEast = mapX + searchTolerance;
	var tempSouth = mapY - searchTolerance;
	var identifyEnvelope = "maxy='" + tempNorth + "' maxx='" + tempEast + "' miny='" + tempSouth + "' minx='" + tempWest+"'";

	curland=false;
	for (var i=0;i<layerCount;i++) {
		  if ((lyrNm[i]=="Cadastre")|| (lyrNm[i]=="Cad Areas and Plan Text")){  
			  if(i==actLyrIndex) {
				  curland=true;
	          }
		  }
	}

	reportEnvelope = identifyEnvelope;
	reportMode = 2;
    if(curland){
       //we need to set the active layer to another layer because tha cadastre is pointing
	   //to a line layer.  We need to goto a poly layer eg:"Cad Areas and Plan Text"  which is 
	   // a hidden layer in the TOC.  This will happen in the asp
		for (var i=0;i<layerCount;i++) {
			  if (lyrNm[i]=="Cad Areas and Plan Text") {
				ActLyr=lyrId[i];
				ActLyrTyp=lyrTyp[i];
				actLyrIndex=i;
				selectType=ActLyrTyp;  
			 }
	    }
        selectCount=0; 
		selectShape="<POLYGON><RING>";
        selectShape=selectShape+"<POINT x='"+tempWest+"' y='"+tempSouth+"' />";
        selectShape=selectShape+"<POINT x='"+tempWest+"' y='"+tempNorth+"' />";    
        selectShape=selectShape+"<POINT x='"+tempEast+"' y='"+tempNorth+"' />";    
        selectShape=selectShape+"<POINT x='"+tempEast+"' y='"+tempSouth+"' />";    
        selectShape=selectShape+"<POINT x='"+tempWest+"' y='"+tempSouth+"' />";
        selectShape=selectShape+'</RING></POLYGON>';    
	    sendToServerASP(66);  
    }else{
       //note for everything but cadastre, we have a new process to return some defined fields
	   // and then if the user wants, we go and get everything later....still needs more 
	   // definition at this stage
       selectCount=0;  
	   writeFeatureReport(); 
    }
}

function f42() { //checkSelected
	var isOk = false;
	if (selectCount>0) isOk = true;
	return isOk;
}

function getidmap() { 
	var xdist=Math.abs(zright-zleft);
	searchTolerance = (xDistance/iWidth) * pixelTolerance;
	var tempLeft = kx-searchTolerance;
	var tempTop = ky-searchTolerance;
	var tempRight = kx+searchTolerance;
	var tempBottom = ky+searchTolerance;
	queryStartRecord=1;
	searchTolerance = (xDistance/iWidth) * pixelTolerance;
	drawSelectBoundary=true;
	selectionMode=2;
	selectType=ActLyrTyp;
	for (var i=0;i<layerCount;i++) {
	  if (lyrNm[i]=="Cad Areas and Plan Text") {
			ActLyr=lyrId[i];
			ActLyrTyp=lyrTyp[i];
			actLyrIndex=i;
			selectType=ActLyrTyp;   
	  }
	}
	selectEnvelope="maxy='" + tempTop + "' maxx='" + tempRight + "' miny='" + tempBottom + "' minx='" + tempLeft + "'";
	selectCount=0; 
	sendToServerASP(6);  
}

function display_geac_lotplan(allstr) {
  var singlequote="\'";
  if(allstr[0]==" "){
	  alert("Property from GEAC NOT found....");
  }else{
    setQueryString="";
	props="";  
	var first=true;
    for(i=0;i<allstr.length;i++){
      var tmparray=allstr[i].split("++");
      var lstr=leftTrim(rightTrim(tmparray[0])).toUpperCase();
      var pstr=leftTrim(rightTrim(tmparray[1])).toUpperCase()+leftTrim(rightTrim(tmparray[2])).toUpperCase();
	  if(first){
         setQueryString ="MRCSDE.PROPERTY.MKYCADAREA.PLAN_TYPE = "+singlequote+ pstr+singlequote +" AND MRCSDE.PROPERTY.MKYCADAREA.LOT = "+singlequote+lstr+singlequote ;
         first=false;
		 props=pstr+"/"+lstr+"'";
	  }else{
         setQueryString =setQueryString+" OR (MRCSDE.PROPERTY.MKYCADAREA.PLAN_TYPE = "+singlequote+ pstr+singlequote +" AND MRCSDE.PROPERTY.MKYCADAREA.LOT = "+singlequote+lstr+singlequote+") " ;
		 props=props+" OR  a.ParcelRef='"+pstr+"/"+lstr+"'";

	  }
    }
	selectCount=allstr.length;
	last_property_str=props;
	parent.ResultsFrame.location="http://www.mimapsmackay.com.au/website/"+app_dir+"/asp/get_property1.asp?property="+props;
  }
}

function rightTrim(sString) {
	while (sString.substring(sString.length-1, sString.length) == ' '){
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}
function leftTrim(sString) {
	while (sString.substring(0, 1) == ' '){
		sString = sString.substring(1,sString.length);
	}
	return sString;
}

function ipa(e) {

	var theX = mouseX;
	var theY = mouseY;
	f71(theX,theY);
	kx=mapX;
	ky=mapY;

	searchTolerance = (xDistance/iWidth) * pixelTolerance;
	var tempWest = mapX - searchTolerance;
	var tempNorth = mapY + searchTolerance;
	var tempEast = mapX + searchTolerance;
	var tempSouth = mapY - searchTolerance;
	var identifyEnvelope = "maxy='" + tempNorth + "' maxx='" + tempEast + "' miny='" + tempSouth + "' minx='" + tempWest+"'";

	reportEnvelope = identifyEnvelope;
	reportMode = 2;
//ppunter 20 march 2006 next lines commented out
//	for (var i=0;i<layerCount;i++) {
//		  if (lyrNm[i]=="Cad Areas and Plan Text") {
//			ActLyr=lyrId[i];
//			ActLyrTyp=lyrTyp[i];
//			actLyrIndex=i;
//			selectType=ActLyrTyp;  
//		 }
//	}
    writeIPAASP(1004);
}

function writeIPAASP(theType){
	XMLMode = theType;
	shwRetrMap();
	//alert("in writeIPAASP, oktosend= "+okToSend);
	okToSend = false;
	Win1 = parent.ASPFrame;
	Win1.document.open();
	var w=Win1.document.writeln;
	s='<input type="hidden" name="';
	w('<html>');
	w('<body onload="document.rsc_prop.submit()">');
	w('<form action="http://www.mimapsmackay.com.au/website/'+app_dir+'/asp/writeIPA.asp" name="rsc_prop" method="post">');
	checkLimits();
	w(s+'LayerID" value="'+lyrId+'">');
	w(s+'LayerName" value="'+lyrNm+'">');
//ppunter 20 march 2006 commented the next 2 lines
	//w(s+'selectType" value="'+selectType+'">');
	//w(s+'ActiveLayerIndex" value="'+actLyrIndex+'">');
	w(s+'XMLMode" value="'+XMLMode+'">');
	w(s+'setQueryString" value="'+setQueryString+'">');
	w(s+'selectEnvelope" value="'+selectEnvelope+'">');
	w(s+'mapService" value="'+mapSv+'">');
	w(s+'toolMode" value="'+toolMode+'">');
	w(s+'host" value="www.mimapsmackay.com.au">');
	//ppunter 20 march 2006 ppunter - commented the next 4 lines below......
	//if (XMLMode==1004) {
	//  w(s+'ActiveLayer" value="'+ActLyr+'">');
	//  w(s+'reportEnvelope" value="'+reportEnvelope+'">');
	//} 
	for (var i=0;i<lyrNm.length;i++ ){
		//ppunter 20 march 2006....note next line does not now check for cadastre
	  if (lyrNm[i]=="Cad Areas and Plan Text"){
		 w(s+'propertyLayerId" value="'+lyrId[i]+'">'); 
		 //ppunter 20 march 2006 ppunter - added the next 4 lines below......
		 w(s+'ActiveLayer" value="'+lyrId[i]+'">');
		 w(s+'reportEnvelope" value="'+reportEnvelope+'">');
		 w(s+'ActiveLayerIndex" value="'+i+'">');
		 w(s+'selectType" value="'+lyrTyp[i]+'">');

	  }
	}
	w('</form>');
	//w('<input type="button" name="submit" value="submit" onclick="document.rsc_prop.submit()"');
//ppunter 20 march 2006 commented the next block of code
//	for (var i=0;i<layerCount;i++) {
//		  if (lyrNm[i]=="Cadastre") {
//			ActLyr=lyrId[i];
//			ActLyrTyp=lyrTyp[i];
//			actLyrIndex=i;
//			selectType=ActLyrTyp;
//			//next lines commented march 2006 ppunter
//			//f43(i);
//			//parent.TOCFrame.document.location=appDir+"toc.htm";
//			
//		 }
//	}

	w('</body>');
	w('</html>');
	Win1.document.close();
}

function Project_Point(e){
	var theX = mouseX;
	var theY = mouseY;
	f71(theX,theY);
	project_pts[project_pts_count]=mapX+","+mapY+"!!";
    project_pts_count+=1;
	projectmp=(right-left)/iWidth;
	sendMapXML();
}
