var MultiselectArray = new Array();

function Multiselect(obj){
	var Multiselect = this;

	/* PROPERTIES */
	this.inputbox = obj.getElementsByTagName('INPUT')[0];
	this.dropimg  = obj.getElementsByTagName('IMG')[0];
	this.dropdown = obj.getElementsByTagName('DIV')[0];
	this.options  = obj.getElementsByTagName('LI');
	this.collapse = this.dropdown.getElementsByTagName('DIV')[0];
	this.status   = false;
	this.def      = 'keine Einschr\u00E4nkung';

	/* MAIN */
	this.inputbox.value=this.def;
        this.inputbox.setAttribute("style", "color:black;");
	this.inputbox.style.color="black";
	this.inputbox.style.backgroundColor="white";

	for(i=0; i < this.options.length; i++){
		this.options[i].onmouseover=function(){
			this.className+=' option-on';
		}
		this.options[i].onmouseout=function(){
			this.className=this.className.replace('option-on','');
		}
		this.options[i].onclick=function(){
			Multiselect.update(this);
		}
		this.options[i].getElementsByTagName('INPUT')[0].onclick=function(){
			this.checked=(this.checked)?false:true;
		}
	}

	/* METHODS */
	this.update=function(option){
		checkbox=option.getElementsByTagName('INPUT')[0];
		value=option.getElementsByTagName('SPAN')[0].innerHTML;

		checkbox.checked=(checkbox.checked)?false:true;

		txt='';
		empty='';
		for(opt=0; opt < this.options.length; opt++){
			if(this.options[opt].getElementsByTagName('INPUT')[0].checked){
				txt+=this.options[opt].getElementsByTagName('SPAN')[0].innerHTML+', ';
			}
		}
		this.inputbox.value=(txt==empty)?this.def:txt.replace(/,\s$/,'').replace('&amp;','&');
		//this.inputbox.disabled=(txt==empty);
                this.inputbox.style.color="black";
		this.inputbox.style.backgroundColor="white";
	}
	this.dropimg.onmousedown=function(){
		this.src=(Multiselect.status)?'/dating/scriptimages/up-click.gif':'/dating/scriptimages/down-click.gif';
	}
	this.dropimg.onmouseup=function(){
		Multiselect.dropopen();
	}
	this.collapse.onclick=function(){
		Multiselect.dropopen();
	}
	this.inputbox.onclick=function(){
		//Multiselect.dropopen();
	}
	this.dropopen=function(){
		this.status=(this.status)?false:true;
		this.dropimg.src=(this.status)?'/dating/scriptimages/up.gif':'/dating/scriptimages/down.gif';
		this.dropdown.style.display=(this.status)?'block':'none';
	}
}


alldiv=document.getElementsByTagName('DIV');
for(n=0; n < alldiv.length; n++){
	if(alldiv[n].className=='multi-select'){
		counter=MultiselectArray.length;
		alldiv[n].style.zIndex=9-counter;
		MultiselectArray[counter] = new Multiselect(alldiv[n]);
	}
}



