/* Variables */
window.ondomready = initReady;
window.ondomready(onReady);
window.onerror = stopError;
var uploads = new Array(null);
var deleted = new Array();
var newMain = "";
var currentUpload = 1;
var countUploads = 0;
var clicked = 0;
var clickPosition = "";
var webcamOpened = 0;
var current = 0;
var ignoreOpen = 0;
var foundWebcam = 0;
var contextmenuElement = null;
var fileId;
var urlOpened = 0;
var total = 0;
var startTime = 0;
var rateArray = new Array();
var url = new Array();
var imagesCount = 0;
var imagesArray = new Array();
var provider = location.href.split("/")[2].split(".")[(location.href.split("/")[2].split(".").length - 2)];
if (provider != "xade" || !provider) {
	provider = "m9x";
	}

/* Functions */
function stopError() {
	return true;
	}
function getElement(id, id2) {
	id = id.toString();
	if (id2 && id2 != null) {
		id += id2.toString();
		}
	if (window.document.getElementById) {
		return window.document.getElementById(id);
		}
	else {
		return window.document.all[id];
		}
	}
function getMovie(name) {
	if (navigator.appName.indexOf("Microsoft") != -1) {
		return window[name];
		}
	else {
		return window.document[name];
		}
	}
function browse(name, uploader) {
	countUploads ++;
	id = uploads.length;
	url = "";
	if (uploader == "url") {
		url = name;
		}
	getElement("url", id).value = url;
	name = name.split("\\");
	name = name[(name.length - 1)];
	name = name.split("/");
	name = name[(name.length - 1)];
	name = name.split("?");
	name = name[0];
	name = name.split(".");
	if (name.length == 1) {
		name[1] = "";
		}
	type = name[(name.length - 1)].toLowerCase();
	filetype = "application";
	if (type == "png" || type == "gif" || type == "jpg" || type == "jpeg" || type == "bmp") {
		imagesCount ++;
		filetype = "image";
		}
	else if (type == "mp3" || type == "wma" || type == "mp2" || type == "wav") {
		filetype = "audio";
		}
	else if (type == "avi" || type == "flv" || type == "mpeg" || type == "mpg" || type == "wmv" || type == "ogg" || type == "mov" || type == "3gp" || type == "3gpp" || type == "3g2" || type == "mp4" || type == "vob") {
		filetype = "video";
		}
	else if (type == "txt" || type == "html" || type == "htm" || type == "php" || type == "pl" || type == "cgi") {
		filetype = "text";
		}
	name[(name.length - 1)] = "";
	newName = name[0];
	for (i = 1; i < name.length - 1; i ++) {
		newName += "." + name[i];
		}
	name = newName;
	uploads[id] = "file";
	if (uploader) {
		uploads[id] = uploader;
		}
	file = window.document.createElement("div");
	file.className = "file";
	file.id = "file" + id;
	file.style.backgroundImage = "url(./images/icons/types/" + filetype + ".png)";
	file.innerHTML = "<div style=\"position: absolute; left: 25px; margin-top: 2px;\"><strong>" + language['name'] + ":</strong> <input type=\"text\" class=\"upload_name\" id=\"value" + id + "\" value=\"" + name + "\" maxlength=\"150\" /></div> <span id=\"status" + id + "\" style=\"position: absolute; right: 0px;\"><div title=\"" + language['delete'] + "\" style=\"float: left; width: 24px; height: 24px; background-image: url(./images/icons/close.png); background-repeat: no-repeat; background-position: 4px 4px; cursor: pointer;\" onclick=\"deleteUpload(" + id + ");\" onmousedown=\"getElement('focus').focus(); clicked = this; this.style.backgroundPosition = '5px -18px';\" onmouseover=\"clickPosition = this.style.backgroundPosition; this.style.backgroundPosition = '4px -19px';\" onmouseout=\"if (clicked == 0) this.style.backgroundPosition = '4px 4px';\"></div></span>";
	getElement("files").appendChild(file);
	getElement("fileinput", id).style.display = "none";
	getElement("value", id).focus();
	id ++;
	fileUpload = window.document.createElement("div");
	fileUpload.id = "file_input" + id;
	fileUpload.innerHTML = "<iframe src=\"./null/\" id=\"uploadframe" + id + "\" name=\"uploadframe" + id + "\"></iframe><form action=\"./\" method=\"post\" target=\"uploadframe" + id + "\" id=\"form" + id + "\" enctype=\"multipart/form-data\" class=\"inline\"><input type=\"hidden\" name=\"UPLOAD_IDENTIFIER\" value=\"" + getElement("uploadid").value + id + "\" /><input type=\"hidden\" name=\"name\" value=\"\" id=\"name" + id + "\" /><input type=\"hidden\" name=\"url\" value=\"\" id=\"url" + id + "\" /><input type=\"file\" name=\"file\" class=\"file\" id=\"fileinput" + id + "\" tabindex=\"1\" onchange=\"browse(this.value);\" onmousedown=\"clicked = getElement('browse'); clicked.style.backgroundPosition = '3px -16px';\" onmouseover=\"clickPosition = getElement('browse').style.backgroundPosition; getElement('browse').style.backgroundPosition = '2px -17px';\" onmouseout=\"if (clicked == 0) getElement('browse').style.backgroundPosition = '2px 6px';\" /></form>";
	getElement("file_container").appendChild(fileUpload);
	return id - 1;
	}
