
//<![CDATA[
var statObj, mathObj;

function dynMap(id, container, viewWidth, viewHeight, originX, originY, limitX, limitY) {
	// Creates an object that will calculate the pixel locations for a defined set of coordinates
	// Internal coordinates are all positive (+180, +90) = (0, 0)-(360, 180)

	// Base functions/properties
	this.init = dynMap__init;
	this.id = id;
	this.initialized = false;

	// Events
	this.onpinclick = null;
	this.onrender = null;
	this.onscroll = null;
	this.onzoom = null;

	// Calculations
	this.calculateDistance = dynMap__calculateDistance;
	this.isWithin = dynMap__isWithin;
	this.getCoordsOfPixel = dynMap__getCoordsOfPixel;
	this.getPixelAtCoord = dynMap__getPixelAtCoord;

	// HTML containers
	this.container = container;
	this.pinContainer = null;
	this.mapContainer = null;
	this.mapImageContainer = null;
	this.mapServiceContainer = null;

	// Pins
	this.pins = new Array();
	this.pinsVisible = false;
	this.createPin = dynMap__createPin;
	this.deletePin = dynMap__deletePin;
	this.showPins = dynMap__showPins;
	this.hidePins = dynMap__hidePins;
	this.updatePins = dynMap__updatePins;
	this.updatePinStep = dynMap__updatePinStep;
	this.renderPin = dynMap__renderPin;
	this.clearPins = dynMap__clearPins;
	this.pinClick = dynMap__pinClick;
	this.showTags = false;
	this.pinsUpdated = false;

	// Views
	this.pixelWidth = -1;
	this.pixelHeight = -1;
	this.viewWidth = viewWidth;
	this.viewHeight = viewHeight;
	this.location = new coord(0, 0);
	this.mapOrigin = new coord(originX, originY);
	this.mapLimit = new coord(limitX, limitY);
	this.wrapMap = 0; // 0 = nowrap, 1 = wrap horiz, 2 = wrap both
	this.mapScaleX = -1;
	this.mapScaleY = -1;
	this.pixelsPerDegreeX = -1;
	this.pixelsPerDegreeY = -1;
	this.currentMap = -1;
	this.moveTo = dynMap__moveTo; // Pixels
	this.moveToCoord = dynMap__moveToCoord; // Coordinates
	this.moveBy = dynMap__moveBy; // Always pixels
	this.smoothScroll = true;
	this.scrollRate = 120; // Pixels per second
	this.scrollDrop = 200; // Pixel distance at which scrolling slows down
	this.updateMapCoords = dynMap__updateMapCoords;
	this.showServiceArea = false;

	// Maps
	this.maps = new Array();
	this.pixelX = -1; //(w - cw) / 2;
	this.pixelY = -1; //(h - ch) / 2;
	this.renderMap = dynMap__renderMap;
	this.addMap = dynMap__addMap;

	// Zooming
	this.updateScale = dynMap__updateScale;
	this.startCoords = this.mapOrigin;
	this.endCoords = this.mapLimit;
	this.zoomScale = 1;
	this.currentZoom = 1;
	this.maxZoom = 4;
	this.minZoom = 0.5;
	this.setZoom = dynMap__setZoom;
}

//for adding/removing the service area overlay map
function changeServiceArea(map, showhide) 
{
	map.mapServiceContainer.style.display = showhide ? 'block' : 'none';
}

