<!-- Hide the script for older browsers

//------------------------------------------------------------------------------    
//  GrocerEase Order Form Java Scripts
//
//  Copyright (c) 1999 GrocerEase Pty Ltd
//
//  Dependant On:  prices.js
//------------------------------------------------------------------------------    

// the global array of all prices
//var  arPrices = new Array();

// call function to populate array when page is loaded
//fillPriceArray(arPrices);

//==============================================================================

function formatAmount(vdblValue) {
//purpose:  formats the specified floating point number to two decimal
//          places and returns the result as a string
//
//parameters:   vdblValue   - the floating point value to format

  //round the value to two decimal places if not zero
  if (vdblValue != 0) {
    vdblValue = vdblValue + 0.005;
    vdblValue = vdblValue * 100;
    vdblValue = parseInt(vdblValue);
    vdblValue = vdblValue / 100;
  }

  //convert the result into a string
  lstrValue = "" + vdblValue;

  //is there are decimal point?
  if (lstrValue.indexOf(".") < 0) {
    //no decimal point
    lstrValue = lstrValue + ".00";

  //is a decimal... is there enough 0's
  } else if (lstrValue.indexOf(".") >= lstrValue.length - 2) {
    //only a single digit
    lstrValue = lstrValue + "0";
  } //if

  //is there a leading zero if value below 1.0?
  if (lstrValue.indexOf(".") == 0) {
    //no leading zero
    lstrValue = "0" + lstrValue;
  }

  return lstrValue;
} //formatAmount

//------------------------------------------------------------------------------    

function getPrice(produceName) {
//purpose:   find the price of the given produce in the hashtable  
//
//parameters:   produceName   - the name of the produce

  ldblValue = parseFloat(arPrices[produceName]);
  if (isNaN(ldblValue) || ldblValue == 0) {
    return "<font color=#FF0000>N/A</font>";
  } else {
    return "$" + formatAmount(ldblValue);
  }
}

//------------------------------------------------------------------------------

function calcTotal(vedtSum) {
//purpose:   calculate the total sum by iterating over all rows

  var ldblSum = 0;
  var ldblValue = 0;
  // I have hardcoded the form here as everyone else fails
  // var lfrmForm = vedtSum.form;
  var lfrmForm = document.forms[0];

  for(lintElement = 0; lintElement < lfrmForm.elements.length; lintElement++) {
    //mask out all sum fields, they are calculated before calcTotal() is called
    if (lfrmForm.elements[lintElement].name.indexOf("Sum") == 0) {
      ldblValue = parseFloat(lfrmForm.elements[lintElement].value);
      if (!isNaN(ldblValue)) ldblSum += ldblValue;
    }
  }
  lfrmForm.edtTotal.value = ldblSum;
}

//------------------------------------------------------------------------------    

function calcTotal2(vfrmForm) {
//purpose:   calculate the total sum by iterating over all rows

  var ldblSum = 0;
  var ldblValue = 0;

  for(lintElement = 0; lintElement < vfrmForm.elements.length; lintElement++) {
    //mask out all sum fields, they are calculated before calcTotal() is called
    if (vfrmForm.elements[lintElement].name.indexOf("Sum") == 0) {
      ldblValue = parseFloat(vfrmForm.elements[lintElement].value);
      if (!isNaN(ldblValue)) ldblSum += ldblValue;
    } 
  }
  vfrmForm.edtTotal.value = formatAmount(ldblSum);
}

//------------------------------------------------------------------------------    

