﻿// JScript File

var webMapAppTopTBCellDiv_Nav = null;
var webMapAppTopTBCellDiv_Ser = null;

function initLinkBarElements() {

    webMapAppTopTBCellDiv_Nav = document.getElementById("TopTBCellDiv_Nav");
    webMapAppTopTBCellDiv_Ser = document.getElementById("TopTBCellDiv_Ser");

    if (webMapAppTopTBCellDiv_Nav != null ) {
        webMapAppTopTBCellDiv_Nav.style.top = "50px";
        webMapAppTopTBCellDiv_Nav.style.right = "15px";
    }
 
    if (webMapAppTopTBCellDiv_Ser != null ) {
        webMapAppTopTBCellDiv_Ser.style.top = "50px";
        webMapAppTopTBCellDiv_Ser.style.left = "473px";
    }

}


function HoverToolBarItemOn(id) {
    var button = document.getElementById(id);
    button.style.border="1px solid #21496b";
    document.getElementById(id).style.fontWeight="900";
    //button.style.border-right-style = "thin solid Black";
}

function HoverToolBarItemOff3(id) {
    var button = document.getElementById(id);
    button.style.border="none";
    document.getElementById(id).style.fontWeight="600";
    button.style.borderLeft = "1px solid Black";
    button.style.borderRight = "1px solid Black";
}

function HoverToolBarItemOff(id) {
    var button = document.getElementById(id);
    button.style.border="none";
    document.getElementById(id).style.fontWeight="600";
    button.style.borderLeft = "1px solid Black";
}

function RefreshMap() {
    FireCallBack("RefreshMap","RefreshMap","");
}

function IMOBackDoor(swis, sbl) {
    var args = "swis=" + swis + "&sbl=" + sbl;
    FireCallBack("IMOBackDoor","IMOBackDoor",args);
}


function clearSelectionChecks() {

    var elems = document.form1.elements;
    for (var i=0; i<elems.length; i++) {
          if (elems[i].id.indexOf('attrbtn_h_') != -1) {
          elems[i].checked = false;
       }
    }
}

function showBusyIcon(id) {
    var icon = document.getElementById(id);
    icon.style.display="block";
}

function hideBusyIcon(id) {
    var icon = document.getElementById(id);
    icon.style.display="none";
}

function startCustomSearch(EventArg, callbackArguments) {

    if(callbackArguments != "") {
        callbackArguments = "&" + callbackArguments;
    }
    
    var message = "EventArg=" + EventArg + callbackArguments; 
    var context = map.controlName;
    
    ShowLoading();

    WebForm_DoCallback('__Page',message,processCallbackResult,context,postBackError,true);
}

function ShowLoading() {
	if (map!=null) {
		if (map.loadingObject!=null) {
		    map.loadingObject.style.visibility = "visible";
		}
	}
	if (page!=null) {
		if (page.loadingObject!=null) {
	        page.loadingObject.style.visibility = "visible";	
	    }
	} 
}

function HideLoading() {
	if (map!=null) {
		if (map.loadingObject!=null) {
		    map.loadingObject.style.visibility = "hidden";
		}
	}
	if (page!=null) {
		if (page.loadingObject!=null) {
		    page.loadingObject.style.visibility = "hidden";
		}
	}
}




function Menu_HoverStatic2(obj, id) {
    var tag = document.getElementById(id);
    
    if(tag != null) {
        document.getElementById(id).style.color = "#FFFFFF";
        obj.className = "Custom_ListStyle_13";
    }
}

function Menu_Unhover2(obj, id) {
    var tag = document.getElementById(id);
    
    if(tag != null) {
        document.getElementById(id).style.color = "#7c6f57";
        obj.className = "Custom_ListStyle_1";
    }
}


function openMe(fileName) {
    window.open('CSV.aspx?fileName=' + fileName, 'hello', 'toolbar=no,status=no,menubar=yes' );
}

//function openLayout(fileName) {
//    window.open(fileName);
//}

function ClearSelection() {
	FireCallBack("ClearSelection","ClearSelection","");
}

function ClearGraphics() {
	FireCallBack("ClearGraphics","ClearGraphics","");
	return false;
}

function ZoomFullExtent() {
	FireCallBack("ZoomFullExtent","ZoomFullExtent", "");
}

