function mousemove_handler(x,y) {
 mapsizeArray = mapsize.split(' ');

 if (imgext != '' && mapext == '') {
  	imgextArray = imgext.split(' ');
 }
 else if (mapext != '' && imgext == '') {
   	imgextArray = mapext.split(' ');
  }
 else if (mapext != '' && imgext != '') {
   	imgextArray = mapext.split(' ');
  }
 else {
 	imgextArray = '';
 }

 if (imgextArray != '')	{
 	coordx = imgextArray[0]*1 + 
	(x*(imgextArray[2]-imgextArray[0])/mapsizeArray[0]);
 	coordy = imgextArray[3] - 
	(y*(imgextArray[3]-imgextArray[1])/mapsizeArray[1]);
 }
 else {
	coordx = '';
	coordy = '';
 }

 document.getElementById("StatusLayer1").innerHTML = " X: " + Math.round(coordx) + " Y: " + Math.round(coordy) + " - Bayfield County Coordinate System";
 
 }
function mouseenter_handler()	{	}


function mouseexit_handler()	{
 //document.getElementById("StatusLayer2").innerHTML = "";
 document.getElementById("StatusLayer1").innerHTML = "";

} 

//  function measure_handler(name, s, t, n, a) {  



  function reset_handler(minx, miny, maxx, maxy) {  }


    function measure_handler(s, t, n, a) {  
     // c = 1 / 72dpi / 12inches_per_foot * 1.0003state_plane_scale_factor
     var c = 0.0011577546296296;	// constant
     var f = currscale * c;		// scale factor
     if (n==1) {
      document.getElementById("StatusLayer2").innerHTML = "Click to continue drawing line"
      }
     if ((s>0) || (t>0)) {
	   document.getElementById("StatusLayer2").innerHTML = "Segment:  " + Math.round(s*f) + " ft, Total:  " + Math.round(t*f) + " ft";
     }

}

  function area_handler(a, d, l, n) {   
   
    var c = 0.0011577546296296;	// constant
    var f = currscale * c;		// scale factor
    if ((n==1) || (n==2)) {
      document.getElementById("StatusLayer2").innerHTML = "Click to continue drawing shape"
      }
    if (n > 2) {
      var text = "Area:  " + Math.round(100*f*f*a*0.000022957)/100 + " acres";
      document.getElementById("StatusLayer2").innerHTML =text;
      }
  }
  
  function fullExtent() {
    var c_value = "";
    for (var i=0; i < document.mapserv.layers.length; i++) {
      if (document.mapserv.layers[i].checked) {
        c_value = c_value + "&layers=" + document.mapserv.layers[i].value;
      }
    }
    var theURL;
    theURL = "/cgi-bin/mapserv.exe?zoomsize=2&mapBox=on&mode=browse&zoomdir=1&map=e:/landrecords/mapviewer/bcmv4101.map" + c_value;
  	 window.location = theURL;
  }
  
   function fullExtent_sv() {
    var theURL;
    theURL = "/cgi-bin/mapserv.exe?zoomsize=2&mapBox=on&mode=browse&zoomdir=1&map=e:/landrecords/mapviewer/bcsv4101.map"
   	window.location = theURL;
  }
  
   function fullExtent_rv() {
    var theURL;
    theURL = "/cgi-bin/mapserv.exe?zoomsize=2&mapBox=on&mode=browse&zoomdir=1&map=e:/landrecords/mapviewer/bcrv4101.map"
   	window.location = theURL;
  }
  
  function zoommcd(newExt) {
   document.mapserv.mode.value = 'browse';
   document.mapserv.mapext.value = newExt;
   document.mapserv.submit();
  }
  
