/*
var background = null ;
var backgroundFrame = null ;
*/
var aiClick = false ;
var button = null ;

var agent = navigator.userAgent.toLowerCase () ;
var browser = new BrowserDetectLite() ;

var pngAlpha = ((browser.isIE55 || browser.isIE6up) && browser.isWin32) ;
var pngNormal = ((browser.isGecko) || (browser.isIE5up && browser.isMac) || (browser.isOpera && browser.isWin && browser.versionMajor >= 6) || (browser.isOpera && browser.isUnix && browser.versionMajor >= 6) || (browser.isOpera && browser.isMac && browser.versionMajor >= 5) || (browser.isOmniweb && browser.versionMinor >= 3.1) || (browser.isIcab && browser.versionMinor >= 1.9) || (browser.isWebtv) || (browser.isDreamcast)) ;

var disabledElements = [];

var windowToReparent = null;
var previousParentNode = null;

var isIE = ((agent.indexOf ("msie") != -1) && (agent.indexOf ("opera") == -1) && (agent.indexOf ("safari") == -1)) ;
var isNAV = ((agent.indexOf ("mozilla") != -1) && (agent.indexOf ("netscape") != -1) && (agent.indexOf ("spoofer") == -1) && (agent.indexOf ("compatible") == -1) && (agent.indexOf ("opera") == -1) && (agent.indexOf ("webtv") == -1) && (agent.indexOf ("hotjava") == -1) && (agent.indexOf ("safari") == -1)) ;
var isOPERA = (agent.indexOf ("opera") != -1) ;
var isMOZ = ((agent.indexOf ("mozilla")) != -1 && !isIE && !isNAV && !isOPERA) ;

function ok() {
	hideWin () ;

	aiClick = true ;

	if (button != null) {
		button.click () ;
	}
}

function cancel() {
	hideWin () ;
	return false ;
}

// shows window declared deeper than locker window is
function errorDeepItem(id, source) {
	error(id, source);
	var locker = top.document.getElementById('formLocker');
	if (locker != null) {
		var win = document.getElementById(id);
		//windowToReparent = win;
		document.forms[0].appendChild(win);
	}
}

var onError = new jsEvent();

function error(id, source) {
	//	var bgPath = "img/bkg-error";

	onError.invoke();

	document.onkeydown = catchKey ;

	if (isMOZ || isNAV) {
		document.captureEvents (Event.KEYDOWN) ;
	}

	button = source ;
/*
	if (background == null) {
		background = document.getElementById ("errorBack") ;
		backgroundFrame = background.childNodes [0] ;

		if (isOPERA) {
			background.children(0).style.display = "none" ;
		}
	}
*/
	lockFormComponents();

	if (aiClick) {
		aiClick = false ;
		return true ;
	}
	else {
		win = document.getElementById (id) ;

		style = win.style ;

		/* SETUP WINDOW PROPERTIES */
		var positionTop = (Math.round((document.body.offsetHeight) / 2) - Math.round(win.offsetHeight / 2) + document.body.scrollTop);

		if(positionTop < 0)
		{
			positionTop = 0;
		}

		style.left = (Math.round ((document.body.offsetWidth) / 2) - Math.round (win.offsetWidth / 2) + document.body.scrollLeft) + "px" ;
		style.top = positionTop + "px";

		if (isOPERA) {
			style.left = (Math.round ((document.body.offsetWidth - document.body.scrollLeft) / 2) - Math.round (win.offsetWidth / 2) + document.body.scrollLeft) + "px" ;
		}
		/* SETUP BACKGROUND PROPERTIES */
/*
		background.style.width = (top.document.body.scrollWidth ? top.document.body.scrollWidth : top.document.body.offsetWidth) + "px";//document.body.scrollWidth + "px" ;
		background.style.height = (isIE && (document.body.scrollHeight > 32760)) ? 32760 : (top.document.body.scrollHeight ? top.document.body.scrollHeight : top.document.body.offsetHeight) + "px" ;

		background.className = "errorBack" ;

		if (pngAlpha) {
			background.style.backgroundImage = 'url(' + bgPath + '.png)';
			background.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=70)";
		} else {
			background.style.backgroundImage = 'url(' + bgPath + (pngNormal ? '.png)' : '.gif)');
		}

		background.style.top = 0;
		background.style.left = 0;

		background.style.display = "block" ;
		background.style.visibility = "visible" ;
*/
/*
		if (isOPERA) {
			formElements=document.forms [0].all;
			for (i=0; i < formElements.length; i++) {
				nowElem=formElements[i];
				if (nowElem.disabled=="true" || nowElem.disabled) disabledElements [disabledElements.length] = nowElem;
				if (((nowElem.tagName=="INPUT" && nowElem.type!="hidden") || nowElem.tagName=="SELECT" || nowElem.tagName=="TEXTAREA") && !isWin(nowElem)) nowElem.disabled=true;
			}
		}
*/
		if (typeof (win.onShow) == "function") {
			win.onShow({ "id": id });
		}

		return false ;
	}
}

