  
//returns preset scales based on the given width and height
//the values will change if there is any change to map size or scale
function GetMapScaleTool(wid, ht) {
	//if(wid <= 128.3641 && ht <= 89.2968) {
	//	return 1;//Max zoom - bld level zoom - 750
	//}
	if(wid <= 427.8803 && ht <= 297.6559) {
		return 2;//st level zoom - 2500
	}
	else if(wid <= 855.7606 && ht <= 595.3118) {
		return 3;//st level zoom - 5000
	}
	else if(wid <= 1711.5212 && ht <= 1190.6234) {
		return 4;//10000
	}
	else if(wid <= 8558 && ht <= 5954) {
		return 5;//50000
	}
	else if(wid <= 30188 && ht <= 21000) {
		return 6;//132063 --- OLD=163950
	}
	
}
  
  //returns preset scales based on the ZoomTool
  function GetScale(toolNo) {
  	if(toolNo == 1) {
  		return 1000;//Max zoom - bld level zoom
  	}
  	if(toolNo == 2) {
  		return 2500;//Street level zoom
  	}
  	if(toolNo == 3) {
  		return 5000;
  	}
  	if(toolNo == 4) {
  		return 10000;
  	}
  	if(toolNo == 5) {
  		return 50000;
  	}
  	if(toolNo == 6) {
  		return 132063;//Zoom extents
  	}  	
  }
  
function funcZoomToMap(strPt, tool, activeZoomTool){
	//alert("Vals " + strPt + ", " + tool + ", " + activeZoomTool);
	// Submit ZOOM
	setZOOMToolImages(activeZoomTool);
	var scale = GetScale(activeZoomTool);
	parent.MapFrame.document.frmNavigation.ActiveZoomTool.value = activeZoomTool
	parent.MapFrame.document.frmNavigation.Cmd.value = tool;
	parent.MapFrame.document.frmNavigation.Scale.value = scale;
	parent.MapFrame.document.frmNavigation.ZoomCoords.value = strPt;
	parent.MapFrame.document.frmNavigation.target = "MapFrame";
	parent.MapFrame.document.frmNavigation.action = "map.asp";
	parent.MapFrame.document.frmNavigation.submit();
}

function funcZoomToMap_Street(strEnv, tool){
	//alert("Vals " + strPt + ", " + tool + ", " + activeZoomTool);
	//get street envelope
	var theEnvelope = new Array();
	theEnvelope = getEnvelopeXYs(strEnv);
	var width = theEnvelope[2] - theEnvelope[0];
	var height = theEnvelope[3] - theEnvelope[1];
	//create center pt
	var cenX = (theEnvelope[2] + theEnvelope[0]) / 2;
	var cenY = (theEnvelope[3] + theEnvelope[1]) / 2;
	var strPt = "" +  cenX.toString() + "," + cenY.toString();

	//get zoomTool id
	var activeZoomTool = GetMapScaleTool(width, height);
	setZOOMToolImages(activeZoomTool);
	var scale = GetScale(activeZoomTool);
	parent.MapFrame.document.frmNavigation.ActiveZoomTool.value = activeZoomTool
	parent.MapFrame.document.frmNavigation.Cmd.value = tool;
	parent.MapFrame.document.frmNavigation.Scale.value = scale;
	parent.MapFrame.document.frmNavigation.ZoomCoords.value = strPt;
	parent.MapFrame.document.frmNavigation.target = "MapFrame";
	parent.MapFrame.document.frmNavigation.action = "map.asp";
	parent.MapFrame.document.frmNavigation.submit();
}

