
var gitWheelTimer;
var gitCheckTimer;
var gitActiveBut = 0;
var gitCenterX, gitCenterY;

var imageHeight;
var imageWidth;
var theImgURL;
var theRefImgURL;
var eMaxxDegs,eMinxDegs,eMaxyDegs,eMinyDegs;
var LonDegsPerPixel,LatDegsPerPixel,startLat,startLon,endLat,endLon;
var fullMaxLat,fullMaxLon,fullMinLat,fullMinLon,oldMinLat,oldMinLon;
var showLayerIds;

var fMap;
var imgMap;
var imgRefMap;


function initMap(){
   fMap = $("frmGit");
   imgMap = $("gitMapImage");
   imgMap = $("gitMapRef");
   objMap = $("divObjects");
   //showLayerIds = "0,1,4,3,2";
   showLayerIds = "0,1,2,3,4,5,6";
   mapProperties();
   fMap.mapWidth.value = imageWidth;
   fMap.mapHeight.value = imageHeight;
   gitServiceAction();
   gitSelectButton("gitZoomIn")
}

function mapProperties(){
    dMap = $("divMapEvents");
    imageWidth = dMap.getWidth();
    imageHeight = dMap.getHeight();
}

function toggleBusinessLayer(chkVal)
{
    //showLayerIds = "0,1,3,2";
    showLayerIds = "0,1,2,3,4,5";
    if(chkVal)
    {
        //showLayerIds = "0,1,4,3,2";
        showLayerIds = "0,1,2,3,4,5,6";
    }
    gitServiceAction();
}

function gitZoomImageIn(){
    mapProperties();
    
    var startx = fMap.startX.value;
    var starty = fMap.startY.value;
    var endx = fMap.endX.value;
    var endy = fMap.endY.value;
    var boxWidth;
    var boxHeight;
    var widthRatio;
    var heightRatio;
    var overallRatio;
    var newWidth,newHeight,newLeft,newTop;
    var temp;

    if(startx > endx){
        temp = startx;
        startx = endx;
        endx = temp;
    }
   
    if(starty > endy){
        temp = starty;
        starty = endy;
        endy = temp;
    }

    
    boxWidth = Math.abs(endx - startx);
    boxHeight = Math.abs(endy - starty);
    
    tempCenterX = (endx+startx)/2;
    tempCenterY = (endy+starty)/2;
    
}



function gitMoveImageUp(){
    difLat = (fMap.maxLat.value - fMap.minLat.value)*.2;
    fMap.minLat.value = parseFloat(fMap.minLat.value) + difLat;
    fMap.maxLat.value = parseFloat(fMap.maxLat.value) + difLat;
    gitServiceAction();
}

function gitMoveImageLeft(){
    difLon = (fMap.maxLon.value - fMap.minLon.value)*.2;
    fMap.minLon.value = parseFloat(fMap.minLon.value) - difLon;
    fMap.maxLon.value = parseFloat(fMap.maxLon.value) - difLon;
    gitServiceAction();
}

function gitMoveImageRight(){
    difLon = (fMap.maxLon.value - fMap.minLon.value)*.2;
    fMap.minLon.value = parseFloat(fMap.minLon.value) + difLon;
    fMap.maxLon.value = parseFloat(fMap.maxLon.value) + difLon;
    gitServiceAction();
}

function gitMoveImageDown(){
    difLat = (fMap.maxLat.value - fMap.minLat.value)*.2;
    fMap.minLat.value = parseFloat(fMap.minLat.value) - difLat;
    fMap.maxLat.value = parseFloat(fMap.maxLat.value) - difLat;
    gitServiceAction();
}


function gitClearButtons(){
    var toolset = $("divMapTools").immediateDescendants();
    toolset.each(function(obj, index) {
        obj.className = "maptoolOf";
    });
    if($('gitPointerEdit')){
        $('gitPointerEdit').className = "maptoolOf";
    }
}

function positionObjects(){
    var objSet = $("divObjects").childElements();
    var lat,lon;
    objSet.each(function(obj, index) {
      
        lat = parseFloat(obj.getAttribute("lat"));
        lon = parseFloat(obj.getAttribute("lon"));
        
        obj.style.top = latToYPos(lat)- 8 + "px";
        obj.style.left = lonToXPos(lon)- 8  + "px";

    });

}