function isLockerVisible() {
	return top.document.getElementById('formLocker') != null;
}

function unlockFormComponents() {
	var locker = null;

	if (isIE) {
		locker = top.document.getElementById('formLocker')
		if (locker != null) {
			top.document.body.removeChild(locker);
		}
	} else if (isOPERA) {
		locker = window.document.getElementById('formLocker')
		if (locker != null) {
			window.document.body.removeChild(locker);
		}
	} else {
		locker = top.document.getElementById('formLocker')
		if (locker != null) {
			top.document.body.removeChild(locker);
		}
		locker = window.document.getElementById('formLocker')
		if (locker != null) {
			window.document.body.removeChild(locker);
		}
	}
}

function lockFormComponents() {
	if (top.document.getElementById('formLocker') != null) return;

	if (isIE) {
		var objFrame = window.top.document.createElement("iframe");
		objFrame.setAttribute('src', 'javascript:""');
		objFrame.className = "frLookupDialog";

		objFrame.style.width = top.document.body.scrollWidth + 'px';
		objFrame.style.height = (top.document.body.scrollHeight ? top.document.body.scrollHeight : top.document.body.offsetHeight) + 'px';
		objFrame.style.display = "block";
		objFrame.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=70)";

		var objDiv = window.top.document.createElement("div");
		objDiv.setAttribute('id', 'formLocker');

		objDiv.style.position = "absolute";
		objDiv.style.width = top.document.body.clientWidth + 'px';
		objDiv.style.height = (top.document.body.scrollHeight ? top.document.body.scrollHeight : top.document.body.offsetHeight) + 'px';
		objDiv.style.top = '0px';
		objDiv.style.left = '0px';
		objDiv.style.zIndex = 10000;

		objDiv.appendChild(objFrame);
		window.top.document.body.appendChild (objDiv);
	} else if (isOPERA){
		var objLocker = window.document.createElement("img");
		objLocker.className = "lookupDialogPad";
		objLocker.setAttribute('src', "img/bkg-error" + (pngNormal ? '.png' : '.gif'));
		objLocker.setAttribute('id', 'formLocker');

		objLocker.style.width = document.body.scrollWidth + 'px';
		objLocker.style.height = Math.max(document.body.scrollHeight, document.body.offsetHeight) + 'px';
		window.document.body.appendChild (objLocker);
	} else {
		var objFrame = window.top.document.createElement("iframe");
		objFrame.setAttribute('src', 'javascript:""');
		objFrame.className = "frLookupDialog";

		objFrame.style.width = top.document.body.scrollWidth + 'px';
		objFrame.style.height = (top.document.body.scrollHeight ? top.document.body.scrollHeight : top.document.body.offsetHeight) + 'px';
		objFrame.style.display = "block";
		objFrame.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=70)";

		var objDiv = window.top.document.createElement("div");
		objDiv.setAttribute('id', 'formLocker');

		objDiv.style.position = "absolute";
		objDiv.style.width = top.document.body.clientWidth + 'px';
		objDiv.style.height = (top.document.body.scrollHeight ? top.document.body.scrollHeight : top.document.body.offsetHeight) + 'px';
		objDiv.style.top = '0px';
		objDiv.style.left = '0px';
		objDiv.style.zIndex = 10000;

		objDiv.appendChild(objFrame);
		window.top.document.body.appendChild (objDiv);
		
		var objLocker = window.document.createElement("img");
		objLocker.className = "lookupDialogPad";
		objLocker.setAttribute('src', "img/bkg-error" + (pngNormal ? '.png' : '.gif'));
		objLocker.setAttribute('id', 'formLocker');

		//objLocker.style.width = document.body.clientWidth + 'px';
		objLocker.style.width = Math.max(document.body.scrollWidth, document.body.offsetWidth) + 'px';
		objLocker.style.height = Math.max(document.body.scrollHeight, document.body.offsetHeight) + 'px';
		window.document.body.appendChild (objLocker);
	}
}

