			function ComboBox(input, list, cid, currId, callback,ev_blur){
				for (method in this) input[method] = this[method]
				addEvent("click", document, this.delSuggest.bind(input))
				input.currchild = -1;
				input.onkeyup = input.expand
				input.onblur  = input.checkField				
				if(ev_blur)	input.ev_blur  = ev_blur						
				input.onclick = input.expand				
				input.content = input.drawSuggest()
				input.position = 0
				
				if(!callback) input.callbackfnk = '"$(\'"+this.id+"\').value=\'"+list[i].name+"\';$(\'"+this.id+"\').setAttribute(\'param\',\'"+list[i].cid+"\')"'
				else input.callbackfnk = callback;
				if(!list.length) input.list = new Array(list);
				else input.list = list				
				
				if(cid)input.cid = cid;
				else input.cid = 'cid'
				if(currId) input.setAttribute("param",currId)
				else input.setAttribute("param","-1")
				return input
			}
			ComboBox.prototype.checkField = function(e){				
				if(this.value !='' && this.getAttribute('param')=='-1'){
					alert('Error: Incorrect data :'+ this.value)
					this.value =''
				}
				if(this.ev_blur)	eval(this.ev_blur);

			}
			ComboBox.prototype.expand = function(e){
				if(window.event || e){
					if(window.event) e = window.event
					if(e.keyCode == 16 || e.keyCode == 37 || e.keyCode == 39) return					
					if(e.keyCode == 13){	
						var div = document.getElementById(this.cid+'_'+this.currchild)
						this.delSuggest()
						if(!div) return
						fireEvent(div,'click')
						//document.getElementById(this.id).value=div.innerHTML	
						//document.getElementById(this.id).setAttribute('param',div.getAttribute('param'))						
						this.currchild = -1;						
						this.delautosuggest()												
						return
					}
					if(e.keyCode == 8 || e.keyCode == 46){
						if(this.timer) clearTimeout(this.timer)
						this.timer = setTimeout(this.expand.bind(this),500)
						return
					}
							
				}
				
				var id = this.checkValue()
				if(id == -1) this.setAttribute("param","-1")
				else this.setAttribute("param",id)					
			
				if(this.value.length == 0){
					this.buildSuggest(this.list)
					switch(e.keyCode){
					case 38: //up
						this.prevNode()
					if(parseInt(document.getElementById(this.cid+'_'+this.currchild).offsetTop)+20>=this.content.offsetHeight){
						this.content.scrollTop = parseInt(this.content.scrollTop)+25;							
						}

					break;
					case 40: //down
						this.nextNode()
						var h = parseInt(document.getElementById(this.cid+'_'+this.currchild).offsetTop);
						if(h+20>=this.content.offsetHeight){						
							this.content.scrollTop = parseInt(this.content.scrollHeight)+25;
						}

					break;
					}
					return
				}

				//this.position = this.value.length 

				
				switch(e.keyCode){
					case 38: //up
						this.prevNode()						
					break;
					case 40: //down
						this.nextNode()
					break;
					default:
					var filter = this.suggest()
		
					if(filter.length){
						//this.value = filter[0]
//						this.selectItem(this.position, this.value.length)
						this.buildSuggest(filter)
						//this.nextNode()					
						if(this.currchild!=-1){
							var div = document.getElementById(this.cid+'_'+this.currchild)
							if(!div) return
							document.getElementById(this.id).setAttribute('param',div.getAttribute('param'))																			
							this.setNode(0)
						}
					} else this.delSuggest()					
					break;
				}

			}

			ComboBox.prototype.checkValue= function(){
				for(var i=0; i <this.list.length; i++){
					if(this.list[i].name == this.value) return this.list[i].eval(this.cid)				
				} return -1
			}

		/*	ComboBox.prototype.selectItem = function(start, end){
				if(this.setSelectionRange) this.setSelectionRange(start, end)
				else if (this.createTextRange) {
					var range = this.createTextRange();
					range.collapse(true);
					range.moveStart('character', start);
					range.moveEnd('character', end);
					range.select();					
				}
			}*/

			ComboBox.prototype.suggest = function(){
				var filter = []
				var f = false;					
				var s,v;				
				for(var i=0; i <this.list.length; i++){
					if(this.list[i].name == this.value) return []
					if(this.list[i].name.substr(0, this.value.length).toLowerCase() == this.value.toLowerCase()){
						if(!f){
						s = this.value;						
						v = this.list[i].name;	
						f = true;			
						this.currchild = 0;
						}
						filter.push(this.list[i])
					}
					
				}
				if(f){				
					this.value = v;			 
					this.autosuggest(s,v);
				}
				return filter
			}
			ComboBox.prototype.delSuggest = function(e){
				if(e && e.target == this) return
				this.content.innerHTML = ""
				this.content.style.display = "none"				
			}
			ComboBox.prototype.drawSuggest = function(list){
				var div = _("div");
				var _div = $('lists_box');
				if(!_div){
					_div = _("div");
					_div.style.width = "0px;"				
					_div.style.height = "0px;"									
					_div.id = "lists_box"
					document.body.appendChild(_div)					
				}
				div.style.position = "absolute"
				div.style.left = position(this).x + "px"
				div.style.top = position(this).y + + this.offsetHeight + "px"
				div.style.width = parseInt(this.offsetWidth)-2 + "px"
				div.style.height = "80px"
				div.style.background = "#EEE"
				div.style.border = "1px #CCC solid"
				div.style.overflowY = "scroll"
				div.style.display = "none"
				div.style.zIndex = "1000"				
				_div.appendChild(div)
				return div
			}
			ComboBox.prototype.setNode = function(index){			
				if(this.currchild > 0) 
				document.getElementById(this.cid+'_'+this.currchild).style.backgroundColor ='#EEEEEE';					
				document.getElementById(this.cid+'_'+index).style.backgroundColor ='#CCCCCC';		
				this.currchild =index;
			}			
			ComboBox.prototype.nextNode = function(){			
				if(this.currchild == this.content.childNodes.length-1){ 
					document.getElementById(this.cid+'_'+this.currchild).style.backgroundColor ='#CCCCCC';		
					return;		
				}
				this.currchild = this.currchild+1;				
				if(this.currchild != 0) document.getElementById(this.cid+'_'+this.currchild).style.backgroundColor ='#EEEEEE';	
				document.getElementById(this.cid+'_'+this.currchild).style.backgroundColor ='#CCCCCC';		
			}
			ComboBox.prototype.prevNode = function(){
				if(this.currchild  == '0') {
					document.getElementById(this.cid+'_'+this.currchild).style.backgroundColor ='#CCCCCC';
					return;
				}
				if(this.currchild  != this.content.childNodes.length)
				document.getElementById(this.cid+'_'+this.currchild).style.backgroundColor ='#EEEEEE';			
				this.currchild  =  this.currchild-1;				
				document.getElementById(this.cid+'_'+this.currchild).style.backgroundColor ='#CCCCCC';
			}
			ComboBox.prototype.buildSuggest = function(list){
				if(this.content.parentNode)
				this.content.parentNode.removeChild(this.content)
				this.content = this.drawSuggest()				
				this.content.style.display = "block"
				
				
//				else this.callbackfnk = eval(this.callbackfnk);
				for(var i=0; i<list.length; i++ ){
					var d = CreateNode('div',{id:this.cid+'_'+i,
											   param:list[i].cid+'',
											   onmouseover:'this.style.background=\'#CCCCCC\'',
  											   onmouseout:'this.style.background=\'#EEEEEE\'',
											   onclick:eval(this.callbackfnk),
  											   style:{cursor:'pointer',marginTop:'3px'}},this.content)
					d.innerHTML = list[i].name;					

				}

			}
			ComboBox.prototype.autosuggest = function(start,end){
				if(this.setSelectionRange) this.setSelectionRange(start.length, end.length)
				else if (this.createTextRange) {
					var range = this.createTextRange();
					range.moveStart('character', start.length);
					range.moveEnd('character', end.length);
					range.select();					
				}    
				this.focus();
			}
			ComboBox.prototype.delautosuggest = function(){
				if(this.setSelectionRange) this.setSelectionRange(0, 0)
				else if (this.createTextRange) {
					var range = this.createTextRange();
					range.collapse(true);
					range.moveStart('character', 0);
					range.moveEnd('character', 0);
					range.select();					
				}     
				this.blur(); 
			}
