﻿// JScript File
var newLoad = false;
var mWidth = 200;
var mHeight = 200;
var reloadTimer;

var m_selectedindex = 0;
var myselects = new Array();
myselects[1] = "county";
myselects[2] = "city";
myselects[3] = "basin";
myselects[4] = "planningunit";
myselects[5] = "quadmap";
myselects[6] = "str";
myselects[7] = "box";
myselects[8] = "point"
myselects[9] = "radius";
myselects[10] = "address";
myselects[11] = "latlong";
myselects[12] = "div_imgsel_single";
myselects[13] = "div_imgsel_dual";


var webMapViewer = "single";
var currimg = "ls1997rgb"
var webMapImagery1 = "ls1997rgb";
var webMapImagery2 = "ls1997rgb";

var m_section;
var m_township;
var m_range;

var m_section_v="";
var m_township_v="";
var m_south_v="S";
var m_range_v="";
var m_east_v="E";

var m_add_v="";
var m_city_v="";
var m_zip_v="";
var m_b2_v="";

var m_dx_v="";
var m_mx_v="";
var m_sx_v="";

var m_dy_v="";
var m_my_v="";
var m_sy_v="";

var m_ddx_v="";
var m_ddy_v="";
var m_b_v=""; 

//function showimg(){
//    var webMapLoad = document.getElementById("imgload");
//    webMapLoad.style.visibility = "visible";   
//}

//function hideimg(){
//    var webMapLoad = document.getElementById("imgload");
//    //alert(esriCurrentResponseCount);
//    webMapLoad.style.visibility = "hidden";   
//}

function resetdivs(x)
{
     var d;
     var i=1;
     var j = myselects.length;
     if (x != null) j = 12;
     for (i=1;i<j;i++)
     {       
          
          d=document.getElementById(myselects[i]);
//          if(d!=null)d.style.visibility="hidden";
          if(d!=null){
              if (d.style.display == 'block') d.style.display = 'none';
          }
          
          var e = document.getElementById('inputerror');
          if (e!=null)e.innerHTML = "";
             
          
       }  
  
}


function displaymap(i)
{
                   
          var singleoptiondiv = document.getElementById("div_imgsel_single");
          var dualoptiondiv = document.getElementById("div_imgsel_dual");
          
          //resize panel height
          var fp = document.getElementById("Type_Panel_BODY");
         var fp_h;  
            
            
          if (document.getElementById('rdSingleImagery').checked){
             fp_h = 55;
          }else{
            fp_h = 95;
          }

          fp.style.height=fp_h+"px";
          //oatingPanelSideResizeCell.style.height=fp_h+"px"
          
          // end of resize panel
          
          var x;
          var l;
     
          var sWidth = getWinWidth();
          var sHeight = getWinHeight();
        
           mHeight = sHeight - 70;
        
         var map = Maps["Map1"]; 


         if ( webMapViewer != i){
                  webMapViewer = i;
                  
                  resetdivs();
                  
                  var context = map.controlName;
                  var argument;
                    
                  var x = document.getElementById("ddlPlaceOptions");
                  x.selectedIndex = 0;
                  
                  switch(i){
                        case "single":

                            
                            document.getElementById("ddlImageOptions").value = currimg;
                            singleoptiondiv.style.display = "block";
                            dualoptiondiv.style.display = "none";
                            arcgisWebApp.MapDisplay2.style.display = "none";
                            
                            arcgisWebApp.adjustMapSize();
                            break
                        case "dual":
		                    document.getElementById("select1").value = currimg;
                            singleoptiondiv.style.display = "none";
                            dualoptiondiv.style.display = "block";

                            arcgisWebApp.MapDisplay2.style.display = "block"; 
                            arcgisWebApp.adjustMapSize();
                         
                            
                           var ext = arcgisWebApp.map._extent;
                           arcgisWebApp.map2.set_extent(ext);           
                           break
                  }
                  
                 context = arcgisWebApp.MapId;
                 argument = "ControlID=Map1&ControlType=Map&EventArg=switch&EventArg=" + i;
                 eval(MyClientCallback);
   
         }   
      }
      

      
       function setvisibility(divid, v){
        var x = document.getElementById(divid);
       if (x != null) x.style.visibility = v;
      }
      
      function mypan(x, y)
{
    map.drawBox = false;
    map.drawShape = false;
    map.dragImage = true;
	   
	    
        var box = calcElementPosition(map.divId);
        var box2 = calcElementPosition(map.containerDivId); 
	    panStartLeft = box.left - box2.left;
	    panStartTop = box.top - box2.top;
	    
				nx = (-1) * (Math.round(x / 2) + 80);
				ny = 0;
				
				mouseDirection =  getMouseDirection(nx , 0);

	            var panMoveX = nx + panStartLeft;
	            var panMoveY = ny + panStartTop;
				
			    var currentX = panStartLeft + nx;
			    var currentY = panStartTop + ny;
			    lastX = currentX;
                lastY = currentY;
				map.moveTiles(currentX, currentY, "left");
				var mapBox = calcElementPosition(map.containerDivId);
				window.status = "in dual mode";

				//alert("In dual mode");
						
			    finishDragImage(map);
			    map.updateView(true);
                map.dragImage = false;
				
}