function lonToXPos(dLon){
        lonratio = Math.abs(eMaxxDegs - eMinxDegs)/imageWidth;
        //alert(dLon + "::" + eMinxDegs + "::" + lonratio);
	//xpos = ((dLon-eMinxDegs)*(imageWidth/(eMaxxDegs-eMinxDegs)));
        xpos = Math.round((dLon-eMinxDegs) / lonratio );
        //alert(xpos + "::" + imageWidth);
	return(xpos)
}


function latToYPos(dLat){
	ypos = imageHeight - ((dLat-eMinyDegs)*(imageHeight/(eMaxyDegs-eMinyDegs)));
	return(ypos)
}


function xPosToLon(xPos){
	lonratio = Math.abs(eMaxxDegs - eMinxDegs)/imageWidth;
	lonpos = lonratio * (xPos)+ parseFloat(eMinxDegs);
	return(lonpos)
}

function yPosToLat(yPos){
	latratio = Math.abs(eMaxyDegs - eMinyDegs)/imageHeight
	var theY = imageHeight - yPos;
	latpos = latratio * theY + parseFloat(eMinyDegs)
	return(latpos);
}

function gitSelectButton(theButton){
    $("divMapEvents").style.display = "block";
    switch(theButton){
        case ("gitZoomIn"):
            gitClearButtons();
            $(theButton).className = "maptoolOn"; 
            fMap.butAction.value = "zoomin";
            break;
        case ("gitZoomOut"):
            gitClearButtons();
            $(theButton).className = "maptoolOn"; 
            fMap.butAction.value = "zoomin";
            break;
        case ("gitPan"):
            gitClearButtons();
            $(theButton).className = "maptoolOn"; 
            fMap.butAction.value = "pan";
            break;
        case ("gitPointer"):
            $("divMapEvents").style.display = "none";
            gitClearButtons();
            $(theButton).className = "maptoolOn"; 
            break;
        case ("gitPointerEdit"):
            gitClearButtons();
            $(theButton).className = "maptoolOn";
            fMap.butAction.value = "pointerEdit";
            break;    }
    fMap.currMapTool.value = theButton;
}

function gitMouseOut(evt){
    e = (window.event)?window.event:evt;
    var eventx = e.clientX - $("divMapEvents").offsetLeft;
    var eventy = e.clientY;
    
    if(gitActiveBut == 1){
        gitActiveBut = 0;
       $("selectBox").style.display = "none";
       $("faker").inpfaker.focus();
       
       

        if(fMap.currMapTool.value == "gitPan"){
            doLoadingMapScreen(1);
            fMap.endX.value = eventx;
            fMap.endY.value = eventy;
            //$("divMap").style.position = "absolute";
            endLat = fMap.posLat.value;
            endLon = fMap.posLon.value;
            var difLat = startLat - endLat;
            var difLon = startLon - endLon;
            
            fMap.minLat.value = parseFloat(fMap.minLat.value) + difLat;
            fMap.minLon.value = parseFloat(fMap.minLon.value) + difLon;
            fMap.maxLat.value = parseFloat(fMap.maxLat.value) + difLat;
            fMap.maxLon.value = parseFloat(fMap.maxLon.value) + difLon;
            gitServiceAction();
        }
    }
}

function gitMouseDown(evt){
    e = (window.event)?window.event:evt;
    var obSrc = e.srcElement;
    var eventx = e.clientX;
    var eventy = e.clientY
    var eventScrnx = e.clientX;
    var eventScrny = e.clientY;
    
    //alert(eventx);
    if(gitActiveBut == 1){
        gitMouseUp(e);
    }
        
    if(fMap.currMapTool.value == "gitPan"){
        gitActiveBut = 1;
        gitCenterX = eventx;
        gitCenterY = eventy;
        
        //$("divMap").style.position = "relative";
        fMap.startX.value = eventx - $("divMapEvents").offsetLeft;
        fMap.startY.value = eventy - $("divMapEvents").offsetTop;
        startLat = fMap.posLat.value;
        startLon = fMap.posLon.value;
    }
    
    if(fMap.currMapTool.value == "gitPointerEdit"){
        if($("frmEdit")){
            $("frmEdit").lat.value = fMap.posLat.value;
            $("frmEdit").lon.value = fMap.posLon.value;
        }
    }
    
    if(fMap.currMapTool.value == "gitZoomIn"){
         
        var sbox = $("selectBox")
        sbox.style.display = "block";
        sbox.style.left = eventx + "px";
        sbox.style.top = eventy + "px";
        sbox.style.width = "1px";
        sbox.style.height = "1px";
        gitCenterX = eventx;
        gitCenterY = eventy;
        fMap.startX.value = eventx - $("divMapEvents").offsetLeft;
        fMap.startY.value = eventy - $("divMapEvents").offsetTop; 
        oldMinLat = fMap.minLat.value;
        oldMinLon = fMap.minLon.value;
        fMap.minLat.value = fMap.posLat.value;
        fMap.minLon.value = fMap.posLon.value;
        gitActiveBut = 1;
    }
    
    if(fMap.currMapTool.value == "gitZoomOut"){
        gitCenterX = eventx;
        gitCenterY = eventy;
        fMap.startX.value = eventx - $("divMapEvents").offsetLeft;
        fMap.startY.value = eventy - $("divMapEvents").offsetTop; 
        oldMinLat = fMap.minLat.value;
        oldMinLon = fMap.minLon.value;
        fMap.minLat.value = fMap.posLat.value;
        fMap.minLon.value = fMap.posLon.value;
        gitActiveBut = 1;
    }
    
    if(fMap.currMapTool.value == "gitIdentify"){
        alert("identify");
    }
     
}

