function InboxFileRequests() {
	var self = this;
	var param;
	var attr;
	var name;
	var u;
	var date;
	this.fileInfo = new Array();

	this.init = function() {
		if (!tplf.getUrlParam('reqFile')) { return false; }
		self.checkForPassword(tplf.getUrlParam('reqFile'));
	}
	this.checkForPassword = function(param) {
		if (!param) { return false; }
		makeRequest('interface/modules/public/checkForPassword.php?function=reqFile.receiveFileInfo("%t","%p")','GET','',true);
	}
	this.receiveFileInfo = function(param,attr) {
		self.fileInfo = new Array();
		self.fileInfo['unique'] = tplf.getUrlParam('reqFile');
		self.fileInfo['type'] = param;
		self.fileInfo['pass'] = attr;
		if (attr == 1) { self.getIdentWindow(); }
		else {
			if (param == 'dir') {
				iScript.init();
			}
			else if (param == 'file') {
				makeRequest('interface/modules/public/login.php?password=undefined&function=reqFile.receiveValidation("%r","%n","%s","%d","%u")','GET','',true);
			}
			else {
				self.getUnknownWindow();
			}
		}
	}
	this.getIdentWindow = function() {
		document.body.style.cursor = 'wait';
		tplf.getHtml('interface/templates/reqFile-login.html',true,'reqFile.writeHtml("otherPages");');
	}
	this.getFileWindow = function() {
		document.body.style.cursor = 'wait';
		tplf.getHtml('interface/templates/reqFile-file.html',true,'reqFile.writeHtml("otherPages");');
	}
	this.getUnknownWindow = function() {
		document.body.style.cursor = 'wait';
		tplf.getHtml('interface/templates/reqFile-unknown.html',true,'reqFile.writeHtml("otherPages");');
	}
	this.writeHtml = function(param) {
		if (!tplf.getHtmlTemplate) { return false; }
		if (!param || !document.getElementById(param)) { param = document.getElementsByTagName('body')[0]; }
		else { param = document.getElementById(param); }
		param.innerHTML = tplf.getHtmlTemplate;
		document.body.style.cursor = '';
		if (self.fileInfo['type'] == 'file' && document.getElementById('downloadFile')) {
			document.getElementById('downloadFile').setAttribute('href','/interface/modules/files/downloadfile.php?reqFile='+self.fileInfo['unique']);
			document.getElementById('downloadFile').style.textDecoration = 'none';
			document.getElementById('hiddenlink').value = self.fileInfo['unique'];
			if (document.getElementById('fileName')) { document.getElementById('fileName').innerHTML = self.fileInfo['name']; }
			if (document.getElementById('fileSize')) { document.getElementById('fileSize').innerHTML = tplf.mathsize(self.fileInfo['size']); }
			if (document.getElementById('fileDate')) { document.getElementById('fileDate').innerHTML = self.fileInfo['date']; }
			if (document.getElementById('owner')) { document.getElementById('owner').innerHTML = self.fileInfo['username']; }
			if (document.getElementById('fileIcon')) { document.getElementById('fileIcon').src = 'interface/modules/geticon/index.php?reqFile='+self.fileInfo['unique']+'&name='+self.fileInfo['name']; }
		}
	}
	this.tryPassword = function(param) {
		if (!param) { return false; }
		document.getElementById('password').disabled = true;
		makeRequest('interface/modules/public/login.php?password='+param+'&function=reqFile.receiveValidation("%r","%n","%s","%d","%u")','GET','',true);
	}
	this.receiveValidation = function(param,name,attr,date,u) {
		if (param == 1) {
			self.fileInfo['name'] = name;
			self.fileInfo['size'] = attr;
			self.fileInfo['date'] = date;
			self.fileInfo['username'] = urldecode(u);
			if (document.getElementById('logintable')) { document.getElementById('logintable').parentNode.removeChild(document.getElementById('logintable')); }
			if (self.fileInfo['type'] == 'dir') {
				iScript.init();
			}
			else if (self.fileInfo['type'] == 'file') {
				self.getFileWindow();
			}
		}
		else {
			if (document.getElementById('wrongPass')) { document.getElementById('wrongPass').style.display = 'block'; }
			document.getElementById('password').value = '';
			document.getElementById('password').disabled = false;
		}
	}
	this.relogin = function() {
		tplf.login();
	}
}
var reqFile = new InboxFileRequests;
reqFile.init();