
	function dem_downloads_setcurrentdir(dir)
	{
		parent.document.getElementById("dem_downloads_currentdir").innerHTML=dir;
	}
	
	function dem_downloads_selectdownload(dlid, mime, name)
	{
		if (dlid==-1)
		{
			parent.document.getElementById("dem_downloads_step1").style.display="block";
			parent.document.getElementById("dem_downloads_step2").style.display="none";		
			parent.document.getElementById("dem_downloads_step3_image").style.display="none";
			parent.document.getElementById("dem_downloads_step3_link").style.display="none";
		} else {
			parent.document.getElementById("dem_downloads_step2").style.display="block";
			if (mime.indexOf("image/")>=0)
			{
				parent.document.getElementById("dem_downloads_step3_image").style.display="block";
				parent.document.forms.dem_downloads_imgparams.elements.dlid.value=dlid;
				parent.document.getElementById("dem_downloads_image").src="../../logic/dl/?size=2&dlid="+dlid;
				parent.document.forms.dem_downloads_imgparams.elements.dlname.value=name;
				parent.document.getElementById("dem_downloads_step1").style.display="none";			
			} else {			
				parent.document.getElementById("pagetext").setActive();
				parent.document.execCommand('createLink',false,"../../logic/dl/?dlid="+dlid);
			}
		}
	}
	
	function dem_downloads_add_download()
	{
		
	}
	
	function dem_downloads_add_image()
	{
		var style="border:0px;";
		var imgpre="";
		var imgpost="";
		var imgtarget="";
		var imgsize="";
		if (document.forms.dem_downloads_imgparams.elements.imgalign.value=="left") style+="margin-right:5px;margin-bottom:5px;";
		if (document.forms.dem_downloads_imgparams.elements.imgalign.value=="right") style+="margin-left:5px;margin-bottom:5px;";
		
		if (document.forms.dem_downloads_imgparams.elements.imgtarget.checked) 
		{
			imgtarget="target=\"_blank\" ";
		} else {
			imgtarget=" ";
		}

		if (document.forms.dem_downloads_imgparams.elements.imglink.value=="1") 
		{
			imgpre="";
			imgpost="";
		}

		if (document.forms.dem_downloads_imgparams.elements.imglink.value=="2") 
		{
			imgpre="<a "+imgtarget+"href=\"../../logic/dl/?dlid="+document.forms.dem_downloads_imgparams.elements.dlid.value+"\">";
			imgpost="</a>";
		}

		if (document.forms.dem_downloads_imgparams.elements.imglink.value=="3") 
		{
			document.execCommand('createlink',false,"../../logic/dl/?dlid="+document.forms.dem_downloads_imgparams.elements.dlid.value);
		} else {
			if (document.forms.dem_downloads_imgparams.elements.imgsize.value=="1") imgsize="1";
			if (document.forms.dem_downloads_imgparams.elements.imgsize.value=="2") imgsize="2";
			if (document.forms.dem_downloads_imgparams.elements.imgsize.value=="0") imgsize="0";
				
			inserthtml(document.getElementById("pagetext"), imgpre+"<img src=\"../../logic/dl/?dlid="+
									document.forms.dem_downloads_imgparams.elements.dlid.value+"&amp;size="+imgsize+"\" "+
									"align=\""+document.forms.dem_downloads_imgparams.elements.imgalign.value+"\" "+
									"alt=\""+document.forms.dem_downloads_imgparams.elements.dlname.value+"\" "+
									"style=\""+style+"\" />"+imgpost);
		}
		dem_downloads_selectdownload(-1, -1, -1);
	}

	function dem_galleries_insert()
	{
		id=document.forms.dem_galleries.elements.dem_galleries_folders.value;
		inserthtml(parent.document.getElementById("pagetext"), 
			"<iframe style=\"BORDER:0px;WIDTH:650px;HEIGHT:540px;margin:0px;\" marginWidth=\"0\" marginHeight=\"0\" src=\"../../logic/gallery/?id="+id+"\" frameBorder=\"0\" scrolling=\"no\" spacing=\"0\"></IFRAME>");
	}
	var dem_ptvarchive_xmlsearchurl="../../modules/dem_ptvarchive/ajax.php";
	var dem_ptvarchive_lastcommand="";
	var dem_ptvarchive_lastparam="";

  ///////////////////////////////////////
	// AJAX command sender
	function dem_ptvarchive_xmlhttpPost(xmlurl, command, params) 
	{
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) 
		{
			self.xmlHttpReq = new XMLHttpRequest();
		} else if (window.ActiveXObject) {
			// IE
			self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
		}
		self.xmlHttpReq.open('POST', xmlurl, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/octet-stream');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            dem_ptvarchive_updatepage(xmlurl, self.xmlHttpReq.responseText, self.xmlHttpReq.responseXML);
        }
    }
    self.xmlHttpReq.send("<"+"?"+"xml version=\"1.0\" encoding=\"UTF-8\" "+"?"+">"+"<Q><FUNCTION>"+command+"<\/FUNCTION>"+params+"<\/Q>");
	}

  ///////////////////////////////////////
	// AJAX response wrapper
	function dem_ptvarchive_updatepage(xmlurl, response, responseXML)
	{
		res=responseXML.getElementsByTagName('RESULTS').item(0);
		document.getElementById("dem_ptvarchive_results").innerText=response;
		switch (res.getElementsByTagName('FUNCTION').item(0).getAttribute("text"))
		{
			case "search":
					showxmltoresults(responseXML);
					break;
		}
	}

	
	function dem_ptvarchive_getvideo(id)
	{
		inserthtml(parent.document.getElementById("pagetext"), "<CENTER><IFRAME style=\"BORDER:0px;WIDTH:384px;HEIGHT:340px;margin:0px;\" marginWidth=\"0\" marginHeight=\"0\" src=\"http://www.pecstv.hu/archivum/embed/?id="+id+"\" frameBorder=\"0\" scrolling=\"no\" spacing=\"0\"></IFRAME></CENTER>");
	}
	
	function dem_ptvarchive_dosearch()
	{
		dem_ptvarchive_lastcommand="search";
		dem_ptvarchive_lastparam="<QUERY>"+encodeURI(document.forms.dem_ptvarchive_videosearch.elements.dem_ptvarchive_query.value)+"<\/QUERY>"+
				"<FROMDATE><\/FROMDATE>"+
				"<TODATE><\/TODATE>";
		dem_ptvarchive_xmlhttpPost(dem_ptvarchive_xmlsearchurl,dem_ptvarchive_lastcommand, dem_ptvarchive_lastparam);
		document.getElementById("dem_ptvarchive_results").innerHTML="<div class=\"info\">Keresés...<\/div>";
	}


  ///////////////////////////////////////
	// XML parser for results
	function showxmltoresults(xml)
	{
		var s="";
		res=xml.getElementsByTagName('RESULTS').item(0);
		if (res.getElementsByTagName('ERRORMESSAGE').item(0).getAttribute("text")=="")
		{
			var pages=res.getElementsByTagName('PAGES').item(0).getAttribute("count");
			var currentpage=res.getElementsByTagName('PAGES').item(0).getAttribute("currentpage");

			document.getElementById("dem_ptvarchive_pages").innerHTML=showpagebuttons(currentpage, pages);

			res=res.getElementsByTagName('VIDEO');
			if (res.length==0)
			{
				s="<div class=\"error\">Sajnos nincs találat<\/div>";
			} else {
				for (i=0;i<res.length;i++)
				{
					var r=res.item(i);
					var cim=r.getAttribute("cim");
					var hirid=r.getAttribute("hirid");
					var creation=r.getAttribute("creation");
					var editor=r.getAttribute("ownername");
					var catname=r.getAttribute("besorolasname");
					var hossz=r.getAttribute("hossz");
					var downloadcount=r.getAttribute("downloadcount");
					var filesize=r.getAttribute("filesize");
			
					s+="<div style=\"background-color:#f0f0f0;padding-top:3px;padding-bottom:3px;margin-top:0px;margin-bottom:0px;font-size:10px;border-top:1px solid #fff;border-bottom:1px solid #d0d0d0;\">"+creation+" - "+catname+"<br />";
					s+="<a href=\"javascript:dem_ptvarchive_getvideo("+hirid+");\">"+cim+"<\/a><\/div>\n";
				}
			}	
		} else {
			s="<div class=\"error\">"+res.getElementsByTagName('ERRORMESSAGE').item(0).getAttribute("text")+"<\/div>";
		}
		document.getElementById("dem_ptvarchive_results").innerHTML=s;
	}


  ///////////////////////////////////////
	// DRAWING PAGE BUTTONS
	function showpagebuttons(currentpage, pages)
	{
		var s=""
		s+="<div class=\"pagebuttons\">";
		if (pages>1)
		{
			s+="<table cellspacing=\"0\" cellpadding=\"0\"><tr><td style=\"text-align:center;\">";
			if (currentpage>0)
			{
				s+="<a href=\"javascript:dem_ptvarchive_loadpage("+(currentpage-1)+");\"><img src=\"../../templates/pecskep/img/buttons/button_left_o.gif\" style=\"width:9px;height:9px;border: 0px;\" alt=\"\" /><\/a>";
			} else {
				s+="&nbsp;";
			}
			s+="<\/td><td class=\"pagebuttons\">"+(1+Math.floor(currentpage))+"<\/td><td class=\"pagebuttons\">";
			if (currentpage<(pages-1))
			{
				s+="<a href=\"javascript:dem_ptvarchive_loadpage("+(1+Math.floor(currentpage))+");\"><img src=\"../../templates/pecskep/img/buttons/button_right_o.gif\" style=\"width:9px;height:9px;border: 0px;\" alt=\"\" /><\/a>";
			} else {
				s+="&nbsp;";
			}		
			s+="<\/td><\/tr><\/table>";
		}
		s+="<\/div>\n";
		return s;		
	}

	function dem_ptvarchive_loadpage(page)
	{
		document.getElementById("dem_ptvarchive_results").innerHTML="<div class=\"info\">Letöltés...<\/div>";
		dem_ptvarchive_xmlhttpPost(dem_ptvarchive_xmlsearchurl,dem_ptvarchive_lastcommand,dem_ptvarchive_lastparam+"<PAGE>"+page+"<\/PAGE>");
	}

