var curConvCookieName = "convcurrency=";

function convCurChanged(el)
{
  var newValue = el.value;

  // Set all currency conversion fields to this currency
  setConvCurrency( newValue );

  // Store value in cookie
  var exp = new Date;
  exp.setFullYear( exp.getFullYear()+1 );
  document.cookie = curConvCookieName+newValue+";expires="+exp.toGMTString()+";path=/";
}

function setConvCurrency( newValue )
{
  var selects = document.getElementsByTagName('select');

  for ( var n=0; n<selects.length; n++ )
  {
    var sel = selects[n];
    if ( sel.className == 'cconv' || sel.getAttribute('class') == 'cconv' )
    {
      sel.value = newValue;
    }
  }
}

function initialiseCurConv()
{
  // If we haven't got any cookies, then don't do anything
  if ( document.cookie.length>0 )
  {
    var ccur_pos = document.cookie.indexOf( curConvCookieName );
    if ( ccur_pos != -1 )
    {
      ccur_pos += curConvCookieName.length;
      var ccur_end = document.cookie.indexOf( ";", ccur_pos );
      if ( ccur_end == -1 )
      {
        ccur_end = document.cookie.length;
      }
      var val = document.cookie.substring( ccur_pos, ccur_end );

      setConvCurrency( val );
    }
  }
}