function CreateNode(name,param,parent){
	var obj = document.createElement(name);
	if(param) CreateParam(param,obj) 
	if(parent) parent.appendChild(obj)
	return obj;
}

function CreateParam(param,obj){
	for(var p in param){
		if(p == 'style')
			CreateParam(param[p],obj.style)
		else	
			if(obj.setAttribute) obj.setAttribute(p,param[p]);
			else obj[p] = param[p];			
	}
}
			
function CopySelect(src,new_index,if_is){
if(!if_is)if_is=false;
var new_select = _('SELECT');
if(!new_index)new_index=-1;
new_select = CopyAttr(src,new_select);	
for(var i=0; i < src.options.length;i++){	
	var o = _('OPTION')
	if(src.options[i].value == new_index) src.options[i].setAttribute('selected','selected')
	else src.options[i].removeAttribute('selected')					
	CopyAttr(src.options[i],o)
	o.innerHTML = src.options[i].innerHTML;					
	if(if_is != false){
		if(src.options[i].getAttribute(if_is.attribute) == if_is.value)	o.style.display = ''
		else o.style.display = 'none'
	}
	new_select.appendChild(o)
}	
return new_select;
}

function setSelectIndex(src,new_index,if_is){
	var s = CopySelect(src,new_index,if_is);
	src.parentNode.appendChild(s)
	src.parentNode.removeChild(src)	
	return s;
}