function calcSum(vedtProduce, price) {
//purpose:   calculate the sum of one row and calls calcTotal()
//
//parameter:    vedtProduce   - the calling input edit field
var ldblValue = price;
  // check first if we were called by another field
  if (vedtProduce.name.indexOf("Sum") == 0) {
    // the sum field triggered this call, so find the QtyXYZ field
    vedtProduce = vedtProduce.form["pid" + vedtProduce.name.substring(3)];
  }

  // assume that the name looks like "QtyXYZ", check if "Qty" is part of name
  if (vedtProduce.name.indexOf("pid") == 0) {
    // strip out produce name by deleting first three chars
    var lstrProduce = vedtProduce.name.substring(3);
    // find price in hash table
   // var ldblValue = parseFloat(arPrices[lstrProduce]);
    var lintQty = parseInt(vedtProduce.value);
    // now check if values valid so far
    if (vedtProduce.value == "" || isNaN(lintQty) || lintQty < 0) {
      // something is wrong, therefore blank line
      vedtProduce.value = "";
      vedtProduce.form["Sum" + lstrProduce].value = "";
    } else {
      // check if produce available (price >= 0)
      if (ldblValue == 0) {
        // produce is not available, hence inform user
        vedtProduce.value = "";
        vedtProduce.form["Sum" + lstrProduce].value = "N/A";
      } else {
        // everything is alright so far, now calculate sum 
        var ldblSum = lintQty * ldblValue;
        // sanity check, do not allow negative values
        if (ldblSum < 0) ldblSum = 0;
        vedtProduce.form["Sum" + lstrProduce].value = formatAmount(ldblSum);
      } 
    }
  }
  // finally calc the total sum, do this all the time 
  calcTotal(vedtProduce.form);
}

//------------------------------------------------------------------------------    

function validateForm(vfrmForm) {
//purpose:   check if order has the minimum price
//
//parameter:    vfrmForm   - the order form

  // check if the name is given
  if (vfrmForm["Last Name"].value == "" || vfrmForm["First Name"].value == "") { 
    alert("You have to provide your first and last name to submit your order."); 
    vfrmForm["First Name"].focus(); 
    return; 
  }

  // check if the total of the order is at least $18
  if (parseFloat(vfrmForm.edtTotal.value) < 18.0 || vfrmForm.edtTotal.value == "") { 
    alert("Please make sure that the total of this order is at least $18 (AUD)."); 
    vfrmForm.edtTotal.focus(); 
    return; 
  }

  // check if the postcode is entered if the customer is a new one
  var lintPostcode = parseInt(vfrmForm.Postcode.value);
  if (!vfrmForm.ExistCust.checked && (vfrmForm.Postcode.value ==  "" || isNaN(lintPostcode))) { 
    alert("You have to provide a postcode to submit your order."); 
    vfrmForm.Postcode.focus(); 
    return; 
  }

  // check if the postcode is correct, ie. in the delivery area
  if (!vfrmForm.ExistCust.checked && (lintPostcode < 4000 || lintPostcode >= 4200)) { 
    alert("We currently do not deliver to your area. Please contact the office " +
      "for further information or use our feedback form."); 
    vfrmForm.Postcode.focus(); 
    return; 
  }

  // if everything is ok, then submit form
  vfrmForm.submit();
}

//------------------------------------------------------------------------------    

