﻿//Results Code..



//Config variables for images
var ResultsConfig = new Object();
ResultsConfig.imagePath = "../images/";
ResultsConfig.zoomInImage = "zoominSmall.gif";
ResultsConfig.evenStyle = 'font-family: Arial, Helvetica, sans-serif; font-size: 11px; color: #666666;';
ResultsConfig.oddStyle = 'font-family: Arial, Helvetica, sans-serif; font-size: 11px; color: #666666; background:#F3F3ED;';
ResultsConfig.fldValSeparator = "::^"; 

var tree; 
//------------------------------------------------------------
function treeInit(resultsText) 
{   
	if(resultsText.toLowerCase() == "no results found")
	{
        var results = document.getElementById("ResultsContainer_UserControl");
            results.innerHTML = '<br />&nbsp;&nbsp;&nbsp;0 Results Found.';
   
	}
    else
    {
        tree = new YAHOO.widget.TreeView("ResultsContainer_UserControl", false,1);
        tree.setExpandAnim(YAHOO.widget.TVAnim.FADE_IN);
	    tree.setCollapseAnim(YAHOO.widget.TVAnim.FADE_OUT);    	
               	
        var root = tree.getRoot(); 	  
       
        var splitlistdataset = resultsText.split("****^");
        var length = splitlistdataset.length;
	    for(var i=0; i < length -1; i++)
	    {
	    //Changed the ## delimeter to ###^ delimer : VJ 05/14/08
	        var splitDataset = splitlistdataset[i].split("###^");  
	        var splitDatable = splitDataset[1].split("***^");
            //var tmpNode = new YAHOO.widget.TextNode(splitDataset[0].toString(), root, false); 		
		    for(var j=0; j < splitDatable.length -1; j++)
		    {
                addDatatable(splitDatable[j], root.index);   
		    }
	    }
	        tree.draw(); 
	    }
} 
//------------------------------------------------------------	
function addDatatable(datatable, dsnode) 
{
    var root = tree.getRoot(); 	  
    var splitDatatable = datatable.split("##^");
    var splitDatarow = splitDatatable[1].split("**^");
	
    var length = splitDatarow.length;
    var numberofelements = length-1;
    var tablenode = new YAHOO.widget.TextNode(splitDatatable[0].toString()+": ("+numberofelements.toString()+ ")", root, true); 
	
    for(var i=0; i < length -1; i++)
    {
        addDatarow(splitDatarow[i], tablenode.index, splitDatatable[0].toString());
    }
}
//Create TOOL TIPS for Street Search Results
var ZoomToolTips = new MouseToolTips(500,1,'generalToolTip',0);   
//------------------------------------------------------------	
function addDatarow(datarow, tableindex, layername) 
{
    var datatable = tree.getNodeByIndex(tableindex);
    var splitDR = datarow.split("*^");
    var length = splitDR.length;
    var tempObjectID ;
    //--------------------for the Graphics ID
    for(var i=0; i < length -1; i++)
    {
        //var splitTempGID = splitDR[i].split(":");
        var splitTempGID = splitDR[i].split(ResultsConfig.fldValSeparator);
        if(splitTempGID[0].toString() == "GRAPHICS_ID")
        tempObjectID =  splitTempGID[1];
    }
	
    //--------------------for the displayfield
    var tempnode1; 
    for(var i=0; i < length -1; i++)
    {
        //var splitIndividual = splitDR[i].split(":");
        var splitIndividual = splitDR[i].split(ResultsConfig.fldValSeparator);
        if(splitIndividual[0].toString() == "Display Field")
        {
        // _________________________________Assuming that the first Column will be object ID
        var id = layername +'***' + tempObjectID.toString()+'***'+ Math.random()+ '***CHK';
        var idimg = layername +'***' + tempObjectID.toString()+'***'+ Math.random()+ '***img';
        
        //old code.. (mod by drew for browser compatibility)
        //var htmllayer  = '<table><tr><td> <input id="'+ id +'" type="checkbox" onclick="IdentifyZoomSelect(this); return false;"/></td><td> <img id="'+ idimg +'" onclick="IdentifyZoomSelect(this);  return false;" src="'+ResultsConfig.imagePath + ResultsConfig.zoomInImage+'"  border="0" /> </td><td>'+ splitIndividual[1].toString()+'</td> </tr> </table>';
        
        // original treeview node with check box to show/hide highlight
        //var htmllayer  = '<span> <input onmouseover="ZoomToolTips.Show(event,this);" toolTip="Select this feature." id="'+ id +'" type="checkbox" onchange="IdentifyZoomSelect(this);"/>  &nbsp; <img onmouseover="ZoomToolTips.Show(event,this);" toolTip="Zoom to this feature." id="'+ idimg +'" onclick="IdentifyZoomSelect(this);" src="'+ResultsConfig.imagePath + ResultsConfig.zoomInImage+'"  border="0" style="cursor:pointer;"/> &nbsp;'+ splitIndividual[1].toString()+'</span>';
        // revised treeview node WITHOUT check box
        //var htmllayer  = '<span>&nbsp;&nbsp;<img onmouseover="ZoomToolTips.Show(event,this);" toolTip="Zoom to this feature." id="'+ idimg +'" onclick="IdentifyZoomSelect(this);" src="'+ResultsConfig.imagePath + ResultsConfig.zoomInImage+'"  border="0" style="cursor:pointer;"/> &nbsp;'+ splitIndividual[1].toString()+'</span>';

// onclick="IdentifyZoomSelect(this); return false;"
        var htmllayer  = '<span> <input onmouseover="ZoomToolTips.Show(event,this);" toolTip="Highlight this feature." id="'+ id +'" type="checkbox" onclick="IdentifyZoomSelect(this); return false;"/>  &nbsp; <img onmouseover="ZoomToolTips.Show(event,this);" toolTip="Zoom to this feature." id="'+ idimg +'" onclick="IdentifyZoomSelect(this);" src="'+ResultsConfig.imagePath + ResultsConfig.zoomInImage+'"  border="0" style="cursor:pointer;"/> &nbsp;'+ splitIndividual[1].toString()+'</span>';

        
        //tempnode1 = new YAHOO.widget.TaskNode(splitIndividual[1].toString(), datatable, false);
        tempnode1 = new YAHOO.widget.TextNode(htmllayer, datatable, false);
       //alert(tempnode1.getToggleLink());
        }
    }
    if(tempnode1 == null)
    {
        tempnode1 = new YAHOO.widget.TextNode("Feature", datatable, false);
    }
    var counterColor = 0;
    var html =  '<table>';
    for(var i=0; i < length -1; i++)
    {
        odd = i % 2;
        var resultStyle =''
        if (odd ==1) { resultStyle = ResultsConfig.oddStyle; }
        else { resultStyle = ResultsConfig.evenStyle; }
    
        //var splitIndividual1 = splitDR[i].split(":");
        var splitIndividual1 = splitDR[i].split(ResultsConfig.fldValSeparator);
        var fieldName = splitIndividual1[0].toString();
        var fieldValue = splitIndividual1[1].toString();
        
        if((fieldName != "GRAPHICS_ID") && (fieldName != "IS_SELECTED") && (fieldName != "ADF Geometry") && (fieldName != "Display Field"))
        {
         html  += '<tr style="'+resultStyle+'"><td toolTip="[b]'+fieldName+ ':[/b] ' + fieldValue+'" onmouseover="ToolTips.Show(event,this)">' + fieldName +'</td> <td>'+ fieldValue+'</td> </tr>';
        }
      }
    html += '</table>';
    var tempnode = new YAHOO.widget.HTMLNode(html , tempnode1, false);
 
}
	
	  
function IdentifyZoomSelect(element)
{
	var	map = $find('Map1');
    var arge = element.id.toString();
    //alert("arge: '" + arge + "'");
    var arguments = arge.split("***"); 
    if(arguments[3].toString() != 'img')
    {
    if(element.checked == true)
    {   
            var message = "ControlID=Map1&ControlType=Map&EventArg=BAMapIdentify&Map1_mode=BAMapIdentify&minx=" + -1 + "&miny=" + -1 + "&LayerName=" + arguments[0].toString() + "&Objectid=" + arguments[1].toString()+ "&idtype=" + "select";
	        var context = map.get_id();  // map.controlName;	<- property not valid at 9.3
            //eval(map.identifyCallbackFunctionString);
            eval(identifyCallbackFunctionString);
        }
        else
        {
            var message = "ControlID=Map1&ControlType=Map&EventArg=BAMapIdentify&Map1_mode=BAMapIdentify&minx=" + -1 + "&miny=" + -1 + "&LayerName=" + arguments[0].toString() + "&Objectid=" + arguments[1].toString()+ "&idtype=" + "unselect";
	        var context = map.get_id();  // map.controlName;	<- property not valid at 9.3
            //eval(map.identifyCallbackFunctionString);
            eval(identifyCallbackFunctionString);
        }
    }
    else
    {
        var message = "ControlID=Map1&ControlType=Map&EventArg=BAMapIdentify&Map1_mode=BAMapIdentify&minx=" + -1 + "&miny=" + -1 + "&LayerName=" + arguments[0].toString() + "&Objectid=" + arguments[1].toString() +"&idtype=" + "zoom";
	    var context = map.get_id();  // map.controlName;	<- property not valid at 9.3
        //eval(map.identifyCallbackFunctionString);
        eval(identifyCallbackFunctionString);
    }
}	
	
	