/*
	---------------------------------------------------------------------------
	- Web 2.0 AJAX Loading Panel 1.0.0                                        -
	---------------------------------------------------------------------------
	- created by: Martin Ivanov (September 2007)                              -
	- website: http://www.acidmartin.com or http://acidmartin.wemakesites.net -
	- email: acid_martin@yahoo.com or martin@acidmartin.com                   -
	---------------------------------------------------------------------------
	
	IMPORTANT REGULATIONS:
	
	1. IF YOU ARE USING THE OBFUSCATED VERSION OF WEB2.0 AJAX LOADING PANEL, IT IS FORBIDDEN TO DEOBFUSCATE AND MODIFY THIS SCRIPT WITHOUT AUTHOR'S WRITTEN PERMISSION. OTHERWISE SUCH ACTIONS WILL BE CONSIDERED VIOLATIONS OF THE COPYRIGHT LAWS AND LEGAL STEPS WILL BE TAKEN.
	
	2. IF YOU HAVE PURCHASED THE SOURCE CODE OF WEB2.0 AJAX LOADING PANEL, YOU CANNOT USE THIS SCRIPT ON WEBPAGES WITHOUT OBFUSCATING IT FIRST. OTHERWISE SUCH ACTIONS WILL BE CONSIDERED VIOLATIONS OF THE COPYRIGHT LAWS AND LEGAL STEPS WILL BE TAKEN.
*/

var Web20AjaxLoadingPanelVersion = '1.0';

function renderLoadingPanel()
{
	var loadingPanelConfigFile = 'Scripts/Web20AjaxLoadingPanel/Config.xml';
	if(window.ActiveXObject)
	{
		config = new ActiveXObject("Microsoft.XMLDOM");
		config.async = false;
		config.load(loadingPanelConfigFile);
	}
	else if(document.implementation && document.implementation.createDocument)
	{
		config = document.implementation.createDocument("","",null);
		config.async = false;
		config.load(loadingPanelConfigFile);
	}
	loadingMessageHeight = config.getElementsByTagName('loadingmessage')[0].getAttribute('height');
	loadingMessageWidth = config.getElementsByTagName('loadingmessage')[0].getAttribute('width');
	var writingCredits = document.createElement('div');
	writingCredits.setAttribute('id', 'credits_' + randomid);
	writingCredits.setAttribute('unselectable', 'on');
	writingCredits.innerHTML = 'Powered by <a href="http://acidmartin.wemakesites.net/?pageId=Web20AjaxLoadingPanel" title="Powered by Web 2.0 AJAX Loading Panel ' + Web20AjaxLoadingPanelVersion + '" style="font-size: 10px; color: white;">Web 2.0 AJAX Loading Panel ' + Web20AjaxLoadingPanelVersion + '</a>';
	writingCredits.style.position = 'absolute';
	writingCredits.style.position = 'fixed';
	writingCredits.style.display = 'none';
	writingCredits.style.visibility = 'visible';
	writingCredits.style.bottom = '8' + 'px';
	writingCredits.style.right = '8' + 'px';
	writingCredits.style.zIndex = '120000';
	writingCredits.style.color = 'white';
	writingCredits.style.font = 'normal 10px Arial, Verdana, Sans-serif';
	var modalPane = document.createElement('div');
	var loadingMessageContainer = document.createElement('div');
	var modalMessageStyles = document.createElement('link');
	var registered = false;
	modalMessageStyles.type = 'text/css';
	modalMessageStyles.rel = 'stylesheet';
	modalMessageStyles.href = 'Scripts/Web20AjaxLoadingPanel/' + Web20AjaxLoadingPanelVersion + '/W20ALP.css';
	document.getElementsByTagName('head')[0].appendChild(modalMessageStyles);
	modalPane.setAttribute('id', 'LoadingMessageModalPane');
	modalPane.style.background = config.getElementsByTagName('modalpanel')[0].getAttribute('backcolor');
	modalPane.style.height = document.documentElement.scrollHeight + 'px';
	loadingMessageContainer.setAttribute('id', 'loadingMessageContainer');
	loadingMessageContainer.unselectable = 'on';
	loadingMessageContainer.innerHTML = config.getElementsByTagName('loadingmessage')[0].getAttribute('text');
	loadingMessageContainer.style.height = loadingMessageHeight + 'px';
	loadingMessageContainer.style.fontFamily = config.getElementsByTagName('loadingmessage')[0].getAttribute('font-family');
	loadingMessageContainer.style.fontWeight = config.getElementsByTagName('loadingmessage')[0].getAttribute('font-weight');
	loadingMessageContainer.style.fontStyle = config.getElementsByTagName('loadingmessage')[0].getAttribute('font-style');
	loadingMessageContainer.style.fontSize = config.getElementsByTagName('loadingmessage')[0].getAttribute('font-size') + 'px';
	loadingMessageContainer.style.color = config.getElementsByTagName('loadingmessage')[0].getAttribute('forecolor');
	loadingMessageContainer.style.lineHeight = loadingMessageHeight + 'px';
	loadingMessageContainer.style.width = loadingMessageWidth + 'px';
	loadingMessageContainer.style.marginLeft = '-' + loadingMessageWidth / '2' + 'px';
	loadingMessageContainer.style.marginTop = '-' + loadingMessageHeight / '2' + 'px';
	loadingMessageContainer.style.backgroundColor = config.getElementsByTagName('loadingmessage')[0].getAttribute('backcolor');
	loadingMessageContainer.style.backgroundImage = 'url(\'' + config.getElementsByTagName("loadingmessage")[0].getAttribute("loadingimage") + '\')';
	document.getElementsByTagName('body')[0].appendChild(writingCredits);
	document.getElementsByTagName('body')[0].appendChild(loadingMessageContainer);
	if(config.getElementsByTagName('modalpanel')[0].getAttribute('modal') != "false")
	{
		document.getElementsByTagName('body')[0].appendChild(modalPane);
		var opacity = config.getElementsByTagName('modalpanel')[0].getAttribute('opacity');
		document.getElementById('LoadingMessageModalPane').className = 'modalPaneTrue';
		document.getElementById('LoadingMessageModalPane').style.filter = 'alpha(opacity=' + opacity + ')';
		document.getElementById('LoadingMessageModalPane').style.opacity = '.' + opacity + '';
	}
}

