﻿ function emptyStr(str) { 
    var i,ch;
    for (i=0;i < str.length;i++) {
      ch=str.charAt(i);
      if ((ch!=" ") && (ch!=unescape("%0D")) && (ch!=unescape("%0A"))) 
         return false;
     }     
    return true;
  }

 function checkEmptyStr(form_field, strText) { 
    var tmpStr = eval("document." + form_field + ".value;");
	if (emptyStr(tmpStr)) {
       alert(strText);
       eval("document." + form_field + ".focus();");
       return true;
     }     
    return false;
  }

  function lenTextarea(strField, strText, numLen) {
    var strVal = eval("document.forms[0]." + strField + ".value;");
    if ((numLen>0) && (strVal.length>numLen)) {
	   alert("Le texte du " + strText + " ne doit pas excéder " + numLen + " symboles!");
       eval("document.forms[0]." + strField + ".focus();");
	   eval("document.forms[0]." + strField + ".select();");
       return false;
	  }
    return true;
  }  
  
  // checking for <textarea> tag value
  // strField is the name of the field
  // strText is the text before the field
  // chkEmpty: true if the field value couldn't be empty
  // numLen is maximum length of the field value
  function checkTextarea(strField, strText, chkEmpty, numLen) {
    var strVal = eval("document." + strField + ".value;");
	var ok = true; 
    if ((chkEmpty) && (emptyStr(strVal))) {
	    ok = false;
	    alert("Votre \"" + strText + "\"!");
	  }
	 
    if ((numLen>0) && (strVal.length>numLen)) {
	    ok = false;
	    alert("Le texte du " + strText + " ne doit pas excéder " + numLen + " symboles!");
	  }
   if (!ok) {
	  eval("document." + strField + ".focus();");
	  eval("document." + strField + ".select();");
      return false;
	}
    return true;
  }
  // how to use
  // if (!checkTextarea("textAnam", "Òåêñò:", true, 200))  return;

 function checkTextareaChars(obj, numChars) {
    var numKey = window.event.keyCode;
	if ((numKey>10) && ((numKey<33) || (numKey>46))) {
     if ((obj.value).length>numChars) 
       return false;
	}
	return true;
  }
  // how to use
  // <textarea name="field_name" onKeyDown="return checkTextarea(this, 200);" ...>
  
 function checkFieldNumeric(fieldObj) {
   fieldObj.value = strToInt(fieldObj.value);
 }
  
 function checkEMail(strEMail) {
   if (strEMail.indexOf(" ")!=-1) return false;
   var tmpPos = strEMail.indexOf("@");
   if (tmpPos<2 || (strEMail.indexOf("@",tmpPos+1)>-1) )  return false;
   if ((strEMail.charAt(0)=='@') || (strEMail.charAt(strEMail.length-1)=='@')) return false;
   return true;
   // var goodEmail = strEMail.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
 }
 function checkEMailField(strField) {
   var strVal = eval("document." + strField + ".value;");
   if (!checkEMail(strVal))  {
	 eval("document." + strField + ".focus();");
	 eval("document." + strField + ".select();");
     alert(document.MailingForm.alert.value);
     return false;
   }
   return true;
 }