function CopyAttr(src,tar){
	for(var i=0; i < src.attributes.length;i++){
		tar.setAttribute(src.attributes[i].name,src.attributes[i].value)		
	}return tar;
}


function copyForm(f_src,f_targ) {	
	for(var i=0;i<f_src.length;i++){
		if(f_src[i].nodeName == 'INPUT' || f_src[i].nodeName == 'TEXTAREA'){	
			f_targ[i].value = f_src[i].value
			CopyAttr(f_src[i],f_targ[i])			
		}else if(f_src[i].nodeName == 'SELECT'){
			f_targ[i].value = f_src[i].value
			for(var j=0; j < f_src[i].options.length;j++){	
				f_targ[i].options[j].innerHTML = f_src[i].options[j].innerHTML;	
				f_targ[i].options[j].removeAttribute("selected")				
				CopyAttr(f_src[i].options[j],f_targ[i].options[j])										
			}                         
		}
	}
}

function replaceChar(str,from,to){
	while(str.indexOf(from) != -1)
		str = str.replace(from, to)
	return str;		
}
function fireEvent(obj,e){
  var event;
  if(document.createEventObject) {
    event = document.createEventObject();
    obj.fireEvent('on'+e, event);
  }
  else if(document.createEvent) {
    event = document.createEvent('MouseEvents');
    event.initEvent(e, 1, 1);
    obj.dispatchEvent(event);
  }
		
}
function htmlspecialchars(str){	
	//str = str.replace(/\&/g, "&#38;");
	/*str = str.replace(/\'/g, "&#39;");
	str = str.replace(/\"/g, "&#34;");
	str = str.replace(/\</g, "&#60;");
	str = str.replace(/\>/g, "&#62;");*/
	return str;
}
function setImageSize(img,w,h){
	var p = img.parentNode;
	var _img = new Image();	
	_img.src = img.src;	
	_img.id = img.id;	
	_img.name = img.name;			
	if(w)_img.width=w;
	if(h)_img.height=h;		
	p.removeChild(img)
	p.appendChild(_img)	
}
function _void(){}

String.prototype.isNumber = function(){
	var reg = /[0-9]/; 
	if(reg.test(this))
	
	return true;	
	return false;	
}

/*
function _to_utf8(s) {
  var c, d = "";
  for (var i = 0; i < s.length; i++) {
    c = s.charCodeAt(i);
    if (c <= 0x7f) {
      d += s.charAt(i);
    } else if (c >= 0x80 && c <= 0x7ff) {
      d += String.fromCharCode(((c >> 6) & 0x1f) | 0xc0);
      d += String.fromCharCode((c & 0x3f) | 0x80);
    } else {
      d += String.fromCharCode((c >> 12) | 0xe0);
      d += String.fromCharCode(((c >> 6) & 0x3f) | 0x80);
      d += String.fromCharCode((c & 0x3f) | 0x80);
    }
  }
  return d;
}

function _from_utf8(s) {
  var c, d = "", flag = 0, tmp;
  for (var i = 0; i < s.length; i++) {
    c = s.charCodeAt(i);
    if (flag == 0) {
      if ((c & 0xe0) == 0xe0) {
        flag = 2;
        tmp = (c & 0x0f) << 12;
      } else if ((c & 0xc0) == 0xc0) {
        flag = 1;
        tmp = (c & 0x1f) << 6;
      } else if ((c & 0x80) == 0) {
        d += s.charAt(i);
      } else {
        flag = 0;
      }
    } else if (flag == 1) {
      flag = 0;
      d += String.fromCharCode(tmp | (c & 0x3f));
    } else if (flag == 2) {
      flag = 3;
      tmp |= (c & 0x3f) << 6;
    } else if (flag == 3) {
      flag = 0;
      d += String.fromCharCode(tmp | (c & 0x3f));
    } else {
      flag = 0;
    }
  }
  return d;
}
*/