### Eclipse Workspace Patch 1.0
#P adsense
Index: adsense.module
===================================================================
RCS file: /cvs/drupal/contributions/modules/adsense/adsense.module,v
retrieving revision 1.61
diff -u -r1.61 adsense.module
--- adsense.module	7 Jul 2007 18:00:32 -0000	1.61
+++ adsense.module	17 Jul 2007 19:54:24 -0000
@@ -20,29 +20,31 @@
  */
 function adsense_ad_formats() {
   return array (
-    '120x90'  =>  array('type' => ADSENSE_TYPE_LINK, 'desc' => t('Ad links 4-links 120x90'),      'code' => '_0ads_al'),
-    '120x240' =>  array('type' => ADSENSE_TYPE_AD,   'desc' => t('Vertical banner'),              'code' => '_as'),
-    '120x600' =>  array('type' => ADSENSE_TYPE_AD,   'desc' => t('Skyscraper'),                   'code' => '_as'),
-    '125x125' =>  array('type' => ADSENSE_TYPE_AD,   'desc' => t('Button'),                       'code' => '_as'),
-    '160x90'  =>  array('type' => ADSENSE_TYPE_LINK, 'desc' => t('Ad links 4-links 160x90'),      'code' => '_0ads_al'),
-    '160x600' =>  array('type' => ADSENSE_TYPE_AD,   'desc' => t('Wide skyscraper'),              'code' => '_as'),
-    '180x90'  =>  array('type' => ADSENSE_TYPE_LINK, 'desc' => t('Ad links 4-links 180x90'),      'code' => '_0ads_al'),
-    '180x150' =>  array('type' => ADSENSE_TYPE_AD,   'desc' => t('Small rectangle'),              'code' => '_as'),
-    '200x200' =>  array('type' => ADSENSE_TYPE_AD,   'desc' => t('Small square'),                 'code' => '_as'),
-    '234x60'  =>  array('type' => ADSENSE_TYPE_AD,   'desc' => t('Half banner'),                  'code' => '_as'),
-    '250x250' =>  array('type' => ADSENSE_TYPE_AD,   'desc' => t('Square'),                       'code' => '_as'),
-    '300x250' =>  array('type' => ADSENSE_TYPE_AD,   'desc' => t('Medium rectangle'),             'code' => '_as'),
-    '336x280' =>  array('type' => ADSENSE_TYPE_AD,   'desc' => t('Large rectangle'),              'code' => '_as'),
-    '468x15'  =>  array('type' => ADSENSE_TYPE_LINK, 'desc' => t('Banner ad links 4-links'),      'code' => '_0ads_al'),
-    '468x60'  =>  array('type' => ADSENSE_TYPE_AD,   'desc' => t('Banner'),                       'code' => '_as'),
-    '728x15'  =>  array('type' => ADSENSE_TYPE_LINK, 'desc' => t('Wide banner ad links 4-links'), 'code' => '_0ads_al'),
-    '728x90'  =>  array('type' => ADSENSE_TYPE_AD,   'desc' => t('Leaderboard'),                  'code' => '_as')
+    '120x90'           =>  array('type' => ADSENSE_TYPE_LINK,   'desc' => t('Ad links 4-links 120x90'),      'code' => '_0ads_al'),
+    '120x240'          =>  array('type' => ADSENSE_TYPE_AD,     'desc' => t('Vertical banner'),              'code' => '_as'),
+    '120x600'          =>  array('type' => ADSENSE_TYPE_AD,     'desc' => t('Skyscraper'),                   'code' => '_as'),
+    '125x125'          =>  array('type' => ADSENSE_TYPE_AD,     'desc' => t('Button'),                       'code' => '_as'),
+    '160x90'           =>  array('type' => ADSENSE_TYPE_LINK,   'desc' => t('Ad links 4-links 160x90'),      'code' => '_0ads_al'),
+    '160x600'          =>  array('type' => ADSENSE_TYPE_AD,     'desc' => t('Wide skyscraper'),              'code' => '_as'),
+    '180x90'           =>  array('type' => ADSENSE_TYPE_LINK,   'desc' => t('Ad links 4-links 180x90'),      'code' => '_0ads_al'),
+    '180x150'          =>  array('type' => ADSENSE_TYPE_AD,     'desc' => t('Small rectangle'),              'code' => '_as'),
+    '200x200'          =>  array('type' => ADSENSE_TYPE_AD,     'desc' => t('Small square'),                 'code' => '_as'),
+    '234x60'           =>  array('type' => ADSENSE_TYPE_AD,     'desc' => t('Half banner'),                  'code' => '_as'),
+    '250x250'          =>  array('type' => ADSENSE_TYPE_AD,     'desc' => t('Square'),                       'code' => '_as'),
+    '300x250'          =>  array('type' => ADSENSE_TYPE_AD,     'desc' => t('Medium rectangle'),             'code' => '_as'),
+    '336x280'          =>  array('type' => ADSENSE_TYPE_AD,     'desc' => t('Large rectangle'),              'code' => '_as'),
+    '468x15'           =>  array('type' => ADSENSE_TYPE_LINK,   'desc' => t('Banner ad links 4-links'),      'code' => '_0ads_al'),
+    '468x60'           =>  array('type' => ADSENSE_TYPE_AD,     'desc' => t('Banner'),                       'code' => '_as'),
+    '728x15'           =>  array('type' => ADSENSE_TYPE_LINK,   'desc' => t('Wide banner ad links 4-links'), 'code' => '_0ads_al'),
+    '728x90'           =>  array('type' => ADSENSE_TYPE_AD,     'desc' => t('Leaderboard'),                  'code' => '_as'),
+    ADSENSE_SEARCH_BOX =>  array('type' => ADSENSE_TYPE_SEARCH, 'desc' => t('AdSense for Search'),                  'code' => '')
     );
 }
 
 // Ad types, link or ad
 define('ADSENSE_TYPE_LINK',                   1);
 define('ADSENSE_TYPE_AD',                     2);
