
    function validate(controls, displayNames, validationTypes)
    {
       var errorMessage = "";
       var beginningMessagePart = "Please check the following: \n";
       var requiredMessagePart = " is required.";
       var formatMessagePart = " is not in the correct format.";
       var defaultValidation = true;

       if(validationTypes != null)
       {
          if(validationTypes.length > 0)
          {
          	defaultValidation = false;
          }
       }

       for(var i=0;i<controls.length;i++)
       {
         if(defaultValidation == true || validationTypes[i] == "required")
         {
         	if(trimAll(controls[i].value).length == 0)
         	{
        		errorMessage = errorMessage + "\n" + displayNames[i] + requiredMessagePart;
         	}
         }
         else if(validationTypes[i] == "format")
         {
         	 if(trimAll(controls[i].value).length > 0 && isNaN(controls[i].value) == true)
             {
             	errorMessage = errorMessage + "\n" + displayNames[i] + formatMessagePart;
             }
         }
       }

       if(errorMessage.length > 0)
       {
       	errorMessage = beginningMessagePart + errorMessage;
       }

       return errorMessage;

    }


    function trimAll(sString)
    {

       if(sString.length == 0)
       {
        	return sString;
       }

		while (sString.substring(0,1) == ' ')
		{
			sString = sString.substring(1, sString.length);
		}

		while (sString.substring(sString.length-1, sString.length) == ' ')
		{
			sString = sString.substring(0,sString.length-1);
		}

		return sString;

    }