//probably a useless method, but keeping it just in case it is being used.
function sortArray(arr, idx) 
{
	if (arr.length == 0)
		return(arr);
	var newArray = new Array();
	for (var i = 0; i < arr.length; i++) 
	{
		if (i == 0) 
		{
			newArray[0] = arr[0];
		} 
		else 
		{
			for (var j = i; j >= 0; j--) 
			{
				if (j > 0 && arr[i][idx] < newArray[j - 1][idx])
					newArray[j] = newArray[j - 1];
				else 
				{
					newArray[j] = arr[i];
					break;
				}
			}
		}
	}
	return(newArray);
}
		
		
// Base functions
function dynMap__init() {
	if (this.initialized)
		return;
	eval('window.' + this.id + ' = this;');
stat.innerHTML += '<br/>Map coordinate ranges = ' + this.mapOrigin.realx + ',' + this.mapOrigin.realy + ' to ' + this.mapLimit.realx + ',' + this.mapLimit.realy;
var c1, p1;
c1 = this.getCoordsOfPixel(0, 0);
p1 = this.getPixelAtCoord(c1);
stat.innerHTML += '<br/>0,0 coord test = ' + c1.realx + ',' + c1.realy + ' = ' + p1[0] + ',' + p1[1];
	this.container.innerHTML = '';
	this.container.style.position = 'relative';
	var mapc = document.createElement('div');
	mapc.id = 'mapContainer';
	mapc.style.position = 'absolute';
	mapc.style.left = '0px';
	mapc.style.top = '0px';
	this.container.appendChild(mapc);
	this.mapContainer = mapc;
	var mapc2 = document.createElement('div');
	mapc2.id = 'mapImageContainer';
	mapc2.style.position = 'absolute';
	mapc2.style.left = '0px';
	mapc2.style.top = '0px';
	this.mapContainer.appendChild(mapc2);
	this.mapImageContainer = mapc2;
mapc2 = document.createElement('div');
mapc2.id = 'mapServiceContainer';
mapc2.style.position = 'absolute';
mapc2.style.left = '0px';
mapc2.style.top = '0px';
mapc2.innerHTML = '<img src="/_layouts/pse/images/paymap/service_overlay.gif" width="1908" height="1162" />';
mapc2.style.display = document.forms[0].elements['showservicearea'].checked ? 'block' : 'none';
mapc2.style.zIndex = 1000;
this.mapContainer.appendChild(mapc2);
this.mapServiceContainer = mapc2;
	var pinc = document.createElement('div');
	pinc.id = 'pinContainer';
	pinc.style.position = 'absolute';
	pinc.style.left = '0px';
	pinc.style.top = '0px';
	pinc.style.zIndex = 2000;
	mapc.appendChild(pinc);
	this.pinContainer = pinc;
stat.innerHTML += '<br/>--updating scale';
	this.updateScale();
	this.setZoom(this.currentZoom);
stat.innerHTML += '<br/>--rendering map';
	this.renderMap();
stat.innerHTML += '<br/>--done';
	this.showPins();
	this.updatePins();
	this.initialized = true;
}

