




//*******************************************************************
//Point object
	function Point () {
	    this.x = 0; 
	    this.y = 0; 
	}

	function toMapPT(objMapImage) {
		degMapWidth = Math.abs(objMapImage.extent.maxx - objMapImage.extent.minx);
		degMapHeight = Math.abs(objMapImage.extent.maxy - objMapImage.extent.miny);
		degPixelX = degMapWidth/objMapImage.width;
		degPixelY = degMapHeight/objMapImage.height;
		var tmpPT = new Point();
		tmpPT.x = objMapImage.extent.minx + (this.x * degPixelX);
		tmpPT.y = objMapImage.extent.maxy - (this.y * degPixelY);
		return tmpPT;
	}

	function fromMapPT(objMapImage) {
		degMapWidth = Math.abs(objMapImage.extent.maxx - objMapImage.extent.minx);
		degMapHeight = Math.abs(objMapImage.extent.maxy - objMapImage.extent.miny);
		degPixelX = degMapWidth/objMapImage.width;
		degPixelY = degMapHeight/objMapImage.height;
		tmpPT = new Point();
		tmpPT.x =(this.x - objMapImage.extent.minx )/ degPixelX;
		tmpPT.y =(objMapImage.extent.maxy - this.y)/ degPixelY;
		return tmpPT;
	}
	
	Point.prototype.toMapPoint = toMapPT;
	Point.prototype.fromMapPoint = fromMapPT;
	
//*******************************************************************



//*******************************************************************
//Extent object
	function Extent () {
	    this.maxx = 0;
	    this.maxy = 0;
		this.minx = 0;
	    this.miny = 0;
	}
	
	//scales extent by factor
	function scaleextent(factor) {
		degMapWidth = Math.abs(this.maxx - this.minx);
		degMapHeight = Math.abs(this.maxy - this.miny);		
		var tmpPT = new Point();
		tmpPT.x = (degMapWidth/2) + this.minx;
		tmpPT.y = this.maxy - (degMapHeight/2);
		newMapWidth = degMapWidth * factor;
		newMapHeight = degMapHeight * factor;
		tmpExtent = new Extent();
		tmpExtent.maxx = tmpPT.x + (newMapWidth/2);
		tmpExtent.minx = tmpPT.x - (newMapWidth/2);
		tmpExtent.maxy = tmpPT.y + (newMapHeight/2);
		tmpExtent.miny = tmpPT.y - (newMapHeight/2);
		return tmpExtent;
	}
	
	//gets map unit extent from pixel extent
	function toExtent(objExtent,objMapImage) {
		var tmpULPT = new Point();
		tmpULPT.x = this.minx;
		tmpULPT.y = this.miny;
		tmpULPT = tmpULPT.toMapPoint(objExtent,objMapImage);
		var tmpLRPT = new Point();
		tmpLRPT.x = this.maxx;
		tmpLRPT.y = this.maxy;
		tmpLRPT = tmpLRPT.toMapPoint(objExtent,objMapImage);
		tmpExtent = new Extent();
		tmpExtent.maxx = tmpLRPT.x; 
		tmpExtent.minx = tmpULPT.x;
		tmpExtent.maxy = tmpULPT.y;
		tmpExtent.miny = tmpLRPT.y;
		return tmpExtent;
	}
	
	//gets pixel extent from mapunitextent
	function fromExtent(objExtent,objMapImage) {	
		var tmpULPT = new Point();
		tmpULPT.x = this.minx;
		tmpULPT.y = this.maxy;
		tmpULPT = tmpULPT.fromMapPoint(objExtent,objMapImage);
		var tmpLRPT = new Point();
		tmpLRPT.x = this.maxx;
		tmpLRPT.y = this.miny;
		tmpLRPT = tmpLRPT.fromMapPoint(objExtent,objMapImage);
		tmpExtent = new Extent();
		tmpExtent.maxx = tmpLRPT.x;
		tmpExtent.minx = tmpULPT.x;
		tmpExtent.maxy = tmpULPT.y; 
		tmpExtent.miny = tmpLRPT.y;
		return tmpExtent;
	}
	
	Extent.prototype.scaleExtent = scaleextent;
	Extent.prototype.toMapExtent = toExtent;
	Extent.prototype.fromMapExtent = fromExtent;
//*******************************************************************


