
	function CheckElement(Form, strName, strType, strErrMsg) // Constructor
	{
		this.Form = Form;
		this.strName = strName;
		this.strType = new String(strType);
		this.strErrMsg = strErrMsg;
		this.arrSubElms = new Array();
	}

	CheckElement.prototype.Element = function() // DOM element - form element or null
	{
		if (this.Form.Form())
		{
			var Elm = this.Form.Form().elements[this.strName];
			/*if (Elm.options)
			{
				Elm = Elm.options[Elm.options.selectedIndex];
			}*/
			return Elm;
		} else {
			return null;
		}
	}

	CheckElement.prototype.Check = function() // String
	{
		if (this.Element())
		{
			var EmailPattern = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
			if (!isNaN(parseInt(this.strType)) && this.Element().value.length < parseInt(this.strType))
			{
				return this.strErrMsg;
			} else if (this.strType == "number" && isNaN(parseInt(this.Element().value))) {
				return this.strErrMsg;
			} else if (this.strType == "email" && !EmailPattern.test(this.Element().value)) {
				return this.strErrMsg;
			} else if (this.strType == "checkbox" && !this.Element().checked) {
				return this.strErrMsg;
			} else if (this.strType.substring(0,9) == "password:") {
				var strPassword = "";
				var Password = this.Element().form;
				if (Password) Password = Password.elements[this.strType.substring(9)];
				if (Password) strPassword = Password.value;
				if (this.Element().value == strPassword)
				{
					return "OK";
				} else {
					return this.strErrMsg;
				}
			//} else if (this.strType.substring(0,6) == "value:" && this.Element().value != this.strType.substring(6)) {
			//	return this.strErrMsg;
			} else {
				return "OK";
			}
		} else {
			return "OK";
		}
	}




	function CheckForm(strFormName) // Constructor
	{
		this.strFormName = strFormName;
		this.arrElms = new Array();
		this.bolSubmit = false;
	}

	CheckForm.prototype.Form = function() // DOM element - form element or null
	{
		var Form = document.forms[this.strFormName];
		if (Form)
		{
			return Form;
		} else {
			return null;
		}
	}

	CheckForm.prototype.AddElm = function(strName, strType, strErrMsg) // Void
	{
		var Elm = new CheckElement(this, strName, strType, strErrMsg);
		if (arguments.length > 3)
		{
			var strSubName = null;
			var strSubType = null;
			Elm.arrSubElms = new Array();
			for (var a = 3; a < arguments.length; a++)
			{
				if (strSubName && strSubType)
				{
					Elm.arrSubElms[Elm.arrSubElms.length] = new CheckElement(this, strSubName, strSubType, arguments[a]);
					strSubName = null;
					strSubType = null;
				} else if (strSubName) {
					strSubType = arguments[a];
				} else {
					strSubName = arguments[a];
				}
			}
		}
		this.arrElms[this.arrElms.length] = Elm;
	}

	CheckForm.prototype.Check = function() // Boolean
	{
		var strErrorMsg = "";
		var FirstErrorElm = null;
		if (this.Form())
		{
			for (var a = 0; a < this.arrElms.length; a++)
			{
				if (this.arrElms[a].Element())
				{
					if (this.arrElms[a].arrSubElms.length > 0 && this.arrElms[a].Check() == "OK")
					{
						var strSubErrorMsg = "";
						for (var b = 0; b < this.arrElms[a].arrSubElms.length; b++)
						{
							if (this.arrElms[a].arrSubElms[b].Check() != "OK") strSubErrorMsg += "    -  " + this.arrElms[a].arrSubElms[b].Check() + "\n";
						}
						if (strSubErrorMsg.length > 0) strErrorMsg += "  *  " + this.arrElms[a].strErrMsg + "\n" + strSubErrorMsg;
					} else if (this.arrElms[a].arrSubElms.length <= 0) {
						if (this.arrElms[a].Check() != "OK") strErrorMsg += "  *  " + this.arrElms[a].Check() + "\n";
						if (strErrorMsg.length > 0 && !FirstErrorElm) FirstErrorElm = this.arrElms[a].Element();
					}
				}
			}
		} else {
			strErrorMsg += "  *  Formuläaret som skulle skickas saknas.\n";
		}
		if (strErrorMsg.length > 0)
		{
			alert("Formuläret kunde inte skickas p g a dessa fel:\n" + strErrorMsg);
			if (FirstErrorElm) FirstErrorElm.focus();
			return false;
		} else {
			return true;
		}
	}

	CheckForm.prototype.Submit = function() // Boolean
	{
		if (this.Check())
		{
			if (!this.bolSubmit && this.Form())
			{
				this.bolSubmit = true;
				//this.Form().submit();
				return true;
			} else {
				return false;
			}
		} else {
			this.bolSubmit = false;
			return false;
		}
	}
