<!-- Copyright © 2002-2003  Terrafin Software.  All rights reserved.
// mark point drawing characteristics
var fillWidth = 22;
var fillHeight = 16;
var fontSize = 11;
var polygonSize = 5;
// =====
var hilightedPoint = -1;
var chart = document.getElementById("chart");
var cstatus = document.getElementById("statusBox");
var chartPanel = document.getElementById("chartInfoPanel");
var tempDiv = document.getElementById("tempDiv");
var curr_Img;
var DrawRoute = 0;
var Lat = 0;
var Lon = 0;
var yCorner = 41;
var xCorner = 104 - xFix;
var yOffset = 0;
var xOffset = 0;
var ScaleHeight = 0;
var ScaleWidth = 0;
var MidLat = 0;
var MidHeight = 0;
var LatDegrees = 0;
var LatMins = 0;
var LonDegrees = 0;
var LonMins = 0;
var ScaleLat = 0;
var ScaleLon = 0;
var FormattedLat = '';
var BottomEdge = 0;
var RightEdge = 0;
var DegreesChar = String.fromCharCode(176);
var MinsChar = String.fromCharCode(180);
var curY = 0;
var curX = 0;
var lastMarkerX = -1, lastMarkerY = -1;
var TopEdge = 0;
var LeftEdge = 0;
var TheChart = '';
var TheLatLon = '';
var oLat = 0;
var oLon = 0;
var dLat = 0;
var dLon = 0;
var distance = 0;
var oclick = 0;
var ajaxWait = 0;
var FormattedDistance = '';
var FormattedDegrees = '';
var OriginX = 0;
var OriginY = 0;
var FormattedOrigin = '';
var NorthSouth = '';

var markPointArray = new Array();
var chg = 2;  // you can change this number to  alter the amount of magnification
var w;  // identifies the width
var h;  // identifies the height
var orig_w;  // placeholder for the original img width
var orig_h;  // placeholder for the original img height
var state=0;  // keeps a count in case an img is clicked more than once
var zoomfactor=1;
var ochartHeight = chartHeight;
var ochartWidth = chartWidth;
var oyCorner = yCorner;
var oxCorner = xCorner;
var waitForMarkerClick = 0;
var markerPointCount = 0;
var markerCurrentLabel = 1;

var IE = (document.all) ? true : false;
var ns4 = (document.layers)? true:false

var jg = new jsGraphics("chartpage");
// jg.setPrintable(true);

// var OpSys = checkOS();
var browserName = navigator.appName;
var browserVersion = parseInt(navigator.appVersion);

var ChartFileName = document.getElementById("chart").nameProp;
var isAltimetry = 0;
//isAltimetry = ChartFileName.indexOf("alt")
// using the title works for loops too
isAltimetry = document.title.indexOf("Altimetry")


// document.write(OpSys);

// document.onkeypress=checkKeys;


ScaleHeight = HiLat - LoLat;
ScaleWidth = HiLon - LoLon;
MidLat = Math.floor((HiLat + LoLat) / 2);
MidHeight = Math.floor(ScaleHeight/2);

// alert (document.title);
// alert (isAltimetry);
// alert (MidLat);
// alert (MidHeight);


if (IE) {
TopEdge = chart.offsetTop + yCorner + 1;
LeftEdge = chart.offsetLeft + xCorner + 1 ;
}
else {
	
	if (browserVersion==5) {
		TopEdge = document.images[0].offsetTop + yCorner;
		LeftEdge = document.images[0].offsetLeft + xCorner;
 	}
	else {
		if (ns4) {
			TopEdge = document.chartpage.document.images[0].y + yCorner;
			LeftEdge = document.chartpage.document.images[0].x + xCorner;
		}
		else {
			TopEdge = document.images[0].y + yCorner;
			LeftEdge = document.images[0].x + xCorner;
		}
	}
}

yOffset = TopEdge;
xOffset = LeftEdge;

BottomEdge = chartHeight + yOffset;
RightEdge = chartWidth + xOffset;


