/*
* Leave the following ;
* Functions Created for file browser by h-master [ http://h-master.net ]
* content here is licensed under the creative commons attribution 2.5 license [ http://www.creativecommons.org/licenses/by/2.5/ ]
*/


function delfile(url){
ans=window.confirm("Wollen sie die Datei wirklich löschen? Wenn ja, drücken Sie auf OK");
  if(ans){
    window.location.replace(url);
  }
}  
function delfolder(url){
ans=window.confirm("Wollen sie das Verzeichnis wirklich löschen? Wenn ja, drücken Sie auf OK");
  if(ans){
    window.location.replace(url);
  }
}  


function preview(obj, file, owidth, oheight) {
	prevBox = document.getElementById("previewbox");
	prevBox.style.display = "block";
	prevBox.style.background = "white";
	prevBox.style.position = "absolute";
	fl = file.length;
	prevBox.style.top = findPosY(obj) + "px";
	prevBox.style.left = findPosX(obj) + fl*5 +  "px";
		if(owidth > 100 && oheight > 100) {
			prevBox.style.width = 100 + "px";
			prevBox.style.height = 100 + "px";
		} else {
			prevBox.style.width = owidth + "px";
			prevBox.style.height = oheight + "px";
		}
	prevBox.style.overflow = "hidden";
	prevBox.style.border = "1px solid #d5d5d5";
	prevBox.innerHTML =  '<img src="' + file + '" alt="' + file + '" />';

}

function findPosX(obj) {
var curleft = 0;
if(obj.offsetParent) {
	while(1) {
	  curleft += obj.offsetLeft;
		if(!obj.offsetParent) {
			break;
		}
	  obj = obj.offsetParent;
	}
} else if(obj.x) {
	curleft += obj.x;
}
return curleft;
}

function findPosY(obj) {
var curtop = 0;
if(obj.offsetParent) {
	while(1) {
	  curtop += obj.offsetTop;
		if(!obj.offsetParent) {
			break;
		}
	  obj = obj.offsetParent;
	}
} else if(obj.y) {
	curtop += obj.y;
}
return curtop;
}
  
function hideprev() {
	prevBox = document.getElementById("previewbox");
	prevBox.style.display = "none";
	prevBox.innerHTML = "";
}

function makeRequest(handle, url, id, getpost, senddata) {
	if(getpost == "undefined" || getpost != "POST" || getpost != "GET") {
		getpost = "GET";
	} 
	var http_request = false;
		if (window.XMLHttpRequest) { // Mozilla, Safari, ...
			http_request = new XMLHttpRequest();
				if (http_request.overrideMimeType) {
					http_request.overrideMimeType('text/xml');
					// See note below about this line
				}
		} else if (window.ActiveXObject) { // IE
			try {
				http_request = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					http_request = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {}
			}
		}

	if (!http_request) {
		alert('Giving up :( Cannot create an XMLHTTP instance');
		return false;
	}
	
	http_request.onreadystatechange = function() { loading(id, http_request, handle);  };
	http_request.open(getpost, url, true);
	if(getpost == "POST") {
		http_request.send(senddata);
	} else {
		http_request.send(null);
	}
}

function loading(id, http_request, handle) {
scrollTo(0,0);
ls = document.getElementById("loading").style;
ps = document.getElementById("progress").style;
ls.display = "block";
ps.display = "block";
ls.position = "fixed";
ps.position = "fixed";

ls.position = "fixed";
ls.top = "0px";
ls.left = "0px";
ls.width = browserprefs('width') + "px";
ls.height = browserprefs('height') + "px";
ls.background = "#4FA3DA";
ls.opacity = 5/10;
ls.filter = 'alpha(opacity=' + 5*10 + ')';

ps.left = ((browserprefs('width')/2) - 100) + "px";
ps.top = ((browserprefs('height')/2) - 100) + "px";

	switch(http_request.readyState) {
		case 0:
		document.getElementById("progress").innerHTML = "unintialized " ;
		break;
		
		case 1:
		document.getElementById("progress").innerHTML = "loading " + '<img src="loading.gif" alt="Loading..." />';
		break;
		
		case 2:
		document.getElementById("progress").innerHTML = "loaded " + '<img src="loading.gif" alt="Loading..." />';
		break;
		
		case 3:
		document.getElementById("progress").innerHTML = "interactive " + '<img src="loading.gif" alt="Loading..." />';
		break;
		
		case 4:
		document.getElementById("loading").style.display = "none";
		document.getElementById("progress").style.display = "none";
		handle(http_request, id);
		break;
	}
}

function showfiles(http_request, id) {
	if (http_request.status == 200) {
		document.getElementById(id).innerHTML = http_request.responseText;
	}
}

function browserprefs(type) {
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		brwsWidth = window.innerWidth;
		brwsHeight = window.innerHeight;
	 } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		brwsWidth = document.documentElement.clientWidth;
		brwsHeight = document.documentElement.clientHeight;
	 } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		brwsWidth = document.body.clientWidth;
		brwsHeight = document.body.clientHeight;
	 }
	 
	switch(type) {
		case "width":
			return brwsWidth;
		break;
		case "height":
			return brwsHeight;
		break;
	}
}
