function printw() {
	print();
}

function closew() {
	close();
}

function neww(urid) {
  if (urid == 1) { var uri='faq.php'; }
  if (urid == 2) { var uri='http://www.yellowpages.ca/searchBusiness.do?action=homeSearch&categorySym=&business=burt%27s+greenhouses&city=odessa&provinceId=ON';}
  if (urid == 3) { var uri='avlist3.php'; }
  if (urid == 4) { var uri='discounts.shtml'; }
  if (urid == 5) { var uri='positions.php'; }
  if (urid == 6) { var uri='ipm.html'; }
  if (urid == 7) { var uri='diarybg.shtml'; }
  if (urid == 8) { var uri='bghpp.html'; }
  if (urid == 9) { var uri='bghtc.html'; }
  NewWindow(uri,'mywin',500,400,'yes','no'); 
}

function goog() {
  var ur = 'http://www.google.com/search?sourceid=navclient&q=';
  ur = ur+document.forms.f.st.value;
  ur = ur+'+site%3Awww%2Eburtsgh%2Ecom';
  NewWindow(ur,'mywin',500,400,'yes','no');
  return false; 
}

function newacct() {
  alert('The registration form will open in a new browser window. ' +
	'Once you have finished the process, close that window and you will be ' +
	' able to return to this window at the same point in the order.');
}

function underc() {
	alert('While this document is under construction please contact us for the latest information. Thankyou.');
}

function test2(q) {
  if (q == '3') var mess = 'Warning: Refreshing screen, Cart is safe, OK?';
  else var mess = 'Warning: Refreshing screen, OK?';
  if (confirm(mess)) return true ;
  else return false ;
}

function subit(uu) {
  var ur = 'http://www.burtsgh.com/avlist3.php?submit=Finalize&sesstag='+uu+'';
  NewWindow(ur,'mywin',400,300,'yes','no');
  return false; 
}

function NewWindow(mypage, myname, w, h, scroll, menu) {
  var winl = 30;
  var wint = 30;
  winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',menubar='+menu+',resizable,status=yes'
  win = window.open(mypage, myname, winprops)
  if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
  return win;
}

function mywin(txt) {
    var msgbox = "<table width='100%' border=1><tr>"
	+"<th>Messages</th></tr>"+txt+"</table>";
  win2=NewWindow('','win2',200,200,'yes','no');
  win2.document.write(msgbox);
  return false;
}

function validate(field,sel) {
var validl = "abcdefghijklmnopqrstuvwxyz";
var validu = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var validn = "0123456789";
var val = '';
if (sel == 'num') val = validn;
else if (sel == 'chl') val = validl;
else if (sel == 'chu') val = validu;
else if (sel == 'cha') val = validl+validu;
else if (sel == 'chn') val = validn;
else val = validl+validu+validn; 
var ok = "yes";
var temp;
  for (var i=0; i<field.value.length; i++) {
    temp = "" + field.value.substring(i, i+1);
    if (val.indexOf(temp) == "-1") {
      ok = "no";
      break;
    }
  }
  if (ok == "no") {
    alert("Invalid characters in this field!");
    field.focus();
    field.select();
  }
}

function check_vals(form) {
  var totq=0;
  var reg = /^[0-9]+$/;
  for (i=0; i < form.elements.length; i++) {
    str=form.elements[i].name;
    if (str.substring(0,2) == 'xq' ) {
      if (!reg.test(form.elements[i].value)) {
        alert('One of your entries contains an invalid value, please verify.');
	return false;
      }
      if (form.elements[i].value > 0) {
        totq=totq+form.elements[i].value;
      }
    }
  }
  if (totq > 0) {
    return true;
  } else {
    alert('Total items ordered is zero. Please check your list.');
    return false;
  }
}

function test_fm(form,un) {
  if (form.fn.value == '') {
    alert('First name is missing');
    return false;
  }
  if (form.ln.value == '') {
    alert('Last name is missing');
    return false;
  }
  if (form.addr.value == '') {
    alert('Delivery address is missing');
    return false;
  }
  if (form.city.value == '') {
    alert('City is missing');
    return false;
  }
  if (form.pcode.value == '') {
    alert('Postal Code is missing');
    return false;
  } else {
    return test_pcode(form.pcode);
  }
  if (form.phone.value == '') {
    alert('Phone number is missing');
    return false;
  } else {
    return test_phone(form.phone);
  }
  if (form.email.value == '') {
    alert('E-mail address is missing');
  } else {
    return test_email(form.email);
  }
  if (un == 'reg') {
    if (form.username.value == '') {
      alert('User Name is missing');
      return false;
    }
  }
  if (un == 'reg' || un == 'mod') {
    if (form.password.value == '') {
      alert('password is missing');
      return false;
    }
    if (form.pass2.value == '') {
      alert('Confirmation password is missing');
      return false;
    }
    if (form.password.value != form.pass2.value) {
      alert('Password and confirmation password are not the same, please retry');
      return false;
    }
  }
}

function test_login(form) {
  if (form.username.value == '') {
    alert('Cannot log in, username missing');
    return false;
  }
  if (form.password.value == '') {
    alert('Cannot log in, password missing');
    return false;
  }
}

function test_pcode(v) {
  var reg = /^[A-Z][0-9][A-Z][ ]?[0-9][A-Z][0-9]$/;
  if (reg.test(v.value)) {
    return pcode_local(v.value);
  } else {
    alert("The post code does not appear to be valid.");
    return false;
  }
}

function pcode_local(pc) {
  pca = pc.substr(0,3);
  if (pc.substr(3,1) == " ") {
    pcb = pc.substr(4,3);
    pc = pca+pcb;
  } else {
    pcb = pc.substr(3,3);
  }
  pc = pca+pc.substr(4,3);
  if (pca == 'K7P' || pca =='K7N' || pca == 'K7M' || pca == 'K7L' || pca == 'K7K') {
    return true;
  }
  if (pca == 'K0H') {
    if (pcb == '2H0' || pcb == '1G0') {
      return true;
    }
  }
  alert("We regret that this postal code is not in our delivery area. Please see the FAQ for details.");
  return false;
}

function test_phone(v) {
  var reg = /^[1]?[- ]?[(]?([1-9]{3})?[)-]?[ ]?[0-9]{3}[- ]?[0-9]{4}$/;
  if (reg.test(v.value)) {
    return true;
  } else {
    alert("The phone number does not appear to be valid.");
    return false;
  }
}

function test_email(v) {      
  var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/;            
  var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
  if (!reg1.test(v.value) && reg2.test(v.value)) {
    return true;
  } else {
    alert("The email address does not appear to be valid.");
    return false;
  }
}