function updateProgress(id, percent, time) {
	getElement("progressbar", id).style.width = (percent * 4.93) + "px";
	getElement("progressvalue", id).innerHTML = percent;
	getElement("progresstime", id).innerHTML = time;
	}
function startUpload() {
	countFiles = 0;
	for (id = 1; id < uploads.length; id ++) {
		if (!isDeleted(id)) {
			countFiles ++;
			getElement("value", id).disabled = "disabled";
			getElement("name", id).value = getElement("value", id).value;
			setStatus(id, "loading");
			}
		}
	if (countFiles > 0) {
		nextUpload();
		}
	}
function nextUpload() {
	while (isDeleted(currentUpload) == true) {
		currentUpload ++;
		}
	if (!uploads[currentUpload]) {
		setTimeout("finished()", 500);
		return true;
		}
	upload(currentUpload);
	currentUpload ++;
	}
function finished() {
	if (imagesCount >= 2) {
		newMain = 	"<div class=\"label_slideshow_url\"><div style=\"float: left;\">" + language['slideshow_url'] + "</div><div style=\"float: right;\"><input type=\"checkbox\" id=\"select_all\" checked=\"checked\" onclick=\"selectAll(this);\" /> <label for=\"select_all\">" + language['select_all'] + "</label></div></div>\n" +
				"<input type=\"text\" class=\"show_url\" value=\"http://" + provider + ".de/slideshow\" id=\"slideshow\" readonly=\"readonly\" onfocus=\"this.select();\" onclick=\"this.select();\" onmouseup=\"this.select();\" /><br /><br />\n" +
				newMain;
		}
	getElement("main").innerHTML = newMain;
	for (i = 0; i < imagesArray.length; i ++) {
		setTimeout("addSlideshow('" + imagesArray[i] + "')", 100);
		}
	}
function uploadType(id) {
	return uploads[id];
	}
function isDeleted(id) {
	if (deleted[id]) {
		return true;
		}
	return false;
	}
function upload(id) {
	current = id;
	if (uploadType(id) == "webcam") {
		getMovie("webcam" + id).upload(id, getElement("value", id).value);
		}
	else if (uploadType(id) == "url") {
		getElement("form", currentUpload).submit();
		watchUpload(id);
		startUrlProgress(id);
		}
	else if (uploader == "html") {
		getElement("form", currentUpload).submit();
		watchUpload(id);
		getProgress(id);
		}
	else {
		getMovie("flash_upload").upload(id, getElement("value", id).value);
		}
	getElement("file", id).style.height = "48px";
	file = window.document.createElement("div");
	file.className = "progressbar";
	file.innerHTML = "<div id=\"progressbar" + id + "\"></div><span><span id=\"progressvalue" + id + "\">0</span>% (<span id=\"progresstime" + id + "\">0</span> " + language['seconds'] + ")</span>";
	getElement("file", id).appendChild(file);
	}
function watchUpload(id) {
	if (newMain == "") {
		if (countUploads == 1) {
			newMain = "<div class=\"title\">" + language['file_uploaded'] + "</div>\n";
			}
		else {
			newMain = "<div class=\"title\">" + language['files_uploaded'] + "</div>\n";
			}
		}
	finish = getElement("uploadframe", id).contentWindow.document;
	if (finish.body.innerHTML.split("finish").length == 2) {
		updateProgress(id, 100, 0);
		if (window.document.getElementById) {
			id = finish.getElementById("id").value;
			type = finish.getElementById("type").value;
			deleteKey = finish.getElementById("delete").value;
			name = finish.getElementById("name").value;
			width = finish.getElementById("width").value;
			height = finish.getElementById("height").value;
			filetype = finish.getElementById("filetype").value;
			}
		else {
			id = finish.all['id'].value;
			type = finish.all['type'].value;
			deleteKey = finish.all['delete'].value;
			name = finish.all['name'].value;
			width = finish.all['width'].value;
			height = finish.all['height'].value;
			filetype = finish.all['filetype'].value;
			}
		addMain(id, type, deleteKey, name, width, height, filetype);
		}
	else if (finish.body.innerHTML.split("error").length == 2) {
		setStatus(id, "error");
		nextUpload();
		}
	else {
		setTimeout(function() { watchUpload(id); }, 100);
		}
	}
function startUrlProgress(id) {
	startTime = new Date();
	startTime = startTime.getTime() / 1000;
	var xmlHttp = false;
	try {
		xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
	catch(e) {
		try {
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
		catch(e) {
			xmlHttp = false;
			}
		}
	if (!xmlHttp && typeof XMLHttpRequest != "undefined") {
		xmlHttp = new XMLHttpRequest();
		}
	xmlHttp.open("POST", "/url_total");
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
			total = xmlHttp.responseText;
			getUrlProgress(id);
			}
		};
	xmlHttp.send("url=" + getElement("url", id).value);
	}
