/* catalogue.js

catalogue functions moved from 4 files to this common script file, 4.3.05

  NormaliseValue() simplified 2.3.05

*/

function NormaliseValue(value) {
  if(value <= 0.9999) {
    Pounds='0';
   } 
   else {
    Pounds=parseInt(value);
  }
  if (value>0) {
    decPence=((value + 0.0049) - Pounds );
    Pence=parseInt(decPence*100);
    } 
  else {
    Pence=0;
       }
  if (eval(Pence) <= 9) {
  Pence='0'+Pence;
   }
    PriceString='£' + Pounds + '.' + Pence + '';
// alert(PriceString+"!");  //added to check operation <---
   return (PriceString);
}
// end of function NormaliseValue()

function AddItem(PlantName,Quantity,Price) { 
if(Quantity<=0)  { 
   rc = alert('Please enter a number');
     } 
   else { 
     Decimalprice=NormaliseValue(Price);
//     alert("Decimalprice = "  + Decimalprice);  //added to check operation <----------
     if (confirm('Add '+Quantity+' '+unescape(PlantName)+' @ '+Decimalprice+' to basket?')) {
       index=document.cookie.indexOf('thymus');
       countbegin=(document.cookie.indexOf('=',index)+1); countend=document.cookie.indexOf(';',index);
       if(countend==-1) {
                        countend=document.cookie.length;
                         } 
       document.cookie='thymus='+document.cookie.substring(countbegin,countend)+
       '['+PlantName+'|'+Quantity+'|'+Price+']; expires=Thu, 1 Jan 2015 00:00:00 UTC; path=/';
       cancelled=false;
     } 
    else { 
      cancelled=true
      }
  return(cancelled) 
  } 
} //end of function AddItem(Name, Qty, Price)