function getImgeryType(x)
{
    //   debugger;
//    showimg();
    
    //expand aoi panel if necessary
    expandFloatingPanel("fpAOI")
    //var aoi = document.getElementById("fpAOI");
    
    var s = document.getElementById("rdSingleImagery");
    if ( s.checked == true){
        webMapImagery1 = x;
        webMapImagery2 = "";
    }else{
        webMapImagery1 = document.getElementById("Select1").value;
        webMapImagery2 = document.getElementById("Select2").value;
        if (webMapImagery1 == webMapImagery2) alert("The two imageries you selected are the same!"); 
    }
    
          

    currimg = webMapImagery1;
    
}

function switchimagery(c){
    var argument;
    var context = map.controlName;
        
    switch(c){
        case 1:
          webMapImagery1 = currimg;
          argument = "ControlID=Map1&ControlType=Map&EventArg=resetlayer&EventArg=" + webMapImagery1 + "&EventArg=1";
         break
        case 2:
            argument = "ControlID=Map1&ControlType=Map&EventArg=resetlayer&EventArg=" + webMapImagery2 + "&EventArg=2";
            break
    
    
    }
   eval(MyClientCallback);
}

function getselected()
 {
 
   resetdivs(2);
   setvisibility('divshowdownload', 'hidden');
    
   var x=document.getElementById("ddlPlaceOptions");
   m_selectedindex=x.selectedIndex;

    if(m_selectedindex!=0)setdiv(myselects[m_selectedindex]);


     switch(m_selectedindex)
     {
        case 2:
            poplist('ddlCity'); 
            break
        case 3:
            poplist('ddlBasin');
            break
        case 4:
            poplist('ddlPU');
            break
       case 5:
            poplist('ddlQuad');
            break
    }
}

function poplist(eid){
    var argument = "ControlID=Map1&ControlType=Map&EventArg=option&EventArg=poplist&EventArg=" + eid;
    var context = map.controlName;
 
   var e = document.getElementById(eid)
   if(e.length<=1){eval(MyClientCallback);} 
}


function setdiv(divid)
{
     var d=document.getElementById(divid);
     if (d!=null){
        //d.style.visibility="visible"; 
        if (d.style.display == 'none') d.style.display = 'block';
     } 
     
    }
    
    
