function createForm(id,view,byname){

	var obj=createNodeByArray.v1.d;
	var root=createNodeByArray.d;

	function label(caption){
		return obj('label',['span',{getValue:function(){return this.firstChild.nodeValue;}},caption]);
	}

	var base={
		toText:function(){
			with(this.parentNode) while(childNodes.length>2) removeChild(childNodes[1]);
			this.style.display='';
		},
		toForm:function(){
			var cont=this;
			this.value.replace(/\/\* +field +(\w+) +"([^"]+)" +\*\/((?:[^\/]|\/(?!\* +\/field +\*\/))*)\/\* +\/field +\*\//g,
				function(str,id,caption,code){
					cont.parentNode.insertBefore(scriptfield(cont,id,caption,code),cont);
				}
			);
			this.value.replace(/<!-- +field +(\w+) +"([^"]+)" +(\d+) +-->((?:[^<]|<(?!!-- +\/field +-->))*)<!-- +\/field +-->/g,
				function(str,id,caption,height,value){
					cont.parentNode.insertBefore(field(cont,id,caption,cont.style.width,height+'px',value),cont);
				}
			);
			this.style.display='none';
		}
	};
	
	if(byname) base=root([document.getElementsByName(id)[0],base]);
	else base=root([document.getElementById(id),base]);

	var ctrl=root(['a',{
		href:'#',style:{display:'block'},
		base:base,status:0,
		caption:['Классический вид','Развёрнутый вид'],
		metod:['toText','toForm'],
		order:[1,0],
		setStatus:function(q){
			if(q!=this.status){
				(this.base[this.metod[q]])();
				this.firstChild.nodeValue=this.caption[this.order[q]];
				this.status=q;
			}
		},
		onclick:function(){this.setStatus(this.order[Number(this.status)]);return false;}
	},'Развёрнутый вид']);



	function scriptfield(base,id,caption,code){
		var div=['div',
		{
			id:id,
			base:base,
			writeVar:function(varname,varvalue){
				if(isNaN(Number(varvalue)))varvalue="'"+varvalue+"'";
				this.base.value=this.base.value.replace(
					new RegExp('(\\/\\* +field +'+this.id+' +"[^"]+" +\\*\\/)((?:[^\\/]|\\/(?!\\* +\\/field +\\*\\/))*)\\/\\* +\\/field +\\*\\/'),
					function(str,tag,code){
						return tag+code.replace(
							new RegExp('\\b'+varname+' *= *((?:\\d+|\'[^\']*\')+);'),
							varname+'='+varvalue+';'
						)+'/* /field */';
					}
				);
			}
		},
		label(caption)];
		
		code.replace(/\b(\w+) *= *((?:\d+|'(?:[^']|\')*')+); *\/\*((?:[^*]|\*(?!\/))+)\*\//g,
			function(str,varname,varvalue,varcaption){
				varvalue=varvalue.replace(/^('|")(.*)\1$/,'$2');
				div.push(obj(varname,['div',,varcaption,obj('text',['input',{
					id:id+'_'+varname,
					varname:varname,
					value:varvalue,
					onchange:function(){
						this.container.container.writeVar(this.varname,this.value);
					}
				}])]));
			}
		);
		var vari=div[3];
		div=root(div);
		return div;
	}
	
	function field(base,id,caption,width,height,value){
		return root(['div',
			{
				id:id,
				base:base,
				writeSize:function(){
					this.base.value=this.base.value.replace(
						new RegExp('<!-- +field +'+this.id+' +"[^"]+" +\\d+ +-'+'->'),
						'<!-- field '+this.id+' "'+this.label.getValue() +'" '+parseInt(this.textarea.style.height)+' -'+'->'
					);
				},
				writeText:function(){
					this.base.value=this.base.value.replace(
						new RegExp('<!-- +field +'+this.id+' +"[^"]+" +\\d+ +-'+'->(?:[^<]|<(?!!-- +\\/field +-'+'->))*<!-- +\\/field +-'+'->'),
						'<!-- field '+this.id+' "'+this.label.getValue() +'" '+parseInt(this.textarea.style.height)+' -'+'->'+this.textarea.value+'<!-- /field -'+'->'
					);
				}
			},
			label(caption),
			' ',
			obj('plus',['a',{href:'#',onclick:function(){this.container.textarea.heightPlus(50);return false;}},'+']),
			' ',
			obj('minus',['a',{href:'#',onclick:function(){this.container.textarea.heightPlus(-50);return false;}},'-']),
			obj('textarea',['textarea',{
				style:{width:width,height:height,display:'block'},
				value:value,
				heightPlus:function(number){
					this.style.height=(parseInt(this.style.height)+number)+'px';
					this.container.writeSize();
				},
				onchange:function(){
					this.container.writeText();
				}
			}])
		]);
	}

	base.parentNode.insertBefore(ctrl,base);
	ctrl.setStatus({text:0,form:1}[view]);
}
