function toggle(elem)
{
	document.getElementById(elem).style.display = (document.getElementById(elem).style.display == "none") ? "" : "none";
}

function openwindow(adress, width, height)
{
	if (width === undefined) width = 880;
	if (height === undefined) height = 570;
	var ran_number= Math.floor(Math.random()*5);
	window.open(adress, 'imagepop' + ran_number,'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+width+', height='+height+', top=100, left=100');

}

function lura_spambots(name, address, domain) {
	document.write("<a href=\"mailto:" + name + "@" + address + "." + domain + "\">" + name + "[<!-- -->at]" + address + "." + domain + "</a>");
}

function externalLinks()
{
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i < anchors.length; i++)
	{
		var ankare = anchors[i];
		if (ankare.getAttribute("href") && ankare.getAttribute("rel") == "external")
			ankare.target = "_blank";
	}
}

function MultiFileUpload(elInput, elList, p)
{
	this.maxFiles = $p(p, "maxfiles", 4096); /* LARGE_ROUND_NUMBER */
	this.namePrefix = $p(p, "prefix", "file");
	var tmpInput = $e(elInput);
	this.elList = $e(elList);
	this.numFiles = 0;
	
	tmpInput.parentNode.replaceChild(this.elInput = this.makeFileInput(), tmpInput);
	L.Element.removeAllChildren(this.elList);
}

MultiFileUpload.prototype =
{
	makeFileInput: function()
	{
		var i;
		i = document.createElement("input");
		i.setAttribute("type", "file");
		i.type = "file";
		L.attachEvent(i, "change", this, this.addFile);
		return i;
	},

	addFile: function(e)
	{
		if (this.numFiles < this.maxFiles)
		{
			var tmpInput = this.makeFileInput();
			this.elInput.parentNode.replaceChild(tmpInput, this.elInput);
			var li = document.createElement("li");
			
			var an = document.createElement("a");
			an.appendChild(document.createTextNode(L.File.baseName(this.elInput.value)));
			an.href = "#";
			an.title = "Remove me";
			L.attachEvent(an, "click", this, this.removeFile);
			li.appendChild(an);
			
			this.elInput.name = this.namePrefix + this.numFiles;
			this.elInput.style.display = "none";
			li.appendChild(this.elInput);
			
			this.elList.appendChild(li);
			
			this.elInput = tmpInput;

			this.numFiles++;
		}
		else
		{
			alert("Maximum number of files reached!");
			this.elInput.value = "";
		}
	},

	removeFile: function(e)
	{
		e.thisElement.parentNode.parentNode.removeChild(e.thisElement.parentNode);
		this.numFiles--;
		return false;
	}
};		