function DownloadFeatureData(id) {
    var obj = document.getElementById(id);
    var type = obj.value;
    
    var elems = document.form1.elements;
    var ct = 0;
    var fids = new Array();
    var currId = "";
    var hasResults = false;
    for (var i=0; i<elems.length; i++) {
        if (elems[i].id.indexOf('attrbtn_h_') != -1) {
            hasResults = true;
            currId = elems[i].id.substring(elems[i].id.lastIndexOf("_")+1)
            if(elems[i].checked) {
                fids[ct] = currId;
                ct++;
            }
        }
    }
    
    if (!hasResults) {
        alert ("There are no results to download.");
        return false;
    }
    
    if ((type == "Highlighted") & (fids.join() == "")) {
        alert ("No features were selected to download.");
        return false;
    }
    

    
    FireCallBack("DownloadFeatureData","AttributeResults","type=" + type + "&fids=" + fids.join());
}

function SelectFeatureRow(rowId, fid) {

    var tablerow = document.getElementById(rowId);
    
    //alert(rowId + " - " + tablerow.className);
  
    if (tablerow.className == "MapViewer_TableDataSelectedStyle") {
        tablerow.className = "MapViewer_TableDataStyle";
    } else {
        tablerow.className = "MapViewer_TableDataSelectedStyle";
    }
    
    var elems = document.form1.elements;
    var ct = 0;
    var fids = new Array()
    var currId = ""
    for (var i=0; i<elems.length; i++) {
        if (elems[i].id.indexOf('attrbtn_h_') != -1) {
            currId = elems[i].id.substring(elems[i].id.lastIndexOf("_")+1)
            if(elems[i].checked) {
                fids[ct] = currId;
                ct++;
            }
        }
    }
    
    FireCallBack("SelectFeatureRow","AttributeResults","fids=" + fids.join());
}

function ZoomToSelected() {
  
    var elems = document.form1.elements;
    var ct = 0;
    var fids = new Array()
    var currId = ""
    for (var i=0; i<elems.length; i++) {
        if (elems[i].id.indexOf('attrbtn_h_') != -1) {
            currId = elems[i].id.substring(elems[i].id.lastIndexOf("_")+1)
            if(elems[i].checked) {
                fids[ct] = currId;
                ct++;
            }
        }
    }
    
    if (fids.join() == "") {
        alert ("Please select at least one feature in the list to zoom to.");
        return false;
    }
    
    FireCallBack("ZoomToSelected","AttributeResults","fids=" + fids.join());
}

function ShowSelected() {
  
    var elems = document.form1.elements;
    var ct = 0;
    var fids = new Array()
    var currId = ""
    for (var i=0; i<elems.length; i++) {
        if (elems[i].id.indexOf('attrbtn_h_') != -1) {
            currId = elems[i].id.substring(elems[i].id.lastIndexOf("_")+1)
            if(elems[i].checked) {
                fids[ct] = currId;
                ct++;
            }
        }
    }
    
    if (fids.join() == "") {
        alert ("No features were selected to filter.");
        return false;
    }

    FireCallBack("ShowSelected","AttributeResults","fids=" + fids.join());
}

function ShowAll() {

    var elems = document.form1.elements;
    var ct = 0;
    var fids = new Array()
    var currId = ""
    for (var i=0; i<elems.length; i++) {
        if (elems[i].id.indexOf('attrbtn_h_') != -1) {
            currId = elems[i].id.substring(elems[i].id.lastIndexOf("_")+1)
            if(elems[i].checked) {
                fids[ct] = currId;
                ct++;
            }
        }
    }

    FireCallBack("ShowAll","AttributeResults","fids=" + fids.join());
}

function BufferSelected(id) {

    var value = document.getElementById(id).value;
  
    var elems = document.form1.elements;
    var ct = 0;
    var fids = new Array()
    var currId = ""
    for (var i=0; i<elems.length; i++) {
        if (elems[i].id.indexOf('attrbtn_h_') != -1) {
            currId = elems[i].id.substring(elems[i].id.lastIndexOf("_")+1)
            if(elems[i].checked) {
                fids[ct] = currId;
                ct++;
            }
        }
    }
    
    if (fids.join() == "") {
        hideBusyIcon('Busy5');
        alert ("No features were selected to buffer.");
        return false;
    }
    
    FireCallBack("BufferSelected","AttributeResults","fids=" + fids.join() + "&distance=" + value);
}

