// START V1.14 (last changed V1.13) norpricesupport.js 
var havealtprice = false;
var allcookies = document.cookie;		// if favourite currency set then use it
var pos = allcookies.indexOf('destcurr=');
if ( pos != -1 )
    {
    var start = pos + 9;
    var end = allcookies.indexOf(';', start);
    if ( end == -1 ) end = allcookies.length;
    var value = unescape(allcookies.substring(start,end));
    var bits = value.split(':');
    var isoname = bits[0];
    var base = bits[1];
    var dest = bits[2];
    var exchange = base / dest;
    var cgibase = cgiurl.replace(/(.*:\/\/)(.*\/).*/, "$2");
    if ( (isoname != hidemain) && (isoname != hidealt) && (dest > 0) 
      && (location.href.indexOf(cgibase + 'bb') == -1) 
      && (location.href.indexOf(cgibase + 'ca') == -1) ) havealtprice = true;
    }

function topounds(nPounds)		// necessary as some browsers still don't support toFixed()
  {
  var nWholeCurrency, nFraction, sFraction;
  var sign = '';
  if ( nPounds < 0 )
    {
    nPounds = Math.abs(nPounds);
    sign = '-';
    } 
  nWholeCurrency = Math.floor(nPounds);                		// no of pounds
  nFraction = Math.round((nPounds - nWholeCurrency) * 100);  	// Number of Fraction (2 decimal places)
  if ( nFraction > 99 ) nFraction = 99;
  if (nFraction < 10)                                  		// Needs to be two digits
    {
    sFraction = "0" + nFraction.toString();            		// Pad with leading zero
    }
  else
    {                                                 		// Already has two digits
    sFraction = nFraction.toString();                  		// So just format it
    }
  return(sign + nWholeCurrency.toString() + '.' + sFraction);
  }

function showalt(price){
if ( havealtprice )
 {
 document.write(getalt(price, true)); // show a formatted price
 }  
}

function getalt(price, formatted){	// return converted price with optional HTML formatting
 var prefix = formatted ? '<span class="altprice">' : '';  // see if we want HTML formatting
 var suffix = formatted ? '</span>' : '';                  //    or just plain text
 var optplus = price.match(/\+/) ? '+' : '';	// remember if leading "+"
 price = price.replace(/&#44;/g,"");     	// remove all commas
 price = price.replace(/&#46;/g,".");    	// restore decimal point
 var pbits = price.match(/(-?\d+\.\d\d)/);	// now look for first [-]n.nn 
 if ( pbits != null )
   { 
   var numprice = pbits[1];
   var altprice = numprice * exchange;
   if ( exchange > hidefraction )
     {
     return prefix + ' (' + optplus + Math.round(altprice) + ' ' + isoname + ')' + suffix;
     }
   else
     {
     return prefix + ' (' + optplus + topounds(altprice) + ' ' + isoname + ')' + suffix;
     }
   }
 return ' --- ';  // should never get here but just in case...
}

// now code to deal with prices embedded in choice description
var selcode;
var pattern = new RegExp('(.*)(' + mainsymbol + ')(\\d+\\.\\d\\d)(.*)');	// match for e.g. £12.34

function cnvtext(text, formatted){
  if ( ! havealtprice ) return text;
  //
  // this routine could be changed to allow for different ways of including the option price.
  //
  var val = text.match(/(.*)\((.*)\)(.*)/);		// have we a "(" and ")" in the text?
  if ( val != null )
    {
    var thisval = val[2];				// extract the value
    thisval = thisval.replace(/[^-\d\.\+]/g,"");	// remove everything but digits, +, - and . 
    if ( isNaN(thisval) ) return text;			// ignore invalid numbers
    return val[1] + '(' + val[2] + ')' + getalt(thisval, formatted) + val[3];	// return potentially converted text
    }
  else
    {
    val = text.match(pattern);				// have we currency symbol then n.nn
    if ( val != null )
      {
      var sign = ''
      var spos = val[1].match(/([-\+])$/);		// see if there was a + or -
      if ( spos != null ) sign = spos[1];
      var thisval = sign + val[3];			// create the optionally signed value
      if ( isNaN(thisval) ) return text;		// ignore invalid numbers
      return val[1] + val[2] + val[3] + getalt(thisval, formatted) + val[4];	// return potentially converted text
      }
    return text;					// return unaltered text
    }
}

function xcheck(text){		// for CHECKBOX and RADIO items
  document.write(cnvtext(text, true));
}

function xselstart(text){	// the <SELECT..>
  selcode = text;
}

function xoption(opt,text){	// each <OPTION>..
  selcode += opt + cnvtext(text, false) + '</option>';
}

function xselend(){		// the </SELECT>
  document.write(selcode + '</SELECT>');
}
// END V1.13 norpricesupport.js

