css="<style type='text/css'>";
css+="div.fileedit {font-size:12px;display:block;clear:both;padding:0;background-color:#fff;}";
css+="div.fileedit img {display:block;float:left;margin-right: 5px;cursor:pointer;cursor:hand;}";
css+="div.fileName {color: #000;font-weight:bold;}";
css+="div.fileSize {color: #999;}";
css+="div.fileDate {color: #999;}";
css+="#subdialog IMG	{	margin-bottom: 0.25em;	}";
css+="#subdialog {	text-align: center;	position: fixed;	_position: absolute;	left: 40%;	top: 25%;	width: 200px;	height: 60px;	background-color: Window;	padding: 2em;	z-index: 20;	border: 0.25em solid ButtonShadow;	display: block;	}";
css+="</style>";
document.write(css);

function inputFile()
	{
	this.baseWeb="/"; // domovska slozka webu |W
	this.defaultFileAdvise="<span style='color:#999'>(Kliknutím na Procházet vložíte soubor)</span>";
	this.blankIcon="images/file_extension_icons/add_file_48.png"; // prazdba ikona W
	this.xmlSource="/modules/imce/file_imce.php?fileinfo=1&guid=";
	this.inputName=null; // jmeno tohoto objektu - instance inputImage
	this.total=0; // celkem zobrazeno obrazku
	this.max=255; // maximalni pocet polozek |W
	this.baseDir="modules/imce/file_imce.php?guid="; // cesta k obaryku bez konkretniho GUID
	this.baseImgDir="nextmedia_extension"; // cesta k obaryku bez konkretniho GUID
	this.splitter=":"; // oddelovac GUID fotografii v db
	this.xmlHttp=false;
	this.iconwidth=48;
	this.iconheight=48;
	this.inProgress=false;
 	this.progressimage=new Image(); 
	this.progressimage.src=this.baseWeb+"/nextmedia_extension/images/load.gif";
	this.parse = function(iname)
		{
		this.xmlSource=this.baseWeb+"/modules/imce/file_imce.php?fileinfo=1&guid=";
		this.progress("Čekejte prosím");
		this.inputName="inputFile_"+iname;
		ieDebug("object '"+this.inputName+"' parse");
		inp = document.getElementsByTagName("input");
		for (this.i=0;this.i<inp.length;this.i++)
			{
			if (inp[this.i].name.indexOf(iname)!=-1)
				 {
				 obal=document.createElement("div");
 				 // obal.style.backgroundColor="#eee";
 				 obal.style.padding="10px";
 				 inp[this.i].parentNode.appendChild(obal);
				 inp[this.i].style.visibility="hidden";
				 if (inp[this.i].value!="")
				 	{
					if (inp[this.i].value!="") defsrc=this.baseWeb+this.baseDir+inp[this.i].value;
					this.arrSrc=inp[this.i].value.split(this.splitter);
					
					for (this.j=0;this.j<this.arrSrc.length;this.j++)
						{
						this.addFileBox(inp[this.i],this.arrSrc[this.j]);
						}
					}
				this.addFileBox(inp[this.i],false);
				}
			}
		this.progress(false);
		}
	this.parseLinks = function(rodic) // spoji a prevede do vstupniho pole vsechny guidy
		{
		inp = document.getElementsByTagName("input");
		lnk ="";
		for (this.k=0;this.k<inp.length;this.k++)
			{
			if (inp[this.k].className=="location")
				{
				if (inp[this.k].value!="") lnk+=inp[this.k].value+this.splitter;
				}
			}
		lnk=lnk.substring(0,lnk.length-1); // odstranit posledni dvojtecku
		rodic.parentNode.getElementsByTagName("input")[0].value=lnk;
		}
	this.addFileBox = function(rodic,url) // polozka soubor
		{
		this.total++;
		if (this.total>this.max) return false;
		rodic=rodic.parentNode.getElementsByTagName("div")[0]; // 1. div pozadovaneho input
		if (!url)
			{
			turl=this.baseWeb+this.emptyImg;
			url="";
			}
		else turl=this.baseWeb+this.baseDir+url;

		obal=document.createElement("div");
		obal.className="fileedit";

		tmp="file_"+this.genRandStr(16);
		if (document.uniqueID) // MSIE nedokaze nastavit atr. NAME a VISIBILITY zpusobuje error
			{
			txt_guid=document.createElement("<input type='text' name='"+tmp+"'>");
			}
		else
			{
			txt_guid=document.createElement("input");
			txt_guid.setAttribute("type","text");
			txt_guid.setAttribute("name",tmp);
			txt_guid.style.visibility="hidden";
			}
		txt_guid.setAttribute("value",url);
		txt_guid.setAttribute("id",tmp);
		txt_guid.setAttribute("defValue",url);
		txt_guid.className="location";
		txt_guid.onfocus=new Function(this.inputName+".changeFile(this);");
		txt_guid.onchange=new Function(this.inputName+".changeFile(this);");
		txt_guid.style.width="0";
		txt_guid.style.height="0";
		txt_guid.style.borderWidth="0";
		txt_guid.style.backgroundColor="transparent";
		txt_guid.style.color="#eee";
		txt_guid.style.cursor="default";
		obal.appendChild(txt_guid);

		fileobal=document.createElement("div");
		fileobal.className="fileobal";
		
		img_icon=document.createElement("img");
		img_icon.className="fileName";
		img_icon.src=this.baseWeb+this.baseImgDir+"/"+this.blankIcon;
		img_icon.width=this.iconwidth;
		img_icon.height=this.iconheight;
		img_icon.onclick=new Function(this.inputName+".showDlg(this.parentNode.parentNode.getElementsByTagName(\"input\")[0]);");
		fileobal.appendChild(img_icon);
						 
		lbl_filename=document.createElement("div");
		lbl_filename.className="fileName";
		lbl_filename.innerHTML=this.defaultFileAdvise;
		fileobal.appendChild(lbl_filename);

 		lbl_filedate=document.createElement("div");
		lbl_filedate.className="fileDate";
		lbl_filedate.innerHTML="&nbsp;";
		fileobal.appendChild(lbl_filedate);

		lbl_filesize=document.createElement("div");
		lbl_filesize.className="fileSize";
		lbl_filesize.innerHTML="&nbsp;";
		fileobal.appendChild(lbl_filesize);

		obal.appendChild(fileobal);

		 		 
		btn_submit=document.createElement("input");
		btn_submit.setAttribute("type","button");
		btn_submit.setAttribute("value","Procházet");
		btn_submit.onclick=new Function(this.inputName+".showDlg(this.parentNode.getElementsByTagName(\"input\")[0]);");
		obal.appendChild(btn_submit);

		btn_delete=document.createElement("input");
		btn_delete.setAttribute("type","button");
		btn_delete.setAttribute("value","Žádný");
		btn_delete.onclick=new Function("this.parentNode.getElementsByTagName('input')[0].value='';"+this.inputName+".changeFile(this.parentNode.getElementsByTagName(\"input\")[0]);");
		obal.appendChild(btn_delete);
		obal.title=tmp;
		rodic.appendChild(obal);

		br=document.createElement("hr");
		br.style.clear="both";
		br.style.visibility="hidden";
		ieDebug("inputname "+txt_guid.name+"\ntmp "+tmp);
		rodic.appendChild(br);
		if (url!="") this.loadXmlData(this.xmlSource+this.getGuid(obal.getElementsByTagName("input")[0].value),tmp);
		return true;
		}
	this.getGuid = function(str)
		{
		if (str.length>16)
			{
			str=str.substring(str.length-16); // poslednich 16 znaku
			}
		return str;
		}
	this.changeFile = function(obj)
		{
		ieDebug(obj.name+" changeFile");
		if (obj.value.length>16)
			{
			obj.value=this.getGuid(this.getGuid(obj.value));
			}

		if (obj.value!="")
			{
			if (obj.getAttribute('defValue')=="")
				{
				obj.setAttribute("defValue",obj.value);
				this.addFileBox(obj.parentNode.parentNode);
				}
			this.loadXmlData(this.xmlSource+this.getGuid(obj.value),obj.id);
			}
 		else
 			{
			this.setFileAttr(obj.id,this.defaultFileAdvise,"&nbsp;","&nbsp;",this.blankIcon);
			}
		this.parseLinks(obj.parentNode.parentNode);
		}
	this.retVal = function(obj)
		{
		if (obj.childNodes[0]) return obj.childNodes[0].nodeValue;
		return "";
		}
	this.readFileDetails = function(objid)
		{
		var fileName = this.xmlHttp.responseXML.getElementsByTagName("FileName")[0];
		var fileSize = this.xmlHttp.responseXML.getElementsByTagName("FormatedFileSize")[0];
		var fileDate = this.xmlHttp.responseXML.getElementsByTagName("FormatedCreated")[0];
		var fileIcon = this.xmlHttp.responseXML.getElementsByTagName("FileIcon")[0];
		if (fileName.childNodes[0]) this.setFileAttr(objid,this.retVal(fileName),this.retVal(fileDate),this.retVal(fileSize),this.retVal(fileIcon));
		}
	this.setFileAttr = function(objid,fileName,fileDate,fileSize,icourl)
		{
//		alert(icourl);
		sloupec=document.getElementById(objid).parentNode.getElementsByTagName("div")[0].getElementsByTagName("div");
		ikona=document.getElementById(objid).parentNode.getElementsByTagName("div")[0].getElementsByTagName("img")[0];
		sloupec[0].innerHTML=fileName;
		sloupec[1].innerHTML=fileDate;
		sloupec[2].innerHTML=fileSize;
		ikona.src=this.baseWeb+this.baseImgDir+"/"+icourl;
		}
	this.showDlg = function(elname)
		{
		imceImageBrowser(elname.name, elname.value, "txtLnkUrl#", window);
		}
	this.loadXmlData = function(url,objid) // zacatek stahovani xml souboru
		{
		// prompt(url,url);
		ieDebug(objid+" loadXmlData");
		this.setFileAttr(objid,"?????","?????","?????",this.blankIcon);
		if (window.XMLHttpRequest)
			{
			this.xmlHttp = new XMLHttpRequest();
			}
		else if (window.ActiveXObject)
			{
			this.xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
		if (document.getElementById(objid))
			 {
			 // MSIE nedokaze dynamicky zjistovat stav u SYNCHRONNIHO prenosu
			 // this.xmlHttp.onreadystatechange =  new Function(this.inputName+".processRequestChange("+objid+");");
			 this.xmlHttp.open("GET", url, false);
			 this.xmlHttp.send(null);
			 this.processRequestChange(objid);
			 }
		}
	this.processRequestChange = function(objid) // stav stahovani se zmenil (ok,chyba,prubeh)
		{
		ieDebug(objid+" processRequestChange");
		if (objid.id) objid=objid.id;
		if (this.xmlHttp.readyState == 4)
			{
			if(this.xmlHttp.status == 200)
				{
				this.readFileDetails(objid);
				}
			else
				{
				alert("Nelze načíst zdroj dat.\n"+ this.xmlHttp.status +":"+ this.xmlHttp.statusText);
				}
			// end of the request, change the status zone
  			}
		else
			{
			// Indicates that the client is *busy*
			}
		}
	this.progress = function (status) // progressbar
	  	{
	  	if (!document.uniqueID) // non MSIE
				{ 
	  		if (status)
				{
				this.inProgress=true;
				if (!document.getElementById("subdialog"))
					 {
					 var subdialog=document.createElement("div"); // pred ni vlozime popisek
					 subdialog.id="subdialog";
					 var dialogimage=document.createElement("img"); // do ni progress
					 dialogimage.src=this.progressimage.src;
					 subdialog.appendChild(dialogimage);
	
					 var subtext=document.createElement("div"); // pred ni vlozime popisek
					 subtext.innerHTML=status;
					 subdialog.appendChild(subtext);
					 document.getElementsByTagName("body")[0].appendChild(subdialog);
					 }
				}
	  	else
				{
				this.inProgress=false;
				if (document.getElementById("subdialog"))
					 {
					 document.getElementsByTagName("body")[0].removeChild(document.getElementById("subdialog"));	
					 }
				}
			}
  	}
	this.genRandStr = function(delka) // nahodny retezec
		{
		znaky="abcdefghijklmnopqrstuvwxyz123456789";
		var retezec;
		retezec="";
		for (var x=0; x <= delka; x++)
			{
			retezec+=znaky.charAt(Math.round(Math.random()*(znaky.length-1)));
			}
		return retezec;
		}
	}

function ieDebug(t)
			 {
//			 if (document.uniqueID) alert(t);
			 }

