/*
 * Webtown Media Directory Search Widget
 * Dimentions: 344px x 125px
 */
try{
  // Browser Sniff
  var gpw_isie6 = ((navigator.userAgent.indexOf("MSIE 6") != -1) && (navigator.userAgent.indexOf("Opera") == -1));

  // Quirks Mode Detect
  var gpw_qmode = true;
  if(document.compatMode) gpw_qmode=(document.compatMode =='BackCompat') ? true:false;

} catch(err) {
  try{console.log(err)}catch(err){};
}

try{
  var gpw_nurl = 'http://national.gopickle.com/';
  // Set a base CSS
  var gpw_cssBase = "display:inline; width:auto; height:auto; overflow:show; float:none; clear:none; border:0; outline:0; background:transparent none; padding:0; margin:0; color:inherit; font-size:inherit; color:#ffffcc; font-family:'Trebuchet MS',sans-serif; text-align:center; line-height:inherit; vertical-align:baseline; quotes:none; text-decoration:none; list-style:none; ";
  // Set a few important css rules for elementss
  var gpw_block = "display: block; clear:both; ";
  var gpw_dim = "width:344px; height:125px; ";
  var gpw_bak24 = gpw_isie6 ? "" : "background:url('http://national.gopickle.com/widgetassets/images/gpwidget_344x125_24bit.png') no-repeat 0 0; ";
  var gpw_bak8 = "background:url('http://national.gopickle.com/widgetassets/images/gpwidget_344x125_8bit.png') no-repeat 0 0; ";
  var gpw_h1strong = gpw_cssBase + "font-weight:bold; color:#fff; white-space:nowrap;";
  var gpw_li = gpw_cssBase + "font-size:11px; line-height:16px;";
  var gpw_lia = gpw_cssBase + "font-size:11px; line-height:16px; text-decoration:underline; color:#9dd8ff; margin:0 0.3em 0 0; white-space:nowrap; ";
  if (gpw_isie6) {
    var gpw_inputtext = ((gpw_qmode)?"width:223px; height:28px;":"width:210px; height:18px;")+" padding:4px 2px; margin:0 0 0 12px; color:#444; font-weight:bold; font-family:'Trebuchet MS',sans-serif; font-size:14px; line-height:16px; text-align:left; float:left;"
  } else {
    var gpw_inputtext = ((gpw_qmode)?"width:218px; height:28px;":"width:185px; height:18px;")+" padding:4px 2px 4px 28px; margin:0 0 0 12px; color:#444; font-weight:bold; font-family:'Trebuchet MS',sans-serif; font-size:14px; line-height:16px; text-align:left; float:left;"
  }

  for ( var gpwi=0; gpwi < document.getElementsByTagName('div').length; gpwi++ ) {
    var gpw = document.getElementsByTagName('div')[gpwi];
    if( gpw.className && ( gpw.className.indexOf('gpwidget_344x125') >= 0)){
      // Find the doimain_url and path_prefix
      var gpw_rurl = gpw.getAttribute('gp_rurl');
      var gpw_rname = gpw.getAttribute('gp_rname');
      var gpw_randomn = Math.ceil(Math.random() * 999999999999);
      gpwCat = [
        {'url':'/categories/212-Trophies','name':'Trophies'},
        {'url':'/categories/292-Nursing-Homes-and-Assisted-Living','name':'Nursing Homes'},
        {'url':'/categories/203-Discount-Stores','name':'Discount Stores'},
        {'url':'/categories/3-Movie-Theaters','name':'Movie Theaters'},
        {'url':'/categories/39-Used-Car-Dealers','name':'Used Cars'},
        {'url':'/categories/381-Churches','name':'Churches'},
        {'url':'/categories/332-Day-Spas','name':'Day Spas'},
        {'url':'/categories/296-Doctors','name':'Doctors'},
        {'url':'/categories/219-Fabric-and-Upholstery-Stores','name':'Fabric Stores'},
        {'url':'/categories/72-Marriage-Counselors','name':'Marriage Counselors'},
        {'url':'/categories/329-Massage-Parlors','name':'Massage'},
        {'url':'/categories/Mobile/426-Mobile-Home-Sales-and-Service','name':'Mobile Homes'},
        {'url':'/categories/170-Restaurants','name':'Restaurants'}
      ];

      gpw.style.cssText = gpw_cssBase + gpw_block + gpw_dim + "overflow:hidden; font-size:10px; line-height 12px;"
      
      var gpw_innerHTML  = '';
      gpw_innerHTML += '<div style="'+ gpw_cssBase + gpw_block + gpw_dim + gpw_bak24 +'">';
      gpw_innerHTML += '<div style="'+ gpw_cssBase + gpw_block + gpw_dim + gpw_bak8 +'">';
      gpw_innerHTML += '<div style="'+ gpw_cssBase + gpw_block +'height:42px; overflow:hidden;">';
      gpw_innerHTML += '<h1 style="'+ gpw_cssBase + gpw_block +'padding:14px 4px 0; font-size:18px; line-height: 18px;">';
      gpw_innerHTML += '<a href="'+ gpw_rurl +'" style="'+ gpw_cssBase + gpw_block +'text-decoration:none;"><strong style="'+gpw_h1strong+'">Search</strong> <strong style="'+gpw_h1strong+'">'+gpw_rname+'</strong> <strong style="'+gpw_h1strong+'">Yellow Pages</strong>';
      gpw_innerHTML += '</a></h1></div>';
      gpw_innerHTML += '<div style="'+ gpw_cssBase + gpw_block +'height:30px; padding:4px 12px 0 0;">';
      gpw_innerHTML += '<form action="'+gpw_rurl+'/search/prepare" method="post" style="'+ gpw_cssBase +'">';
      gpw_innerHTML += '<div>';
      if (!gpw_isie6) {
        gpw_innerHTML += '<div style="float:left; width:1px; height:28px; padding:0; margin:0; overflow:visible;">';
        gpw_innerHTML += '<label for="search_input' + gpw_randomn + '" style="display:block; position:absolute; width:44px; height:38px; padding:0; margin:-10px 0 0; background:url(http://national.gopickle.com/widgetassets/images/gpwidget_pointer.png) no-repeat top right;"></label>';
        gpw_innerHTML += '</div>';
      }
      //gpw_innerHTML += '<input name="search" style="width:213px; height:auto; padding:4px 2px; margin:1px 0 0 12px; color:#444; font-weight:bold; font-family:\'Trebuchet MS\',sans-serif; font-size:14px; line-height:16px; text-align:left; float:left; clear:none;" type="text" value="" />';

      gpw_innerHTML += '<input name="search" id="search_input'+gpw_randomn+'" style="'+gpw_inputtext+'" type="text" value="" />';

      gpw_innerHTML += '<input name="submit" style="width:90px; height:auto; padding:4px; margin:0; color:#000; font-weight:normal; font-family:sans-serif; font-size:12px; line-height:16px; text-align:center; float:right; clear:none;" type="submit" value="Search" />';
      gpw_innerHTML += '</div></form></div>';
      gpw_innerHTML += '<div style="'+ gpw_cssBase + gpw_block +'height:32px; line-height:12px; padding:4px 8px 0 12px; overflow:hidden;">';
      gpw_innerHTML += '<ul style="'+ gpw_cssBase +'">';
      gpw_innerHTML += '<li style="'+gpw_li+'font-weight:bold; margin:0 0.3em 0 0;">Top Searches </li>';
      while ( gpwCat.length >= 1 ) {
        var rand = Math.floor(Math.random()*gpwCat.length);
        gpw_innerHTML += '<li style="'+gpw_li+'"><a href="'+gpw_rurl+gpwCat[rand].url+'" style="'+gpw_lia+'">'+gpwCat[rand].name+'</a> </li>';
        gpwCat.splice(rand,1);
      }
      gpw_innerHTML += '<li style="'+gpw_li+'"><a href="'+gpw_rurl+'/categories/alpha" style="'+gpw_lia+'">More</a> </li>';
      gpw_innerHTML += '</ul></div>';
      gpw_innerHTML += '</div>';
      gpw_innerHTML += '</div>';
      
      gpw.innerHTML = gpw_innerHTML;
    }
  }
} catch(err) {
  try{console.log(err)}catch(err){};
}