// JScript File
var webMapAppTopTBCellDiv_Ser = null;

var checkKeys = "";


function initLinkBarElements() {

    webMapAppTopTBCellDiv_Ser = document.getElementById("TopTBCellDiv_Ser");
 
    if (webMapAppTopTBCellDiv_Ser != null ) {
        webMapAppTopTBCellDiv_Ser.style.top = "50px";
        webMapAppTopTBCellDiv_Ser.style.left = "323px";
    } 
}

function switchCategory(id) {
    
    var obj1 = document.getElementById(id + '_image');
    
    if(document.getElementById(id + '_div').style.display == "block") {
        document.getElementById(id + '_div').style.display = "none";
        obj1.src = "images/max.gif";
    } else {
        document.getElementById(id + '_div').style.display = "block";
        obj1.src = "images/min.gif";
    }
}




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 ZoomToLocation(val) {

//    var obj = document.getElementById('ddZoomMunis');
//    var loc;
//    
//    var i;
//    for (i=0; i<obj.options.length; i++) {
//        if (obj.options[i].selected) {
//            loc = obj.options[i].value;
//        }
//    }
    
	FireCallBack("ZoomToLocation","ZoomToLocation", "location=" + val);
}

function navigateToLogin() {
    window.location="Login.aspx"
}

function ShowQuickMap() {

    var obj = document.getElementById('ddZoomMunis1');
    var loc;
    
    var i;
    for (i=0; i<obj.options.length; i++) {
        if (obj.options[i].selected) {
            loc = obj.options[i].value;
        }
    }
    
	FireCallBack("ShowQuickMap","ShowQuickMap", "sMuni=" + loc);
}

function ShowQuickMap2(val1, val2) {
    //alert(val1 + ", " + val2);
    //return false;

//    var obj = document.getElementById('ddZoomMunis1');
//    var loc;
//    
//    var i;
//    for (i=0; i<obj.options.length; i++) {
//        if (obj.options[i].selected) {
//            loc = obj.options[i].value;
//        }
//    }
//    
	FireCallBack("ShowQuickMap","ShowQuickMap", "sMuni=" + val1 + "&sMapName=" + val2);
}

function expandTOC() {   
	FireCallBack("ExpandTOC","ExpandTOC", "");
}

function hideMainNode() {   
	FireCallBack2("HideMainNode","HideMainNode", "");
}

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 ("Must highlight parcel(s) 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";
        tablerow.style.backgroundColor = "#f4f4f4";
    } else {
        tablerow.className = "MapViewer_TableDataSelectedStyle";
        tablerow.style.backgroundColor = "";
    }
    
    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 ("Must highlight parcel(s) 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 ("Must highlight parcel(s) to buffer.");
        return false;
    }
    
    FireCallBack("BufferSelected","AttributeResults","fids=" + fids.join() + "&distance=" + value);
}

function SearchByOwner(id, id2) {
    
    var value;
    var value2;
    
    var txtField;
    var txtField2;

    txtField = document.getElementById(id);
    txtField2 = document.getElementById(id2);
        
    value = txtField.value;
    value2 = txtField2.value;

    FireCallBack("SearchByOwner","AttributeResults","searchText=" + value + "&swis=" + value2);
}

function SearchBySBL(id, id2) {

    var value;
    var value2;
    
    var txtField;
    var txtField2;

    txtField = document.getElementById(id);
    txtField2 = document.getElementById(id2);
        
    value = txtField.value;
    value2 = txtField2.value;
    
    FireCallBack("SearchBySBL","AttributeResults","searchText=" + value + "&swis=" + value2);
}



function _Submit(e, id) {

    if(e.keyCode == "13") {
        if (id == "AddressSearchTable") {
            showBusyIcon('Busy3');
            SearchByAddress('txtAddress2', 'txtAddress1');
        } else if (id == "OwnerSearchTable") {
            showBusyIcon('Busy1');
            SearchByOwner('TextBox2', 'dd4');
        } else if (id == "SBLSearchTable") {
            showBusyIcon('Busy2');
            SearchBySBL('txtSBL', 'dd3');
        } else if (id == "AbuttersTable") {
            showBusyIcon('Busy5');
            BufferSelected('TextBox1');
        } else if (id == "DownloadResultsTable") {
            DownloadFeatureData('DropDownList2');
        } else if (id == "MapTitleTable") {
            showBusyIcon('Busy4');
            PrintPreview('txtMapTitle', 'ddSaveAs');
        }
    }
    
    return false;
}