if (!IE) document.captureEvents(Event.MOUSEMOVE | Event.MOUSEDOWN);
document.onmousemove=getLatLon;

if (ns4) {
//	document.chartpage.document.images[0].onmousedown = getOriginCoords;  // this works with NS4
}
else {
	//document.images[0].onmousedown = getOriginCoords;  // this works with IE5 and NS6
}

function whichElement(e)
{
	var targ;
	if (!e)
	{
		var e = window.event;
	}
	if (e.target)
	{
		targ = e.target;
	}
	else if (e.srcElement)
	{
		targ = e.srcElement;
	}
	if (targ.nodeType == 3)
	{
		targ = targ.parentNode;
	}
  return targ;
}
	
function getOriginCoords() {
	if (oclick != 0) {
		oLat = LatDegrees + (LatMins / 60);
		oLon = LonDegrees + (LonMins / 60);
		markOrigin(curX, curY);
		FormattedOrigin = '(' + Math.abs(LatDegrees) + DegreesChar + ' ' + LatMinsString + '.' + LatSecsString + MinsChar + ' ' + NorthSouth + ' / ' + LonDegrees + DegreesChar + ' ' + LonMinsString + '.' + LonSecsString + MinsChar + ' W)';

	}
	if(waitForMarkerClick != 0){
		if(hilightedPoint != -1 && DrawRoute == 0) return;
		if(hilightedPoint != -1){
			var thePoint = markPointArray[hilightedPoint];
			if(thePoint[0] == lastMarkerX && thePoint[1] == lastMarkerY) return;
		}
		dLat = LatDegrees + (LatMins / 60);
		dLon = LonDegrees + (LonMins / 60);
		showPopup(curX, curY, "markPoint(" + curX + ", " + curY + ", getPopupText()" + ", " + fillWidth + " , " + fillHeight + ", " + polygonSize + " ," + fontSize +")");
		//markPoint(curX, curY);
	}
}


function resetBoundaries()  {
//alert ("in resetBoundaries");
yCorner = oyCorner * zoomfactor;
xCorner = oxCorner * zoomfactor;
chartHeight=ochartHeight * zoomfactor;
chartWidth=ochartWidth * zoomfactor;
//alert (zoomfactor);

if (IE) {
TopEdge = chart.offsetTop + yCorner + 1;
LeftEdge = chart.offsetLeft + xCorner + 1 ;
}
else {
	
	if (browserVersion==5) {
		TopEdge = document.images[0].offsetTop + yCorner;
		LeftEdge = document.images[0].offsetLeft + xCorner;
 	}
	else {
		if (ns4) {
			TopEdge = document.chartpage.document.images[0].y + yCorner;
			LeftEdge = document.chartpage.document.images[0].x + xCorner;
		}
		else {
			TopEdge = document.images[0].y + yCorner;
			LeftEdge = document.images[0].x + xCorner;
		}
	}
}

yOffset = TopEdge;
xOffset = LeftEdge;

BottomEdge = chartHeight + yOffset;
RightEdge = chartWidth + xOffset;
}