function disableForm() {
	document.onkeydown = catchKey ;

	if (isMOZ || isNAV) {
		document.captureEvents (Event.KEYDOWN) ;
	}

	lockFormComponents();

	if (aiClick) {
		aiClick = false ;
		return true ;
	}
	else {
		return false ;
	}
}

function hideAjaxWindow(){
	style.left = "-1000px" ;
	style.top = "-1000px" ;
}

function enableForm() {
	unlockFormComponents();

	document.onkeydown = function() {};

	if (isMOZ || isNAV) {
		document.releaseEvents (Event.KEYDOWN) ;
	}
}

function hideWin() {
	if (windowToReparent != null) {
		previousParentNode.appendChild(windowToReparent);
		windowToReparent = null;
	}

	style.left = "-1000px" ;
	style.top = "-1000px" ;
/*
	if (background == null) {
		background = document.getElementById("errorBack") ;
	}

	background.style.display = "none" ;
	background.style.visibility = "hidden" ;
*/
	unlockFormComponents();

	document.onkeydown = function() {} ;

	if (isMOZ || isNAV) {
		document.releaseEvents (Event.KEYDOWN) ;
	}
/*
	if (isOPERA) {
		formElements=document.forms [0].all;
		for (i=0; i < formElements.length; i++) {
			nowElem=formElements[i];
			if (!isWin(nowElem)) nowElem.disabled=false;
		}
	}
*/
}

function isDisabled(_obj){
	for (var i = 0 ; i < disabledElements.length ; i++) {
		if (_obj == disabledElements [i]) {
			return true;
		}
	}
	return false ;
}
/*
function isWin(elem){
	check = false;

	while (elem.parentNode!=null) {
		if (elem.parentNode.className == "errorWin") check = true;
		elem = elem.parentNode;
	}

	return check;
}
*/
function catchKey(e) {
	var keyCode = (isMOZ || isNAV) ? e.which : event.keyCode ;

	if (keyCode == 0) {
		if ((isMOZ || isNAV) && e.cancelable) {
			e.preventDefault ();

			if (!isOPERA) {
				var locker = top.document.getElementById("formLocker");

				if (locker != null) {
					locker.childNodes[0].contentWindow.focus();
				}
			}
		}
		else {
			return false;
		}
	}
	else {
		return true;
	}
}

function checkErrorWindow()
{
	var result = true;

	if (typeof(WindowPopupVisibilityMode) != "undefined")
	{
		if (WindowPopupVisibilityMode != null)
		{
			result = false;
		}
	}

	return result;
}