function getAOI()
        {
            setvisibility('divshowdownload', 'hidden');
            setvisibility('fpResult', 'hidden');
            
           var fp = document.getElementById('fpResult');
           if (fp != null)fp.style.display = 'none';
            
            showLayer("imgload");
             
            context = map.controlName;
            var t;
            var v;        
            getparameters();
             switch(m_selectedindex)
            {
                case 0:
                    hideLayer("imgload");
                    alert("Please select place.");
                    break
                case 1:
                  t=document.getElementById("ddlCounty");
                  m_county=t.options[t.selectedIndex].text;
                  if (m_county=="St.Johns")m_county="St Johns";
                  argument = "EventArg=option&EventArg=1&EventArg=" + m_county;
                  eval(MyClientCallback);
                  break    
               case 2:
                  t=document.getElementById("ddlCity");
                  if (t.selectedIndex == 0) {
                    alert("Please select city.");
                    hideLayer("imgload");
                  }  else{
                      v=t.options[t.selectedIndex].text;
                      argument = "EventArg=option&EventArg=2&EventArg=" + v;
                      eval(MyClientCallback);  
                  }
                  break
               case 3:
                  t=document.getElementById("ddlBasin");
                  if (t.selectedIndex == 0){
                     alert("Please select basin.");
                     hideLayer("imgload");
                  }else{
                    v=t.options[t.selectedIndex].text;
                    argument = "EventArg=option&EventArg=3&EventArg=" + v;
                    eval(MyClientCallback); 
                  }
                  
                  break
               case 4:
                  t=document.getElementById("ddlPU");
                  if (t.selectedIndex == 0){
                    alert("Please select planning unit.");
                    hideLayer("imgload");
                  }else{
                    v=t.options[t.selectedIndex].text;
                    argument = "EventArg=option&EventArg=4&EventArg=" + v;
                    eval(MyClientCallback);
                  }
                    
                  break 
                case 5:
                  t=document.getElementById("ddlQuad");
                  if (t.selectedIndex == 0){
                    alert("Please select quad.");
                    hideLayer("imgload");
                  }else{
                      v=t.options[t.selectedIndex].text;
                      argument = "EventArg=option&EventArg=5&EventArg=" + v;
                      eval(MyClientCallback);
                  }
                    
                  break 
                case 6: 
                  argument = "EventArg=option&EventArg=6&EventArg=" + m_section_v + "&EventArg=" + m_township_v + "&EventArg=" + m_south_v + "&EventArg=" + m_range_v + "&EventArg=" + m_east_v;
                  eval(MyClientCallback); 
                  break  
                case 7: 
                    //hideimg();
                    hideLayer("imgload");
                    break
                case 8:
                    //hideimg();
                    hideLayer("imgload");
                    break
                case 9: 
                    //hideimg();
                    hideLayer("imgload");
                    t=document.getElementById("txtRadius")
                    argument = "EventArg=option&EventArg=9&EventArg=" +  t.value;
                    eval(MyClientCallback);  
                    break
                case 10:
                    argument = "EventArg=option&EventArg=10&EventArg=" + m_add_v + "&EventArg=" + m_city_v + "&EventArg=" + m_zip_v  + "&EventArg=" + 0 ; //m_b2_v;
                    eval(MyClientCallback);
                    break
                 case 11:
                    argument = "EventArg=option&EventArg=11&EventArg=" + m_dx_v + "&EventArg=" + m_mx_v + "&EventArg=" + m_sx_v + "&EventArg=" + m_dy_v + "&EventArg=" + m_my_v;
                    argument += "&EventArg=" + m_sy_v + "&EventArg=" + m_ddx_v + "&EventArg=" + m_ddy_v + "&EventArg=" + m_b_v;
                    eval(MyClientCallback);
                    break         
            }      
        }

function  getparameters()
{
    var serr="";
    var x;
    
     switch(m_selectedindex)
    {
        case 6:
            m_section=document.getElementById("txtSection");
            m_township=document.getElementById("txtTownship");
            m_range=document.getElementById("txtRange");
            
            m_section_v=m_section.value;
                      
            m_township_v=m_township.value;
            m_range_v=m_range.value;
        

            break
    
        case 7:
            x="SelectByBox"; 
            mytoolselect(x, 'Toolbar1');
            //mytoolselect(x, 'Toolbar2');
            break
        case 8:
             x="SelectByPoint";
             mytoolselect(x, 'Toolbar1');
             //mytoolselect(x, 'Toolbar2');
             break
        case 9:
            x="SelectByPoint";
             mytoolselect(x, 'Toolbar1');
             //mytoolselect(x, 'Toolbar2');
             break
        case 10:
            var add1=document.getElementById("txtAddress");
            var city=document.getElementById("txtCity");
            
            var zip=document.getElementById("txtZip");
            //var b2=document.getElementById("txtBuffer2");
            
            
            m_add_v=add1.value;
            m_city_v=city.value;
            m_zip_v=zip.value;
            //m_b2_v=b2.value;
            
            break
        case 11:
            var dx=document.getElementById("txtDx");
            var mx=document.getElementById("txtMx");
            var sx=document.getElementById("txtSx");
            
            var dy=document.getElementById("txtDy");
            var my=document.getElementById("txtMy");
            var sy=document.getElementById("txtSy");
                     
            var ddx=document.getElementById("txtDDx");             
            var ddy=document.getElementById("txtDDy");
            
            var b=document.getElementById("txtBuffer");
           
         
            m_dx_v=dx.value;
            m_mx_v=mx.value;
            m_sx_v=sx.value;
            
            m_dy_v=dy.value;
            m_my_v=my.value;
            m_sy_v=sy.value;
            
            m_ddx_v=ddx.value;
            m_ddy_v=ddy.value;
            
            m_b_v=b.value;
            
            break
        
     }
}
  
 function mytoolselect(toolName, toolbarName)
{

    var f = document.forms[docFormID];
//    var toolbarName = 'Toolbar1';
    var toolbarItemName = toolName;
    var imageTag = toolbarName + toolbarItemName + 'Image';
    var cell = toolbarName + toolbarItemName;
    var toolbar = Toolbars[toolbarName];
    f.elements[toolbar.currentToolField].value = toolbarItemName;
    var clientAction =  toolbar.items[toolbarItemName].clientAction;
   

    if (clientAction != null){
        var clientActions = '';
        if (!toolbar.items[toolbarItemName].isClientActionCustom){
            var buddies = toolbar.buddyControls;
            if (buddies != null){
                for (var i = 0; i < buddies.length; i++){
                    var modeField = f.elements[buddies[i] + '_mode'];
                    if (modeField != null)modeField.value = toolbarItemName;
                    var cursor = toolbar.items[toolbarItemName].cursor;
                    if (cursor != null)
                        clientActions = clientActions + clientAction + "( '" + buddies[i] + "' , '" + toolbarItemName + "', " + toolbar.items[toolbarItemName].showLoading + ",'" + cursor + "'); ";
                }
             }
        }
        else{
            clientActions = clientAction;
        }
        
        var clientActionFunction = new Function(clientActions);
        clientActionFunction.call(null);

        Toolbars[toolbarName].selectTool();
        Toolbars[toolbarName].refreshGroup();
    }
}    

      function showlist(){
            var context = map.controlName;
            var argument = "ControlID=Map1&ControlType=Map&EventArg=showlist";
             eval(MyClientCallback);
      
      }   
      

      
      
      
      //******************************