function gitMouseMove(evt){
    e = (window.event)?window.event:evt;
    var obSrc = e.srcElement;
    var eventx = e.clientX - $("divMapEvents").offsetLeft;
    var eventy = e.clientY; //- $("divMapEvents").offsetTop;
    
    fMap.posX.value = eventx-1;
    fMap.posY.value = eventy - $("divMapEvents").offsetTop-3;
    
    fMap.posLat.value = yPosToLat(fMap.posY.value);
    fMap.posLon.value = xPosToLon(fMap.posX.value);
    
    if(gitActiveBut == 1){
  
        if(fMap.currMapTool.value == "gitPan"){  
            imgMap.style.left = (eventx - gitCenterX)+"px";
            imgMap.style.top = (eventy - gitCenterY)+"px";
            objMap.style.left = (imgMap.offsetLeft)+"px"
            objMap.style.top = (imgMap.offsetTop)+ "px";
        }
        
        if(fMap.currMapTool.value == "gitZoomIn"){
            var fixX = eventx;
            var fixY = eventy;
            var sbox = $("selectBox")
            var boxLeft = gitCenterX - Math.abs(eventx-gitCenterX) + document.body.scrollLeft + 2;
            var boxTop = gitCenterY - Math.abs(eventy-gitCenterY) + document.body.scrollTop + 2;
            var boxWidth = Math.abs(eventx - gitCenterX - 1);
            var boxHeight = Math.abs(eventy - gitCenterY - 3);
            
            sbox.style.width = boxWidth + "px";
            sbox.style.height = boxHeight + "px";
            if(fixX < gitCenterX){
                sbox.style.left = (fixX + document.body.scrollLeft + 2) + "px";
            }
            else{
                sbox.style.left = (gitCenterX + document.body.scrollLeft) + "px";
            }
            if(fixY < gitCenterY){
                sbox.style.top = (fixY + document.body.scrollTop + 2) + "px";
            }
            else{
                sbox.style.top = (gitCenterY + document.body.scrollTop) + "px";
            }
        }
    }
}