+define('ADSENSE_TYPE_SEARCH',                 3);
 
 define('ADSENSE_MAX_GROUPS',                  5);
 define('ADSENSE_MAX_CHANNELS',                10);
@@ -75,6 +77,22 @@
 define('ADSENSE_SECTION_IGNORE',              '<!-- google_ad_section_start(weight=ignore) -->');
 define('ADSENSE_SECTION_END',                 '<!-- google_ad_section_end -->');
 
+define('ADSENSE_SEARCH_RESULT_START',         '<!-- Google Search Result Snippet Starts -->');
+define('ADSENSE_SEARCH_RESULT_END',           '<!-- Google Search Result Snippet Ends -->');
+define('ADSENSE_SEARCH_COLOR_TEXT',           'adsense_search_color_text');
+define('ADSENSE_SEARCH_COLOR_BORDER',         'adsense_search_color_border');
+define('ADSENSE_SEARCH_COLOR_BG',             'adsense_search_color_bg');
+define('ADSENSE_SEARCH_COLOR_TITLE',          'adsense_search_color_title');
+define('ADSENSE_SEARCH_COLOR_URL',            'adsense_search_color_url');
+define('ADSENSE_SEARCH_COLOR_VISITED_URL',    'adsense_search_color_visited_url');
+define('ADSENSE_SEARCH_COLOR_LIGHT_URL',      'adsense_search_color_light_url');
+define('ADSENSE_SEARCH_DOMAIN',               'adsense_search_domain');
+define('ADSENSE_SEARCH_LANGUAGE',             'adsense_search_language');
+define('ADSENSE_SEARCH_COUNTRY',              'adsense_search_country');
+define('ADSENSE_SEARCH_TEXTBOX_LENGTH',       'adsense_search_textbox_length');
+define('ADSENSE_SEARCH_FRAME_WIDTH',          'adsense_search_frame_width');
+define('ADSENSE_SEARCH_BOX',                  'Search Box');
+
 function adsense_get_ad_code($format) {
   $all_ads = adsense_ad_formats();
   return $all_ads[$format]['code'];
@@ -143,6 +161,12 @@
        'type'     => MENU_CALLBACK,
       );
    }
+   $items[] = array(
+       'path'     => 'adsense/search',
+       'callback' => 'adsense_search',
+       'access'   => user_access('access adsense search result page'),
+       'type'     => MENU_CALLBACK,
+      );
    return $items;
 }
 
@@ -150,7 +174,7 @@
  * Implementation of hook_perm().
  */
 function adsense_perm() {
-  return array ('hide adsense', 'view clicks');
+  return array ('hide adsense', 'view clicks', 'access adsense search result page');
 }
 
 function adsense_admin_settings() {
@@ -294,6 +318,69 @@
     );
   }
 
