function Point(x, y)
{
  this.x = x;
  this.y = y;
}

function decode(string) 
{
  return unescape(string.replace(/\+/g, " "));
}

function getargs() 
{
  var args = new Object();
  var query = location.search.substring(1);   // Get query string.
  var pairs = query.split("&");           // Break at ampersand.
  for(var i = 0; i < pairs.length; i++) 
  {
    var pos = pairs[i].indexOf('=');          // Look for "name=value".
    if (pos == -1) continue;                  // If not found, skip.
    var argname = pairs[i].substring(0,pos);  // Extract the name.
    var value = pairs[i].substring(pos+1);    // Extract the value.			    
    args[argname] = decode(value);            // Store as a property.
  }
  return args;                                // Return the object.
}

function objekt(minx, miny, maxx, maxy)
{
	var temp = new Array(4);
  temp[0] = ms.extent[0] + ms.cellsize*minx;
  temp[1] = ms.extent[3] - ms.cellsize*maxy;
  temp[2] = ms.extent[0] + ms.cellsize*maxx;	
  temp[3] = ms.extent[3] - ms.cellsize*miny;	
	url = 'http://www.mittkulturminne.no/nt/kart/resultat.php?reg_av='+args['reg_av']+'&minx='+temp[0]+'&maxy='+temp[1]+'&maxx='+temp[2]+'&miny='+temp[3];
	window.open(url,"resultat","width=500,height=340,scrollbars=no,toolbar=no,directories=no,menubar=no,statusbar=no,resizable=yes");
}
	
function lightup(button) 
{
  var img;  
  if(button == active_button) return;
  
  if(button == "back")
  {
  	if(peker.next != null)
  	{
		  img = eval("document." + button);
		  img.src = "/nt/icon/icon_" + button + '_2.gif';
  	}
  }
  else if(button == "forward")
  {
  	if(peker.last != null)
  	{
		  img = eval("document." + button);
		  img.src = "/nt/icon/icon_" + button + '_2.gif';
  	}
  }
  else
  {
	  img = eval("document." + button);
	  img.src = "/nt/icon/icon_" + button + '_2.gif';
  }
}

function lightoff(button) 
{
  var img;  
  if(button == active_button) return;  
  img = eval("document." + button);
  img.src = "/nt/icon/icon_" + button + '_1.gif';
}

function buttonclick(button) 
{
  var img;
  var last_active_button;
  var title;
  
  last_active_button = active_button;
  active_button = '';
  
  for(var i=0; i<buttons.length; i++)
    lightoff(buttons[i]);
    
  img = eval("document." + button);
  img.src = "/nt/icon/icon_" + button + '_2.gif';
  					
  if(button == 'fullextent') {
      ms.mode = "map";
      ms.setextent( 221875.001, 7000000.001, 503125.001, 7225000.001);
      buttonclick('zoomin');
      ms.draw();
      //parent.location = "/tools/mapviewer/basinviewer.htm"
  } else if(button == 'back') { 
      listeForrige();
         
   } else if(button == 'forward') {
      listeNeste();
           
   } else if(button == 'identify') {
      ms.boxon();
      active_button = button;     
   } else if(button == 'km') { 
      ms.zoomdir = 0;
      ms.boxoff();
      active_button = button;            
   } else {
      ms.mode = "map";
      if(button == 'zoomin') {
         ms.zoomdir = 1;
         ms.boxon();
      } else if(button == 'zoomout') {
         ms.zoomdir = -1;
         ms.boxoff();
      } else {
         ms.zoomdir = 0;
         ms.boxoff();
      }  
      active_button = button;
   }
}

// Function definitions
function AdjustExtent(extent, width, height) 
{	
  var cellsize = Math.max((extent[2] - extent[0])/(width-1), (extent[3] - extent[1])/(height-1));
  if(cellsize > 0) {
    var ox = Math.max(((width-1) - (extent[2] - extent[0])/cellsize)/2,0);
    var oy = Math.max(((height-1) - (extent[3] - extent[1])/cellsize)/2,0);
    extent[0] = extent[0] - ox*cellsize;
    extent[1] = extent[1] - oy*cellsize;
    extent[2] = extent[2] + ox*cellsize;
    extent[3] = extent[3] + oy*cellsize;
  }	
  return(cellsize);
}