function gitMouseUp(evt){
    e = (window.event)?window.event:evt;
    var eventx = e.clientX - $("divMapEvents").offsetLeft;
    var eventy = e.clientY;
    
    if(gitActiveBut == 1){
        gitActiveBut = 0;
        doLoadingMapScreen(1);
        if(fMap.currMapTool.value == "gitPan"){
            fMap.endX.value = eventx;
            fMap.endY.value = eventy;
            //$("divMap").style.position = "absolute";
            endLat = fMap.posLat.value;
            endLon = fMap.posLon.value;
            var difLat = startLat - endLat;
            var difLon = startLon - endLon;
            
            fMap.minLat.value = parseFloat(fMap.minLat.value) + difLat;
            fMap.minLon.value = parseFloat(fMap.minLon.value) + difLon;
            fMap.maxLat.value = parseFloat(fMap.maxLat.value) + difLat;
            fMap.maxLon.value = parseFloat(fMap.maxLon.value) + difLon;
            gitServiceAction();
        }
        
        if(fMap.currMapTool.value == "gitZoomIn"){
            if(Math.abs(fMap.startX.value - eventx)>3){
                fMap.endX.value = eventx;
                fMap.endY.value = eventy;
                fMap.maxLat.value = fMap.posLat.value;
                fMap.maxLon.value = fMap.posLon.value;
            }
            else{
                difLat = (parseFloat(fMap.maxLat.value) - parseFloat(oldMinLat))*.2;
                difLon = (parseFloat(fMap.maxLon.value) - parseFloat(oldMinLon))*.2;
                centerLat = (parseFloat(fMap.maxLat.value)+parseFloat(oldMinLat))/2;
                centerLon = (parseFloat(fMap.maxLon.value)+parseFloat(oldMinLon))/2;
                
               
                fMap.maxLat.value = parseFloat(fMap.maxLat.value) - (centerLat - parseFloat(fMap.minLat.value)) - difLat;
                fMap.maxLon.value = parseFloat(fMap.maxLon.value) - (centerLon - parseFloat(fMap.minLon.value)) - difLon;
                fMap.minLat.value = parseFloat(oldMinLat) - (centerLat - parseFloat(fMap.minLat.value)) + difLat;
                fMap.minLon.value = parseFloat(oldMinLon) - (centerLon - parseFloat(fMap.minLon.value)) + difLon;
               
               
            }
            $("selectBox").style.display = "none";
            gitZoomImageIn();
            gitServiceAction();
            
        }
        
        if(fMap.currMapTool.value == "gitZoomOut"){
            
            difLat = (parseFloat(fMap.maxLat.value) - parseFloat(oldMinLat))*.2;
            difLon = (parseFloat(fMap.maxLon.value) - parseFloat(oldMinLon))*.2;
            centerLat = (parseFloat(fMap.maxLat.value)+parseFloat(oldMinLat))/2;
            centerLon = (parseFloat(fMap.maxLon.value)+parseFloat(oldMinLon))/2;
            
           
            fMap.maxLat.value = parseFloat(fMap.maxLat.value) - (centerLat - parseFloat(fMap.minLat.value)) + difLat;
            fMap.maxLon.value = parseFloat(fMap.maxLon.value) - (centerLon - parseFloat(fMap.minLon.value)) + difLon;
            fMap.minLat.value = parseFloat(oldMinLat) - (centerLat - parseFloat(fMap.minLat.value)) - difLat;
            fMap.minLon.value = parseFloat(oldMinLon) - (centerLon - parseFloat(fMap.minLon.value)) - difLon;
               
            gitServiceAction();
            
        }
    
    }
}

function hlightProp(objSrc,refid){
    objSrc.style.backgroundColor='#E4CDA3';
    var rid;
   
    var propObj = $("divObjects").getElementsByClassName('objProp');
    propObj.each(function(obj, index) {
        rid = obj.getAttribute("refid");
        if(rid == refid){
            
            obj.style.borderColor = "Red"
        }
    });
}

function unHlightProp(objSrc,refid){
    objSrc.style.backgroundColor='Transparent';
    var rid;
    var propObj = $("divObjects").getElementsByClassName('objProp');
    propObj.each(function(obj, index) {
        rid = obj.getAttribute("refid");
        if(rid == refid){
            obj.style.borderColor = "Transparent"
        }
    });
}

