var ie = (document.all);
var moz = (document.getElementById && !ie);
var msgBox = null;

// wyswietlenie warstwy

function writeMessageBoxHtml() {
	document.write(
	'<div id="MessageBox" onMouseOver="focusMessageBox();" onClick="focusMessageBox();" style="position:absolute; height:100%; width:97%; top:0px;  margin: 0px; left:0px; z-index: 1000; display:none;">'
	+'	<table height="100%" cellspacing="0" cellpadding="0" width="100%" border="0">'
	+'		<tr>'
	+'			<td align="center">'
	+'				<table width="560" cellspacing="0" cellpadding="0" border="0">'
	+'					<tr>'
	+'						<td width="1" rowspan="4" bgcolor="#4279B5"><img src="images/spacer.gif" width="1" height="1" alt="" border="0"></td>'
	+'						<td height="1" bgcolor="#4279B5"><img src="images/spacer.gif" width="1" height="1" alt="" border="0"></td>'
	+'						<td width="1" rowspan="4" bgcolor="#4279B5"><img src="images/spacer.gif" width="1" height="1" alt="" border="0"></td>'
	+'						<td width="2" rowspan="5" bgcolor="#2165A5" valign="top"><img src="images/message/tlo.gif" width="2" height="2" alt="" border="0"></td>'
	+'					</tr>'
	+'					<tr bgcolor="#F2F3EE">'
	+'						<td	valign="top">'
	+'							<span id="msgCommand" style="display: none;"></span>'
	+'							<table cellspacing="0" cellpadding="0" width="100%" border="0">'
	+'								<tr>'
	+'									<td style="padding-top: 5px" valign="top" width="1"><img src="../admin/images/message/information.gif" id="msgImage" width="60" height="60" alt="" border="0"></td>'
	+'									<td style="padding: 7px;" valign="top">'
	+'										<div id="msgTitle"></div>'
	+'										<div id="msgInfo"></div>'
	+'									</td>'
	+'									<td width="1"><img src="images/spacer.gif" width="1" height="1" alt="" border="0"></td>'
	+'								</tr>'
	+'							</table>'
	+'						</td>'
	+'					</tr>'
	+'					<tr bgcolor="#F2F3EE">'
	+'						<td style="padding: 7px 0px 7px 0px;" valign="top" align="center"><div id="msgButton"></div></td>'
	+'					</tr>'
	+'					<tr>'
	+'						<td height="1" bgcolor="#72746D"><img src="images/spacer.gif" width="1" height="1" alt="" border="0"></td>'
	+'					</tr>'
	+'					<tr>'
	+'						<td height="2" colspan="3" bgcolor="#2165A5"><img src="images/message/tlo.gif" width="2" height="2" alt="" border="0"></td>'
	+'					</tr>'
	+'				</table>'
	+'			</td>'
	+'		</tr>'
	+'	</table>'
	+'</div>'
	);
}

// pokaz
function showMessageBox(title, info, image, type, command) {
	if (!ie && !moz) return;

	// ustaw parametry tytulu
	_msgTitle = findObj("msgTitle");
	if (title) {
		if (info) {
			_msgTitle.innerHTML = title + '<table width="100%" cellspacing="0" cellpadding="0" border="0" style="margin: 7px 0px 5px 0px;"><tr><td background="images/spacer1.gif"><img src="images/spacer.gif" alt="" width="1" height="2" border="0"></td></tr></table>';
		} else {
			_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 = "";
		_msgImage.style.display = "none";
	}

	// ustaw parametry przyciskow
	_msgButton = findObj("msgButton");
	if (type == 'YesNo') {
		//_msgButton.innerHTML = '<input type="submit" id="msgDef" value="<?php echo $_cfg['lang']['msgBox']['tak']; ?>" class="button" style="width: 100px;" onClick="returnMessageBox(\'YES\');">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" value="<?php echo $_cfg['lang']['msgBox']['nie']; ?>" class="button" style="width: 100px;" onClick="returnMessageBox(\'NO\');">';
		_msgButton.innerHTML = '<input type="submit" id="msgDef" value="TAK" class="button" style="width: 100px;" onClick="returnMessageBox(\'YES\');">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" value="NIE" class="button" style="width: 100px;" onClick="returnMessageBox(\'NO\');">';
	} else {
		//_msgButton.innerHTML = '<input type="submit" id="msgDef" value="<?php echo $_cfg['lang']['msgBox']['ok']; ?>" class="button" style="width: 130px;" onClick="returnMessageBox(\'OK\');">';
		_msgButton.innerHTML = '<input type="submit" id="msgDef" value="OK" class="button" style="width: 130px;" onClick="returnMessageBox(\'OK\');">';
	}

	// ustaw parametry polecenia do wykonania
	_msgCommand = findObj("msgCommand").innerHTML;
	if (command) {
		_msgCommand = command;
	} else {
		_msgCommand = "";
	}

	msgBox = findObj("MessageBox").style;
	msgBox.display = "block";
	moveMessageBox();
	hideMessageBoxSelectField();
}

// funkcja wykorzystuje ta sama warstwe co funkcja showMessageBox
// rozni sie ona tym ze do showCustomMessageBox w INFO mozemy wstawic
// cokolwiek (HTML, formularze przyciski itp)
// 
// jezeli chcemy wyswietlic HTML-a nalezy go przed przekazaniem do funkcji zakodowac
// nalezy zamienic nastepujace znaki:
// '<' = '%%'
// '>' = '##'
// '"' = '@@'
function showCustomMessageBox(title, info, html) {
if (!ie && !moz) return;

	// ustaw parametry tytulu
	_msgTitle = findObj("msgTitle");
	if (title) {
		if (info) {
			_msgTitle.innerHTML = title + '<table width="100%" cellspacing="0" cellpadding="0" border="0" style="margin: 7px 0px 5px 0px;"><tr><td background="images/spacer1.gif"><img src="images/spacer.gif" alt="" width="1" height="2" border="0"></td></tr></table>';
		} else {
			_msgTitle.innerHTML = title;
		}
		_msgTitle.style.display = "block";
	} else {
		_msgTitle.innerHTML = "";
		_msgTitle.style.display = "none";
	}
	
	// podmien znaki HTML
	if (html) {
		exp = /%%/g;
		info = info.replace(exp, '<');
		exp = /##/g;
		info = info.replace(exp, '>');
		exp = /@@/g;
		info = info.replace(exp, '"');
	}
	

	// ustaw parametry informacji
	_msgInfo = findObj("msgInfo");
	if (info) {
		_msgInfo.innerHTML = info;
		_msgInfo.style.display = "block";
	} else {
		_msgInfo.innerHTML = "";
		_msgInfo.style.display = "none";
	}
	
	// wyczysc butona jezeli istnieje
	_msgButton = findObj("msgButton");
	_msgButton.innerHTML = '';

	msgBox = findObj("MessageBox").style;
	msgBox.display = "block";
	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.body.scrollLeft + 15 + "px";
		msgBox.top = document.body.scrollTop - 85 + "px";
	} else if (moz) {
		msgBox.top = window.pageYOffset - 85 + "px";
	}
	msgTimeOut = setTimeout("moveMessageBox()", 100);
}

// schowaj
function hideMessageBox() {
	// w przypadku ie pokaz ukryte pola typu select
	showSelectField(ie);

	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));
	}
}

writeMessageBoxHtml();
focusMessageBox();