// Pins
function dynMap__pin(id) {
	this.id = id;
	this.text = null;
	this.desc = null;
	this.image = null;
	this.coords = null;
	this.rendered = null;
	this.tag = null;
}
function dynMap__createPin(pinId, pinText, pinDesc, pinImage, pinCoords) {
	var p = new dynMap__pin(pinId);
	p.text = pinText;
	p.desc = pinDesc;
	p.image = pinImage;
	p.coords = pinCoords;
	this.pins[this.pins.length] = p;
	this.pinsUpdated = false;
	if (this.pinsVisible)
		this.updatePins();
	return(p);
}
function dynMap__deletePin(pin) {
	for (var i = 0; i < this.pins.length; i++)
		if (this.pins[i] == pin) {
			for (var j = i; j < this.pins.length - 1; j++)
				this.pins[j] = this.pins[j + 1];
			this.pins.length = this.pins.length - 1;
			break;
		}
	this.pinContainer.removeChild(pin);
}
function dynMap__clearPins() {
	this.pins.length = 0;
	this.pinContainer.innerHTML = '';
	this.hidePins();
}
function dynMap__updatePins() {
	if (this.pinsUpdated)
		return;
stat.innerHTML += '<br/>--updating pins';
	if (this.pins.length > 0 && !this.pins[0].rendered)
		this.pinContainer.style.display = 'none';
	this.updateMapCoords(this.pixelX, this.pixelY);
	this.pinsUpdated = true;
	this.updatePinStep(0);
}
function dynMap__updatePinStep(step) {
	if (step >= this.pins.length) {
		if (this.pinsVisible) this.pinContainer.style.display = 'block';
		return;
	}
	var v, p;
	p = this.pins[step];
	v = true; //this.pinsVisible ? (p.coords.x >= this.mapOrigin.x && p.coords.x <= this.mapLimit.x && p.coords.y >= this.mapOrigin.y && p.coords.y <= this.mapLimit.y) : false;
	if (!p.rendered)
		this.renderPin(p);
//stat.innerHTML += '<br/>--adjusting pin position';
	var px = this.getPixelAtCoord(p.coords);
	p.rendered.style.left = Math.round(px[0] - 5) + 'px'; // - this.zoomScale * 12) + 'px';
	p.rendered.style.top = Math.round(px[1] - 5) + 'px'; // + this.zoomScale * 21) + 'px';
//stat.innerHTML += '<br/>--pin moved to ' + p.rendered.style.left + ', ' + p.rendered.style.top;
//stat.innerHTML += '<br/>--adjusting pin visibility: ' + v;
	p.rendered.style.display = v ? 'block' : 'none';
	setTimeout(this.id + '.updatePinStep(' + (step + 1) + ');', 10);
}
function dynMap__pinClick(id) {
stat.innerHTML += '<br/>Searching for pin "' + id + '"';
	var p = null;
	for (var i = 0; i < this.pins.length; i++)
		if (this.pins[i].id == id) {
			p = this.pins[i];
			break;
		}
	if (!p)
		return;
	stat.innerHTML += '<br/>--Pin clicked: ' + p.id + ', ' + p.text;
	if (this.onpinclick)
		this.onpinclick(p);
}
function dynMap__renderPin(pin) {
	if (!pin.rendered) {
		var pins = this.pinContainer;
		var p = document.createElement('div');
		p.style.display = 'none';
		p.style.position = 'absolute';
		p.style.verticalAlign = 'top';
		p.id = pin.id;
		p.innerHTML = '<table border="0" cellpadding="0" cellspacing="0"><tr><td valign="top" width="10"><a href="#' + pin.id + '" onclick="' + this.id + '.pinClick(\'' + pin.id + '\');return(false);" title="' + (pin.text || 'Pin') + (pin.desc ? ('\n' + pin.desc) : '') + '"><img src="' + pin.image + '" border="0" width="10" height="10" /></a></td>' + (this.showTags ? ('<td valign="top" style="padding-left:4px; font-size:7pt; background-color: #f0f0f0;">' + pin.tag + '</td>') : '') + '</tr></table>';
		pins.appendChild(p);
		pin.rendered = p;
	}
}
function dynMap__showPins(noupdate) {
	this.updatePins();
	if (!this.pinsVisible) {
		this.pinContainer.style.display = 'block';
		if (!noupdate) this.pinsVisible = true;
		if (!noupdate) this.updatePins();
	}
}
function dynMap__hidePins(noupdate) {
	if (this.pinsVisible) {
		this.pinContainer.style.display = 'none';
		if (!noupdate) this.pinsVisible = false;
		if (!noupdate) this.updatePins();
	}
}

// Coordinates
// We have this specific object for coordinates because of one major thing--negative coordinates
// This object will automatically add 180 to the passed values to compensate for negatives
function coord(x, y) {
	this.x = x + 180;
	this.y = 180 - (y + 90);
	this.realx = x;
	this.realy = y;
	this.radx = x * Math.PI / 180;
	this.rady = y * Math.PI / 180;
}
// And this object converts our "special" coordinate object back into real coordinates
function realCoord(c) {
	this.x = c.x - 180;
	this.y = 0 - (c.y - 90);
}
// And this one allows us to create virtual coordinates from other virtual coordinates without converting back to real coordinates (very useful for distance calculations)
function virtualCoord(x, y) {
	this.x = x;
	this.y = y;
	this.realx = x - 180;
	this.realy = 0 - (y - 90);
	this.radx = this.realx * Math.PI / 180;
	this.rady = this.realy * Math.PI / 180;
}