function getUrlProgress(id) {
	var xmlHttp = false;
	try {
		xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
	catch(e) {
		try {
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
		catch(e) {
			xmlHttp = false;
			}
		}
	if (!xmlHttp && typeof XMLHttpRequest != "undefined") {
		xmlHttp = new XMLHttpRequest();
		}
	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
			nowTime = new Date();
			nowTime = nowTime.getTime() / 1000;
			timeLeft = nowTime - startTime;
			rate = xmlHttp.responseText / timeLeft;
			rateArray[rateArray.length] = rate;
			rateNum = 0;
			for (i = 0; i < rateArray.length; i ++) {
				rateNum += rateArray[i];
				}
			rate = rateNum / rateArray.length;
			time = Math.round((total - xmlHttp.responseText) / rate);
			if (xmlHttp.responseText / total * 100 != 0) {
				updateProgress(id, Math.round(xmlHttp.responseText / total * 100), time);
				}
			if (xmlHttp.responseText / total * 100 < 100) {	
				setTimeout(function() { getUrlProgress(id); }, 100);
				}
			}
		};
	xmlHttp.open("GET", "/url_current/" + getElement("uploadid").value + "" + id);
	xmlHttp.send(null);
	}
function getProgress(id) {
	var xmlHttp = false;
	try {
		xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
	catch(e) {
		try {
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
		catch(e) {
			xmlHttp = false;
			}
		}
	if (!xmlHttp && typeof XMLHttpRequest != "undefined") {
		xmlHttp = new XMLHttpRequest();
		}
	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
			data = xmlHttp.responseText.split(",");
			if (data[0] != "") {
				percent = Math.round(data[0] / data[1] * 100);
				updateProgress(id, percent, data[2]);
				}
			if (finish[id] != 1) {
				setTimeout(function() { getProgress(id); }, 100);
				}
			}
		};
	xmlHttp.open("GET", "./status/" + getElement("uploadid").value + id);
	xmlHttp.send(null);
	}
