
function alertContents(http_request, r)
{
	if (http_request.readyState == 4)
	{
		if (http_request.status == 200)
		{
			p = document.getElementById('myPanel');

			p.innerHTML = http_request.responseText;

			if (document.getElementById('_username'))
				document.getElementById('_username').focus();

			if (r)
			{
				document.location.reload();
				myDestroyPanel();
			}
		}
    }
}

function sendRequest(url, f, r)
{
	//alert(url);

	if (window.XMLHttpRequest)
	{
		var http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType)
		{
        	http_request.overrideMimeType('text/xml');
        }
	} else
	if (window.ActiveXObject)
	{
		try {
        	http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e)
		{
        	try {
            	http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
        }
	}

	if (!http_request)
	{
    	return false;
	}

	http_request.onreadystatechange = function() { f(http_request, r); };
	http_request.open('GET', url, true);
	http_request.send(null);

	return true;
}

function sendLogin()
{
	sendRequest("admin.php?step=login&slim=1&username=" + document.getElementById('_username').value + "&password=" + document.getElementById('_password').value, alertContents, true);
}

function myCreatePanel()
{
	var p = document.createElement('div');
	p.setAttribute('id', 'myPanel');
	//p.setAttribute('style', 'width: 100%; top: 0px; left: 0px; padding: 0px; padding-top: 5px; position: absolute; height: 28px; background-color: #d4d0c8; border-bottom: 1px solid #808080; border-top: 1px solid white; font-family: tahoma; font-size: 11px;');
	p.style.width   = '100%';
	p.style.top     = '0px';
	p.style.left    = '0px';
	p.style.padding = '0px';
	if (document.all)
	{
		p.style.paddingTop = '0px';
		p.style.position = 'absolute';
	}
	else
	{
		p.style.paddingTop = '5px';
		p.style.position = 'fixed';
	}

	p.style.height = '28px';
	p.style.backgroundColor = '#d4d0c8';
	p.style.borderBottom = '1px solid #808080';
	p.style.borderTop = '1px solid white';
	p.style.fontFamily = 'tahoma';
	p.style.fontSize = '11px';
	p.style.zIndex = 100;

	sendRequest('admin.php?slim=1', alertContents, false);

	document.body.appendChild(p);

	var a = document.getElementById('myPanel');
}

function myDestroyPanel()
{
	var p = document.getElementById('myPanel');

	document.body.removeChild(p);
}

function ShowHidePanel()
{
	var a = document.getElementById('myPanel');
	if (!a)
		myCreatePanel();
	else
		myDestroyPanel();

	return false;
}

function myKeyboardEvent(e)
{
	var k;
	/*
	if(document.all)
	{
		k = window.event.keyCode;
	} else
	{
		k = e.keyCode;
	}
	*/
	if (window.event)
	{
		k = window.event.keyCode;
	} else
	{
		if (e) k = e.which;
	}

	if (k == 112)
	{
		ShowHidePanel();
		return false;
	}

	return true;
}

function checkEnter(event, f)
{
	if (event.keyCode == 13)
    {
    	f();
    }
}

function myCustomFileBrowser(dir) {
	var template = new Array();

	template['width']  = 750;
	template['height'] = 500;

	var leftVal = (screen.width - template['width']) / 2;
	var topVal  = (screen.height - template['height']) / 2;

	window.open('js/tiny_mce/plugins/filemanager/InsertFile/insert_file.php' + "?browser=yes&pricelist=yes&url=" + dir, 'FileManagerBrowser', 'dialog=yes,modal=yes,toolbar=no,directories=no,scrollbars=no,menubar=no,status=no,statusbar=no,resizible=no,width=' + template['width'] + ',height=' + template['height'] + ',left=' + leftVal + ',top=' + topVal);
}

/*
if (!document.all)
	document.documentElement.onkeypress = myKeyboardEvent;
else
	document.onkeypress = myKeyboardEvent;

document.documentElement.onhelp  = ShowHidePanel;
*/
document.onkeydown = myKeyboardEvent;