function gitServiceAction(){
   frmG = $("frmGit");
   locM = frmG.butAction.value;
   var doinit =(locM == "initPage")? true : false;
   maxxDegs = frmG.maxLon.value;
   minxDegs = frmG.minLon.value;
   maxyDegs = frmG.maxLat.value;
   minyDegs = frmG.minLat.value;
   var rndm;
    rndm = Math.round(Math.random() * 1000000);

   var reqURL = "mapSvlt?mode=" + locM + "&imgW=" + imageWidth + "&imgH=" + imageHeight;
   if(!doinit){
      reqURL += "&maxx=" + maxxDegs + "&maxy=" + maxyDegs + "&minx=" + minxDegs + "&miny=" + minyDegs;
//      reqURL += "&allLyrIDs=0,1,3,2,4";		//<<- maintain visible layers settings
      reqURL += "&allLyrIDs=0,1,2,3,4,5,6";		//<<- maintain visible layers settings
      reqURL += "&onLyrIDs=" + showLayerIds;
    }
    reqURL += "&rnd="+rndm
 
    new Ajax.Request(reqURL,{method:'get',
    onComplete:function(t){
        var theResp = t.responseText;
        $("contRespText").innerHTML = theResp;
        if (theResp.length > 0){
            
                var argArr = theResp.split(/\t/);
                var i;
                for (i=0; i<argArr.length; i++){	//<<-- loop thru args returned [name=val0(,val1,..valn)]
                //	alert(argArr[i]);
                        var thisAttr = argArr[i].split(/=/);	//<<- break into name & value
                //		alert(thisAttr[0]);alert(thisAttr[1]);

                        if(thisAttr[0] == "url"){
                                frmG.imageURL.value = thisAttr[1];
                                theImgURL = thisAttr[1];
                                setImgURL();

                        }
                               

                        if(thisAttr[0] == "maxx"){
                                maxxDegs = thisAttr[1];		//<<- store for future calculations
                                if(parseFloat(maxxDegs) > 180) maxxDegs = 180;
                                frmG.maxLon.value = maxxDegs;
                                eMaxxDegs = parseFloat(maxxDegs);
                        }
                        if(thisAttr[0] == "maxy"){
                                maxyDegs = thisAttr[1];	
                                if(parseFloat(maxyDegs) > 90) maxyDegs = 90;
                                frmG.maxLat.value = maxyDegs;
                                eMaxyDegs = parseFloat(maxyDegs);
                        }
                        if(thisAttr[0] == "minx"){
                                minxDegs = thisAttr[1];	
                                if(parseFloat(minxDegs) < -180) minxDegs = -180;
                                frmG.minLon.value = minxDegs;
                                eMinxDegs = parseFloat(minxDegs);
                        }
                        if(thisAttr[0] == "miny"){
                                minyDegs = thisAttr[1];	
                                if(parseFloat(minyDegs) < -90) minyDegs = -90;
                                frmG.minLat.value = minyDegs;
                                eMinyDegs = parseFloat(minyDegs);
                        }
                        

                        if(thisAttr[0] == "lIDsAll"){
                                /*  split out the id's to be displayed in the layer list - this is done on initial load only */ 

                                if (doinit){		//<<- save id's of *ALL* layers for entire map -  only set during initial setup!!!
                                        layerIdArr = thisAttr[1].split(/,/);
                                        layerIdArr.reverse();		//<<- order is returned lowest layer first so we need to reverse for display

                                        frmG.lyrIDsAll.value = thisAttr[1];		//<<- stored in hidden field in original order 
                                }
                                else
                                        frmG.lyrIDsNow.value = thisAttr[1];		//<<- store current layers for use ... not sure why yet

                        }
                        if(thisAttr[0] == "lTypesAll"){		//<<- only returned during initial setup?
                                frmG.lyrTypesAll.value = thisAttr[1];
                                lTypesArr = thisAttr[1].split(/,/);			// use for spatial queries
                        }
                        if(thisAttr[0] == "lNamesAll"){		// ** WORKS WITH lIDsAll, & lyrIDsOn to CREATE LAYERS ** //
                                // split out the name's to be displayed in the layer list :: same order as ID's
                                layerNameArr = thisAttr[1].split(/,/);
                                layerNameArr.reverse();
                                frmG.lyrNamesNow.value = thisAttr[1];	// stored in reverse order
                        }

                        if(thisAttr[0] == "lIDsOn"){		//<<- only returned during initial setup?
                                frmG.lyrIDsOn.value = thisAttr[1];
                                lIDsOnArr = thisAttr[1].split(/,/);			// use later for loops/checks
                        }
                        if(thisAttr[0] == "activeLyrID"){
                                frmG.activeLyrID.value = thisAttr[1];
                        }

                        /* ---   spatial filter results   --- */
                       // if(thisAttr[0] == "recIDs"){ 
                                //	split out the id's of the features selected???  may not need this here.
                                //	recIdArr = thisAttr[1].split(/,/);
                        //        document.mapForm.recIDs.value = thisAttr[1];	//<-- store selected features
                       // }
                }
                /*	-------------------------------- *
                 *		calculate degsPerPixel ...
                 *	-------------------------------- */
                //	yDegs = Math.abs(parseFloat(loc_maxy) - parseFloat(loc_miny));
                var xDegs = Math.abs(parseFloat(maxxDegs) - parseFloat(minxDegs));
                LonDegsPerPixel = xDegs/imageWidth;			//<<- global var
                
                var yDegs = Math.abs(parseFloat(maxxDegs) - parseFloat(minxDegs));
                LatDegsPerPixel = yDegs/imageHeight;
                
                positionObjects();
                doLoadingMapScreen(0);
                if(doinit){
                    fullMaxLat = eMaxyDegs;
                    fullMaxLon = eMaxxDegs;
                    fullMinLat = eMinyDegs;
                    fullMinLon = eMinxDegs;
                }
                
                /*	-------------------------------- */
           gitServiceReference(); 
        }
    },
    onFailure:function(t){
        $("responseText").innerHTML = t.responseText;
    }
    
    });

}

