/* 
	Author: marele, Framfab
*/

/*
	DropDownSelector Constructor
*/
function DropDownSelector()
{

}
DropDownSelector.prototype = new Utils();

DropDownSelector.prototype.populateDropDown = function (sId)
{
	// 
	var oThis = this;
	
	// 
	var oContainer = this.getObj("dropdown-" + sId);
	var oLinks = this.getObj("links-" + sId);
	var aLinks = oLinks.getElementsByTagName("a");

	//
	var oForm = document.createElement("form");
	var oSelect = document.createElement("select");
	oSelect.id = "select-" + sId;
	oSelect.onchange = this.changePage;
	oForm.appendChild(oSelect);
	
	//
	oContainer.appendChild(oForm)
	
	var qStr = (location.search != "") ? location.search.substring(1,location.search.length) : false;
	var year = false;
	if(qStr){
		if(qStr.toLowerCase().indexOf('year') != -1) year = qStr.substring(qStr.indexOf('year'), qStr.length).split("&")[0].split("=") [1];
	}

	for(var i=0; i<aLinks.length; i++) {
		oSelect.options[i] = new Option(aLinks[i].firstChild.nodeValue, aLinks[i].href);
		if(aLinks[i].href == location.href || aLinks[i].firstChild.nodeValue == year) oSelect.options[i].selected = true;
	}
	
	oLinks.style.display = "none";
	//o.style.display = (o.className.indexOf('inline') != -1) ? "inline" : "block";
}

DropDownSelector.prototype.changePage = function()
{
	var sLocation = this.options[this.selectedIndex].value;
	if(sLocation.indexOf("execjs#") != -1){
		var iStart = sLocation.indexOf("execjs#")+7;
		var sJSMethodCall = sLocation.substring(iStart);
		try {
			var oFunc = new Function(sJSMethodCall);
			oFunc();
		} catch(e) { }
	} else {
		document.location.href = sLocation;
	}
}
DropDownSelector.prototype.moveDropDown = function(sId)
{
	// Get first article element
	var oDiv = document.getElementsByTagName("div");
	var oInsertionPoint = false;
	for(var i=0; i<oDiv.length; i++){
		if(oDiv[i].className.indexOf("inner") != -1){
			oInsertionPoint = oDiv[i];
			break;
		}
	}
	if(oInsertionPoint){
		var oSelect = document.getElementById("dropdown-" + sId)
		oInsertionPoint.insertBefore(oSelect,oInsertionPoint.firstChild);
	}
}