var ie = !((document.getElementById && !document.all) || window.opera)
//var ie = (document.all);
var moz = (document.getElementById && !ie);
var msgBox = null;

// preload obrazkow
img = new Image();
img.src = 'images/message/progres_bar.gif';

// wyswietlenie warstwy
function writeMessageBoxHtml() {
	document.write(
	'<div id="MessageBox" onMouseOver="focusMessageBox();" onClick="focusMessageBox();" style="position:absolute; width:100%; top:0px;  margin: 0px; left:0px; z-index: 1000; display:none;">'
	+'	<iframe id="iframek" style="display: none; width: 436px; left:50%; margin-left: -138px; position: absolute; z-index: -1;"></iframe>'
	+'	<table cellspacing="0" cellpadding="0" width="100%" border="0">'
	+'		<tr>'
	+'			<td align="center">'
	+'					<table width="436" cellspacing="0" cellpadding="0" border="0" bgcolor="#ffffff" style="margin-left: 160px; border: solid 1px #974802;">'
	+'						<tr>'
	+'							<td	valign="top">'
	+'								<table width="100%" border="0" cellspacing="0" cellpadding="0" class="prof_dzial">'
	+'									'
	+'									<tr>'
	+'										<td align="left" style="padding-left: 11px; width: 1px;"><img src="../admin/images/message/information.gif" id="msgImage" width="24" height="24" alt="" border="0" /></td>'
	+'										<td class="help_naglowek"><div id="msgTitle"></div></td>'
	+'										<td align="right" style="padding-right: 11px;"><img src="images/message/close.gif" border="0" width="24" height="24" alt="" onclick="hideMessageBox()" style="cursor: pointer;" /></td>'
	+'									</tr>'
	+'								'
	+'								</table>'
	+'								<table cellspacing="1" cellpadding="1" width="100%" border="0" class="helpInfoContent">'
	+'									<tr>'
	+'										'
	+'										<td style="padding: 10px; text-align: justify" valign="top">'
	+'												<div id="msgInfo"></div>'
	+'										</td>'
	+'									</tr>'
	+'								</table>'
	+'							</td>'
	+'						</tr>'
	+'					</table>'
	+'			</td>'
	+'		</tr>'
	+'	</table>'
	+'</div>'
	);
}

// pokaz
function showMessageBox(title, info, image) {
	if (!ie && !moz) return;

	// ustaw parametry tytulu
	_msgTitle = findObj("msgTitle");
	if (title) {
		_msgTitle.innerHTML = title;
		_msgTitle.style.display = "block";
	} else {
		_msgTitle.innerHTML = "";
		_msgTitle.style.display = "none";
	}

	// ustaw parametry dodatkowej informacji
	_msgInfo = findObj("msgInfo");
	if (info) {
		_msgInfo.innerHTML = info;
		_msgInfo.style.display = "block";
	} else {
		_msgInfo.innerHTML = "";
		_msgInfo.style.display = "none";
	}

	// ustaw parametry ikony
	_msgImage = findObj("msgImage");
	if (image) {
		_msgImage.src = "images/message/" + image + ".gif";
		_msgImage.style.display = "block";
	} else {
		_msgImage.src = "images/message/spacer.gif";
		_msgImage.style.display = "none";
	}

	msgBox = findObj("MessageBox").style;
	msgBox.display = "block";
	if (ie) {
		msgBox.top = document.documentElement.clientHeight - findObj("MessageBox").offsetHeight + "px";
	} else if (moz) {
		msgBox.top = window.innerHeight - findObj("MessageBox").offsetHeight + "px";
	}
	moveMessageBox();
	hideMessageBoxSelectField();
}

// w przypadku ie i pokaznego MessageBox'a ukryj pola typu select
function hideMessageBoxSelectField() {
	if (ie && msgBox && msgBox.display == "block") {
		//hideSelectField();
	}
}