function getLatLon(e) {
// Copyright © 2002-2003  Terrafin Software.  All rights reserved.
checkOnce1(e);
if (IE) {
   curY=event.clientY+document.body.scrollTop;
   curX=event.clientX+document.body.scrollLeft;
   Lat=event.clientY+document.body.scrollTop-yOffset;
    Lon=event.clientX+document.body.scrollLeft-xOffset;
  }
  else {
    curX=e.pageX;
    curY=e.pageY;
    Lat=e.pageY-yOffset;
    Lon=e.pageX-xOffset;
 }  

   ScaleLat = (Lat * ScaleHeight)/chartHeight;
   ScaleLon = (Lon * ScaleWidth)/chartWidth;

 if (curY < yOffset || curY > BottomEdge || curX < xOffset || curX> RightEdge) {
    Lat=0;
    Lon=0;
    FormattedLat='';
    FormattedLon='';
  }
  else {
     Lat = ScaleHeight - ScaleLat + LoLat;
     Lon = ScaleWidth - ScaleLon + LoLon ;     

//some kind of workaround for large regions, funky but better than nothing
	if (isAltimetry >= 0) {
		if (ScaleHeight > 400) {
			if (Lat >= MidLat) {
//				Lat = Lat + ((HiLat-Lat)* (MidHeight/10000))	;
				Lat = Lat + ((HiLat-Lat)* (HiLat*1.2/100000))	;
			}
			else {
//				Lat = Lat + ((Lat-LoLat)* (MidHeight/10000))	;
				Lat = Lat + ((Lat-LoLat)* (HiLat*1.2/100000))	;
			}	

		}			
	}
     dLat = Lat/60;
     dLon = Lon/60;	 	
 
 // if negative value, south latitudes    
     if (Lat < 0) {
     		LatDegrees = Math.ceil(Lat/60);
     }
     else {
     		LatDegrees = Math.floor(Lat/60);
     }
     
     LatMins = Lat - (60*LatDegrees);

     if (LatMins < 0) {
     		TheMins = Math.ceil(LatMins);
     }
     else {
     		TheMins = Math.floor(LatMins);
     }

     if (Math.abs(TheMins) < 10) {
     	  LatMinsString = '0' + Math.abs(TheMins);
     }
     else {
        LatMinsString = Math.abs(TheMins);
     }	
     TheSecs = LatMins - TheMins;	
     TheSecs = Math.round(TheSecs*100);
     if (Math.abs(TheSecs) < 10) {
     	  LatSecsString = '0' + Math.abs(TheSecs);
     }
     else {
        LatSecsString = Math.abs(TheSecs);
     }	
     
     if (LatDegrees < 0) {
     		NorthSouth = 'S';
     }
     else {
     		NorthSouth = 'N';
     }
     
     FormattedLat = Math.abs(LatDegrees) + DegreesChar + ' ' + LatMinsString + '.' + LatSecsString + MinsChar + ' ' + NorthSouth ;		

     LonDegrees = Math.floor(Lon/60);
     LonMins = Lon - (60*LonDegrees);
     TheMins = Math.floor(LonMins);
     if (TheMins < 10) {
     	  LonMinsString = '0' + TheMins;
     }
     else {
        LonMinsString = TheMins;
     }	
     TheSecs = LonMins - TheMins;	
     TheSecs = Math.round(TheSecs*100);
     if (TheSecs < 10) {
     	  LonSecsString = '0' + TheSecs;
     }
     else {
        LonSecsString = TheSecs;
     }	
     FormattedLon = LonDegrees + DegreesChar + ' ' + LonMinsString + '.' + LonSecsString + MinsChar + ' W';		

 }

  if (FormattedLat != '' || FormattedLon != '') {
	TheLatLon = FormattedLat + ' / ' + FormattedLon;
  } 
  else {
	TheLatLon = '';
  }
  
//oLat = 27;
//oLon = 77;

if (oLat != 0 && !DrawRoute) {
	getDistance();
	HeadingAndDistance = '   Distance: ' + FormattedDistance + '  Bearing: ' + FormattedDegrees + '  from origin ' + FormattedOrigin;
}
else {
	HeadingAndDistance = '';
}
	
if (TheLatLon != '') {
	setTemp((curX - LeftEdge + xCorner)/zoomfactor, (curY - TopEdge + yCorner)/zoomfactor, "tempDiv", false);
	if(oclick == 1) {
		if(cstatus != undefined)cstatus.firstChild.firstChild.data = "Click a position on the chart to specify your origin...";

	}
	else {
		if(cstatus != undefined)cstatus.firstChild.firstChild.data = TheLatLon + '   ' + HeadingAndDistance;
	}
	
//    if (zoomfactor > 1) {
//			if (IE) {
//				window.status = TheLatLon + '   ' + HeadingAndDistance;
//			}
//		}


 }
else {
	if(cstatus != undefined)cstatus.firstChild.firstChild.data = '';

//    if (zoomfactor > 1) {
//				window.status = TheLatLon;
//		}

}


 // document.Coordinates.Latitude.value=FormattedLat ;
 // document.Coordinates.Longitude.value=FormattedLon;
 // document.Coords.XCoord.value=curX;
 // document.Coords.YCoord.value=curY;  


return true;
}

