<?xml version="1.0" encoding="UTF-8" ?> 
<Module>
  <ModulePrefs title="Google Local Search"
  description="Quick Local Search right on your Google home page."
  author="Phillip Bogle"
  height="340"
  author_affiliation="Jobster"
  author_location="Seattle"
  author_email="philbogle+localsearch@gmail.com"
  title_url="http://local.google.com"
  screenshot="http://www.thebogles.com/google/localsearch.gif"
 /> 
  <UserPref name="home" display_name="Home Addr" required="true" datatype="location"/>
  <UserPref name="work" display_name="Work Addr" required="true" datatype="location"/>
   <Content type="html"> 
     <![CDATA[ 
<meta http-equiv="P3P" content='CP="IDC DSP COR CURa ADMa OUR IND PHY ONL COM STA"'>
<style>
 body { overflow: hidden; font-family:arial,sans-serif; font-size: 82%}

a.shortcut { text-decoration: none; }

a.shortcut em {
 font-style: normal;
 font-weight: normal;
  text-decoration: underline;
}

a.shortcut:hover {
}
</style>

<script>

// Cookie functions
function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
      return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break; 
  }
  return null;
}
function SetCookie (name,value,expires,path,domain,secure) {
  document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}

function DeleteCookie (name,path,domain) {
  if (GetCookie(name)) {
    document.cookie = name + "=" +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

function setDefaultLoc(loc)
{

    SetCookie("loc", loc, "Thu,31-Dec-2020 00:00:00 GMT")
    defaultLoc = prefs.getString(loc);
}
</script>

	      
<form method="get" action="javascript:doSearch()">
<input type="hidden" name="site" value="local">
<input type="hidden" name="dm" value="none">
<table style="width: 100%; padding: 2px; margin-top: 5px">
<tr> <td> <input style="width: 55%" name="q" id="q"> <input type="submit" id="submit" value="Search"> </td></tr>

<tr> <td>


<script>
var prefs = new _IG_Prefs(__MODULE_ID__);
var home = prefs.getString('home');
var work = prefs.getString('work');

locCookie = GetCookie("loc");
setDefaultLoc(locCookie ? locCookie : "home")

homeChecked = (defaultLoc != work) ? "checked" : ""
workChecked = (defaultLoc == work) ? "checked" : ""
document.write('<span title="Search near ' + home + '"><input accesskey="h" onfocus="form.q.focus(); form.q.select()" onclick="setDefaultLoc(\'home\');" type="radio" ' + homeChecked + ' name="near" value="' + home + '">&nbsp;<a class="shortcut" href="http://maps.google.com?z=2&near=' + escape(home) + '" target="_top"><em>H</em>ome</a></span>');
document.write('&nbsp;&nbsp;');
document.write('<span title="Search near ' + work + '"><input onfocus="form.q.focus(); form.q.select()" accesskey="w" onclick="setDefaultLoc(\'work\');" type="radio" ' + workChecked + ' name="near" value="' + work + '">&nbsp;<a class="shortcut" href="http://maps.google.com?z=2&near=' + escape(work) + '" target="_top"><em>W</em>ork</a></span>');


function doSearch()
{
    var params = 'q=' + document.getElementById('q').value + "&near=" + defaultLoc;
    url = 'http://www.google.com/xhtml?site=local&dm=none&' + params
    _gel('submit').disabled = true;
    _gel('q').select();
    _gel('results').innerHTML = '<br><em> Searching... </em>'
    _IG_FetchContent(url, function (r) {
	 // clean up the google response text a bit
	 r = r.substring(r.indexOf("A."));
	 r = r.substring(0, r.indexOf('<form method="get" action="/xhtml">'));
	 r = r.replace(/<\/div><div><br\/>/g, '<hr>')
	 r = r.replace(/[ ]?<br\/>/g, ", ");
	 r = r.replace(/ mi /g, "&nbsp;mi&nbsp;");
	 r = r.replace(/\) /g, ")&nbsp;");
	 r = r.replace(/<div\/?>/g, " ");
	 r = r.replace(/href="\/xhtml\?/g, 'target="_top" href="http://local.google.com?"');

	 endIndex = r.indexOf("E.");
	 if (endIndex) { 
	    r=r.substring(0, endIndex);
	 }			    

	 r = r.replace(/[A-Z][.]/g, "");

	 r += '<a target="_top" href="http://local.google.com?' + params + '"><b>&raquo; All Google Local Results</b></a>';
	 _gel('results').innerHTML = '<hr>' + r;
 	 _gel('submit').disabled = false;
     });
    }
    </script>
    <br>
    <div id="results" style="height: 300px; width: 100%; font-size: 82%">
	<span style="color: gray">
<br>
<ul>
<li>	Use this widget to quickly do local searches without leaving your Google home page.   <br> <br>
<li>	You can use the Alt-H or Alt-W keyboard shortcuts at any time to start searching near your home or work.  <br> <br>
<li>    Click on the home or work label to show a Google map of that location.
</ul>
    </div>

    </td> </tr>
    </table>
    </form>

    ]]> 
   </Content> 
</Module>