// get min and max x,y's from envelope str, return an array with values
function getEnvelopeXYs(theString) {
	var theEnvelope = new Array();
	//theString = theString.toUpperCase();
	var tempString = "";
	var startpos = theString.indexOf(",",startpos);
	tempString = theString.substring(0,startpos);
	theEnvelope[0] = parseFloat(tempString);
	//alert("0 " + theEnvelope[0]);
	startpos = startpos + 1;
	var endpos = theString.indexOf(",",startpos);
	tempString = theString.substring(startpos,endpos);
	theEnvelope[1] = parseFloat(tempString);
	startpos = endpos + 1;
	//alert("0 " + theEnvelope[1] + ", " + tempString);
	
	endpos = theString.indexOf(",",startpos);
	tempString = theString.substring(startpos,endpos);
	theEnvelope[2] = parseFloat(tempString);
	startpos = endpos + 1;
	
	tempString = theString.substring(startpos,theString.length);
	theEnvelope[3] = parseFloat(tempString);
	
	return theEnvelope;

}


  function ActivateZoomIn(imgPrefix) {
  //Used by SingleClick Client except Basic Viewer
  //imgPrefix is optional... used by Chameleon Interface
	if (imgPrefix == null) {
		imgPrefix = "";
		}	
    ///setToolImage('ZOOMIN','2',imgPrefix); 
    document.frmNavigation.Cmd.value = 'ZOOMIN';
    document.frmNavigation.target="";
    document.frmNavigation.action = 'map.asp';
  }
  
  function ActivateZoomOut(imgPrefix) {
  //Used by SingleClick Client except Basic Viewer
  //imgPrefix is optional... used by Chameleon Interface
	if (imgPrefix == null) {
		imgPrefix = "";
		}	
    ///setToolImage('ZOOMOUT','2',imgPrefix); 
    document.frmNavigation.Cmd.value = 'ZOOMOUT';
    document.frmNavigation.target="";
    document.frmNavigation.action = 'map.asp';
  }
  
  function ActivatePan(imgPrefix) {
  //Used by SingleClick Client except Basic Viewer
  //imgPrefix is optional... used by Chameleon Interface
	if (imgPrefix == null) {
		imgPrefix = "";
		}	
    ///setToolImage('PAN','2',imgPrefix); 
    alert("Inside activepan");
    document.frmNavigation.Tool.value = 'PAN';
    document.frmNavigation.target="TextFrame";
    document.frmNavigation.action = 'map.asp';
  }
  
  function ActivateIdentify(targetwin,imgPrefix) {
  //Used by SingleClick Client except Basic Viewer
  //imgPrefix is optional... used by Chameleon Interface
	if (imgPrefix == null) {
		imgPrefix = "";
		}	
    ///setToolImage('IDENTIFY','2',imgPrefix); 
    document.frmNavigation.Cmd.value = 'IDENTIFY';
    document.frmNavigation.target = targetwin;
    document.frmNavigation.action = 'identify.asp';
  }
  
  //Kumara added here
  function ActivatePanZoomIn(scale) {
    //Used by SingleClick Client except Basic Viewer
    //imgPrefix is optional... used by Chameleon Interface
    //alert("active pan zi " + scale);
      setPZToolImage('PANZOOMIN','2',scale);
      document.frmNavigation.Cmd.value = 'PANZOOMIN';//'PANZOOMIN';
      document.frmNavigation.Scale.value = scale;
      document.frmNavigation.target="";
      document.frmNavigation.action = 'map.asp';
      document.frmNavigation.submit();
      //document.frmNavigation.ProcessMap(document.frmNavigation.dctPresentationInfo);
    }
//

  
function PopOut(sURL,sTitle,iHeight,iWidth,ynScroll,ynResize) {

var objWin;
  objWin = window.open(sURL, sTitle, "height="+iHeight+",width="+iWidth+",scrollbars="+ynScroll+",resizable="+ynResize+"");
  if (parseInt(navigator.appVersion) >=4) objWin.window.focus();
  
  //document.frmNavigation.Cmd.value = 'IDENTIFY';
  //document.frmNavigation.target = "TextFrame";
  //document.frmNavigation.action = 'identify.asp';
  //document.frmNavigation.submit();

}


