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 password = "";
	
    // Loop through the elements of the form, looking for all
    // text and textarea elements that don't have an "optional" property
    // defined. Then, check for fields that are empty and make a list of them.
    // Also, if any of these elements have a "min" or a "max" property defined,
    // then verify that they are numbers and that they are in the right range.
    // Put together error messages for fields that are wrong.

    for(var i = 0; i < f.length; i++) 
	{
        var e = f.elements[i];


        if (((e.type == "text") || (e.type == "textarea") || (e.type == "password")) && (e.optional != undefined) && (!e.optional))
        {

            // first check if the field is empty
            if ((e.value == null) || (e.value == "") || isblank(e.value))
            {
                empty_fields += "\n          " + e.name;
                continue;
            }


            // Now check for fields that are supposed to be email addresses.
            if ((e.type == "text")  && e.email)
            {
              var s = e.value;
              var res = s.match(/^(\w|\.|\-|\_){1,}@\w{1,}\.(\w|\.|\-|\_){1,}$/);
              if (res == null)
                errors += e.name + " is not a valid email format (eg name@server.domain)\n";				
            }
			
			// Now check for regular expressions			
            var z = e.reg
			//alert("z:"+z );
            if (z != null)
			{
			  {
                var s = new String(e.value);
				var r = e.reg;
			    var res2 = s.match(r);
			    if (res2 == null)
			    {
                   errors += e.name + " is not a valid pattern must be " + e.regpattern +"\n";				
			    }
			  }
			}
            // Now check if password or confirm password
            if ((e.type == "password")  && e.P1)
            {
              password = e.value;
			}
            if ((e.type == "password")  && e.P2)
            {
              if (password != e.value)
			  {
			    errors += "Password and Confirm Password are not the same \n";
			  }
			}
        }
    }
	
	

    // Now, if there were any errors, display the messages, and
    // return false to prevent the form from being submitted.
    // Otherwise return true.

    if (!empty_fields && !errors) return true;

    msg  = "______________________________________________________\n\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\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;
}

