/*
if (typeof window.onload == 'function') {
    var oldOnload = window.onload;
    window.onload = function() {
        oldOnload();
        init();
		alert("me");
    };
} else {
    window.onload = init;
}

function init() {
    fullExtent();
}
*/
///////////////////////////////////////////////////////////////////////
// output
///////////////////////////////////////////////////////////////////////
//the extent we ask for might not be the extent that comes back, thus need to set to the correct extent
function setOutputExtent(locMinx, locMiny, locMaxx, locMaxy) {
		
		setMapParams(locMinx, locMiny, locMaxx, locMaxy);
		//replaced with function setMapParams()
    // minx = locMinx;
    // miny = locMiny;
    // maxx = locMaxx;
    // maxy = locMaxy;
}
function setOutputScale(locScale,textScale){
    scale = locScale;
	mapScale=locScale;
	document.getElementById("div_mapScale").innerHTML='1:'+textScale;
	//checkAllTreeItems();
}
function setMapImageUrl(imageUrl) {
	//reset the activeMap and then show it
	document.getElementById(mapImageId).style.zIndex=4;
	document.getElementById(mapImageId2).style.zIndex=5;
    document.images[mapImageName].src = imageUrl;
   	clipLayer(mapImageId,0,0,mapWidth,mapHeight);
    positionLayer(mapImageId,0,0,positionLayerId);
	setTimeout("showLayer(mapImageId);",200);
	setTimeout("resetPanImage();",500);
	document.getElementById(mapImageId).style.zIndex=4;
	document.getElementById(mapImageId2).style.zIndex=5;
	
	
	//resetPanImage();
	//hideLayer(mapImageId2);
	//return false;
	//document.getElementById("imgSrc").value="update/reset/show ("+mapImageId+")\n"+document.getElementById("imgSrc").value;
	
	//take what is now the inactive map and hide it / reset it
	//hideLayer(mapImageId2);
	//setTimeout("hideLayer(mapImageId2);",6000)
    //positionLayer(mapImageId2,0,0,positionLayerId);
	//document.getElementById("imgSrc").value="hide/reset ("+mapImageId2+")\n"+document.getElementById("imgSrc").value;
		
	//document.getElementById("imgSrc").value="\nactiveImage("+activeMapImage+") ="+mapImageId+"/"+mapImageName+"\n"+document.getElementById("imgSrc").value;
		
	/*
	activeMapImage=1;
	mapImageId = "theMap";
	mapImageId2 = "theMap2";
	mapImageName = "mapImageSrc";
	mapImageName2 = "mapImageSrc2";
	*/
}

function resetPanImage(){
hideLayer(mapImageId2);
positionLayer(mapImageId2,0,0,positionLayerId);
clipLayer(mapImageId2,0,0,mapWidth,mapHeight);
}
///////////////////////////////////////////////////////////////////////
// tools
///////////////////////////////////////////////////////////////////////
function refreshMap(newMinx,newMiny,newMaxx,newMaxy) {
    if (!loading) {
        showLoading();
        getMapImage(datasource, newMinx,newMiny,newMaxx,newMaxy);
    } 
}

function zoomToFeature(Axl_ID,KeyField,featureID) {
    if (!loading) {
        showLoading();
        getZoomToFeature(Axl_ID,KeyField,featureID);
    } 
}
function doSuccessMapSet() {
    hideLayer(zoomBoxId);
    hideLoading();
}

function doFailMapSet(error,message) {
    alert("Message:"+message);
    hideLayer(zoomBoxId);
    hideLoading();
	if(message!= null){
		//document.getElementById('toolBox1').style.zIndex=1000;
		//document.getElementById('toolBox1').innerHTML=error;
	    //showLayer('toolBox1');
		/*
		tmp=window.open();
		tmp.document.write("<html><body>"+error+"</body></html>");
		tmp.document.close();
		*/
//		document.getElementById('pageContent').innerHTML="<br><br><br><br><br>"+error;
	}
}

function showError(error){

   // hideLoading();
}

function setState(mode) {

    if (mode == "zoomBox") {
        setZoomBoxEvents();
    } else if (mode == "zoomOut") {
        setZoomOutEvents();
    } else if (mode == "extent") {
        setExtentEvents();
    } else if (mode == "pan") {
        setPanEvents();
    }  else if (mode == "fullExtent") {
        fullExtent();
    } 
    currentMode = mode;
}

function invokePanAction(act) {
    if (act == "n") {
        pan(0,50);
    } else if (act == "s") {
        pan(0,-50);
    } else if (act == "w") {
        pan(-50,0);
    } else if (act == "e") {
        pan(50,0);
    } else if (act == "nw") {
        pan(-50,50);
    } else if (act == "ne") {
        pan(50,50);
    } else if (act == "sw") {
        pan(-50,-50);
    } else if (act == "se") {
        pan(50,-50);
    }
    
}
function fullExtent() {
    refreshMap(fullMinx,fullMiny,fullMaxx,fullMaxy);
}
function setFullExtent() {
	setMapParams(fullMinx,fullMiny,fullMaxx,fullMaxy);
}
function full50Extent() {
	refreshMap(full50Minx,full50Miny,full50Maxx,full50Maxy);
}
function setFull50Extent() {
	setMapParams(full50Minx,full50Miny,full50Maxx,full50Maxy);
}
function resetImage() {
    document.zoomBoxImg.src = imgPath + zoomBoxImage+".gif";
    document.zoomOutImg.src = imgPath + zoomOutImage+".gif";
    document.panImg.src = imgPath + panImage+".gif";
    document.extentImg.src = imgPath + extentImage+".gif";
}


function setPressedImage(mode, imageName) {
    eval("document."+mode+"Img.src = '"+imgPath+imageName+"_down.gif'");
}

// zoom action
function zoom(percent) {
    var centerX = (minx+maxx)/2.0;
    var centerY = (miny+maxy)/2.0;
    
    var width = fullWidth * (percent/100);
    var newMinx = centerX - (width/2.0);
    var newMaxx = centerX + (width/2.0);

    var height = fullHeight * (percent/100);
    var newMiny = centerY - (height/2.0);
    var newMaxy = centerY + (height/2.0);

    refreshMap(newMinx,newMiny,newMaxx,newMaxy);
}

function zoomIn() {
    var nextLevel = parseInt(whichZOOM) - 1;
    if (nextLevel > 0) {
        swapGroup(nextLevel + 'ZOOM','ZOOM');
        whichZOOM = nextLevel + 'ZOOM';
        zoomToLevel(--nextLevel);
    }
}

function zoomOut() {
    var nextLevel = parseInt(whichZOOM) + 1;
    if (nextLevel < 11) {
        swapGroup(nextLevel + 'ZOOM','ZOOM');
        whichZOOM = nextLevel + 'ZOOM';
        zoomToLevel(--nextLevel);
    }
}

///////////////////////////////////////////////////////////////////////
// other
///////////////////////////////////////////////////////////////////////

function getNumber(num) {
    var t = Math.pow(10, decimalNum);
    return Math.round(num*t)/t;
}
