﻿// 

    function GetTextForTextTool()
	{
		var theText1 = 'TextTool$$$';
		var theText2 = document.getElementById('TextBoxTextTool').value;
        UseCallback(theText1 + theText2);        
	} 
	function GetDrawingOptionsColor()
	{
		var theText1 = 'DrawingColor$$$';
		var theText2 = document.getElementById('DropDownListDrawingColor').value;
        UseCallback(theText1 + theText2);
	} 
	function GetDrawingTextSize()
	{
		var theText1 = 'TextSize$$$';
		var theText2 = document.getElementById('DropDownListTextSize').value;
        UseCallback(theText1 + theText2);
	}
	function GetDrawingPointSize()
	{
		var theText1 = 'PointSize$$$';
		var theText2 = document.getElementById('TextBoxPointSize').value;
        UseCallback(theText1 + theText2);
	}
	function GetDrawingPointType()
	{
		var theText1 = 'PointType$$$';
		var theText2 = document.getElementById('DropDownListPointType').value;
        UseCallback(theText1 + theText2);
	} 
	function GetDrawingLineThickness()
	{
		var theText1 = 'LineThickness$$$';
		var theText2 = document.getElementById('TextBoxLineThickness').value;
        UseCallback(theText1 + theText2);
	} 
	
	
	function PopulateLayersDropDown(section, resourceDropDownName, layersDropDownName, fieldsDropDownName)
	{
	    // section = AutoLabel, SpatialQuery, TabularQuery
	
	    var resourceDropDown = document.getElementById(resourceDropDownName);
	    var resourceName = resourceDropDown.options[resourceDropDown.selectedIndex].text;
	    var layersDropDown = document.getElementById(layersDropDownName);
	    
	    var hiddenListBox = document.getElementById('ListBoxHiddenLayerList');
	    
	    // clear dropdown
        for (var i = (layersDropDown.options.length-1); i >= 0; i--){
         layersDropDown.options[i]=null;
        }
        
        // read the hidden listbox with layers and populate the dropdown
        var newOption;
        
        // iterate through the hidden list box
        for (var j = 0; j < (hiddenListBox.options.length); j++){
            
            // if the resourceName is the same as the value of the resourceDropDown
            var splitResult;
            if (resourceName == hiddenListBox.options[j].text) {
                splitResult = hiddenListBox.options[j].value.split(',');
                newOption = document.createElement("Option");              
                newOption.value = splitResult[0] + ',' + resourceName;
                newOption.text = splitResult[1];
                layersDropDown.add(newOption);
            }
        }
        
        
        if (fieldsDropDownName != null) {
            // populate the fieldsDropDown
            PopulateFieldsDropDown(section, layersDropDownName, fieldsDropDownName)
        }
        else
        {
            // return the new layerId back
            var layerID = layersDropDown.value.split(',')[0]
            var theText1 = 'update' + section + '$$$' + resourceName + '$$$' + layerID;
            UseCallback(theText1);
        }
	}
	
	function PopulateFieldsDropDown(section, layersDropDownName, fieldsDropDownName)
	{
	    var layersDropDown = document.getElementById(layersDropDownName);
	    var fieldsDropDown = document.getElementById(fieldsDropDownName);
	    var hiddenListBox = document.getElementById('ListBoxHiddenFieldList');
	    
	    var splitResult = layersDropDown.options[layersDropDown.selectedIndex].value.split(',');
	    var layerID = splitResult[0];
        var layerDataSourceName = splitResult[1];
        var layerName = layersDropDown.text;

	    // clear dropdown
        for (var i = (fieldsDropDown.options.length-1); i >= 0; i--){
         fieldsDropDown.options[i]=null;
        }
        
        // read the hidden listbox with fields and populate the dropdown
        var newOption;
        
        // iterate through the hidden list box
        for (var j = 0; j < (hiddenListBox.options.length); j++){
            
            //Format: the field name is the text, and the value is "dataSourceName,layerID"
            // check to see if this is the right dataSourceName
            splitResult = hiddenListBox.options[j].value.split(',');
            var fieldDataSourceName = splitResult[0];
            var fieldLayerID = splitResult[1];
            
            if (layerDataSourceName == fieldDataSourceName)  {

                // if the layerID is the same as the value of the layersDropDown
                if (layerID == fieldLayerID) {
                                    
                    newOption = document.createElement("Option");              
                    newOption.value = hiddenListBox.options[j].text;
                    newOption.text = hiddenListBox.options[j].text;
                    fieldsDropDown.add(newOption);
                }
            }
        }
        
        if (fieldsDropDownName == "DropDownListAutoLabelField")
        {
            newOption = document.createElement("Option");              
            newOption.value = "<Numbered>";
            newOption.text = "<Numbered>";
            fieldsDropDown.add(newOption);        
        }        
        
        // return the name of the resource, the new layerId and the first field name... and the layerName
        var layerID = layersDropDown.value.split(',')[0];
		var theText1 = 'update' + section + '$$$' + layerDataSourceName + '$$$' + layerID + '$$$' + fieldsDropDown.options[0].text + '$$$' + layerName;
        UseCallback(theText1);
    }

	function PopulateFieldsDropDown2(section, layersDropDownName, fieldsDropDownName)
	{
	    var layersDropDown = document.getElementById(layersDropDownName);
	    var fieldsDropDown = document.getElementById(fieldsDropDownName);
	    var hiddenListBox = document.getElementById('ListBoxHiddenFieldList');
	    
	    var splitResult = layersDropDown.options[layersDropDown.selectedIndex].value.split(',');
	    var layerID = splitResult[0];
        var layerDataSourceName = splitResult[1];
        var layerName = layersDropDown.text;

	    // clear dropdown
        for (var i = (fieldsDropDown.options.length-1); i >= 0; i--){
         fieldsDropDown.options[i]=null;
        }
        
        // read the hidden listbox with fields and populate the dropdown
        var newOption;
        
        // iterate through the hidden list box
        for (var j = 0; j < (hiddenListBox.options.length); j++){
            
            //Format: the field name is the text, and the value is "dataSourceName,layerID"
            // check to see if this is the right dataSourceName
            splitResult = hiddenListBox.options[j].value.split(',');
            var fieldDataSourceName = splitResult[0];
            var fieldLayerID = splitResult[1];
            
            if (layerDataSourceName == fieldDataSourceName)  {

                // if the layerID is the same as the value of the layersDropDown
                if (layerID == fieldLayerID) {
                                    
                    newOption = document.createElement("Option");              
                    newOption.value = hiddenListBox.options[j].text;
                    newOption.text = hiddenListBox.options[j].text;
                    fieldsDropDown.add(newOption);
                }
            }
        }
        
        if (fieldsDropDownName == "DropDownListAutoLabelField")
        {
            newOption = document.createElement("Option");              
            newOption.value = "<Numbered>";
            newOption.text = "<Numbered>";
            fieldsDropDown.add(newOption);        
        }
        
        // return the name of the resource, the new layerId and the first field name
        // var layerID = layersDropDown.value.split(',')[0];
		// var theText1 = 'update' + section + '$$$' + layerDataSourceName + '$$$' + layerID + '$$$' + fieldsDropDown.options[0].text;
        // UseCallback(theText1);
    }	
	
	function GetAutoLabelFieldValue()
	{
		var theText1 = 'AutoLabelField$$$';
		var theText2 = document.getElementById('DropDownListAutoLabelField').value;
        UseCallback(theText1 + theText2);	    
	}
	
	function GetElementValue(controlName)
	{
	    var theText1 = controlName
	    var theText2 = document.getElementById(controlName).value;
	    UseCallback(theText1 + "$$$" + theText2);	
	}
	
	function SetTextOnlyValue()
	{
	    var theText1 = "TextOnlyValue";
	    var theText2 = "TextOnlyValue";
	    UseCallback(theText1 + "$$$" + theText2);	
	}	
	
	function SetDrawingOnlyValue()
	{
	    var theText1 = "DrawingOnlyValue";
	    var theText2 = "DrawingOnlyValue";
	    UseCallback(theText1 + "$$$" + theText2);
	}		
	
	function SetAutoLabelValue()
	{
	    var labelLayer = document.getElementById('DropDownListAutoLabelLayer').value;
	    var queryLayer = document.getElementById('DropDownListQueryLayer').value;
	
        if (labelLayer != queryLayer) {
            alert('Auto Label Panel Layer Must Match Query Panel Layer To Use This Function.');
        }

	    var theText1 = "AutoLabelValue";
	    var theText2 = "AutoLabelValue";
	    UseCallback(theText1 + "$$$" + theText2);	
	}	
	
	function GetElementText(controlName)
	{
	    var theText1 = controlName
	    var theText2 = document.getElementById(controlName).text;
	    UseCallback(theText1 + "$$$" + theText2);	
	}

	function GenerateQueryString()
	{
	    var layerID = document.getElementById('DropDownListAutoLabelLayer').value;
	    var fieldName = document.getElementById('DropDownListAutoLabelField').value;
	    var operator = document.getElementById('DropDownListOperator').value;
	    
	    var stringTextBox = document.getElementById('TextBoxTabularQueryString');
        
        stringTextBox.value = fieldName + ' ' + operator + ' ';
	}

    function HandleEvent(TextBox1, context)
    {
      
      HideGraphicTimed();
      
    }