function addMain(id, type, deleteKey, name, width, height, filetype) {
	showtype = type;
	showname = name.split(" ").join("_");
	imageCheckBox = "";
	if (filetype == "image") {
		if (imagesCount >= 2) {
			imagesArray[imagesArray.length] = id;
			imageCheckBox = "<input type=\"checkbox\" id=\"slideshow" + id + "\" checked=\"checked\" onclick=\"if (this.checked == true) addSlideshow('" + id + "'); else removeSlideshow('" + id + "');\" /> <label for=\"slideshow" + id + "\">" + language['slideshow_add'] + "</label>";
			}
		viewer = "<img src=\"./files/" + id + "/thumbnail/" + showname + "." + showtype + "\" alt=\"" + language['loading'] + "\" style=\"width: " + width + "px; height: " + height + "px;\" />";
		html = "&lt;a href=&quot;http://" + provider + ".de/files/" + id + "/&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://" + provider + ".de/files/" + id + "/" + showname + "." + showtype + "&quot; alt=&quot;" + provider + ".de - files over board&quot; style=&quot;width: " + width + "px; height: " + height + "px;&quot; /&gt;&lt;/a&gt;";
		}
	else if (filetype == "audio" || filetype == "video") {
		showtype = "png";
		viewer = 	"<object codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0\" style=\"width: " + width + "px; height: " + height + "px;\">\n" +
				"<param name=\"allowScriptAccess\" value=\"always\" />\n" +
				"<param name=\"allowFullScreen\" value=\"true\" />\n" +
				"<param name=\"movie\" value=\"./files/" + id + "/player\" />\n" +
				"<param name=\"quality\" value=\"high\" />\n" +
				"<param name=\"bgcolor\" value=\"#000000\" />\n" +
				"<param name=\"flashvars\" value=\"file=" + id + "\" />\n" +
				"<embed src=\"./files/" + id + "/player\" flashvars=\"file=" + id + "\" quality=\"high\" width=\"" + width + "\" height=\"" + height + "\" bgcolor=\"#000000\" allowScriptAccess=\"always\" allowFullScreen=\"true\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />\n" +
				"</object>";
		html = "&lt;object style=&quot;width: " + width + "px; height: " + height + "px;&quot;&gt;&lt;param name=&quot;allowScriptAccess&quot; value=&quot;always&quot; /&gt;&lt;param name=&quot;allowFullScreen&quot; value=&quot;true&quot; /&gt;&lt;param name=&quot;movie&quot; value=&quot;http://" + provider + ".de/files/" + id + "/player&quot; /&gt;&lt;param name=&quot;quality&quot; value=&quot;high&quot; /&gt;&lt;param name=&quot;bgcolor&quot; value=&quot;#000000&quot; /&gt;&lt;param name=&quot;flashvars&quot; value=&quot;file=" + id + "&quot; /&gt;&lt;embed src=&quot;http://" + provider + ".de/files/" + id + "/player&quot; flashvars=&quot;file=" + id + "&quot; quality=&quot;high&quot; width=&quot;" + width + "&quot; height=&quot;" + height + "&quot; bgcolor=&quot;#000000&quot; allowScriptAccess=&quot;always&quot; allowFullScreen=&quot;true&quot; type=&quot;application/x-shockwave-flash&quot; pluginspage=&quot;http://www.macromedia.com/go/getflashplayer&quot; /&gt;&lt;/object&gt;";
		}
	else if (filetype == "text") {
		showtype = "png";
		viewer = "<img src=\"./files/" + id + "/" + showname + "." + showtype + "\" alt=\"" + language['loading'] + "\" style=\"width: " + width + "px; height: " + height + "px;\" />";
		html = "&lt;a href=&quot;http://" + provider + ".de/files/" + id + "/&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://" + provider + ".de/files/" + id + "/" + showname + "." + showtype + "&quot; alt=&quot;" + provider + ".de - files over board&quot; style=&quot;width: " + width + "px; height: " + height + "px;&quot; /&gt;&lt;/a&gt;";
		}
	else if (filetype == "application") {
		showtype = "png";
		viewer = "<img src=\"./files/" + id + "/" + showname + "." + showtype + "\" alt=\"" + language['loading'] + "\" style=\"width: " + width + "px; height: " + height + "px;\" />";
		html = "&lt;a href=&quot;http://" + provider + ".de/files/" + id + "/&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://" + provider + ".de/files/" + id + "/" + showname + "." + showtype + "&quot; alt=&quot;" + provider + ".de - files over board&quot; style=&quot;width: " + width + "px; height: " + height + "px;&quot; /&gt;&lt;/a&gt;";
		}
	newMain += 	"<div class=\"label_file\" style=\"background-image: url(./images/icons/types/" + filetype + ".png);\"><div style=\"float: left;\">" + name + "</div><div style=\"float: right;\">" + imageCheckBox + "</div></div>\n" +
			"<div class=\"viewfile\">" + viewer + "<br />\n" +
			"<div class=\"space\"><div style=\"float: left;\"><strong>" + language['url'] + ":</strong></div><div style=\"float: right;\"><input type=\"text\" class=\"url\" value=\"http://" + provider + ".de/files/" + id + "/\" readonly=\"readonly\" onfocus=\"this.select();\" onclick=\"this.select();\" onmouseup=\"this.select();\" /></div></div>\n" +
			"<div class=\"space\"><div style=\"float: left;\"><strong>" + language['direct_url'] + ":</strong></div><div style=\"float: right;\"><input type=\"text\" class=\"direct_url\" value=\"http://" + provider + ".de/files/" + id + "/" + showname + "." + type + "\" readonly=\"readonly\" onfocus=\"this.select();\" onclick=\"this.select();\" onmouseup=\"this.select();\" /></div></div>\n" +
			"<div class=\"space\"><div style=\"float: left;\"><strong>" + language['delete'] + ":</strong></div><div style=\"float: right;\"><input type=\"text\" class=\"delete_url\" value=\"http://" + provider + ".de/delete/" + deleteKey + "/" + id + "\" readonly=\"readonly\" onfocus=\"this.select();\" onclick=\"this.select();\" onmouseup=\"this.select();\" /></div></div>\n" +
			"<div class=\"space\"><div style=\"float: left;\"><strong>" + language['bbcode'] + ":</strong></div><div style=\"float: right;\"><input type=\"text\" class=\"upload_bbcode\" value=\"[url=http://" + provider + ".de/files/" + id + "/][img]http://" + provider + ".de/files/" + id + "/" + showname + "." + showtype + "[/img][/url]\" readonly=\"readonly\" onfocus=\"this.select();\" onclick=\"this.select();\" onmouseup=\"this.select();\" /></div></div>\n" +
			"<div class=\"space\"><div style=\"float: left;\"><strong>" + language['htmlcode'] + ":</strong></div><div style=\"float: right;\"><input type=\"text\" class=\"upload_htmlcode\" value=\"" + html + "\" readonly=\"readonly\" onfocus=\"this.select();\" onclick=\"this.select();\" onmouseup=\"this.select();\" /></div></div>\n" +
			"</div><br />\n";
	setStatus(current, "finished");
	nextUpload();
	}
function addSlideshow(id) {
	getElement("slideshow").value += "/" + id;
	inputs = window.document.getElementsByTagName("input");
	count = 0;
	for (i = 0; i < inputs.length; i ++) {
		if (inputs[i].type == "checkbox" && inputs[i].checked == true) {
			count ++;
			}
		}
	if (count >= imagesCount) {
		getElement("select_all").checked = true;
		}
	}
function removeSlideshow(id) {
	getElement("slideshow").value = getElement("slideshow").value.split("/" + id).join("");
	getElement("select_all").checked = false;
	}
