/* author: richardh@mcphcity-bpu.com */
/* Generated by AceHTML Freeware http://freeware.acehtml.com */
/* Creation date: 6/14/2004 */
var mouseDrag = false;
var overID;
var atRow;
var atCol;
var begRow;
var endRow;
var begCol;
var endCol;

var hiColor = '#FFFF99';
var normColor = '#99FFFF';

function clearRow (r) {
	var i;
	if ((r < 1) || (r > 6)) return;
	for (i = 1; i <= 6; i++)
	  {
	    var obj = document.getElementById (r + '-' + i);
		obj.style.backgroundColor = normColor;
		obj.style.fontWeight = 'normal';
	  }
	return;
}

function clearCol (c) {
	var i;
	if ((c < 1) || (c > 6)) return;
	for (i = 1; i <= 6; i++)
	  {
	    var obj = document.getElementById (i + '-' + c);
		obj.style.backgroundColor = normColor;
		obj.style.fontWeight = 'normal';
	  }
	return;
}

function drawRect() {
var r = (endRow > begRow) ? begRow : endRow;
var c = (endCol > begCol) ? begCol : endCol;
var h = (endRow > begRow) ? endRow : begRow;
var w = (endCol > begCol) ? endCol : begCol;
var i;
var j;

clearRow (r - 1);
clearRow (h + 1);
clearCol (c - 1);
clearCol (w + 1);

for (i = r; i <= h; i++)
	for (j = c; j <= w; j++)
	  {
		var obj = document.getElementById (i + '-' + j);
		obj.style.backgroundColor = hiColor;
		obj.style.fontWeight = 'bold';
	  }
return;
}

function clearMap() {
	var r;
	var c;

	for (r=1; r<=6; r++)
	  for (c = 1; c <= 6; c++)
	    {
		  var obj = document.getElementById (r + '-' + c);
		  obj.style.backgroundColor = normColor;
		  obj.style.fontWeight = 'normal';
		}
	return true;
}

function getCellID (x, y) {

	var dragX;
	var dragY;

	var mapX = document.getElementById ('map').offsetLeft;
	var mapY = document.getElementById ('map').offsetTop;
	var mapW = document.getElementById ('map').offsetWidth;
	var mapH = document.getElementById ('map').offsetHeight;
	var w = mapW / 6;
	var h = mapH / 6;

    //status = "X:" + x + " Y:" + y + " MapX:" + mapX + " Y:" + mapY;

	x = x - mapX;
	y = y - mapY;

	if ((x < 0) || (y < 0) || (x > mapW) || (y > mapH)) return false;

	for (c=0; c<6; c++)
	  {
		if ((x > (c * w)) && (x <= ((c + 1) * w)))
		  {
		  	dragX = c + 1;
			break;
		  }
	  }
	
	for (r=0; r<6; r++)
	  {
		if ((y > (r * h)) && (y <= ((r + 1) * h)))
		  {
		  	dragY = r + 1;
			break;
		  }
	  }

	atRow = dragY;
	atCol = dragX;
	  
	return true;
}

function onMouseDown (e) {
	var x = (is.ns) ? e.pageX : event.x + document.body.scrollLeft;
	var y = (is.ns) ? e.pageY : event.y + document.body.scrollTop;

	clearMap();

	if (!getCellID (x, y)) return true;

	begRow = endRow = atRow;
	begCol = endCol = atCol;

	drawRect ();
	
	mouseDrag = true;
	
	return false;	
}

function onMouseMove (e) {

	if (!mouseDrag) return true;

	var x = (is.ns) ? e.pageX : event.x + document.body.scrollLeft;
	var y = (is.ns) ? e.pageY : event.y + document.body.scrollTop;

	if (!getCellID (x, y)) return true;

	endRow = atRow;
	endCol = atCol;
	
	drawRect();
	
	return false;
}

function onMouseUp (e) {

	if (!mouseDrag) return true;

	var x = (is.ns) ? e.pageX : event.x + document.body.scrollLeft;
	var y = (is.ns) ? e.pageY : event.y + document.body.scrollTop;

	if (!getCellID (x, y)) return true;

	endRow = atRow;
	endCol = atCol;
	
	mouseDrag = false;

	var begE = (begCol < endCol) ? begCol : endCol;
	var endE = (begCol < endCol) ? endCol : begCol;
	var begS = (begRow < endRow) ? begRow : endRow;
	var endS = (begRow < endRow) ? endRow : begRow;

	begE = 4 * begE - 3;
	endE = 4 * endE + 1;

	begS = 4 * begS - 3;
	endS = 4 * endS + 1;

	//Increment south key to skip the letter 'I'
	if (begS > 8) begS ++;
	if (endS > 8) endS ++;

	parent.document.all("corners").src = "mapQuery.asp?txtTownship=" + frmTownship.txtTownship.value +
        "&txtRange=" + frmTownship.txtRange.value +
        "&begE=" + begE + "&endE=" + endE + "&begS=" + begS + "&endS=" + endS;
	parent.document.all("myData").src = "twnshpInfo.asp?txtTownship=" + frmTownship.txtTownship.value +
        "&txtRange=" + frmTownship.txtRange.value +
        "&begE=" + begE + "&endE=" + endE + "&begS=" + begS + "&endS=" + endS;

	return true;
}