function gitServiceReference(){
  //alert("in");
   //frmG = $("frmGit");
   //locM = frmG.butAction.value;
   //var doinit =(locM == "initPage")? true : false;
   var doinit = false;
   rmaxxDegs = frmG.maxLon.value;
   rminxDegs = frmG.minLon.value;
   rmaxyDegs = frmG.maxLat.value;
   rminyDegs = frmG.minLat.value;
   var refWidth = 100;
   var refHeight = 100;
   var rndm;
    rndm = Math.round(Math.random() * 1000000);

   var reqURL = "mapSvlt?mode=reference&imgW=" + refWidth + "&imgH=" + refHeight;
   if(!doinit){
      reqURL += "&maxx=-76.63846&maxy=38.69655&minx=-77.33034&miny=38.23769";
      reqURL += "&refmaxx=" + rmaxxDegs + "&refmaxy=" + rmaxyDegs + "&refminx=" + rminxDegs + "&refminy=" + rminyDegs;
//      reqURL += "&allLyrIDs=0,1,3,2,4";		//<<- maintain visible layers settings
      reqURL += "&allLyrIDs=0,1,2,3,4,5,6,acetate";		//<<- maintain visible layers settings
      reqURL += "&onLyrIDs=1,2,3,acetate2";
    }
    reqURL += "&rnd="+rndm
    //alert(reqURL);
    new Ajax.Request(reqURL,{method:'get',
    onComplete:function(t){
        var theResp = t.responseText;
        //alert(theResp);
        $("contRespText").innerHTML = theResp;
        if (theResp.length > 0){
            
                var argArr = theResp.split(/\t/);
                var i;
                for (i=0; i<argArr.length; i++){	//<<-- loop thru args returned [name=val0(,val1,..valn)]
                //	alert(argArr[i]);
                        var thisAttr = argArr[i].split(/=/);	//<<- break into name & value
                //		alert(thisAttr[0]);alert(thisAttr[1]);

                        if(thisAttr[0] == "url"){
                                //frmG.imageURL.value = thisAttr[1];
                                //alert(thisAttr[1]);
                                theRefImgURL = thisAttr[1];
                                //alert(theRefImgURL);
                                setRefImgURL();

                        }
                               

//                        if(thisAttr[0] == "maxx"){
//                                maxxDegs = thisAttr[1];		//<<- store for future calculations
//                                if(parseFloat(maxxDegs) > 180) maxxDegs = 180;
//                                frmG.maxLon.value = maxxDegs;
//                                eMaxxDegs = parseFloat(maxxDegs);
//                        }
//                        if(thisAttr[0] == "maxy"){
//                                maxyDegs = thisAttr[1];	
//                                if(parseFloat(maxyDegs) > 90) maxyDegs = 90;
//                                frmG.maxLat.value = maxyDegs;
//                                eMaxyDegs = parseFloat(maxyDegs);
//                        }
//                        if(thisAttr[0] == "minx"){
//                                minxDegs = thisAttr[1];	
//                                if(parseFloat(minxDegs) < -180) minxDegs = -180;
//                                frmG.minLon.value = minxDegs;
//                                eMinxDegs = parseFloat(minxDegs);
//                        }
//                        if(thisAttr[0] == "miny"){
//                                minyDegs = thisAttr[1];	
//                                if(parseFloat(minyDegs) < -90) minyDegs = -90;
//                                frmG.minLat.value = minyDegs;
//                                eMinyDegs = parseFloat(minyDegs);
//                        }
//                        
//
//                        if(thisAttr[0] == "lIDsAll"){
//                                /*  split out the id's to be displayed in the layer list - this is done on initial load only */ 
//
//                                if (doinit){		//<<- save id's of *ALL* layers for entire map -  only set during initial setup!!!
//                                        layerIdArr = thisAttr[1].split(/,/);
//                                        layerIdArr.reverse();		//<<- order is returned lowest layer first so we need to reverse for display
//
//                                        frmG.lyrIDsAll.value = thisAttr[1];		//<<- stored in hidden field in original order 
//                                }
//                                else
//                                        frmG.lyrIDsNow.value = thisAttr[1];		//<<- store current layers for use ... not sure why yet
//
//                        }
//                        if(thisAttr[0] == "lTypesAll"){		//<<- only returned during initial setup?
//                                frmG.lyrTypesAll.value = thisAttr[1];
//                                lTypesArr = thisAttr[1].split(/,/);			// use for spatial queries
//                        }
//                        if(thisAttr[0] == "lNamesAll"){		// ** WORKS WITH lIDsAll, & lyrIDsOn to CREATE LAYERS ** //
//                                // split out the name's to be displayed in the layer list :: same order as ID's
//                                layerNameArr = thisAttr[1].split(/,/);
//                                layerNameArr.reverse();
//                                frmG.lyrNamesNow.value = thisAttr[1];	// stored in reverse order
//                        }
//
//                        if(thisAttr[0] == "lIDsOn"){		//<<- only returned during initial setup?
//                                frmG.lyrIDsOn.value = thisAttr[1];
//                                lIDsOnArr = thisAttr[1].split(/,/);			// use later for loops/checks
//                        }
//                        if(thisAttr[0] == "activeLyrID"){
//                                frmG.activeLyrID.value = thisAttr[1];
//                        }

                        /* ---   spatial filter results   --- */
                       // if(thisAttr[0] == "recIDs"){ 
                                //	split out the id's of the features selected???  may not need this here.
                                //	recIdArr = thisAttr[1].split(/,/);
                        //        document.mapForm.recIDs.value = thisAttr[1];	//<-- store selected features
                       // }
                } //end for
                /*	-------------------------------- *
                 *		calculate degsPerPixel ...
                 *	-------------------------------- */
                //	yDegs = Math.abs(parseFloat(loc_maxy) - parseFloat(loc_miny));
                var xDegs = Math.abs(parseFloat(maxxDegs) - parseFloat(minxDegs));
                LonDegsPerPixel = xDegs/imageWidth;			//<<- global var
                
                var yDegs = Math.abs(parseFloat(maxxDegs) - parseFloat(minxDegs));
                LatDegsPerPixel = yDegs/imageHeight;
                
                positionObjects();
                doLoadingMapScreen(0);
                if(doinit){
                    fullMaxLat = eMaxyDegs;
                    fullMaxLon = eMaxxDegs;
                    fullMinLat = eMinyDegs;
                    fullMinLon = eMinxDegs;
                }
                
                /*	-------------------------------- */
            
        }
    },
    onFailure:function(t){
        $("responseText").innerHTML = t.responseText;
    }
    
    });

}

