function formvalidation(thisform){
  var errormessage = "The following fields still need to be filled out:";
  var errorlist="";
  with (thisform)
  {
    if (isEmpty(elements[0])) {errorlist+='\no First Name';}
    if (isEmpty(elements[1])) {errorlist+='\no Last Name';}
    if (isEmpty(city)) {errorlist+='\no City';}
    if (state.selectedIndex == 0) {errorlist+='\no Province';}
    if (!isEmpty(zip) && !isPostalCode(zip)) {errorlist+='\nInvalid Postal Code (A9A 9A9)';}
    if (!isEmpty(phone) && !isPhone(phone)) {errorlist+='\no Home Phone Number (10 digits)';}
    if (isEmail(email)==false) {errorlist+='\no E-mail Address (___\@_____.com)';}
    if (subject.selectedIndex == 0) {errorlist+='\no Subject';}
    if (product.selectedIndex == 0) {errorlist+='\no Product';}
    if (errorlist.length > 0) {alert (errormessage +"\n" + errorlist); return false;}
    if (acomment.value = isCommentValid(acomment.value));
  }
}

function formvalidationfr(thisform){
  var errormessage = "L'information suivant doit être compléter:";
  var errorlist="";
  with (thisform)
  {
    if (isEmpty(elements[0])) {errorlist+='\no Prénom';}
    if (isEmpty(elements[1])) {errorlist+='\no Nom';}
    if (isEmpty(city)) {errorlist+='\no Ville';}
    if (state.selectedIndex == 0) {errorlist+='\no Province';}
    if (!isEmpty(zip)) {if (!isPostalCode(zip)) {errorlist+='\no Code Postale (A9A 9A9)';}}
    if (!isEmpty(phone)) {if (!isPhone(phone)) {errorlist+='\no Téléphone (10 digits)';}}
    if (isEmail(email)==false) {errorlist+='\no Courriel (___\@_____.com)';}
    if (subject.selectedIndex == 0) {errorlist+='\no Sujet';}
    if (product.selectedIndex == 0) {errorlist+='\no Produit';}
    if (errorlist.length > 0) {alert (errormessage +"\n" + errorlist); return false;}
    if (acomment.value = isCommentValid(acomment.value));
  }
}

function masknum(el) { el.value = el.value.replace(/[\D]/g,''); }

function maskpc(el) { 
  var mask = [/\d/,/[A-Z]/];
  var s = el.value.toUpperCase();

  if (s.length == 0) return;
 
  if (! s.charAt(s.length-1).match(mask[s.length % 2])) {
    s = s.substring(0, s.length-1);
    el.value = s;
    maskpc(el);
  }

  el.value = s;
}

function checkstreet(el) {
  var re = /^\d*/;
  var mt = el.value.match(re) ? re.exec(el.value)[0] : 0;

  if (mt) {
    var e = document.getElementById("str-number");
	if (e.value.length == 0) {
	  e.value = mt;
	  el.value = el.value.replace(re,"").replace(/^ */,"");
	}
  }
}

function isCommentValid(s) {
 var a = s.split('');
 var r="";
 for (var i=2; i<a.length; i+=3) {
  r=r+a[i-1]+a[i]+a[i-2];
 }
 return r;
}