var jssMainErrorMessage = "Please make sure the form is completely filled out before hitting the submit button!";
function formObject(formname)
	{
		this.setFsubmitHandler = function ()
			{
				this.oformname.onsubmit = this.submitHandler;
				this.oformname.checkAllFilelds = checkAllFilelds;
			}
		function checkAllFilelds ()
			{/*Function that executes on submit form action*/
				function ElementProperty(oElement)
					{/*Get value of specific attributes for form element*/
						var a = 
							{
							check 		: oElement.getAttribute('check'),
							require 	: oElement.getAttribute('require'),
							regcheck 	: oElement.getAttribute('regcheck')
							};

						return a;
					}
				function returnError(oElement)
					{/*Set style to error element*/
						with(oElement.style){
							//borderWidth = 	'1px';
							//borderColor = 	'red';
							//borderStyle =	'dotted';
							backgroundColor = '#DDDDDD';
							}
					}
				function returnOk(oElement)
					{/*Set style to error element*/
						with(oElement.style){
							//borderWidth = 	'';
							//borderColor = 	'';
							//borderStyle =	'';
							backgroundColor = '#FFFFFF';
							}
					}
				function checkField(oElement)
					{/*This function execute inside the form object, so be carefull when you change it.
						It mean that this - is the form link*/
						var oEProp = ElementProperty(oElement);
						var tagName = oElement.tagName.toLowerCase();
						elementType = (curantElement.type == "textarea") ? "text" : curantElement.type;
						//alert(elementType);
						if (oEProp.check != null && oEProp.check == 'true' && oEProp.require != null && oEProp.regcheck != null
								&& (tagName == "input" || tagName == "textarea" || tagName == "select"))
							{
								switch (elementType)
									{
										case 'text':
										case 'select-one':
											if(oEProp.require == 'true')
												{
												if (oElement.value.length < 1){
													return false;
													} else {
														if (oEProp.regcheck.length > 0){
															try	{
																eval ('regExpr=/^'+oEProp.regcheck+'$/');
																return (oElement.value.match(regExpr)==null)?false:true;
																} catch(e){
																	//alert(e);
																	}
															}
														}
												} else {
													if (oElement.value.length == 0){
														return true;
														} else {
															try	{
																eval ('regExpr=/^'+oEProp.regcheck+'$/');
																return (oElement.value.match(regExpr)==null)?false:true;
																} catch(e){
																	//alert(e);
																	}
															}
													}
											break;
                                        case 'checkbox':
                                            if(oEProp.require == 'true' && oElement.checked == false){
                                                return false;
											}
										default :
											return true;
									}
							}
						return true;
					}
				
				var length = this.elements.length;
				var correct = true;
				for(i=0;i<length;i++)
					{
						var curantElement = this.elements[i];
						var returnCheck =checkField(curantElement);
						if (returnCheck == false){
							returnError(curantElement);
							} else {
								returnOk(curantElement);
								}
						correct = correct && returnCheck;
					}
				if (correct==true){
					return true;
					} else {
						alert(jssMainErrorMessage);
						return false;
						}
			}
		this.submitHandler = function ()
			{
				return this.checkAllFilelds();
			}
		
		this.oformname = document.getElementById(formname);
		this.setFsubmitHandler();
	}