+  $form['types_colors']['search'] = array(
+    '#type' => 'fieldset',
+    '#collapsible' => true,
+    '#collapsed' => true,
+    '#title' => t('AdSense for Search attributes'),
+  );
+
+  $form['types_colors']['search'][ADSENSE_SEARCH_COLOR_TEXT] = array(
+    '#type' => 'textfield',
+    '#title' => t('Text color'),
+    '#default_value' => variable_get(ADSENSE_SEARCH_COLOR_TEXT, '000000'),
+    '#size' => 6,
+    '#maxlength' => 6
+  );
+
+  $form['types_colors']['search'][ADSENSE_SEARCH_COLOR_BORDER] = array(
+    '#type' => 'textfield',
+    '#title' => t('Border color'),
+    '#default_value' => variable_get(ADSENSE_SEARCH_COLOR_BORDER, '336699'),
+    '#size' => 6,
+    '#maxlength' => 6
+  );
+
+  $form['types_colors']['search'][ADSENSE_SEARCH_COLOR_BG] = array(
+    '#type' => 'textfield',
+    '#title' => t('Background color'),
+    '#default_value' => variable_get(ADSENSE_SEARCH_COLOR_BG, 'FFFFFF'),
+    '#size' => 6,
+    '#maxlength' => 6
+  );
+
+  $form['types_colors']['search'][ADSENSE_SEARCH_COLOR_TITLE] = array(
+      '#type' => 'textfield',
+      '#title' => t('Title color'),
+      '#default_value' => variable_get(ADSENSE_SEARCH_COLOR_TITLE, '0000FF'),
+      '#size' => 6,
+      '#maxlength' => 6
+    );
+
+  $form['types_colors']['search'][ADSENSE_SEARCH_COLOR_URL] = array(
+    '#type' => 'textfield',
+    '#title' => t('URL color'),
+    '#default_value' => variable_get(ADSENSE_SEARCH_COLOR_URL, '008000'),
+    '#size' => 6,
+    '#maxlength' => 6
+  );
+
+  $form['types_colors']['search'][ADSENSE_SEARCH_COLOR_VISITED_URL] = array(
+    '#type' => 'textfield',
+    '#title' => t('Visited URL color'),
+    '#default_value' => variable_get(ADSENSE_SEARCH_COLOR_VISITED_URL, '663399'),
+    '#size' => 6,
+    '#maxlength' => 6
+  );
+
+  $form['types_colors']['search'][ADSENSE_SEARCH_COLOR_LIGHT_URL] = array(
+    '#type' => 'textfield',
+    '#title' => t('Light URL color'),
+    '#default_value' => variable_get(ADSENSE_SEARCH_COLOR_LIGHT_URL, '0000FF'),
+    '#size' => 6,
+    '#maxlength' => 6
+  );
+
   $form['channels'] = array(
     '#type' => 'fieldset',
     '#collapsible' => true,
@@ -457,6 +544,320 @@
     '#description' => t('This better targets Google ads to the teaser and body of nodes.'),
   );
 
