<?xml version="1.0" encoding="UTF-8"?> 
 <Module>
  <ModulePrefs title="Local Gas Prices" title_url="http://www.satctranscripts.com/2008/10/local-gas-finder.html"
  directory_title="Local Gas Prices Finder"
  description="This powerful gadget helps vehicle drivers find the lowest gas prices in local area. All station addresses are directly linked to GoogleMaps so that you can easily check them out."
  category="lifestyle" category2="tools" author="satctranscripts.com"
  author_email="admin@satctranscripts.com" author_link="http://www.satctranscripts.com/"
  width="400" height="300" scaling="false" scrolling="true"
  screenshot="http://sites.google.com/site/satcscripts/gasprice/GasPrice.GIF"
  thumbnail="http://sites.google.com/site/satcscripts/gasprice/GasPrice.GIF" >
  <Require feature="dynamic-height"/>
  </ModulePrefs>
  <UserPref name="zipcode" display_name="Zip Code" datatype="string" required="true" default_value="10001" /> 
  <UserPref name="showRegular" display_name="Show Regular?" datatype="bool" required="false" default_value="true" /> 
  <UserPref name="showPlus" display_name="Show Plus?" datatype="bool" required="false" default_value="true" /> 
  <UserPref name="showPremium" display_name="Show Premium?" datatype="bool" required="false" default_value="false" /> 
  <UserPref name="showDiesel" display_name="Show Diesel?" datatype="bool" required="false" default_value="false" /> 
  <UserPref name="stationCount" display_name="Stations Count" datatype="string" required="false" default_value="5" /> 
  <UserPref name="milesRadius" display_name="Miles Radius (max 9.0)" datatype="string" required="false" default_value="5" /> 
  <UserPref name="sortBy" display_name="Sort By:" datatype="enum" default_value="2">
  <EnumValue value="2" display_value="Regular Price" /> 
  <EnumValue value="3" display_value="Plus Price" /> 
  <EnumValue value="4" display_value="Premium Price" /> 
  <EnumValue value="5" display_value="Diesel Price" /> 
  <EnumValue value="99" display_value="Miles" /> 
  </UserPref>
  <Content type="html">
   
 <![CDATA[ 
<script type="text/javascript"><!--
google_ad_client = "pub-6006082808733900";
/* 234x60 */
google_ad_slot = "8371662828";
google_ad_width = 234;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>

<div id="content_div"></div>
<script type="text/javascript">
<!--
  // Get userprefs
var prefs = new _IG_Prefs();
var zipcode = prefs.getString("zipcode");
var showRegular = prefs.getBool("showRegular");
var showPlus = prefs.getBool("showPlus");
var showPremium = prefs.getBool("showPremium");
var showDiesel = prefs.getBool("showDiesel");
var stationCount = prefs.getInt("stationCount");
var milesRadius = parseFloat(prefs.getString("milesRadius"));
var sortBy = prefs.getInt("sortBy");
function DisplayToGadget(gasStations) {
  var htmlToOutput = "";
  htmlToOutput += "<table style='padding:0; margin:0; width:100%; text-align:center; background-color:#00FF80; '>";
  if (gasStations.length == 0) {
    htmlToOutput += "<caption style='width: 100%; font-size:1em; background-color:#00FF80; font-weight:bold; font-family:Verdana;'>Sorry, no gas prices could be found in ZipCode " + zipcode + ". Please try another zip code.</caption>";
  } else {
    htmlToOutput += "<caption style='font-size:1em; background-color:#00FF80; font-weight:bold; font-family:Verdana;'>Lowest Gas Prices In ZipCode "+ zipcode +" </caption>";
    htmlToOutput += "<thead style='font-size:.6em; font-family:Verdana;'><tr>";
    htmlToOutput += "<th style='width:10%'>Station/Brand</th>";
    htmlToOutput += "<th style='width:40%'>Address</th>";
    if (showRegular)
      htmlToOutput += "<th>Regular</th>";
    if (showPlus)
      htmlToOutput += "<th>Plus</th>";
    if (showPremium)
      htmlToOutput += "<th>Premium</th>";
    if (showDiesel)
      htmlToOutput += "<th>Diesel</th>";
    htmlToOutput += "</tr></thead><tbody style='font-size:.6em; font-family:Verdana;'>";
    //start loop to go through each of the gas stations
    for (var j = 0; j < Math.min(stationCount, gasStations.length); j++) {
      if (gasStations[j] == undefined)
        continue;
    
      //starts a new row for the gas stations to be displayed
      //first column of the table is the brand and station name
      htmlToOutput += "<tr>"
      htmlToOutput += "<td style='background-color:#FFFFFF; text-align:left;'><div style='font-weight:bold'>";
      htmlToOutput += gasStations[j].brand;
      htmlToOutput += "</div><div>"
      htmlToOutput += parseFloat(gasStations[j].distance).toFixed(2);
      htmlToOutput += " miles</div></td>";
      htmlToOutput += "<td style='background-color:#FFFFFF; text-align:left;'>";
      htmlToOutput += "<address><a href='http://maps.google.com/?q=";
      htmlToOutput += gasStations[j].address.DisplayStreetAddress() + ", " + gasStations[j].address.DisplayRestOfAddress();
      htmlToOutput += "' target='_blank'>";
      htmlToOutput += gasStations[j].address.DisplayStreetAddress() + "\n";
      htmlToOutput += gasStations[j].address.DisplayRestOfAddress();
      htmlToOutput += "</a></address></td>";
      if (showRegular) {
        //display the regular gas price
        htmlToOutput += "<td style='background-color:#FFFFFF; text-align:center;'>";
        if (gasStations[j].regularPrice != 9999) {
          htmlToOutput += "<div style='font-weight:bold'>";
          htmlToOutput += formatPrice(gasStations[j].regularPrice);
          htmlToOutput += "</div><div>";
          htmlToOutput += formatDate(gasStations[j].regularDate);
          htmlToOutput += "</div>";
        } else {
          htmlToOutput += "--";
        }
        htmlToOutput += "</td>";
      }
      if (showPlus) {
        //display the plus prices
        htmlToOutput += "<td style='background-color:#FFFFFF; text-align:center;'>";
        if (gasStations[j].plusPrice != 9999) {
          htmlToOutput += "<div style='font-weight:bold'>";
          htmlToOutput += formatPrice(gasStations[j].plusPrice);
          htmlToOutput += "</div><div>";
          htmlToOutput += formatDate(gasStations[j].plusDate);
          htmlToOutput += "</div>";
        } else {
          htmlToOutput += "--";
        }
        htmlToOutput += "</td>";
      }
      if (showPremium) {
        //display the premium prices
        htmlToOutput += "<td style='background-color:#FFFFFF; text-align:center;'>";
        if (gasStations[j].premiumPrice != 9999) {
          htmlToOutput += "<div style='font-weight:bold'>";
          htmlToOutput += formatPrice(gasStations[j].premiumPrice);
          htmlToOutput += "</div><div>";
          htmlToOutput += formatDate(gasStations[j].premiumDate);
          htmlToOutput += "</div>";
        } else {
          htmlToOutput += "--";
        }
        htmlToOutput += "</td>";
      }
      if (showDiesel) {
        //display the diesel prices
        htmlToOutput += "<td style='background-color:#FFFFFF; text-align:center;'>";
        if (gasStations[j].dieselPrice != 9999) {
          htmlToOutput += "<div style='font-weight:bold'>";
          htmlToOutput += formatPrice(gasStations[j].dieselPrice);
          htmlToOutput += "</div><div>";
          htmlToOutput += formatDate(gasStations[j].dieselDate);
          htmlToOutput += "</div>";
        } else {
          htmlToOutput += "--";
        }
        htmlToOutput += "</td>";
      }
      htmlToOutput += "</tr>";
    }
  }
  htmlToOutput += "</tbody></table>";
  return htmlToOutput;
        _IG_AdjustIFrameHeight();
}
function formatPrice(price) {
  var tempPrice = price + "";

  while (tempPrice.length < 4)
    tempPrice += "0";
  return tempPrice
}
function formatDate(date) {
  return (date.getMonth() + 1) + "/" + date.getDate() + "/" + date.getFullYear();
}
function Address() {
  function DisplayStreetAddress() {
    return (this.street);
  }
  function DisplayRestOfAddress() {
    return (this.city + ", " + this.state + " " + this.zip);
  }
  this.street = "";
  this.city = "";
  this.state = "";
  this.zip = 00000;
  this.DisplayStreetAddress = DisplayStreetAddress;
  this.DisplayRestOfAddress = DisplayRestOfAddress;
}
function GasStation() {
  this.brand = "";
  this.distance = 0.0;
  this.address = new Address();
  this.regularPrice = 0;
  this.regularDate = new Date();
  this.plusPrice = 0;
  this.plusDate = new Date();
  this.premiumPrice = 0;
  this.premiumDate = new Date();
  this.dieselPrice = 0;
  this.dieselDate = new Date();
}
function sortStations(a, b) {
  switch (sortBy) {
    case 3:
      return a.plusPrice - b.plusPrice;
    case 4:
      return a.premiumPrice - b.premiumPrice;
    case 5:
      return a.dieselPrice - b.dieselPrice;
    case 99:
      return a.distance - b.distance;
    default:
      return a.regularPrice - b.regularPrice;
  }
}
var url = "http://www.motortrend.com/widgetrss/gas-prices-" + zipcode + ".xml";
//var url = _IG_GetCachedUrl("http://www.motortrend.com/widgetrss/gas-prices-" + zipcode + ".xml");
var key1 = parseInt(zipcode.charAt(0)) * 100 + parseInt(zipcode.charAt(4)) * 10 + parseInt(zipcode.charAt(2));
var key2 = parseInt(zipcode.charAt(2)) * 100 + parseInt(zipcode.charAt(3)) * 10 + parseInt(zipcode.charAt(1));
function decodePrice(encodedPrice) {
  var price = "";
  if (encodedPrice.charAt(0) == "Z") {
    price = "-";
    encodedPrice = encodedPrice.substring(1);
  }
  for (x = 0; x < encodedPrice.length; x++) {
    if (encodedPrice.charCodeAt(x) == 32)
      break;

    price += encodedPrice.charCodeAt(x) - parseInt(zipcode.charAt(1)) % 6 - 65;
  }
  return (price / key1 + key2) / 100;
}
function getGasStations(feed) {
  if (feed == null) {
    alert("There is no data.")
    return;
  }
  var gasStations = new Array(feed.Entry == undefined ? 0 : feed.Entry.length);
  var count = 0;

  if (feed.Entry != undefined) {
    for (i = 0; i < feed.Entry.length; i++) {
      var entry = feed.Entry[i];
      var title = entry.Title;
      var description = entry.Summary;
      var station = title.substring(0, title.indexOf(" "));
      var address = title.substring(title.indexOf(" ") + 1, title.indexOf(" (")); // 5 space delimiter
      var distance = parseFloat(title.substring(title.indexOf(" (") + 2, title.lastIndexOf(" m")));
      var gas = description.split("\t");
      var regular = gas[0].substring(gas[0].indexOf(": ") + 2);
      var plus = gas[1].substring(gas[1].indexOf(": ") + 2);
      var premium = gas[2].substring(gas[2].indexOf(": ") + 2);
      var diesel = gas[3].substring(gas[3].indexOf(": ") + 2);
      var gasStation = new GasStation();
      gasStation.brand = station;
      gasStation.distance = distance;
      if (regular != "N/A")
        gasStation.regularPrice = decodePrice(regular);
      else
        gasStation.regularPrice = 9999;
      gasStation.regularDate = new Date(entry.Date * 1000);
      if (plus != "N/A")
        gasStation.plusPrice = decodePrice(plus);
      else
        gasStation.plusPrice = 9999;
      gasStation.plusDate = new Date(entry.Date * 1000);
      if (premium != "N/A")
        gasStation.premiumPrice = decodePrice(premium);
      else
        gasStation.premiumPrice = 9999;
      gasStation.premiumDate = new Date(entry.Date * 1000);
      if (diesel != "N/A")
        gasStation.dieselPrice = decodePrice(diesel);
      else
        gasStation.dieselPrice = 9999;
      gasStation.dieselDate = new Date(entry.Date * 1000);
      gasStation.address.street = address.substring(0, address.indexOf(","));
      var temp = address.substring(address.indexOf(",") + 2);
      var firstBreak = temp.indexOf(",");
      gasStation.address.city = temp.substring(0, firstBreak);
      gasStation.address.state = temp.substring(firstBreak + 2, firstBreak + 4);
      gasStation.address.zip = temp.substring(firstBreak + 5);

      var gasTotal = 0;
      if (showRegular && gasStation.regularPrice != 9999)
        gasTotal += gasStation.regularPrice;
      if (showPlus && gasStation.plusPrice != 9999)
        gasTotal += gasStation.plusPrice;
      if (showPremium && gasStation.premiumPrice != 9999)
        gasTotal += gasStation.premiumPrice;
      if (showDiesel && gasStation.dieselPrice != 9999)
        gasTotal += gasStation.dieselPrice;
      if (gasTotal > 0 && gasStation.distance <= milesRadius)
        gasStations[count++] = gasStation;
    }
  }
  gasStations.sort(sortStations);
  var html = DisplayToGadget(gasStations);
  _gel("content_div").innerHTML = html;
}
_IG_FetchFeedAsJSON(url, getGasStations, 50, true);
// -->
</script>
<script type="text/javascript">
var sc_project=6113252; 
var sc_invisible=1; 
var sc_security="2bfdacbf"; 
</script>
<script type="text/javascript"
src="http://www.statcounter.com/counter/counter.js"></script><noscript><div
class="statcounter"><a title="drupal analytics"
href="http://www.statcounter.com/drupal/"
target="_blank"><img class="statcounter"
src="http://c.statcounter.com/6113252/0/2bfdacbf/1/"
alt="drupal analytics" ></a></div></noscript>

  ]]> 
    
  </Content>
 </Module>