function SearchByOwner(id) {
    
    var value;
    
    var txtField;
    //if (isIE) {
        txtField = document.getElementById(id);
        
        value = txtField.value;
//    } else {
//        txtField = document.getElementsByName(id);
//        
//        var el;
//        var els = document.getElementsByName(id); 
//        var len=els.length;
//        
//        if (els.length == 0) {
//            value="xxxxxx";
//        } else {
//            value = els[0].value;
//        }
    //}
    
        
    FireCallBack("SearchByOwner","AttributeResults","searchText=" + value);
}

function SearchBySBL(id) {

    var value;
    
    var txtField;
    //if (isIE) {
        txtField = document.getElementById(id);
        
        value = txtField.value;
//    } else {
//        txtField = document.getElementsByName(id);
//        
//        var el;
//        var els = document.getElementsByName(id); 
//        var len=els.length;
//        
//        if (els.length == 0) {
//            value="xxxxxx";
//        } else {
//            value = els[0].value;
//        }
//    }
    
    FireCallBack("SearchBySBL","AttributeResults","searchText=" + value);
}

function _Submit(e, id) {

    if(e.keyCode == "13") {
        if (id == "AddressSearchTable") {
            showBusyIcon('Busy3');
            SearchByAddress('txtAddress2', 'txtAddress1');
        } else if (id == "OwnerSearchTable") {
            showBusyIcon('Busy1');
            SearchByOwner('TextBox2');
        } else if (id == "SBLSearchTable") {
            showBusyIcon('Busy2');
            SearchBySBL('txtSBL');
        } else if (id == "AbuttersTable") {
            showBusyIcon('Busy5');
            BufferSelected('TextBox1');
        } else if (id == "DownloadResultsTable") {
            DownloadFeatureData('DropDownList2');
        } else if (id == "MapTitleTable") {
            showBusyIcon('Busy4');
            PrintPreview('txtMapTitle');
        }
    }
    
    return false;
}

function changeToButton(id) {
    document.getElementById(id).type = "button";
}

function SearchByAddress(id1, id2) {

    var value1;
    var value2;
    
    var txtField1;
    var txtField2;
    
    //if (isIE) {
        txtField1 = document.getElementById(id1);
        txtField2 = document.getElementById(id2);
        
        value1 = txtField1.value;
        value2 = txtField2.value;
//    } else {
//        txtField1 = document.getElementsByName(id1);
//        txtField2 = document.getElementsByName(id1);
//        
//        var el;
//        var els = document.getElementsByName(id1); 
//        var len=els.length;
//        
//        if (els.length == 0) {
//            value1="xxxxxx";
//        } else {
//            value1 = els[0].value;
//        }
//        
//        els = document.getElementsByName(id2); 
//        len=els.length;
//        
//        if (els.length == 0) {
//            value2="xxxxxx";
//        } else {
//            value2 = els[0].value;
//        }
//    }
    
    FireCallBack("SearchByAddress","AttributeResults","searchText=" + value1 + "&searchText2=" + value2);
}

function ZoomToFeature(id,Rowcount,ObjectID) {
	FireCallBack("ZoomToFeature","AttributeResults","objectid=" + ObjectID);
}

function PrintPreview(id) {
    var txtField1 = document.getElementById(id);
	FireCallBack("PrintPreview","PrintPreview","MapTitle=" + txtField1.value);
}


//Fires a Callback to the Server
//Parameters:
//  ServerFunction - The case to execute on the server
//  ServerMode -    The mode being exected
//  ServerVars - Any values used in executing serverside function.  Values need to be in var=value&var=value&var=value format
//  Example ServerVars: objectid=34&layer=Roads
function FireCallBack(ServerFunction, ServerMode, ServerVars) {

    if(ServerVars != "") {
        ServerVars = "&" + ServerVars;
    }

    var message = "ControlID=Map1&ControlType=Map&EventArg=" + ServerFunction + "&Map1_mode=" + ServerMode + ServerVars; 
    var context = map.controlName;

    WebForm_DoCallback('__Page',message,processCallbackResult,context,postBackError,true);

}