function selectAll(elm) {
	first = 1;
	inputs = window.document.getElementsByTagName("input");
	for (i = 0; i < inputs.length; i ++) {
		if (inputs[i].type == "checkbox" && first == 0) {
			if (elm.checked == false) {
				inputs[i].checked = false;
				}
			else {
				inputs[i].checked = true;
				}
			}
		if (first == 1) {
			first = 0;
			}
		}
	if (elm.checked == true) {
		for (i = 0; i < imagesArray.length; i ++) {
			removeSlideshow(imagesArray[i]);
			setTimeout("addSlideshow('" + imagesArray[i] + "')", 100);
			}
		}
	else {
		for (i = 0; i < imagesArray.length; i ++) {
			removeSlideshow(imagesArray[i]);
			}
		}
	}
function setStatus(id, status) {
	if (status == "loading") {
		getElement("status", id).innerHTML = "<img src=\"./images/loading.gif\" alt=\"\" title=\"" + language['loading'] + "\" style=\"float: left; width: 16px; height: 16px; margin-bottom: -3px; margin-right: 4px; margin-top: 4px;\" />";
		}
	else if (status == "finished") {
		getElement("status", id).innerHTML = "<img src=\"./images/icons/tick.png\" alt=\"\" title=\"" + language['finished'] + "\" style=\"float: left; width: 16px; height: 16px; margin-bottom: -3px; margin-right: 4px; margin-top: 4px;\" />";
		}
	else if (status == "error") {
		getElement("status", id).innerHTML = "<img src=\"./images/icons/cross.png\" alt=\"\" title=\"" + language['error'] + "\" style=\"float: left; width: 16px; height: 16px; margin-bottom: -3px; margin-right: 4px; margin-top: 4px;\" />";
		}
	}
function deleteUpload(id) {
	deleted[id] = true;
	getElement("file_input", id).innerHTML = "";
	getElement("file", id).style.display = "none";
	}
function showJavaScriptPage() {
	var swf_version = GetSwfVer().toString().split("WIN ").join("").split(",").join(".").split(".")[0] * 1;
	if (swf_version >= 9) {
		uploader = "flash";
		}
	else {
		uploader = "html";
		}
	swf_version = 1;
	getElement("upload_wrapper").style.display = "block";
	getElement("nojavascript").style.display = "none";
	if (uploader == "html") {
		getElement("webcam").style.display = "none";
		getElement("webcam_button").style.display = "none";
		getElement("spacer").style.display = "none";
		getElement("upload").style.left = "288px";
		getElement("upload_button").style.left = "288px";
		}
	else {
		getElement("flashupload").innerHTML =	"<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" id=\"flash_upload\" width=\"74\" height=\"30\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab\">\n" +
												"<param name=\"movie\" value=\"./upload.swf?sessionid=" + getElement("sessionid").value + "\" />\n" +
												"<param name=\"quality\" value=\"high\" />\n" +
												"<param name=\"bgcolor\" value=\"#dddddd\" />\n" +
												"<param name=\"allowScriptAccess\" value=\"sameDomain\" />\n" +
												"<param name=\"flashvars\" value=\"sessionid=" + getElement("sessionid").value + "\" />\n" +
												"<embed src=\"./upload.swf?sessionid=" + getElement("sessionid").value + "\" flashvars=\"sessionid=" + getElement("sessionid").value + "\" quality=\"high\" bgcolor=\"#dddddd\" width=\"74\" height=\"30\" name=\"flash_upload\" align=\"middle\" play=\"true\" loop=\"false\" quality=\"high\" allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\"></embed>\n" +
												"</object>";
		getElement("flashupload").style.display = "block";
		}
	}
function bodyOnMouseUp() {
	if (clicked != 0) {
		clicked.style.backgroundPosition = clickPosition;
		}
	clicked = 0;
	id = uploads.length;
	if (webcamOpened == 1) {
		if (getElement("menu", id).style.display == "block" && ignoreOpen == 0) {
			getElement("menu", id).style.display = "none";
			ignoreOpen = 1;
			}
		else if (getElement("menu", id).style.display == "none" && ignoreOpen == 1) {
			ignoreOpen = 0;
			}
		}
	}
function uploadLanguage() {
	return new Array(language['all_files'], language['images'], language['videos'], language['audio'], language['texts'], language['applications']);
	}