function getDistance() {
	var pi = 3.14159265;
	var DLo = 0;
	var x = 0;
	var y = 0;
	var res = 0;
	var deg = 0;
	var LatDiff = 0;
 	var LatDiffMins = 0;
	var HalfLatDiff = 0;
	var lm = 0;
	var DLo = 0;
	var DLoMins = 0;
	var p = 0;
	var CRads = 0;
	var CDegrees = 0;
	var Direction1 = '';
	var Direction2 = '';
	var Heading = 0;
	var MagDegrees = 0;


	oLatRads = oLat * (pi / 180);
	oLonRads = oLon * (pi / 180);
	dLatRads = dLat * (pi / 180);
	dLonRads = dLon * (pi / 180);
	
	x = oLonRads - dLonRads;
	if (x < 0) {
		x = -1*x;
	}

	if (x > pi) {
		x = 2 * pi - x;
	}

	DLo = x;
	y = Math.sin(dLatRads) * Math.sin(oLatRads) + Math.cos(dLatRads) * Math.cos(oLatRads) * Math.cos(x);
	res = Math.atan(-1*y / Math.sqrt(-1*y*y+1)) + 1.5708;

	deg = res * 180 / pi;
	distance = res * 3437.74677;
	FormattedDistance = (Math.round(distance*10))/10 + " NM";

	LatDiff = Math.abs(oLat - dLat);

	if (LatDiff == 0) {
		LatDiff = .000000001;
	}

	LatDiffMins = LatDiff * 60;
	HalfLatDiff = LatDiff / 2;
	lm = Math.abs(oLat - HalfLatDiff);
	DLo = Math.abs(oLon - dLon);
	DLoMins = DLo * 60;
	lm = lm * pi / 180;
	p = DLoMins * Math.cos(lm);
	CRads = Math.atan(p / LatDiffMins);
	CDegrees = CRads * 180 / pi;

	if (oLat > dLat) {
		Direction1 = "S";
	} else {
		Direction1 = "N";
	}

	if (oLon < dLon) {
		Direction2 = "W";
	} else {
		Direction2 = "E";
	}

	Heading = Direction1 + Direction2;

	if (Heading == "NW") CDegrees = 360 - CDegrees;
	if (Heading == "NE") CDegrees = CDegrees;
	if (Heading == "SW") CDegrees = 180 + CDegrees;
	if (Heading == "SE") CDegrees = 180 - CDegrees;

	MagDegrees = CDegrees + MagVar;
	
	if (MagDegrees < 0) MagDegrees = MagDegrees + 360;
	FormattedDegrees = Math.round(MagDegrees) + DegreesChar + " Mag.";
	




//window.defaultStatus = y + " " + res + " " + distance ;
return true;
}

function setoclickvalue() {
//alert ("set oclick=1")
	oclick=1;
	 ClearAll();
	oLat=0;

  resetZoom( ); 

}