//*******************************************************************
//URL object
	function UpdateURL() {
		this.getmap = '';
		this.extent = new Extent();
		//this.pixelExtent = new Extent();
		//this.selectExtent = new Extent();
		//this.point = new Point();
		this.mapwidth = 0;
		this.mapheight = 0;
		this.layertype = '';
		this.zone = 0;
	} 

	//creates url to update map
	function GetURL() {
		//url =  'http://' + this.server + this.port + '/' + this.allias + '/' + this.getmap + '?env=' + this.env;
		//
		//url = url + '&x=' + this.point.x + '&y=' + this.point.y + '&cmd=' +  this.cmd + '&view=' + this.view + '&ViewType=' + this.viewtype;
		//url = url + '&legend=' + this.needlegend;
		//url = url + '&mwidth=' + this.mapwidth + '&mheight=' + this.mapheight;
		//url = url + '&lwidth=' + this.legendwidth + '&lheight=' + this.legendheight;
		//url = url + '&LyrVis=' + this.layervis + '&group=' + this.group;
		
		url = this.getmap //x=' + this.point.x + '&y=' + this.point.y + '&cmd=' + this.cmd;
		url = url + '?zone=' + this.zone + '&theme=' + this.layertype;
		url = url + '&maxx=' + this.extent.maxx + '&minx=' + this.extent.minx + '&maxy=' + this.extent.maxy + '&miny=' + this.extent.miny;
		url = url + '&mwidth=' + this.mapwidth + '&mheight=' + this.mapheight; 
		//url = url + '&lrx=' + this.selectExtent.maxx + '&ulx=' + this.selectExtent.minx + '&lry=' + this.selectExtent.maxy + '&uly=' + this.selectExtent.miny;
		//url = url + '&radius=' + this.radius;
		//url = url + '&activeLayer=' + this.activeLayer + '&layervis=' + this.layervis;
		//url = url + '&fid=' + this.fid + '&findlayer=' + this.findlayer;
		
		return url;
	}
	UpdateURL.prototype.URL = GetURL; 

//End UpdateURL objects
//*******************************************************************



//*******************************************************************
//Map object
	function Map () {
	    this.width = 0;
	    this.height = 0;
			this.left = 0;
	    this.top = 0;
	    this.extent = new Extent();
	    this.extent.maxx = 0;
	    this.extent.maxy = 0;
	    this.extent.minx = 0;
	    this.extent.miny = 0;
	    this.elementID = '';
	}
		
	function toMap(pt) {
		degMapWidth = Math.abs(this.extent.maxx - this.extent.minx);
		degMapHeight = Math.abs(this.extent.maxy - this.extent.miny);
		degPixelX = degMapWidth/this.width;
		degPixelY = degMapHeight/this.height;
		var tmpPT = new Point();
		tmpPT.x = this.extent.minx + (pt.x * degPixelX);
		tmpPT.y = this.extent.maxy - (pt.y * degPixelY);
		return tmpPT;
	}

	function fromMap(pt) {
		degMapWidth = Math.abs(this.extent.maxx - this.extent.minx);
		degMapHeight = Math.abs(this.extent.maxy - this.extent.miny);
		degPixelX = degMapWidth/this.width;
		degPixelY = degMapHeight/this.height;
		tmpPT = new Point();
		tmpPT.x =(pt.x - this.extent.minx )/ degPixelX;
		tmpPT.y =(this.extent.maxy - pt.y)/ degPixelY;
		return tmpPT;
	}
		
		
	function updatemap(objURL,objProcessFrame) {
		url = objURL.GetURL()
		var theDOM = getDOM();
		if (theDOM=='LAYERS') {
			document.layers[objProcessFrame.elementID].src = url;
		}
		if (theDOM=='ALL') {
			[objProcessFrame.name].location = url
		}
		if (theDOM=='GETID') {
			[objProcessFrame.name].location = url
		}	
	}	
		
	function updatemapextent(maxx,maxy,minx,miny) {
		this.extent.maxx = maxx;
		this.extent.maxy = maxy;
		this.extent.minx = minx;
		this.extent.miny = miny;
	}	
		
	function updatemapimage(imageurl) {
		var theDOM = getDOM();
		if (theDOM=='LAYERS') {
			document.layers[this.elementID].background.src = imageurl;
		}
		if (theDOM=='ALL') {
			document.all(this.elementID).style.background = 'url(' + imageurl + ')';
		}
		if (theDOM=='GETID') {
			document.getElementById(this.elementID).style.background = 'url(' + imageurl + ')';
		}	
	}	
		
		
		//scales extent by factor
	function scalemap(factor) {
		degMapWidth = Math.abs(this.extent.maxx - this.extent.minx);
		degMapHeight = Math.abs(this.extent.maxy - this.extent.miny);		
		var tmpPT = new Point();
		tmpPT.x = (degMapWidth/2) + this.extent.minx;
		tmpPT.y = this.maxy - (degMapHeight/2);
		newMapWidth = degMapWidth * factor;
		newMapHeight = degMapHeight * factor;
		tmpExtent = new Extent();
		tmpExtent.maxx = tmpPT.x + (newMapWidth/2);
		tmpExtent.minx = tmpPT.x - (newMapWidth/2);
		tmpExtent.maxy = tmpPT.y + (newMapHeight/2);
		tmpExtent.miny = tmpPT.y - (newMapHeight/2);
		this.extent =  tmpExtent;
	}	
		
		
		
	function mapclick(evt) {
		tmpPT = new Point();
		tmpPT.x = -9999;
		tmpPT.y = -9999;
		var DOM = getDOM();
			if (evt.x) {
				x = evt.offsetX;
			}
			if (evt.y) {
				y = evt.offsetY;
			}
			if (evt.pageX) {
				x = evt.pageX - this.left;
			}
			if (evt.pageY) {
				y = evt.pageY - this.top;
			}

			if (DOM=="LAYERS") {
				if (x >= 0 && x <= this.width && y >=0 && y <=this.height) {
					tmpPT.x = x;
					tmpPT.y = y;
				}
				else {
					tmpPT.x = -9999;
					tmpPT.y = -9999;
				}
			}
			if (DOM=="ALL") {
				tmpPT.x = x - this.left;
				tmpPT.y = y - this.top;
			}
				if (DOM=="GETID") {
				tmpPT.x = x 
				tmpPT.y = y 
			}
		return tmpPT;
	}
		
		
		
		
	Map.prototype.toMapPoint = toMap;
	Map.prototype.fromMapPoint = fromMap;
	Map.prototype.UpdateMapImage = updatemapimage;
	Map.prototype.UpdateMap = updatemap;
	Map.prototype.UpdateMapExtent = updatemapextent;
	Map.prototype.ScaleMap = scalemap;
	Map.prototype.MapClick = mapclick;
