function CustomForm()
{
	function getFormIfExists(form_id)
	{
		var cForm = $(form_id);
		if (!cForm)
		{
			alert('no such DOM elements: ' + form_id);
			return false;
		}
	
		if (cForm.nodeName.toLowerCase() != "form")
		{
			alert('this Dom elements is not a FORM type = ' + cForm.nodeName);
			return false;
		}
		return cForm;
	}
	
	/**
	 * 
	 * @param {String} formID
	 * @param {Object} oProp {incl: ['select', 'input']} or {excl: ['textarea']}
	 */
	this.getElements = function(formID, oProp)
	{
		var cForm = getFormIfExists(formID);
		if (!cForm)
			return false;
		
		var aOutput = [];
		for (var i = 0; i < cForm.length; i++)
		{
			var el = cForm.elements[i];
			if (el.name == "")
				continue;
				
			if (oProp.incl)
			{
				for (var j = 0; j < oProp.incl.length; j++)
				{
					if (oProp.incl[j].toLowerCase() == el.nodeName.toLowerCase())
						aOutput.push(el);
				}
			}
			else if (oProp.excl)
			{
				for (var j = 0; j < oProp.excl.length; j++)
				{
					if (oProp.excl[j].toLowerCase() != el.nodeName.toLowerCase())
						aOutput.push(el);
				}
			}
		}
		return aOutput;
		
	}
	
	/**
	 * Check, if the form has needed name
	 * @param {String} formID Form id, where to find element
	 * @param {String} name Needed form element name
	 * @return {Mixed} if form hasn't name then false, else FORM element
	 */
	this.hasElemByName = function(formID, name)
	{
		var cForm = getFormIfExists(formID);
		if (!cForm)
			return false;
		
		for (var i = 0; i < cForm.length; i++)
		{
			var el = cForm.elements[i];
			if (!el.name || (el.name != name))
				continue;
			
			return el;
		}
		return false;
	}
	
	this.setPropByName = function(formID, name, new_val)
	{
		var cForm = getFormIfExists(formID);
		if (!cForm)
			return false;

		for (var i = 0; i < cForm.length; i++)
		{
			var el = cForm.elements[i];
			if (!el.name || (el.name != name))
				continue;
			
			el.value = new_val;
			return true;
		}
		return false;
	}
	
	this.setPropById = function(formID, id, new_val)
	{
		var cForm = getFormIfExists(formID);
		if (!cForm)
			return false;

		for (var i = 0; i < cForm.length; i++)
		{
			var el = cForm.elements[i];
			if (!el.id || (el.id != id))
				continue;
				
			el.value = new_val;
			return true;
		}
		return false;
	}
	
	
	this.getPropByName = function(formID, name)
	{
		var cForm = getFormIfExists(formID);
		if (!cForm)
			return false;

		for (var i = 0; i < cForm.length; i++)
		{
			var el = cForm.elements[i];
			if (!el.name || (el.name != name))
				continue;
			
			return el.value;
		}
	}
	
	this.getPropById = function(formID, id)
	{
		var cForm = getFormIfExists(formID);
		if (!cForm)
			return false;

		for (var i = 0; i < cForm.length; i++)
		{
			var el = cForm.elements[i];
			if (!el.id || (el.id != id))
				continue;
				
			return el.value;
		}
	}
	/**
	 * Enable/Disable all buttons in <form>
	 * @param {String} formID <form> elements ID attribute
	 * @param {String} state Can be "ON"/"OFF"
	 */
	this.switchAllButtons = function (formID, state)
	{
		var cForm = getFormIfExists(formID);
		if (!cForm)
			return false;

		for (var i = 0; i < cForm.length; i++)
		{
			var el = cForm.elements[i];
			if (!el.type)
				continue;
			
			if (el.type == 'button' || el.type == 'submit' || el.type == 'reset')
			{
				if (state == 'OFF')
				{
					el.setAttribute('disabled', 'disabled');
				}
				else if (state == 'ON')
				{
					if (el.disabled)
						el.removeAttribute('disabled');
				}
			}
		}
		return true;
	}
	
	/**
	 * Enable/Disable all buttons in <form>
	 * @param {String} formID <form> elements ID attribute
	 * @param {String} buttonId Button Id
	 * @param {String} state Can be "ON"/"OFF"
	 */
	this.switchButton = function(formID, buttonId, state)
	{
		var cForm = getFormIfExists(formID);
		if (!cForm)
			return false;

		for (var i = 0; i < cForm.length; i++)
		{
			var el = cForm.elements[i];
			if (!el.type)
				continue;
			
			if ((el.type == 'button' || el.type == 'submit' || el.type == 'reset') && (el.id == buttonId))
			{
				if (state == 'OFF')
				{
					el.setAttribute('disabled', 'disabled');
				}
				else if (state == 'ON')
				{
					if (el.disabled)
						el.removeAttribute('disabled');
				}
			}
		}
		return true;
	}
	
	/**
	 * Enable/Disable all checkboxes
	 * @param {String} formID <form> elements ID attribute
	 * @param {String} state can be only "ON", "INVERT", "OFF"
	 * @return {Boolean} Check results
	 */
	this.switchAllBoxes = function(formID, state)
	{
		var cForm = getFormIfExists(formID);
		if (!cForm)
			return false;

		for (var i = 0; i < cForm.length; i++)
		{
			var el =  cForm.elements[i];
			if (!el.type)
				continue;
			
			if (el.type == 'checkbox')
			{
				if (el.checked && state == 'OFF')
					el.checked = false;
				else if (!el.checked && state == 'ON')
					el.checked = true;
				else if (el.checked && state == 'INVERT')
					el.checked  = false;
				else if (!el.checked && state == 'INVERT')
					el.checked  = true;
			}
		}
		return true;
	}
}

var FormControl = new CustomForm();