// Zooming
function dynMap__updateScale() {
	var curMap = this.maps[this.currentMap];
	// Take the horizontal distance between the dimensions of the map and calculate how many degrees per pixel...since the map is squared, we can assume this for vertical, too
	this.mapScaleX = this.calculateDistance(this.mapOrigin, new virtualCoord(this.mapLimit.x, this.mapOrigin.y)) / this.pixelWidth;
	this.pixelsPerDegreeX = 1 / this.mapScaleX;
	this.mapScaleY = this.calculateDistance(this.mapOrigin, new virtualCoord(this.mapOrigin.x, this.mapLimit.y)) / this.pixelHeight;
	this.pixelsPerDegreeY = 1 / this.mapScaleY;
}
function dynMap__setZoom(scale) {
	// The higher the scale, the bigger the picture is
	if (scale < this.minZoom || scale > this.maxZoom)
		return;
	// Firstly, we need to find out where we are and assume that's our center
	var c = this.location;
	// Next, let's obtain the map that is closest to this scale
	var ms = this.zoomScale, cm = this.currentMap;
	for (var i = 0; i < this.maps.length; i++) {
		var m = this.maps[i];
		if (m.mapScaleX == scale || (Math.abs(scale - m.mapScaleX) < Math.abs(ms - m.mapScaleX))) {
			ms = m.mapScaleX;
			cm = i;
		}
	}
	// Now that we have a new mapScale, we need to set our zoomLevel and update the global scale
	this.pixelWidth = this.pixelWidth / this.zoomScale * scale;
	this.pixelHeight = this.pixelHeight / this.zoomScale * scale;
	this.zoomScale = scale;
	this.currentMap = cm;
	this.updateScale();
	// Last, we have to recenter the map to the new coordinate center
//	var p = this.getPixelAtCoord(this.location);
//	this.pixelX = p[0] - this.viewWidth / 2;
//	this.pixelY = p[1] - this.viewHeight / 2;
//	this.updateMapCoords(this.pixelX, this.pixelY);
	this.moveToCoord(this.location, true);
	// And now we render it
	this.renderMap();
newMap.pinsUpdated = false;
newMap.updatePins();
	if (this.onzoom != null)
		this.onzoom();
}

