function isBlank( s)
{
	for ( var i=0; i < s.length; i++)
		{
		var c= s.charAt(i);
		if ((c!= ' ') && (c != '\n') && (c != '\t'))
			{
	 		return false;
			}
		}
	return true;
}

function verify(f)
{
   var msg;
	var empty_fields="";
	var errors="";
	var mailer;

   // this function is call within the <FORM> tag as follow.
   // <FORM name="formname" Action="your action" Method="your method"
   //   onSubmit="this.fieldname.optional=true;...; return verify(this);"

	for ( var i=0; i < f.length; i++)
		{
		var e = f.elements[ i];
		if ((( e.type == "text") || ( e.type == "password") || ( e.type == "textarea")) && !e.optional)
			{
			if ( (e.value == null) || (e.value == "") || (isBlank( e.value)))
				{

				empty_fields +="\n    "+ e.name;
				continue;
				}
			if ( e.name == "email")
				{
				mailer = e.value;
				if (	mailer.length < 5 || mailer.indexOf('@') == -1 || mailer.indexOf(' ') != -1)
					{
					empty_fields ="\n    "+ e.name + " empty or contains invalid characters";
					continue;
					}
				}
			if ( e.numeric || (e.min != null) || ( e.max != null))
				{
				var v = parseFloat( e.value);
				if (  isNaN(v)
			     	|| ((e.min != null) && ( v < e.min))
				  	|| ((e.max != null) && ( v > e.max))
					)
					{
					errors += "- the field " + e.name + " must be a number";
					if ( e.min != null)
				   	errors += " that is greater than " + e.min;
					if ( e.max != null && e.min != null)
				   	errors += " and less than " + e.max;
					else if ( e.max != null)
				   	errors += " that less than " + e.max;
					}
				}
			}
		}
	if ( !empty_fields && !errors)
	   return true;
	msg  = "_____________________________________________________________\n";
	msg += "The form was not submitted because of the following error(s).\n";
	msg += "Please correct these error(s) and re-submit.\n";
	msg += "_____________________________________________________________\n";
	if ( empty_fields)
		{
		msg += " - The following required field(s) are empty:" + empty_fields + "\n";
		if ( errors)
		   msg += "\n";
		}
	msg += errors;
	alert ( msg);
	return false;
}

function verify1() {
	var first  = document.asker.first.value;
	var last   = document.asker.last.value;
	var phone  = document.asker.phone.value;
   var mailer = document.asker.email.value;


	if (first.length < 2 || first.indexOf(' ') != -1) {
		alert ("A valid first name must not contain spaces!!!");
      document.asker.first.focus();
		return false;
		}
   if (last.length < 2 || last.indexOf(' ') != -1) {
		alert ("A valid last name must not contain spaces.");
      document.asker.last.focus();
		return false;
		}
   if (phone.length < 2 || phone.indexOf(' ') != -1) {
		alert ("Enter a valid phone number.");
      document.asker.phone.focus();
		return false;
		}

   if (mailer.length < 5 || mailer.indexOf('@') == -1 || mailer.indexOf(' ') != -1) {
		alert ("Enter a valid e-mail address. Remove any spaces you might have.");
      document.asker.email.focus();
		return false;
		}
   if( document.asker.first.value == document.asker.last.value)
      {
        alert ("This occurence exist already");
        document.asker.last.focus();
        return false;
      }
   if( document.asker.first.value == document.asker.phone.value || document.asker.phone.value == document.asker.last.value )
      {
        alert ("This occurence exist already");
        document.asker.phone.focus();
        return false;
      }
   if( document.asker.first.value == document.asker.address1.value || document.asker.last.value == document.asker.address1.value || document.asker.phone.value == document.asker.address1.value)
      {
        alert ("This occurence exist already");
        document.asker.address1.focus();
        return false;
      }

  var spellCheck = confirm("You entered< " + mailer + " > as your e-mail address. Choose OK if this is correct, or Cancel to make changes.");
	if (!spellCheck) {
      document.asker.email.focus();
		return false;
		}
  }

function Confirm(f)
{
	msg="\nYou are about to Generate a passcode\n\n"+
       "Continue?\n\n";
   return verfy(f);
}

function makedeletelist(f,n)
{
  	var list;
   var first;
   var mytmp
   var mymsg;

   first = 1;

   mymsg = "";
  	for ( k=1; k <= n; k++)
		{
      v = eval ("document.form1.CB"+k+".checked");
      if ( v)
         {
         op = eval("document.form1.CB"+k+".value");
         if ( first)
            {
            list = op;
            mytmp  = op;
            first = 0;
            }
         else
         	{
         	list = list + "=" + op;
            mytmp= mytmp + " \n" + op;
            }
         }
      }
	document.form1.userlist.value = list;
   if ( list.length)
   	{

      mymsg ="Are you sure you want to delete the user(s) below?:\n"+ mytmp + "\n\n";
      mymsg += "\nDelete ?\n";
      if ( confirm(mymsg))
      	return true;
      else
         return false;
      }
     else
     	  return false;
}

function clicie() {
 // Fonction de détection pour Internet Explorer
 if (event.button==2) {
  alert("Thanks for visiting World_Data_Trust Site");
 }
}

function clicns(e){
 // Fonction pour Netscape
 if (e.which==3){
   alert("Thanks for visiting World_Data_Trust Site");
   return false;
 }
}

function MaskRightClick(msg)
{
	if (document.all)
	   {
	   document.onmousedown=clicie;
	   }
	if (document.layers)
	   {
      alert("Right click");
	   document.captureEvents(Event.MOUSEDOWN); document.onmousedown = clicns;
	   }
}

function prepareUrl()
{
selection = document.form1.Urls.options[document.form1.Urls.selectedIndex].value;
document.form1.chemin.value = selection;
}

function sendme()
{
location.replace( document.form1.chemin.value);
}
