function fileListDialog(files){
	var name = new Array();
	var urn = new Array();
	var type = new Array();
	var size = new Array();
	var latest = new Array();


		i=0
		name[i] = files[i].name;
		urn[i] = files[i].urn;
		type[i] = files[i].type;
		size[i] = files[i].size;
		latest[i] = files[i].lastModifiedDate;

	//display file status
	var output = "<hr>The number of files is "+files.length+"<br><hr/>";
		output+="Name:"+name[i]+"<br>"+"URN:"+urn[i]+"<br>"+"Type:"+type[i]+"<br>"+"Size:"+size[i]+"<br>"+"Date:"+latest[i]+"<br><hr>"
		document.getElementById("filestatus").innerHTML = output;

		document.getElementById("filecontent").innerHTML = "";
	//get file contents
	fileread(files,"filecontent","file");

}

function fileread(blob,place,variable){
		var f = blob[i];
		var reader = new FileReader();

		if(f.type.match("text.*")){
			reader.onload = function(e){
				document.getElementById(place).innerHTML = reader.result;
				document.getElementById(variable).value = reader.result;
				document.getElementById("flag").value = "text";
			}
			reader.readAsText(f,"utf-8");
		}

		if(f.type.match("image.*")){
			reader.onload = function(e){
	var img = document.createElement("img");
	img.src = reader.result;
	document.getElementById(place).appendChild(img);
				document.getElementById(variable).value = reader.result;
	document.getElementById("flag").value = "image";
			}
			reader.readAsDataURL(f);
		}

}


function onDrop(event){
	var files = event.dataTransfer.files;
	var disp = document.getElementById("disp");
	disp.innerHTML = "";

	for(i=0;i<files.length;i++){
		var f = files[i];
		var reader = new FileReader();

		if(!f.type.match('image.*')&&!f.type.match('text.*')){
			alert("Drag and Drop Image or Text file!");
			continue;
		}

		reader.onerror = function(event){
			disp.innerHTML = "read error!";
		}

		if(f.type.match('text.*')){
			reader.onload = function(event){
				disp.innerHTML = event.target.result;
				document.getElementById("file").value = reader.result;
			}
			reader.readAsText(f,"utf-8");
		}

		if(f.type.match('image.*')){
			reader.onload = function(event){
				var img = document.createElement("img");
				img.src = event.target.result;
				disp.appendChild(img);
				document.getElementById("file").value = reader.result;
			}
			reader.readAsDataURL(f);
		}
	}

	reader.addEventListener('progress',function(event){
	 document.getElementById("progress").innerHTML = Math.floor((event.loaded / event.total)*100);
	},true);

			event.preventDefault();
}

function onDragOver(event){
	event.preventDefault();
}