//*******************************************************************






//*******************************************************************
//legend
	function Legend() {
		this.width = 0;
		this.height = 0;
		this.view = '';
		this.viewtype = '';
		this.elementID = '';
		this.legendURL = '';
	}
	
	function updatelegend(url) {
		var theDOM = getDOM();
		if (theDOM=='LAYERS') {
			document.layers[this.elementID].background.src = url;
		}
		if (theDOM=='ALL') {
			document.all(this.elementID).style.background = 'url(' + url + ')';
		}
		if (theDOM=='GETID') {
			document.getElementById(this.elementID).style.background = 'url(' + url + ')';
		}	
	}
	
	Legend.prototype.UpdateLegend = updatelegend;
//*******************************************************************	
	
	
//*******************************************************************	
//loading image


	function LoadImage() {
		this.elementID = '';
	}
	
	function turnoff(){
		var theDOM = getDOM();
		if (theDOM=='LAYERS') {
			document.layers[this.elementID].visibility = 'hide';
		}
		if (theDOM=='ALL') {
			document.all(this.elementID).style.visibility = "hidden";
		}
		if (theDOM=='GETID') {
			document.getElementById(this.elementID).style.visibility = "hidden";
		}
	}

	function turnon(){
		var theDOM = getDOM();
		if (theDOM=='LAYERS') {
			document.layers[this.elementID].visibility = 'show';
		}
		if (theDOM=='ALL') {
			document.all(this.elementID).style.visibility = "visible";
		}
		if (theDOM=='GETID') {
			document.getElementById(this.elementID).style.visibility = "visible";
		}	
	
	}

LoadImage.prototype.TurnOff = turnoff;
LoadImage.prototype.TurnOn = turnon;

//*******************************************************************	



//*******************************************************************	
//process frame
function ProcessFrame() {
	this.elementID = '';
	this.NSelementID = '';
	this.name = '';
}
	
function updateframe(url) {
	
	var DOM = getDOM();
	//frm = this.name.location
	if (DOM=='LAYERS') {
		document.layers[this.NSelementID].src = url;
	}
	if (DOM=='ALL') {
		//document[this.name].location = url;
		frame.location = url;
	}
	if (DOM=='GETID') {
		//document.frames[this.name].location.href = url;
		//[this.name].location = url
		frame.location = url;
	}	
}
	ProcessFrame.prototype.UpdateFrame= updateframe;
//*******************************************************************		
	
	
	
//*******************************************************************
//dom
function getDOM() {
	var browser = navigator.appName;
	var version = parseInt(navigator.appVersion);
	var DOM = "";
	if (document.getElementById) {
		DOM = "GETID";
	}
	else {
		if (browser != "Microsoft Internet Explorer") {
			if (version<5 ){
				DOM = "LAYERS";			
			}
		}
		else {
			DOM = "ALL";
		}
	}
	return DOM;
}
//*******************************************************************