function changeToButton(id) {
    document.getElementById(id).type = "button";
}

function ToggleAddressNode() {

    TreeViewPlusObjects['Toc_Panel_Toc1'].toggleNodeState('5563b1116a7e4c69a9399e68aa243977', false);

}

function SearchByAddress(id1, id2) {

    var value1;
    var value2;
    
    var txtField1;
    var txtField2;
    
    txtField1 = document.getElementById(id1);
    txtField2 = document.getElementById(id2);
        
    value1 = txtField1.value;
    value2 = txtField2.value;
    
    FireCallBack("SearchByAddress","AttributeResults","searchText=" + value1 + "&searchText2=" + value2);
}

function ClearAddressPoints() {
    FireCallBack("ClearAddressPoints","ClearAddressPoints","");
}

function ZoomToFeature(id,Rowcount,ObjectID) {
	FireCallBack("ZoomToFeature","AttributeResults","objectid=" + ObjectID);
}

//function PrintPreview(id, id2) {
//    var txtField1 = document.getElementById(id);
//    var dd1 = document.getElementById(id2);
//	FireCallBack("PrintPreview","PrintPreview","MapTitle=" + txtField1.value + "&pageSize=" + dd1.value);
//}

function ZoomAndPrint(PrintKey, ParcelID) {
	FireCallBack("ZoomToFeature","AttributeResults","objectid=" + ParcelID);
	
	setTimeout("PrintFlyer('" + PrintKey + "', '" + ParcelID + "')", 3000);
}

function PrintPreview(id, id2) {
    var txtField1 = document.getElementById(id);
    var dropDown1 = document.getElementById(id2);
	FireCallBack("PrintPreview","PrintPreview","MapTitle=" + txtField1.value + "&MapType=" + dropDown1.value);
}

function PrintFlyer(PrintKey, ParcelID) {
	FireCallBack("PrintFlyer","AttributeResults","PrintKey=" + PrintKey + "&ParcelID=" + ParcelID);
}


