/**
 * Set new url in IiFrame at showDownload page
 **/
var iFrameLoader;
function setFramesrc(to) {
    //$('disableIframe').fade(0.4);
    $('LoadingMessage').set('text',to);
    $('LoadingBox').fade('in');
    $('downloadsiframe').setProperty('src',to);
    //iFrameLoader = window.setTimeout("stopIFrameLoading()", 10000);
}
function downloadFile(type, ignore_adbl, title)
{
	if (adbl && ignore_adbl == null)
		alert(download_message);
	else if (title != null)
		window.open("http://"+domain+"/download-file.php?type=" + type + "&n=" + title);
	else
		window.open("http://"+domain+"/download-file.php?type=" + type);
}

function bookmark(url)
{
	window.open(url);
}

function markTextarea(id)
{
	var textarea = document.getElementById(id);
	textarea.focus();
	textarea.select();
}

function handleMoreLinks()
{
	switch (req.readyState)
	{
		case 4:
			if (req.status != 200)
				alert("Error: " + req.status);
			else {
				var xml = req.responseXML;
				var error = xml.getElementsByTagName("error")[0];
				error = error.firstChild.nodeValue;
				if (error != "none") {
					alert(error);
					break;
				}
				
				var row = xml.getElementsByTagName("row");
				var more_links = document.getElementById("more_links");
				var fragment = document.createDocumentFragment();
				for (var i = 0; row[i] != null; i++)
				{
					var col = row[i].childNodes;
					var table_element = document.createElement("tr");
					table_element.setAttribute("class", "small");
					for (var u = 0; col[u] != null; u++)
					{
						var content = col[u].childNodes;
						for (var x = 0; content[x] != null; x++)
						{
							var column = document.createElement("td");
							column.innerHTML = content[x].nodeValue;
							table_element.appendChild(column);
						}
					}
					fragment.appendChild(table_element);
				}
				more_links.parentNode.replaceChild(fragment, more_links);
			}
			break;
	}
}

function requestMoreLinks(category, name_short)
{	
	try {
		req = new XMLHttpRequest();
	}
	catch (e) {
		try {
			req = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				req = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (failed) {
				req = null;
			}
		}
	}
	if (req == null) {
		alert("Error creating Ajax request object.");
		return;
	}
	
	req.open("GET", "http://"+domain+"/more_links.php?n="+name_short, true);
	req.onreadystatechange = handleMoreLinks;
	req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	req.send(null);
}
