<!-- hide this script from non-javascript-enabled browsers
// these functions are used by order.php and orderandpay.php
//
function Hash() {
  this.length = 0;
  this.items = new Array();
  for (var i = 0; i < arguments.length; i += 2) {
    if (typeof(arguments[i + 1]) != 'undefined') {
      this.items[arguments[i]] = arguments[i + 1];
      this.length++;
    }
  }
  this.getItem = function(in_key) {
    return this.items[in_key];
  }
}
// set selectable options
function setOptions(hash, select) {
  var x = 0;
  select.options.length = 0;
  for (var a in hash.items)
    select.options[x++] = new Option(hash.items[a],a);
}

// set select box options based on the selected value of another
function setSelect(select_in, hash_in, hash_out, select_out, defaultZero) {
  var id = select_in.options[select_in.selectedIndex].value;
  var arr = hash_in.getItem(id);
//alert('ARR ' + id + '=' + arr);
  select_out.options.length = 0;
  var x = 0;
  if (defaultZero)
    select_out.options[x++] = new Option(defaultZero,0);
  for (var a in arr)
    select_out.options[x++] = new Option(hash_out.getItem(arr[a]),arr[a]);
}

function displayDiv(szDivID, iState) // 1 visible, 0 hidden
{
    if(document.layers)	   //NN4+
    {
       document.layers[szDivID].visibility = iState ? "show" : "hide";
       document.layers[szDivID].display = iState ? "block" : "none";
    }
    else if(document.getElementById)	  //gecko(NN6) + IE 5+
    {
        var obj = document.getElementById(szDivID);
        obj.style.visibility = iState ? "visible" : "hidden";
	obj.style.display = iState ? "block" : "none";
    }
    else if(document.all)	// IE 4
    {
        document.all[szDivID].style.visibility = iState ? "visible" : "hidden";
	document.all[szDivID].style.display = iState ? "block" : "none";

    }
}
//
function setSizePrice(form,priceDiv,rrpDiv) {
  var x = form.siz.options[form.siz.selectedIndex];
  if (rrpDiv) {
    var i = x.value.indexOf('|');
    document.getElementById(priceDiv).innerHTML = '$'+x.value.substr(0,i);
    document.getElementById(rrpDiv).innerHTML = '$'+x.value.substr(i+1);
  }
  else
    document.getElementById(priceDiv).innerHTML = '$'+x.value;
  form.sizn.value = x.innerHTML;
}

function formErr(msg) {
  alert("You must enter " + msg);
  return false;
}

// returns 'true' if the order form can be submitted
function checkOrderForm() {
  var a = document.form1;

  var radioSelected = false;
  for (c = 0; c < a.paymethod.length; c++) {
    if (a.paymethod[c].checked)
      radioSelected = true;
  }
  if (!radioSelected) {
    alert("You must select a Payment Method");
    return false;
  }

  if (!a.name.value)     return formErr("a Name");
  if (!a.email.value)    return formErr("an Email Address");
  if (!a.phone.value)    return formErr("a Phone Number");
  if (!a.address1.value) return formErr("an Address 1");
  if (!a.city.value)     return formErr("a City");
  if (!a.state.value)    return formErr("a State");
  if (!a.postcode.value) return formErr("a Postcode");
  if (!a.country.value)  return formErr("a Country");
  
  if (a.deliver.checked == false) {
    if (!a.dname.value)     return formErr("a Delivery Name");
    if (!a.demail.value)    return formErr("a Delivery Email Address");
    if (!a.dphone.value)    return formErr("a Delivery Phone Number");
    if (!a.daddress1.value) return formErr("a Delivery Address 1");
    if (!a.dcity.value)     return formErr("a Delivery City");
    if (!a.dstate.value)    return formErr("a Delivery State");
    if (!a.dpostcode.value) return formErr("a Delivery Postcode");
    if (!a.dcountry.value)  return formErr("a Delivery Country");
  }

  if (a.terms.checked == false) {
    alert("You must agree to the Terms and Conditions");
    return false;
  }

  return true;
}

// returns 'true' if the credit card form can be submitted
function checkCCForm() {
  var a = document.ccform;
  if (!a.ccname.value) return formErr("a Name");
  if (!a.ccnum.value)  return formErr("a Credit Card Number");
  if (!a.ccexp.value)  return formErr("a Credit Card Expiry Date");
  if (!a.ccpin.value)  return formErr("a 3 Digit Pin");

  return true;
}