// Client-side printing javascript functions
var printWin = null;

// Called when another task executes--updates list of tasks
function RefreshTaskResults(callbackFunctionString) {
    // Must include a delay, otherwise causes repeated client callback loop
    var sendString = "sendRefreshTaskResults(\"" + callbackFunctionString + "\")";
    window.setTimeout(sendString, 200);
}

function sendRefreshTaskResults(callbackFunctionString){
    var argument='EventArg=updateTaskResults';
    var context=null;
    eval(callbackFunctionString);
}

function PrintTaskSendRequest(button, callbackFunctionString, mapId) {
    doHourglass();
    var pre = getControlPrefix(button.id);
    
    // get task results items checked
    var cblPrefix = pre + "_cblResults";
    var cbResult = null;
    var printItems = "";
    var listDone = false;
    var i = 0;
    
    while (!listDone) {
        cbResult = document.getElementById(cblPrefix + "_" + i.toString());
        if (cbResult != null) {
            if (cbResult.checked) {
                // add to list of checked results items
                if (printItems.length > 0) printItems += ",";
                printItems += i.toString();
            }
            i++;
        }
        else {
            listDone = true;
        }
    }
    
    // get map print options from form
    var printTitle = "";
    var printBox = document.getElementById(pre + "_ptitle");
    if (printBox != null) {
        // replace "&"
        printTitle = printBox.value;
        printTitle = printTitle.replace(/&/, "##amp##");
        printTitle = escape(printTitle);
    }
    
    var printMap = document.getElementById(pre + "_printMap").checked;
    if (!printMap)
        mapId = "";
    var widthList = document.getElementById(pre + "_width");
    var resolutionList = document.getElementById(pre + "_resolution");
    var printWidth = widthList.options[widthList.selectedIndex].value;
    var printResolution = resolutionList.options[resolutionList.selectedIndex].value;
    var scale = escape(document.getElementById(pre + "_scale").value);
    
    var argument = "mapId="+mapId + "&title="+printTitle;  //EventArg=getPrintPage&
    argument += "&printResults="+printItems;
    argument += "&width="+printWidth + "&resolution="+printResolution + "&scale="+scale;
    //alert(argument);
    var context=null;
    executeTask(argument, callbackFunctionString);
    //eval(callbackFunctionString);
   
    // hide print dialog
    //window.setTimeout("hideFloatingPanel('"+pre+"')", 1000);
}

// Called from server-generated function after print request
function PrintTaskDisplayPage(printContent) {   //printImageUrl, mapHeight, taskResultsHtml) {

    var windowOptions = "toolbar=yes,width=700,height=600,top=100,left=200,scrollbars=yes,resizable=yes";
    if (!printWin || printWin.closed) {
        printWin = window.open("", "printWindow", windowOptions);
    }
     
    
    if (printWin != null) {
    
        // restore line breaks (encoded as xxrnxx at server)
        var regexp = /xxrnxx/gi;
        printContent = printContent.replace(regexp, "\n");
        
        // "unescape" the content
        printContent = decode(printContent);
        
        printWin.document.write(printContent);

        printWin.document.close();
        printWin.focus();
    }
    else
        alert("Cannot display print preview window. Check that popup blockers are disabled for this site.");
        
    undoHourglass();
    
}