function BrowserDetectLite(){
	var ua = navigator.userAgent.toLowerCase();
	this.ua = ua;

	this.isSafari = (ua.indexOf('safari') != -1);
	this.isFireFox = (ua.indexOf('firefox') != -1);
	this.isGecko     = (ua.indexOf('gecko') != -1);
	this.isMozilla   = (this.isGecko && ua.indexOf("gecko/") + 14 == ua.length);
	this.isNS        = ( (this.isGecko) ? (ua.indexOf('netscape') != -1) : ( (ua.indexOf('mozilla') != -1) && (ua.indexOf('spoofer') == -1) && (ua.indexOf('compatible') == -1) && (ua.indexOf('opera') == -1) && (ua.indexOf('webtv') == -1) && (ua.indexOf('hotjava') == -1) ) );
	this.isIE        = ( (ua.indexOf("msie") != -1) && (ua.indexOf("opera") == -1) && (ua.indexOf("webtv") == -1) ); 
	this.isOpera     = (ua.indexOf("opera") != -1); 
	this.isKonqueror = (ua.indexOf("konqueror") != -1); 
	this.isAol       = (ua.indexOf("aol") != -1); 
	this.isOmniweb   = (ua.indexOf("omniweb") != -1);
	this.isDreamcast   = (ua.indexOf("dreamcast") != -1);

	this.isIECompatible = ( (ua.indexOf("msie") != -1) && !this.isIE);
	this.isNSCompatible = ( (ua.indexOf("mozilla") != -1) && !this.isNS && !this.isMozilla);

	this.versionMinor = parseFloat(navigator.appVersion); 

	if (this.isNS && this.isGecko) {
		this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('/') + 1 ) );
	}

	else if (this.isIE && this.versionMinor >= 4) {
		this.versionMinor = parseFloat( ua.substring( ua.indexOf('msie ') + 5 ) );
	}

	else if (this.isOpera) {
		if (ua.indexOf('opera/') != -1) {
			this.versionMinor = parseFloat( ua.substring( ua.indexOf('opera/') + 6 ) );
		}
		else {
			this.versionMinor = parseFloat( ua.substring( ua.indexOf('opera ') + 6 ) );
		}
	}

	else if (this.isKonqueror) {
		this.versionMinor = parseFloat( ua.substring( ua.indexOf('konqueror/') + 10 ) );
	}

	this.versionMajor = parseInt(this.versionMinor); 
	this.geckoVersion = ( (this.isGecko) ? ua.substring( (ua.lastIndexOf('gecko/') + 6), (ua.lastIndexOf('gecko/') + 14) ) : -1 );

	this.isWin   = (ua.indexOf('win') != -1);
	this.isWin32 = (this.isWin && ( ua.indexOf('95') != -1 || ua.indexOf('98') != -1 || ua.indexOf('nt') != -1 || ua.indexOf('win32') != -1 || ua.indexOf('32bit') != -1) );
	this.isMac   = (ua.indexOf('mac') != -1);
	this.isUnix  = (ua.indexOf('unix') != -1 || ua.indexOf('linux') != -1 || ua.indexOf('sunos') != -1 || ua.indexOf('bsd') != -1 || ua.indexOf('x11') != -1)

	this.isNS4x = (this.isNS && this.versionMajor == 4);
	this.isNS40x = (this.isNS4x && this.versionMinor < 4.5);
	this.isNS47x = (this.isNS4x && this.versionMinor >= 4.7);
	this.isNS4up = (this.isNS && this.versionMinor >= 4);
	this.isNS6x = (this.isNS && this.versionMajor == 6);
	this.isNS6up = (this.isNS && this.versionMajor >= 6);

	this.isIE4x = (this.isIE && this.versionMajor == 4);
	this.isIE4up = (this.isIE && this.versionMajor >= 4);
	this.isIE5x = (this.isIE && this.versionMajor == 5);
	this.isIE55 = (this.isIE && this.versionMinor == 5.5);
	this.isIE5up = (this.isIE && this.versionMajor >= 5);
	this.isIE6x = (this.isIE && this.versionMajor == 6);
	this.isIE6up = (this.isIE && this.versionMajor >= 6);

	this.isIE4xMac = (this.isIE4x && this.isMac);
}

// Loading panel

