
var BROWSER={
	ie:document.all && !window.opera,
	ie6:navigator.appVersion.indexOf("MSIE 6")!=-1,
	ie7:navigator.appVersion.indexOf("MSIE 7")!=-1,
	chrome:navigator.appVersion.indexOf("Chrome")!=-1,
	safari:navigator.appVersion.indexOf("Safari")!=-1 && navigator.appVersion.indexOf("Chrome")==-1,
	opera:window.opera
};


var _=function(obj,route){
	if(!obj) return null;
	if(typeof obj=="string" && document.getElementById) obj=document.getElementById(obj);
	if(obj) return route?_DOM(obj,route):obj;
	else return null;
};


//Linguistic DOM objects search functionality
// ">" - next sibling tag
// "<" - prefious sibling tag
// "^" - first child tag
// "$" - last child tag
// "/" - parent node
// "~" - search  in child nodes
// "@" - return array matches
// "." - className property
// ":" - id property
// "#" - name property
// ----- RegExp to search _\(\'?\"?[a-zA-Z0-9_]+\'?\"?,
function _DOM(obj,route){
	route=route.replace(/[^<>\^$\/~a-z0-9_@.:# ]/gi,""); //clear uncorrect instructions
	route=route.replace(/(^[a-z@.:#].*)/i,"^$1"); //normalize inctructions (start with firstChild)
	route=route.replace(/((\<+)|(\>+)|(\^)|(\$)|(\/)|(\~)|(\@))/g,"$1*").replace(/\*([a-z0-9_@.:# ])/gi,"$1"); //add "any tag" (*) pointer
	var tags=route.toUpperCase().match(/([a-z0-9_*.:# ]+)/gi) || []; //create tags array
	var pointer=route.replace(/[^<>\^$\/~@]+/g,"+"); //split inctructions
	
	//alert(route+" ||| "+tags+" ||| "+pointer+" ||| ")
	var fit={
		">":"nextSibling",
		"<":"previousSibling",
		"^":"firstChild",
		"$":"lastChild",
		"/":"parentNode",
		".":BROWSER.ie?"className":"class",
		":":"id",
		"#":"name"
	};
	var tagPos=0, childPos=0;
	var char, tag, tagName, propKey, propValue, found, childNodes;
	var matches=[];

	while((char=pointer.charAt(0))){
		if(char=="+"){//change filter by "tag"
			if(tags[tagPos+1]) tagPos++;
			pointer=pointer.substr(1);
			continue;
		}
		
		tagName=tags[tagPos];
		propKey="";
		
		//if property exist
		if(tagName && (/[.:#]/.test(tagName))){
			propKey=fit[tagName.replace(/[^.:#]/g,"")];
			tag=tagName.match(/([a-z1-6_]*)[.:#]([a-z0-9_ ]*)/i);
			tagName=tag[1] || "*";
			propValue=tag[2];
			//alert(tagName+" "+propKey+" "+propValue)
		}
		
		//search in child nodes
		if(char=="~"){
			if(!childNodes) childNodes=obj.getElementsByTagName(tagName);
			else childPos++;
		}
		else if(childNodes){
			childNodes=null;
			childPos=0;
		}
		
		if(!(obj=obj[fit[char]] || (childNodes && childNodes[childPos]))) return matches.length?matches:null; //set next object
		found=!(obj.nodeType!=1 || (tagName!="*" && obj.tagName!=tagName) || (propKey && (!obj.getAttribute(propKey) || typeof obj.getAttribute(propKey)!="string" || obj.getAttribute(propKey).toUpperCase()!=propValue)));
		if(found) pointer=pointer.substr(1);
		
		//if first/last child not found in first step
		if((char=="^" || char=="$") && !found){
			pointer=pointer.replace(/./,(char=="^"?">":"<"));
		}
		
		//if matches symbol was found (return array of matches)
		if(pointer.charAt(0)=="@"){
			if(char=="^" && found) char=">";
			pointer=char+pointer;
			matches[matches.length]=obj;
		}
	}
	return obj;
};




function addEvent(el, evname, func) {
	if(!el["on"+evname] && el!=window && el!=document) return el["on"+evname]=func;
	if(el.attachEvent) el.attachEvent("on"+evname, func); // IE
	else if(el.addEventListener) el.addEventListener(evname, func, true); // Gecko / W3C
	else el["on"+evname]=func;
};

function removeEvent(el, evname, func) {
	//if(el["on"+evname]) return el["on"+evname]=null;
	if(el.detachEvent) el.detachEvent("on" + evname, func); // IE
	else if (el.removeEventListener) el.removeEventListener(evname, func, true); // Gecko / W3C
	else el["on"+evname]=null;
};



//get tag Attribute
function _ATTR(obj,attr){
	obj=_(obj);
	if(!obj || !attr) return null;
	return obj.getAttribute && obj.getAttribute(attr)!=undefined ? obj.getAttribute(attr) : (obj[attr]!=undefined ? obj[attr] : null);
};

//get tag Event
function _EV(obj,attr,args){
	var _prop_=_ATTR(obj,attr);
	if(_prop_ && /^on[a-z]+/.test(attr))
		return  typeof _prop_=="function" ? _prop_ : function(){return (new Function(args,_prop_)).apply(obj, arguments)};
	else 
		return function(){};
};



// element className & style functions
var Style=function(obj){
	obj=_(obj);
	return {
		empty:function(){
			return obj.className.replace(/\s/g,"")==""?true:false;
		},
		all:function(name){
			return !this.empty()?obj.className.split(/\s+/):[];
		},
		exist:function(name){
			for(var i=0, c=this.all(name), l=c.length; i<l; i++)
				if(c[i]==name) 
					return true;
			return false;
		},
		set:function(name){
			obj.className=name;
		},
		add:function(name){
			this.remove(name);
			obj.className+=' '+name;
			return true;
		},
		remove:function(name){
			obj.className=obj.className.replace(new RegExp("((^)|(\\s))"+name+"((\\s)|($))"),"$3");
			return false;
		},
		invert:function(name){
			return this.exist(name) ? this.remove(name) : this.add(name);
		},
		clear:function(){
			obj.className='';
		}
	}
};


//Element styles functions
var CSS=function(obj){
	obj=_(obj);
	return {
		//convert js style property to css property (zIndex -> z-index)
		js2css:function(prop){
			return prop.replace(/([A-Z])/g,"-$1").toLowerCase();
		},
		//get style|styles value from css element (arguments=[string|hash|array])
		get:function(prop){
			if(typeof prop=="string"){
				if(obj.currentStyle) return obj.currentStyle[prop];
				if(window.getComputedStyle) return window.getComputedStyle(obj,null).getPropertyValue(this.js2css(prop));
			}
			else if(prop){
				var style={};
				for(var i in prop){
					if(prop.length) i=prop[i]; //get prop if array
					style[i]=this.get(i);
				}
				return style;
			}
			else return 0;
		},
		//set new styles to element & return old styles (arguments=[hash])
		set:function(hash){
			var style={};
			for(var i in hash){
				if(i=="opacity" && BROWSER.ie){
					var val=Number(hash[i])*100;
					i="filter";
					hash[i]=(val==100?"":"Alpha(opacity="+val+")");
				}
				style[i]=this.get(i);
				obj.style[i]=hash[i];
			}
			return style;
		},
		//copy style|styles from obj to anoter element & return this styles (arguments=[string|array])
		copy:function(prop,to){
			if(typeof prop=="string")
				return (to.style[prop]=this.get(prop));
			else if(prop){
				var style=this.get(prop);
				for(var i in style)
					to.style[i]=style[i];
				return style;
			}
			return null;
		},
		//check current element style|styles (arguments=[hash])
		check:function(hash){
			for(var i in hash)
				if(hash[i]!=this.get(i))
					return false;
			return true;
		}
	}
};



// universal HTML creator
function makeHTML(OBJ,root,before){
	var tag=root;
	for(var i in OBJ){
		if(i=="tag") tag=document.createElement(OBJ[i]);
		else if(i=="append") 
			for(var j in OBJ[i]){ 
				if(OBJ[i][j].tag) 
					tag.appendChild(makeHTML(OBJ[i][j]));
			}
		else if(tag) tag[i]=OBJ[i];
	}
	if(root && root!=tag){
		if(before) root.insertBefore(tag, before);
		else root.appendChild(tag);
	}
	return tag;
};






//-----------------------------------------------------------

var COOKIE={
	set:function(name, value, expire) {
		if(expire){
			var d=new Date();
			d.setTime(d.getTime()+expire*1000);
			expire="; expires="+d.toUTCString();
		}
		else expire="";
		document.cookie=name+"="+escape(value)+expire+"; path=/";
	},
	get:function(name) {
		if(document.cookie.length==0) return false;
		var offset=document.cookie.indexOf(name+"=");
		if(offset!=-1) { 
			offset+=name.length+1;
			var end=document.cookie.indexOf(";", offset);
			if (end==-1) end=document.cookie.length;
			return unescape(document.cookie.substring(offset, end)) 
		}
		return false;
	}
};




//js include
document.include=function(src){
	if(!document.includes) document.includes={};
	if(document.includes[src]) return false;
	document.includes[src]=1;
	src=(/^https?:\/\/.+/.test(src)?src:GLOBAL_PATH+src);
	if(src.indexOf(".css")==-1) document.write('<'+'script type="text/javascript" src="'+src+'"><'+'/script>');
	else document.write('<link type="text/css" rel="stylesheet" href="'+src+'" />');
};






function Num(val){
	if(isNaN(val)) val=val.replace(/,/,"."); //if float [,]
	if(isNaN(val)) val=parseInt(val); //if [px]
	if(isNaN(val)) val=0;
	return Number(val);
};


function Coord(e){
	return {x:BROWSER.ie?event.clientX+document.documentElement.scrollLeft:e.pageX, y:BROWSER.ie?event.clientY+document.documentElement.scrollTop:e.pageY};
};



//Hash functions
function Hash(h){
	var _h={};
	for(var i in h) _h[i]=h[i];
	
	return {
		clone:function(){
			return _h;
		},
		count:function(){
			var k=0;
			for(var i in _h) k++;
			return k;
		},
		branch:function(){
			var h=this.clone();
			while(typeof h=="object") 
				for(var i in h){ 
					h=h[i]; 
					break;
				}
			return h;
		},
		merge:function(){
			for(var i=0, l=arguments.length; i<l; i++)
				for(var j in arguments[i])
					_h[j]=arguments[i][j];
			return _h;
		},
		replace:function(key,value){
			if(typeof key=="number") key=this.key(key);
			_h[''+key]=value;
			return	_h;
		},
		record:function(at){
			var k=0;
			for(var i in _h) if(at==k++) return [i, _h[i]];
			return [null,null];
		},
		key:function(at){
			return this.record(at)[0];
		},
		value:function(at){
			return this.record(at)[1];
		}
	}
};


Date.prototype._0=function(num){return (num<10?"0"+num:num)};

//debug output for Array & Hash objects (crusial in Chrome)
if(!BROWSER.chrome && !BROWSER.safari)
Array.prototype.toString =
Object.prototype.toString = function() {
	var cont = [];
	var addslashes=function(s){return s.split('\\').join('\\\\').split('"').join('\\"');};
	for (var k in this) { 
		if (cont.length) cont[cont.length-1] += ",";
		var v = this[k];
		var vs = ''; 
		if (v.constructor == String) vs = '"' + addslashes(v) + '"';
		else vs=v.toString();
		cont[cont.length]=k + ": " + vs;
	}
	cont = "	" + cont.join("\n").split("\n").join("\n	");
	var s = cont;
	if (this.constructor == Object) s = "{\n"+cont+"\n}";
	if (this.constructor == Array) s = "[\n"+cont+"\n]";
	return s;
};// GLOBAL JS SETTINGS

var LANG="de"; //default language

var GLOBAL_PATH="front/default/";
var IMGS_PATH=GLOBAL_PATH+"imgs/";

var DEBUGGER_ENABLED=1;

var AJAX_ENABLED=1;
var AJAX_GET="?ajax=1";
var AJAX_POST="?ajax=1";
var CACHE_DEFAULT=60;  //default ajax cache [in minutes]

var PICKER_COLORS=["#000000","#000033","#003300","#660000","#333333","#000066","#006600","#990000","#666666","#000099","#009900","#cc0000","#999999","#0000cc","#00cc00","#ff0000","#aaaaaa","#0033ff","#00cc33","#ff9900","#cccccc","#0066ff","#00cc66","#ffcc00","#eeeeee","#0099ff","#00ff00","#ffff00","#ffffff","#3333ff","#00ff99","#ffff66"];
var VCat={
	edit:function(obj){
		obj.parentNode.defalutHTML=obj.parentNode.innerHTML;
		GET({ref:_ATTR(obj, "aref"), target:obj.parentNode});
	},
	remove:function(obj){
		GET({ref:_ATTR(obj, "aref"), oncomplete:function(){obj.parentNode.parentNode.removeChild(obj.parentNode)}});
	},
	save:function(obj){
		GET({ref:_ATTR(obj, "aref"), target:obj.parentNode});
	},
	cancel:function(obj){
		obj.parentNode.innerHTML=obj.parentNode.defalutHTML;		
	},
	select:function(obj, checked){
		var form=obj.target?_(obj.target):_(obj, "/form");
		var inputs=_(form, "~@input");
		for(var i=0; i<inputs.length; i++){
			if(checked!=undefined) inputs[i].checked=checked?true:false;
			else if(inputs[i].checked){checked=1; break;}
		}
		form.submit_button.style.display=checked?"inline":"none";
	}
};


function init_help_block(obj){
	obj.onclick=function(){
		this.parentNode.className="help help_act";
	}
	_(obj, ">a").onclick=function(){
		this.parentNode.className="help";
	}
};


function quellcode(obj){
	if(!obj.inited){
		obj.tr_class=obj.parentNode.parentNode.className;
		obj.onclick=function(){return quellcode(this)}
	}
	obj.inited=1;
	obj.isOpen=obj.isOpen?0:1;
	obj.parentNode.parentNode.className=obj.isOpen?obj.tr_class+" nb":obj.tr_class;
	_(obj.target).parentNode.style.display=obj.isOpen?"table-row":"none";
	_(obj, "~i").className=obj.isOpen?"act":"";
	return false;
};



function showhide(obj){
	if(typeof obj=="string") obj=_(obj);
	else obj=obj.parentNode;
	if(!obj.inited){
		obj.classDefault=obj.className; 
		obj.inited=1;
	}
	obj.isOpen=obj.isOpen?0:1;
	obj.className=obj.isOpen?obj.classDefault+" "+obj.classDefault+"_act":obj.classDefault;
	return false;
};


var Modal={
	create:function(){
		this.block=makeHTML({tag:"div", id:"modal", append:[
			{tag:"span"}
		]}, document.body);
		this.layer=_(this.block, "~span");
		this.inited=1;
	},
	showhide:function(b, opacity){
		if(!this.inited) this.create();
		this.block.style.display=b?"block":"none";
		if(opacity!=undefined) CSS(this.layer).set({opacity:opacity});
		this.isOpen=b;	
	},
	show:function(opacity){
		this.showhide(1, opacity);
	},
	hide:function(){
		this.showhide(0);	
	}
};


var Popup={
	create:function(){
		var _this=this;
		this.block=makeHTML({tag:"div", id:"popup", append:[
			{tag:"a", className:"close", onclick:function(){_this.hide()}},
			{tag:"div", className:"top"},
			{tag:"div", className:"body"},
			{tag:"div", className:"bottom"}
		]}, document.body);
		this.body=_(this.block, "~div.body");
		addEvent(document, "keydown", function(e){
			if((Key(e).isEscape() || (Key(e).isEnter() && _this.hasOkButton())) && _this.isOpen) _this.hide()
		});
		this.inited=1;
	},
	showhide:function(b){
		Modal.showhide(b, 0.07);
		this.block.style.visibility=b?"visible":"hidden";
		this.isOpen=b;
	},
	show:function(content){
		if(!this.inited) this.create();
		this.body.innerHTML=content;
		this.block.style.marginTop=-Math.round(this.block.offsetHeight/2)+"px";
		this.showhide(1);
		return false;
	},
	hide:function(){
		this.showhide(0);
		this.body.innerHTML="";
		return false;
	},
	hasOkButton:function(){
		var okButton=_(this.block, "~div.buts^a");
		if(okButton && okButton.className=="but but_ok") return true;
		else return false;
	}
};


(Picker=function(obj){this.create(obj)}).prototype={
	create:function(obj){
		var _this=this;
		this.root=obj.parentNode;
		this.root.onclick=function(){_this.input.focus()};
		this.block=makeHTML({tag:"div"}, this.root);
		for(var i=0; i<PICKER_COLORS.length; i++){
			var item=document.createElement("a");
			item.style.backgroundColor=item.color=item.href=PICKER_COLORS[i];
			item.onmousedown=function(){return _this.pickColor(this.color)};
			this.block.appendChild(item);
		}
		
		this.input=_(this.root, "~input");
		this.input.onkeyup=function(){_this.setColor(this.value)}
		this.input.onfocus=function(){_this.show()}
		this.input.onblur=function(){_this.hide()}
		this.setColor(this.input.value);
		this.inited=1;
	},
	showhide:function(b){
		if(!this.inited) this.create();
		this.block.style.display=b?"block":"none";
		this.isOpen=b;	
	},
	show:function(){
		this.showhide(1);
	},
	hide:function(){
		this.showhide(0);	
	},
	setColor:function(color){
		if(/#[0-9A-Fa-f]{6}/.test(color)) this.root.style.backgroundColor=color;
	},
	pickColor:function(color){
		this.input.value=color;
		this.setColor(color);
	}
}



var Key=function(event){
	return {
		code:function(){return window.event?window.event.keyCode:event.which;},
		is:function(num){return this.code()==num},
		isEnter:function(){return this.code()==13},
		isEscape:function(){return this.code()==27}
	}
};


// activate item on click (set className="act")
function _act(obj){
	if(!obj || !obj.parentNode) return false;
	if(_ATTR(obj, "noact")!=undefined) return false;
	var parpar=(obj.parentNode.tagName=="LI" || obj.parentNode.tagName=="VAR");
	var par=(parpar ? obj.parentNode.parentNode : obj.parentNode);
	if(!par.set) par.set=function(i){return (i==undefined?par.cur:_(par, '~@a')[i]).onclick();}; //init funtion [set]
	if(!par.act) par.act=function(i){return _act(_(par, '~@a')[i]);}; //init funtion [set]
	if(!par.unset) par.unset=function(){Style(par.cur).remove("act"); par.cur=null; return false;}; //init funtion [set]
	if(!par.cur) par.cur=_(par, (_ATTR(par, "act")=="all"?"~":"^")+"a.act"); // if no [cur] try to find it ()
	if(par.cur) Style(par.cur).remove("act");
	Style(obj).add("act");
	if(par.cur==obj) return false;
	if(parpar){
		if(par.cur) Style(par.cur.parentNode).remove("act");
		Style(obj.parentNode).add("act");
	}
	par.cur=obj;
	(_ATTR(obj, "onact") || function(){})(); //call [onact] event
	return false;
};



// periodical ajax executer
function periodical(obj, sec, cond){
	if(cond==undefined) cond=1;
	if(obj.tm) clearTimeout(obj.tm);
	obj.tm=setTimeout(function(){if(obj && cond) obj.onclick() }, sec*1000);
};



var Script={
	preload:function(obj){
		if(!obj) return;
		var _this=this;
		if(!obj.inLoading){
			this.load(_ATTR(obj, "src"));
			obj.callback=new Function(obj.innerHTML);
			obj.inLoading=1;
		}
		obj.tm=1;
		setTimeout(function(){ if(obj.tm){obj.tm=0; _this.exec(obj);}}, 500);
	},
	load:function(file){
		//alert(file);
		makeHTML({tag:"script", type:"text/javascript", src:file}, document.body);
	},
	exec:function(obj){
			try{obj.callback.apply(obj);}catch(e){this.preload(obj)};
		
	}
};


function checkbox_group(obj){
	var chb=_(obj, "/span~@input");
	var checked_all=true;
	var set_all;
	if(chb[0]==obj) set_all=obj.checked;
	for(var i=1; i<chb.length; i++){
		if(!chb[i].checked) checked_all=false;
		if(set_all!=undefined) chb[i].checked=set_all;
	}
	if(set_all!=undefined) return true;
	chb[0].checked=checked_all;
}

function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    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 "";
}


function img_fs(obj, w, h){
	if(!_("imgFS")){
		makeHTML({tag:"div", id:"imgFS", append:[
			{tag:"a", className:"close", onclick:function(){this.parentNode.style.display="none"; Modal.hide();}},
			{tag:"img"},
		]}, document.body);
	}
	var root=_("imgFS");
	var img=_(root, "~img");
	img.src=obj.href;
	img.width=w;
	img.height=h;
	var top=Math.round((document.documentElement.clientHeight-img.height)/2);
	var scrollTop=document.documentElement.scrollTop;
	root.style.top=(top>0?top+scrollTop:scrollTop)+"px";
	root.style.marginLeft=-Math.round(img.width/2)+"px";
	Modal.show(0.5);
	root.style.display="block";
	return false;
}


function myfunction(obj) {
return true;
//alert('state: ' + obj.state + ' file: ' + obj.file);
}//© <stipuha /> development (2007)
//> AJAX debugger console
//--------------------------------
//> Calling: ctrl+shift+q


var Debugger={
	win:null,
	data:'',
	init:function(){
		//attach debugger window call on key combination
		addEvent(document, "keypress", function(e){
			var ev=e?e:window.event; 
			var key=ev.keyCode?ev.keyCode:ev.which;  
			//alert(ev.ctrlKey+","+ev.shiftKey+","+ev.altKey+","+key);	//ctrl+shift+q
			if(ev.ctrlKey  && ev.shiftKey  && (key==113 || key==81 || key==17) ) Debugger.winopen();
		});
	},
	winopen:function(){
		this.win=window.open('', 'debug', 'scrollbars=no,status=yes,resizable=yes,width=780,height=560');
		this.load();
	},
	
	load:function(){
		this.win.document.open();
		this.win.document.write("<title>AJAX debugger</title><input type='button' value='refresh' onclick='window.opener.Debugger.load()' /><div style='width:100%;height:95%;overflow-y:auto; border:1px solid #555; font:12px \"Courier New\"'>"+this.data+"</div>");
		this.win.document.close();
	},
	
	add:function(txt){
		txt=txt.replace(/={20,}/g,"");
		txt=txt.replace(/</g,"&lt;");
		txt=txt.replace(/>/g,"&gt;");
		txt=txt.replace(/\t/g,"&nbsp; ");
		this.now=new Date();
		this.data+="["+this.now._0(this.now.getHours())+":"+this.now._0(this.now.getMinutes())+":"+this.now._0(this.now.getSeconds())+"]\n";
		this.data+="====================\n";
		this.data+=txt+"\n\n\n";
		
		this.data=this.data.replace(/\n/g,"<br />");
		return false;
	}
};

//© <stipuha /> development (2008)
//> AJAX
//-------------------------------- 
//  ___example#1___
//  (req=new Ajax()).onready=function(response){ready_func(response)};
//	req.file="index.php";
//	req.query="abc=123&def=456";
//	req.send();
//
//  ___example#2___
//	new Ajax({
//		file:"index.php", 
//		query:"abc=123&def=456",
//		onready:function(response){ready_func(response)},
//		send:1
//	});


(Ajax=function(opt){this.init(opt)}).prototype={
	
	CACHE:{},
	
	init:function(opt){
		opt=opt || {};
		this.method=opt.method || "http";
		this.file=opt.file || "";
		this.query=opt.query || "";
		this.caching=opt.caching || false;
		this.hash=opt.hash || {};
		this.onready=opt.onready || function(){};
		if(opt.onready) this.send();
	},
		
	send:function(){
		//add hash to query
		this.query+=this.json2query(this.hash);
		//if cache==true > call data from cache & return
		try{if(this.caching && this.CACHE[this.query]) return this.ondata(this.CACHE[this.query]);}catch(e){};
		
		var _this=this;
		var request, response;
		var SID=(new Date()).getTime()+Math.round(Math.random()*1000);
		
		switch(this.method){
			case "http":
				request=window.XMLHttpRequest?new XMLHttpRequest():(new ActiveXObject("Msxml2.XMLHTTP") || null); // ||"Microsoft.XMLHTTP" - ie5x
				if(request){
					request.open('POST', this.file, true);
					request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); // $_POST[] || $_REQUEST[]
					request.onreadystatechange=function(){
						if(request.readyState==4){
							if(request.getResponseHeader('Content-Type') && request.getResponseHeader('Content-Type').indexOf("/xml")!=-1) response=_this.xml2json(request); //xml
							else response=(new Function('return '+request.responseText))(); //json
							_this.ondata(response);
						}
					};
					request.send(this.query); //request send 
					break;
				}
				
			case "script":
				request=document.createElement("script");
				if(request){
					request.id=SID;
					var src=this.file+"?"+"_scriptID_="+request.id+"&"+this.query;
					if(BROWSER.ie) request.src=src.substr(0,2048); //MAX msie:2kb
					else{request.src=src; request.src=request.src.substr(0,4096)}; //MAX gesko:4Kb
					request.onreadystatechange=function(response){
						if(response && !response.initEvent){
							_this.ondata(response);
							setTimeout(function(){request.parentNode.removeChild(request)},13);
						}
					};
					document.body.appendChild(request); //request send 
					break;
				}
				
			case "form":
				var request=document.createElement(BROWSER.ie?"<iframe name="+SID+">":"iframe");
				if(request){
					request.name=SID;
					request.style.position="absolute";
					request.style.visibility="hidden";
					this.form.appendChild(request);
					//this.form.encoding="multipart/form-data";
					this.form.method="post";
					this.form.target=request.name;
					this.form.action=this.file+this.form.action.replace(/.*(\?.*)$/,"$1");
					request.onreadystatechange=request.onload=function(response){
						if(!request.readyState || request.readyState=="complete"){
							_this.ondata((new Function('return '+request.contentWindow.document.body.innerHTML))());
							setTimeout(function(){request.parentNode.removeChild(request)},13);
						}
					};
					this.form.submit(); //request send 
					break;
				}
				
			default: return request;
		}
	},
	
	ondata:function(response){
		if(this.caching || this.CACHE[this.query]) this.CACHE[this.query]=response; //cache response data
		this.response=response;
		this.onready(response);
	},
	
	json2query:function(hash, pref){
		var query="";
		for(var i in hash){
			var key=(pref?pref+"["+i+"]":i);
			query+=(typeof hash[i]=="object" ? this.json2query(hash[i],key) : "&"+key+"="+hash[i].toString().replace(/&/g, "%26"));
		}
		return query;
	},
	
	xml2json:function(request){
		var parseXML=function(node){
			if(node.childNodes.length==1 && (node.firstChild.nodeType==3 || node.firstChild.nodeType==4)) return node.firstChild.data; //if text node
			var hash={};
			for(var i=0, childs=node.childNodes, l=childs.length; i<l; i++)
				if(childs[i].nodeType==1)
					if(hash[childs[i].tagName]){ //if node has array type
						if(typeof hash[childs[i].tagName]=="string" || (typeof hash[childs[i].tagName]=="object" && !hash[childs[i].tagName].length)) 
							hash[childs[i].tagName]=[hash[childs[i].tagName]]; //reinit node (set array type)
						hash[childs[i].tagName][hash[childs[i].tagName].length]=parseXML(childs[i]);
						}
					else hash[childs[i].tagName]=parseXML(childs[i]);
			return hash;
		};
		var doc=BROWSER.ie?request.responseXML:(new DOMParser()).parseFromString(request.responseText, "text/xml"); //get XML content
		var response={obj:{}, text:''};
		if(doc && doc.documentElement) response.obj=parseXML(doc);
		return response;
	},
	
	onerror:function(message){alert("Server output error...\n"+message)}
};//--------------------------------
//CLIENT CONFIGURATION
//--------------------
// define aref="?key1=value&key2=(this.value)&key3=(func())" (get query)
// define target="uid123" (unique tag id for ajax content)
// define autoload (automatic send get query on load content)
// define onstarting="func()" (event calling before ajax sending)
// define oncomplete="func()" (event calling when content already loaded)

//SERVER CONFIGURATION
//--------------------
// define $RESPONSE["complete"]=1 (condition for execute oncomplete function after POST query)
// define $RESPONSE["alert"]="message message message" (condition for open system information popup)



//> HTMLAJAX functionality
//----------------------------------
var HTMLAJAX=function(obj){
	var _this=this;
	
	this.init=function(){	
		this.obj=obj;
		//init vars
		this.target=_ATTR(obj,"target");
		this.target=(this.target=="this"?obj:_(this.target));
		this.indicatorShow=eval(_ATTR(obj,"indicator"));
		this.onstarting=_EV(obj,'onstarting','request');
		this.oncomplete=_EV(obj,'oncomplete','response');
		this.onfailure=_EV(obj,'onfailure','response');	
		//init ajax
		(this.req=new Ajax()).onready=function(response){_this.onready(response)};
		this.cache_time=_ATTR(obj,"cache")||_ATTR(obj.cache_obj,"cache");

		return this;
	};

	this.exec=function(){
		if(this.target) this.target.call_func=this.constructor.lastCall; //attach call ajax on target
		
		//execute external operations
		if(this.onstarting(this.req.hash)==false) return false; //break if onstarting event return false
		
		//execute internal operations
		if(this.onbeforesend()==false) return false; //break if onbeforesend function  return false
		
		//try to set cache
		if(this.cache_time) this.constructor.cache.set(this.cache_time, this.req, this.obj||this.obj.cache_obj); 
		
		this.indicator(1);
		this.req.send();
		return false;
	};
	
	//show global ajax loading icon
	this.indicator=function(b){
		if(this.constructor.loader && this.indicatorShow!=0) this.constructor.loader.style.display=b?"block":"none";
		return false;
	};
	
	//parse ajax referer link (ARL=aref)
	this.url2query=function(url){
		if(!url) return "";
		var file=url.replace(/([^?]*\/)*([^?]*)\??.*/,"$2"); //get file name
		if(file) this.req.file=file; //overwrite ajax handler file name
		url=url.replace(/[^?]*\??/,""); //get query [a=1&b=2&c=3]
		if(!url) return "";
		url=this.func2query(url); //check & try to execute function in query
		return url;
	};
	
	//for function in query (dynamic executeble query)
	this.func2query=function(url){
		var dyn=url.match(/&?[a-z0-9_]+=\(%?[^&]+\)/gi);
		if(dyn && dyn.length){
			for(var i=0,a,l=dyn.length;i<l;i++){
				a=dyn[i].split(/=/);
				var ue=false;
				if(ue=/^\(%/.test(a[1]))a[1]=a[1].replace(/^\(%/, "("); //unescape definition
				var hash={};
				var key=a[0].replace(/&/,"");
				var value=(new Function('return '+a[1])).apply(obj);
				hash[key]=value;
				var res="";
				res=this.req.json2query(hash);
				if(ue && typeof res=="string") res=unescape(res);
				url=url.replace(/&?[a-z0-9_]+=\(%?[^&]+\)/i, res); //add value to query
			}
		}
		return url;
	};
	
	this.onready=function(response){
		if(!response) return Debugger.add("\nNO RESPONSE!\n");
		
		if(DEBUGGER_ENABLED) 
			Debugger.add("(target="+this.obj.target+")\n"+"["+this.req.query+"]\n"+"\n----------\n"+response.obj+"\n----------\n"+response.text);
		
		if(this.target){
			this.target.innerHTML=response.text; //if echo -- write innerHTML
			if(response.obj) this.targetProp(this.target, response.obj.target); //if target properties in response exist set properties to target
			init_content(this.target);
		}
		
		//execute internal operations
		this.onreturn(response);
		this.constructor.onresponse(response);
		
		//execute external operations
		if(response.obj.complete==undefined || Number(response.obj.complete)) this.oncomplete(response);
		else this.onfailure(response);
		
		this.indicator(0);
	};
	
	this.targetProp=function(target, props){
		if(props)
			for(var i in props)
				target[i]=props[i];
	};
	
	this.onbeforesend=function(){};
	this.onreturn=function(){};
	
	return this.init();
};

HTMLAJAX.loader=null; //ajax loader icon
HTMLAJAX.onresponse=function(){}; //function is called when response complete
HTMLAJAX.lastCall=null; //last request which call ajax

//HTMLAJAX CACHE control functionality
HTMLAJAX.cache={
	MULTIPLIER:60*1000, // set cache in [minutes]
	from:(new Date()).getTime(),
	init:function(cache_time){
		var cache_param={};
		var ts=(new Date()).getTime();
		cache_param.period=Number(cache_time=="*"?CACHE_DEFAULT:cache_time);
		cache_param.start=ts;
		cache_param.end=ts+cache_param.period*this.MULTIPLIER;
		return cache_param;
	},
	expire:function(cache_param){ //check cache time out
		var ts=(new Date()).getTime();
		if(cache_param.end<ts || cache_param.start<this.from){ //if cache time out replace cache params (start & end)
			cache_param.start=ts;
			cache_param.end=this.init(cache_param.period).end;
			return true;
		}
		return false;
	},
	set:function(cache_time, ajax, cache_obj){
		// from tag:  cache="5" (5 minutes cache) || cache="*" (default cache)
		if(cache_time && cache_obj){
			if(!cache_obj.cache_param) cache_obj.cache_param=this.init(cache_time);
			if(!this.expire(cache_obj.cache_param) && !cache_obj.nocaching) ajax.caching=true;
		}
	},
	reset:function(){this.from=(new Date()).getTime()}
};




// GET - ajax subclass
function GET(obj){
	if(!AJAX_ENABLED) return false;
		
	var htmlajax=new HTMLAJAX(obj); /*init parent class*/
	htmlajax.req.file=AJAX_GET;
	htmlajax.req.query=htmlajax.url2query(obj.ref||obj.aref||_ATTR(obj,"aref")||_ATTR(obj,"href")); //set query params
	if(obj.nodeType!=1 && obj.hash) htmlajax.req.hash=obj.hash;
	if(!htmlajax.req.query && !obj.hash) return false; //exit if no parameters
	
	htmlajax.onbeforesend=function(){
		if(this.target && this.indicatorShow!=0) this.target.innerHTML=HTMLAJAX.loader?HTMLAJAX.loader.alt:"...";
	};
	htmlajax.onreturn=function(response){
		_act(obj);
		if(GET.onresponse) GET.onresponse(this);
	};
  return htmlajax.exec();
};
 


// POST - ajax subclass
function POST(obj, sender){
	if(!AJAX_ENABLED) return false;
	
	if(obj.in_process) return false;
	obj._form=(obj.tagName=="FORM" ? obj : (obj.form || _(obj, "/form"))); //find form element if obj is not a FORM
		
	htmlajax=new HTMLAJAX(obj); /*init parent class*/
	htmlajax.req.file=AJAX_POST;
	htmlajax.req.query=htmlajax.url2query(_ATTR(obj._form,"action")); //set parameters from form attribute [action]
	
	if(sender && sender.name) htmlajax.req.hash[sender.name]=true; //deliver sender button name
	
	if(obj._form.elements)
		for(var i=0;i<obj._form.elements.length;i++){
			if(obj._form.elements[i].tagName=="FIELDSET" || obj._form.elements[i].tagName=="OBJECT") continue;
			var is_send=((!obj._form.elements[i].getAttribute("flag")&&!_ATTR(obj,"flag"))||(obj._form.elements[i].getAttribute("flag")&&_ATTR(obj,"flag")&&obj._form.elements[i].getAttribute("flag")==_ATTR(obj,"flag"))?1:0);
			if(is_send && obj._form.elements[i].getAttribute("send")!=undefined) is_send=eval(obj._form.elements[i].getAttribute("send"));
			
			if(is_send && obj._form.elements[i].type=="checkbox") htmlajax.req.hash[obj._form.elements[i].name]=(obj._form.elements[i].checked?1:0);
			else if(is_send && obj._form.elements[i].type=="radio"){ if(obj._form.elements[i].checked) htmlajax.req.hash[obj._form.elements[i].name]=obj._form.elements[i].value;}
			else if(is_send && obj._form.elements[i].type=="file") htmlajax.req.hash[obj._form.elements[i].name]=obj._form.elements[i];
			else if(is_send) htmlajax.req.hash[obj._form.elements[i].name]=obj._form.elements[i].value;
		}
		
	htmlajax.onbeforesend=function(){
		obj.in_process=1;
	};
	htmlajax.onreturn=function(response){
		setTimeout(function(){obj.in_process=0},500);
		if(POST.onresponse) POST.onresponse(this);
	};
  return htmlajax.exec();
};

//Â© <stipuha /> development (2007)
//> Custom forms controls

var Forms={};


// check single value
Forms.checkValue=function(value,rule){
	var rules=[];
	var reg_ext=/.+\.([A-Za-z0-9]+)/;
	var reg_url=/^http:\/\/.+\..+/;
	rules["video_ext"]={"avi":1,"mpe":1,"mpeg":1,"wmv":1,"aif":1,"mov":1,"mkv":1,"flv":1,"mp2":1,"mp4":1,"rm":1,"dv":1,"yuv":1,"3gp":1,"3gp2":1};
	rules["image_ext"]={"jpg":1,"jpeg":1,"gif":1,"eps":1,"pcx":1,"raw":1,"pct":1,"pict":1,"pxr":1,"png":1,"pbm":1,"pgm":1,"ppm":1,"pnm":1,"pfm":1,"pam":1,"tga":1,"vda":1,"icb":1,"vst":1,"tif":1,"tiff":1,"bmp":1,"apx":1,"cpt":1,"gbr":1,"iff":1,"img":1,"jp2":1,"jpc":1,"j2c":1,"jpx":1,"kdc":1,"qti":1,"qtif":1,"xcf":1};
	rules["audio_ext"]={"mp3":1,"wav":1,"mid":1};
	if(rule=="video_ext") return rules["video_ext"][value.replace(reg_ext, "$1").toLowerCase()];
	if(rule=="image_ext") return rules["image_ext"][value.replace(reg_ext, "$1").toLowerCase()];
	if(rule=="audio_ext") return rules["audio_ext"][value.replace(reg_ext, "$1").toLowerCase()];
	if(rule=="url") return reg_url.test(value);
	return false;
};



Forms.checkFields=function(obj){
	function concat(arrarr){
		var outarr=[];
		for(var i=0, l=arrarr.length; i<l; i++)
			for(var j=0, ll=arrarr[i].length; j<ll; j++)
				outarr.push(arrarr[i][j]);
		return outarr;
	};
	var form=obj;
	while(form.tagName.toLowerCase()!="form") form=form.parentNode; //find form element in parent nodes
	var els=concat([form.getElementsByTagName("input"),form.getElementsByTagName("textarea"),form.getElementsByTagName("select")]);
	var req;
	for(var i=0, l=els.length; i<l; i++){
		if(req=els[i].getAttribute("require")){
			if(els[i].getAttribute("send")!=undefined && !eval(els[i].getAttribute("send"))) continue; //if field is not to send
			if(req=="empty" && els[i].value.replace(/\s+/,"")=="") return document.alert(els[i].lang);
			if(req=="checked" && !els[i].checked) return document.alert(els[i].lang);
			if(req=="video_ext" && !Forms.checkValue(els[i].value,"video_ext")) return document.alert(els[i].lang);
			if(req=="image_ext" && !Forms.checkValue(els[i].value,"image_ext")) return document.alert(els[i].lang);
			if(req=="audio_ext" && !Forms.checkValue(els[i].value,"audio_ext")) return document.alert(els[i].lang);
			if(req=="url" && !Forms.checkValue(els[i].value,"url")) return document.alert(els[i].lang);
		}
	}
	return true;
};

// reset form fields
Forms.fieldsReset=function(root){
	function clearInputFile(inp){
		var par=inp.parentNode;
		inp.parentNode.innerHTML=inp.parentNode.innerHTML;
		return par.getElementsByTagName("input")[0];
	};
	var els=root.getElementsByTagName("*");
	for(var i=0, l=els.length; i<l; i++){
		if(!els[i]) continue;
		
		if(els[i].getAttribute("temporary")!=undefined) els[i].innerHTML="";
		if(els[i].getAttribute("disabled")!=undefined) els[i].disabled=els[i].getAttribute("disabled")?1:0;
		if(els[i].getAttribute("send")!=undefined) els[i].setAttribute("send",0);
		if(_ATTR(els[i],"type")=="file") clearInputFile(els[i]);
		if(_ATTR(els[i],"type")=="checkbox") els[i].checked=0;
		//if(els[i].onfocus){ els[i].onfocus(); }
		if(_ATTR(els[i],"type")=="text" || els[i].tagName.toLowerCase()=="textarea"){
			els[i].value="";
			if(els[i].def_value && els[i].onblur) els[i].onblur();
		}
		if(els[i].reset) els[i].reset(); //for custom select
		if(_ATTR(els[i],"onreset")) els[i][_ATTR(els[i],"onreset")](); //start onreset event
	}
	return false;
};


//fix textarea length
Forms.maxlength=function(obj, len){
	obj.value=obj.value.substr(0,len)
};



Forms.dropAjaxFilter=function(input){
	//return false;
	var list=document.createElement("div");
	list.className="drop_filter";
	input.parentNode.insertBefore(list,input.nextSibling);
	
	input.inFocus=true;
	input.isOpen=false;
	input.onkeydown=function(e){if(Key(e).is(13)) return false;}; 
	input.onkeyup=function(e){
		if(this.isOpen && (Key(e).is(40) || Key(e).is(38) || Key(e).is(13))) return list.act(Key(e).code());
		this._value=this.value; 
		if(this.value) GET(this);
		else list.close();
	}; 
	input.onfocus=function(){ this.onkeyup(); this.inFocus=true};
	input.onblur=function(){ list.close(); this.inFocus=false;};
	input.oncomplete="if(this.inFocus){ this.list.showhide(1); this.list.init(); }";
	input.setAttribute("indicator","0");
	input.target=input.list=list;
	list.input=input;
	list.init=function(){
		var items=_(list, "~@a");
		if(!items) return false;
		for(var i=0; i<items.length; i++){
			items[i].onmousedown=function(){list.lock=true};
			items[i].onclick=function(){input.value=this.innerHTML; list.showhide(0); return false};
			items[i].onmouseup=function(){list.lock=false};
		}
	};
	list.close=function(){
		if(!list.lock) setTimeout(function(){list.showhide(0);},100);
	};
	list.showhide=function(b){
		input.isOpen=showhide(list,b);
	};
	list.act=function(code){
		if(code==13){
			 if(list.cur){ input._value=input.value; list.showhide(0);}
			 return false;
		}
		if(!list.firstChild) return false;
		var next;
		list.cur=_(list, "~a.act");
		if(list.cur) list.cur.className="";
		if(!list.cur) next=list[code==40?"firstChild":"lastChild"];
		else next=list.cur[code==40?"nextSibling":"previousSibling"];
		if(next){
			next.className="act";
			input.value=next.innerHTML;
			list.cur=next;
		}
		else input.value=input._value;
		return false;
	};
};


//stylizing FileBrowse control (autoreplace)
//expamle: 
//	<span id="upload_img"></span>
//	<a class="but_ort" type="file" name="file_1" target="upload_img">Browse...</a>
Forms.fileBrowse=function(obj){
	this.init=function(){
		this.obj=obj;
		obj.onmouseover=function(){return false};
		obj.onclick=function(){ return false};
		
		var input=document.createElement("input");
		input.type="file";
		input.name=obj.getAttribute("name");
		input._onchange=BROWSER.ie?_EV(obj, "onchange"):obj.onchange;
		input.size=1;
		if(obj.getAttribute("lang")) input.setAttribute("lang", obj.getAttribute("lang"));
		if(obj.getAttribute("flag")) input.setAttribute("flag", obj.getAttribute("flag"));
		
	
		var but_browse=document.createElement("div");
		but_browse.className=obj.className;
		but_browse.innerHTML=obj.innerHTML;
		but_browse.target=_ATTR(obj, "target");
		but_browse.sender=_ATTR(obj, "sender");
		but_browse.loader=_ATTR(obj, "loader");
		but_browse.clear=_ATTR(obj, "clear");
		but_browse.onclear=function(){
			if(this.target) _(this.target).innerHTML="&nbsp;"; 
			Forms.fieldsReset(this);
			this.getElementsByTagName("input")[0].onchange=input.onchange;
		}
				
		obj.parentNode.replaceChild(but_browse,obj);
		obj=but_browse;
		input.browse=obj;
		
		if(this.obj.getAttribute("hidden")){
			var input_hidden=document.createElement("input");
			input_hidden.type="hidden";
			input_hidden.name=this.obj.getAttribute("hidden");
			input_hidden.value=0;
			obj.insertBefore(input_hidden, obj.firstChild);
		}
		
		input.onchange=function(){
			if(input._onchange) input._onchange();
			if(obj.target) _(obj.target).innerHTML=Forms.getFileName(this.value); 
			if(input_hidden) input_hidden.value=this.value?1:0;
		};
		
		
		//CSS(input).set({fontSize:'100px', position:'absolute', margin:'-30px 0 0 -300px', opacity:0, filter:'Alpha(opacity:0)', cursor:'pointer'});
		//CSS(obj).set({overflow:'hidden'});
		if(CSS(obj).check({position:'static'})) CSS(obj).set({position:'relative'});
		obj.insertBefore(input,obj.firstChild);
		
	};
	return this.init();
};


//parse path string
Forms.getFileName=function(value){
	return value.replace(/([^\\]*\\)+([^\\]*\.[A-Za-z]+)/, "$2");
};

//input functions
Forms.input=function(obj){
	
	var _this=this;
	
	this.init=function(){
		obj.onfocus=null;
		if(obj.getAttribute("mask")){
			addEvent(obj, "keyup", function(event){_this.mask(this)});
			addEvent(obj, "blur", function(event){_this.mask(this)});
		}
		if(obj.getAttribute("onenterkey")){
			addEvent(obj, "keyup", function(event){if(_this.isEnter(event)) _EV(this,'onenterkey')()});
		}
		if(obj.getAttribute("default")!=undefined){
			this.setDefault(obj);
		}
		
		return this;
	};
	
	//apply RegExp mask onkey up
	this.mask=function(obj){
		var re=new RegExp("[^"+obj.getAttribute("mask")+"]","gi");
		obj.value=obj.value.replace(re,"");
	};
	
	//check enter key
	this.isEnter=function(event){
		return (window.event?window.event.keyCode:event.which)==13;
	};
	
	//init default input value & input styles
	this.setDefault=function(obj){
		function setOpt(obj){
			if(obj.def_opt) CSS(obj).set(obj.def_value==obj.value?obj.def_style:obj.def_opt);
		};
		//init
		if(!obj.def_value){
			var opt=_ATTR(obj,"default");
			if(opt && /^{[^}]*}$/.test(opt)){ 
				obj.def_opt=(new Function("return "+opt))();
				obj.def_value=obj.value=obj.getAttribute("value") || obj.value;
				obj.def_style=CSS(obj).get(obj.def_opt);
			}
			else if(opt) obj.def_value=obj.def_text=opt;
			addEvent(obj, "focus", function(){_this.setDefault(this)});
			addEvent(obj, "blur", function(){if(!this.value) this.value=this.def_value; setOpt(this)});
		}
		//execute
		//alert(obj.name+": "+obj.def_value+" -- "+obj.value);
		if(obj.def_value==obj.value) obj.value=obj.def_text?obj.def_text:"";
		setOpt(obj);
		
	};
	return this.init();
};




Forms.checkbox=function(obj){
	obj.chb=obj.getElementsByTagName("input")[0];
	if(!obj.classNative){
		CSS(obj.chb).set({opacity:"0", filter:"alpha(opacity:0)", cursor:"pointer"});
		if(!obj.className) obj.className="checkbox";
		obj.classNative=obj.className;
		obj.classAct=obj.className+" "+obj.className+"_act";
		obj._checked=0;
	}
	if(obj.chb.checked){
		obj.className=obj.classAct;
		obj._checked=1;
	}
	obj.onclick=function(e){
		var target=window.event?window.event.srcElement:e.target;
		this._checked=this._checked?0:1;
		this.className=this._checked?this.classAct:this.classNative;
		if(target.tagName==this.tagName){ 
			this.chb.checked=this._checked;
			if(this.chb.onchange) this.chb.onchange(); 
			return false; 
		}
		else if(this.chb.onchange) this.chb.blur(); 
		return true;
	}
};




//Custom select control
//--------------------------------
//> INITIALIZE
//  new Select(select_obj)

Forms.select=function(obj){
	var _this=this;
	var _block, _element, _field, _content, _dropdown, _arrow,  _inInit;
	
	this.isOpen=false;
	
	this.init=function(){
		_inInit=true;
		obj.style.display="none";
		
		this.isOver=0;
		
		_block=document.createElement("span");
		_block.className="custom_select "+obj.className;
		_block.onmouseover=function(){_this.isOver=1};
		_block.onmouseout=function(){_this.isOver=0};
				
		//create hidden input element for submit
		_element=document.createElement("input");
		_element.type="hidden";
		_element.value=obj.value;
		_element.name=obj.name;
		_element.id=obj.id;
		_element.disabled=obj.disabled;
		_element.aref=_ATTR(obj, "aref");
		_element.target=_ATTR(obj, "target");
		_element.onchange=obj.onchange;
		_element.autoload=(_ATTR(obj,"autoload")!=undefined);
		_element.className="";
		_element.update=function(){_this.update(_element)};
		_element.reset=function(){_this.set(_element.defaultElement)};
		_block.appendChild(_element);
		
		
		_field=document.createElement("var");
		_field.className="field";
		_element.field=_field;
		_arrow=document.createElement("a");
		_arrow.className="arrow";
		_field.appendChild(_arrow);
		_content=document.createElement("var");
		_field.appendChild(_content);
		_block.appendChild(_field);
		_content.onclick=_arrow.onclick=function(){return _this.dropdown()};
									
		_dropdown=document.createElement("span");
		_dropdown.className="dropdown";
		
		_element.options=[];
		if(obj.options.length)
			for(var i=0; i<obj.options.length; i++) {
				var a=document.createElement("a");
				a.innerHTML=obj.options[i].innerHTML;
				a.className=obj.options[i].className;
				a.value=obj.options[i].value;
				a.onclick=function(){return _this.set(this);};
				CSS(a).set({display:"block", whiteSpace:"nowrap", textDecoration:"none" });
				//CSS(a).copy("color", obj.options[i]);
				_element.options.push(a);
				if(obj.options[i].selected || obj.value==a.value) _element.selected=_element.defaultElement=a;
				if(_ATTR(obj.options[i],"image")){
					var img=document.createElement("img");
					img.src=_ATTR(obj.options[i],"image");
					a.insertBefore(img, a.firstChild);
				}
				_dropdown.appendChild(a);
			}
		_block.appendChild(_dropdown);
		setTimeout(function(){_this.create()},12); //replace select to custom select after initializing
		
		return this;
	};
	
	this.create=function(){
		if(!obj || !obj.parentNode) return false;
		
		obj.parentNode.replaceChild(_block, obj);
		
		//overwrite styles
		CSS(_block).set({position:"relative", textDecoration:"none"});
		if(BROWSER.ie){ if(document.selects_count==undefined) document.selects_count=0; CSS(_block).set({zIndex:100-(document.selects_count++)});} //fix z-index for IE
		CSS(_field).set({whiteSpace:"nowrap"});
		CSS(_content).set({fontStyle:"normal"});
		CSS(_arrow).set({position:"absolute", display:"block", top:0, right:0});
		CSS(_dropdown).set({position:"absolute", visibility:"hidden"});

		if(obj.options.length){
			_element.selected ? this.set(_element.selected) : this.set(_element.options[0]); //set default or act
			addEvent(document,"mouseup", function(){if(_this.isOpen && !_this.isOver) setTimeout(function(){_this.dropdown(0)},40)}); //define exernal click event
		}
		_inInit=false;
	};
	
	this.update=function(_element){
		//Style(_element.field)[_element.disabled?"add":"remove"]("disabled");
		for(var i=0; i<_element.options.length; i++) {
			if(_element.options[i].value==_element.value){
				this.set(_element.options[i]);
				break;	
			}				
		}
	};
	
	this.dropdown=function(d){
		if(_element.disabled) return false;
		if(parseInt(CSS(_dropdown).get("width"))==_dropdown.clientWidth) CSS(_dropdown).set({height:"auto"}); //if scroll bar = auto height
		if(d==undefined) d=_dropdown.style.visibility!="visible";
		_dropdown.style.visibility=d?"visible":"hidden";
		
		this.isOpen=d;
		return false;
	};
	
	this.set=function(obj){
		_element.prevValue=_element.value;
		_element.value=obj.value;
		_element.selected=obj;
		_content.innerHTML=obj.innerHTML;
		
		this.autoInlineWidth();
		this.dropdown(0);
		
		if((!_inInit && _element.prevValue!=_element.value) || _element.autoload){
			if(_element.onchange) _element.onchange(); //call onchange event
			if(_element.aref) GET(_element); //call onchange event
		}
		
		//act element in dropdown
		if(this.cur) Style(this.cur).remove("act");
		Style(obj).add("act");
		this.cur=obj;
		
		return false;
	};
	
	this.autoInlineWidth=function(){
		if(CSS(_block).check({display:"block"})) return false; //control is block
		_field.style["paddingRight"]=0;
		var offset=_dropdown.offsetWidth-_field.offsetWidth-parseInt(CSS(_field).get("marginRight"))-parseInt(CSS(_field).get("marginLeft"))-parseInt(CSS(_block).get("borderRightWidth"))-parseInt(CSS(_block).get("borderLeftWidth"));
		if(offset>0) _field.style["paddingRight"]=offset+"px";
	};
	
	
		
	return this.init();
};

//initialize output content
function init_content(root){
	
	var tags;
		
	if(tags=_(root, "~@script")){
		for(var i=0, l=tags.length; i<l; i++){
			if((tags[i].type=="ajax/javascript" || !tags[i].type)){
				var func=(new Function(tags[i]?tags[i].innerHTML:""));
				if(!tags[i].src) func.apply(tags[i]); //normal script execution
				else try{func.apply(tags[i])}catch(e){Script.preload(tags[i])} //modular script execution
			}
		}
	}


	if(tags=_(root, "~@a")){
		for(var i=0, l=tags.length; i<l ;i++){
			var tag=tags[i];
			
			if(_ATTR(tag, "aref")) tag.aref=_ATTR(tag, "aref");
			//if(!tag.aref && tag.href.indexOf("?")!=-1) tag.aref=tag.href;				
			if(tag.aref && !tag.href && !tag.onclick) tag.href="#"; //set empty href value <a href="#"> (for non IE)
			
			if(tag.aref && tag.aref.indexOf("?")!=-1 && !tag.onclick && tag.target.indexOf("_")!=0) tag.onclick=function(e){ return GET(this,e)}; //attach ajax GET handler	
		
			
			if(_ATTR(tag, "type")){
				
				if(_ATTR(tag, "type")=="submit"){ //tag as submit button
					tag.form=tag.target?_(tag.target):_(tag, "/form");
					if(tag.form){
						tag.onclick=function(){return POST(this.form, this)};
						tag.form.submit_button=tag;
						tag.form.onsubmit=function(){this.submit_button.onclick(); return false;}; //send form on ENTER click
					}
				}
				
				if(_ATTR(tag, "type")=="file"){ //tag as file browse control
					tag.onmouseover=function(){Forms.fileBrowse(this)};
				}
			}
			
			if(_ATTR(tag, "autoload")!=undefined && tag.onclick!=undefined){// automatic execute tag onload
				var _tag=tag;
				if(_ATTR(tag, "autoload")) setTimeout(function(){if(_tag && _tag.parentNode) _tag.onclick()}, _ATTR(_tag, "autoload")*1000);
				else _tag.onclick();
			}
			
			if(!tag.onfocus) tag.onfocus=function(){this.blur()};
			
			if(tag.className=="open" && tag.parentNode.className=="help") init_help_block(tag);
			
		}
	}
	
	
	
	if(tags=_(root, "~@select")){
		for(var i=0, l=tags.length; i<l ;i++){
			new Forms.select(tags[i]);
		}
	}

	
};


if(DEBUGGER_ENABLED) Debugger.init();

addEvent(window, "load", function(){				  
});

document.onload=function(){
	HTMLAJAX.loader=_("loader_ico");
	HTMLAJAX.loader.style.display="none";	
	init_content(document);		
	if ((_("block_more_info")) && (getCookie("UserFirstLogin") == 1 ) ) {
		_("block_more_info").onclick();
		setCookie('UserFirstLogin',0,3650)
	}
}
	
//---------AJAX response listeners 


//process the responce variables (json structure)
HTMLAJAX.onresponse=function(response){
	if(!response || !response.obj) return;
	if(response.obj.alert) Popup.show(response.obj.alert);
};

//google analitics
GET.onresponse=function(htmlajax){};




