<?xml version="1.0" encoding="UTF-8" ?> 
<Module>
<ModulePrefs title="Brad's First Google Gadget Example"
             description="Description"
             author="Bradley D. Brown"
             author_location="Littleton, CO"
             author_affiliation="TUSC"
             author_email="brownb@tusc.com"
             height="145" 
             width="300"
             thumbnail="/images/chart.jpg"
             directory_title="iPerspective Sample"
             scrolling="true"
             screenshot="/images/chart.jpg"
             render_inline="optional" >
 <Require feature="dynamic-height" />
</ModulePrefs>
  <UserPref name="myOperator" display_name="Operator" default_value="="/>
  <UserPref name="myValue" display_name="Value to Lookup" default_value="300000"/>
  <UserPref name="myRows" display_name="Records to Display" default_value="50"/>
  <UserPref name="mySort" display_name="Sort Descending" datatype="bool" default_value="false"/>
  <UserPref name="mychoice" display_name="Show Improvement Value" datatype="bool" default_value="false"/>
  <Content type="html">
<![CDATA[ 
  
  <div id="content_div"></div>
  <link rel="stylesheet" type="text/css" href="http://visapi-gadgets.googlecode.com/svn/trunk/pilesofmoney/pom.css"/>
  <script type="text/javascript" src="http://visapi-gadgets.googlecode.com/svn/trunk/pilesofmoney/pom.js"></script>
  <script type="text/javascript" src="http://www.google.com/jsapi"></script>
  <div id="chartdiv"></div>
  <table border=1>

  <script type="text/javascript">      
  function displayMenu() {	  	  
      // XML Property Values
      var prefs = new _IG_Prefs(__MODULE_ID__);
      var valueLimit = prefs.getInt("myValue");
      var operator = prefs.getString("myOperator");
      var rows = prefs.getString("myRows");
      var trueRows = 0;
      var description = prefs.getBool("mychoice");
      var sortDesc = prefs.getBool("mySort");
      // var url = "http://iperspective.dynalias.com/AppServerWS/DOUGLAS_VALUATIONTAPI?invoke=getFullSet&param0=&param1=&param2=&param3=&param4=50";
      var url = "http://iperspective.dynalias.com:8080/AppServerWS/DOUGLAS_VALUATIONTAPI?invoke=getFullSet&param0=where+TOTAL_ACTUAL_VALUE" + operator + valueLimit + "&param1=&param2=&param3=TOTAL_ACTUAL_VALUE" + (sortDesc==true?"+desc":"") + "&param4=" + rows;
	  
      _IG_FetchXmlContent(url, function (response) {
         if (response == null || typeof(response) != "object" || response.firstChild == null) {
           _gel("content_div").innerHTML = "<i>Invalid data.</i>";
           return;
        }	

	// Start building HTML string that will be displayed in <div>.
        // Set the style for the <div>.
	var html = "<div style='padding: 5px;background-color: #ccf;font-family:Arial, Helvetica;" +
                   "text-align:left;font-size:90%'>";    

        // Google Visualization API
        ma = new Array(rows);
        google.load('visualization', '1');
        google.setOnLoadCallback(drawChart);
        function drawChart() {
          var chart;
          var data = new google.visualization.DataTable();
          data.addColumn('string', 'Label');
          data.addColumn('number', 'Value');
          data.addRows(trueRows);
          for (r=0;r<trueRows;r++) {
            if (ma[r]==null) {break};
            data.setCell(r, 0, 'Property '+ma[r][0]);
            data.setCell(r, 1, parseFloat(ma[r][1]),'$'+ma[r][1]);
          }
          var chartDiv = document.getElementById('chartdiv');
          var options = {title: 'Value by Home'};
          chart = new PilesOfMoney(chartDiv);
          chart.draw(data, options);
        }

        // Set style for title.
        html +="<div style='text-align:center; font-size: 120%; color: yellow; " +
                "font-weight: 700;'>";     

        // Display menu title. Use getElementsByTagName() to retrieve the <menu> element.
        // Since there is only one menu element in the file,
        // you can get to it by accessing the item at index "0". 
        // You can then use getAttribute to get the text associated with the
        // menu "title" attribute.
        // BDB - var title = response.getElementsByTagName("menu").item(0).getAttribute("title");	
        
        // Alternatively, you could retrieve the title by getting the menu element node
        // and calling the "attributes" function on it. This returns an array
        // of the element node's attributes. In this case, there is only one
        // attribute (title), so you can display the value for the attribute at
        // index 0. For example:
        // 
        // BDB - uncommented
        var title = response.getElementsByTagName("return").item(0).attributes.item(0).nodeValue;
        
		// Append the title to the HTML string.
		//html += title + "</font></h3>";
                html += "Brad's Cool Gadget from iPerspective</font></h3> Values" + operator + valueLimit;

        // Append the title to the HTML string.
        // html += title + "</div><br>";

        html += "<table border=1><tr><th>ID</th><th>Land Value</th><th>Total Value</th><tr>";
        
        // Get a list of the <item> element nodes in the file
        var itemList = response.getElementsByTagName("item");        
        // Loop through all <item> nodes
        for (var i = 0; i < itemList.length ; i++) { 
		   // For each <item> node, get child nodes.
		   var nodeList = itemList.item(i).childNodes;
		   // Loop through child nodes. Extract data from the text nodes that are
		   // the children of the associated name, price, and  element nodes.
           for (var j = 0; j < nodeList.length ; j++) {
             var node = nodeList.item(j);
	         if (node.nodeName == "TAXABLE_LAND_ACTUAL_VALUE") {
                     var landValue = node.firstChild.nodeValue;
		 }
                 if (node.nodeName == "ID") {
                     var id = node.firstChild.nodeValue;				 
		 }
		 if (node.nodeName == "TOTAL_ACTUAL_VALUE")  {
		     var actualValue = node.firstChild.nodeValue;				 
		 }
                 // If the user chose to display descriptions and
                 // the nodeName is "#cdata-section", grab the 
                 // contents of the description CDATA for display.
                 if (node.nodeName == "description" && description==true)
                 {
                    if (node.firstChild.nodeName == "TAXABLE_IMPR_ACTUAL_VALUE") 
                        var data = node.firstChild.nodeValue;
                 }
		      }			 
			  
              // Append extracted data to the HTML string.
              html += "<td>" + id + "</td>";
	      html += "<td>" + landValue + "</td>";
 	      // If "actualValue" is greater than the user-specified calorie limit,
	      // display it in red.
              html += "<td>";
	      if(actualValue > valueLimit) {
                  html += "<font color=#ff0000>";
				  html += actualValue;
				  html += " </font>";		 
			 }
			  else
			      html += actualValue;
              html += "</td></tr>";

              // Add a multidimensional array
              ma[i] = new Array(2);
              ma[i][0] = id;
              ma[i][1] = actualValue;

              // If user has chosen to display descriptions
              if (description==true)
              {
                 html += "<i>" + data + "</i><br>";
              }
              
        } 	
        trueRows = i;
        html += "</table></div>";

	// Display HTML string in <div>
	_gel('content_div').innerHTML = html;   		 
     });	   
  }

  _IG_RegisterOnloadHandler(displayMenu);
  </script>

  ]]> 
  </Content>
  </Module>


















