function PopOut(sURL,sTitle,iHeight,iWidth,ynScroll,ynResize) {
  var objWin;
  objWin = window.open(sURL, sTitle, "height="+iHeight+",width="+iWidth+",scrollbars="+ynScroll+",resizable="+ynResize+"");
  if (parseInt(navigator.appVersion) >=4) objWin.window.focus();
}

function StripPXFromString(originalString)
{
    return originalString.replace(/px/i, "");
}

function attachClickEvent(obj, method) 
{     
    if (obj.addEventListener)
    {   
        obj.addEventListener('click', method, false);
    }
    else
    {
        obj.onclick = method;
        //obj.attachEvent('onclick', method);
    }
}

function PrintPage() {
if (window.print != null) { 
	window.print(); 
	} 
else { 
	alert('Your browser does not support this shortcut.  Please select Print from the File menu.'); 
	}
};

function addImgToDiv(mapDiv, img) {
    
  mapDiv.appendChild(img);
}

function removeImgFromDiv(mapDiv, img) {
  //var d = document.getElementById('myDiv');
  //var olddiv = document.getElementById(divNum);
  //d.removeChild(olddiv);
}

function getLayer(name) {
	if (document.layers)
		return(document.layers[name]);
	else if (document.getElementById)
	{
		var theObj = document.getElementById(name);
		return theObj.style;
	}
	else
		return null;
}
		
// move layer to x,y
function moveLayer(name, x, y) {		
			
  	var layer = getLayer(name);
  	   		
  	//var xMove = x - parseInt(StripPXFromString(layer.left));
  	//var yMove = y - parseInt(StripPXFromString(layer.top));    		
  	   		
   	if (layer.moveTo)
    {
      layer.moveTo(x + parseInt(m_BorderOffset.value), y + parseInt(m_BorderOffset.value));
    }
    else 
    {
      layer.left = x +  parseInt(m_BorderOffset.value); // Added 15 for the navigation cells 
   		layer.top  = y +  parseInt(m_BorderOffset.value);
   	}
   	
   	//return new point(xMove, yMove);
}

// clip layer display to clipleft, cliptip, clipright, clipbottom
	// Not working with Mozilla Milestone 12 (Nav5)
function clipLayer2(name, clipleft, cliptop, clipright, clipbottom) {		
	  var layer = getLayer(name);		
	  
	  if (m_sClientBrowserType == 'Netscape') 
	  {	
      layer.clip = 'rect(' + cliptop + 'px ' +  clipright + 'px ' + clipbottom + 'px ' + clipleft +'px)';
    }
	  else 
	  {
		  layer.clip = 'rect(' + cliptop + ' ' +  clipright + ' ' + clipbottom + ' ' + clipleft +')';
	  }
}

function resetLayer()
{
	clipLayer2("mapLayer", 0, 0,  m_imgMapCanvas.width, m_imgMapCanvas.height);
	moveLayer("mapLayer", 0, 0);
}

/*function resetMarkerLayer()
{
  clipLayer2("markerLayer", 0, 0,  m_imgMapCanvas.width, m_imgMapCanvas.height);
	moveLayer("markerLayer", 0, 0);	
}*/

var mouseX;
var mouseY;

var panLayer;

var _lastMousePosition;

// move map image with mouse
function panMouse(newX, newY) {
  
	var xMove = newX-mouseX;
	var yMove = newY-mouseY;
	
	/*var xActualMove = newX - _lastMousePosition.x;
	var yActualMove = newY - _lastMousePosition.y;
	
	_lastMousePosition = new point(newX, newY);*/
	
	var cLeft = -xMove;
	var cTop = -yMove;
	
	var cRight = m_imgMapCanvas.width;
	var cBottom = m_imgMapCanvas.height;
	
	if (xMove>0) {
		cLeft = 0;
		cRight = m_imgMapCanvas.width - xMove;
	}
	if (yMove>0) {
		cTop = 0;
		cBottom = m_imgMapCanvas.height - yMove;
	}
	
	//alert('cLeft: ' + cLeft + ' cTop: ' + cTop + ' cRight: ' + cRight + ' cBottom: ' + cBottom);
	clipLayer2("mapLayer",cLeft,cTop,cRight,cBottom);
	moveLayer("mapLayer",xMove,yMove);
		
	//_mapMarkerTracker.MoveMarkers(xActualMove, yActualMove);
}

function StartPan(startX, startY) {
	
	mouseX = startX;
	mouseY = startY;

  //_lastMousePosition = new point(startX, startY);

	DisplayDebug('Start Pan!');
}

function StopPan(newX, newY)
{
	DisplayDebug('End Pan!');
	m_IsPanning = false;
	
	var tempLeft=m_mapViewer.getExtent().getLeft();;
	var tempRight=m_mapViewer.getExtent().getRight();;
	var tempTop=m_mapViewer.getExtent().getTop();;
	var tempBottom=m_mapViewer.getExtent().getBottom();;
	
	//DisplayDebug('tempTop: ' + tempTop + ' tempRight: ' + tempRight + ' tempLeft: ' + tempLeft + ' tempBottom: ' + tempBottom);
	
	var ixOffset = newX-mouseX;;
	var iyOffset = mouseY-newY;
	
	//alert ('ixOffset: ' + ixOffset);
	//alert ('iyOffset: ' + iyOffset);
	
	pixelX = Math.abs(tempRight-tempLeft) / m_imgMapCanvas.width;
	pixelY = Math.abs(tempBottom-tempTop) / m_imgMapCanvas.height;
	
	var xOffset = pixelX * ixOffset;
	var yOffset = pixelY * iyOffset;
	
	var eTop = tempTop - yOffset;
	var eRight = tempRight - xOffset;
	var eLeft = tempLeft - xOffset;
	var eBottom = tempBottom - yOffset;
	
	//DisplayDebug('eTop: ' + eTop + ' eRight: ' + eRight + ' eLeft: ' + eLeft + ' eBottom: ' + eBottom);

	// Save the extents
	m_mapViewer.setExtent(new rect(eLeft,eTop,eRight,eBottom));

	submit();
	
	//resetLayer();
	
	return true;
}