function submitForm(form) {
 window.open("", "edi_thankyou", "width=610,height=260,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=yes");
 setTimeout(function () { document.location.href = document.referrer; }, 50);
}

function validate(form, fields) {
 var msg = "Please fill in the following fields:\n";
 var error = 0;
 var pairs = fields.split("&");

 for (var i = 0; i < pairs.length; ++i) {
  var temp = pairs[i].split("=");
  var field = temp[0];
  var name = temp[1];
  var element = eval("document." + form + "." + field);
  var valid = true;
  
  if (element.type == "checkbox") {
  	valid = element.checked;
  }
  
  else {
  	valid = allTrim(element.value) != "";
  }
  
  if (!valid) {
   ++error;
   msg += name + "\n";
  }
 }
 
 if (error > 0) {
  alert(msg);
  return false;
 }
 
 submitForm(form);
 return true;
}

function allTrim(cValue){
 var lDone=false;
 while (lDone==false){
  if (cValue.length==0) {return cValue;}
  if (cValue.indexOf(' ')==0){cValue=cValue.substring(1);lDone=false; continue;}
  else {lDone=true;}
  if (cValue.lastIndexOf(' ')==cValue.length-1){cValue=cValue.substring(0, cValue.length-1);lDone=false;continue;}
  else {lDone=true;}
 }
 return cValue;
}
