	/*
	*	Class for form's fields check
	*/
	function CheckFields() {

		/*
		*	field types
		*	new field type can be added here with corresponding regular expression
		*/
		this.fieldTypes = { "string" : [ new RegExp("^[A-z0-9À-ÿ]+$"), "Invalid string" ], 
							"email" : [ new RegExp("^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-z]{2,4}$"), "Invalid string" ], 
							"login" : [ new RegExp("^[a-zA-Z0-9.-]+$"), "Invalid string" ], 
							"password" : [ new RegExp("^[a-zA-Z0-9.-]+$"), "Invalid string" ], 
							"datetime" : [ new RegExp("^(19[0-9]{2}|[2-9][0-9]{3})-((0(1|3|5|7|8)|10|12)-(0[1-9]|1[0-9]|2[0-9]|3[0-1])|(0(4|6|9)|11)-(0[1-9]|1[0-9]|2[0-9]|30)|(02)-(0[1-9]|1[0-9]|2[0-9]))\x20(0[0-9]|1[0-9]|2[0-3])(:[0-5][0-9]){2}$"), "Invalid date!" ],
							"double" : [ new RegExp("^-?\d+(\.\d+)?$"), "Invalid double" ],   
							"number" : [ new RegExp("^[0-9]+$"), "Invalid number" ]};
		this.fields = new Array();
		this.result = new Array();
		this.errorColor = "red";
		
		/* 
		* 	function setField
		*	adds form's field that should be checked
		*/
		this.setField = function(id, type, not_null) {
			if(id != undefined && type != undefined) {
				var obj = document.getElementById(id);
				if(obj) {
					this.fields[this.fields.length] = [obj, type];
					obj.num = (this.fields.length - 1);
					obj.check = this.checkField;
					obj.not_null = not_null;
					obj.parent = this;
					
					//	creating error text label
					var errorText = document.getElementById('error_'+id);
					errorText.innerHTML = this.fieldTypes[type][1];
					errorText.style.display = "none";
					obj.errorText = errorText;
					
					obj.onfocus = function(e) { this.style.background = "white"; }
					obj.onblur = function(e) { this.check(this, this.parent); }
				}
			}
		}
		
		/*
		*	function checkField
		*	checks form's input field for correctness
		*/
		this.checkField = function(obj, el) {	
			var parent = el?el:this;
			var res = parent.fieldTypes[parent.fields[obj.num][1]][0].test(obj.value);
			if(!res && !obj.not_null) {
				var re = new RegExp("^[ \t]*$");
				res = re.test(obj.value);
			}
			obj.style.background = res?"white":parent.errorColor;
			obj.errorText.style.display = res?"none":"block";
			return res;
		}
		
		/* 
		* 	function check
		* 	perform check's of form's input fields
		*	returns result in popup (can be changed)
		*/
		this.check = function() {
			var result = true;
			for(var i=0; i<this.fields.length;i++)
			{
				if(!this.checkField(this.fields[i][0], null))
					result = false;
			}
			return result;
		}
		
		/*
		*	function setErrorText
		*	sets text for error messages for scpecific field type
		*/
		this.setErrorText = function(type, message) {
			this.fieldTypes[type][1] = message;
		}
	}

	
	
		function Test(id,type,msg,not_null)
		{
			if(typeof not_null=='undefined') not_null=true;
			var temp = new CheckFields();
			temp.errorColor = "#fbb1c2";
			temp.setErrorText(type, msg);
			temp.setField('r['+id+']', type, not_null);
			temp.check();
		}
		
		function validateField(id, type, notNull)
		{
		}
				
		function check(id,type,msg,t,f) {
			var u = new ajax();
			var elem = document.getElementById('r['+id+']');
			res=u.check_value(id,type,elem.value,t,f);

			if(id=='login')
				(res)?set_false(id,msg):set_true(id);
			else
				(!res)?set_false(id,msg):set_true(id);
		}
		
		function is_confirm(id,cid,msg)
		{
			var iobj = document.getElementById('r['+id+']');
			var cobj = document.getElementById('r['+cid+']');
			
			(cobj.value==iobj.value)?set_true(id):set_false(id,msg);
		}
		
		function set_true(id)
		{
			var div = document.getElementById('error_r['+id+']');
			div.innerHTML = '';
			div.style.display='none';
		}
		
		function set_false(id,msg)
		{
			var div = document.getElementById('error_r['+id+']');
			var elem = document.getElementById('r['+id+']');
			elem.onfocus = function(e) { this.style.background = "white"; }
			elem.style.background="#fbb1c2";
			div.innerHTML = msg;
			div.style.display='block';
		}

		function isempty(id,msg)
		{
			var elem = document.getElementById('r['+id+']');
			(elem.value=='')?set_false(id,msg):set_true(id);
		}
		
		function build_methods(id,id_m) {
			var u = new ajax();
			var elem = document.getElementById(id);
			var to = document.getElementById(id_m);
			p=u.build_m(elem.value);
			to.innerHTML='<select name="r[method_id]" id="r[method_id]">'+p+'</select>';
		}

function build_method(value)
{
        var req = new JsHttpRequest();
        req.onreadystatechange = function()
        {
                if(req.readyState==4)
                        document.getElementById('method_id').innerHTML=req.responseText;
			document.getElementById('parametr').innerHTML='';

        }
        req.open(null, '/tools/build.php?ide=method', true);
        req.send( { q: value } );
}

function build_parametr(value)
{
        var req = new JsHttpRequest();
        req.onreadystatechange = function()
        {
                if(req.readyState==4)
                        document.getElementById('parametr').innerHTML=req.responseText;
        }
        req.open(null, '/tools/build.php?ide=parametr', true);
        req.send( { q: value } );
}