//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 showSBSPanel() {
        //closeHelp('btnHelp2', 'div_SBLHelp', 'FloatingPanel3');
        setTimeout("showFloatingPanel_Custom('FloatingPanel3')", 500);
        setTimeout("setFieldFocus('FloatingPanel3','dd3')",600);
        
        FireCallBack("FillDropDown1","FillDropDown1","ddID=dd3");
  } 
  
  function showSBAPanel() {
        //closeHelp('btnHelp3', 'div_AddressHelp', 'FloatingPanel4');
        setTimeout("showFloatingPanel_Custom('FloatingPanel4')", 500);
        setTimeout("setFieldFocus('FloatingPanel4','txtAddress1')",600);
  }

  function showSBOPanel() {
        //closeHelp('btnHelp1', 'div_OwnerHelp', 'FloatingPanel2');
        setTimeout("showFloatingPanel_Custom('FloatingPanel2')", 500);
        setTimeout("setFieldFocus('FloatingPanel2','dd4')",600);
        
        FireCallBack("FillDropDown1","FillDropDown1","ddID=dd4");
  }
  
  function showMapTitlePanel() {
        setTimeout("clearField('FloatingPanel5')",450);
        setTimeout("showFloatingPanel_Custom('FloatingPanel5')", 500);
        setTimeout("setFieldFocus('FloatingPanel5','txtMapTitle')",600);
  }
  
  function showSearchPanel() {
        setTimeout("showFloatingPanel_Custom('FP_Search')", 500);
  }
  
  function fillTypes() {
    var selectBox = document.getElementById('searchTypes');
    
    selectBox.options.length = 0;
    selectBox.options[0] = new Option("","");  // empty option
    
	for(var i=0; i < mySearchTypes.searchtypes.searchtype.length; i++) {
	    var xx = 1;
	    var tempVars = [];

	    tempVars[0] = mySearchTypes.searchtypes.searchtype[i].attributes.name;
	    tempVars[1] = mySearchTypes.searchtypes.searchtype[i].attributes.label;
		selectBox.options[i+1] = new Option(tempVars[1],tempVars[0]);
	}
  }
  
  setSearchFields = function() {
    var val = document.getElementById('searchTypes').value;
    var searchFields = "";
    var searchFieldLabels = "";
    var searchFieldDatatypes = "";
    var searchLayer = "";
    //var idField = "";
    //var gisidField = "";
    
    for(var i=0; i < mySearchTypes.searchtypes.searchtype.length; i++) {
        if(val == mySearchTypes.searchtypes.searchtype[i].attributes.name) {
            searchLayer = mySearchTypes.searchtypes.searchtype[i].attributes.layer
            //idField = mySearchTypes.searchtypes.searchtype[i].attributes.idfield
            //gisidField = mySearchTypes.searchtypes.searchtype[i].attributes.gisidfield
        
            if(mySearchTypes.searchtypes.searchtype[i].searchfield.length) {
                for(var j=0; j < mySearchTypes.searchtypes.searchtype[i].searchfield.length; j++) {
                    var tval1 = mySearchTypes.searchtypes.searchtype[i].searchfield[j].attributes.name;
                    var tval2 = mySearchTypes.searchtypes.searchtype[i].searchfield[j].attributes.label;
                    var tval3 = mySearchTypes.searchtypes.searchtype[i].searchfield[j].attributes.datatype;
                    if(j<mySearchTypes.searchtypes.searchtype[i].searchfield.length-1) {
                        searchFields = searchFields + tval1 + '$s$';
                        searchFieldLabels = searchFieldLabels + tval2 + '$s$';
                        searchFieldDatatypes = searchFieldDatatypes + tval3 + '$s$'; 
                    } else {
                        searchFields = searchFields + tval1;
                        searchFieldLabels = searchFieldLabels + tval2;
                        searchFieldDatatypes = searchFieldDatatypes + tval3;
                    }
                }
            } else {
                var tval1 = mySearchTypes.searchtypes.searchtype[i].searchfield.attributes.name;
                var tval2 = mySearchTypes.searchtypes.searchtype[i].searchfield.attributes.label;
                var tval3 = mySearchTypes.searchtypes.searchtype[i].searchfield.attributes.datatype;
                searchFields = tval1;
                searchFieldLabels = tval2;
                searchFieldDatatypes = tval3;
            }
        }
    }
    
    //alert(searchFields);
    
    var mySearchFields = searchFields.split('$s$');
    var mySearchFieldLabels = searchFieldLabels.split('$s$');
    
    var tbl = document.getElementById('tblSearchFields');    
    for(var rows=tbl.tBodies[0].rows.length-1; rows>=0;rows--) {
        tbl.tBodies[0].deleteRow(rows);
    }
    
    if((mySearchFields.length == 1) && (mySearchFields[0] == "")) {
        return false;
    }
    
    var row = tbl.tBodies[0].insertRow(0);
    row.style.height = "1px";
    
    var cella = row.insertCell(0);
    cella.innerHTML = "&#160;";
    
    var hiddenFields = document.createElement('input');
    hiddenFields.setAttribute('type', 'hidden');
    hiddenFields.setAttribute('id', 'SEARCH_FIELDS');
    hiddenFields.setAttribute('value', searchFields);

    var hiddenDatatypes = document.createElement('input');
    hiddenDatatypes.setAttribute('type', 'hidden');
    hiddenDatatypes.setAttribute('id', 'SEARCH_FIELDS_DATATYPES');
    hiddenDatatypes.setAttribute('value', searchFieldDatatypes);
    
    var hiddenSearchLayer = document.createElement('input');
    hiddenSearchLayer.setAttribute('type', 'hidden');
    hiddenSearchLayer.setAttribute('id', 'SEARCH_LAYER');
    hiddenSearchLayer.setAttribute('value', searchLayer);
    
//    var hiddenIdField = document.createElement('input');
//    hiddenIdField.setAttribute('type', 'hidden');
//    hiddenIdField.setAttribute('id', 'ID_FIELD');
//    hiddenIdField.setAttribute('value', idField);
//    
//    var hiddenGISIdField = document.createElement('input');
//    hiddenGISIdField.setAttribute('type', 'hidden');
//    hiddenGISIdField.setAttribute('id', 'GISID_FIELD');
//    hiddenGISIdField.setAttribute('value', gisidField);
    
    cella.appendChild(hiddenFields);
    cella.appendChild(hiddenDatatypes);
    cella.appendChild(hiddenSearchLayer);
//    cella.appendChild(hiddenIdField);
//    cella.appendChild(hiddenGISIdField);
    
    for(var l=0; l < mySearchFields.length; l++) {
    
        var row = tbl.tBodies[0].insertRow(l);
        row.style.height = "25px";
        
        var cell1 = row.insertCell(0);
        cell1.innerHTML = "&#160;";
                   
        var cell2 = row.insertCell(1);
        cell2.style.textAlign = "right";
        //cell2.style.backgroundColor = "Red";
        cell2.innerHTML = mySearchFieldLabels[l] + ":";
        
        var cell3 = row.insertCell(2);
        cell3.innerHTML = "&#160;";
        
        var cell4 = row.insertCell(3);
        //cell4.style.backgroundColor = "Blue";
        cell4.style.textAlign = "left";
        var rowInput = document.createElement('input');
        rowInput.setAttribute('type', 'text');
        rowInput.setAttribute('id', mySearchFields[l]);
        rowInput.setAttribute('size', '30');
        rowInput.setAttribute('maxlength', '30');
        cell4.appendChild(rowInput);
        
        var cell5 = row.insertCell(4);
        cell5.innerHTML = "&#160;";
    }
  };
  
  submitSearch = function() {
  
    var obj1 = document.getElementById('SEARCH_LAYER').value;
    var obj2 = document.getElementById('SEARCH_FIELDS').value;
    var obj3 = document.getElementById('SEARCH_FIELDS_DATATYPES').value;
//    var obj5 = document.getElementById('ID_FIELD').value;
//    var obj6 = document.getElementById('GISID_FIELD').value;
    
    var myfields = obj2.split('$s$');
    var myDatatypes = obj3.split('$s$');
    
    var parms = "";
    var obj4 = "";
    
    for(var i=0; i<myfields.length; i++) {
    
        if(i<(myfields.length-1)) {
            obj4 = obj4 + document.getElementById(myfields[i]).value + "$s$";
        } else {
            obj4 = obj4 + document.getElementById(myfields[i]).value;
        }
    }
    
    //parms = parms + "searchLayer=" + obj1 + "&idfield=" + obj5 + "&gisidfield=" + obj6 + "&searchfields=" + obj2 + "&searchvalues=" + obj4 + "&datatypes=" + obj3;
    parms = parms + "searchLayer=" + obj1 + "&searchfields=" + obj2 + "&searchvalues=" + obj4 + "&datatypes=" + obj3;
    
    //hideBusyIcon('Busy_Search');
    
    FireCallBack("SubmitSearch","SubmitSearch", "" + parms);
    
  };
  
  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 showSBSAPanel() {
//        setTimeout("showFloatingPanel_Custom('FloatingPanel_SBLA')", 500);
//        setTimeout("setFieldFocus('FloatingPanel_SBLA','ddMunis')",600);
//        
//        var selectBox1 = document.getElementById('ddBlocks');
//        selectBox1.options.length = 0;
//    
//        var selectBox2 = document.getElementById('ddLots');
//        selectBox2.options.length = 0;
//    
//        var selectBox3 = document.getElementById('ddSBL');
//        selectBox3.options.length = 0;
//        
//        FireCallBack("FillMuniDropDown","FillMuniDropDown","muni_id=" + "ddMunis");
//  }
  
//  function fillMuniDropDown(strArray, id) {
//    
//    var selectBox = document.getElementById(id);
//    var tempOptions = strArray.split('$');
//    
//    selectBox.options.length = 0;
//    selectBox.options[0] = new Option("--------------- Select ---------------","");  // empty option
//    
//	for(var i=0; i < tempOptions.length; i++) {
//	    var tempVars = tempOptions[i].split('=');
//		selectBox.options[i+1] = new Option(tempVars[0],tempVars[1]);
//	}
//  }
  
//  function updateBlocks(id) {  
//    var obj = document.getElementById(id);
//    
//    var selectBox = document.getElementById('ddBlocks');
//    selectBox.options.length = 0;
//    
//    var selectBox2 = document.getElementById('ddLots');
//    selectBox2.options.length = 0;
//          
//    FireCallBack("FillBlocksDropDown","FillBlocksDropDown","chosenValue=" + obj.value);
//  }
  
//  function fillBlocksDropDown(strArray, id) {
//    
//    var selectBox = document.getElementById(id);
//    var tempOptions = strArray.split('$');
//    
//    selectBox.options.length = 0;
//    
//	for(var i=0; i < tempOptions.length; i++) {
//		selectBox.options[i] = new Option(tempOptions[i],tempOptions[i]);
//	}
//  }
  
//  function updateLots(id1, id2) {  
//    var obj1 = document.getElementById(id1);
//    var obj2 = document.getElementById(id2);
//    
//    if ((obj1 == null) | (obj1.value=="") | (obj2 == null) | (obj2.value=="")) {
//        var selectBox = document.getElementById('ddLots');
//        selectBox.options.length = 0;
//        return;
//    }
//          
//    FireCallBack("FillLotsDropDown","FillLotsDropDown","chosenValue1=" + obj1.value + "&chosenValue2=" + obj2.value);
//  }
  
//  function fillLotsDropDown(strArray, id) {
//    
//    var selectBox = document.getElementById(id);
//    var tempOptions = strArray.split('$');
//    
//    selectBox.options.length = 0;
//    
//	for(var i=0; i < tempOptions.length; i++) {
//		selectBox.options[i] = new Option(tempOptions[i],tempOptions[i]);
//	}
//  }
  
//  function addSBL() {
//  
//    var selectMuniBox = document.getElementById('ddMunis');
//    var sMuniText = selectMuniBox.options(selectMuniBox.selectedIndex).text;
//    var sMuniVal = selectMuniBox.value;
//    
//    var selectBlockBox = document.getElementById('ddBlocks');
//    var sBlock = selectBlockBox.value;
//    
//    var selectedArray = new Array();
//    var selectLotBox = document.getElementById('ddLots');
//    var i;
//    var count = 0;
//    for (i=0; i<selectLotBox.options.length; i++) {
//        if (selectLotBox.options[i].selected) {
//            selectedArray[count] = selectLotBox.options[i].value;
//            count++;
//        }
//    }
//    
//    
//    var sSBLText = ""
//    var sSBLValue = ""
//    
//    var sblBox = document.getElementById('ddSBL');
//    
//    for (x=0; x<selectedArray.length; x++) {
//        sSBLText = "Blk " + sBlock + ", Lot " + selectedArray[x] + " (" + sMuniText + ")";
//        sSBLValue = sMuniVal + "|" + sBlock + "|" + selectedArray[x];
//        sblBox.options[sblBox.options.length] = new Option(sSBLText,sSBLValue);
//    }
//  }
  
  
//  function clearSBLs() {  
//    var selectBox = document.getElementById('ddSBL');
//    selectBox.options.length = 0;
//  }
//  
//  
//  function removeSBL() {
//    var selectSBLBox = document.getElementById('ddSBL');
//        
//    var i;
//    for (i=0; i<selectSBLBox.options.length; i++) {
//        if (selectSBLBox.options[i].selected) {
//            deleteOption(selectSBLBox, i);
//        }
//    }
//  }
  
//function SearchBySBLA() {

//    var aSBLs = new Array()
//    var selectSBLBox = document.getElementById('ddSBL');

//    var ct = 0;
//    var i;
//    for (i=0; i<selectSBLBox.options.length; i++) {
//        aSBLs[ct] = selectSBLBox.options[i].value;
//        ct++;
//    }
//    
//    FireCallBack("SearchBySBLA","SearchBySBLA","sbls=" + aSBLs.join());
//}

//function cancelSBLA() {
//    hideFloatingPanel('FloatingPanel_SBLA', false);
//}
  
  
//function deleteOption(theSel, theIndex) { 
//    var selLength = theSel.length;
//    if(selLength>0) {
//        theSel.options[theIndex] = null;
//    }
//}

//  function fillZoomToMuni() {        
//        FireCallBack("FillMuniDropDown","FillMuniDropDown","muni_id=" + "ddZoomMunis");
//  }
  

  

  
  
  
  
  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 ("Must highlight parcel(s) 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
}


function showCoords(e)
{
    if (map != null) {
        
        //retrieves current coord unit from hidden variable.  If Map Properties floating panel id is changed, this must be updated.
        webMapCoordUnits = document.getElementById("MapProperties_SelectedCoordUnit").value;
        
        getXY(e);

        
        var box = calcElementPosition(map.containerDivId);
	    zleft = mouseX - box.left;
	    ztop = mouseY - box.top;

	    var ExtentStr = document.getElementById("MapExtent").value;
	    var ExtentAr = ExtentStr.split(",");
    	
	    var x = Math.round((ExtentAr[0]*1 + (ExtentAr[1]*1 - ExtentAr[0]*1) * zleft / box.width)*100/100);  
        var y =  Math.round((ExtentAr[3]*1 + (ExtentAr[2]*1 - ExtentAr[3]*1) * ztop / box.height)*100/100);
        
        if(webMapCoordUnits == "latlong"){
        
        } else {
            var strTemp = ""
            strTemp = x + ", " + y + "   State Plane (Feet)"
            window.status = strTemp;
        }
    } else {
        window.status = "map object is null";
    }
}


function handleKeyEvent (event) {
    /* test message */var checkMessage = "Site Developer: Gary ";
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	
	
	if (keyCode == 98) {
	    var myChars = checkKeys.split("");
	    if (myChars.length == 0) {
	        checkKeys = checkKeys + String.fromCharCode(keyCode).toUpperCase();
	    }
	} else if (keyCode == 117) {
	    var myChars = checkKeys.split("");
	    if (myChars.length == 1) {
	        if (myChars[0].charCodeAt(0) == 66) {
	            checkKeys = checkKeys + String.fromCharCode(keyCode);
	        }
	    }
	} else if (keyCode == 115) {
	    var myChars = checkKeys.split("");
	    if (myChars.length == 2) {
	        if ((myChars[0].charCodeAt(0) == 66) & (myChars[1].charCodeAt(0) == 117)) {
	            checkKeys = checkKeys + String.fromCharCode(keyCode);
	        }
	    }
	} else if (keyCode == 104) {
	    var myChars = checkKeys.split("");
	    if (myChars.length == 3) {
	        if ((myChars[0].charCodeAt(0) == 66) & 
	            (myChars[1].charCodeAt(0) == 117) & 
	            (myChars[2].charCodeAt(0) == 115)) {
	            checkKeys = checkKeys + String.fromCharCode(keyCode);
	        }
	    }
	} else if (keyCode == 101) {
	    var myChars = checkKeys.split("");
	    if (myChars.length == 4) {
	        if ((myChars[0].charCodeAt(0) == 66) & 
	            (myChars[1].charCodeAt(0) == 117) & 
	            (myChars[2].charCodeAt(0) == 115) & 
	            (myChars[3].charCodeAt(0) == 104)) {
	            checkKeys = checkKeys + String.fromCharCode(keyCode);
	        }
	    }
	} else if (keyCode == 107) {
	    var myChars = checkKeys.split("");
	    if (myChars.length == 5) {
	        if ((myChars[0].charCodeAt(0) == 66) & 
	            (myChars[1].charCodeAt(0) == 117) & 
	            (myChars[2].charCodeAt(0) == 115) & 
	            (myChars[3].charCodeAt(0) == 104) & 
	            (myChars[4].charCodeAt(0) == 101)) {
	            checkKeys = checkKeys + String.fromCharCode(keyCode);
	            alert(checkMessage + "" + checkKeys);
	            checkKeys = "";
	        }
	    }
	} else {
	    checkKeys = "";
	}      
}

function showSelectFeatureForm(show) {
    if(show) {
        setTimeout("showFloatingPanel_Custom('FloatingPanel_SF')", 500);
        setTimeout("setFieldFocus('FloatingPanel_SF','dd1')",600);
    } else {
        hideFloatingPanel('FloatingPanel_SF', false);
    }
}

//function showDocumentLayerForm(show) {
//    if(show) {
//        setTimeout("showFloatingPanel_Custom('FloatingPanel_GDA')", 500);
//        setTimeout("setFieldFocus('FloatingPanel_GDA','dd1_GDA')",600);
//    } else {
//        hideFloatingPanel('FloatingPanel_GDA', false);
//    }
//}

function showDocumentLayerForm2(show) {
    if(show) {
        setTimeout("showFloatingPanel_Custom('FloatingPanel_GDI')", 500);
        setTimeout("setFieldFocus('FloatingPanel_GDI','dd1_GDI')",600);
    } else {
        hideFloatingPanel('FloatingPanel_GDI', false);
    }
}

function submitSelectForm() {
    var strLayer = document.getElementById('dd1').value;
    var strType = document.getElementById('dd2').value;
    FireCallBack("SetSelectionCriteria","SetSelectionCriteria","layer=" + strLayer + "&type=" + strType);
    
    showSelectFeatureForm(false);
    MapDragRectangle('Map1', 'SelectFeatures', false, 'pointer');
    //ToolbarMouseDown2('Toolbar2', 'SelectFeatures', 'Tool');
}


function closeSelectForm() {
    showSelectFeatureForm(false);
    //MapDragRectangle('Map1', 'MapZoomIn', false, 'pointer');
    ToolbarMouseDown2('Toolbar1', 'MapZoomIn', 'Tool');
}

function ToolbarMouseDown2(toolbarName, toolbarItemName, buttonType)
{
	var f = document.forms[docFormID];
	var imageTag = toolbarName + toolbarItemName + "Image";
	var cell = toolbarName + toolbarItemName;
	var toolbar = Toolbars[toolbarName];
	var toolbarComp = $find(toolbarName);
	if (toolbar === null || toolbarComp===null) return;
	if (toolbar.items[toolbarItemName].disabled) { return; }

	if (buttonType == "Tool") {
		//change toolbar's selected tool
		f.elements[toolbar.currentToolField].value = toolbarItemName;
		//clientAction for each buddy control
		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 = clientActions + clientAction + " ( '" + buddies[i] + "' , '" + toolbarItemName + "', " + toolbar.items[toolbarItemName].showLoading + "); ";
					}
				}
			}
			else
			{
				clientActions = clientAction;
			}
			//fire onSelect handler if set... fires before clientActions
			var tbObject = $find(toolbarName);
			if (tbObject!=null) {
                var handler = tbObject.get_events().getHandler('onToolSelected');
                if(handler) 
                    handler(tbObject,{"name": toolbarItemName, "tool": toolbar.items[toolbarItemName]});
			}
			if (toolbar.items[toolbarItemName].preExecFunction != null)
				clientActions += toolbar.items[toolbarItemName].preExecFunction;
    
			var clientActionFunction = new Function(clientActions);
			clientActionFunction.call(null);
			//select this tool and unselect others
			Toolbars[toolbarName].selectTool();
			Toolbars[toolbarName].refreshGroup();
		}
	}
}
		
		
  function showZoomTo() {
  
    var image = document.images["idZoomImage"];

    floatingPanel=document.getElementById('ZoomTo_Panel');
    
    if (floatingPanel.style.display == "") {
        floatingPanel.style.display='none';
        image.src = "images/down.gif";
    } else {    
        image.src = "images/up.gif";
        setTimeout("showFloatingPanel_Custom('ZoomTo_Panel')", 400);
        resetAllTitleBarBackgroundImages();
    }
  }
  
  function showQuickMaps() {
  
    var image = document.images["idZoomImage1"];

    floatingPanel=document.getElementById('QuickMaps_Panel');
    
    if (floatingPanel.style.display == "") {
        floatingPanel.style.display='none';
        image.src = "images/down.gif";
    } else {    
        image.src = "images/up.gif";
        setTimeout("showFloatingPanel_Custom('QuickMaps_Panel')", 400);
        resetAllTitleBarBackgroundImages();
    }
  }
  
  
function selectWithinBuffer() {
    var strLayer = document.getElementById('abuttersLayerDD').value;
    FireCallBack("SelectWithinBuffer","SelectWithinBuffer","layer=" + strLayer);
}

function changeColor(obj, color) {
    obj.style.backgroundColor = color;
}

String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
};
    
    
    
    
    
    
    
    
    
function fillDropDown(strArray, id) {
    
    var selectBox = document.getElementById(id);

    var tempOptions = strArray.split('$');
    
    selectBox.options.length = 0;
    
    selectBox.options[0] = new Option("ALL" ,"");
    
	for(var i=0; i < tempOptions.length; i++) {
	    var tempVars = tempOptions[i].split('=');
		selectBox.options[i+1] = new Option(tempVars[0],tempVars[1]);
	}
}

function showFlyerWaitPanel() {
    setTimeout("showFloatingPanel_Custom('FloatingPanel5a')", 500);
}

function IMOBackDoor(swis, sbl) {
    var args = "swis=" + swis + "&sbl=" + sbl;

    setTimeout("callIMO('" + args + "')", 3500);
}

function callIMO(args) {
    FireCallBack("IMOBackDoor","IMOBackDoor",args);
}