function markOrigin(x,y)
{
 // jg.setPrintable(true);  // Problem in IE5?
  jg.setColor("red"); // green
  jg.fillEllipse(x-3, y-3, 7, 7); // co-ordinates related to the document
  jg.paint(); // draws, in this case, directly into the document

  OriginX = x;
  OriginY = y;
  oclick = 0;	

  resetZoom( ); 
}
function drawDottedLine(jg, x1, y1, x2, y2){
	var width = 5;
	var space = 3;
	var dx = Math.abs(x1 - x2), dy = Math.abs(y1 - y2);
	var xinc = (x1 < x2 ? 1 : -1);
	var yinc = (y1 < y2 ? 1 : -1);
	var drawn = 0;
	var notdrawn = 0;
	if(dx > dy) {
		var incr = dy / dx;
		var curx = x1, cury = y1;
		var err = 0;
		while(dx--){
			if(drawn < width) {
				jg._mkDiv(curx, cury, 2, 2);
				drawn++;
			}
			else {
				notdrawn++;
			}
			if(notdrawn == space){
				drawn = 0;
				notdrawn = 0;
			}
			err += incr;
			if(err > 0.5) {
				cury += yinc;
				err-=1;
			}
			curx += xinc;
		}
		return;
	}
	if(dx < dy) {
		var incr = dx / dy;
		var curx = x1, cury = y1;
		var err = 0;
		while(dy--){
			if(drawn < width) {
				jg._mkDiv(curx, cury, 2, 2);
				drawn++;
			}
			else {
				notdrawn++;
			}
			if(notdrawn == space){
				drawn = 0;
				notdrawn = 0;
			}
			err += incr;
			if(err > 0.5) {
				curx += xinc;
				err-=1;
			}
			cury += yinc;
		}
	}
}
function addMarkInfo(markLabel,comment){
	var trow = chartPanel.insertRow(chartPanel.rows.length);
	var cell1 = trow.insertCell(0);
	cell1.className = "PointIndexCellStyle";
	cell1.innerHTML = markLabel + ".";
	var cell2 = trow.insertCell(1);
	cell2.className = "LatLonCellStyle";
	cell2.innerHTML = TheLatLon;
	var cell3 = trow.insertCell(2);
	cell3.className = "TempCellStyle";
	cell3.innerHTML = "Temp: <span id=\"tempDiv_" + markerPointCount + "\"></span>";
	var cell4 = trow.insertCell(3);
	cell4.className = "DistanceCellStyle";
	var cell5 = trow.insertCell(4);
	cell5.className = "CommentCellStyle";

	if(oLat != 0 && DrawRoute == 1){
		getDistance();
		cell4.innerHTML = FormattedDistance + " " + FormattedDegrees;
	}
	if(comment != null && comment.length > 0)
		cell5.innerHTML = "note: " + comment;

	setTemp((curX - LeftEdge + xCorner), (curY - TopEdge + yCorner), ("tempDiv_" + markerPointCount), true);

	if(DrawRoute == 1){
		oLat = dLat;
		oLon = dLon;
	}
}
function urlencode(s) {
  s = encodeURIComponent(s);
  return s.replace(/~/g,'%7E').replace(/%20/g,'+');
 }