function openWebcam(event) {
	if (webcamOpened == 1) {
		return true;
		}
	webcamOpened = 1;
	if (!event) {
		event = window.event;
		}
	x = event.pageX ? event.pageX : event.clientX + window.document.body.scrollLeft;
	y = event.pageY ? event.pageY : event.clientY + window.document.body.scrollTop;
	if (!x) {
		x = 100;
		y = 100;
		}
	id = uploads.length;
	webcamBox = window.document.createElement("div");
	webcamBox.id = "webcam" + id;
	webcamBox.className = "webcam";
	webcamBox.style.top = y + "px";
	webcamBox.style.left = x + "px";
	webcamBox.innerHTML = 	"<div style=\"width: 320px; height: 240px;\" id=\"webcam_flash" + id + "\">\n" +
				"<object codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0\" style=\"width: 320px; height: 240px;\">\n" +
				"<param name=\"allowScriptAccess\" value=\"always\" />\n" +
				"<param name=\"allowFullScreen\" value=\"true\" />\n" +
				"<param name=\"movie\" value=\"./webcam.swf\" />\n" +
				"<param name=\"quality\" value=\"high\" />\n" +
				"<param name=\"bgcolor\" value=\"#f6f6f6\" />\n" +
				"<param name=\"flashvars\" value=\"\" />\n" +
				"<embed src=\"./webcam.swf\" flashvars=\"\" quality=\"high\" width=\"320\" height=\"240\" bgcolor=\"#f6f6f6\" allowScriptAccess=\"always\" allowFullScreen=\"true\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" name=\"webcam" + id + "\" id=\"webcam" + id + "\" />\n" +
				"</object>\n" +
				"</div>\n" +
				"<div style=\"width: 320px; height: 22px; background-image: url(./images/webcam_background.png);\">\n" +
				"<div style=\"float: left; width: 22px; height: 22px; background-image: url(./images/icons/webcam.png); background-repeat: no-repeat; background-position: 3px 3px; cursor: pointer;\" onclick=\"webcamCapture();\" onmousedown=\"getElement('focus').focus(); clicked = this; this.style.backgroundPosition = '4px -19px';\" onmouseover=\"clickPosition = this.style.backgroundPosition; this.style.backgroundPosition = '3px -20px';\" onmouseout=\"if (clicked == 0) this.style.backgroundPosition = '3px 3px';\"></div>\n" +
				"<div id=\"webcam_name" + id + "\" style=\"float: left; margin-left: 3px; padding: 2px; width: 269px; text-align: center;\"></div>\n" +
				"<div title=\"" + language['close'] + "\" style=\"float: left; width: 22px; height: 22px; background-image: url(./images/icons/close.png); background-repeat: no-repeat; background-position: 3px 3px; cursor: pointer;\" onclick=\"closeWebcam();\" onmousedown=\"getElement('focus').focus(); clicked = this; this.style.backgroundPosition = '4px -19px';\" onmouseover=\"clickPosition = this.style.backgroundPosition; this.style.backgroundPosition = '3px -20px';\" onmouseout=\"if (clicked == 0) this.style.backgroundPosition = '3px 3px';\"></div>\n" +
				"</div>";
	window.document.body.appendChild(webcamBox);
	}
function closeWebcam() {
	webcamOpened = 0;
	window.document.body.removeChild(getElement("webcam", id));
	}
function webcam(cameras, current) {
	id = uploads.length;
	if (cameras == false) {
		getElement("webcam_flash", id).innerHTML = "<div style=\"padding: 40px 5px 0px 5px; text-align: center; font-size: 30px;\"><span style=\"color: #ff0000;\">" + language['error'] + "</span><br />" + language['error_no_webcam'] + "</div>";
		}
	else {
		foundWebcam = 1;
		if (cameras.length == 1) {
			getElement("webcam_name", id).innerHTML = current;
			}
		else {
			select = "<div class=\"select\">\n" +
				 "<div class=\"button\" id=\"select" + id + "\" onclick=\"if (ignoreOpen == 0) { getElement('menu', " + id + ").style.display = 'block'; ignoreOpen = 0; }\">" + current + "</div><img src=\"./images/select.png\" alt=\"\" onclick=\"if (ignoreOpen == 0) { getElement('menu', " + id + ").style.display = 'block'; ignoreOpen = 0; }\" style=\"margin-left: -1px; margin-bottom: -3px; float: left;\" />\n" +
				 "<div id=\"menu" + id + "\" class=\"menu\">\n";
			for (i = 0; i < cameras.length; i ++) {
				select += "<div onmousedown=\"getElement('select', " + id + ").innerHTML = this.innerHTML; switchWebcam('" + i + "');\">" + cameras[i] + "</div>\n";
				}
			select += "</div>";
			select += "</div>";
			getElement("webcam_name", id).innerHTML = select;
			}
		}
	}
function switchWebcam(select) {
	getMovie("webcam" + uploads.length).switchWebcam(select);
	}
function webcamCapture() {
	if (foundWebcam == 0) {
		return true;
		}
	id = uploads.length;
	webcamOpened = 0;
	getMovie("webcam" + id).capture();
	getElement("webcam", id).style.top = "-500px";
	browse("Webcam.jpg", "webcam");
	}
function decrypt(s) {
	var n = 0;
	var r = "";
	for (var i = 0; i < s.length; i++) {
		n = s.charCodeAt(i);
		if(n >= 8364) {
			n = 128;
			}
		r += String.fromCharCode(n - 1);
		}
	return r;
	}