function pan(direction, pansize) {
     var x, y;
 
     var width  = 500;
     var height = 350;
  
     if(direction == 'n') {
       x = (width-1)/2.0; // x
       y = 0 - (height * pansize)/2.0; // y
     }
     else if(direction == 'nw') {
       x = 0 - (width * pansize)/2.0; // x
       y = 0 - (height * pansize)/2.0; // y
     }
     else if(direction == 'ne') {
       x = (width-1) + (width * pansize)/2.0; // x
       y = 0 - (height * pansize)/2.0; // y
     }
     else if(direction == 's') {
       x = (width-1)/2.0; // x
       y = (height-1) + (height * pansize)/2.0; // y
     } 
     else if(direction == 'sw') {
       x = 0 - (width * pansize)/2.0; // x
       y = (height-1) + (height * pansize)/2.0; // y
     } 
     else if(direction == 'se') {
       x = (width-1) + (width * pansize)/2.0; // x
       y = (height-1) + (height * pansize)/2.0; // y
     } 
     else if(direction == 'e') {
       x = (width-1) + (width * pansize)/2.0; // x
       y = (height-1)/2.0; // y
     } 
     else if(direction == 'w') {
       x = 0 - (width * pansize)/2.0; // x
       y = (height-1)/2.0; // y
     }
        
     // now build a url to call the MapServer nabbing whatever you might need from the
     // main form and setting imgxy to the values of x and y from above, then redirect
     // the browser to that location 
 
     // add layers to URL, checkboxes get updated by [*check] directives
 
       
     var newURL = baseURL + "&imgxy=" + x + "+" + y;
     location.href = newURL + "&zoomsize=1";
  }
 

  
function setbox_handler(minx, miny, maxx, maxy) {
  document.mapserv.imgbox.value = minx + " " + miny + " " + maxx + " " + maxy;
  document.mapserv.imgxy.value = minx + " " + miny;
  document.mapserv.submit();
}

function seterror_handler(message) { 
  alert(message);
}

    
  function newscale() {
   // if Win32, monitor is likely to be 96dpi, otherwise monitor is likely to be 72dpi
    if (navigator.platform == "Win32") {  
      document.mapserv.scale.value = document.mapserv.scalenum.value / 96 * 72;
    }
    
    else {
      document.mapserv.scale.value = document.mapserv.scalenum.value;
    }
    
   document.mapserv.mode.value = 'browse';  

   	imgextArray = mapext.split(' ');
   	coordx = imgextArray[0]*1 + ((imgextArray[2] - imgextArray[0]) / 2);
   	coordy = imgextArray[1]*1 + ((imgextArray[3] - imgextArray[1]) / 2);
   document.mapserv.mapxy.value = coordx+ " " +coordy;
   document.mapserv.submit();
  }
  
  function searchButton() {
  	if (document.mapserv.pinnum.value.length > 0) {
  		pinquery();}
    else if (document.mapserv.pinold.value.length > 0){
    	pinquery();}
    else if (document.mapserv.lastname.value.length > 0){
    	namequery();}
    else if ((document.mapserv.sec.value.length > 0) && (document.mapserv.twn.value.length > 0) && (document.mapserv.rng.value.length > 0)) {
     	trsquery();}
    else {
    	alert("Required value missing");}
  }
  
  function searchButton_sv() {
    var s = document.mapserv.sec.value
    var t = document.mapserv.twn.value
    var r = document.mapserv.rng.value
  	 if ((s.length >= 1) && (t.length >= 1) && (r.length >= 1)) {
     	trsquery();}
    else {
    	cornquery();}
  }
  
  function pinquery() {
    var errStatus=0;
    var theValue;
    if (document.mapserv.pinnum.value.length > 0) {
      theValue = trim(document.mapserv.pinnum.value);}
    else {
      theValue = trim(document.mapserv.pinold.value);}
    if ((document.mapserv.pinnum.value.length > 0)&&(document.mapserv.pinnum.value.length!=32)) {
      alert("PIN must be 23 digits");
      errStatus=1;
    }  
    if ((document.mapserv.pinold.value.length > 0)&&(document.mapserv.pinold.value.length!=12)) {
      alert("Old PIN must be 12 digits");
      errStatus=1;
    }     	
    	
    RegExp = /\s/ 
    while(RegExp.test(theValue)) {theValue = theValue.replace(" ","");}  
    RegExp = /-/ 
    while(RegExp.test(theValue)) {theValue = theValue.replace("-","");}  
    document.mapserv.mode.value = 'ITEMQUERY';
    document.mapserv.zoomdir.value = 1
    document.mapserv.qlayer.value = 'parcelsel';
    document.mapserv.qstring.value = theValue;
    document.mapserv.mapext.value='shapes';
    
    if (theValue.length == 12) {
      document.mapserv.qitem.value = 'comp_no';}
    else {
      document.mapserv.qitem.value = 'strippclno';}
    if (errStatus==0) {
  	  document.mapserv.submit();}
  }
  
  function gopin(thepin) {
    document.mapserv.pinnum.value = thepin
    pinquery()
  }
  
  function namequery() {
    document.mapserv.lastname.value = trim(document.mapserv.lastname.value)
    document.mapserv.lastname.value = document.mapserv.lastname.value.toUpperCase()
    document.mapserv.zoomdir.value = 1
    document.mapserv.qlayer.value = 'qlastname';
    //document.mapserv.map_qlastname_filter.value = "('[LASTNAME]'=~ /^%lastname%/)";
    document.mapserv.qitem.value = 'LASTNAME';
    document.mapserv.qstring.value = document.mapserv.lastname.value;
    document.mapserv.mode.value = 'ITEMNQUERY';
    document.mapserv.mapext.value = '564922.639745 292857.354452 933108.403634 616034.437785';
    document.mapserv.submit();
  }
   
  function trsquery() {
    document.mapserv.mode.value = 'itemnquery';
    document.mapserv.qlayer.value = 'qtrs';
    var errStatus=0;
    var d = "2"
    var s = document.mapserv.sec.value
    var t = document.mapserv.twn.value
    var r = document.mapserv.rng.value
    
    if ((s.length == 0) || (t.length == 0) || (r.length == 0)) {
  	  alert("Missing Section/Township/Range value");
  	  errStatus=1;
    }
    
    var sNum = parseFloat(s)
    if ((sNum > 36) || (sNum < 1)) {
      alert("Section value must be between 1 and 36");
     errStatus=1;
    }   	

    if (s.length == 1) {
  	  s='0'+s;
    }
    var tNum = parseFloat(t)
    if ((tNum > 52) || (tNum < 43)) {
      alert("Township value must be between 43 and 52");
     errStatus=1;
    }

    var rNum = parseFloat(r)
    if ((rNum > 9) || (rNum < 3)) {
      alert("Township value must be between 3 and 9");
     errStatus=1;
    }    
      
    if (r.length == 1) {
  	  r='0'+r;
    }
 
    document.mapserv.trs.value = d+t+r+s    
    document.mapserv.qitem.value='dtrs';
    document.mapserv.qstring.value = d+t+r+s;
    document.mapserv.mapext.value = '564922.639745 292857.354452 933108.403634 616034.437785'; 

    if (errStatus==0) {
      document.mapserv.submit();}
  }  

