	function ValidateInputText(Control, Datatype, Message, Min, Max, Required)
	{
		if( Required == "undefined")
			Required = false
		var ControlValue = Control.value
		//checks if required, exits if not and field is empty.
		if( Required == true && ControlValue.length == 0)
		{	
			AlertFocus(Control, Message)
			return false
		}
		if( Required != true && ControlValue.length == 0)
		{	
			return true
		}
		
		//checks datatype and performs necessary validation
		switch(Datatype)
		{
			case "integer":
				var valid = "0123456789"
				var temp;
				for (var i=0; i<ControlValue.length; i++) 
					{
					temp = "" + ControlValue.substring(i, i+1);
					if (valid.indexOf(temp) == "-1")
						{
						AlertFocus(Control, "This field must be a number")
						return false
						}
					}
			
			
				var MinMessage = Message + "\nIt must be at least " + Min
				var MaxMessage = Message + "\nIt can not be greater than " + Max
				if (Min != "")
				{
					if(ControlValue < Min)
					{
						AlertFocus(Control, MinMessage)
						return false
					}
				}
				if (Max != "")
				{
					if(ControlValue > Max)
					{
						AlertFocus(Control, MaxMessage)
						return false
					}
				}
				break;

			case "email":
				if (!ControlValue.match(/^\S+\@\S+\.\S+$/ig))
				{
					AlertFocus(Control, "Invalid Email Address.")
					return false
				}
				return StringLengthValidation(Control, Message, Min, Max)
				break;
				
			case "string":
				return StringLengthValidation(Control, Message, Min, Max)
				break;
				
			case "time":
				var timePat = /^(\d{1,2}):(\d{2})?$/;
	
				var matchArray = ControlValue.match(timePat);
				if (matchArray == null) 
				{			
					if(Required != "Required")
					{
						AlertFocus(Control, Message)
						return false
					}
					else
					{
						AlertFocus(Control, "Time is not in a valid format.\nExample format: 8:00")
						return false
					}
				}
				hour = matchArray[1];
				minute = matchArray[2];
				
				if (hour < 0  || hour > 12) 
				{
					AlertFocus(Control, "Time is not in a valid format.\nHour must be between 1 and 12.")
					return false
				}
				if (minute<0 || minute > 59) 
				{
					AlertFocus(Control, "Time is not in a valid format.\nMinute must be between 0 and 59.")
					return false
				}
				break;
		}
		return true
	}
	
	function StringLengthValidation(Control, Message, Min, Max)
	{
		var len = Control.value.length
		var MinMessage = Message + "\nIt must contain at least " + Min + " characters."
		var MaxMessage = Message + "\nIt can not contain more than " + Max + " characters."
		if (Min != "")
	  	{
	    	if(len < Min)
	        {
				AlertFocus(Control, MinMessage)
				return false
			}
		}
		if (Max != "")
	  	{
			if(len > Max)
	        {
				AlertFocus(Control, MaxMessage)
				return false
			}
		}
		return true
	}
	
	function AlertFocus(Control, Message)
	{
		try
		{
			alert(Message)
			Control.focus()
		}
		catch(e)
		{
			if(e.number!=-2146826178)
				alert("Having a problem performing alerting and focusing on form validation\n " + e.description)	
		}
	}
