function windowOpen(url, name, w, h)
{
// Fudge factors for window decoration space.
w += 36;
h += 96;
 var win = window.open(url,
  name,
  'width=' + w + ', height=' + h + ', ' +
  'location=no, menubar=no, ' +
  'status=no, toolbar=no, scrollbars=yes, resizable=yes');
 win.resizeTo(w, h);
 win.focus();
}

function addBoxes()
{
  var subTotal = 0;
  var inputs = document.getElementsByTagName('input'); 
  for(var k=0;k<inputs.length;k++)
  {
    if(inputs[k].type == 'text'){
      if(inputs[k].name.match('price') == 'price')
      {
        if(inputs[k].value != ""){
          if(isNaN(inputs[k].value)){
            alert("non-numeric!");
          }else
          {
            if(inputs[k].value.length < 7){
              subTotal = subTotal + parseInt(inputs[k].value);
            }else
            {
              alert("value too large");
            }
          }
        }
      }
    }
  }
  //alert(boxValue);
  document.forms['quote'].subtotal.value = subTotal;
  //alert (subTotal);
  var total = 0;
  // supply 5% GST
  var nGST = subTotal * 0.05;
  nGST = Math.round(nGST*100)/100;
  total = subTotal + nGST;
  
  document.forms['quote'].subGST.value = nGST;
  if(document.forms['quote'].subPST){
    var nPST = subTotal * 0.07;
    nPST = Math.round(nPST*100)/100;
    document.forms['quote'].subPST.value = nPST;
    total = total + nPST
  }
  total = Math.round(total*100)/100;
    // grand total box
  document.forms['quote'].total.value = total;
}

function validateEmail()
{
  var email = document.getElementById('custemail');
  if (email.value != ""){
    var filter = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
    if (!filter.test(email.value)) {
      alert('Please provide a valid email address');
      email.focus
      return false;
    }
  }else{
    return true;
  }
}

function validatePhone()
{
  var strPhone = document.getElementById('custphone');
  if (strPhone.value != ""){
    var filter = /^(\+\d)*\s*(\(\d{3}\)\s*)*\d{3}(-{0,1}|\s{0,1})\d{2}(-{0,1}|\s{0,1})\d{2}$/;
    if (!filter.test(strPhone.value)) {
      alert('Please provide a valid telephone number');
      strPhone.focus
      return false;
    }
  }else{
    return true;
  }
}

function validateCustomerName() 
{
  var strCustomer = document.getElementById('customer').value;
  var regex = /^([a-zA-Z0-9 _-]+)$/;
  if (strCustomer != ""){
    if (strCustomer.match(regex)){
      return true;
    }
    else{
      alert ("Please enter a valid Customer Name!");
      return false;
    }
  }else{
    return true;
  }
}

function maxLength(maxvalue)
{
  var q = eval("document.forms['quote'].inforequest.value.length");
  var r = q - maxvalue;
  var msg = "There are too many characters in the Info Request box. Please abbreviate "+
            "your text by at least "+r+" characters";
  if (q > maxvalue){
    alert(msg);
    return false;
  }else{
    return true;
  }
}
