function displayLoadingPanel()
{
	var registered = true;
	if(!registered)
	{
		if(document.getElementById('credits_' + randomid) != null)
		{
			if(config.getElementsByTagName('modalpanel')[0].getAttribute('modal') != "false")
			{
				document.getElementById('LoadingMessageModalPane').style.display = 'block';
			}
			if(config.getElementsByTagName('loadingmessage')[0].getAttribute('visible') != "false")
			{
				document.getElementById('loadingMessageContainer').style.display = 'block';
			}
			document.getElementById('credits_' + randomid).style.display = 'block';
			//hidePageScrollBars();
		}
		else
		{
			alert('Web 2.0 AJAX Loading ' + Web20AjaxLoadingPanelVersion + ' Panel System Message:\n\nYou are using an illegally modified version of Web 2.0 AJAX Loading Panel. Please, either rollback the changes you\'ve made, or download it again from my website. The script will not start.')
		}
	}
	else
	{
		document.getElementById('credits_' + randomid).style.display = 'none';
		if(config.getElementsByTagName('modalpanel')[0].getAttribute('modal') != "false")
		{
			document.getElementById('LoadingMessageModalPane').style.display = 'block';
		}
		if(config.getElementsByTagName('loadingmessage')[0].getAttribute('visible') != "false")
		{
			document.getElementById('loadingMessageContainer').style.display = 'block';
		}
		// hidePageScrollBars();
	}
}

function hideLoadingPanel()
{
	if(config.getElementsByTagName('modalpanel')[0].getAttribute('modal') != "false")
	{
		document.getElementById('LoadingMessageModalPane').style.display = 'none';
	}
	document.getElementById('loadingMessageContainer').style.display = 'none';
	if(document.getElementById('credits_' + randomid) != null)
	{
		document.getElementById('credits_' + randomid).style.display = 'none';
	}
	showPageScrollBars();
}

function hidePageScrollBars()
{
	//document.documentElement.style.overflowY = 'hidden';
}

function showPageScrollBars()
{
	//document.documentElement.style.overflowY = 'auto';
}

var randomid = Math.floor(Math.random()*100000000000000);