+
+  $form['search'] = array(
+    '#type' => 'fieldset',
+    '#collapsible' => true,
+    '#collapsed' => true,
+    '#title' => t('AdSense Search')
+  );
+
+  global $base_url;
+  $form['search'][ADSENSE_SEARCH_DOMAIN] = array(
+    '#type' => 'textfield',
+    '#title' => t('URL for SiteSearch'),
+    '#default_value' => variable_get(ADSENSE_SEARCH_DOMAIN, $base_url),
+    '#size' => 255,
+    '#maxlength' => 255
+  );
+
+  $form['search'][ADSENSE_SEARCH_COUNTRY] = array(
+    '#type' => 'select',
+    '#title' => t('Country or territory for Google domain'),
+    '#default_value' => variable_get(ADSENSE_SEARCH_COUNTRY, 'www.google.com'),
+    '#options' => array('www.google.co.uk'  => t('United Kingdom'),
+                        'www.google.ca'     => t('Canada'),
+                        'www.google.de'     => t('Germany'),
+                        'www.google.co.jp'  => t('Japan'),
+                        'www.google.fr'     => t('France'),
+                        'www.google.com.au' => t('Australia'),
+                        'www.google.it'     => t('Italy'),
+                        'www.google.at'     => t('Austria'),
+                        'www.google.ch'     => t('Switzerland'),
+                        'www.google.es'     => t('Spain'),
+                        'www.google.nl'     => t('Netherlands'),
+                        'www.google.be'     => t('Belgium'),
+                        'www.google.dk'     => t('Denmark'),
+                        'www.google.se'     => t('Sweden'),
+                        'www.google.no'     => t('Norway'),
+                        'www.google.com.br' => t('Brazil'),
+                        'www.google.pt'     => t('Portugal'),
+                        'www.google.fi'     => t('Finland'),
+                        'www.google.co.kr'  => t('South Korea'),
+                        'www.google.cn'     => t('China'),
+                        'www.google.com.hk' => t('Hong Kong'),
+                        'www.google.com.tw' => t('Taiwan'),
+                        'www.google.com.sg' => t('Singapore'),
+                        'www.google.com.af' => t('Afghanistan'),
+                        'www.google.com'    => t('Albania'),
+                        'www.google.com'    => t('Algeria'),
+                        'www.google.as'     => t('American Samoa'),
+                        'www.google.com'    => t('Andorra'),
+                        'www.google.com'    => t('Angola'),
+                        'www.google.off.ai' => t('Anguilla'),
+                        'www.google.com'    => t('Antarctica'),
+                        'www.google.com.ag' => t('Antigua and Barbuda'),
+                        'www.google.com.ar' => t('Argentina'),
+                        'www.google.am'     => t('Armenia'),
+                        'www.google.com'    => t('Aruba'),
+                        'www.google.az'     => t('Azerbaijan'),
+                        'www.google.bs'     => t('Bahamas'),
+                        'www.google.com.bh' => t('Bahrain'),
+                        'www.google.com.bd' => t('Bangladesh'),
+                        'www.google.com'    => t('Barbados'),
+                        'www.google.com'    => t('Belarus'),
+                        'www.google.com.bz' => t('Belize'),
+                        'www.google.com'    => t('Benin'),
+                        'www.google.com'    => t('Bermuda'),
+                        'www.google.com'    => t('Bhutan'),
+                        'www.google.com.bo' => t('Bolivia'),
+                        'www.google.ba'     => t('Bosnia and Herzegovina'),
+                        'www.google.co.bw'  => t('Botswana'),
+                        'www.google.com'    => t('Bouvet Island'),
+                        'www.google.com'    => t('British Indian Ocean Territory'),
+                        'www.google.com.bn' => t('Brunei Darussalam'),
+                        'www.google.bg'     => t('Bulgaria'),
+                        'www.google.com'    => t('Burkina Faso'),
+                        'www.google.bi'     => t('Burundi'),
+                        'www.google.com.kh' => t('Cambodia'),
+                        'www.google.com'    => t('Cameroon'),
+                        'www.google.com'    => t('Cape Verde'),
+                        'www.google.com'    => t('Cayman Islands'),
+                        'www.google.com'    => t('Central African Republic'),
+                        'www.google.com'    => t('Chad'),
+                        'www.google.cl'     => t('Chile'),
+                        'www.google.com'    => t('Christmas Island'),
+                        'www.google.com'    => t('Cocos (Keeling) Islands'),
+                        'www.google.com.co' => t('Colombia'),
+                        'www.google.com'    => t('Comoros'),
+                        'www.google.cg'     => t('Congo'),
+                        'www.google.cd'     => t('Congo, Democratic Republic'),
+                        'www.google.co.ck'  => t('Cook Islands'),
+                        'www.google.co.cr'  => t('Costa Rica'),
+                        'www.google.ci'     => t('Cote d&#39;Ivoire'),
+                        'www.google.hr'     => t('Croatia'),
+                        'www.google.com.cu' => t('Cuba'),
+                        'www.google.com'    => t('Cyprus'),
+                        'www.google.cz'     => t('Czech Republic'),
+                        'www.google.dj'     => t('Djibouti'),
+                        'www.google.dm'     => t('Dominica'),
+                        'www.google.com.do' => t('Dominican Republic'),
+                        'www.google.tp'     => t('East Timor'),
+                        'www.google.com.ec' => t('Ecuador'),
+                        'www.google.com.eg' => t('Egypt'),
+                        'www.google.com.sv' => t('El Salvador'),
+                        'www.google.com'    => t('Equatorial Guinea'),
+                        'www.google.com'    => t('Eritrea'),
+                        'www.google.ee'     => t('Estonia'),
+                        'www.google.com.et' => t('Ethiopia'),
+                        'www.google.com'    => t('Falkland Islands (Malvinas)'),
+                        'www.google.com'    => t('Faroe Islands'),
+                        'www.google.com.fj' => t('Fiji'),
+                        'www.google.com'    => t('French Guiana'),
+                        'www.google.com'    => t('French Polynesia'),
+                        'www.google.com'    => t('French Southern Territories'),
+                        'www.google.com'    => t('Gabon'),
+                        'www.google.gm'     => t('Gambia'),
+                        'www.google.ge'     => t('Georgia'),
+                        'www.google.com'    => t('Ghana'),
+                        'www.google.com.gi' => t('Gibraltar'),
+                        'www.google.gr'     => t('Greece'),
+                        'www.google.gl'     => t('Greenland'),
+                        'www.google.com'    => t('Grenada'),
+                        'www.google.gp'     => t('Guadeloupe'),
+                        'www.google.com'    => t('Guam'),
+                        'www.google.com.gt' => t('Guatemala'),
+                        'www.google.com'    => t('Guinea'),
+                        'www.google.com'    => t('Guinea-Bissau'),
+                        'www.google.gy'     => t('Guyana'),
+                        'www.google.ht'     => t('Haiti'),
+                        'www.google.com'    => t('Heard and McDonald Islands'),
+                        'www.google.hn'     => t('Honduras'),
+                        'www.google.hu'     => t('Hungary'),
+                        'www.google.is'     => t('Iceland'),
+                        'www.google.co.in'  => t('India'),
+                        'www.google.co.id'  => t('Indonesia'),
+                        'www.google.com'    => t('Iran'),
+                        'www.google.com'    => t('Iraq'),
+                        'www.google.ie'     => t('Ireland'),
+                        'www.google.co.il'  => t('Israel'),
+                        'www.google.com.jm' => t('Jamaica'),
+                        'www.google.jo'     => t('Jordan'),
+                        'www.google.kz'     => t('Kazakhstan'),
+                        'www.google.co.ke'  => t('Kenya'),
+                        'www.google.ki'     => t('Kiribati'),
+                        'www.google.com'    => t('Kuwait'),
+                        'www.google.kg'     => t('Kyrgyzstan'),
+                        'www.google.la'     => t('Lao People&#39;s Democratic Republic'),
+                        'www.google.lv'     => t('Latvia'),
+                        'www.google.com'    => t('Lebanon'),
+                        'www.google.co.ls'  => t('Lesotho'),
+                        'www.google.com'    => t('Liberia'),
+                        'www.google.com.ly' => t('Libya'),
+                        'www.google.li'     => t('Liechtenstein'),
+                        'www.google.lt'     => t('Lithuania'),
+                        'www.google.lu'     => t('Luxembourg'),
+                        'www.google.com'    => t('Macau'),
+                        'www.google.com'    => t('Macedonia'),
+                        'www.google.com'    => t('Madagascar'),
+                        'www.google.mw'     => t('Malawi'),
+                        'www.google.com.my' => t('Malaysia'),
+                        'www.google.mv'     => t('Maldives'),
+                        'www.google.com'    => t('Mali'),
+                        'www.google.com.mt' => t('Malta'),
+                        'www.google.com'    => t('Marshall Islands'),
+                        'www.google.com'    => t('Martinique'),
+                        'www.google.com'    => t('Mauritania'),
+                        'www.google.mu'     => t('Mauritius'),
+                        'www.google.com'    => t('Mayotte'),
+                        'www.google.com.mx' => t('Mexico'),
+                        'www.google.fm'     => t('Micronesia'),
+                        'www.google.md'     => t('Moldova'),
+                        'www.google.com'    => t('Monaco'),
+                        'www.google.mn'     => t('Mongolia'),
+                        'www.google.ms'     => t('Montserrat'),
+                        'www.google.co.ma'  => t('Morocco'),
+                        'www.google.com'    => t('Mozambique'),
+                        'www.google.com'    => t('Myanmar'),
+                        'www.google.com.na' => t('Namibia'),
+                        'www.google.nr'     => t('Nauru'),
+                        'www.google.com.np' => t('Nepal'),
+                        'www.google.com'    => t('Netherlands Antilles'),
+                        'www.google.com'    => t('New Caledonia'),
+                        'www.google.co.nz'  => t('New Zealand'),
+                        'www.google.com.ni' => t('Nicaragua'),
+                        'www.google.com'    => t('Niger'),
+                        'www.google.com.ng' => t('Nigeria'),
+                        'www.google.nu'     => t('Niue'),
+                        'www.google.com.nf' => t('Norfolk Island'),
+                        'www.google.com'    => t('Northern Mariana Islands'),
+                        'www.google.com'    => t('North Korea'),
+                        'www.google.com.om' => t('Oman'),
+                        'www.google.com.pk' => t('Pakistan'),
+                        'www.google.com'    => t('Palau'),
+                        'www.google.com'    => t('Palestinian Territory'),
+                        'www.google.com.pa' => t('Panama'),
+                        'www.google.com'    => t('Papua New Guinea'),
+                        'www.google.com.py' => t('Paraguay'),
+                        'www.google.com.pe' => t('Peru'),
+                        'www.google.com.ph' => t('Philippines'),
+                        'www.google.pn'     => t('Pitcairn'),
+                        'www.google.pl'     => t('Poland'),
+                        'www.google.com.pr' => t('Puerto Rico'),
+                        'www.google.com.qa' => t('Qatar'),
+                        'www.google.com'    => t('Reunion'),
+                        'www.google.ro'     => t('Romania'),
+                        'www.google.ru'     => t('Russian Federation'),
+                        'www.google.rw'     => t('Rwanda'),
+                        'www.google.com'    => t('Saint Kitts and Nevis'),
+                        'www.google.com'    => t('Saint Lucia'),
+                        'www.google.com.vc' => t('Saint Vincent and the Grenadines'),
+                        'www.google.ws'     => t('Samoa'),
+                        'www.google.sm'     => t('San Marino'),
+                        'www.google.st'     => t('Sao Tome and Principe'),
+                        'www.google.com.sa' => t('Saudi Arabia'),
+                        'www.google.sn'     => t('Senegal'),
+                        'www.google.com'    => t('Serbia and Montenegro'),
+                        'www.google.sc'     => t('Seychelles'),
+                        'www.google.com'    => t('Sierra Leone'),
+                        'www.google.sk'     => t('Slovakia'),
+                        'www.google.si'     => t('Slovenia'),
+                        'www.google.com.sb' => t('Solomon Islands'),
+                        'www.google.com'    => t('Somalia'),
+                        'www.google.co.za'  => t('South Africa'),
+                        'www.google.com'    => t('South Georgia and The South Sandwich Islands'),
+                        'www.google.lk'     => t('Sri Lanka'),
+                        'www.google.sh'     => t('St. Helena'),
+                        'www.google.com'    => t('St. Pierre and Miquelon'),
+                        'www.google.com'    => t('Sudan'),
+                        'www.google.com'    => t('Suriname'),
+                        'www.google.com'    => t('Svalbard and Jan Mayen Islands'),
+                        'www.google.com'    => t('Swaziland'),
+                        'www.google.com'    => t('Syria'),
+                        'www.google.com.tj' => t('Tajikistan'),
+                        'www.google.com'    => t('Tanzania'),
+                        'www.google.co.th'  => t('Thailand'),
+                        'www.google.com'    => t('Togo'),
+                        'www.google.tk'     => t('Tokelau'),
+                        'www.google.to'     => t('Tonga'),
+                        'www.google.tt'     => t('Trinidad and Tobago'),
+                        'www.google.com'    => t('Tunisia'),
+                        'www.google.com.tr' => t('Turkey'),
+                        'www.google.tm'     => t('Turkmenistan'),
+                        'www.google.com'    => t('Turks and Caicos Islands'),
+                        'www.google.com'    => t('Tuvalu'),
+                        'www.google.co.ug'  => t('Uganda'),
+                        'www.google.com.ua' => t('Ukraine'),
+                        'www.google.ae'     => t('United Arab Emirates'),
+                        'www.google.com'    => t('United States Minor Outlying Islands'),
+                        'www.google.com.uy' => t('Uruguay'),
+                        'www.google.co.uz'  => t('Uzbekistan'),
+                        'www.google.vu'     => t('Vanuatu'),
+                        'www.google.com'    => t('Vatican'),
+                        'www.google.co.ve'  => t('Venezuela'),
+                        'www.google.com.vn' => t('Viet Nam'),
+                        'www.google.vg'     => t('Virgin Islands (British)'),
+                        'www.google.co.vi'  => t('Virgin Islands (U.S.)'),
+                        'www.google.com'    => t('Wallis and Futuna Islands'),
+                        'www.google.com'    => t('Western Sahara'),
+                        'www.google.com'    => t('Yemen'),
+                        'www.google.co.zm'  => t('Zambia'),
+                        'www.google.co.zw'  => t('Zimbabwe'),
+                        'www.google.com'    => t('United States'),
+                       )
+  );
+
+  $form['search'][ADSENSE_SEARCH_LANGUAGE] = array(
+    '#type' => 'select',
+    '#title' => t('Site Language'),
+    '#default_value' => variable_get(ADSENSE_SEARCH_LANGUAGE, 'en'),
+    '#options' => array('ar'    => t('Arabic'),
+                        'bg'    => t('Bulgarian'),
+                        'zh-CN' => t('Chinese (simplified)'),
+                        'zh-TW' => t('Chinese (traditional)'),
+                        'hr'    => t('Croatian'),
+                        'cs'    => t('Czech'),
+                        'da'    => t('Danish'),
+                        'nl'    => t('Dutch'),
+                        'en'    => t('English'),
+                        'fi'    => t('Finnish'),
+                        'fr'    => t('French'),
+                        'de'    => t('German'),
+                        'el'    => t('Greek'),
+                        'iw'    => t('Hebrew'),
+                        'hu'    => t('Hungarian'),
+                        'in'    => t('Indonesian'),
+                        'it'    => t('Italian'),
+                        'ja'    => t('Japanese'),
+                        'ko'    => t('Korean'),
+                        'no'    => t('Norwegian'),
+                        'pl'    => t('Polish'),
+                        'pt'    => t('Portuguese'),
+                        'ro'    => t('Romanian'),
+                        'ru'    => t('Russian'),
+                        'sk'    => t('Slovak'),
+                        'es'    => t('Spanish'),
+                        'sv'    => t('Swedish'),
+                        'tr'    => t('Turkish')
+                       )
+  );
+
+  $form['search'][ADSENSE_SEARCH_TEXTBOX_LENGTH] = array(
+    '#type' => 'textfield',
+    '#title' => t('Length of text box'),
+    '#default_value' => variable_get(ADSENSE_SEARCH_TEXTBOX_LENGTH, 15),
+    '#size' => 2,
+    '#maxlength' => 2
+  );
+
+  $form['search'][ADSENSE_SEARCH_FRAME_WIDTH] = array(
+    '#type' => 'textfield',
+    '#title' => t('Width of results area'),
+    '#default_value' => variable_get(ADSENSE_SEARCH_FRAME_WIDTH, 500),
+    '#size' => 3,
+    '#maxlength' => 3
+  );
+
   return system_settings_form($form);
 }
 
