<search function="curr">
  <name>Currency Conversion</name>
  <description>
    Convert from one currency to another using the Universal Currency Converter.<br/>
    <div class="helpboxDescLabels">Usage:</div>
  <table class="helpboxDescTable">
  <tr><td>curr /from:&lt;<i>curr1</i>&gt; /to:&lt;<i>curr2</i>&gt; &lt;<i>amount</i>&gt;</td></tr>
   </table>
    <div class="helpboxDescLabels">Example:</div>
    <table class="helpboxDescTable">
  <tr><td>curr /from:usd /to:gbp 100</td></tr>
  </table>
  </description>
  <category>Travel</category>
  <link>http://www.xe.com/ucc/</link>
  <contributor>Monty Scroggins, Neel Doshi</contributor>
  
  <form name="currf"
    action="http://www.xe.com/ucc/convert.cgi"
    method="post">
    <input type="hidden" name="Amount" value="" />
    <input type="hidden" name="From" value="" />
    <input type="hidden" name="To" value="" />
  </form>
  
  <script><![CDATA[
  currency_regex = /^\s*(\.(\d+)|(\d+(\.\d*)?))(\s*)([A-Za-z]{3})\s*([<>]|to)\s*([A-Za-z]{3})\s*$/i; 
  
  // the auto-detection routine used for special handling of strings entered into the
  // toolbar that look like currency conversions.
  function autodetect_currency(q)
  {
    // detect strings that look like ABC<CBA or ABC>CBA upper or lower case
    var res = q.match(currency_regex);
    if (res) 
    {
      curr2(q);
      return true;
    }
  }
  
  function curr2(q)
  {
    if( nullArgs("curr", q) )
      return false;

    // detect strings that look like ABC<CBA or ABC>CBA upper or lower case
    var res = q.match(currency_regex);
    if (res) 
    {
      if (res[7] == '<') 
      {
        document.currf.From.value=res[8].toUpperCase();
        document.currf.To.value=res[6].toUpperCase();
      }
      else
      {
        document.currf.From.value=res[6].toUpperCase();
        document.currf.To.value=res[8].toUpperCase();
      }
      document.currf.Amount.value=res[1];
      submitForm(currf);
    }
  }
  
  function curr(q)
  {
    if ( nullArgs("curr", q) )
      return false;
  
    var func_name = "curr";
    var switch_list = new Array("from", "to");
    var args = parseArgs(q, switch_list);
  
    // check if the required switches are set
    for (var j = 0; j < switch_list.length; j++)
    {
      if (typeof args.switch_val[switch_list[j]] == "undefined" || args.switch_val[switch_list[j]] == "")
      {
        alert(func_name + ":  /" + switch_list[j] + " switch must be entered.  Type '" + func_name + " ?' to see instructions");
        return false;
      }
    }
  
    currf.Amount.value = args.q;
    currf.From.value = args.switch_val["from"].toUpperCase();
    currf.To.value = args.switch_val["to"].toUpperCase();
    submitForm(currf);
    return true;
  }
  ]]></script>

  <copyright>
	Copyright (c) 2002 David Bau
	Distributed under the terms of the
	GNU Public License, Version 2 (http://www.gnu.org/copyleft/gpl.txt)
  </copyright>
</search>