var repoTimer;
function setImgURL(){
    $("gitMapImage").src = theImgURL;
    reposImg();
}

function setRefImgURL(){
    $("gitMapRef").src = theRefImgURL;
    //if(imgRefMap.offsetLeft != 100){
      imgRefMap.style.top = "0px";
      imgRefMap.style.left = "100px";
    //}
}

function reposImg(){
    if(imgMap.offsetLeft != 0){
      imgMap.style.top = "0px";
      imgMap.style.left = "0px";
      objMap.style.top = "0px";
      objMap.style.left = "0px";
    }
    
}

function doQuickZoom(lat,lon){
    doLoadingMapScreen(1);
    var tmp = fMap.butAction.value;
    fMap.butAction.value = "zoomin"
    var buffer = .02
    fMap.minLat.value = parseFloat(lat) - buffer;
    fMap.minLon.value = parseFloat(lon) - buffer;
    fMap.maxLat.value = parseFloat(lat) + buffer;
    fMap.maxLon.value = parseFloat(lon) + buffer;
    gitServiceAction();
    fMap.butAction.value = tmp;
}

function doZoomOut(){
    doLoadingMapScreen(1);
    difLat = (fMap.maxLat.value - fMap.minLat.value)*.3;
    difLon = (fMap.maxLon.value - fMap.minLon.value)*.3;
    fMap.minLat.value = parseFloat(fMap.minLat.value) - difLat;
    fMap.minLon.value = parseFloat(fMap.minLon.value) - difLon;
    fMap.maxLat.value = parseFloat(fMap.maxLat.value) + difLat;
    fMap.maxLon.value = parseFloat(fMap.maxLon.value) + difLon;
    gitServiceAction();
}

function doZoomFullExtent(){
    doLoadingMapScreen(1);
    fMap.minLat.value = fullMinLat;
    fMap.minLon.value = fullMinLon;
    fMap.maxLat.value = fullMaxLat;
    fMap.maxLon.value = fullMaxLon;
    gitServiceAction();
}