// Maps
function dynMap__renderMap() {
this.mapImageContainer.innerHTML = 'rendering';
	// Renders the map
	var curMap = this.maps[this.currentMap];
	var cont = this.mapContainer;
	var img = this.mapImageContainer;
	if (curMap.isTiled) { // Tiled maps work a bit differently, because we only render the visible tiles instead of the entire map
	} else {
		img.innerHTML = '<img src="' + curMap.imageSrc + '" width="' + this.pixelWidth + '" height="' + this.pixelHeight + '" />';
		this.mapServiceContainer.innerHTML = '<img src="/_layouts/pse/images/paymap/service_overlay.gif" width="' + this.pixelWidth + '" height="' + this.pixelHeight + '" />';
	}
/*	this.pixelX = 0 - Math.round((this.location.x - this.mapOrigin.x) * this.pixelsPerDegreeX - this.viewWidth / 2);
	this.pixelY = 0 - Math.round((this.location.y - this.mapOrigin.y) * this.pixelsPerDegreeY - this.viewHeight / 2);
	if (this.pixelX > 0)
		this.pixelX = 0;
	if (this.pixelX < -(this.pixelWidth - this.viewWidth))
		this.pixelX = -(this.pixelWidth - this.viewWidth);
	if (this.pixelY > 0)
		this.pixelY = 0;
	if (this.pixelY < -(this.pixelHeight - this.viewHeight))
		this.pixelY = -(this.pixelHeight - this.viewHeight);
//	this.location = this.getCoordsOfPixel(this.pixelX + this.viewWidth / 2, this.pixelY + this.viewHeight / 2);
	this.updateMapCoords(this.pixelX, this.pixelY);
	cont.style.left = this.pixelX + 'px';
	cont.style.top = this.pixelY + 'px';*/
	this.moveToCoord(this.location, true);
	this.updatePins();
}
function dynMap__getCoordsOfPixel(x, y) {
	var cx, cy;
	cx = this.mapOrigin.x + x * this.mapScaleX;
	cy = this.mapOrigin.y + y * this.mapScaleY;
	return(new virtualCoord(cx, cy));
}
function dynMap__getPixelAtCoord(c) {
	var cx, cy;
	cx = (c.x - this.mapOrigin.x) * this.pixelsPerDegreeX;
	cy = (c.y - this.mapOrigin.y) * this.pixelsPerDegreeY;
	return(new Array(cx, cy));
}
function dynMap__updateMapCoords(x, y) {
	var cx, cy;
	cx = Math.round(x);
	cy = Math.round(y);
	this.startCoords = this.getCoordsOfPixel(cx, cy);
	this.endCoords = this.getCoordsOfPixel(cx + this.viewWidth, cy + this.viewHeight);
}
function dynMap__map(parent, scale, mapImg, isTiled, tileExt, tileWidth, tileHeight, tileIndexes) {
	// All maps must have the same coordinate origin and limit as the base object
	this.parent = parent;
	this.mapScale = scale; // mapScale is a reverse multiplier of the root mapScale...thus, if mapScale here is 2 and the root mapScale is 1.5 deg/pix, this will cause the map to render at a scale of 0.75 deg/pix
	this.imageSrc = mapImg; // For tiled maps, this is the base filename (ie: maps/2x/map)...tileExtension contains the file extension (ie: gif)
	this.pixelWidth = parent.pixelWidth * scale;
	this.pixelHeight = parent.pixelHeight * scale;
	this.isTiled = isTiled;
	this.tiles = null;
	this.tileExtension = '';
	if (isTiled) {
		this.tileExtension = '.' + tileExt;
		var tilesAcross = parent.pixelWidth / tileWidth;
		var tilesDown = parent.pixelHeight / tileHeight;
		this.tiles = new Array(tilesDown);
		for (var d = 0; d < tilesDown; d++) {
			this.tiles[d] = new Array(tilesAcross);
			for (var a = 0; a < tilesAcross; a++) {
				this.tiles[d][a] = mapImg + '_' + (tileIndexes == null ? (d * tilesAcross + a) : (tileIndexes[d * tilesAcross + a])) + this.tileExtension;
			}
		}
	}
}
function dynMap__moveTo(x, y, noviewadapt, nosmooth) {
stat.innerHTML += '<br/>moveTo: ' + x + ',' + y;
	var cx, cy;
	cx = Math.round(x - (noviewadapt ? 0 : (this.viewWidth / 2)));
	if (cx > 0) cx = 0;
	if (cx < -(this.pixelWidth - this.viewWidth)) cx = -(this.pixelWidth - this.viewWidth);
	cy = Math.round(y - (noviewadapt ? 0 : (this.viewHeight / 2)));
	if (cy > 0) cy = 0;
	if (cy < -(this.pixelHeight - this.viewHeight)) cy = -(this.pixelHeight - this.viewHeight);
	if (!this.smoothScroll || nosmooth) {
		this.mapContainer.style.left = cx + 'px';
		this.mapContainer.style.top = cy + 'px';
	} else {
		var smoothIt = new smoothMove(this.mapContainer, cx, cy);
		this.showServiceArea = this.mapServiceContainer.style.display == 'block';
		smoothIt.onfinish = new Function(this.id + '.updatePins();' + this.id + '.mapServiceContainer.style.display="' + (this.showServiceArea ? 'block' : 'none') + '";');
		this.mapServiceContainer.style.display="none";
		smoothIt.go();
	}
	this.updateMapCoords(cx, cy);
	this.pixelX = cx;
	this.pixelY = cy;
stat.innerHTML += '<br/>New pixel coords: ' + cx + ',' + cy;
	this.location = this.getCoordsOfPixel(this.viewWidth / 2 - cx, this.viewHeight / 2 - cy);
stat.innerHTML += '<br/>Location: ' + this.location.realx + ',' + this.location.realy;
}
function dynMap__moveToCoord(c, nosmooth) {
	var cx, cy, p;
	p = this.getPixelAtCoord(c);
	cx = Math.round(this.viewWidth / 2 - p[0]); //Math.round((c.x - this.mapOrigin.x) * this.pixelsPerDegreeX - this.viewWidth / 2);
	cy = Math.round(this.viewHeight / 2 - p[1]); //Math.round((c.y - this.mapOrigin.y) * this.pixelsPerDegreeY - this.viewHeight / 2);
stat.innerHTML += '<br/>moveToCoord in pixels: ' + cx + ',' + cy;
	this.moveTo(cx, cy, true, nosmooth);
}
function dynMap__moveBy(x, y) { // Always pixel values
	var cx, cy;
	cx = this.pixelX + x;
	cy = this.pixelY + y;
	this.moveTo(cx, cy, true);
}
function dynMap__calculateDistance(point1, point2) {
	var hd, vd, d;
	hd = Math.abs(point2.x - point1.x);
	vd = Math.abs(point2.y - point1.y);
	d = Math.pow(hd * hd + vd * vd, 0.5);
	return(d);
}
function dynMap__isWithin(basepoint, pointcheck, distinmiles) {
//	var distInDegrees = this.calculateDistance(basepoint, pointcheck);
	var dist2 = calcD(basepoint.radx, basepoint.rady, pointcheck.radx, pointcheck.rady);
	if (dist2 <= distinmiles)
		return(true);
	return(false);
}



function calcD(lat1, long1, lat2, long2) {
	var R = 3963.19246; // miles
	var dLat  = lat2 - lat2;
	var dLong = long2 - long1;

	var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
		  Math.cos(lat1) * Math.cos(lat2) * Math.sin(dLong/2) * Math.sin(dLong/2);
	var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
	var d = R * c * 2;
	return(d);
}