function FireCallBack2(ServerFunction, ServerMode, ServerVars) {


    var message = "ControlID=PageLayout1&ControlType=PageLayout&EventArg=" + ServerFunction + "&PageLayout1_mode=" + ServerMode + ServerVars; 
    //var context = map.controlName;

    WebForm_DoCallback('__Page',message,processCallbackResult,'',postBackError,true);

}


  function openLayout(imageURL) {
    window.open(imageURL); 
  }
  
  function toggleHelp(buttonId, id) {
  
    var obj;
    
    obj = document.getElementById(id);
    btnHelp = document.getElementById(buttonId);
    
    if(obj.style.display == "block") {
        obj.style.display = "none";
        btnHelp.value = "Show Help >>";
    } else {
        obj.style.display = "block";
        btnHelp.value = "<< Hide Help";
    }
    
//    var btnHelp;

//    if (isIE) {
//        btnHelp = document.getElementById(buttonId);
//    } else {

//        var el;
//        alert(buttonId);
//        btnHelp = document.getElementsByName(buttonId);
//        alert(btnHelp.length);
//        
//        if (btnHelp.length == 0) {
//            btnHelp=null;
//        } else {
//            btnHelp = els[0];
//        }
//    }
//    
//    alert(btnHelp);
//    
//    //if(btnHelp == null) {
//        if(obj.style.display == "block") {
//            alert('a: ' + btnHelp.value + '-');
//            btnHelp.value = "Show Help >>";
//        } else {
//            alert('b' + btnHelp.value + '-');
//            btnHelp.value = "<< Hide Help";
//        }
//    //}
  }
  
  function closeHelp(buttonId, helpDivId, panel) {
  
        var helpDiv = document.getElementById(helpDivId);
        helpDiv.style.display = "none";

        var btnHelp
        //if (isIE) {
            btnHelp = document.getElementById(buttonId);
//        } else {
//            btnHelp = document.getElementsByName(buttonId);
//        }
        
        btnHelp.value = "Show Help >>";

        var fPanel = document.getElementById(panel);
        fPanel.style.height = "125px";
  }
  
  function setFieldFocus(id, id2) {
  
    var obj = document.getElementById(id);
    if(obj != null) {
      if((obj.style.display == "block") || (obj.style.display == "")) {
      
        //if (isIE) {
            document.getElementById(id2).focus();
//        } else {
//            document.getElementByNames(id2)[0].focus();
//        }
      }
    }
  }
  
  function clearField(id) {
    var txtbox = document.getElementById(id);
    if(txtbox != null) {
      txtbox.value = "";
    }
  }
  
  function showSBOPanel() {
        closeHelp('btnHelp1', 'div_OwnerHelp', 'FloatingPanel2');
        setTimeout("showFloatingPanel_Custom('FloatingPanel2')", 500);
        setTimeout("setFieldFocus('FloatingPanel2','TextBox2')",600);
  }
  
  function showMapTitlePanel() {
        setTimeout("clearField('FloatingPanel5')",450);
        setTimeout("showFloatingPanel_Custom('FloatingPanel5')", 500);
        setTimeout("setFieldFocus('FloatingPanel5','txtMapTitle')",600);
  }
  
  function showMagnifier() {
    // this is a custom function to work around ie7 glitch of losing everything in browser except floating panels
    setTimeout("showFloatingPanel_Custom('Magnifier1')", 500);
    esriMagnifiers.Magnifier1.hideMapImage();
  }
  
//function showMagnifierPanel(fpID) {
//    floatingPanel=document.getElementById(fpID);
//    floatingPanel.style.display='';    
//}
  
  function moveMagnify() {
    var x = document.getElementById("Magnifier1");
    x.style.left = 0 + "px";
  }
  
  
  function showSBSPanel() {
        closeHelp('btnHelp2', 'div_SBLHelp', 'FloatingPanel3');
        setTimeout("showFloatingPanel_Custom('FloatingPanel3')", 500);
        setTimeout("setFieldFocus('FloatingPanel3','txtSBL')",600);
  }
  
  function showSBAPanel() {
        closeHelp('btnHelp3', 'div_AddressHelp', 'FloatingPanel4');
        setTimeout("showFloatingPanel_Custom('FloatingPanel4')", 500);
        setTimeout("setFieldFocus('FloatingPanel4','txtAddress1')",600);
  }

