function forward(URL) {
	if (URL != '' && URL != '-----') {
		window.location.href = URL;
	}
}

function removeImage() {
	var div = document.getElementById('imageDiv');
	var n = div.childNodes.length;
	var i = 0;
	var child;
	while (i < n) {
		child = div.firstChild;
		div.removeChild(child);
		i++;
	}
	div.style.visibility = 'hidden';
	div.style.display = 'none';
	var divBg = document.getElementById('imageBg');
	divBg.style.visibility = 'hidden';
	divBg.style.display = 'none';
}

function zoomImage(img, w, h, p) {
	var f = 1;
	while (w * f < window.innerWidth && h * f < window.innerHeight) {
		f += 1;
	}
	f--;
	w *= f;
	h *= f;
	var divBg = document.getElementById('imageBg');
	divBg.style.width = '100%';
	divBg.style.height = '100%';
	divBg.style.visibility = 'visible';
	divBg.style.display = 'block';
	var div = document.getElementById('imageDiv');
	var n = div.childNodes.length;
	var i = 0;
	var child;
	while (i < n) {
		child = div.firstChild;
		div.removeChild(child);
		i++;
	}
	div.style.width = w + 'px';
	div.style.height = h + 'px';
	div.style.top = ((window.innerHeight - h) / 2) + 'px';
	div.style.left = ((window.innerWidth - w) / 2) + 'px';
	var shot = document.createElement('img');
	shot.setAttribute('style', 'position:absolute;top:0px;left:0px;z-index:998;');
	shot.setAttribute('src', img);
	shot.setAttribute('width', w);
	shot.setAttribute('height', h);
	shot.setAttribute('alt', '');
	shot.setAttribute('onclick', 'removeImage();');
	div.appendChild(shot);
	if (p != '') {
		var spacer = document.createElement('img');
		spacer.setAttribute('style', 'position:absolute;top:0px;left:0px;z-index:999;');
		spacer.setAttribute('src', p);
		spacer.setAttribute('width', w);
		spacer.setAttribute('height', h);
		spacer.setAttribute('alt', '');
		spacer.setAttribute('onclick', 'removeImage();');
		div.appendChild(spacer);
	}
	div.style.visibility = 'visible';
	div.style.display = 'block';
}

function addCode(code, target) {
	// the textarea
	var obj = document.getElementsByName(target)[0];
	if (obj) {
		if (obj.selectionStart !== false) {
			// Gecko / Opera
			var start = obj.selectionStart;
			var end	  = obj.selectionEnd;
			obj.value = obj.value.substr(0, start) +  '[' + code + ']' + obj.value.substring(start, end) + '[/' + code + ']' + obj.value.substr(end, obj.value.length);
			obj.focus();
			var pos = start + code.length + 2;
			obj.setSelectionRange(pos, pos);
		} else if (document.selection !== false) {
			// Internet Exploder (*choke*)
			obj.focus();
			var str = document.selection.createRange().text;
			document.selection.createRange().text = '[' + code + ']' + str + '[/' + code + ']';
		} else {
			// other browsers
			obj.value += '[' + code + '][/' + code + ']';
			obj.focus();
		}
	}
}

function newFiles(base, lang, id, mode) {
	if (mode == 'batch') {
		window.open(base + 'popup/batchupload.php?lang=' + lang + '&id=' + id, 'filewindow', 'width=600, height=450, scrollbars=yes');
	} else if (mode == 'apps') {
		window.open(base + 'popup/batchupload.php?lang=' + lang + '&id=' + id + '&mode=apps', 'filewindow', 'width=600, height=450, scrollbars=yes');
	}
}

function manageFiles(base, lang, id, mode) {
	window.open(base + 'popup/managefiles.php?lang=' + lang + '&id=' + id + '&mode=' + mode, 'filewindow', 'width=600, height=450, scrollbars=yes');
}

function classifyFiles(base, lang, id) {
	window.open(base + 'popup/classifyfiles.php?lang=' + lang + '&id=' + id, 'filewindow', 'width=600, height=450, scrollbars=yes');
}

function addDownload(dl, desc) {
	var obj = document.getElementById('formtable');
	var tr = document.createElement('tr');
	var td = document.createElement('td');
	td.appendChild(document.createTextNode(dl));
	tr.appendChild(td);
	td = document.createElement('td');
	td.setAttribute('colspan', '2');
	var input = document.createElement('input');
	input.setAttribute('type', 'text');
	input.setAttribute('name', 'download[]');
	td.appendChild(input);
	tr.appendChild(td);
	obj.appendChild(tr);
	tr = document.createElement('tr');
	td = document.createElement('td');
	td.appendChild(document.createTextNode(desc));
	tr.appendChild(td);
	td = document.createElement('td');
	td.setAttribute('colspan', '2');
	input = document.createElement('input');
	input.setAttribute('type', 'text');
	input.setAttribute('name', 'downloaddescription[]');
	td.appendChild(input);
	tr.appendChild(td);
	obj.appendChild(tr);
	tr = document.createElement('tr');
	td = document.createElement('td');
	td.setAttribute('colspan', '3');
	var hr = document.createElement('hr');
	td.appendChild(hr);
	tr.appendChild(td);
	obj.appendChild(tr);
}

function addDocument(doc, desc, list, translist, comment) {
	var obj = document.getElementById('formtable');
	var tr = document.createElement('tr');
	var td = document.createElement('td');
	td.appendChild(document.createTextNode(doc));
	tr.appendChild(td);
	td = document.createElement('td');
	td.setAttribute('colspan', '2');
	var input = document.createElement('input');
	input.setAttribute('type', 'text');
	input.setAttribute('name', 'document[]');
	td.appendChild(input);
	tr.appendChild(td);
	obj.appendChild(tr);
	tr = document.createElement('tr');
	td = document.createElement('td');
	td.appendChild(document.createTextNode(desc));
	tr.appendChild(td);
	td = document.createElement('td');
	td.setAttribute('colspan', '2');
	var select = document.createElement('select');
	select.setAttribute('name', 'documenttype[]');
	var options = list.split(';');
	var transoptions = translist.split(';');
	for (var i = 0; i < options.length - 1; i++) {
		var option = document.createElement('option');
		option.setAttribute('value', options[i]);
		option.appendChild(document.createTextNode(transoptions[i]));
		select.appendChild(option);
	}
	td.appendChild(select);
	tr.appendChild(td);
	obj.appendChild(tr);
	tr.appendChild(td);
	tr = document.createElement('tr');
	td = document.createElement('td');
	td.appendChild(document.createTextNode(comment));
	tr.appendChild(td);
	td = document.createElement('td');
	td.setAttribute('colspan', '2');
	input = document.createElement('input');
	input.setAttribute('type', 'text');
	input.setAttribute('name', 'documentcomment[]');
	td.appendChild(input);
	tr.appendChild(td);
	obj.appendChild(tr);
	tr = document.createElement('tr');
	td = document.createElement('td');
	td.setAttribute('colspan', '3');
	var hr = document.createElement('hr');
	td.appendChild(hr);
	tr.appendChild(td);
	obj.appendChild(tr);
}

function resetgamesform() {
	var el = document.getElementById('system');
	el.checked = true;
	el = document.getElementById('genre');
	el.checked = true;
	el = document.getElementById('year');
	el.checked = true;
	el = document.getElementById('letter');
	el.checked = true;
	el = document.getElementById('rating');
	el.checked = true;
	el = document.getElementById('reviewer');
	el.checked = true;
	el = document.getElementById('licence');
	el.checked = true;
	el = document.getElementById('company');
	el.value = '';
	el = document.getElementById('keyword');
	el.value = '';
}
