function createPopup(type, root_path)
{
	switch(type)
	{							
		case 'login':	LightBox 		= document.createElement('div');
						PopupWindow 	= document.createElement('div');
						TitleBar 		= document.createElement('div');
						Title			= document.createElement('h1');
						XButton			= document.createElement('div');
						LoginForm 		= document.createElement('form');
						//UsernameLabel	= document.createElement('label');
						Username		= document.createElement('input');
						//PasswordLabel	= document.createElement('label');
						Password		= document.createElement('input');
						AutoLoginLabel	= document.createElement('label');
						AutoLogin		= document.createElement('input');
						ViewOnlineLabel	= document.createElement('label');
						ViewOnline		= document.createElement('input');
						Redirect		= document.createElement('input');
						Submit			= document.createElement('input');
						
						TitleText		= document.createTextNode('Login');
						XButtonText		= document.createTextNode('X');
						//UsernameText	= document.createTextNode('Username: ');
						//PasswordText	= document.createTextNode('Password: ');
						AutoLoginText	= document.createTextNode('Log me in automatically each visit');
						ViewOnlineText	= document.createTextNode('Hide my online status this session');
						
						LightBox.setAttribute('id', 'lightBox');
						PopupWindow.setAttribute('id', 'PopupWindow');
						
						document.body.appendChild(LightBox);
						document.body.appendChild(PopupWindow);
						
						LightBox.style.height	= Element.getHeight('phpbb') + 'px';
						PopupWindow.style.left	= document.viewport.getWidth() / 2 - Element.getWidth('PopupWindow') / 2 + 'px';
						PopupWindow.style.top 	= document.viewport.getHeight() / 2 - Element.getHeight('PopupWindow') / 2 + 'px';
						PopupWindow.appendChild(TitleBar);
						
						LightBox.observe('contextmenu', function(event) {
							event.stop();
						});
						PopupWindow.observe('contextmenu', function (event) {
							event.stop();
						});
						
						TitleBar.setAttribute('class', 'titleBar');
						TitleBar.appendChild(Title);
						TitleBar.appendChild(XButton);
						
						Title.appendChild(TitleText);
						
						XButton.appendChild(XButtonText);
						XButton.setAttribute('id', 'xButton');
						XButton.setAttribute('title', 'Close');
						
						XButton.observe('click', function() {
							document.body.removeChild(LightBox);
							document.body.removeChild(PopupWindow);
							LightBox.stopObserving('contextmenu');
							PopupWindow.stopObserving('contextmenu');
						});
						
						LoginForm.setAttribute('action', root_path + 'ucp.php?mode=login');
						LoginForm.setAttribute('method', 'post');
						
						PopupWindow.appendChild(LoginForm);
						
						Redirect.setAttribute('type', 'hidden');
						Redirect.setAttribute('name', 'redirect');
						Redirect.setAttribute('value', '../index.php');
						
						LoginForm.appendChild(Redirect);
						
						Username.setAttribute('type', 'text');
						Username.setAttribute('name', 'username');
						Username.setAttribute('value', 'Username');
						Username.setAttribute('tabindex', '1');
						Username.observe('focus', function() {
							currentValue = Username.value;
							Username.value = currentValue == 'Username' ? '' : currentValue;
						});
						Username.observe('blur', function() {
							currentValue = Username.value;
							Username.value = currentValue == '' ? 'Username' : currentValue;
						});
						
						LoginForm.appendChild(Username);
						
						Password.setAttribute('type', 'password');
						Password.setAttribute('name', 'password');
						Password.setAttribute('value', 'Password');
						Password.setAttribute('tabindex', '2');
						Password.observe('focus', function() {
							currentValue = Password.value;
							Password.value = currentValue == 'Password' ? '' : currentValue;
						});
						Password.observe('blur', function() {
							currentValue = Password.value;
							Password.value = currentValue == '' ? 'Password' : currentValue;
						});
						
						LoginForm.appendChild(Password);
						
						AutoLoginLabel.setAttribute('for', 'autologin');
						
						LoginForm.appendChild(AutoLoginLabel);
						
						AutoLogin.setAttribute('type', 'checkbox');
						AutoLogin.setAttribute('name', 'autologin');
						AutoLogin.setAttribute('id', 'autologin');
						AutoLogin.setAttribute('checked', 'checked');
						
						AutoLoginLabel.appendChild(AutoLogin);
						AutoLoginLabel.appendChild(AutoLoginText);
						
						LoginForm.appendChild(ViewOnlineLabel);
						
						ViewOnline.setAttribute('type', 'checkbox');
						ViewOnline.setAttribute('name', 'viewonline');
						ViewOnline.setAttribute('id', 'viewonline');
						
						ViewOnlineLabel.appendChild(ViewOnline);
						ViewOnlineLabel.appendChild(ViewOnlineText);
						ViewOnlineLabel.setAttribute('for', 'viewonline');
						
						Submit.setAttribute('type', 'submit');
						Submit.setAttribute('name', 'login');
						Submit.setAttribute('value', 'Login');
						
						LoginForm.appendChild(Submit);
						
						Username.focus();
						
						Event.observe(window, 'beforeunload', function() {
							document.body.removeChild(LightBox);
							document.body.removeChild(PopupWindow);
							Event.stopObserving(window, 'beforeunload');
						});
	}
}