function datePicker() {
//purpose:  create a calendar on the fly for the next week
//          starting today

  // define variables
  today      = new Date;
  calcdate   = new Date;
  thisYear   = today.getYear();
  // correct Y2K differencies in this method call
  if (thisYear < 1000) {
    thisYear = thisYear + 1900;
  }
  thisMonth  = today.getMonth() + 1;
  thisDate   = today.getDate();

  myYear     = new Array(13);
  myMonth    = new Array(13);
  myDate     = new Array(13);
  month      = new Array(13);

  month[1] = "JAN";
  month[2] = "FEB";
  month[3] = "MAR";
  month[4] = "APR";
  month[5] = "MAY";
  month[6] = "JUN";
  month[7] = "JUL";
  month[8] = "AUG";
  month[9] = "SEP";
  month[10]= "OCT";
  month[11]= "NOV";
  month[12]= "DEC";

  day = new Array(7);
  day[0] = "Sun";
  day[1] = "Mon";
  day[2] = "Tue";
  day[3] = "Wed";
  day[4] = "Thu";
  day[5] = "Fri";
  day[6] = "Sat";

  monthArray = new Array(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
  maxDays    = monthArray[thisMonth - 1];

  // handle leap year
  if (thisMonth == 2) {
    if ((thisYear / 4) != parseInt(thisYear / 4)) maxDays = 28;
    else maxDays = 29;
  }

  // load arrays with date data
  myYear[0]  = thisYear;
  myMonth[0] = thisMonth;
  myDate[0]  = thisDate;

  // determine proper year, month and day to put into
  // each array element
  for(i = 0 ; i < 13 ; i++){
    if (myMonth[i] != 12){
      if (myDate[i] != maxDays) {
        myMonth[i+1] = myMonth[i];
      }
      else {
        myMonth[i+1] = myMonth[i] + 1;
      }
      myYear[i+1] = myYear[i];
    }
    else {
      if (myDate[i] != maxDays) {
        myMonth[i+1] = myMonth[i];
        myYear[i+1] = myYear[i];
      }
      else {
        myMonth[i+1] = 1;
        myYear[i+1] = myYear[i] + 1;
      }
    }
    if (myDate[i] != maxDays) {
      myDate[i+1] = (myDate[i] + 1);
    }
    else {
      myDate[i+1] = 1;
    }
  }

  // print the whole mess
  document.write("<select name=date size=1>");
  for(j = 1 ; j < 14 ; j++) {
    calcdate.setYear(myYear[j]);
    calcdate.setMonth(myMonth[j] - 1);
    calcdate.setDate(myDate[j]);
    document.write("<option value=\"" + day[calcdate.getDay()] + "-" + myDate[j]
      + "-" + month[myMonth[j]] + "-" + myYear[j] + "\"");
    // selected the day after tomorrow as the default date
    if (j == 2) {
      document.write(" selected");
    }
    myDate[j] = "" + myDate[j];
    if (myDate[j].length == 1) {
      myDate[j] = "0" + myDate[j];
    }
    document.write(">");
    document.write(day[calcdate.getDay()] + " " + myDate[j] + "-" + month[myMonth[j]] + "-" + myYear[j]);
  }
  document.write("</select>"); 
}

//------------------------------------------------------------------------------    

function checkBrowser() {       
//purpose:  test the version of the browser for the following script

  if (navigator.appVersion.indexOf("(X11") != -1 || 
    navigator.appVersion.indexOf("(Mac") != -1) return 1;
  else return 0;
}

//------------------------------------------------------------------------------    

// declare and initialise the global tracker variables for 
// the description window

stat = 0;
dow = 0;

function showDesc(url, dow, winwidth, winheight) {
// purpose:  popup a separate window for the description of each produce
//           keep track if window is open and close in case it is
 
  // prepend path to given URL - saves resources in html page
  url = "/fruit/" + url;

  // check the state of the popup window, if it is not open then pop it up
  if (stat == 0) {
    description = window.open(url, 'descr', 'toolbar=no,location=no,' +
     'directories=no,status=no,menubar=no,scrollbar=no,scrollbars=auto,' + 
     'resizable=no,copyhistory=no,width=' + winwidth + ',height=' + winheight);
    description.focus();
    stat = dow;
    if (checkBrowser() == 1 ) window.open(url, 'descr');
  } else {
    // the window was open, therefore close it
    description.close();
    // if a new one is to be displayed then open the corresponding page
    if (stat != dow) { 
      stat = dow;
      description=window.open(url, 'descr', 'toolbar=no,location=no,' +
        'directories=no,status=no,menubar=no,scrollbar=no,scrollbars=auto,' +
        'resizable=no,copyhistory=no,width=' + winwidth + ',height=' + winheight);
      description.focus();
      if (checkBrowser() == 1 ) window.open(url, 'descr');
    } else {
      stat = 0;
    }
  }
}

//==============================================================================
    
//end hide for older browsers -->
