/**
 * Genworth Header Forms
 *
 * The GenworthHeaderForms.js is a collection of JavaScript methods used by the 
 * Country Select and Search Forms located in the header of pages in the 
 * Gewnworth.com domain.
 *
 * @author Genworth Financial, Inc.
 * @created 19 April 2007 
 * @since 19 April 2007
 * @version 1.0
 * @modified 19 April 2007 : Birth
 */

/* ===== COUNTRY SELECTOR ===== */
/**
 * public initCountrySelector method
 */
  /* void */ function initCountrySelector ()
  {
    /*String*/    var loc = window.location.href;
    /*SelectOne*/ var sel = document.getElementById('countrySelector');
    for (/*int*/ var i=1; i<sel.length; i++)
    {
      if (loc.indexOf(sel.options[i].value) == 0)
      {
        sel[i].selected = true;
        break;
      }
    }
  }

/**
 * public submitGatewayCountrySelect method
 */
  /*void*/ function submitGatewayCountrySelect ()
  {
    /*Checkbox*/  var cb = document.getElementById('remember');
    submitCountrySelect(cb.checked);
  }


/**
 * public submitCountrySelect method
 */
  /*void*/ function submitCountrySelect (/*boolean*/ writeCookie)
  {
    /*SelectOne*/ var sel = document.getElementById('countrySelector');
    /*int*/       var sid = sel.selectedIndex;
    //sel.selectedIndex = 0;
    if (sid < 1) { alert ('Please select a Country.'); return; }

    /*String[]*/  var csa = _parseSelectValue(sel[sid].value);
    if (window.location.href.indexOf(csa[0]) == 0) { return; }
    if (writeCookie) { CookieFactory.createCookie('country', encode(csa[0]), 365); }
    window.location.href=csa[0];
  }

/**
 * private parseSelectValue method
 *
 * @param val The value from the countrySelector
 * @return String[] The array of values parsed from the val<br>
 *          0: The URL
 *          1: The QueryString
 *          2: Mapping value for Flash Map
 */
  /*String[]*/ function _parseSelectValue (/*String*/ val)
  {
    /*String*/    var va = new Array();
    /*String[]*/  var ar1 = val.split( "|" );
    /*String[]*/  var ar2 = ar1[0].split("?");
    va[0] = ar2[0];
    va[1] = ar2[1];
    va[2] = ar1[1];
    return va;
  }

/**
 * public resetCountrySelector method
 */
  /*void*/ function resetCountrySelector ()
  {
    /*SelectOne*/ var sel = document.getElementById('countrySelector');
    sel.selectedIndex = 0;
  }


/* ===== SEARCH FORM ===== */
/**
 * public submitSearchForm method
 */
  /*void*/ function submitSearchForm ()
  {
    /*TextBox*/ var sb = document.getElementById('search_text');
    if (!sb.value || sb.value.match(/^\s*$/) || sb.value == 'Search')
    { 
      alert('Please enter your search criteria.');
      return;
    }
    document.searchForm.q.value=sb.value;  
    document.searchForm.submit();   
  }