function showImprintLinks() {
	getElement("maximilian").innerHTML = decrypt("nbyjnjmjboAnbyjwc/ef");
	getElement("tobias").innerHTML = decrypt("nftdiAp3pomjof/ef");
	if (getElement("heinz")) {
		getElement("heinz").innerHTML = decrypt("eswcvfmpxAu.pomjof/ef");
		}
	else {
		getElement("tobias2").innerHTML = decrypt("nftdiAp3pomjof/ef");
		}
	}
function contactMaximilian() {
	location.href = decrypt("nbjmup;nbyjnjmjboAnbyjwc/ef");
	}
function contactHeinz() {
	location.href = decrypt("nbjmup;eswcvfmpxAu.pomjof/ef");
	}
function contactTobias() {
	location.href = decrypt("nbjmup;nftdiAp3pomjof/ef");
	}
function hideFileOperations() {
	var files = window.document.getElementsByTagName("div");
	for (i = 0; i < files.length; i ++) {
		if (files[i].className == "") {
			files[i].style.display = "none";
			}
		}
	}
function editName(id) {
	getElement("input", id).value = getElement("icon", id).title;
	getElement("input", id).style.display = "block";
	getElement("input", id).focus();
	getElement("name", id).innerHTML = "";
	getElement("icon", id).style.backgroundColor = "#f6f6f6";
	getElement("icon", id).style.border = "1px #dddddd solid";
	}