function showFloatingPanel_Custom(fpID) {
    floatingPanel=document.getElementById(fpID);
    floatingPanel.style.display='';
}
  
  
//  function hideFloatingPanel2(fpID, doCallback, argument)
//{   
//    floatingPanel=document.getElementById(fpID);
//    
//    if (floatingPanel==null)
//        return;    
//                    
//    esriPanel = FloatingPanels[fpID];
//    floatingPanel.style.display='none';
//    var hfVisible = document.getElementById(fpID + '_hfVisible');
//    if (hfVisible!=null) {
//        hfVisible.value='false';
//        hfVisible.style.zIndex = '';
//    }
//        
//    if (esriPanel.contentOnHideFunction!=null) 
//        eval(esriPanel.contentOnHideFunction);
//        
//    //show container if directly on page
//    var fpContainer = document.getElementById(fpID + "_Container");
//    if (fpContainer != null)
//        fpContainer.style.display='none';

//	ie6Workarounds(fpID);

//    if (doCallback == true || doCallback == null)
//    {
//        if (argument == null)
//            argument='EventArg=hidden';
//        else
//            argument += '&EventArg=hidden';

//        var context=null;
//        eval(FloatingPanels[fpID].callbackFunctionString);
//    }
//}

//function showFloatingPanel2(fpID, doCallback, argument)
//{

//    //alert('a');
//    
//    floatingPanel=document.getElementById(fpID);
//    alert('b: ' + floatingPanel.style.display);
//    var hfVisible = document.getElementById(floatingPanel.id + '_hfVisible');

//    if ((hfVisible.value == null) || (hfVisible.value == "false") || (hfVisible.value == "")) {
//    
//        
//        
//        esriPanel = FloatingPanels[fpID];
//        
//        floatingPanel.style.display='';
//        //alert('c');
//        var hfVisible = document.getElementById(floatingPanel.id + '_hfVisible');
//        if (hfVisible!=null) hfVisible.value='true';
//        if (esriPanel.contentOnShowFunction!=null) eval(esriPanel.contentOnShowFunction);
//        //show container if directly on page
//        var fpContainer = document.getElementById(fpID + "_Container");
//        if (fpContainer != null)
//            fpContainer.style.display='';
//            
//        esriBringFloatingPanelToFront(fpID);
//	    ie6Workarounds(fpID);
//    	
//	    if (esriPanel.docked && esriPanel.onDockFunction!=null) 
//	        esriPanel.onDockFunction(floatingPanel);
//    	
//        if (doCallback == true || doCallback == null)
//        {
//             if (argument == null)
//                argument='EventArg=shown';
//            else
//                argument += '&EventArg=shown';
//            var context=null;
//            eval(FloatingPanels[fpID].callbackFunctionString);
//        }
//    } else {
//        hideFloatingPanel2(fpID, false);
//    }
//    
//    //alert('f');
//}


function toggleList(buttonId) {

    var elems = document.form1.elements;
    var ct = 0;
    var fids = new Array()
    var currId = ""
    for (var i=0; i<elems.length; i++) {
        if (elems[i].id.indexOf('attrbtn_h_') != -1) {
            currId = elems[i].id.substring(elems[i].id.lastIndexOf("_")+1)
            if(elems[i].checked) {
                fids[ct] = currId;
                ct++;
            }
        }
    }
    
    var btnShowResults = document.getElementById(buttonId);
    if (btnShowResults == null) {
        return false;
    }

    if (btnShowResults.value == "Show Highlighted Only") {
    
        if (fids.join() == "") {
            alert ("No features were selected to filter.");
            return false;
        }
        
        FireCallBack("ShowSelected","AttributeResults","fids=" + fids.join());
    } else if (btnShowResults.value == "Show All") {
        FireCallBack("ShowAll","AttributeResults","fids=" + fids.join());
    }
}

function changeButtonText(buttonId, text) {

    var btnShowResults = document.getElementById(buttonId);
    if (btnShowResults == null) {
        return false;
    }
    
    btnShowResults.value = text
}

String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

function navigateToHome() {
    window.location="index.htm"
}