// zmien pozycje
function moveMessageBox() {
	if (ie) {
		msgBox.left = document.documentElement.scrollLeft + "px";
		msgBox.top = document.documentElement.scrollTop + document.documentElement.clientHeight - findObj("MessageBox").offsetHeight + "px";
		findObj("iframek").style.display = 'block';
		findObj("iframek").style.height = findObj("MessageBox").offsetHeight;
	} else if (moz) {
		msgBox.top = window.innerHeight + window.pageYOffset - findObj("MessageBox").offsetHeight + "px";
	}
	msgTimeOut = setTimeout("moveMessageBox()", 400);
}

// schowaj
function hideMessageBox() {
	// w przypadku ie pokaz ukryte pola typu select
	//showSelectField(ie);
	if (ie) {
		findObj("iframek").style.display = 'none';
	}
	msgBox.display = "none";
	clearTimeout(msgTimeOut);
}

// ustaw domyslny focus
function focusMessageBox() {
	msg = findObj("MessageBox");
	if (msg && msg.style.display == "block" && findObj("msgDef") != null) {
		findObj("msgDef").focus();
	}
}

// polecenie do wykonania
function returnMessageBox(button) {
	hideMessageBox();
	if (_msgCommand) {
		eval(_msgCommand.replace('msgButton', button));
	}
}

// w przypadku IE ukryj pola typu select
function hideSelectField() {
	if (document.all) {
		var arrSelects = document.getElementsByTagName("select");
		for (var i=0; i<arrSelects.length; i++) { 	
			arrSelects[i].style.visibility = "hidden";
		};
	}
}
writeMessageBoxHtml();
focusMessageBox();

function showHelp(slowo, id_projektu, lang)
{
	showMessageBox('<strong>Pomoc</strong>', '<div style="text-align: center;"><img src="images/message/progres_bar.gif" border="0" alt="" /></div>', 'question');
	
	// inicjalizacja obiektu
	try {
		request = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e1) {
		try {
			request = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e2) {
			request = null;
		}
	}
	if (!request && typeof XMLHttpRequest != "undefined") {
		request = new XMLHttpRequest();
	}
	
	if(request)
	{
		request.onreadystatechange = checkData;
		request.open("GET", baseHref+'getHelp.php?id_slowa='+ slowo +'&id_projektu='+ id_projektu +'&lang='+ lang, true);
		request.send(null);
	}
}

function checkData ()
{
	if (request.readyState == 4) {
		
		_msgInfo = findObj("msgInfo");
		
        if (request.status == 200) {
			info = request.responseText;
			exp = /\n/g;
			_msgInfo.innerHTML = info.replace(exp, '<br>');
			_msgInfo.style.display = "block";
        } else {
            _msgInfo.innerHTML = "Wystapil blad w odczycie danych:\n" + request.statusText;
            _msgInfo.style.display = "block";
        }
    }
}

function showRegisteredInfo(typ, dane, id_projektu, lang)
{
	showMessageBox('<strong>Informacje</strong>', '<div style="text-align: center;"><img src="images/message/progres_bar.gif" border="0" alt="" /></div>', 'question');
	
	// inicjalizacja obiektu
	try {
		request = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e1) {
		try {
			request = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e2) {
			request = null;
		}
	}
	if (!request && typeof XMLHttpRequest != "undefined") {
		request = new XMLHttpRequest();
	}
	
	if(request)
	{
		request.onreadystatechange = checkRegisteredData;
		request.open("GET", baseHref+'getRegisteredInfo.php?typ='+ typ +'&dane='+ dane +'&id_projektu='+ id_projektu +'&lang='+ lang, true);
		request.send(null);
	}
}

function checkRegisteredData ()
{
	if (request.readyState == 4) {
		
		_msgInfo = findObj("msgInfo");
		
        if (request.status == 200) {
			info = request.responseText;
			_msgInfo.innerHTML = info;
			_msgInfo.style.display = "block";
        } else {
            _msgInfo.innerHTML = "Wystapil blad w odczycie danych:\n" + request.statusText;
            _msgInfo.style.display = "block";
        }
    }
}