function getControlPrefix (fullControlId) {
    var lastUnderscore = fullControlId.lastIndexOf("_");
    return fullControlId.substring(0, lastUnderscore);
}

function doHourglass() {
    document.body.style.cursor = 'wait';
}
function undoHourglass() {
    document.body.style.cursor = 'auto';
}

var conversionMap = {
    "amp" : "&",
    "lt" : "<",
    "gt" : ">",
    "apos" : "'",
    "quot" : '"'
}

function decode(entityString) {
    return entityString.replace(/&(\w+);/g, function(m,g) {
        return conversionMap[g]||m;
    });
}

//for zoom to previous/next


// for navigation toolbar  
function setToolSelect(toolName, toolbarName)
{
    var f = document.forms[docFormID];
    var toolbarItemName = toolName;
    var imageTag = toolbarName + toolbarItemName + 'Image';
    var cell = toolbarName + toolbarItemName;
    var toolbar = Toolbars[toolbarName];
    f.elements[toolbar.currentToolField].value = toolbarItemName;
    var clientAction =  toolbar.items[toolbarItemName].clientAction;
  
    if (clientAction != null){
        var clientActions = '';
        if (!toolbar.items[toolbarItemName].isClientActionCustom){
            var buddies = toolbar.buddyControls;
            if (buddies != null){
                for (var i = 0; i < buddies.length; i++){
                    var modeField = f.elements[buddies[i] + '_mode'];
                    if (modeField != null)modeField.value = toolbarItemName;
                    var cursor = toolbar.items[toolbarItemName].cursor;
                    if (cursor != null)
                        clientActions = clientActions + clientAction + "( '" + buddies[i] + "' , '" + toolbarItemName + "', " + toolbar.items[toolbarItemName].showLoading + ",'" + cursor + "'); ";
                }
             }
        }
        else{
            clientActions = clientAction;
        }
        
        var clientActionFunction = new Function(clientActions);
        clientActionFunction.call(null);

        Toolbars[toolbarName].selectTool();
        Toolbars[toolbarName].refreshGroup();
        Toolbars[toolbarName].refreshCommands();
    }
}




function showPrint()
{
    //webPrintStatus.style.visibility = "visible";
    var argument = "ControlID=Map1&ControlType=Map&EventArg=MapPrint";
    var context = arcgisWebApp.MapId;
    window.status = "Process map print..."
    eval(MyClientCallback);
}      



function MytoggleMagnifier() 
{
   var mag = document.getElementById('Magnifier1');
   var mag2= document.getElementById('Magnifier2');
   var dual = document.getElementById('rdDualImagery');
   
   if (dual.checked) {
        if (mag2!=null) { 
//            toggleFloatingPanelVisibility('Magnifier2');
            if (mag2.style.display == 'none')mag2.style.display = ''; 
        } else 
            alert("Magnifier is not available"); 
   }
   if (mag!=null) { 
//            toggleFloatingPanelVisibility('Magnifier1'); 
            if (mag.style.display == 'none')mag.style.display = '';
    } else 
        alert("Magnifier is not available");
       
    
}





// for magnifier control
function getCenterLocation(fpID)
{
   var fp = $get(fpID);
   var fw = fp.clientWidth;
//  var ch = document.getElementById(fpID+"_Crosshair");
//  var aoi = document.getElementById(fpID+"_AOIBox");
//  var aw = aoi.clientWidth;

  var l1 = parseInt(fp.style.left);
  var awl = l1 +  fw / 2 ; //ch.offsetLeft - aw / 2;   
   
  return awl;
}