var loadingPanelScrollTimeout, loadingPanelSyncLoadTimer;

function showLoadingPanel(divID, imgURL)
{
	disableForm();

	if (typeof(style) != "undefined" && style.left != "-1000px")
	{
		isWindowVisible = true;

		hideAjaxWindow();
	}
	else
	{
		isWindowVisible = false;
	}

	var container = document.getElementById(divID).parentNode;

	if (container != null)
	{
		if (document.getElementById("loadingImg") == null)
		{
			var loadingImg = document.createElement("img");

			container.appendChild(loadingImg);

			loadingImg.id = "loadingImg";
			loadingImg.style.zIndex = "10100"
			loadingImg.style.left = (Math.round ((document.body.offsetWidth) / 2) - Math.round (loadingImg.offsetWidth / 2) + document.body.scrollLeft) + "px" ;
			loadingImg.style.top = (Math.round ((document.body.offsetHeight) / 2) - Math.round (loadingImg.offsetHeight / 2) + document.body.scrollTop) + "px" ;
			loadingImg.src = imgURL;
			loadingImg.style.position = "absolute";

			document.body.onscroll = document.body.onresize = function(){
				if (loadingPanelScrollTimeout) clearTimeout(loadingPanelScrollTimeout)
				loadingPanelScrollTimeout=setTimeout("syncLoadingPanel()",50)
			}

			if (isOPERA) {
				loadingImg.left = (Math.round ((document.body.offsetWidth - document.body.scrollLeft) / 2) - Math.round (loadingImg.offsetWidth / 2) + document.body.scrollLeft) + "px" ;
			}
		}
	}
}

function hideLoadingPanel(popupID) {
	var container = document.getElementById(popupID).parentNode;

	if (container != null) {
		var loadingImg = document.getElementById("loadingImg");

		if (loadingImg != null) {
			loadingImg.parentNode.removeChild(loadingImg);
		}
	}
	
	if (typeof(isWindowVisible) != "undefined" && isWindowVisible == true) {
		error(popupID);
	}
}

function syncLoadingPanel()
{
	var repeat=false, obj;
	var step=10;
	var loadObj = document.getElementById("loadingImg");

	if (loadingPanelSyncLoadTimer) clearTimeout(loadingPanelSyncLoadTimer);

	if (loadObj != null && loadObj.style.visibility != "hidden") obj = loadObj; else return;

	/* Fast position 
	obj.style.top=document.body.scrollTop+document.body.clientHeight/2-obj.offsetHeight/2
	obj.style.left=document.body.clientWidth/2-obj.offsetWidth/2
	*/

	topReq = document.body.scrollTop + document.body.clientHeight / 2 - obj.offsetHeight / 2;
	leftReq = document.body.clientWidth / 2 - obj.offsetWidth / 2;

	if (obj.offsetTop < topReq)
	{
		obj.style.top = obj.offsetTop+step;
		if (obj.offsetTop + step>topReq) obj.style.top=topReq; else repeat=true;
	}

	if (obj.offsetTop > topReq) {
		obj.style.top = obj.offsetTop - step;
		if (obj.offsetTop - step < topReq) obj.style.top = topReq; else repeat = true;
	}

	if (obj.offsetLeft < leftReq) {
		obj.style.left = obj.offsetLeft + step;
		if (obj.offsetLeft + step > leftReq) obj.style.left = leftReq; else repeat = true;
	}
	if (obj.offsetLeft > leftReq) {
		obj.style.left = obj.offsetLeft - step;
		if (obj.offsetLeft - step < leftReq) obj.style.left = leftReq; else repeat = true;
	}

	if (repeat) loadingPanelSyncLoadTimer = setTimeout("syncLoadingPanel()", 0)
}

function setMsgText(ctrlId, text) {
	var ctrl = document.getElementById(ctrlId);
	if (ctrl != null) {
		ctrl.innerHTML = text;
	}
}
//Do not remove this comment
//Do not remove this comment