function setToolImage(tool, mode, prefix) {
	//Used by Graphical Button Clients.
	//prefix is an optional argument to the image file name.
	if (prefix == null) {
		prefix = "";
		}
	var imageFile = 'images/' + prefix + tool + mode + '.gif';	

	// Dull all images first.
	document.ZOOMIN.src = 'images/'+ prefix +'zoomin1.gif';
	document.ZOOMOUT.src = 'images/'+ prefix +'zoomout1.gif';
	document.PAN.src = 'images/'+ prefix +'pan1.gif';
	document.IDENTIFY.src = 'images/'+ prefix +'identify1.gif';

	//Then brighten the passed tool.
	if (tool == "ZOOMIN") {
		document.ZOOMIN.src = imageFile;
		}
	if (tool == "ZOOMOUT") {
		document.ZOOMOUT.src = imageFile;
		}
	if (tool == "PAN") {
		document.PAN.src = imageFile;
		}
	if (tool == "IDENTIFY") {
		document.IDENTIFY.src = imageFile;
		}
}

function setPZToolImage(tool, scale) {
	//Used by Graphical Button Clients.
	//prefix is an optional argument to the image file name.
	var imageFile = 'images/zm1.jpg';
	document.BUTTON5.src = 'images/zm0.jpg';
	document.BUTTON1.src = 'images/zm0.jpg';
	document.BUTTON2.src = 'images/zm0.jpg';
	document.BUTTON3.src = 'images/zm0.jpg';
	document.BUTTON4.src = 'images/zm0.jpg';
	//alert("active pan zi " + tool + " " + mode + " " + scale);
	if(tool == "PANZOOMIN") {
		if(scale == "5") {
			document.BUTTON5.src = imageFile;	
		}
		if(scale == "1") {
			document.BUTTON1.src = imageFile;	
		}
		if(scale == "2") {
			document.BUTTON2.src = imageFile;	
		}
		if(scale == "3") {
			document.BUTTON3.src = imageFile;	
		}
		if(scale == "4") {
			document.BUTTON4.src = imageFile;	
		}
	}
}



function setZOOMToolImages(scale) {
	//alert('Inside Change Tool..' + scale);
	//Used by Graphical Button Clients.
	//prefix is an optional argument to the image file name
	var imageFile = 'images/zoombar_on.gif';
	parent.ToolFrame.document.Form1.ZOOM1.src = 'images/zoombar_off.gif';
	parent.ToolFrame.document.Form1.ZOOM2.src = 'images/zoombar_off.gif';
	parent.ToolFrame.document.Form1.ZOOM3.src = 'images/zoombar_off.gif';
	parent.ToolFrame.document.Form1.ZOOM4.src = 'images/zoombar_off.gif';
	parent.ToolFrame.document.Form1.ZOOM5.src = 'images/zoombar_off.gif';
	parent.ToolFrame.document.Form1.ZOOM6.src = 'images/zoombar_off.gif';
	//alert("active pan zi " + tool + " " + mode + " " + scale);
	//if(tool == "PANZOOMIN") {
	if(scale == "1") {
		parent.ToolFrame.document.Form1.ZOOM1.src = imageFile;	
	}
	if(scale == "2") {
		parent.ToolFrame.document.Form1.ZOOM2.src = imageFile;	
	}
	if(scale == "3") {
		parent.ToolFrame.document.Form1.ZOOM3.src = imageFile;	
	}
	if(scale == "4") {
		parent.ToolFrame.document.Form1.ZOOM4.src = imageFile;	
	}
	if(scale == "5") {
		parent.ToolFrame.document.Form1.ZOOM5.src = imageFile;	
	}
	if(scale == "6") {
		parent.ToolFrame.document.Form1.ZOOM6.src = imageFile;	
	}

}

function ProcessLink(sURL) {
		document.body.style.cursor = "wait";
		document.location = sURL;
}