function MyMagSets(l)
        {         
           
           fpID = "Magnifier1";
           fpID2 = "Magnifier2";
           
         var fp = $get("Magnifier1");
         var fp2 = $get("Magnifier2");
        
          var fpTitleRow=document.getElementById(fpID+"_Title");
          var fpTitleRow2=document.getElementById(fpID2+"_Title");
          var dualoptiondiv = document.getElementById("div_imgsel_dual"); 
          
          
          fpTitleRow.onmouseup=function(e){
                if (arcgisWebApp.MapDisplay2.style.display == "block"){
                    var t = getCenterLocation(fpID);                
                    var l = parseInt(arcgisWebApp.MapDisplay2.style.left);                               
                    if (t >= l){
                        toggleFloatingPanelVisibility('Magnifier2'); 
                        toggleFloatingPanelVisibility('Magnifier1');
                        fp2.style.top = fp.style.top;
                        fp2.style.left = fp.style.left;
                    }
                }
           }
           
           fpTitleRow2.onmouseup=function(e){
               if (arcgisWebApp.MapDisplay2.style.display == "block"){
                    var t = getCenterLocation(fpID2);
                    var l = parseInt(arcgisWebApp.MapDisplay2.style.left);  
                    if (t < l){
                        toggleFloatingPanelVisibility('Magnifier2'); 
                        toggleFloatingPanelVisibility('Magnifier1');
                        fp.style.top = fp2.style.top;
                        fp.style.left = fp2.style.left;
                    }
                }
           }            
          
//           var l1 ;
//           var l2 ;
//           var awl;
//           
//          var fw = fp.clientWidth;
//          var ch = document.getElementById(fpID+"_Crosshair");
//          var ch2 = document.getElementById(fpID2+"_Crosshair");
//          var aoi = document.getElementById(fpID+"_AOIBox");
//          var aw = aoi.clientWidth;

//          var fpTitleRow=document.getElementById(fpID+"_Title");
//          var fpTitleRow2=document.getElementById(fpID2+"_Title");
//          
//          fpTitleRow.onmouseup=function(e){
//                var t = fp.style.bottom;
//                l1 = parseInt(fp.style.left);
//                window.status = l1;
//                awl = l1 + ch.offsetLeft - aw / 2;     
//                if (awl > l){
//                     fp.style.left = (l - (ch.offsetLeft - aw / 2 )) + 'px';
//                     fp.style.bottom = t;
//                }
//           } 
//          
//          var s = document.getElementById('rdSingleImagery');
//          if (s.checked != true){
//                 fpTitleRow2.onmouseup=function(e){
//                 
//                 l2 = parseInt(fp2.style.left);
//                 window.status = l2;
//                 
//                var t = fp2.style.bottom;
//                awl = l2 + ch2.offsetLeft + aw / 2;   
//                if (awl < l){
//                     fp2.style.left = (l - ch.offsetLeft -aw / 2 ) + 'px';
//                     fp2.style.bottom = t;
//                }
//           }
//          
//          }
         
           
           
        } 
        
//function MyMagSetts(l)
//        {         
//           
//           fpID = "Magnifier1";
//           fpID2 = "Magnifier2";
//           
//           fp = esriMagnifiers[fpID].floatingPanel;
//           fp2 = esriMagnifiers[fpID2].floatingPanel;
//          
//          
//           var l1 ;
//           var l2 ;
//           var awl;
//           
//          var fw = fp.clientWidth;
//          var ch = document.getElementById(fpID+"_Crosshair");
//          var ch2 = document.getElementById(fpID2+"_Crosshair");
//          var aoi = document.getElementById(fpID+"_AOIBox");
//          var aw = aoi.clientWidth;

//          var fpTitleRow=document.getElementById(fpID+"_Title");
//          var fpTitleRow2=document.getElementById(fpID2+"_Title");
//          
//          fpTitleRow.onmouseup=function(e){
//                var t = fp.style.bottom;
//                l1 = parseInt(fp.style.left);
//                window.status = l1;
//                awl = l1 + ch.offsetLeft - aw / 2;     
//                if (awl > l){
//                     fp.style.left = (l - (ch.offsetLeft - aw / 2 )) + 'px';
//                     fp.style.bottom = t;
//                }
//           } 
//          
//          var s = document.getElementById('rdSingleImagery');
//          if (s.checked != true){
//                 fpTitleRow2.onmouseup=function(e){
//                 
//                 l2 = parseInt(fp2.style.left);
//                 window.status = l2;
//                 
//                var t = fp2.style.bottom;
//                awl = l2 + ch2.offsetLeft + aw / 2;   
//                if (awl < l){
//                     fp2.style.left = (l - ch.offsetLeft -aw / 2 ) + 'px';
//                     fp2.style.bottom = t;
//                }
//           }
//          
//          }
//         
//           
//           
//        } 
        
        
        
   
      
 
function gettip(v){
    if(v =='single')document.getElementById('tip').innerHTML="(Tip: show one image)";
    else document.getElementById('tip').innerHTML="(Tip: show side-by-side image for comparison)";
    document.body.style.cursor = 'help';
}

      
function resettip(){
document.getElementById('tip').innerHTML=" ";
document.body.style.cursor = 'default';


}        


