	
	is={
		obj:function(o){
			return typeof o =='object';
		},
		func:function(f){
			return typeof f == 'function';
		}
	}
	
	function copyproperties(source,destination,skipkeys){
		for(var k in source)if(!skipkeys || !skipkeys[k])destination[k]=source[k];
	}
	
	function makeClass(){
		var copyproperties=function(source,destination,skipkeys){
			for(var k in source)if(!skipkeys || !skipkeys[k])destination[k]=source[k];
		}
		var skip_in_transcription = {'prototype':true,makeSingleton:true,inst:true,singletonMode:true};
		
		var classfunc=function(){
			var callee=arguments.callee;
			
			if(!callee.prototypeTranscribed)copyproperties(callee,callee.prototype,skip_in_transcription);
			callee.prototypeTranscribed=true;
					
			if(!callee.singletonMode)
				if(this.init)
					this.init.apply(this,arguments);
		};
		
		classfunc.makeSingleton = function(){
			//this === classfunc - TRUE;
			if(this.singletonMode)return;//bo juz jest jeden singleton
			this.singletonMode=true;
			this.inst = new classfunc();
			if(this.prototype.init)this.prototype.init.apply(this.inst,arguments);
		};
		
		for(var i=0;i<arguments.length;i++){
			var src=arguments[i];
			if(is.obj(src))copyproperties(src,classfunc.prototype);
			else if(is.func(src)){
				if(src.makeSingleton && !src.prototypeTranscribed){
					copyproperties(src,src.prototype,skip_in_transcription);
					src.prototypeTranscribed=true;
					//jezeli instancja tej klasy tj arguments[i] nie zostala jeszcze stworzona ani razu to jej metody 
					//nie zostaly jeszcze transcrybowane na prototype! tutaj to robimy przyklad: addon.somemetod
				}
				copyproperties(src.prototype,classfunc.prototype);
			}
		}
		return classfunc;
	}
	
	cookieJar={
	
		initialized:false,
		flash_name:'flashcookie',
		
		init:function(){
			this.initialized=true;
			//this.cookie2flashcookie();
		},
		
		
		cookie2flashcookie:function(){
			if(document.cookie.length>0){
				var src=document.cookie.substring(0,document.cookie.length);
				src=src.split(';');
				for(var i=0;i<src.length;i++){
					var nv=src[i].split('=');
					//console.log(nv[0],'-->',unescape(nv[1]));
				}
			}
		},
		
		get:function(c_name){
			if(!this.initialized)this.init();
			
			if (document.cookie.length>0)
  			{
  				var c_start=document.cookie.indexOf(c_name + "=");
  				if (c_start!=-1)
    			{ 
	    			c_start=c_start + c_name.length+1; 
    				var c_end=document.cookie.indexOf(";",c_start);
    				if (c_end==-1) c_end=document.cookie.length;
    				return unescape(document.cookie.substring(c_start,c_end));
    			} 
  			}
			return "";
		},
		
		set:function(c_name,value,expiredays){
			if(!this.initialized)this.init();
			
			var exdate=new Date();
			exdate.setDate(exdate.getDate()+expiredays);
			document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
		},
		
		destroy:function(c_name)
		{
			this.set(c_name,'',-99);
		}	
	}
	
	function expand_object(obj1,obj2)
	{
		for(var x in obj2)if(!obj1[x])obj1[x]=obj2[x];
		return obj1;	
	}
	
	
	assoc={
		count:function(obj){
			if(!is.obj(obj))return 0;
			var counter=0;
			for(var k in obj)counter++;
			return counter;
		},
		keys:function(obj){
			var res=[];
			var c=0;
			if(is.obj(obj))for(var k in obj)res[c++]=k;
			return res;
		},
		values:function(obj){
			var res=[];
			var c=0;
			if(is.obj(obj))for(var k in obj)res[c++]=k;
			return res;
		},
		first:function(obj){
			var res=[];
			if(is.obj(obj))
				for(var k in obj){
					res[0]=k;
					res[1]=obj[k];
					return res;
				}
			return res;
		},
		last:function(obj){
			
		},
		map:function(obj,callback){
			if(is.obj(obj) && is.func(callback))
				for(var k in obj)obj[k]=callback(k,obj[k]);
			return obj;
		}
	}
	
	function count_keys(obj)
	{
		var counter=0;
		for(var x in obj)counter++;
		return counter;	
	}
	
	function obj_keys(obj)//albo dac do prototype jako getKeys()
	{
		var res=[];
		if(obj)for(var key in obj)res.push(key);
		return res;
	}
	
	function obj_values(obj)//albo dac do prototype jako getValues()
	{
		var res=[];
		for(var key in obj)res.push(obj[key]);
		return res;
	}
	

	function print_var(obj)
	{
		var out='';
		for(k in obj)out+=k+' ('+(typeof obj[k])+') >>> '+obj[k]+'\n';
		alert(out);
	}
	
	function set_display(id,visible)
	{	
		if(typeof id=='string')id=[id];
		else if(!(id instanceof Array))return;
		var el;
		for(var i=0;i<id.length;i++)
		{
			el=document.getElementById(id[i]);
			if(!el)continue;
			if(visible===undefined)el.style.display=(el.style.display=='none')?'block':'none';
			else if(visible===true)el.style.display='block';
			else if(visible===false)el.style.display='none';
		}
	}
		
	
	function createDOM(tagdef,properties,objcontent,iteration_data)
	{
		
		var first_element=null,temp=null,child_tags=[],child_properties={},table_tag=false;
			
		var is_dom_el = function(obj){return ((obj!=null) && (typeof obj=="object") && (obj.appendChild!=null))}
		
		var parse_tag = function(tag)
		{
			//alert(tag);
			var res={name:'',classname:'',id:'',title:'',html:''};
			var match=tag.match(/^\s*([a-zA-Z]+[1-6]?){1}\s*(\..+?)?\s*(\#.+?)?\s*(\^.+?)?\s*(\=.+?)?\s*$/);
			if(match==null)return res;
			if(match[1]!=undefined)res.name=match[1].toUpperCase();
			if(match[2]!=undefined)res.classname=match[2].substr(1);
			if(match[3]!=undefined)res.id=match[3].substr(1);
			if(match[4]!=undefined)res.title=match[4].substr(1);
			if(match[5]!=undefined)res.html=match[5].substr(1);
			return res;
		}
		
		var create_element = function(tag_obj,parentobj)
		{
			//alert(tag_obj.name);
			
			if(tag_obj.name.indexOf('INPUT')==0 && tag_obj.name.length>7)tag_obj.name=tag_obj.name.substr(6);
			
			
			var temp;
			if(tag_obj.name=='CHECKBOX' || tag_obj.name=='RADIO' || tag_obj.name=='TEXT' || tag_obj.name=='FILE' || tag_obj.name=='SUBMIT' || tag_obj.name=='RESET')
			{
				try
				{
					temp=document.createElement('<input type="'+tag_obj.name+'"/>');
				}
				catch(err)
				{
					temp=document.createElement('input');
					temp.setAttribute('type',tag_obj.name);
				}
					temp.is_input_field=true;
				
			}
			else  temp=document.createElement(tag_obj.name);
			
			if(!is_dom_el(temp))return null;
			
			if(tag_obj.id)
			{
				if((iteration_data!=null) && (tag_obj.id.indexOf('$')>0))tag_obj.id=tag_obj.id.split('$').join(iteration_data.nr);
				temp.setAttribute("id",tag_obj.id);
			}
			if(tag_obj.classname)
			{
				if(iteration_data!=null)
				{
					if(tag_obj.classname.indexOf('%')>0)tag_obj.classname=tag_obj.classname.split('%').join((iteration_data.nr%2)?'_even':'_odd');
					if(tag_obj.classname.indexOf('$$')>0)tag_obj.classname=tag_obj.classname.split('$$').join((iteration_data.nr==0)?'_first':((iteration_data.nr==(iteration_data.count-1))?'_last':''));
				}
				temp.className=tag_obj.classname;
			}
			if(tag_obj.title.length)temp.setAttribute('title',tag_obj.title);
			if(tag_obj.html.length)
			{
				if(temp.is_input_field==true)temp.value=tag_obj.html;
				else temp.innerHTML=tag_obj.html;
			}
			
			temp.appendMe=temp.addMe=function(parentobj)
			{
				if(typeof parentobj=="string"){if(parentobj.indexOf('#')==0)parentobj=parentobj.substr(1);parentobj=document.getElementById(parentobj);}
				if(is_dom_el(parentobj)){
					parentobj.appendChild(this);
					//if(window.update_parent_height)window.update_parent_height();
				}
				return this;
			}
			temp.prependMe=function(parentobj)
			{
				if(typeof parentobj=="string"){if(parentobj.indexOf('#')==0)parentobj=parentobj.substr(1);parentobj=document.getElementById(parentobj);}
				if(is_dom_el(parentobj))
				{
					if(parentobj.hasChildNodes())parentobj.insertBefore(this,parentobj.firstChild);
					else parentobj.appendChild(this);
					//if(window.update_parent_height)window.update_parent_height();
				}
				return this;
			}
			
			if(parentobj!=null)parentobj.appendChild(temp);
			return temp;
		}
		
		if((properties instanceof Array) || (typeof properties=="function") || (is_dom_el(properties)))
		{
			objcontent=properties;
			properties={};
		}
		
		if(tagdef.indexOf('{')>0)
		{
			var wrap_tags = tagdef.split('{');
			var wrap_el=null;
			wrap_el=first_element=create_element(parse_tag(wrap_tags.shift()));
			tagdef=wrap_tags.pop();
			for(var i=0;i<wrap_tags.length;i++)wrap_el=create_element(parse_tag(wrap_tags[i]),wrap_el);
		}
		
		if(tagdef.indexOf('}')>0)
		{
			child_tags = tagdef.split('}');
			tagdef=child_tags.shift();
		}
		
		var tag=parse_tag(tagdef);
		table_tag=((tag.name=='TBODY') || (tag.name=='THEADER') || (tag.name=='TFOOTER') || (tag.name=='TABLE'));
		if(child_tags.length)
		{
			if(table_tag)
			{
				if(!child_tags[1])child_tags[1]='TD';
				else if(child_tags[1].indexOf('(')>0)child_tags[1]=child_tags[1].split('(').join('{');
			}
			else if(child_tags[0].indexOf('(')>0)child_tags[0]=child_tags[0].split('(').join('{');
		}
		
		if(temp==null)
		{
			if((wrap_el!=undefined) && (wrap_el!=null))
				temp=create_element(tag,wrap_el);
			else
				first_element=temp=create_element(tag);
		}
		
		for(var prop in properties)if(properties[prop]!=null)
		{
			if((prop=='child') && (typeof properties[prop]=='object'))child_properties=properties[prop];
			else if(prop=='$focus'){if(properties[prop]==true && temp.focus)temp.focus();} 
			else if((prop=='onclick') && ((temp.tagName=='a') || (temp.tagName=='A')) && (properties['href']==undefined)){temp.onclick=properties[prop];temp.setAttribute('href','javascript:void(null)');}
			else if((typeof properties[prop]=='function') || (prop=='id'))temp[prop]=properties[prop];
			else if(prop=='style')temp.style.cssText=properties[prop];
			else if((prop=='class') || (prop=='classname') || (prop=='className'))temp.className=properties[prop];
			else if(prop=='html')temp.innerHTML=properties[prop];
			else if((prop.charAt(0)=='$') && (typeof properties[prop]=='string'))temp.style.cssText=temp.style.cssText+' '+prop.substr(1).split('_').join('-')+':'+properties[prop]+';';
			else if(prop.substr(0,4)=='var_')temp[prop.substr(4)]=properties[prop];
			else if(typeof properties[prop]=='string')temp.setAttribute(prop,properties[prop]);
			//tutaj trzeba dodac opcje do ustawiania pojedynczych wartosci stylu
		}
			
		if (objcontent==null){}
		else if(typeof objcontent=="function"){temp.onclick=objcontent; if((temp.tagName=='a') || (temp.tagName=='A'))temp.setAttribute('href','javascript:void(null)');}
		else if(is_dom_el(objcontent))temp.appendChild(objcontent);
		else if(child_tags.length && (objcontent instanceof Array))
		{
			if(table_tag && (objcontent[0] instanceof Array))
			{
				var oldtemp=temp;
				if(tag.name=='TABLE')
				{
					var temp2=document.createElement('TBODY');
					temp.appendChild(temp2);
					temp=temp2;
				}
				for(var i=0,c=objcontent.length;i<c;i++)
					if(objcontent[i] instanceof Array)
					{
						var tr=createDOM(child_tags[0],{},[],{nr:i,count:c,tr:0}).appendMe(temp);
						for(var j=0,c2=objcontent[i].length;j<c2;j++)
						{	
							if((typeof objcontent[i][j]=="object") || (typeof objcontent[i][j]=="function"))
								createDOM(child_tags[1],child_properties,objcontent[i][j],{nr:j,count:c2,tr:i}).appendMe(tr);
							else if((typeof objcontent[i][j]=="string") || (typeof objcontent[i][j]=="number"))
								createDOM(child_tags[1],child_properties,{},{nr:j,count:c2,tr:i}).appendMe(tr).wrapped_element.innerHTML=objcontent[i][j]+'';
						}
					}
				temp=oldtemp;
			}
			else 
				for(var i=0,c=objcontent.length;i<c;i++)
				{
					if((typeof objcontent[i]=="object") || (typeof objcontent[i]=="function"))
						createDOM(child_tags[0],child_properties,objcontent[i],{nr:i,count:c,tr:0}).appendMe(temp);
					else if((typeof objcontent[i]=="string") || (typeof objcontent[i]=="number"))
						createDOM(child_tags[0],child_properties,{},{nr:i,count:c,tr:0}).appendMe(temp).wrapped_element.innerHTML=objcontent[i]+'';
				}
		}
		else if(objcontent instanceof Array)
			for(var i=0,c=objcontent.length;i<c;)
			{
				//tagdef=string, properties=object, content=dom|function|array
				if(objcontent[i] == undefined)break;
				else if(is_dom_el(objcontent[i])){temp.appendChild(objcontent[i]);i++;continue;}
				else if(objcontent[i] instanceof Array){createDOM(objcontent[i][0],objcontent[i][1],objcontent[i][2]).appendMe(temp);i++;continue;}
				
				var a2=objcontent[i+1],a3=objcontent[i+2];
				
				if((a2 instanceof Array) || (typeof a2=="function") || is_dom_el(a2))
					{createDOM(objcontent[i],child_properties,a2).appendMe(temp);i+=2;}
				else if(typeof a2=="object")
				{
					if((a3 instanceof Array) || (typeof a3=="function") || is_dom_el(a3))
						{createDOM(objcontent[i],a2,a3).appendMe(temp);i+=3;}
					else
						{createDOM(objcontent[i],a2,[]).appendMe(temp);i+=2;}
				}
				else if(typeof objcontent[i]=="string")
					{createDOM(objcontent[i],child_properties,[]).appendMe(temp);i++;}
				else continue;
			}
		
		first_element.wrapped_element=temp;
		return first_element;
	}
	
	
function fieldSelection(field, start, end) {
	//opera.postError(field.createTextRange,field.setSelectionRange,field.selectionStart);
	//w operze trzeba bylo zmienic kolejnosc aby sie nie pieprzylo ustawianie
	if( field.setSelectionRange ){
		field.setSelectionRange(start, end);
	}
	else if( field.createTextRange ){
		var selRange = field.createTextRange();
		selRange.collapse(true);
		selRange.moveStart("character", start);
		selRange.moveEnd("character", end);
		selRange.select();
	} else {
		if( field.selectionStart ){
			field.selectionStart = start;
			field.selectionEnd = end;
		}
	}
	//field.focus();
};
	