validMsg='Please wait';

function checkForm(theForm,validMsg) { 
    var why = ""; var ff=theForm;  
if (ff.name!='review') {
   if(ff.name!='update') { why += checkEmail(ff.email.value); if (why!="") { alert(why); ff.email.focus(); return false; }}
	if(ff.name!='forgot' && ff.name!='contact' && ff.name!='signin'){why += checkPassword(ff.pswd.value); if (why!=""){ alert(why); ff.pswd.focus(); return false; }}
	if(ff.name=='contact') {  why += checkIll(ff.msg.value,'message'); if (why!="") { alert(why); ff.msg.focus(); return false; }}
    if(ff.name=='register' || ff.name=='update') {
	   why += checkName(ff.prenom.value,'first name'); if(why!=""){alert(why);ff.prenom.focus();return false;}
	   why += checkName(ff.nom.value,'last name'); if (why!="") { alert(why); ff.nom.focus(); return false; }
   	   why += checkName(ff.addr1.value,'address'); if(why!=""){alert(why);ff.addr1.focus();return false; }
	   why += checkName(ff.ville.value,'city'); if (why!="") { alert(why); ff.ville.focus(); return false; }
	   why += checkName(ff.zip.value,'zip code'); if (why!="") { alert(why); ff.zip.focus(); return false; }
     // why += checkDropdown(ff.pays.selectedIndex); if (why!="") { alert(why); ff.pays.focus(); return false; }
   } //end if register
}
else if(ff.name=='review') {  
	  var radios = ff.elements.payOption; 
	  for (i=0, n=radios.length; i<n; i++) { if (radios[i].checked) { var checkvalue = radios[i].value; break; }}
      why += checkRadio(checkvalue); if (why!="") { alert(why); radios[0].focus(); return false; }
	  why += checkIll(ff.comment.value,'comment'); if (why!="") { alert(why); ff.comment.focus(); return false; }
   }
  
      validMsg=validMsg;
      subOnce(theForm,validMsg) //firefox
 return true;
}

function subOnce(ff,validMsg) {
  if (ff.submit != null) {
    ff.submit.disabled = true;  ff.submit.value =validMsg;
	if (ff.submit.disabled) { return false; }
  }
  return true;
}
// email
function checkEmail (strng) {var error="";
if (strng == "") {  error = "You didn't enter an email address.\n";}
    var emailFilter=/^.+@.+\..{2,4}$/;
    if (!(emailFilter.test(strng))) {  error = "Please enter a valid email address.\n";}
    else { var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ //test email for illegal characters
         if (strng.match(illegalChars)) {error = "The email address contains invalid characters.\n"; }
    }
return error;
}

// phone number
function checkPhone (strng) {var error = "";
//if (strng == "") {error = "You didn't enter a phone number.\n";}
var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
    if (isNaN(parseInt(stripped))) {error = "The phone number contains invalid characters."; }
   // if (!(stripped.length == 10)) {error = "The phone number is less than 10 digits.\n"; } 
return error;
}

// password 
function checkPassword (strng) {var error = "";
if (strng == "") {error = "You didn't enter a password.\n";}
 var illegalChars = /[\W_]/; // allow only letters and numbers - since local may mean accents
	 //  var illegalChars = /^[a-zA-Z0-9][a-zA-Z0-9]{5,7}$/;
	// var illegalChars = /['.$vv.'[<>~`!@#$%^&*_=+{}|;?]|[|]]+/;
    if ((strng.length < 6) || (strng.length > 8)) {error = "The password must have 6 to 8 characters.\n"; }
    else if (illegalChars.test(strng)) { error = "The password contains invalid characters.\n"; } 
   /* else if (!((strng.search(/(a-z)+/)) && (strng.search(/(A-Z)+/)) && (strng.search(/(0-9)+/)))) {
     error = "The password must contain at least one uppercase letter, one lowercase letter, and one numeral.\n";
    }  */
return error; 
}    

// username - 4-10 chars, uc, lc, and underscore only.
function checkName (strng,msg) {var error = "";
if (strng == "") { error = "Your "+msg+" is empty.\n";}
    var illegalChars= /[\<\>\,\;\:\\\"\[\]\?]/    //debut crochet \(\)\/
   // if ((strng.length < 4) || (strng.length > 10)) {error = "The name is the wrong length.\n";} else 
   if (strng.match(illegalChars)) {error = "The "+msg+" contains invalid characters.\n"; } 
return error;
}       

function checkIll (strng,msg) {var error = "";
if (strng == "") { error = "Your "+msg+" is empty.\n";}
    var illegalChars= /[\}\{\~\<\>\\]/   
   if (strng.match(illegalChars)) {error = "The "+msg+" contains invalid characters.\n"; } 
return error;
}   

function checkIllAccount (strng,msg) {var error = "";
    var illegalChars= /[\}\{\~\<\>\\]/   
   if (strng.match(illegalChars)) {error = msg+" contains invalid characters.\n"; } 
return error;
}  

function checkZip (strng) {var error = "";
if (strng == "") { error = "You didn't enter a ZIP code.\n";}
    var illegalChars = /\W/; // allow letters, numbers, and underscores
    if (illegalChars.test(strng)) {error = "The ZIP code contains invalid characters.\n"; } 
return error;
}  

// non-empty textbox
function isEmpty(strng,msg) {var error = "";
  if (strng.length <2) { error = "Please enter your "+msg+".\n"}
return error;	  
}

// was textbox altered
function isDifferent(strng) {var error = ""; 
  if (strng != "Can\'t touch this!") { error = "You altered the inviolate text area.\n"; }
return error;
}

// exactly one radio button is chosen
function checkRadio(checkvalue) {var error = "";
   if (!(checkvalue)) { error = "You must choose a method of payment.\n"; }
return error;
}
 
// valid selector from dropdown list
function checkDropdown(choice) {var error = "";
    if (choice == 0) {error = "Select your country from the drop-down list.\n"; }    
return error;
}
 