//for test only
function dockFloatingPanel2(fpID)
{
    var fp = document.getElementById(fpID);
    if (fp==null)return;
    if (FloatingPanels[fpID]==null)return;
   
   ie6SaveCheckboxState(fp); 
    
    // first set some dock settings
    fp.style.width="100%";
    fp.style.position="relative";
    fp.style.top="0px";
    fp.style.left="0px";
    
    //var dockParent=FloatingPanels[fpID].dockParent;
    var dockParent=document.getElementById(FloatingPanels[fpID].dockParent);
    if (dockParent==null)return;
    //
    // add floatingpanel to dock parent
    //
    // this is to work-around a netscape 8.1.2 bug. If the floatingpanel parent
    // is the same as the node we are appending it to, then it will crash netscape.
    // this workaround just checks to see if the floatingpanel parent is the same as
    // the docking container, if so, we remove the node first before we dock it.
    fp.removeNode(true); // for some reason, it needs to be removed twice for netscape 8.1.2
    if (dockParent==fp.parentElement) fp.removeNode(true); 
    dockParent.appendChild(fp);
    // make floatingpanel not draggable
    var fpTitleRow=document.getElementById(fpID+"_Title");
    fpTitleRow.style.cursor="";
    fpTitleRow.onmousedown=null;
    // turn on contextmenu
    if (FloatingPanels[fpID].dockedContextMenuID!=null && FloatingPanels[fpID].dockedContextMenuID.length>0)
    {
        fpTitleRow=document.getElementById(fpID+"_Title");
        fpTitleRow.oncontextmenu=function(e){esriShowContextMenu(e,FloatingPanels[fpID].dockedContextMenuID,"","TitleRow");return false;};
    }    
    // make width not resizable
    var fpResizeImage=null;
    fpResizeImage=document.getElementById(fpID+"_SideResizeImage");
    fpResizeImage.style.cursor="";
    fpResizeImage.onmousedown=null;
    // make corner not resizable
    fpResizeImage=document.getElementById(fpID+"_CornerResizeImage");
    fpResizeImage.style.cursor="";
    fpResizeImage.onmousedown=null;
    
    // switch from undockedImage to dockedImage
    var dockButton=document.getElementById(fpID+"_DockButton");
    switchImageSourceAndAlphaBlend(dockButton,FloatingPanels[fpID].dockedImage, FloatingPanels[fpID].forcePNG);
    
    FloatingPanels[fpID].docked=true;
	ie6Workarounds(fpID);
	ie6RetrieveCheckboxState(fp);
	//if (FloatingPanels[fpID].onDockFunction != null) FloatingPanels[fpID].onDockFunction(fp);
}   

function undockFloatingPanel2(fpID)
{
    var fp = document.getElementById(fpID);
    if (fp==null)return;
    if (FloatingPanels[fpID]==null)return;

	ie6SaveCheckboxState(fp);
	
    var outsideContainerID=fpID + "_Container";
    var outsideContainer=document.getElementById(outsideContainerID);
    
    // create outside container if it doesn't exist
    if (outsideContainer==null)
    {
        outsideContainer=document.createElement('div');
        outsideContainer.id=outsideContainerID;
        outsideContainer.style.margin="0px";
        outsideContainer.style.padding="0px";
        document.body.appendChild(outsideContainer);
    }
    
    // add floatingpanel to outside container
    //
    // first set style height and width to clientheight and clientwidth
    fp.style.width=fp.clientWidth+"px";
    //fp.style.height=fp.clientHeight+"px";
    // set some undock settings
    var rect=calcElementPosition(fpID);
    fp.style.left=rect.left+rect.width+10+"px";
    fp.style.top=rect.top+"px";
    fp.style.position="absolute";
    // store dockParent
    FloatingPanels[fpID].dockParent=fp.parentNode.id;
    // add floatingpanel to outside container
    outsideContainer.appendChild(fp);
    // make floatingpanel draggable
    var fpTitleRow=document.getElementById(fpID+"_Title");
    fpTitleRow.style.cursor="move";
    fpTitleRow.onmousedown=function(e){if(!isLeftButton(e))return; esriBringFloatingPanelToFront(fpID);startWindowDrag(fpID);};
 
    // turn off dockedContextMenu
    fpTitleRow=document.getElementById(fpID+"_Title");
    fpTitleRow.oncontextmenu=null;
    // make width resizable
    var fpResizeImage=null;
    fpResizeImage=document.getElementById(fpID+"_SideResizeImage");
    fpResizeImage.style.cursor="w-resize";
    fpResizeImage.onmousedown=function(){startWindowResize(fpID,'width');if(!isIE)return false;};
    // make height resizable
    fpResizeImage=document.getElementById(fpID+"_BottomResizeImage");
    fpResizeImage.style.cursor="s-resize";
    fpResizeImage.onmousedown=function(){startWindowResize(fpID,'height');if(!isIE)return false;};
    // make corner resizable
    fpResizeImage=document.getElementById(fpID+"_CornerResizeImage");
    fpResizeImage.style.cursor="nw-resize";
    fpResizeImage.onmousedown=function(){startWindowResize(fpID);if(!isIE)return false;};
    // switch from dockedImage to undockedImage
    var dockButton=document.getElementById(fpID+"_DockButton");
    switchImageSourceAndAlphaBlend(dockButton,FloatingPanels[fpID].undockedImage, FloatingPanels[fpID].forcePNG);
    FloatingPanels[fpID].docked=false;
    esriBringFloatingPanelToFront(fpID);
	ie6Workarounds(fpID);
	ie6RetrieveCheckboxState(fp);
}   

