
  function showData(cd,format,rate,lossless,hard,resultElementName) { 
  var rip, ripCost, arc, arcCost, disk, discount, tot, totCost, hardCost, dvd, hardtype  ;
  var cdName = document.getElementById('cdn');
  var cdaName = document.getElementById('cda');
  var ripName = document.getElementById('ripSpace');
  var arcName = document.getElementById('arcSpace');
  var totName = document.getElementById('totSpace');
  var hdName = document.getElementById('hardDisk');

  var ripC = document.getElementById('ripCost');
  var arcC = document.getElementById('arcCost');
  var totC = document.getElementById('totCost');
  var hdC = document.getElementById('hardCost');
  var discC = document.getElementById('Discount')
  var hdtype  = document.getElementById('hdType');
  var hdcost = document.getElementById('hdCost');
  
  hardCost = Number(hard.substring(0,3));
  hardtype = hard.substring(4,30);
  hdtype.innerHTML = hardtype;
  hdcost.innerHTML = "£ " + (hardCost).toFixed(2);
  //cd = document.xform.cdcount.value ;
  var cdcount = document.getElementById('cdcount') ;
  var elem = document.getElementById('cderror');
 
  cd = cdcount.value;
 
   // Ensure valid CD count
   var ageRE = /^[0-9]{1,3}$/
  if (!ageRE.test(cd)) {
    // msg (ifld, "error", "Error : CD count must be a number");  
    elem.innerHTML = "Error : CD Count must be a number between 25 and 300";
    cdcount.value = "";
    setfocus(cdcount);
    return false;
  }

  if ( (cd > 300) || (cd < 25) ) {
    // msg (ifld, "error", "Error : CD count must be between 25 and 300");  
    elem.innerHTML = "Error : CD Count must be between 25 and 300";
    cdcount.value = "";
    setfocus(cdcount);
    return false;
  }

    elem.innerHTML = "";

 
 
  if (cd < 50) 
     rip = 1.00;
  else if (cd < 200)
     rip = 0.90;
  else 
     rip = 0.8;
     
  if (cd < 50)
     discount = 0;
  else if (cd  < 100)
      discount = 0.1 * cd;
  else 
      discount = 0.2 * cd;
  
        
  ripCost = rip * cd;
  
  // disk space =  ~74mins per cd / 1x factor for VBR - therefore
  disk = Math.ceil((74*60*rate*cd)/(8*1024*1024),2);

  if (lossless == "None")
  {   arc = 0;  
      arcCost = 0; 
      cdaName.innerHTML = "No archive requested" ;
      arcName.innerHTML = "0GB" ;
      arcC.innerHTML = "£ 0" ;
  }
  else
  {   arc = Math.ceil(0.45 * cd); 
      arcCost = 0.2 * cd; 
      cdaName.innerHTML = cd + " CDs in " + lossless + " format";
      arcName.innerHTML = arc + "GB";
      arcC.innerHTML = "£ " + (arcCost).toFixed(2) ;
  }
     
  tot = disk + arc ;
  dvd = Math.ceil(tot / 4.7) ;
  totCost = (ripCost + arcCost + hardCost) - discount ;
  
  if (tot < 80) 
       hdName.innerHTML = "80GB" ;
  else if (tot < 160)
       hdName.innerHTML = "160GB" ;
  else if (tot < 200)
       hdName.innerHTML = "200GB" ;
  else if (tot < 250)
       hdName.innerHTML = "250GB" ;
  else 
       hdName.innerHTML = "300GB" ;


  
  ripName.innerHTML = disk + "GB";
  cdName.innerHTML = cd + " CDs in " + format + " format at " + rate + "Kbs";
  totName.innerHTML = tot + " GB, " + dvd + " DVDs";
  totC.innerHTML = "£ " + (totCost).toFixed(2);
  ripC.innerHTML = "£ " + (ripCost).toFixed(2);
  discC.innerHTML = "£ " + (discount).toFixed(2);

  document.demo.secret.value = "CDs = " + cd + " Format = " + format + " Rate = " + rate + " Archive = " + lossless + " Harddisk = " + hardtype + "\n" +
                       "Rip cost = " + ripCost + "Tot cost = " + totCost ;
   }
   
  function validateOnSubmit() {
    var elem;
    var errs=0;
    // execute all element validations in reverse order, so focus gets
    // set to the first one in error.

    if (!validateTelnr  (document.forms.demo.telnr, 'inf_telnr', true)) errs += 1; 
    if (!validateEmail  (document.forms.demo.email, 'inf_email', true)) errs += 1; 
    if (!validatePresent(document.forms.demo.from,  'inf_from'))        errs += 1; 

    if (errs>1)  alert('There are fields which need correction before sending');
    if (errs==1) alert('There is a field which needs correction before sending');

    return (errs==0);
  }
// ----------------------------------------------------------------------
// Javascript form validation routines.
// Author: Stephen Poley
//
// Simple routines to quickly pick up obvious typos.
// All validation routines return true if executed by an older browser:
// in this case validation must be left to the server.
//
// Update Aug 2004: have tested that IE 5.0 and IE 5.5 both support DOM model
// sufficiently well, so innerHTML option removed (redundant).
//
// Update Jun 2005: discovered that reason IE wasn't setting focus was
// due to an IE timing bug. Added 0.1 sec delay to fix.
//
// Update Oct 2005: minor tidy-up: unused parameter removed
// ----------------------------------------------------------------------