@@ -472,7 +873,9 @@
         if (_adsense_page_match()) {
           // Ad should be displayed
           // Check cache first
-          $ad = _adsense_get_ad($format, $group, $channel);
+          $ad = $format != ADSENSE_SEARCH_BOX
+              ? _adsense_get_ad($format, $group, $channel)
+              : _adsense_get_searchbox($group, $channel);
         }
         else {
           $ad = '<!--adsense: page not in match list-->';
@@ -704,13 +1107,18 @@
  */
 function _adsense_can_insert_another($format = '160x600') {
   static $num_ads = array(
-    ADSENSE_TYPE_AD   => 0,
-    ADSENSE_TYPE_LINK => 0,
+    ADSENSE_TYPE_AD     => 0,
+    ADSENSE_TYPE_LINK   => 0,
+    ADSENSE_TYPE_SEARCH => 0,
     );
 
   $ad_list = adsense_ad_formats();
   $type = $ad_list[$format]['type'];
-  if ($num_ads[$type] < 3) {
+  if ($num_ads[ADSENSE_TYPE_SEARCH] < 1) {
+    $num_ads[$type]++;
+    $ret = TRUE;
+  }
+  elseif ($num_ads[$type] < 3) {
     $num_ads[$type]++;
     $ret = TRUE;
   }
@@ -864,6 +1272,7 @@
       for($group=1; $group<ADSENSE_MAX_GROUPS+1; $group++) {
         $group_list[$group] = 'Group ' . $group;
       }
+      $group_list[$group] = ADSENSE_SEARCH_BOX;
 
       for($channel=1; $channel<ADSENSE_MAX_CHANNELS+1; $channel++) {
         $channel_list[$channel] = 'Channel ' . $channel;
@@ -1206,3 +1615,74 @@
   return l($title, $path);
 }
 
+function _adsense_get_searchbox($group = 1, $channel = 1) {
+
+  $group = _adsense_validate_group($group);
+
+  $client = adsense_get_client_id();
+
+  $border   = variable_get(ADSENSE_SEARCH_COLOR_BORDER,      '336699');
+  $title    = variable_get(ADSENSE_SEARCH_COLOR_TITLE,       '0000FF');
+  $bg       = variable_get(ADSENSE_SEARCH_COLOR_BG,          'FFFFFF');
+  $text     = variable_get(ADSENSE_SEARCH_COLOR_TEXT,        '000000');
+  $url      = variable_get(ADSENSE_SEARCH_COLOR_URL,         '008000');
+  $visited  = variable_get(ADSENSE_SEARCH_COLOR_VISITED_URL, '663399');
+  $light    = variable_get(ADSENSE_SEARCH_COLOR_LIGHT_URL,   '0000FF');
+
+  $channel  = variable_get(ADSENSE_AD_CHANNEL . _adsense_validate_channel($channel), '');
+
+  global $base_url;
+  $domain         = variable_get(ADSENSE_SEARCH_DOMAIN,         $base_url);
+  $language       = variable_get(ADSENSE_SEARCH_LANGUAGE,       'en');
+  $textbox_length = variable_get(ADSENSE_SEARCH_TEXTBOX_LENGTH, 15);
+
+  $output .= _adsense_add_nl('<form method="get" action="/adsense/search" target="_top" style="text-align:left;">');
+  $output .= _adsense_add_nl('<input type="hidden" name="domains" value="'    . $domain  . '"></input>');
+  $output .= _adsense_add_nl('<input type="text" name="as_q" size="'          . $textbox_length . '" maxlength="255" value="' . $_GET['as_q'] . '"></input>');
+  $output .= _adsense_add_nl('<input type="hidden" name="sitesearch" value="' . $domain  . '"></input>');
+  $output .= _adsense_add_nl('<input type="hidden" name="client" value="'     . $client  . '"></input>');
+  $output .= _adsense_add_nl('<input type="hidden" name="channel" value="'    . $channel . '"></input>');
+  $output .= _adsense_add_nl('<input type="hidden" name="forid" value="1"></input>' );
+  $output .= _adsense_add_nl('<input type="hidden" name="ie" value="UTF-8"></input>');
+  $output .= _adsense_add_nl('<input type="hidden" name="oe" value="UTF-8"></input>');
+  $output .= _adsense_add_nl('<input type="hidden" name="cof" value="GALT:'          . $url
+                                                                 . ';GL:1;DIV:'      . $border
+                                                                 . ';VLC:'           . $visited
+                                                                 . ';AH:center;BGC:' . $bg
+                                                                 . ';ALC:'           . $title
+                                                                 . ';LC:'            . $title
+                                                                 . ';T:'             . $text
+                                                                 . ';GFNT:'          . $light
+                                                                 . ';GIMP:'          . $light
+                                                                 . ';FORID:11"></input>');
+  $output .= _adsense_add_nl('<input type="hidden" name="hl" value="' . $language   . '"></input>');
+  $output .= _adsense_add_nl('<input type="submit" name="sa" value="' . t('Search') . '"></input>');
+  $output .= _adsense_add_nl('</form>');
+
+  return $output;
+}
+
+function adsense_search() {
+
+  global $base_url;
+  $width   = variable_get(ADSENSE_SEARCH_FRAME_WIDTH, '500');
+  $domain  = variable_get(ADSENSE_SEARCH_DOMAIN     , $base_url);
+  $country = variable_get(ADSENSE_SEARCH_COUNTRY    , 'www.google.com');
+
+
+  $output .= _adsense_add_nl(ADSENSE_SEARCH_RESULT_START);
+  $output .= _adsense_add_nl('<div id="googleSearchUnitIframe"></div>');
+
+  $output .= _adsense_add_nl('<script type="text/javascript">');
+  $output .= _adsense_add_nl('   var googleSearchIframeName = \'googleSearchUnitIframe\';');
+  $output .= _adsense_add_nl('   var googleSearchFrameWidth = ' . $width   . ';');
+  $output .= _adsense_add_nl('   var googleSearchFrameborder = 0 ;');
+  $output .= _adsense_add_nl('   var googleSearchDomain = \''   . $country . '\';');
+  $output .= _adsense_add_nl('</script>');
+  $output .= _adsense_add_nl('<script type="text/javascript"');
+  $output .= _adsense_add_nl('         src="http://www.google.com/afsonline/show_afs_search.js">');
+  $output .= _adsense_add_nl('</script>');
+  $output .= _adsense_add_nl(ADSENSE_SEARCH_RESULT_END);
+
+  return $output;
+}
