splitSelect = {
	selects:[],
	current:null,
	firstName:'discipline_lvl_1',
	secondName:'discipline_lvl_2',
	init:function(){
		var s = document.getElementById(splitSelect.firstName);
		var c = document.createElement('select');
		c.onchange=function(){
			splitSelect.choose(this.selectedIndex);
		}
		s.parentNode.insertBefore(c, s);
		var g = s.getElementsByTagName('optgroup');
		for(var i=0,j=g.length;i<j;i++){
			var o = g[i].getElementsByTagName('option');
			var news = document.createElement('select');
			s.parentNode.insertBefore(news, s);
			news.style.display='none';
			splitSelect.selects.push(news);
			var k=0;
			c.appendChild(o[0]);
			while(o[k]){
				if(o[k].getAttribute('selected')==='selected'){
					splitSelect.current = i;
					news.style.display = 'block';
				}
				news.appendChild(o[k]);
			}
		}
		c.selectedIndex = splitSelect.current;
		s.parentNode.removeChild(s);
		c.id = splitSelect.firstName;
		c.name = splitSelect.firstName;
		if(splitSelect.current === null){
			splitSelect.selects[0].style.display = 'block';
			splitSelect.selects[0].selectedIndex = 0;
			c.selectedIndex = 0;
			splitSelect.current = 0;
		}
	},
	choose:function(o){
		
		if(splitSelect.current !== null){
			
			splitSelect.selects[splitSelect.current].style.display='none';
			splitSelect.selects[splitSelect.current].name='';
		}
		
		splitSelect.selects[o].style.display='block';			
		splitSelect.selects[o].name=splitSelect.secondName;			
		splitSelect.current = o;
		
		splitSelect.selects[o].firstChild.selected = 'selected';
	}
}
window.onload=splitSelect.init;