var cxradian = 180/Math.PI;
var cxa = 3963.19246;
var cxf = 1/298.257;
var cxe = 0.08181922;

function calcDistance(lat1,long1,lat2,long2) {
	var F, G, lambda, omega, S, C, R, D, s;
	F = (lat1+lat2)/2;
	G = (lat1-lat2)/2;
	lambda = (long1-long2)/2;
	with(Math) {
		S = pow(sin(G)*cos(lambda),2)+pow(cos(F)*sin(lambda),2);
		C = pow(cos(G)*cos(lambda),2)+pow(sin(F)*sin(lambda),2);
		omega = atan(sqrt(S/C));
		R = sqrt(S*C)/omega;
		D = 2*omega*cxa;
		H1 =(3*R-1)/2/C;
		H2 =(3*R+1)/2/S;
		s = D*(1+cxf*H1*pow(sin(F)*cos(G),2)-cxf*H2*pow(cos(F)*sin(G),2));
	}
	return s;
}


function dynMap__addMap(scale, mapImg, isTiled, tileExt, tileWidth, tileHeight, tileIndexes) {
	this.maps[this.maps.length] = new dynMap__map(this, scale, mapImg, isTiled, tileExt, tileWidth, tileHeight, tileIndexes);
	if (this.currentMap == -1)
		this.currentMap = 0;
	return(this.maps[this.maps.length - 1]);
}

function moveTo(obj, x, y, usesmooth) {
//	if (!statObj) statObj = document.getElementById('status');
//	if (!mathObj) mathObj = document.getElementById('mathstat');
	if (!usesmooth) {
		obj.style.left = x + 'px';
		obj.style.top = y + 'px';
	} else {
		var smoothIt = new smoothMove(obj, x, y);
		smoothIt.go();
	}
}
function moveBy(obj, x, y, usesmooth) {
//	if (!statObj) statObj = document.getElementById('status');
//	if (!mathObj) mathObj = document.getElementById('mathstat');
	var newx, newy;
	newx = (parseInt(obj.style.left, 10) || 0) + x;
	newy = (parseInt(obj.style.top, 10) || 0) + y;
	if (obj.offsetWidth + newx < w) newx = -(obj.offsetWidth - w);
	if (obj.offsetHeight + newy < h) newy = -(obj.offsetHeight - h);
	if (newx > 0) newx = 0;
	if (newy > 0) newy = 0;
	if (!usesmooth) {
		obj.style.left = newx + 'px';
		obj.style.top = newy + 'px';
	} else {
		var smoothIt = new smoothMove(obj, newx, newy);
		smoothIt.steps = Math.floor(smoothMove_steps / 3);
		smoothIt.go();
	}
}

var w = 600, h = 700;
var enableSmoothing = true;

var isIE = (document.all && document.getElementById && navigator.appName.indexOf('Opera') == -1);

var smoothMove_steps = 60;
var smoothMove_delay = 30;
var smoothMove_multiplier = 2.8;
var smoothMoves = new Array();

function smoothMove(obj, destx, desty) {
//	if (!statObj) statObj = document.getElementById('status');
//	if (!mathObj) mathObj = document.getElementById('mathstat');
	this.obj = obj;
	this.x = destx;
	this.y = desty;
	this.startx = parseInt(this.obj.style.left, 10) || 0;
	this.starty = parseInt(this.obj.style.top, 10) || 0;
	this.step = 0;
	this.steps = smoothMove_steps;
	this.delay = smoothMove_delay;
	this.started = false;
	this.index = smoothMoves.length;
	smoothMoves[smoothMoves.length] = this;
	this.moveNext = smoothMove__moveNext;
	this.go = smoothMove__go;
	this.stop = smoothMove__stop;
	this.remove = smoothMove__remove;
	this.onfinish = null;
}
function smoothMove__moveNext() {
	if (!this.started)
		this.go();
	this.step++;
	var newx, newy, powsteps, powstep;
	powsteps = Math.pow(this.steps, smoothMove_multiplier);
	powstep = Math.pow(this.steps - this.step, smoothMove_multiplier);
	newx = this.step >= this.steps ? this.x : ((this.startx - this.x) / powsteps * powstep + this.x);
	newy = this.step >= this.steps ? this.y : ((this.starty - this.y) / powsteps * powstep + this.y);
//statObj.innerHTML = this.step + '/' + this.steps + ': ' + this.startx + ',' + this.starty + ' -&gt; ' + this.x + ',' + this.y + ' == ' + newx + ',' + newy;
//mathObj.innerHTML += this.step + ': ' + powsteps + ', ' + powstep + ', ' + (powsteps / powstep) + '<br/>';
	this.obj.style.left = newx + 'px';
	this.obj.style.top = newy + 'px';
	if (this.step < this.steps)
		setTimeout("smoothMoves[" + this.index + "].moveNext();", this.delay);
	else
		this.remove();
}
function smoothMove__go() {
//mathObj.innerHTML = '';
	this.started = true;
	if (this.x != this.startx || this.y != this.starty)
		setTimeout("smoothMoves[" + this.index + "].moveNext();", this.delay);
	else
		this.remove();
}
function smoothMove__stop() {
	this.started = false;
	this.remove();
}
function smoothMove__remove() {
	for (var i = this.index; i < smoothMoves.length - 1; i++)
		smoothMoves[i] = smoothMoves[i + 1];
	if (this.onfinish != null) this.onfinish();
}

