splitSelect = {
	selects:[],
	current:null,
	firstName:'type_formation_lvl_1',
	secondName:'type_formation_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';
	}
}


splitSelect2 = {
	selects:[],
	current:null,
	firstName:'discipline_lvl_1',
	secondName:'discipline_lvl_2',
	init:function(){
		var s = document.getElementById(splitSelect2.firstName);
		var c = document.createElement('select');
		c.onchange=function(){
			splitSelect2.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';
			splitSelect2.selects.push(news);
			var k=0;
			c.appendChild(o[0]);
			while(o[k]){
				if(o[k].getAttribute('selected')==='selected'){
					splitSelect2.current = i;
					news.style.display = 'block';
				}
				news.appendChild(o[k]);
			}
		}
		c.selectedIndex = splitSelect2.current;
		s.parentNode.removeChild(s);
		c.id = splitSelect2.firstName;
		c.name = splitSelect2.firstName;
		if(splitSelect2.current === null){
			splitSelect2.selects[0].style.display = 'block';
			splitSelect2.selects[0].selectedIndex = 0;
			c.selectedIndex = 0;
			splitSelect2.current = 0;
		}
	},
	choose:function(o){
		if(splitSelect2.current !== null){
			splitSelect2.selects[splitSelect2.current].style.display='none';
			splitSelect2.selects[splitSelect2.current].name='';
		}
		splitSelect2.selects[o].style.display='block';			
		splitSelect2.selects[o].name=splitSelect2.secondName;			
		splitSelect2.current = o;
		splitSelect2.selects[o].firstChild.selected = 'selected';
	}
}
/*
window.onload=splitSelect.init;
window.onload=splitSelect.init;
*/
SafeAddOnload(splitSelect.init);
SafeAddOnload(splitSelect2.init);