function xmlHttpSend(url, reqVars) {
	var xmlHttp = false;
	try {
		xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
	catch(e) {
		try {
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
		catch(e) {
			xmlHttp = false;
			}
		}
	if (!xmlHttp && typeof XMLHttpRequest != "undefined") {
		xmlHttp = new XMLHttpRequest();
		}
	xmlHttp.open("POST", url);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlHttp.send(reqVars);
	}
function changeName(elm, id, type) {
	name = elm.value;
	if (elm.value.length > 18) {
		elm.value = elm.value.substr(0, 15) + "...";
		}
	getElement("input", id).style.display = "none";
	getElement("name", id).innerHTML = elm.value;
	getElement("name", id).title = name;
	getElement("icon", id).style.backgroundColor = "";
	getElement("icon", id).style.border = "";
	xmlHttpSend("/changename/" + type + "/" + id, "name=" + name);
	}
function moveToFolder(id, type) {
	getElement("information").style.display = "block";
	fileId = id;
	tds = window.document.getElementsByTagName("td");
	for (i = 0; i < tds.length; i ++) {
		if (tds[i].innerHTML != "") {
			if (tds[i].className != "folder") {
				tds[i].getElementsByTagName("div")[0].style.display = "none";
				}
			else {
				fid = tds[i].getElementsByTagName("div")[0].id.substr(4);
				if (fid == id) {
					tds[i].getElementsByTagName("div")[0].style.display = "none";
					}
				else {
					tds[i].getElementsByTagName("a")[3].href = "javascript:toFolder(" + fid + ", '" + type + "');";
					}
				}
			}
		}
	}
function toFolder(id, type) {
	getElement("information").style.display = "none";
	icons = new Array();
	tds = window.document.getElementsByTagName("td");
	for (var i = 0; i < tds.length; i ++) {
		if (tds[i].innerHTML != "") {
			iconId = tds[i].getElementsByTagName("div")[0].id.substr(4);
			if (fileId != iconId) {
				icons[icons.length] = new Array(tds[i].className, tds[i].innerHTML);
				}
			}
		}
	for (var i = 0; i < tds.length; i ++) {
		if (icons[i]) {
			tds[i].className = icons[i][0];
			tds[i].innerHTML = icons[i][1];
			iconId = tds[i].getElementsByTagName("div")[0].id.substr(4);
			tds[i].getElementsByTagName("div")[0].style.display = "block";
			if (tds[i].className == "folder") {
				tds[i].getElementsByTagName("a")[3].href = "http://" + provider + ".de/folder/" + iconId;
				}
			}
		else {
			tds[i].className = "";
			tds[i].innerHTML = "";
			}
		}
	xmlHttpSend("/file_folder/" + type + "/" + fileId + "/" + id, null);
	}
function newFolder(current) {
	trs = window.document.getElementsByTagName("tr");
	lastTr = trs[(trs.length - 1)];
	tds = lastTr.getElementsByTagName("td");
	if (tds.length == 6) {
		getElement("files").innerHTML += "<tr></tr>";
		trs = window.document.getElementsByTagName("tr");
		lastTr = trs[(trs.length - 1)];
		}
	var xmlHttp = false;
	try {
		xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
	catch(e) {
		try {
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
		catch(e) {
			xmlHttp = false;
			}
		}
	if (!xmlHttp && typeof XMLHttpRequest != "undefined") {
		xmlHttp = new XMLHttpRequest();
		}
	xmlHttp.open("GET", "/new_folder/" + current);
	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
			lastTr.innerHTML += "<td class=\"folder\">\n" +
						"<div class=\"icon\" title=\"" + language['new_folder'] + "\" id=\"icon" + xmlHttp.responseText + "\" onmouseover=\"this.getElementsByTagName('div')[0].style.display = 'block'; this.getElementsByTagName('div')[2].style.display = 'block'; this.getElementsByTagName('div')[4].style.display = 'block';\" onmouseout=\"this.getElementsByTagName('div')[0].style.display = 'none'; this.getElementsByTagName('div')[2].style.display = 'none'; this.getElementsByTagName('div')[4].style.display = 'none';\">\n" +
						"<div style=\"right: 37px;\">\n" +
						"<a href=\"javascript:;\" onclick=\"editName('" + xmlHttp.responseText + "');\"><div class=\"operation\" style=\"background-image: url(http://" + provider + ".de/images/icons/edit_hover.png);\" title=\"" + language['edit'] + "\"></div></a>\n" +
						"</div>\n" +
						"<div style=\"right: 19px;\">\n" +
						"<a href=\"http://" + provider + ".de/deletefolder/" + xmlHttp.responseText + "\"><div class=\"operation\" style=\"background-image: url(http://" + provider + ".de/images/icons/close.png);\" title=\"" + language['delete'] + "\"></div></a>\n" +
						"</div>\n" +
						"<div style=\"left: 2px;\">\n" +
						"<a href=\"javascript:;\" onclick=\"moveToFolder('" + xmlHttp.responseText + "', 'folder');\"><div class=\"operation\" style=\"background-image: url(http://" + provider + ".de/images/icons/folder_hover.png);\" title=\"" + language['move_to_folder'] + "\"></div></a>\n" +
						"</div>\n" +
						"<input type=\"text\" onblur=\"changeName(this, '" + xmlHttp.responseText + "', 'folder');\" id=\"input" + xmlHttp.responseText + "\" />\n" +
						"<a href=\"http://" + provider + ".de/folder/" + xmlHttp.responseText + "\" class=\"icon\">\n" +
						"<img src=\"http://" + provider + ".de/images/big_icons/folder.png\" alt=\"\" /><br />\n" +
						"<span id=\"name" + xmlHttp.responseText + "\">" + language['new_folder'] + "</span>\n" +
						"</a>\n" +
						"</div>\n" +
						"</td>";
			hideFileOperations();
			}
		};
	xmlHttp.send(null);
	}
function openUrl(event) {
	if (urlOpened == 1) {
		return true;
		}
	urlOpened = 1;
	if (!event) {
		event = window.event;
		}
	x = event.pageX ? event.pageX : event.clientX + window.document.body.scrollLeft;
	y = event.pageY ? event.pageY : event.clientY + window.document.body.scrollTop;
	if (!x) {
		x = 100;
		y = 100;
		}
	getElement("url_window").style.display = "block";
	getElement("url_window").style.top = y + "px";
	getElement("url_window").style.left = x + "px";
	}
function checkUrl(elm) {
	url = elm.value
	newValue = "";
	urls = url.split("\n");
	if (urls[(urls.length - 1)] != "") {
		return true;
		}
	checkCurrentUrl(0, urls.length, urls);
	elm.value = "";
	}
function checkCurrentUrl(id, max, urls) {
	var xmlHttp = false;
	try {
		xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
	catch(e) {
		try {
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
		catch(e) {
			xmlHttp = false;
			}
		}
	if (!xmlHttp && typeof XMLHttpRequest != "undefined") {
		xmlHttp = new XMLHttpRequest();
		}
	xmlHttp.open("POST", "/check_url");
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
			if (xmlHttp.responseText == "true") {
				browse(urls[id], 'url');
				if (id + 1 < max) {
					checkCurrentUrl(id + 1, max, urls);
					}
				}
			}
		};
	xmlHttp.send("url=" + urls[id]);
	}
function closeUrl() {
	id = uploads.length;
	getElement("url_window").style.display = "none";
	urlOpened = 0;
	}
function initReady(fn) {
	if (window.document.addEventListener) {
		window.document.addEventListener("DOMContentLoaded", fn, false);
		}
	else {
		window.document.onreadystatechange = function(){
			readyState(fn);
			}
		}
	}
function readyState(func) {
      	if (window.document.readyState == "interactive" || window.document.readyState == "complete") {
      		func();
      		}
	}
function onReady() {
	if (location.href.split("/")[3] == "" || location.href.split("/").length == 3) {
		showJavaScriptPage();
		}
	else if (location.href.split("/")[3] == "imprint") {
		showImprintLinks();
		}
	else if ((location.href.split("/")[3] == "files" || location.href.split("/")[3] == "folder") && (!location.href.split("/")[4] || location.href.split("/")[4] == "")) {
		hideFileOperations();
		}
	}
function getKeys(elm) {
	keys = elm.value.split("\n");
	for (i = 0; i < keys.length; i ++) {
		if (keys[i].split("/")[4] && keys[i].split("/")[4] != "") {
			url[url.length] = keys[i].split("/")[4];
			}
		}
	if (url.length > 0) {
		getElement("url").style.display = "block";
		getElement("url").value = "http://m9x.de/slideshow/" + url.join("/");
		}
	elm.value = "";
	}
