/*
*  Copyright Mirek Komárek aka Fred http://js-playground.blogspot.com
*  use as you want until this copyright notice stay here
*/
var d=document,pltext;
function getId(id){
	return d.getElementById(id);
};
function CE(el){
	return d.createElement(el);
}
function SA(el,atrib,val){
	return el.setAttribute(atrib,val);
}
function kostra(id1) {
	getId(id1).style.display='none';
	var cy=CE('div');
	cy.id='cy';
	var pl=CE('p');
	var ul=CE('ul');
	var opt=getId(id1).getElementsByTagName('option');
	for(var i=0;i<opt.length;i++) {
		var li=CE('li');
		ul.appendChild(li);
		var ah=CE('a');
		try {
			if(window.addEventListener) {
				ah.finnRestSort=i+1;
				ah.addEventListener("click", w3cFinnSort ,false);
			}
			else {
				ah.attachEvent("onclick", ieFinnSort(i+1));
			}
		}
		catch(ex) {
			alert(ex.description);
		}
		ah.appendChild(d.createTextNode(opt[i].childNodes[0].nodeValue));
		li.appendChild(ah);
	}
	var inp=CE('input');
	SA(inp,'type','hidden');
	inp.value='';
	inp.id='cil';
	getId(id1).parentNode.insertBefore(cy,getId(id1).nextSibling);
	cy.appendChild(pl);
	cy.appendChild(ul);
	cy.parentNode.insertBefore(inp,cy);
	var lbl=d.getElementsByTagName('label');
	for(var i=0;i<lbl.length;i++) {
		if(lbl[i].htmlFor==id1) {
			lbl[i].style.display='none';
			pl.appendChild(d.createTextNode(lbl[i].childNodes[0].nodeValue));
		}
	}
}
function ieFinnSort(finnRestSort) {
	return function() {
		try { 
			Sem.setSortMethod(finnRestSort);
		}
		catch(ex) {
			alert(ex.description);
		}
	}
}
function w3cFinnSort() {
	try {
		Sem.setSortMethod(this.finnRestSort);
	}catch(ex) {
		alert(ex.description);
	}
}
function gv() {
	kostra('cx');
	var kde=getId('cy');
	var fC=kde.firstChild;
	if(kde.firstChild.nodeType==3) {
		fC=kde.firstChild.nextSibling;
	}//gecko
	fC.onclick=function() {
		this.parentNode.className=this.parentNode.className=='hd'?'':'hd';
	};
	fC.onmouseover=function() {
		this.className='hv';
	};
	fC.onmouseout=function() {
		this.className='';
	};
	kde.className='hd'; 
	var co=kde.getElementsByTagName('a');
	for(var i=0;i<co.length;i++) {
	
		co[i].onclick=function(){
			getId('cil').value=this.getAttribute('rel');
			this.parentNode.parentNode.parentNode.className='hd';
			var ntext=d.createTextNode(this.childNodes[0].nodeValue);
			fC.removeChild(fC.childNodes[0]);
			fC.appendChild(ntext);
			return false;
		};
	}
}
if(document.childNodes){
	window.onload= function() {
		if(Sem.getListType()!="null" && Sem.getListType()!="") {
			gv();
		}
		Sem.onLoad();
	}
}
	