function redirect(URL)
{
	window.location.assign(URL);	
}

function filename(str)
{
	name = str.substring(str.lastIndexOf('\\') + 1);
	$('filename').update(name);
}

UserInfo = {
	ContainerId: 'outer_box',
	init: function() {
		Popup = document.createElement('div');
		Popup.setAttribute('id', UserInfo.ContainerId);
		Popup.hide();
	},
	show: function(content, event)
	{		
		document.body.appendChild(Popup);
		
		Popup.innerHTML = unescape(content);
		Popup.show();
		
		Event.observe(Event.findElement(event), 'mousemove', function(event) {
			Popup.style.top = Event.pointerY(event) + 23 + 'px';
			Popup.style.left = Event.pointerX(event) + 12 +  'px';
		});
		
		Event.observe(Event.findElement(event), 'click', function() {
			Popup.hide();
		});
		
		Event.observe(Event.findElement(event), 'mouseout', function() {
			Popup.hide();
		});
	}
}

function AudioPlayer(src)
{
	var testPlayer = document.createElement("audio");
	var isIE = navigator.userAgent.indexOf("MSIE") != -1 ? true : false;
	var width = 250;
	var height = 16;
	var type = "application/quicktime";
	var classid = "CLSID:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B";
	
	if (navigator.plugins["Microsoft® Windows Media Player Firefox Plugin"] || isIE)
	{
		type = "application/x-mplayer2";
		classid = "CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6";
		height = 45;
	}

	var source = src;
	
	legacyPlayer = "<object classid=\"" + classid + "\" type=\"" + type + "\" width=\"" + width + "\" height=\"" + height + "\">\
						<param name=\"url\" value=\"" + source + "\" />\
						<param name=\"uiMode\" value=\"full\" />\
						<param name=\"autoStart\" value=\"false\" />\
						<embed src=\"" + source + "\" type=\"" + type + "\" autostart=\"false\" width=\"" + width + "\" height=\"" + height + "\"></embed>\
					</object>";
	
	if (testPlayer.canPlayType)
	{
		Extension = source.split('.');
		Ext = Extension[Extension.length - 1];
		
		if (Ext == "mp3")
			mimeType = "audio/mp3";
		else if (Ext == "wav")
			mimeType = "audio/x-wav";
		else if (Ext == "wma")
			mimeType = "audio/x-ms-wma";
		else
			mimeType = "";
			
		if ((testPlayer.canPlayType(mimeType) == "probably" || testPlayer.canPlayType(mimeType) == "maybe") && !isIE)
			audioPlayer = '<audio preload="metadata" src="' + source + '" controls>' + legacyPlayer + '</audio>';
		else
			audioPlayer = legacyPlayer;
	}
	else
		audioPlayer = legacyPlayer;
	
	testPlayer = null;
	
	document.open();
	document.write(audioPlayer);
	document.close();
}