function writePostData(){
	var hiddenLabels = document.getElementById("labelsInput");
	var hiddenXCoords = document.getElementById("xCoordsInput");
	var hiddenYCoords = document.getElementById("yCoordsInput");
	var hiddenChartPanel = document.getElementById("chartPanelInput");
	var hiddenDrawRoutes = document.getElementById("drawRoutesInput");
	hiddenLabels.value = hiddenXCoords.value = hiddenYCoords.value = hiddenDrawRoutes.value = "";
	for(var i = 1; i < markPointArray.length; i++){
		var thePoint = markPointArray[i];
		var x = thePoint[0];
		var y = thePoint[1];
		var label = thePoint[5];
		hiddenXCoords.value += (x - LeftEdge + xCorner) + ",";
		hiddenYCoords.value += (y - TopEdge + yCorner) + ",";
		hiddenLabels.value += label +",";
	}
	hiddenChartPanel.value = chartPanel.innerHTML;
	hiddenDrawRoutes.value = DrawRoute == 1 ? "yes" : "no";
}
function markPoint(x, y, comment, fillWidth, fillHeight, polygonSize, fontSize){
	if(ajaxWait) return;
	if(TheLatLon == '') return;
	ajaxWait = 1;
	document.body.style.cursor = "wait";
	setTimeout(function() { ajaxWait = 0; document.body.style.cursor = "default";}, 1000);
	markerPointCount++;

	// check if user clicked on existing point
	if(hilightedPoint != -1){
		var oldPoint = markPointArray[hilightedPoint];
		if(DrawRoute == 1 && lastMarkerX != -1){
			jg.setZIndex("0");
			drawDottedLine(jg, lastMarkerX, lastMarkerY, oldPoint[0], oldPoint[1]);
			jg.paint();
		}
		dLat = oldPoint[2];
		dLon = oldPoint[3];
		lastMarkerX = oldPoint[0];
		lastMarkerY = oldPoint[1];
		TheLatLon = oldPoint[4];
		addMarkInfo(oldPoint[5], comment);
		markPointArray.push(new Array(oldPoint[0], oldPoint[1], dLat, dLon, TheLatLon, oldPoint[5]));
	} else {
		var xText = x - 15 - 6 * markerCurrentLabel / 10;
		markPointArray.push(new Array(curX, curY, dLat, dLon, TheLatLon, markerCurrentLabel));
		if(lastMarkerX != -1 && DrawRoute == 1) {
			jg.setZIndex("0");
			drawDottedLine(jg, lastMarkerX, lastMarkerY, curX, curY);
		}
		fwidth = fillWidth + 6 * markerPointCount / 10;
		var newdiv = document.createElement("div");
		newdiv.id = "borderMkDiv" + markerPointCount;
		newdiv.style.zIndex = (markerPointCount - 1) * 2 + 1;
		newdiv.style.display = "none";
		newdiv.style.backgroundColor = "rgb(255,0,255)";
		newdiv.style.position = "absolute";
		newdiv.style.left = xText-2;
		newdiv.style.top = y - fillHeight / 2 -2;
		newdiv.style.width = fwidth +4;
		newdiv.style.height = fillHeight+4;
		document.body.appendChild(newdiv);
		jg.setZIndex(markerPointCount * 2);
		if (DrawRoute == 1) {
			jg.setColor("#ffaaff");
			jg.fillRect(xText, y - fillHeight / 2, fwidth, fillHeight, "mkDiv" + markerPointCount);
		}
		jg.setColor("#aa00aa");
		jg.fillPolygon(new Array(x - polygonSize + 1, x, x + polygonSize - 1, x), new Array(y, y - polygonSize + 1, y, y + polygonSize - 1), "mkDiv" + markerPointCount);
		jg.setColor("#550055");
		jg.drawPolygon(new Array(x - polygonSize, x, x + polygonSize, x), new Array(y, y - polygonSize, y, y + polygonSize), "mkDiv" + markerPointCount);

		jg.setFont("", fontSize + "pt", Font.BOLD);
		jg.setColor("#aa00aa");
		jg.drawString(markerCurrentLabel, xText, y - fontSize, "mkDiv" + markerPointCount);
		jg.paint();
		addMarkInfo(markerCurrentLabel++, comment);
		lastMarkerX = curX;
		lastMarkerY = curY;
		
	}
}


function ClearAll()
{
	 if (jg) jg.clear() ;
 
   	if (ns4) {
		//document.onmousedown = getOriginCoords;
	 	 //document.chartpage.document.images[0].onmousedown = getOriginCoords;  // this works with NS4
  	}
 	 else {
		 //document.images[0].onmousedown = getOriginCoords;  // this works with IE5 and NS6
 	 }

 resetZoom( );
}


function resetZoom()  {
	state = 0;
	zoomfactor = 1;
	resetBoundaries( ) ;
	orig_size(chart);
}


function checkOS() {
  if(navigator.userAgent.indexOf('IRIX') != -1)
    { var OpSys = "Irix"; }
  else if((navigator.userAgent.indexOf('Win') != -1) &&
  (navigator.userAgent.indexOf('95') != -1))
    { var OpSys = "Windows95"; }
  else if(navigator.userAgent.indexOf('Win') != -1)
    { var OpSys = "Windows"; }
  else if(navigator.userAgent.indexOf('Mac') != -1)
    { var OpSys = "Macintosh"; }
  else { var OpSys = "other"; }
  return OpSys;
}

function clearOrigin( ) {
	if (zoomfactor == 1) {
	 	if (jg) jg.clear() ;
	}
}