// Coordinate mapping
var minXCoord, minYCoord, maxXCoord, maxYCoord;
minYCoord = 48.995055555555555555555555555556, maxYCoord = 46.600813888888888888888888888889;
minXCoord = -123.18513888888888888888888888889, maxXCoord = -120.26078055555555555555555555556;
var startY = 47.30565476, startX = -122.3074707; // Center of map


function searchNow(pgForm)
{
	newMap.clearPins();
	newMap.hidePins();
	var xmlhttp =  null;
	//try and get the object
	try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
	catch (e) 
	{ 
		try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
		catch (e) 
		{ 
			try { xmlhttp = new XMLHttpRequest(); }
			catch (e) 
			{ xmlhttp = false; }
		}
	}
	if(xmlhttp)
	{
		//alert("/_layouts/pse/forms/getzips.aspx?zip="+pgForm.elements['zip'].value+"&radius="+pgForm.elements['radius'].value);

		//xmlhttp.open("GET","/_layouts/pse/forms/getzips.aspx?zip="+pgForm.elements['zip'].value+"&radius="+pgForm.elements['radius'].value,false);
		xmlhttp.open("GET","/forms/getzips.aspx?zip="+pgForm.elements['zip'].value+"&radius="+pgForm.elements['radius'].value,false);
		xmlhttp.send(null);
		var returntext = xmlhttp.responseText;
		//alert(returntext);
		
		var objZipResults = document.getElementById('zipresults');
		objZipResults.innerHTML = returntext;
		//get coords
		//xmlhttp.open("GET","/_layouts/pse/forms/getzips.aspx?zip="+pgForm.elements['zip'].value+"&action=coords",false);
		xmlhttp.open("GET","/forms/getzips.aspx?zip="+pgForm.elements['zip'].value+"&action=coords",false)
		xmlhttp.send(null);
		var returntext = xmlhttp.responseText;
		//alert(returntext);
		
		var LatLong = returntext.split(";");
		if(LatLong[1] != '0' && LatLong[0] != '0')
		{
		    newMap.moveToCoord(new coord(LatLong[1]*1, LatLong[0]*1)); 
		}
        if(pgForm.elements['zip'].value != '')
        {
		xmlhttp.open("GET","/forms/getzips.aspx?zip="+pgForm.elements['zip'].value+"&radius="+pgForm.elements['radius'].value+"&action=pins",false);
		xmlhttp.send(null);
		var returntext = xmlhttp.responseText;
		if(returntext.length > 0)
		{
			if(returntext.indexOf("||") > -1)
			{
				var pinArray = returntext.split("||");
				for(var i = 0; i < pinArray.length; i++)
				{
					var pinSplit = pinArray[i].split(";");
					newMap.createPin(pinSplit[0],pinSplit[1],pinSplit[2],pinSplit[3], new coord(pinSplit[4]*1,pinSplit[5]*1));
				}
			}
			else
			{
				var pinSplit = returntext.split(";");
				newMap.createPin(pinSplit[0],pinSplit[1],pinSplit[2],pinSplit[3], new coord(pinSplit[4]*1,pinSplit[5]*1));
			}
		}
		newMap.showPins();
		}
	}
}


	
	

