/* 
 * Graham Hellewell ghellewell@sandi.net
 * San Diego Unified School District
 * 08/13/08
 * ======
 *
 * JavaScript Functions used by the bond map page at:
 * http://www.sandi.net/bond/map/
 *
 */

    //<![CDATA[
    var map;
    var mgr;
    var allmarkers = [];
	var markercount;
	var map_icon;

	/**
	 * loadMap()
	 * ======
	 * Creates the Google Map control if browser is compatible.
	 * Calls setupSchoolMarkers to create map markers.
	 *
	 * params (none)
	 */
    function loadMap() {
      if (GBrowserIsCompatible()) {
        var cntrLat, cntrLong;

		map = new GMap2(document.getElementById("map"));
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
				
		// Center map by specific latitude and longitude
		map.setCenter(new GLatLng(32.8180719184, -117.105463867), 11);

        //alert("creating marker manager");
		mgr = new GMarkerManager(map);
		
		// Get XML file with school data
        request = GXmlHttp.create(); 
        request.open("GET", "SDUSD_Schools.xml", true); 
        request.onreadystatechange = setupSchoolMarkers;
        request.send(null);		
		
      } else {
	    //alert("Your browser does not support Google Maps.");
	  }
    }


	/**
	 * setupSchoolMarkers()
	 * ======
	 * Called by loadMap().
	 * Creates map markers for all schools found in XML file
	 *
	 * params (none)
	 */
    function setupSchoolMarkers() {
      allmarkers.length = 0;
      var markers = [];
	  var schlName, schlCode, schlGrades, schlLower, schlUpper;
	  var schlAddress, schlCity, schlState, schlZip, schlPhone;
	  var schlCalendar, schlGradeLow, schlGradeHigh;
	  var schlYearBuilt, schlSqFeet, schlAcres, schlConditionRating;
	  var url_school, url_dfa, url_ssbpl;
	  var budget_safety, budget_compliance, budget_learning,
	      budget_repair, budget_replace, budget_growth, 
		  budget_cte, budget_escalation, budget_total;
	  var schlType, schlLatitude, schlLongitude;
	  var markerPopUp, markerPopUp2;
	  var icontype;
	  var schlList = "";

      // Get radio button value selected
	  map_icon = gup("map_icon");
	  if ( map_icon.length <= 0 ) map_icon = "pushpin_icon";
	  icontype = map_icon;
	  //alert("icon type = " + icontype);
	  
	  // Only continue if readystate is appropriate 
      if (request.readyState == 4) {
		  if (request.status != 200) {
			 alert("file not found:" + request.status);
			 return;
		  }
		  var xmlDoc = request.responseXML;
		  if (!xmlDoc) {
			 alert("invalid xml file");
			 return;
		  }
		  
		  // Get node lists for each data field from the XML file
		  // XML_names contains all names for all the schools
		  XML_names = xmlDoc.documentElement.getElementsByTagName("name");
		  XML_codes = xmlDoc.documentElement.getElementsByTagName("code");
		  XML_lat = xmlDoc.documentElement.getElementsByTagName("latitude");
		  XML_long = xmlDoc.documentElement.getElementsByTagName("longitude");
		  XML_type = xmlDoc.documentElement.getElementsByTagName("type");
		  XML_address = xmlDoc.documentElement.getElementsByTagName("address");
		  XML_city = xmlDoc.documentElement.getElementsByTagName("city");
		  XML_state = xmlDoc.documentElement.getElementsByTagName("state");
		  XML_zip = xmlDoc.documentElement.getElementsByTagName("zip");
		  XML_phone = xmlDoc.documentElement.getElementsByTagName("phone");
		  XML_gradelow = xmlDoc.documentElement.getElementsByTagName("grade_low");
		  XML_gradehigh = xmlDoc.documentElement.getElementsByTagName("grade_high");
		  XML_calendar = xmlDoc.documentElement.getElementsByTagName("calendar");
		  XML_yearbuilt = xmlDoc.documentElement.getElementsByTagName("year_built");
		  XML_sqfeet = xmlDoc.documentElement.getElementsByTagName("square_feet");
		  XML_acres = xmlDoc.documentElement.getElementsByTagName("acres");
		  XML_conditionrating = xmlDoc.documentElement.getElementsByTagName("condition_rating");
		  //budget_safety, budget_compliance, budget_learning, budget_repair, budget_replace, budget_growth, budget_total
		  XML_budgetsafety = xmlDoc.documentElement.getElementsByTagName("budget_safety");
		  XML_budgetcompliance = xmlDoc.documentElement.getElementsByTagName("budget_compliance");
		  XML_budgetlearning = xmlDoc.documentElement.getElementsByTagName("budget_learning");
		  XML_budgetrepair = xmlDoc.documentElement.getElementsByTagName("budget_repair");
		  XML_budgetreplace = xmlDoc.documentElement.getElementsByTagName("budget_replace");
		  XML_budgetgrowth = xmlDoc.documentElement.getElementsByTagName("budget_growth");
		  XML_budgetcte = xmlDoc.documentElement.getElementsByTagName("budget_cte");
		  XML_budgetescalation = xmlDoc.documentElement.getElementsByTagName("budget_escalation");
		  XML_budgettotal = xmlDoc.documentElement.getElementsByTagName("budget_total");
		  XML_url_school = xmlDoc.documentElement.getElementsByTagName("url_school");
		  XML_url_dfa = xmlDoc.documentElement.getElementsByTagName("url_dfa");
		  XML_url_ssbpl = xmlDoc.documentElement.getElementsByTagName("url_ssbpl");
		  //alert("num schools in XML file = " + XML_names.length);
		  //alert("num year_built in XML file = " + XML_yearbuilt.length);
		  
		  // For each school found, creat a new marker on the map
		  for (var i=0; i < XML_names.length; i++) {
			 //markerPopUp = getSchoolInfo(i); 
			 schlName = XML_names[i].childNodes[0].nodeValue;
			 schlCode = XML_codes[i].childNodes[0].nodeValue;
			 schlAddress = XML_address[i].childNodes[0].nodeValue;
			 schlCity = XML_city[i].childNodes[0].nodeValue;
			 schlState = XML_state[i].childNodes[0].nodeValue;
			 schlZip = XML_zip[i].childNodes[0].nodeValue;
			 schlPhone = XML_phone[i].childNodes[0].nodeValue;
			 schlCalendar = XML_calendar[i].childNodes[0].nodeValue;
			 schlGradeLow = XML_gradelow[i].childNodes[0].nodeValue;
			 schlGradeHigh = XML_gradehigh[i].childNodes[0].nodeValue;
			 schlYearBuilt = XML_yearbuilt[i].childNodes[0].nodeValue;
			 schlSqFeet = XML_sqfeet[i].childNodes[0].nodeValue;
			 schlAcres = XML_acres[i].childNodes[0].nodeValue;
			 schlConditionRating = XML_conditionrating[i].childNodes[0].nodeValue;
			 budget_safety = XML_budgetsafety[i].childNodes[0].nodeValue;
			 budget_compliance = XML_budgetcompliance[i].childNodes[0].nodeValue;
			 budget_learning = XML_budgetlearning[i].childNodes[0].nodeValue;
			 budget_repair = XML_budgetrepair[i].childNodes[0].nodeValue;
			 budget_replace = XML_budgetreplace[i].childNodes[0].nodeValue;
			 budget_growth = XML_budgetgrowth[i].childNodes[0].nodeValue;
			 budget_cte = XML_budgetcte[i].childNodes[0].nodeValue;
			 budget_escalation = XML_budgetescalation[i].childNodes[0].nodeValue;
			 budget_total = XML_budgettotal[i].childNodes[0].nodeValue;
			 url_school = XML_url_school[i].childNodes[0].nodeValue;
			 url_dfa = XML_url_dfa[i].childNodes[0].nodeValue;
			 url_ssbpl = XML_url_ssbpl[i].childNodes[0].nodeValue;
			 //markerPopup = schlName;
			 //if (i < 5) alert("schlname = " + schlName);
			 schlLatitude = parseFloat(XML_lat[i].childNodes[0].nodeValue);
			 schlLongitude = parseFloat(XML_long[i].childNodes[0].nodeValue);
			 schlType = XML_type[i].childNodes[0].nodeValue;
			 // make schlObject to pass as parameter to getSchoolInfo function
			 schlObject = new SchoolObject(schlName, schlCode, schlAddress, schlCity, schlState, schlZip, schlPhone, schlCalendar, schlType, schlGradeLow, schlGradeHigh, schlYearBuilt, schlSqFeet, schlAcres, schlConditionRating, url_school, url_dfa, url_ssbpl, schlLatitude, schlLongitude, budget_safety, budget_compliance, budget_learning, budget_repair, budget_replace, budget_growth, budget_cte, budget_escalation, budget_total);
			 markerPopUp = getSchoolInfo(schlObject);
			 
			 // get second popup text
			 markerPopUp2 = getBudgetInfo(schlObject);

			 // get icon for map based on icon type
			 if ( icontype == "school_icon" ) {
			   var icon = getIconSchool(schlType);
			 } else {
			   var icon = getIconPushpin(schlType);
			 }
			 
			 // make map marker for school
			 var marker = createSchlMarker(new GLatLng(schlLatitude, schlLongitude), markerPopUp, markerPopUp2, schlName, icon);
			 // add marker to marker arrays
			 markers.push(marker);
			 allmarkers.push(marker);
			
			 // set school type of marker
			 marker.type = schlType;
			 // set name of marker
			 marker.name = schlName;
			
			 // add school to list of clickable items
			 schlList = schlList + "<div><a class=\"schllist\" href=\"javascript:GEvent.trigger(allmarkers[" + i + "],'click');\">";
			 schlList = schlList + schlName + "</a></div>"; 
		  }
		  // max zoom is 8, if zoomed out farther, icons will disappear
		  mgr.addMarkers(markers, 8);	
		  
		  // add SDUSD icon for when zoom is between 8 and 4
		  var icon = new GIcon();
		  icon.image = "images/SDUSD_map_icon.png";
		  icon.shadow = "images/SDUSD_map_icon_shadow.png";
		  icon.iconSize = new GSize(30, 40);
		  icon.shadowSize = new GSize(51, 40);
		  icon.iconAnchor = new GPoint(30 >> 1, 40 >> 1);
		  icon.infoWindowAnchor = new GPoint(30 >> 1, 40 >> 1);
		  var marker = new GMarker(new GLatLng(32.752866, -117.147802), {title: "San Diego Unified School District (SDUSD)", icon: icon});
		  mgr.addMarker(marker, 4, 7);	 
		  
		  // refresh marker manager object, draw markers on map now
		  mgr.refresh();
		  
		  document.getElementById("school_list").innerHTML += schlList;
		  
		  // since all the markers are loaded by default, make sure all the boxes are checked
		  document.getElementById("Elementary").checked = true;
		  document.getElementById("Middle/Junior High").checked = true;
		  document.getElementById("Senior High").checked = true;
		  document.getElementById("Other District Sites").checked = true;
		  document.getElementById("Charter Schools").checked = true;
		  document.getElementById("Non Public").checked = true;
		  
	      // update counter to show schools displayed at this time
		  markercount = XML_names.length;
  	      document.getElementById("filtercount1").innerHTML = markercount + " schools displayed based on current filter";

	  }	       
    }
	
	/**
	 * ShowHideMarkers(schlType)
	 * ======
	 * Hides or shows markers on the map, based on
	 * the checkboxes for each school type.
	 *
	 * params:
	 *   schlType - string indicating type of school/icon
	 */	
	function ShowHideMarkers(schlType) {
	  var schlList = "";
	  
	  // close any open info windows
	  map.getInfoWindow().hide();
	  
      if (document.getElementById(schlType).checked == false) { // hide the marker
        for (var i=0; i < allmarkers.length; i++) {
          if (allmarkers[i].type == schlType)  {
            //map.removeOverlay(allmarkers[i]);
			allmarkers[i].hide();
			markercount--;
          } 
        }
      } else { // show the marker again
        for (var i=0; i < allmarkers.length; i++) {
          if (allmarkers[i].type == schlType)  {
            //map.addOverlay(allmarkers[i]);
			allmarkers[i].show();
			markercount++;
          }
        }
      }
	  
	  // update list of schools
	  for (var i=0; i < allmarkers.length; i++) {
	    if ( ! allmarkers[i].isHidden() ) {
		  // add school to list of clickable items
		  schlList = schlList + "<div><a class=\"schllist\" href=\"javascript:GEvent.trigger(allmarkers[" + i + "],'click');\">";
		  schlList = schlList + allmarkers[i].name + "</a></div>"; 
		}
	  }
	  
	  // update counter to show schools displayed at this time
	  document.getElementById("filtercount1").innerHTML = markercount + " schools displayed based on current filter";
	  // update list of schools
	  document.getElementById("school_list").innerHTML = schlList;
	}
	
	/**
	 * getIconPushpin(schooltype)
	 * ======
	 * Creates an object of type GIcon.
	 * Icon will be a simple pushpin type.
	 *
	 * params:
	 *   schooltype - string indicating type of school/type of icon.
	 */
	function getIconPushpin(schooltype) {
      var icon = null;
	  var shadow = "images/shadow.png";
	  var iconanchor_width = 6;
	  var iconanchor_height = 20;
	  var infoanchor_width = 5;
	  var infoanchor_height = 1;
	  var icon_width = 12;
	  var icon_height = 20;
	  var shadow_width = 22;
	  var shadow_height = 20;
	  
	  // Elementary = Red icon
	  if ( schooltype == "Elementary" ) {
        icon = new GIcon();
        icon.image = "images/red.png";
	  }
	  // Middle Level = Blue icon
	  if ( schooltype == "Middle/Junior High" ) {
        icon = new GIcon();
        icon.image = "images/blue.png";
	  }
	  //  Senior High = Green icon
	  if ( schooltype == "Senior High" ) {
        icon = new GIcon();
        icon.image = "images/green.png";
	  }
	  //  Other Disrict Sites = Brown icon
	  if ( schooltype == "Other District Sites" ) {
        icon = new GIcon();
        icon.image = "images/brown.png";
	  }
	  //  Charter = Yellow icon
	  if ( schooltype == "Charter Schools" ) {
        icon = new GIcon();
        icon.image = "images/yellow.png";
	  }
	  
	  //  Charter = Orange icon
	  if ( schooltype == "Non Public" ) {
        icon = new GIcon();
        icon.image = "images/orange.png";
	  }
	  
	  // If icon was not created yet, use brown icon (other district sites)
	  if (! icon) {
	    icon = new GIcon();
		icon.image = "images/brown.png";
	  }

      // Set common properties for icon
      icon.shadow = shadow;
      icon.iconSize = new GSize(icon_width, icon_height);
      icon.shadowSize = new GSize(shadow_width, shadow_height);
      icon.iconAnchor = new GPoint(iconanchor_width, iconanchor_height);
      icon.infoWindowAnchor = new GPoint(infoanchor_width, infoanchor_height);

      return icon;
	}

	/**
	 * getIconSchool(schooltype)
	 * ======
	 * Creates an object of type GIcon.
	 * Icon will be a custom school icon.
	 *
	 * params:
	 *   schooltype - string indicating type of school/type of icon.
	 */
	function getIconSchool(schooltype) {
      var icon = null;
	  var shadow = "images/casetta_shadow.png";
	  var iconanchor_width = 32 >> 1;	// signed, bitwise right-shift
	  var iconanchor_height = 32 >> 1;
	  var infoanchor_width = 32 >> 1;
	  var infoanchor_height = 32 >> 1;
	  var icon_width = 32;
	  var icon_height = 32;
	  var shadow_width = 59;
	  var shadow_height = 32;
	  
	  // Elementary = Red icon
	  if ( schooltype == "Elementary" ) {
        icon = new GIcon();
        icon.image = "images/casetta_red.png";
	  }
	  // Middle Level = Blue icon
	  if ( schooltype == "Middle/Junior High" ) {
        icon = new GIcon();
        icon.image = "images/casetta_blue.png";
	  }
	  //  Senior High = Green icon
	  if ( schooltype == "Senior High" ) {
        icon = new GIcon();
        icon.image = "images/casetta_green.png";
	  }
	  //  Other Disrict Sites = Brown icon
	  if ( schooltype == "Other District Sites" ) {
        icon = new GIcon();
        icon.image = "images/casetta_brown.png";
	  }
	  //  Charter = Yellow icon
	  if ( schooltype == "Charter Schools" ) {
        icon = new GIcon();
        icon.image = "images/casetta_yellow.png";
	  }
	  //  Non Public = Orange icon
	  if ( schooltype == "Non Public" ) {
        icon = new GIcon();
        icon.image = "images/casetta_orange.png";
	  }
	  
	  // If icon was not created yet, use brown icon (other district sites)
	  if (! icon) {
        icon = new GIcon();
        icon.image = "images/casetta_brown.png";
	  }

      // Set common properties for icon
      icon.shadow = shadow;
      icon.iconSize = new GSize(icon_width, icon_height);
      icon.shadowSize = new GSize(shadow_width, shadow_height);
      icon.iconAnchor = new GPoint(iconanchor_width, iconanchor_height);
      icon.infoWindowAnchor = new GPoint(infoanchor_width, infoanchor_height);

      return icon;
	}

	/**
	 * SchoolObject definition
	 * ======
	 * School data object holds relevant data for each school.
	 * Passed as a parameter to functions needing school data.
	 */	
	function SchoolObject(name, code, address, city, state, zip, phone, calendar, type, gradelow, gradehigh, yearbuilt, sqfeet, acres, conditionrating, url_school, url_dfa, url_ssbpl, lat, long, budget_safety, budget_compliance, budget_learning, budget_repair, budget_replace, budget_growth, budget_cte, budget_escalation, budget_total)
	{
	  this.name = name;
	  this.code = code;
	  this.address = address.replace(/unknown/,"");
	  this.city = city.replace(/unknown/,"");
	  this.state = state.replace(/unknown/,"");
	  this.zip = zip.replace(/unknown/,"");
	  this.phone = phone.replace(/unknown/,"");
	  this.calendar = calendar.replace(/unknown/,"");
	  this.type = type.replace(/District Run/,"");
	  this.gradelow = gradelow.replace(/unknown/,"");
	  this.gradehigh = gradehigh.replace(/unknown/,"");
	  this.yearbuilt = yearbuilt.replace(/unknown/,"");
	  this.sqfeet = sqfeet.replace(/unknown/,"");
	  this.acres = acres.replace(/unknown/,"");
	  this.conditionrating = conditionrating.replace(/unknown/,"");
	  //budget_safety, budget_compliance, budget_learning, budget_repair, budget_replace, budget_growth, budget_total
	  this.budget_safety = budget_safety.replace(/unknown/,"");
	  this.budget_compliance = budget_compliance.replace(/unknown/,"");
	  this.budget_learning = budget_learning.replace(/unknown/,"");
	  this.budget_repair = budget_repair.replace(/unknown/,"");
	  this.budget_replace = budget_replace.replace(/unknown/,"");
	  this.budget_growth = budget_growth.replace(/unknown/,"");
	  this.budget_cte = budget_cte.replace(/unknown/,"");
	  this.budget_escalation = budget_escalation.replace(/unknown/,"");
	  this.budget_total = budget_total.replace(/unknown/,"");
	  this.url_school = url_school.replace(/unknown/,"");
	  this.url_dfa = url_dfa.replace(/unknown/,"");
	  this.url_ssbpl = url_ssbpl.replace(/unknown/,"");
	  this.lat = lat;
	  this.long = long;
	}

	/**
	 * getSchoolInfo(schlObject)
	 * ======
	 * Returns a string of formatted HTML to display in map bubble for an icon.
	 *
	 * params:
	 *   schlOBject - Object containing school data for info window
	 */	
	function getSchoolInfo(schlObject) {
      var schlName;
	  var schlGradeLow, schlGradeHigh, schlGrades;
      var schlAddress, schlCity, schlState, schlZip;
      var schlLatitude, schlLongitude;
      var schlPhone, schlType, schlCalendar, schlCode;
	  var schlWebSite, schlDFA, schlSSBPL;
	  var schlYearBuilt, schlSquareFeet, schlAcres, schlConditionRating;
	  var schlConditionPercent, schlConditionText;
      var schlMapPopUpText;

	  schlName = schlObject.name;
	  schlGradeLow = schlObject.gradelow;
	  schlGradeHigh = schlObject.gradehigh;
	  schlAddress = schlObject.address;
	  schlCity = schlObject.city;
	  schlState = schlObject.state;
	  schlZip = schlObject.zip;
	  schlLatitude = schlObject.lat;
	  schlLongitude = schlObject.long;
	  schlPhone = schlObject.phone;
	  schlType = schlObject.type;
	  schlCalendar = schlObject.calendar;
	  schlCode = schlObject.code;
	  schlWebSite = schlObject.url_school;
	  schlDFA = schlObject.url_dfa;
	  schlSSBPL = schlObject.url_ssbpl;
	  schlYearBuilt = schlObject.yearbuilt;
	  schlSquareFeet = schlObject.sqfeet;
	  schlAcres = schlObject.acres;
	  schlConditionRating = schlObject.conditionrating;
	  
  	  schlGrades = "" ;
	  if ( schlGradeLow < 0 ) {
        schlGrades = schlGrades + "Pre K";
	  } else {
		schlGrades = schlGrades + schlGradeLow;
	  }
	  schlGrades = schlGrades + " - " + schlGradeHigh;
	  
	  // create Info Window HTML for school info
	  schlMapPopUpText = "<table style=\"width:400px\" cellpadding=\"1\" cellspacing=\"1\">"
	  //schlMapPopUpText = "<table  cellpadding=\"1\" cellspacing=\"1\">"
	  // school address
	  schlMapPopUpText = schlMapPopUpText 
	                   + "<tr><td class=\"infowindowbold\">Address:</td>" 
	                   + "<td class=\"maptext\">" + schlAddress + "<br />";
	  // school city
	  if ( schlCity.length > 0 ) {
  	    schlMapPopUpText = schlMapPopUpText;
	    schlMapPopUpText = schlMapPopUpText + schlCity;
	  }
	  // school state
	  if ( schlState.length > 0 ) {
  	    schlMapPopUpText = schlMapPopUpText + ", ";
	    schlMapPopUpText = schlMapPopUpText + schlState;
	  }
	  // school zip
	  if ( schlZip.length > 0 ) {
  	    schlMapPopUpText = schlMapPopUpText + ", ";
	    schlMapPopUpText = schlMapPopUpText + schlZip;
	  }
  	  schlMapPopUpText = schlMapPopUpText + "</td></tr>";
	  
	  if ( schlPhone.length > 0 ) {
  	    schlMapPopUpText = schlMapPopUpText + "<tr><td class=\"infowindowbold\">Phone:</td>";
	    if ( schlPhone.length > 7 ) {
			schlPhone = schlPhone.replace(")",") ");
		}
		schlMapPopUpText = schlMapPopUpText + "<td class=\"maptext\">" + schlPhone + "</td></tr>";
	  }
	  //schlMapPopUpText = schlMapPopUpText + "<b>School Type:</b> " + schlType.replace(/District Run/, "") + "<br />";
	  schlMapPopUpText = schlMapPopUpText + "<tr><td class=\"infowindowbold\">School Type:</td>" 
	                   + "<td class=\"maptext\">" + schlType + "</td></tr>";
	  schlMapPopUpText = schlMapPopUpText + "<tr><td class=\"infowindowbold\">Grade Levels:</td>" 
	                   + "<td class=\"maptext\">" + schlGrades + "</td></tr>";
	  if ( schlCalendar.length > 0 ) {
	    schlMapPopUpText = schlMapPopUpText + "<tr><td class=\"infowindowbold\">Calendar Type:</td>" 
		                 + "<td class=\"maptext\">" + schlCalendar + "</td></tr>";
	  }

	  // display year built
	  if ( schlYearBuilt.length > 0 ) {
	    schlMapPopUpText = schlMapPopUpText + "<tr><td class=\"infowindowbold\">Year Built:</td>" 
		                 + "<td class=\"maptext\">" + schlYearBuilt + "</td></tr>";
	  }
	  
	  // display square feet
	  if ( schlSquareFeet.length > 0 ) {
	    var sfrounded = Math.round(schlSquareFeet) + "";  // make it a string
		schlMapPopUpText = schlMapPopUpText + "<tr><td class=\"infowindowbold\">Building Area:</td>" 
		                 + "<td class=\"maptext\">" + format(sfrounded, '3', ',') + " sq. ft.</td></tr>";
	  }
	  
	  // display acres
	  if ( schlAcres.length > 0 ) {
	    schlMapPopUpText = schlMapPopUpText + "<tr><td class=\"infowindowbold\">Land Area:</td>" 
		                 + "<td class=\"maptext\">" + schlAcres + " acres</td></tr>";
	  }
	  
	  // display condition rating
	  if ( schlConditionRating.length > 0 ) {
		schlConditionPercent = formatPercentage(schlConditionRating);
		schlConditionPercent = round(schlConditionPercent, 1);
		if ( schlConditionRating < 0.05 ) {
		  schlConditionText = "good";
		} else if ( schlConditionRating >= 0.05 && schlConditionRating <= 0.10 ) {
		  schlConditionText = "fair";
		} else if ( schlConditionRating > 0.10 ) {
		  schlConditionText = "poor";
		}
	    schlMapPopUpText = schlMapPopUpText + "<tr><td class=\"infowindowbold\">Facility Condition Index (FCI):</td>" 
		                 + "<td class=\"maptext\">" + schlConditionText + " (" + schlConditionPercent
						 + "%) <a href=\"#\" onClick=\"MyWindow=window.open('help_conditionrating.html','MyWindow', "
						 + "'toolbar=no,location=no,directories=yes,status=no,menubar=yes, "
						 + "scrollbars=yes,resizable=yes,width=350,height=450'); return false;\">"
						 + "<img src=\"images/question.jpg\" style=\""
						 + "width:13px;height:13px;border:0px;\" "
						 + "alt=\"About the Facility Condition Index (FCI)\" title=\""
						 + "About the Facility Condition Index (FCI)\" /></a></td></tr>";
	  }
	  
	  // display school web site link if it exists
	  if ( schlWebSite.length > 0 ) {
	    schlMapPopUpText = schlMapPopUpText + "<tr><td colspan=\"2\" class=\"maptext\"><a href=\"" 
		                 + schlWebSite + "\" target=\"_blank\">School Web Site</a></td></tr>";
	  }
	  
	  // display DFA link if it exists
	  if ( schlDFA.length > 0 ) {
	    schlMapPopUpText = schlMapPopUpText + "<tr><td colspan=\"2\" class=\"maptext\"><a href=\"" 
		                 + schlDFA + "\" target=\"_blank\">District Facilities Assessment</a>";
		schlMapPopUpText = schlMapPopUpText
						 + " <a href=\"#\" onClick=\"MyWindow=window.open('help_dfa.html','MyWindow', "
						 + "'toolbar=no,location=no,directories=yes,status=no,menubar=yes, "
						 + "scrollbars=yes,resizable=yes,width=350,height=400'); return false;\">"
						 + "<img src=\"images/question.jpg\" style=\""
						 + "width:13px;height:13px;border:0px;\" "
						 + "alt=\"About the District Facilities Assessment\" title=\""
						 + "About the District Facilities Assessment\" /></a> "
						 + " <img src=\"http://www.sandi.net/images/pdf_icon.gif\" "
		                 + "alt=\"Adobe Acrobat Document\" title=\"Adobe Acrobat Document\" style=\"width:10px;height:10px\" /> "
						 + "</td></tr>";
	  }
	  
	  // display SSBPL link if it exists
	  if ( schlSSBPL.length > 0 ) {
	    schlMapPopUpText = schlMapPopUpText + "<tr><td colspan=\"2\" class=\"maptext\"><a href=\"" 
		                 + schlSSBPL + "\" target=\"_blank\">Site-Specific Bond Project List</a>";
		schlMapPopUpText = schlMapPopUpText 						 
		                 + " <a href=\"#\" onClick=\"MyWindow=window.open('help_ssbpl.html','MyWindow', "
						 + "'toolbar=no,location=no,directories=yes,status=no,menubar=yes, "
						 + "scrollbars=yes,resizable=yes,width=350,height=400'); return false;\">"
						 + "<img src=\"images/question.jpg\" style=\""
						 + "width:13px;height:13px;border:0px;\" "
						 + "alt=\"About the Site-Specific Bond Project List\" title=\""
						 + "About the Site-Specific Bond Project List\" /></a> "
						 + " <img src=\"http://www.sandi.net/images/pdf_icon.gif\" "
		                 + "alt=\"Adobe Acrobat Document\" title=\"Adobe Acrobat Document\" style=\"width:10px;height:10px\" /> "

						 + "</td></tr>";
	  }
	  
	  // end table
	  schlMapPopUpText = schlMapPopUpText + "</table>"; 
	  	  
	  return schlMapPopUpText;
	}

	/**
	 * getBudgetInfo(schlOBject)
	 * ======
	 * Returns a string of formatted HTML to display in map bubble for an icon.
	 *
	 * params:
	 *   schlOBject - Object containing school data for info window
	 */	
	function getBudgetInfo(schlObject) {
      var schlName;
	  var schlGradeLow, schlGradeHigh, schlGrades;
      var schlAddress, schlCity, schlState, schlZip;
      var schlLatitude, schlLongitude;
      var schlPhone, schlType, schlCalendar, schlCode;
	  var schlWebSite, schlDFA, schlSSBPL;
	  var schlYearBuilt, schlSquareFeet, schlAcres, schlConditionRating;
	  var schlConditionPercent, schlConditionText;
      var schlMapPopUpText;
	  var blnSquareFeetExists, psfcalc;

	  schlName = schlObject.name;
	  schlGradeLow = schlObject.gradelow;
	  schlGradeHigh = schlObject.gradehigh;
	  schlAddress = schlObject.address;
	  schlCity = schlObject.city;
	  schlState = schlObject.state;
	  schlZip = schlObject.zip;
	  schlLatitude = schlObject.lat;
	  schlLongitude = schlObject.long;
	  schlPhone = schlObject.phone;
	  schlType = schlObject.type;
	  schlCalendar = schlObject.calendar;
	  schlCode = schlObject.code;
	  schlWebSite = schlObject.url_school;
	  schlDFA = schlObject.url_dfa;
	  schlSSBPL = schlObject.url_ssbpl;
	  schlYearBuilt = schlObject.yearbuilt;
	  schlSquareFeet = schlObject.sqfeet;
	  schlAcres = schlObject.acres;
	  schlConditionRating = schlObject.conditionrating;
	  budget_safety = schlObject.budget_safety;
	  budget_compliance = schlObject.budget_compliance;
	  budget_learning = schlObject.budget_learning;
	  budget_repair = schlObject.budget_repair;
	  budget_replace = schlObject.budget_replace;
	  budget_growth = schlObject.budget_growth;
	  budget_cte = schlObject.budget_cte;
	  budget_escalation = schlObject.budget_escalation;
	  budget_total = schlObject.budget_total;
	  blnSquareFeetExists = false;
	  
	  // create Info Window HTML for budget info
	  // display square feet
	  schlMapPopUpText = "";
	  
	  // check to see if there is any budget data
	  if (budget_safety.length <= 0 && budget_compliance.length <= 0 &&
		  budget_learning.length <= 0 && budget_repair.length <= 0 &&
		  budget_growth.length <= 0 && budget_total.length <= 0) {
	    schlMapPopUpText = "<br />Budget information is not available for this school.";
		return schlMapPopUpText;
	  }
	  
	  schlMapPopUpText = schlMapPopUpText + "<span class=\"markertitle\">"
	                   + schlName + "</span><br /><br />";
					   
      if ( schlSquareFeet.length > 0 ) {
		//schlSquareFeet.toFixed(0);
		var sfrounded = Math.round(schlSquareFeet) + "";  // make it a string
	    schlMapPopUpText = schlMapPopUpText + "<b>Building Area:</b> " 
		                 + format(sfrounded, '3', ',') + " sq. ft.";
	    blnSquareFeetExists = true;
	  } 
	  schlMapPopUpText = schlMapPopUpText + "<p></p><table style=\"width:400px\" cellpadding=\"1\" cellspacing=\"1\">"
	  //schlMapPopUpText = "<table  cellpadding=\"1\" cellspacing=\"1\">"
	  // table columns
	  schlMapPopUpText = schlMapPopUpText 
	                   + "<tr><td class=\"budget_header\" style=\"width:200px;\">Category</td>"
					   + "<td class=\"budget_header\" style=\"width:100px;text-align:right\">Total</td>"
					   + "<td class=\"budget_header\" style=\"width:100px;text-align:right\">Per Sq. Ft.</td></tr>"
	  // budget_safety, budget_compliance, budget_learning, budget_repair, budget_replace, budget_growth, budget_total
	  if ( budget_safety.length > 0 && budget_safety > 0 ) {
	    schlMapPopUpText = schlMapPopUpText 
	                     + "<tr><td class=\"budget_data\">Improve Student "
						 + "Health, Safety & Security" //</td>";
						 + " <a href=\"#\" onClick=\"MyWindow=window.open('help_budget_safety.html','MyWindow', "
						 + "'toolbar=no,location=no,directories=yes,status=no,menubar=yes, "
						 + "scrollbars=yes,resizable=yes,width=350,height=450'); return false;\">"
						 + "<img src=\"images/question.jpg\" style=\""
						 + "width:13px;height:13px;border:0px;\" "
						 + "alt=\"About Improving Student "
						 + "Health, Safety & Security\" title=\""
						 + "About Improving Student "
						 + "Health, Safety & Security\" /></a></td>";
		schlMapPopUpText = schlMapPopUpText 
		                 + "<td class=\"budget_data\" style=\"text-align:right\">$" + format(Math.round(budget_safety) + "", '3', ',') + "</td>";
		if ( blnSquareFeetExists ) {
		  psfcalc = budget_safety / schlSquareFeet;
		  //if (schlCode == "0003A") alert("psfcalc = " + psfcalc.toFixed(2));
		  schlMapPopUpText = schlMapPopUpText 
		                   + "<td class=\"budget_data\" style=\"text-align:right\">$" + psfcalc.toFixed(2) + "</td></tr>";
		} else {
		  schlMapPopUpText = schlMapPopUpText 
		                   + "<td class=\"budget_data\"></td></tr>";			
		}
	  }
	  if ( budget_compliance.length > 0 && budget_compliance > 0 ) {
	    schlMapPopUpText = schlMapPopUpText 
	                     + "<tr><td class=\"budget_data\">Improve School "
						 + "Accessibility and Code Compliance Upgrades"
						 + " <a href=\"#\" onClick=\"MyWindow=window.open('help_budget_compliance.html','MyWindow', "
						 + "'toolbar=no,location=no,directories=yes,status=no,menubar=yes, "
						 + "scrollbars=yes,resizable=yes,width=350,height=450'); return false;\">"
						 + "<img src=\"images/question.jpg\" style=\""
						 + "width:13px;height:13px;border:0px;\" "
						 + "alt=\"About Improving School "
						 + "Accessibility and Code Compliance Upgrades\" title=\""
						 + "About Improving School "
						 + "Accessibility and Code Compliance Upgrades\" /></a></td>";
		schlMapPopUpText = schlMapPopUpText 
		                 + "<td class=\"budget_data\" style=\"text-align:right\">$" + format(Math.round(budget_compliance) + "", '3', ',') + "</td>";
		if ( blnSquareFeetExists ) {
		  psfcalc = budget_compliance / schlSquareFeet;
		  //if (schlCode == "0003A") alert("psfcalc = " + psfcalc.toFixed(2));
		  schlMapPopUpText = schlMapPopUpText 
		                   + "<td class=\"budget_data\" style=\"text-align:right\">$" + psfcalc.toFixed(2) + "</td></tr>";
		} else {
		  schlMapPopUpText = schlMapPopUpText 
		                   + "<td class=\"budget_data\"></td></tr>";			
		}
	  }
	  if ( budget_learning.length > 0 && budget_learning > 0 ) {
	    schlMapPopUpText = schlMapPopUpText 
	                     + "<tr><td class=\"budget_data\">Improve Student "
						 + "Learning and Instruction"
						 + " <a href=\"#\" onClick=\"MyWindow=window.open('help_budget_learning.html','MyWindow', "
						 + "'toolbar=no,location=no,directories=yes,status=no,menubar=yes, "
						 + "scrollbars=yes,resizable=yes,width=350,height=450'); return false;\">"
						 + "<img src=\"images/question.jpg\" style=\""
						 + "width:13px;height:13px;border:0px;\" "
						 + "alt=\"About Improving Student "
						 + "Learning and Instruction\" title=\""
						 + "About Improving Student "
						 + "Learning and Instruction\" /></a></td>";
		schlMapPopUpText = schlMapPopUpText 
		                 + "<td class=\"budget_data\" style=\"text-align:right\">$" + format(Math.round(budget_learning) + "", '3', ',') + "</td>";
		if ( blnSquareFeetExists ) {
		  psfcalc = budget_learning / schlSquareFeet;
		  //if (schlCode == "0003A") alert("psfcalc = " + psfcalc.toFixed(2));
		  schlMapPopUpText = schlMapPopUpText 
		                   + "<td class=\"budget_data\" style=\"text-align:right\">$" + psfcalc.toFixed(2) + "</td></tr>";
		} else {
		  schlMapPopUpText = schlMapPopUpText 
		                   + "<td class=\"budget_data\"></td></tr>";			
		}
	  }
	  if ( budget_repair.length > 0 && budget_repair > 0 ) {
	    schlMapPopUpText = schlMapPopUpText 
	                     + "<tr><td class=\"budget_data\">Major Building Systems Repair "
						 + "/ Replacement"
						 + " <a href=\"#\" onClick=\"MyWindow=window.open('help_budget_repair.html','MyWindow', "
						 + "'toolbar=no,location=no,directories=yes,status=no,menubar=yes, "
						 + "scrollbars=yes,resizable=yes,width=350,height=450'); return false;\">"
						 + "<img src=\"images/question.jpg\" style=\""
						 + "width:13px;height:13px;border:0px;\" "
						 + "alt=\"About Major Building Systems Repair "
						 + "/ Replacement\" title=\""
						 + "About Major Building Systems Repair "
						 + "/ Replacement\" /></a></td>";
		schlMapPopUpText = schlMapPopUpText 
		                 + "<td class=\"budget_data\" style=\"text-align:right\">$" + format(Math.round(budget_repair) + "", '3', ',') + "</td>";
		if ( blnSquareFeetExists ) {
		  psfcalc = budget_repair / schlSquareFeet;
		  //if (schlCode == "0003A") alert("psfcalc = " + psfcalc.toFixed(2));
		  schlMapPopUpText = schlMapPopUpText 
		                   + "<td class=\"budget_data\" style=\"text-align:right\">$" + psfcalc.toFixed(2) + "</td></tr>";
		} else {
		  schlMapPopUpText = schlMapPopUpText 
		                   + "<td class=\"budget_data\"></td></tr>";			
		}
	  }
	  if ( budget_cte.length > 0 && budget_cte > 0 ) {
	    schlMapPopUpText = schlMapPopUpText 
	                     + "<tr><td class=\"budget_data\">Career Technical Education "
						 + " <a href=\"#\" onClick=\"MyWindow=window.open('help_budget_cte.html','MyWindow', "
						 + "'toolbar=no,location=no,directories=yes,status=no,menubar=yes, "
						 + "scrollbars=yes,resizable=yes,width=350,height=450'); return false;\">"
						 + "<img src=\"images/question.jpg\" style=\""
						 + "width:13px;height:13px;border:0px;\" "
						 + "alt=\"About Career Technical Education"
						 + "\" title=\""
						 + "About Career Technical Education"
						 + "\" /></a></td>";
		schlMapPopUpText = schlMapPopUpText 
		                 + "<td class=\"budget_data\" style=\"text-align:right\">$" + format(Math.round(budget_cte) + "", '3', ',') + "</td>";
		if ( blnSquareFeetExists ) {
		  psfcalc = budget_cte / schlSquareFeet;
		  //if (schlCode == "0003A") alert("psfcalc = " + psfcalc.toFixed(2));
		  schlMapPopUpText = schlMapPopUpText 
		                   + "<td class=\"budget_data\" style=\"text-align:right\">$" + psfcalc.toFixed(2) + "</td></tr>";
		} else {
		  schlMapPopUpText = schlMapPopUpText 
		                   + "<td class=\"budget_data\"></td></tr>";			
		}
	  }
	  if ( budget_escalation.length > 0 && budget_escalation > 0 ) {
	    schlMapPopUpText = schlMapPopUpText 
	                     + "<tr><td class=\"budget_data\">Escalation "
						 + " <a href=\"#\" onClick=\"MyWindow=window.open('help_budget_escalation.html','MyWindow', "
						 + "'toolbar=no,location=no,directories=yes,status=no,menubar=yes, "
						 + "scrollbars=yes,resizable=yes,width=350,height=450'); return false;\">"
						 + "<img src=\"images/question.jpg\" style=\""
						 + "width:13px;height:13px;border:0px;\" "
						 + "alt=\"About Escalation"
						 + "\" title=\""
						 + "About Escalation"
						 + "\" /></a></td>";
		schlMapPopUpText = schlMapPopUpText 
		                 + "<td class=\"budget_data\" style=\"text-align:right\">$" + format(Math.round(budget_escalation) + "", '3', ',') + "</td>";
		if ( blnSquareFeetExists ) {
		  psfcalc = budget_escalation / schlSquareFeet;
		  //if (schlCode == "0003A") alert("psfcalc = " + psfcalc.toFixed(2));
		  schlMapPopUpText = schlMapPopUpText 
		                   + "<td class=\"budget_data\" style=\"text-align:right\">$" + psfcalc.toFixed(2) + "</td></tr>";
		} else {
		  schlMapPopUpText = schlMapPopUpText 
		                   + "<td class=\"budget_data\"></td></tr>";			
		}
	  }
	  if ( budget_replace.length > 0 && budget_replace > 0 ) {
	    schlMapPopUpText = schlMapPopUpText 
	                     + "<tr><td class=\"budget_data\">Replace inadequate school "
						 + "buildings or sites with new permanent construction</td>";
		schlMapPopUpText = schlMapPopUpText 
		                 + "<td class=\"budget_data\" style=\"text-align:right\">$" + format(Math.round(budget_replace) + "", '3', ',') + "</td>";
		if ( blnSquareFeetExists ) {
		  psfcalc = budget_replace / schlSquareFeet;
		  //if (schlCode == "0003A") alert("psfcalc = " + psfcalc.toFixed(2));
		  schlMapPopUpText = schlMapPopUpText 
		                   + "<td class=\"budget_data\" style=\"text-align:right\">$" + psfcalc.toFixed(2) + "</td></tr>";
		} else {
		  schlMapPopUpText = schlMapPopUpText 
		                   + "<td class=\"budget_data\"></td></tr>";			
		}
	  }
	  if ( budget_growth.length > 0 && budget_growth > 0 ) {
	    schlMapPopUpText = schlMapPopUpText 
	                     + "<tr><td class=\"budget_data\">Accommodating Student "
						 + "Enrollment Growth</td>";
		schlMapPopUpText = schlMapPopUpText 
		                 + "<td class=\"budget_data\" style=\"text-align:right\">$" + format(Math.round(budget_growth) + "", '3', ',') + "</td>";
		if ( blnSquareFeetExists ) {
		  psfcalc = budget_growth / schlSquareFeet;
		  //if (schlCode == "0003A") alert("psfcalc = " + psfcalc.toFixed(2));
		  schlMapPopUpText = schlMapPopUpText 
		                   + "<td class=\"budget_data\" style=\"text-align:right\">$" + psfcalc.toFixed(2) + "</td></tr>";
		} else {
		  schlMapPopUpText = schlMapPopUpText 
		                   + "<td class=\"budget_data\"></td></tr>";			
		}
	  }
	  if ( budget_total.length > 0 ) {
	    schlMapPopUpText = schlMapPopUpText 
	                     + "<tr><td class=\"budget_totals\">Total</td>";
		schlMapPopUpText = schlMapPopUpText 
		                 + "<td class=\"budget_totals\" style=\"text-align:right\">$" + format(Math.round(budget_total) + "", '3', ',') + "</td>";
		if ( blnSquareFeetExists ) {
		  psfcalc = budget_total / schlSquareFeet;
		  //if (schlCode == "0003A") alert("psfcalc = " + psfcalc.toFixed(2));
		  schlMapPopUpText = schlMapPopUpText 
		                   + "<td class=\"budget_totals\" style=\"text-align:right\">$" + psfcalc.toFixed(2) + "</td></tr>";
		} else {
		  schlMapPopUpText = schlMapPopUpText 
		                   + "<td class=\"budget_totals\"></td></tr>";			
		}
	  }
	  
	  // end table
	  schlMapPopUpText = schlMapPopUpText + "</table>"; 
	  	  
	  return schlMapPopUpText;
	}


	/**
	 * createSchlMarker(point, marker_label, marker_title, marker_icon)
	 * ======
	 * Creates an object of type GMarker.
	 * Marker will be located on map at the location specified by point.
	 * Title of marker will be marker_title.
	 * Icon of marker will be marker_icon.
	 * Body of text in marker infowindow/bubble will be marker_label.
	 *
	 * params:
	 *   point 		  - Where the marker should be on the map (lat/long pair).
	 *   marker_label - Body of text to display in infowindow/bubble.
	 *   marker_title - Title of marker.
	 *   marker_icon  - Icon for marker.
	 */
    // Creates a marker at the given point with given label and title
    function createSchlMarker(point, marker_label, marker_label2, marker_title, marker_icon) {
	  var lat_streetview, long_streetview;
	  var isnegative = 0;
	  
	  lat_streetview = point.lat();
	  long_streetview = point.lng();
	  
  	  // get lat and long from point parameter
	  // round the value to less decimal places for use with streetview
	  lat_streetview = point.lat();
	  long_streetview = point.lng();
	  //alert("point.lat = " + lat_streetview);
	  //alert("point.long = " + long_streetview);
	  // round values to 3 decimals to try and get street view data
      if ( long_streetview < 0 ) {
		// the toFixed() function can't handle negative numbers
		isnegative = 1;
		long_streetview = Math.abs(long_streetview);
	  }
	  lat_streetview = lat_streetview.toFixed(3);
	  //alert("rounded lat = " + lat_streetview);
	  long_streetview = long_streetview.toFixed(3);
	  if ( isnegative > 0 ) {
		long_streetview = "-" + long_streetview;	
      }
	  //alert("rounded long = " + long_streetview);
	  
	  // Create the marker at specified point, with given title and icon
	  var marker = new GMarker(point, {title: marker_title, icon: marker_icon});
	  
	  // Create array for infowindow tabs
	  var infowindowtabs = [];
	  var tabHTML = "";
	  
	  // Create the school info tab
	  tabHTML = "<span class=\"maptext\"><span class=\"markertitle\">"
	          + marker_title + "</span><br /><br />" 
			  + marker_label + "</span>";
	  var schlInfoTab = new GInfoWindowTab("School Info",  tabHTML);
	  infowindowtabs.push(schlInfoTab);
	  
	  // Create the budget info tab
	  //if ( marker_label2.length > 0 ) {
	  tabHTML = "<span class=\"maptext\">" + marker_label2 + "</span>";
	  var schlBudgetTab = new GInfoWindowTab("Budget Info",  tabHTML);
	  infowindowtabs.push(schlBudgetTab);
	  //}
	  	  
	  // Create street view tab
	  tabHTML = "<div style=\"width:400px;\"><div id=\"streetmap\" "
	          + "style=\"width:400px;height:250px;\" class=\"maptext\">"
              + "<br />Street View is not available for this school."
              + "</div></div>";
	  var schlStreetViewTab = new GInfoWindowTab("Street View", tabHTML);	  
	  infowindowtabs.push(schlStreetViewTab);
	  
	  // Street View Panorama object
	  var streetviewpanorama = 'undefined';
	  
      //alert("adding map point for " + marker_title);
      GEvent.addListener(marker, "click", function() {
	    //marker.openInfoWindowHtml('<span class="maptext"><span class="markertitle">' + marker_title + '</span><br /><br />' + marker_label + '</span>');
	    //map.panTo(point);
		// Bind info window tabs to marker
		marker.openInfoWindowTabs(infowindowtabs);
        // Set street view 
		if (streetviewpanorama == 'undefined') {
          //streetviewpanorama = new GStreetviewPanorama(document.getElementById("streetmap"), { latlng:point });
		  streetviewpanorama = new GStreetviewPanorama(document.getElementById("streetmap"));
		  // set the latitude and longitude of street view
		  //streetviewpanorama.setLocationAndPOV(point);
		  // use a less precise version of latitude and longitude, to try
		  // and ensure we can display a street view.
		  streetviewpanorama.setLocationAndPOV(new GLatLng(lat_streetview, long_streetview));
		  //var newlatlong = panoClient.getNearestPanoramaLatLng(point, GetNewLatLong);
		  GEvent.addListener(streetviewpanorama, "error", handleNoFlash);
        }
      });
	  
	  // Return the marker that was created
      return marker;
    }
	
	/**
	 * getRadioValue(radioGroupName)
	 * ======
	 * Inpects form radio button options and returns value selected.
	 * Code from sajuks user, http://www.experts-exchange.com/Web/Web_Languages/JavaScript/Q_21466494.html
	 *
	 * params:
	 *   radioGroupName - string indicating which radio button option to inspect in form data.
	 */
    function getRadioValue(radioGroupName) {
      radios = document.getElementsByName(radioGroupName);
      for (i = 0; i < radios.length; i++) {
        if (radios[i].checked) return radios[i].value;
      }
	}
		
	/**
	 * handleNoFlahs
	 * ======
	 * Function to handle when browser does not support flash.
	 *
	 * params:
	 *   errorCode - 
	 */
    function handleNoFlash(errorCode) {
      if (errorCode == FLASH_UNAVAILABLE) {
        alert("Error: Flash doesn't appear to be supported by your browser");
        return;
      }
    } 
	
	/**
	 * formatPercentage(n)
	 * ======
	 * Function to handle formatting percentage values
	 *
	 * params:
	 *   n - number or percentage to format
	 */
    function formatPercentage (n) {
      var myPercent;
	  myPercent = n * 100;
	  return myPercent;
    }
	
	/**
	 * format
	 * ======
	 * Formats a number to include comma delimeters, etc.
	 *
	 * params:
	 *   value - number to format
	 *   spacing - how many spaces between delimiters
	 *   delimiter - what delimeter to use
	 */
	function format(value, spacing, delimiter)
	{
		var isplace =0;
		var i;
		var outstring = "";
		var mydecimals = "";
		
		// if value contains decimals, then
		// strip off decimals and ignore them GRH 08/05/08
		if ( value.length > 0 ) {
		  if ( value.indexOf(".") > 0 ) {
			  // save the value after the decimals and add it when we're done
			  mydecimals = value.substr(value.indexOf("."), value.length);
			  value = value.substr(0, value.indexOf("."));
		  }
		}
	
		// supress the leading 0's
		var position;
		for(i = 0; i < value.length ; i++)
		{
			if (value.charAt(i) != "0")
			{
				position = i;
				break;
			}
		}
		
		if ( value.length > 0 ) {
		  value = value.substring(i, value.length);
		}
		var len = value.length -1;
		// inserts the delimiter in the number string in a reverse manner.
		for (i= len; i>=0; i--)
		{
			outstring += value.charAt(i);	
			isplace++;
			if (isplace == eval(spacing))
			{
				if ( i != 0)outstring += delimiter;
				isplace = 0;
			}
		}
	
		// home grown reverse function
		var len = outstring.length -1;
		var output = "";
		for (i= len; i>=0; i--)
		{
			output += outstring.charAt(i);
		}
		
		if (output.length <= 0) output = "0";
		
		// check to see if decimals were found, if so put them back
		if ( mydecimals.length > 0 ) {
			output = output + mydecimals;
		}
		
		return output;
	}
	
	/**
	 * round()
	 * ======
	 * Function used for rounding numbers
	 *
	 * params:
	 *   n - number value
	 *   d - decimal places in end result, rounded number
	 */
	function round (n, d) {
	  n = n - 0;
	  d = d || 2;
	  var f = Math.pow(10, d);
	  n = Math.round(n * f) / f;
	  n += Math.pow(10, - (d + 1));
	  n += '';
	  return d == 0 ? n.substring(0, n.indexOf('.')) :
		  n.substring(0, n.indexOf('.') + d + 1);
	}


	/**
	 * gup()
	 * ======
	 * Function used for getting URL parameters from page
	 * Taken from http://www.netlobo.com/url_query_string_javascript.html
	 *
	 * params (none)
	 *   name - name of URL parameter to find
	 */
	function gup( name )
	{
	  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	  var regexS = "[\\?&]"+name+"=([^&#]*)";
	  var regex = new RegExp( regexS );
	  var results = regex.exec( window.location.href );
	  if( results == null )
		return "";
	  else
		return results[1];
	}
	
    //]]>