function zoom_in(this_Img) {
	// this function increases the size of the image
  curr_Img = chart;
//	curr_Img = this_Img;  getting rid of this variable, not working in safari
	state++;
	zoomfactor++;
        if (zoomfactor > 4) zoomfactor = 4;	//maximum zoom 4x
	if (state == 1) {
		orig_w = curr_Img.width;
		orig_h = curr_Img.height;
	}

	curr_Img.width = orig_w * zoomfactor;
	curr_Img.height = orig_h * zoomfactor;

	resetBoundaries( ) ;
//alert (chartWidth) ;

}

function zoom_out(this_Img) {
	// this function decreases the size of the image
	curr_Img = chart;
//	curr_Img = this_Img;
	zoomfactor--;
        if (zoomfactor < 1) zoomfactor = 1;	//minimum original size
	curr_Img.width = orig_w * zoomfactor;
	curr_Img.height = orig_h * zoomfactor;

	resetBoundaries( ) ;
//alert (chartWidth) ;

}
function orig_size(orig_Img) {
	// this function returns the image to original size
	if(curr_Img != undefined) {
		curr_Img.width = orig_w;
		curr_Img.height = orig_h;
		state = 0;
		zoomfactor = 1;
		resetBoundaries( ) ;
	}
}

function checkKeys(e) {
	if (document.all) {
		e = window.event ;
	}
	
	var key;

	if (document.layers) {
		key = e.which;
	}
	if (document.all) {
		key = e.keyCode;
	}

	if (key == 27) {
//alert (key);
		resetZoom() ;
	}
				



}
function WaitForMarkerClick(enabled){
	for(var i = chartPanel.rows.length - 1; i >= 0; i--){
		chartPanel.deleteRow(i);
	}
	var allDivs = document.getElementsByTagName("div");
	var ok = 1;
	while(ok) {
		ok = 0;
		for(var i = 0; i < allDivs.length; i++){
			var theDiv = allDivs[i];
			if(theDiv.id.indexOf("borderMkDiv") != -1){
				theDiv.parentNode.removeChild(theDiv);
				ok = 1;
				break;
			}
		}
	}

	hilightedPoint = -1;
	markPointArray = new Array(new Array(0,0));
	var hiddenXCoords = document.getElementById("xCoordsInput");
	var hiddenYCoords = document.getElementById("yCoordsInput");
	var hiddenChartPanel = document.getElementById("chartPanelInput");
	var hiddenDrawRoutes = document.getElementById("drawRoutesInput");
	hiddenXCoords.value = hiddenYCoords.value = hiddenChartPanel.value = "";
	hiddenDrawRoutes.value = "no";
	waitForMarkerClick = enabled;
	markerPointCount = 0;
	markerCurrentLabel = 1;
	ClearAll();
	DrawRoute = 0;
	resetZoom();
	oLat = 0;
	lastMarkerX = -1;
}
function checkEnter(e){
	var characterCode;
	if(e && e.which){
		e = e
		characterCode = e.which;
	}
	else{
		e = event;
		characterCode = e.keyCode;
	}

	if(characterCode == 13){
		document.getElementById("popupBoxButton").click();
		return false;
	}
	else{
		return true;
	}
}

window.onscroll = function() { var sbox = document.getElementById("statusBox"); if(sbox != null && IE) sbox.style.left = document.body.scrollLeft; }
function checkOnce1(e) {
	var target = whichElement(e);
	if(hilightedPoint != -1){
		var hiDiv = document.getElementById("borderMkDiv" + hilightedPoint);
		hiDiv.style.display = "none";
		hilightedPoint = -1;
	}
	if(target.className.indexOf('mkDiv') != -1){
		var index = target.className.substring(5);
		hilightedPoint = index;
		var borderDiv = document.getElementById("borderMkDiv" + index);
		borderDiv.style.display = "inline";
	}
}
document.onmousedown = function(e) {
	var target = whichElement(e);
	if(target.id == 'chart' || target.className.indexOf('mkDiv') != -1){
		getOriginCoords();
		oclick = 0 ;
		return false;
	}
	return true;
}
// Copyright © 2002-2006  Terrafin Software.  All rights reserved. -->