var nbsp = 160;    // non-breaking space char
var node_text = 3; // DOM text node-type
var emptyString = /^\s*$/
var glb_vfld;      // retain vfld for timer thread

// -----------------------------------------
//                  trim
// Trim leading/trailing whitespace off string
// -----------------------------------------

function trim(str)
{
  return str.replace(/^\s+|\s+$/g, '')
}


// -----------------------------------------
//                  setfocus
// Delayed focus setting to get around IE bug
// -----------------------------------------

function setFocusDelayed()
{
  glb_vfld.focus()
}

function setfocus(vfld)
{
  // save vfld in global variable so value retained when routine exits
  glb_vfld = vfld;
  setTimeout( 'setFocusDelayed()', 100 );
}


// -----------------------------------------
//                  msg
// Display warn/error message in HTML element
// commonCheck routine must have previously been called
// -----------------------------------------

function msg(fld,     // id of element to display message in
             msgtype, // class to give element ("warn" or "error")
             message) // string to display
{
  // setting an empty string can give problems if later set to a 
  // non-empty string, so ensure a space present. (For Mozilla and Opera one could 
  // simply use a space, but IE demands something more, like a non-breaking space.)
  var dispmessage;
  if (emptyString.test(message)) 
    dispmessage = String.fromCharCode(nbsp);    
  else  
    dispmessage = message;

  var elem = document.getElementById(fld);
  //elem.InnerHTML = dispmessage;  
  elem.firstChild.nodeValue = dispmessage;  
  
//  elem.className = msgtype;   // set the CSS class to adjust appearance of message
}

// -----------------------------------------
//            commonCheck
// Common code for all validation routines to:
// (a) check for older / less-equipped browsers
// (b) check if empty fields are required
// Returns true (validation passed), 
//         false (validation failed) or 
//         proceed (don't know yet)
// -----------------------------------------

var proceed = 2;  

function commonCheck    (vfld,   // element to be validated
                         ifld,   // id of element to receive info/error msg
                         reqd)   // true if required
{
  if (!document.getElementById) 
    return true;  // not available on this browser - leave validation to the server
  var elem = document.getElementById(ifld);
  if (!elem.firstChild)
    return true;  // not available on this browser 
  if (elem.firstChild.nodeType != node_text)
    return true;  // ifld is wrong type of node  

  if (emptyString.test(vfld.value)) {
    if (reqd) {
      msg (ifld, "error", "ERROR: required");  
      setfocus(vfld);
      return false;
    }
    else {
      msg (ifld, "warn", "");   // OK
      return true;  
    }
  }
  return proceed;
}

// -----------------------------------------
//            validatePresent
// Validate if something has been entered
// Returns true if so 
// -----------------------------------------

function validatePresent(vfld,   // element to be validated
                         ifld )  // id of element to receive info/error msg
{
  var stat = commonCheck (vfld, ifld, true);
  if (stat != proceed) return stat;

  msg (ifld, "warn", "");  
  return true;
}

// -----------------------------------------
//               validateEmail
// Validate if e-mail address
// Returns true if so (and also if could not be executed because of old browser)
// -----------------------------------------

function validateEmail  (vfld,   // element to be validated
                         ifld,   // id of element to receive info/error msg
                         reqd)   // true if required
{
  var stat = commonCheck (vfld, ifld, reqd);
  if (stat != proceed) return stat;

  var tfld = trim(vfld.value);  // value of field with whitespace trimmed off
  var email = /^[^@]+@[^@.]+\.[^@]*\w\w$/
  if (!email.test(tfld)) {
    msg (ifld, "error", "ERROR: not a valid e-mail address");
    setfocus(vfld);
    return false;
  }

  var email2 = /^[A-Za-z][\w.-]+@\w[\w.-]+\.[\w.-]*[A-Za-z][A-Za-z]$/
  if (!email2.test(tfld)) 
    msg (ifld, "warn", "Unusual e-mail address - check if correct");
  else
    msg (ifld, "warn", "");
  return true;
}


// -----------------------------------------
//            validateTelnr
// Validate telephone number
// Returns true if so (and also if could not be executed because of old browser)
// Permits spaces, hyphens, brackets and leading +
// -----------------------------------------

function validateTelnr  (vfld,   // element to be validated
                         ifld,   // id of element to receive info/error msg
                         reqd)   // true if required
{
  var stat = commonCheck (vfld, ifld, reqd);
  if (stat != proceed) return stat;

  var tfld = trim(vfld.value);  // value of field with whitespace trimmed off
  var telnr = /^\+?[0-9 ()-]+[0-9]$/
  if (!telnr.test(tfld)) {
    msg (ifld, "error", "ERROR: not a valid telephone number. Characters permitted are digits, space ()- and leading +");
    setfocus(vfld);
    return false;
  }

  var numdigits = 0;
  for (var j=0; j<tfld.length; j++)
    if (tfld.charAt(j)>='0' && tfld.charAt(j)<='9') numdigits++;

  if (numdigits<6) {
    msg (ifld, "error", "ERROR: " + numdigits + " digits - too short");
    setfocus(vfld);
    return false;
  }

  if (numdigits>14)
    msg (ifld, "warn", numdigits + " digits - check if correct");
  else { 
    if (numdigits<10)
      msg (ifld, "warn", "Only " + numdigits + " digits - check if correct");
    else
      msg (ifld, "warn", "");
  }
  return true;
}