function doPan(dir){
    doLoadingMapScreen(1);
    difLat = (fMap.maxLat.value - fMap.minLat.value)*.3;
    difLon = (fMap.maxLon.value - fMap.minLon.value)*.3;
    
    
    switch (dir) {
      case 'up':
        fMap.minLat.value = parseFloat(fMap.minLat.value) + difLat;
        fMap.minLon.value = parseFloat(fMap.minLon.value);
        fMap.maxLat.value = parseFloat(fMap.maxLat.value) + difLat;
        fMap.maxLon.value = parseFloat(fMap.maxLon.value);
        break;
      case 'down':
        fMap.minLat.value = parseFloat(fMap.minLat.value) - difLat;
        fMap.minLon.value = parseFloat(fMap.minLon.value);
        fMap.maxLat.value = parseFloat(fMap.maxLat.value) - difLat;
        fMap.maxLon.value = parseFloat(fMap.maxLon.value);
        break;
      case 'right':
        fMap.minLat.value = parseFloat(fMap.minLat.value);
        fMap.minLon.value = parseFloat(fMap.minLon.value) + difLon;
        fMap.maxLat.value = parseFloat(fMap.maxLat.value);
        fMap.maxLon.value = parseFloat(fMap.maxLon.value) + difLon;
        break;
      case 'left':
        fMap.minLat.value = parseFloat(fMap.minLat.value);
        fMap.minLon.value = parseFloat(fMap.minLon.value) - difLon;
        fMap.maxLat.value = parseFloat(fMap.maxLat.value);
        fMap.maxLon.value = parseFloat(fMap.maxLon.value) - difLon;
        break;
      default:
        break;
    }
    gitServiceAction();
}

function doLoadingMapScreen(toggle){
    if(toggle){
       Effect.Appear("divLoadingMap", {duration:.3}); 
    }
    else{
       Effect.Fade("divLoadingMap", {duration:.3}); 
    }
    
}

//function identifyFeature(){
//	// need to be able to differenciate between normal map action and a querystring request
//	if (setExtent == "false"){	// _NOT_ a querystring request!
//		cx = lonVar;
//		cy = latVar;
//	}
//	setExtent = "false";	//<<- setExtent=y will *only* happen once so force the issue!
//	
//	/* --  build the request message for map refresh -- *
//	 * ------------------------------------------------ */	
//	var reqURL = "mapSvlt?mode=identify&imgW=" + mapWidth + "&imgH=" + mapHeight;	
//	//	reqURL += "&trq=yes";		// send back only the <REQUEST> AXL!	<<++++++++++++++++++
//	//	reqURL += "&trp=yes";		// send back only the <RESPONSE> AXL!	<<++++++++++++++++++
//	reqURL += "&maxx=" + maxxDegs + "&maxy=" + maxyDegs + "&minx=" + minxDegs + "&miny=" + minyDegs;
//	reqURL += "&cX=" + cx + "&cY=" + cy; 
//	reqURL += "&allLyrIDs=" + document.mapForm.lyrIDsAll.value;		//<<- maintain visible layers settings
//	reqURL += "&onLyrIDs=" + document.mapForm.lyrIDsOn.value;		//<<- maintain visible layers settings
//	reqURL += "&alID=" + activeLyrID;		//<<- send the [A]ctive [L]ayer ID (alID)
//	loadDivOn();
//	//	alert(reqURL);
//	loadXMLDoc(reqURL);		//<<- refreshes map with selected features highlighted
//	
//	/*  send request for <GET_FEATURES> --> <FEATURES> returned  ::  mode=getFeatures (mapSvlt)   
//	 *  --------------------------------------------------------------------------------------- */	
//	reqURL = "mapSvlt?mode=getFeatures&imgW=" + mapWidth + "&imgH=" + mapHeight;	
//	//	reqURL += "&trq=yes";		// send back only the <REQUEST> AXL!	<<++++++++++++++++++  switch to innerText mode to view!
//	//	reqURL += "&trp=yes";		// send back only the <RESPONSE> AXL!	<<++++++++++++++++++
//	reqURL += "&maxx=" + maxxDegs + "&maxy=" + maxyDegs + "&minx=" + minxDegs + "&miny=" + minyDegs;
//	reqURL += "&cX=" + cx + "&cY=" + cy; 
//	reqURL += "&alID=" + activeLyrID;		//<<- send the [A]ctive [L]ayer ID (alID)
//	loadDivOn();
//	getFeatureData(reqURL);		//<<- sets data view contents.
//	//	toggleTab('datatab');
//}