function MyMapIdentify()
{
    map2 = arcgisWebApp.map2;
    map = arcgisWebApp.map;
    
    var div2 = document.getElementById("Map_Panel");
    if (div2.style.display != 'none'){
    
    var toolbar = Toolbars["Toolbar1"];
    
    document.body.style.cursor = toolbar.items["MapIdentify"].cursor;;
    }
    
    //
    //MapPoint(map_2.controlName, "MapIdentify", false);
    //map_2.divObject.onmousedown = MyMapIdClick;
    
}

function MyMapIdClick(e) {
    map = Maps['Map1'];
    map.cursor = map.divObject.style.cursor;
     
    var mapdisplay2 = document.getElementById("divmap2");
    
        
    getXY(e)
    if (webMapAppMapDisplay_2.style.display != 'none'){
        var l = (getWinWidth() + webMapAppLeftPanelWidth + webMapAppToggleWidth) / 2;
        if (mouseX > l) map = Maps['Map2'];
    }
    
   //alert(map.controlName);

	var box = calcElementPosition(map.containerDivId);
	zleft = mouseX - box.left;
	ztop = mouseY - box.top;

	map.xMin=zleft;
	map.yMin=ztop;
	var div = document.getElementById("IdentifyLocation");
	if (div==null) {
	    addIdentifyLocation();
	}
	map.getTopLeftTile();
	var fpBody = document.getElementById('Results_TaskResults1');
	var html = fpBody.innerHTML;
	fpBody.innerHTML = "<div><img src='images/callbackActivityIndicator.gif' align='middle'/> Getting Information. . .</div>" + html;
	showFloatingPanel('Results');
	fpBody=document.getElementById('Results_BodyRow');
	if (fpBody.style.display=="none")
	    toggleFloatingPanelState('Results','images/collapse.gif','images/expand.gif');

	var message;
	if (map.controlName == 'Map1'){
	    message = "ControlID=Map1&ControlType=Map&EventArg=MapIdentify&Map1_mode=MapIdentify&minx=" + zleft + "&miny=" + ztop;
	}else{
	    message = "ControlID=Map2&ControlType=Map&EventArg=MapIdentify&Map2_mode=MapIdentify&minx=" + zleft + "&miny=" + ztop;
	}
	
	var context = map.controlName;
	eval(map.identifyCallbackFunctionString);
	
	
	div = document.getElementById("IdentifyLocation");
	// point is bottom center... 2 pixels up for shadow
	var cWidth = Math.floor(div.clientWidth / 2);
	var cHeight = div.clientHeight;
	//alert(cWidth + " x " + cHeight); // width and height might not be available on first time.... if so, approximate size needed
	if (cWidth==0) cWidth = 12;
	if (cHeight==0) cHeight = 29;
	var idLeft = zleft - parseInt(map.divObject.style.left) - cWidth;
	var idTop = ztop - parseInt(map.divObject.style.top) - cHeight + 2; // add two back for icon bottom
//	if (isIE) {
//	    idTop+=2; 
//	    //idLeft+=2;
//	}
	window.setTimeout('moveLayer("IdentifyLocation", ' + idLeft + ', ' + idTop + '); showLayer("IdentifyLocation");', 0);
	map.mode = map.tempMode;
	map.actionType = map.tempAction;
	map.cursor = map.tempCursor;
	return false;
	
}