NS4 = (document.layers) ? true : false;
  
  function checkEnter(textbx,event)
  { 	
    var code = 0;
    var theVal;
	if (NS4) {
		code = event.which}
	else {
		code = event.keyCode}
	if (textbx==2){
		theVal = document.mapserv.pinnum.value
		if (code==45) {
			theVal = theVal;}
		else if (theVal.length==2||theVal.length==6){
			document.mapserv.pinnum.value = theVal + "-";}
		else if (theVal.length==8||theVal.length==11){
			document.mapserv.pinnum.value = theVal + "-";}
    else if (theVal.length==14||theVal.length==17){
			document.mapserv.pinnum.value = theVal + "-";}
    else if (theVal.length==19||theVal.length==22){
			document.mapserv.pinnum.value = theVal + "-";}
    else if (theVal.length==26) {
			document.mapserv.pinnum.value = theVal + "-";
		}
	}
	if (code==13){

	  if (textbx==1){
	    newscale()}
	  if (textbx==2){
	    pinquery()}
	  if (textbx==3){
	    namequery()}
	  if (textbx==4){
	    createMap(document.mapserv.maptitle.value)}
	  if (textbx==5){
	    trsquery()}  
	  if (textbx==6){
	    pinquery()}     }
		
  }

function checkEnter_sv(textbx,event)  { 	
   var code = 0;
   var theVal;
	if (NS4) {
		code = event.which}
	else {
		code = event.keyCode}
	if (code==13){
	  if (textbx==1){
	    newscale()}
	  if (textbx==2){
	    cornquery()}	    
	  if (textbx==3){
	    trsquery()}
 }
}


  function trsquery() {
    document.mapserv.mode.value = 'itemnquery';
    document.mapserv.qlayer.value = 'qtrs';
    var errStatus=0;
    var d = "2"
    var s = document.mapserv.sec.value
    var t = document.mapserv.twn.value
    var r = document.mapserv.rng.value
   
    if ((s.length == 0) || (t.length == 0) || (r.length == 0)) {
  	  alert("Missing Section/Township/Range value");
  	  errStatus=1;
    }
    
    var sNum = parseFloat(s)
    if ((sNum > 36) || (sNum < 1)) {
      alert("Section value must be between 1 and 36");
     errStatus=1;
    }   	

    if (s.length == 1) {
  	  s='0'+s;
    }
    var tNum = parseFloat(t)
    if ((tNum > 52) || (tNum < 43)) {
      alert("Township value must be between 43 and 52");
     errStatus=1;
    }

    var rNum = parseFloat(r)

    if ((rNum > 9) || (rNum < 3)) {
      alert("Range value must be between 3 and 9");
     errStatus=1;
    }    
   
    if (r.length == 1) {
  	  r='0'+r;
    }
    document.mapserv.mapext.value='shapes';
    document.mapserv.zoomdir.value = 1;
    document.mapserv.trs.value = d+t+r+s    
    document.mapserv.qitem.value='dtrs';
    document.mapserv.qstring.value = d+t+r+s;
    document.mapserv.qlayer.value = 'qtrs';

    if (errStatus==0) {
      document.mapserv.submit();
    }
  }

  function cornquery() {
    var errStatus=0;
    var tn = document.mapserv.cornid_tn.value;
    var rn = document.mapserv.cornid_rn.value;
    var sc = document.mapserv.cornid_sc.value;
    var rw = document.mapserv.cornid_rw.value;
    var cl = document.mapserv.cornid_cl.value;

   
    if ((tn.length == 0) || (rn.length == 0) || (sc.length == 0) || (rw.length == 0) || (cl.length == 0)) {
  	   alert("Missing Township/Range/Section/Row/Column value");
  	   errStatus=1;
    }
    else {
	    var tnNum = parseFloat(tn);
	    if ((tnNum > 52) || (tnNum < 43)) {
	      alert("Township value must be between 43 and 52");
	     errStatus=1;
	    }
	
	    var rnNum = parseFloat(rn);
	    if ((rnNum > 9) || (rnNum < 3)) {
	      alert("Range value must be between 3 and 9");
	     errStatus=1;
	    }    
	    if (rn.length == 1) {
	  	  rn='0'+rn;
	    }
	
	    var scNum = parseFloat(sc);
	    if ((scNum > 36) || (scNum < 1)) {
	      alert("Section value must be between 1 and 36");
	      errStatus=1;
	    }   	
	    if (sc.length == 1) {
	  	   sc='0'+sc;
	    }
	
	    var rwNum = parseFloat(rw);
	    if ((rwNum != 0) && (rwNum != 10) && (rwNum != 20) && (rwNum != 30)) {
	      alert("Invalid row value.  See Help");
	      errStatus=1;
	    }   	
	    if (rw.length == 1) {
	  	   rw='0'+rw;
	    }
	    
	    var clNum = parseFloat(cl);
	    if ((clNum != 0) && (clNum != 10) && (clNum != 20) && (clNum != 30)) {
	      alert("Invalid column value.  See Help");
	      errStatus=1;
	    }   	
	    if (cl.length == 1) {
	  	   cl='0'+cl;
	    }
  
    
	   var cornid = tn+rn+sc+rw+cl;
	   document.mapserv.mode.value = 'ITEMQUERY';
	   document.mapserv.zoomdir.value = 1;
	   document.mapserv.qlayer.value = 'cornsel';
	   document.mapserv.qstring.value = '([COR_ID]=' + cornid + ')';
	   document.mapserv.mapext.value='shapes';
	 }

    if (errStatus==0) {
      document.mapserv.submit();
    }
  }
 

  function toTitleCase(s) {
	var re1 = /(\w)(\w*)/;

	// Make an array of words that are in the input string
 	var a1 = s.split(/\s+/g);
 
	// Loop through each word
	for (i = 0; i < a1.length; i++ ) {
  		// Split word into first letter followed by the rest of word
  		var a2 = a1[i].match(re1); 
  		// Capitalize first character of word
  		a1[i] = a2[1].toUpperCase()+ a2[2].toLowerCase();
    }
  	// Return new string built from words in array, separated by spaces
	return a1.join(" ");
	}

  function trim(strText) { 
    // this will get rid of leading spaces 
    while (strText.substring(0,1) == ' ') 
        strText = strText.substring(1, strText.length);

    // this will get rid of trailing spaces 
    while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);

   return strText;
  }
  function themeInfo(themeURL) {
    window.open(basehref+ themeURL, 'NewWindow','toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width=420,height=450');
  }
  
  function hideLayer(szDivID) {
    toggleBox(szDivID, 0);
    }
  
  function showLayer(szDivID) {
    toggleBox('LegendLayer',0);
    toggleBox('SearchLayer',0);
    toggleBox('ReferenceLayer',0);
    toggleBox('PrintLayer',0);
    toggleBox(szDivID, 1);
    if (szDivID == 'PrintLayer') {
    	document.mapserv.maptitle.focus();}
  	 else if(szDivID == 'SearchLayer') {
    	document.mapserv.pinnum.focus();}
  }
  function showLayer_sv(szDivID) {
    toggleBox('SearchLayer',0);
    toggleBox('ReferenceLayer',0);
    toggleBox('PrintLayer',0);
    toggleBox(szDivID, 1);
    if (szDivID == 'PrintLayer') {
    	document.mapserv.maptitle.focus();}
  	 else if(szDivID == 'SearchLayer') {
    	document.mapserv.sec.focus();}
  }
  
  function toggleBox(szDivID, iState) // 1 visible, 0 hidden 
  {
    var obj = document.layers ? document.layers[szDivID] : document.getElementById ?  document.getElementById(szDivID).style : document.all[szDivID].style;
    obj.visibility = document.layers ? (iState ? "show" : "hide") : (iState ? "visible" : "hidden");
  }


  function pinURL() {
  	window.open('http://www.bayfieldcounty.org/LandRecords/parcel_map_PIN.htm', 'NewWindow');
  }
  
  function showHelp() {
    window.open(basehref + '/bcmv4101_help.htm', 'NewWindow','toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=550,height=550');
  } 
  
  function showHelp_sv() {
    window.open(basehref + '/bcsv4101_help.htm', 'NewWindow','toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=550,height=550');
  }   
 
  function createMap(theTitle) {
   top.consoleRef=window.open('','myconsole',
    'width=700,height=525'
     +',menubar=1'
     +',toolbar=1'
     +',status=0'
     +',scrollbars=1'
     +',resizable=1')
   top.consoleRef.document.writeln(
    '<html><head><title>Map Generated from Bayfield County MapViewer</title></head>'
     +'<body onLoad="self.focus()">'
     +'<table border=2 cellpadding="0" width="654" bordercolor="#000000"><tr><td><table border="0" cellpadding="0" width="650"><tr><td colspan="2"><font face="Arial" size="4"><b>'
     +theTitle
     +'</b></font></td></tr><tr><td rowspan="2">'
     +'<img border="1" src="'
     +mapImage
     +'" width="499" height="438"></td><td valign="middle" align="center">&nbsp;<p>&nbsp;</p><p>&nbsp;'
     +'</p><p><img border="0" src="/landrecords/mapviewer/viewer_images/north.gif" width="78" height="78"></p></td></tr><tr><td valign="bottom" align="center">'
     +'<img border="1" src="'
     +refImage
     +'" width="128" height="194"><br><font face="Arial" size="1">BAYFIELD COUNTY</font></td></tr><tr><td align="right">'
     +'<img border="0" src="'
     +sbImage
     +'" width="120" height="26"></td><td></td></tr></table></tr><td></table></body></html>');     
    top.consoleRef.document.close();
  }
  
  
var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input,len, e) {
var keyCode = (isNN) ? e.which : e.keyCode; 
var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
if(input.value.length >= len && !containsElement(filter,keyCode)) {
input.value = input.value.slice(0, len);
input.form[(getIndex(input)+1) % input.form.length].focus();
}
function containsElement(arr, ele) {
var found = false, index = 0;
while(!found && index < arr.length)
if(arr[index] == ele)
found = true;
else
index++;
return found;
}
function getIndex(input) {
var index = -1, i = 0, found = false;
while (i < input.form.length && index == -1)
if (input.form[i] == input)index = i;
else i++;
return index;
}
return true;
}
  -->
