// This script sends the data to dwb_search or to our keywords cgi program

function switch_scripts(searchForm) {
  if (searchForm.search_type[0].checked) {
    searchForm.action = "http://search.bellinghamherald.com/search-bin/search.pl.cgi";
    searchForm.method = "get";
    searchForm.product = 'pubsys';
    searchForm.collection = 'ENDECA_INDEX';
    searchForm.live_template = 'http://pubsys.bellinghamherald.com/237/index.html';
    searchForm.preview_template = 'http://preview.bellinghamherald.com/237/index.html';
    searchForm.fields = '*';
    searchForm.results_per_page = '25';
    searchForm.aggregate_key = 'meta_rollup';
    searchForm.sort = 'pubsys_story_print_publish_dt desc';
    searchForm.target = 'bellinghamherald';
    searchform.preview = '1';

    return(true);
  }
  else if (searchForm.search_type[1].checked) {
    searchForm.action = 'http://search.bellinghamherald.com/search-bin/search.pl.cgi';
    searchForm.product.value = 'Yahoo%2COverture';
    searchForm.collection.value = 'WEB';
    searchForm.live_template.value = 'http://pubsys.bellinghamherald.com/237/v-ysr/index.html'; 
    searchForm.preview_template.value = 'http://preview.bellinghamherald.com/237/v-ysr/index.html';
    searchForm.error_template.value = 'http://pubsys.bellinghamherald.com/237/v-yerr/index.html';
    searchForm.results_per_page.value = '10';
    searchForm.preview = '0';
    searchForm.sf_Keywords.value = searchForm.sf_pubsys_story.value;
    return true;
  }
  else {
    return(false);
  }
}

//Added for Yahoo.

function searchFormSubmit(form) {

     if (form.aff.value == 'archives' || form.aff[1].checked == true) {

         window.location = "http://www.newslibrary.com/nlsearch.asp?search_mode=all&action=search&date_mode=year&year=last+180+days&sort=d%3Ah&nitems=10&region=behb&dbquery=" + form.keywords.value;
             return false;

     }
     else if (form.aff[2].checked == true || form.aff.value == 'web') {
         var encoded_keywords = encodeURIComponent(form.keywords.value);
         var section_num = '237';
         var url_version = 'ysr';
         var params = 'product=Yahoo%2COverture&' +
                      'collection=WEB&' +
                      'live_template=http%3A%2F%2Fwww.bellinghamherald.com%2F' + section_num + '%2Fv-' + url_version + '%2Findex.html&' +
                      'error_template=http%3A%2F%2Fwww.bellinghamherald.com%2F' + section_num + '%2Fv-yerr%2Findex.html&' +
                      'preview_template=http%3A%2F%2Fpreview.bellinghamherald.com%2F' + section_num + '%2Fv-' + url_version + '%2Findex.html&' +
                      'results_per_page=10' +
		      '&prop_related=1&prop_dym=1';
         window.location = "http://search.bellinghamherald.com/search-bin/search.pl.cgi?sf_Keywords=" + encoded_keywords + '&' + params;

         return false;
     }

     return true;
 }

function getParams(params) {
   var Params = new Object ();
   if ( ! params ) return Params;
   var Pairs = params.split(/[;&]/);
   for ( var i = 0; i < Pairs.length; i++ ) {
      var KeyVal = Pairs[i].split('=');
      if ( ! KeyVal || KeyVal.length != 2 ) continue;
      var key = unescape( KeyVal[0] );
      var val = unescape( KeyVal[1] );
      val = val.replace(/\+/g, ' ');
      Params[key] = val;
   }
   return Params;
}

