//<![CDATA[
var animationSpeed = 'fast';

var DHTML = (document.getElementById || document.all || document.layers);

function MM_swapImgRestore() { //v3.0
    var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
    var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
        var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
        if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
    var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
        d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
    if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
    for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
    if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
    var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
        if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

// Send request to add edit capacity.
function sendEmail() {
	if(!validationEmail())
		return false;

	var parameters = new Array(
		'tellAboutObituaryEmail1',
		'tellAboutObituaryName1',
		'tellAboutObituaryObituaryId'
	);
	ajaxRequestMethodExtended('showobituary', 'sendEmail', parameters, sendEmailResponse, null, 'tellAboutObituaryBox', 'wysyłanie', 1);
}

// Get response of add edit capacity.
function sendEmailResponse() {
	var response = ajaxResponseMethod(null);
	var message = '';
	// Add success.
	if (response == 1) {
		message = '<font color="#33CC00"><b>Wysłano wiadomość.</b></font>';
		clearSendEmailForm();
	}
	// Add false.
	else if (response == -1) {
		message = '<font color="#CC0000"><b>Nie wysłano wiadomości</b></font>';
	}
	var messageBox = new GetObject('tellAboutObituaryBox');
	if(message!=''){
		messageBox.obj.innerHTML = message;
		messageBox.styl.height = '16px';
	}else{
		messageBox.styl.height = '0px';
	}
}

// Valid form.
// @return Bool True or false dependence on form valid.
function validationEmail() {
	if (!DHTML)
		return;

	var messageBox = new GetObject('tellAboutObituaryBox');
    var count = 0;
    
    messageBox.styl.height = '16px';
    
    var tellAboutObituaryName = null;
    var tellAboutObituaryEmail = null;
    
    for(var i = 1; i < 2; i++){
		tellAboutObituaryName = new GetObject('tellAboutObituaryName'+i);
		tellAboutObituaryEmail = new GetObject('tellAboutObituaryEmail'+i);

		if(validValue(tellAboutObituaryEmail, "isEmpty", messageBox, "test")) {
			// EMAIL
	        if(!validValue(tellAboutObituaryEmail, "isEmpty", messageBox)){
	                tellAboutObituaryEmail.obj.focus();
	                return false;
	        }
	        if(!validValue(tellAboutObituaryEmail, "isString:1:256", messageBox)){
	                tellAboutObituaryEmail.obj.focus();
	                return false;
			}
	        if(!validValue(tellAboutObituaryEmail, "isEmail", messageBox)){
	                tellAboutObituaryEmail.obj.focus();
	                return false;
			}
			// NAME
			if(!validValue(tellAboutObituaryName, "isEmpty", messageBox)){
	                tellAboutObituaryName.obj.focus();
	                return false;
	        }
	        if(!validValue(tellAboutObituaryName, "isString:1:100", messageBox)){
	                tellAboutObituaryName.obj.focus();
	                return false;
			}
			
			count++;
		}
	}
	
            
    if (count == 0) {
		messageBox.obj.innerHTML = '<font color="#AA0000">Brak adresów e-mail!</font>';
		return false;
    }

	messageBox.styl.height = '0px';

	return true;
}

// Valid form.
// @return Bool True or false dependence on form valid.
function clearSendEmailForm() {
	if (!DHTML)
		return;
    
    var tellAboutObituaryName = null;
    var tellAboutObituaryEmail = null;
    
    for(var i = 1; i < 2; i++){
		tellAboutObituaryName = new GetObject('tellAboutObituaryName'+i);
		tellAboutObituaryEmail = new GetObject('tellAboutObituaryEmail'+i);
		tellAboutObituaryName.obj.value = '';
		tellAboutObituaryEmail.obj.value = '';
	}
}


//////////////////////////////////////
//									//
// PAMIĘTAMY						//
// - obsługa dodawania wpisów		//
//									//
//									//
//////////////////////////////////////
function addNewsletter(){
	alert('Błąd! [0x0EF31D93] - Odśwież stronę i spróbuj ponownie.');
}

// Send request to add edit capacity.
function addNewsletterJS() {
	if(!validationNewsletter())
		return false;

	var parameters = new Array('pamietamyName', 'pamietamyEmail', 'pamietamyObituaryId', 'pamietamyPolicyConfirm', 'pamietamySelect', 'antyspam_response_field', 'titleFormField', 'timeFormField', 'mathFormField');
	ajaxRequestMethod('showobituary', 'addNewsletter', parameters, addNewsletterResponse, 'pamietamyButton', 'pamietamyBox');
}

// Get response of add edit capacity.
function addNewsletterResponse() {
	var response = ajaxResponseMethod('pamietamyButton');
	var message = '';
	if(typeof(response) != "undefiend"){
	
		var pamietamyCode = new GetObject('antyspam_response_field');
		pamietamyCode.obj.className= 'css_input_text_normal';
		var pamietamyName = new GetObject('pamietamyName');
		pamietamyName.obj.className= 'css_input_text_normal';
		
	   
		// Add false.
		if (response == -1) {
			message = '<font color="#AA0000"><b>Nie dodano wpisu.</b></font>';
		}
		else if (response == -2) {
			message = '<font color="#AA0000"><b>Musisz zaakceptować regulamin.</b></font>';
		}
		else if (response == -3) {
			message = '<font color="#AA0000"><b>Nie można dodać ponownie autora!</b></font>';
		}
		else if (response == -4) {
			message = '<font color="#AA0000"><b>Podany wpis juz istnieje.</b></font>';
		}
		else if (response == -5) {
			message = '<font color="#AA0000"><b>Inny błąd dodawania wpisu.</b></font>';
		}
		else if (response == -6) {
			message = '<font color="#AA0000"><b>Wpisałeś/wpisałaś zakazane słowo!</b></font>';
			pamietamyName.obj.className= 'css_input_text_error';
		}
		else if (response == -7) {
			message = '<font color="#AA0000"><b>Wpisano błędny wynik działania!</b></font>';
			antyspam.reload();
			pamietamyCode.obj.className= 'css_input_text_error';
		}
		// Add success.
		else if(typeof(response) != "undefined" && response != ''){
			var raArr = response.split(':');
			if(raArr[0] && raArr[1]){ 
				rA = raArr[0];	// ID newslettera
				rB = raArr[1];	// czy dodał bez emaila (0) czy z (1)
				rC = raArr[2];	// czy jest automatyczna akcepacta (1) czy nie (0)
				rD = raArr[3];	// hash
				rE = raArr[4];	// imie i nazwisko właściciela (trzeba unescape())
				rF = raArr[5];	// email dodającego się
				closeDialog();
				if(rB == 0){
					// dodał bez emaila
					if(rC == 1){
						// automatyczna akceptacja
						$('#confirmDiv').html('<div style="text-align: center; line-height: 35px; margin: 30px auto;">Wprowadzone dane zostały wpisane do listy &quot;<em>Pamiętamy...</em>&quot;<br/><br/><input type="button" onclick="closeLayer();" value="Zamknij okno" style="width: 150px;" class="css_input_button" /></div>');
					}else{
						// brak automatycznej akceptacji
						$('#confirmDiv').html('<div style="text-align: center; line-height: 35px; margin: 30px auto;">Twój wpis pojawi się w liście &quot;<em>Pamiętamy...</em>&quot; jak tylko zostanie zaakceptowany przez <b>'+unescape(rE)+'</b><br/><br/><input type="button" onclick="closeLayer();" value="Zamknij okno" style="width: 150px;" class="css_input_button" /></div>');
					}
				}else{
					// dodał z mailem
					
					// pokaż okienko akceptacji
					$('#confirmDiv').html('<input type="hidden" id="pamietamyHash" value="'+unescape(rD)+'"/>'+
					'<div style="text-align: center; line-height: 35px; margin: 30px auto;">'+
					'Aby Twoje dane pojawiły się w liście &quot;<em>Pamiętamy...</em>&quot; konieczne będzie ich zaakceptowanie w mailu, który zostanie wysłany na podany adres:<br/>'+
					'<b>'+unescape(rF)+'</b><br/>'+
					'Sprawdź czy we wprowadzonym adresie nie ma błędów.<br/><br/>'+
					'<input type="button" onclick="acceptNewsletter(1);" value="Akceptuj" id="acptBtn" style="width: 100px;" class="css_input_button" />'+
					'&nbsp;<input type="button" onclick="acceptNewsletter(0);" id="rejBtn" value="Odrzuć" style="width: 100px;" class="css_input_button" />'+
					'</div>');

				}
				message = '';
				if(showNewsletterBox() == true){
					clearNewsletter();
					closeDialog();
				}
			}
		}
	
	}


	var messageBox = new GetObject('pamietamyBox');
	messageBox.obj.innerHTML = message;
}

// Valid form.
// @return Bool True or false dependence on form valid.
function validationNewsletter() {
	if (!DHTML)
		return;

	var messageBox = new GetObject('pamietamyBox');
	var pamietamyName = new GetObject('pamietamyName');
	var pamietamyEmail = new GetObject('pamietamyEmail');
	var pamietamyCode = new GetObject('antyspam_response_field');
	var pamietamySelect = $('#pamietamySelect').val();
	
	if(!validValue(pamietamyName, "isEmpty", messageBox))
		return false;

	if(!validValue(pamietamyName, "isString:1:100", messageBox))
		return false;

	if(pamietamySelect == 1){
	    if(!validValue(pamietamyEmail, "isEmpty", messageBox))
			return false;
		if(!validValue(pamietamyEmail, "isString:1:256", messageBox))
			return false;
		if(!validValue(pamietamyEmail, "isEmail", messageBox))
			return false;
	}	
		
	var pamietamyPolicyConfirm = new GetObject('pamietamyPolicyConfirm');
	if(pamietamyPolicyConfirm.obj.value == 0){
		messageBox.obj.innerHTML = '<font color="#AA0000"><b>Musisz zaakceptować regulamin.</b></font>';
		pamietamyPolicyConfirm.obj.focus();
		return false;	
	}

	return true;
}

function clearNewsletter(){
	var pamietamyName = new GetObject('pamietamyName');
	var pamietamyEmail = new GetObject('pamietamyEmail');
	var pamietamyCode = new GetObject('antyspam_response_field');
	var pamietamySelect1 = new GetObject('pamietamySelect_1');
	var pamietamySelect = new GetObject('pamietamySelect');
	var pamietamyPolicyConfirm = new GetObject('pamietamyPolicyConfirm');
	$('#captchaImgMain').attr('src', '/package/captcha/captcha.php'+'?'+Math.random());
	pamietamyName.obj.value = '';
	pamietamyEmail.obj.value = '';
	pamietamyCode.obj.value = '';
	pamietamySelect1.obj.checked = true;
	pamietamySelect.obj.value = 1;
	pamietamyPolicyConfirm.obj.value = 0;
	pamietamyPolicyConfirm.obj.checked = false;
	$('#captchaDiv').hide();
	$('#emailDiv').show();
	$('#pamietamySelect').val('1');
}

function acceptNewsletter(variant){
	var rejBtn = new GetObject('rejBtn');
	var acptBtn = new GetObject('acptBtn');
	acptBtn.obj.disabled=true;
	rejBtn.obj.disabled=true;
	
	var hash = $('#pamietamyHash').val();
	var ajaxUrl = 'acceptSelect='+variant+'&pamietamyHash='+hash;
	ajaxRequestMethodSimple('showobituary', 'acceptNewsletter', ajaxUrl, acceptNewsletterResponse, null, 'pamietamyBox');
}

function acceptNewsletterResponse(){
	var response = ajaxResponseMethod(null);
	
	if(typeof(response) != "undefined"){
		if(response == 1){
			$('#confirmDiv').html('<div style="text-align: center; line-height: 35px; margin: 30px auto;">Odświeżanie widoku...<br/><img src="/gfx/ajax_loader_whitebg.gif" alt="czekaj..."/></div>');
			setTimeout('window.location.reload()', 100);
		}else if(response == -1){
			$('#confirmDiv').html('<div style="text-align: center; line-height: 35px; margin: 30px auto; color: #CC0000;">Błąd kodu sprawdzającego.<br/><input type="button" onclick="closeLayer();" value="Zamknij okno" style="width: 150px;" class="css_input_button" /></div>');
		}else if(response == -2){
			$('#confirmDiv').html('<div style="text-align: center; line-height: 35px; margin: 30px auto; color: #CC0000;">Błąd pobierania danych.<br/><input type="button" onclick="closeLayer();" value="Zamknij okno" style="width: 150px;" class="css_input_button" /></div>');
		}
	}
	
	var messageBox = new GetObject('pamietamyBox');
	messageBox.obj.innerHTML = '';
}


function showRemembers(){
	$('#pamietamyOver').fadeOut(animationSpeed, function(){$('#pamietamyForm').fadeIn(animationSpeed);});
}
function hideRemembers(){
	$('#pamietamyForm').fadeOut(animationSpeed, function(){$('#pamietamyOver').fadeIn(animationSpeed);});
	clearNewsletter();
}
function changePamietamyState(that){
	if(that.checked && that.value == 1){
		$('#emailDiv').show();
		$('#captchaDiv').hide();
		$('#pamietamySelect').val('1');
	}else if(that.checked && that.value == 0){
		$('#emailDiv').hide();
		$('#captchaDiv').show();
		$('#pamietamySelect').val('0');
	}
}

function showNewsletterBox(){
	return expandConfirmBox(2);
}




function expandConfirmBox(setler, elem, checkHeight){
	if(typeof(elem) == "undefined") elem = 'confirmDiv';
	if(typeof(checkHeight) == "undefined") checkHeight = true;
	var disablepageLay = new GetObject('disablepageLay');
	var pageSize = getPageSize();
	disablepageLay.obj.onclick = function(){};
	disablepageLay.obj.onkeydown = function(){};
	disablepageLay.styl.display = 'block';
//	disablepageLay.styl.height = pageSize[1]+'px';
//	disablepageLay.styl.width = pageSize[0]+'px';
	
	$('#disablepageLay').height($(document).height()).width($(document).width());
	$(window).resize(function(){$('#disablepageLay').height($(document).height()).width($(document).width());});
	
	if(setler>=1){
		displayConfirmDiv(elem, checkHeight);
		if(setler==1){
			disableAllElements(elem);
		}
	}
	
	return true;
}

function displayConfirmDiv(elem, checkHeight){
	if(typeof(elem) == "undefined") elem = 'confirmDiv';
	var confirmDiv = new GetObject(elem);
	var tmpH = 300;
	var tmpW = 500;
	var _sn = 0;
	tmpH = $('#'+elem).height()+_sn;
	tmpW = $('#'+elem).width();
	
	if(tmpH >= 500 && checkHeight === true){
		$('#'+elem).css({
			'position': 'fixed',
			'height': '500px',
			'overflow': 'auto',
			'width': tmpW+'px'
		});
	}else{
		$('#'+elem).css({
			'position': 'fixed',
			'height': 'auto',
			'overflow': 'auto',
			'width': tmpW+'px'
		});
	}
	
	var pageSize = getPageSize();
	var placeX = Math.round((pageSize[2] - tmpW)/2);
	var placeY = Math.round((pageSize[3] - tmpH)/2);
	
	// w przypadku gdy mamy niska rozdzielczosc a duze okienko
	// jak np w dodawniu kondolencji to placeY wychodzi ujemne
	// wiec okienko spieprza do gory za bardzo
	
	if( $('#'+elem).outerHeight(true)+_sn > $(window).height() ){
		var _d = ( $('#'+elem).outerHeight(true)+_sn - $(window).height() );
		$('#'+elem).css({
			'overflow' : 'auto'
		}).height( ( $(window).height() - 35 -_sn) );
		placeY = 0;
	}
	placeY = parseInt( ($(window).height() - $('#'+elem).outerHeight(true)+_sn) / 2 );
	if (placeY < 0) { 
		placeY = 0;
	}
	
	$('#'+elem).css({
		'top': placeY+'px',
		'left': placeX+'px'
	}).fadeIn(animationSpeed);
	
	$(window).resize(function(){
		var pageSize = getPageSize();
		var placeX = Math.round((pageSize[2] - tmpW)/2);
		var placeY = Math.round((pageSize[3] - tmpH)/2);
		if (placeY < 0) { 
			placeY = 0;
		}
		if( $('#'+elem).outerHeight(true) > $(window).height() ){
			var _d = ( $('#'+elem).outerHeight(true) - $(window).height() );
			$('#'+elem).css({
				'overflow' : 'auto'
			}).height( ( $(window).height() - 35 ) );
			placeY = 0;
		}
//		if(($('#'+elem).offset().top + $('#'+elem).outerHeight(true)) > $(window).height()){
//			placeY = parseInt( ( ( ($('#'+elem).offset().top + $('#'+elem).outerHeight(true)) - $(window).height() + 35 ) / 2 ) );
//			placeY = parseInt( $('#'+elem).offset().top / 2 );
//		}
		placeY = parseInt( ($(window).height() - $('#'+elem).outerHeight(true)) / 2 );
		if (placeY < 0) { 
			placeY = 0;
		}
		$('#'+elem).css({
			'top': placeY+'px',
			'left': placeX+'px'
		});
	});
	
}

function centerElement(elem, checkHeight){
	if(typeof(elem) == "undefined") elem = 'confirmDiv';
	var confirmDiv = new GetObject(elem);
	var tmpH = 300;
	var tmpW = 500;
	tmpH = $('#'+elem).height()+79;
	tmpW = $('#'+elem).width();
	
	if(tmpH >= 500 && checkHeight === true){
		$('#'+elem).css({
			'position': 'absolute',
			'height': '500px',
			'overflow': 'auto',
			'width': tmpW+'px'
		});
	}else{
		$('#'+elem).css({
			'position': 'absolute',
			'height': 'auto',
			'overflow': 'auto',
			'width': tmpW+'px'
		});
	}
	
	var pageSize = getPageSize();
	var placeX = Math.round((pageSize[2] - tmpW)/2);
	var placeY = Math.round((pageSize[3] - tmpH)/2);
	
	$('#'+elem).css({
		'top': placeY+'px',
		'left': placeX+'px'
	}).fadeIn(animationSpeed);
	
}

function closeLayer(elem){
	if(typeof(elem) == "undefined") elem = 'confirmDiv';
	$('#'+elem).fadeOut(animationSpeed, function(){$('#disablepageLay').fadeOut(animationSpeed, function(){$('select, object').show();});});
	
}


function disableAllElements(elem){
	
//	if(elem){
//		$('body').children('table:first').find('a,input,textarea,select,button').focus(function(){
//			$(this).blur();
//		});
//		return;
//	}else{
		
		var objBody = document.getElementsByTagName("body").item(0);
		var bodyChilds = objBody.childNodes;
		var inputFields = document.getElementsByTagName('input');
		var aObj = document.getElementsByTagName('a');
		for(var i=0; i<bodyChilds.length;i++){
			if(typeof bodyChilds[i] != 'undefiend'){
				bodyChilds[i].onkeydown = function(){return false;};
				bodyChilds[i].onclick = function(){return false;};
				bodyChilds[i].onfocus = function(){this.blur();return false;};
			}
		}
		for(var j=0; j<inputFields.length;j++){
			if(typeof inputFields[j] != 'undefiend'){
				if(	inputFields[j].name == "confirmPolicy" || inputFields[j].name == "agreePolicy" || inputFields[j].name == "disagreePolicy"){// || inputFields[j].id == "kupamieciReturn" || inputFields[j].id == "formLoginBox" || inputFields[j].id == "formPasswordBox" || inputFields[j].name == "przycisk"){
					continue;
				}else{
					inputFields[j].onkeydown = function(){return false;};
					inputFields[j].onclick = function(){return false;};
					inputFields[j].onfocus = function(){this.blur();return false;};
					inputFields[j].readOnly = true;
					inputFields[j].disabled = true;
				}
			}
		}
		for(var k=0; k<aObj.length;k++){
			if(typeof aObj[k] != 'undefiend'){
				if(	aObj[k].id == "continueLink" || aObj[k].id == "homeLink" || aObj[k].id == "policyLink" || aObj[k].id == "moreEmailsLink"){
					continue;
				}else{
					aObj[k].onkeydown = function(){return false;};
					aObj[k].onclick = function(){return false;};
					aObj[k].onfocus = function(){this.blur();return false;};
				}
			}
		}
//	}
}

function checkBox(ident){
	var imgObj = new GetObject(ident);
	var fieldObj = new GetObject(ident+'Form');
	var current = imgObj.obj.src;
	if(current.indexOf('gfx/false.gif')!=-1){
		imgObj.obj.src = 'gfx/true.gif?'+Math.random();
		fieldObj.obj.value = '1';
	}else if(current.indexOf('gfx/true.gif')!=-1){
		imgObj.obj.src = 'gfx/false.gif?'+Math.random();
		fieldObj.obj.value = '0';
	}
}

function confirmAR(redlink, checkval){
	var confirmPolicyForm = new GetObject('confirmPolicyForm');
	if(confirmPolicyForm.obj.value == 0 && checkval == 1){
		alert('Musisz wpierw potwierdzić przeczytanie regulaminu.');
	}else{
		window.location = redlink;
	}
}

function closeShowObituary(redlink){
	//window.location=redlink;
	closeLayer();
}
function closeMessage(obiID, md5){
	var md5_str = md5 || '';
	if(document.getElementById('formCheckboxDoNotShow').checked == true){
		setCookie('_kupamiec_pl_note_'+obiID+(md5_str != '' ? '_md5_'+md5_str : ''), 5, 365);
	}
	closeLayer();
}
function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString()) + "; path=/; domain=kupamieci.pl";
}
/////////
// GET PAGE SIZE IN PIXELS
////////
function getPageSize(){
	
	var xScroll, yScroll;
		
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = window.innerWidth + window.scrollMaxX;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		
		var windowWidth, windowHeight;
		
		if (self.innerHeight) {	// all except Explorer
			if(document.documentElement.clientWidth){
				windowWidth = document.documentElement.clientWidth; 
			} else {
				windowWidth = self.innerWidth;
			}
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	
		
		// for small pages with total height less then height of the viewport
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else { 
			pageHeight = yScroll;
		}
	
		// for small pages with total width less then width of the viewport
		if(xScroll < windowWidth){	
			pageWidth = xScroll;		
		} else {
			pageWidth = windowWidth;
		}

		//return [pageWidth,pageHeight];

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}

function addFavorites(page_url, page_title){
	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(page_title, page_url,"");
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite( page_url, page_title); }
	else if(window.opera && window.print) { // Opera Hotlist
		alert('Dodawanie do zakładek w przeglądarce Opera nie jest aktualnie wspierane. Wciśnij CTRL+D aby dodać ręcznie.');
	}
}



/**
 *
 * FlowPlayer Functions
 *
 **/
function fpStopOthers(that){
	$f("*").each(function() {
		if(that.id() != this.id())
			$f(this.id()).pause();
	});
}

function initRemembers(maxHeight){
	var curHeight = 0;
	$('#pamietamyList').children('.remembersElement').each(function(){
		curHeight += $(this).height() + ($.browser.msie && ( $.browser.version == '7.0' )  ? 2 : 0);
		if(curHeight > maxHeight){
			$(this).remove();
		}
	});
}

/**
 *
 * Windows funcitons
 *
 **/
function initDialog(innerText, elem, action, close_func){
	if(typeof(innerText) == "undefined") innerText = '';
	if(typeof(elem) == "undefined") elem = 'dialogDiv';
	if(typeof(action) == "undefined") action = 'show';
	if(typeof(close_func) == "undefined") close_func = 'dialogCloseFunction();';
	
	if(action == 'hide'){
		$('#'+elem).fadeOut(animationSpeed, function(){$(this).hide();$(this).html();});
		closeLayer(elem);
		//$('#'+elem).html();
		return true;
	}
	if(action == 'collapse'){
		$('#'+elem).css('height', 'auto').children('div:not(.dialogDivMessage)').hide();
		return true;
	}
	
	if($('#'+elem).length > 0){
		var dialog = $('#'+elem);
	}else{
		$(document.createElement("div")).attr("id",elem).prependTo("body"); 
		var dialog = $('#'+elem);
	}
	
	if($('#dialogDivButton').length > 0){
		var dialogButton = $('#dialogDivButton');
	}else{
		$(document.createElement("div")).attr("id",'dialogDivButton').prependTo("body"); 
		var dialogButton = $('#dialogDivButton');
	}

	$('select, object').hide();
	
	var bodyBorderColor = $("body").css("backgroundColor");
	
	dialog.html(innerText).css({
		width: '650px', height: 'auto', borderColor: bodyBorderColor
	});
	
	dialogButton.prependTo(dialog).show().html('X').css({ 'borderColor' : bodyBorderColor, 'color' : bodyBorderColor }).click(function(){eval(close_func);});
	
	expandConfirmBox(2, 'dialogDiv', false);
	
	window.scrollTo(0,0);
}
function closeDialog(){
	initDialog('', 'dialogDiv', 'hide');
}
 
 
 function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

/**
 * 
 * Obserwowanie nekrologu
 * 
 */
function followObituary(obiId){
	var parameters = 'obituary_id=' + encodeURIComponent(obiId);
	ajaxRequestMethodSimple('showobituary', 'followObituary', parameters, followObituaryResponse, null, null);
}
function followObituaryResponse() {
	var response = ajaxResponseMethod(null);
	if(typeof(response) != "undefined"){
		var oo_follow = $('#oo_follow');
		if(response == 'on'){
			oo_follow.addClass('oo_follow_active');
			oo_follow.attr('title', 'Zakończ obserwowanie tej Strony Pamięci');
			alert('Strona Pamięci została dodana do obserwowanych.');
		}else if(response == 'off'){
			oo_follow.removeClass('oo_follow_active');
			oo_follow.attr('title', 'Obserwuj tę Stronę Pamięci');
			alert('Usunięto Stronę Pamięci z listy obserwowanych.');
		}
	}
}

/**
 * Obituary Options
 */
oo = function () {
	
	var _forward_timer = null;
	var org_backgroundColor = null;
	function forward(){
		if(document.getElementById('tellAboutObituaryName1')){
			clearTimeout(_forward_timer);
			var taon = document.getElementById('tellAboutObituaryName1'); 
			var taoe = document.getElementById('tellAboutObituaryEmail1');
			taon.focus();
			if(org_backgroundColor == null)
				org_backgroundColor = taon.style.backgroundColor
			taon.style.backgroundColor = '#FFFF99';
			taoe.style.backgroundColor = '#FFFF99';
			
			_forward_timer = setTimeout(function(){
				taon.style.backgroundColor = org_backgroundColor;
				taoe.style.backgroundColor = org_backgroundColor;
			}, 3000);
			
		}
		return false;
	}
	
	var isIEmac = false; /*@cc_on @if(@_jscript&&!(@_win32||@_win16)&&(@_jscript_version<5.5)) isIEmac=true; @end @*/
    var isMSIE = (-[1,]) ? false : true;
    var cjTitle = document.title;
    var cjHref = location.href;

    function hotKeys() {
        var ua = navigator.userAgent.toLowerCase();
        var str = '';
        var isWebkit = (ua.indexOf('webkit') != - 1);
        var isMac = (ua.indexOf('mac') != - 1);

        if (ua.indexOf('konqueror') != - 1) {
            str = 'CTRL + B'; // Konqueror
        } else if (window.home || isWebkit || isIEmac || isMac) {
            str = (isMac ? 'Command/Cmd' : 'CTRL') + ' + D'; // Netscape, Safari, iCab, IE5/Mac
        }
        return ((str) ? 'Wciśnij ' + str + ' aby dodać tę stronę do ulubionych.' : str);
    }

    function isIE8() {
        var rv = -1;
        if (navigator.appName == 'Microsoft Internet Explorer') {
            var ua = navigator.userAgent;
            var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
            if (re.exec(ua) != null) {
                rv = parseFloat(RegExp.$1);
            }
        }
        if (rv > - 1) {
            if (rv >= 8.0) {
                return true;
            }
        }
        return false;
    }

    function add_bookmark(a) {
        try {
            if (typeof a == "object" && a.tagName.toLowerCase() == "a") {
                a.style.cursor = 'pointer';
                if ((typeof window.sidebar == "object") && (typeof window.sidebar.addPanel == "function")) {
                    window.sidebar.addPanel(cjTitle, cjHref, ""); // Gecko
                    return false;   
                } else if (isMSIE && typeof window.external == "object") {
                    if (isIE8()) {
                        window.external.AddToFavoritesBar(cjHref, cjTitle); // IE 8                    
                    } else {
                        window.external.AddFavorite(cjHref, cjTitle); // IE <=7
                    }
                    return false;
                } else if (window.opera) {
                    a.href = cjHref;
                    a.title = cjTitle;
                    a.rel = 'sidebar'; // Opera 7+
                    return false;
                } else {
                    alert(hotKeys());
                }
            } else {
                throw "Error occured.\r\nNote, only A tagname is allowed!";
            }
        } catch (err) {
            alert(err);
        }
        return false;
    }
    
    /**
     * Dodawanie znicza
     */
    function add_candle(){
    	try{
    		var obituary_id = document.getElementById('oo_obituary_id').value;
    		var captcha_src = document.getElementById('oo_captcha_src').value;
    		var innerText = '<div class="add_form_outer"><h1 class="t">Zapal znicz</h1><div class="centerBox" style="width: 630px;">'+
                '   <div class="fieldRow">'+
                '   	<div class="fieldTitle">Twoje imię i nazwisko: <span class="redStar">*</span></div>'+
                '   	<div class="fieldValue"><input name="candleNameForm" id="candleNameForm" class="css_input_text_normal" type="text" style="width: 445px;" value="" maxlength="100" /></div>'+
				'	</div>'+
				'   <div class="center"style="clear:both;">'+
                '   	Treść: (max: 200 znaków)'+
				'	</div>'+
                '    <textarea name="candleTextForm" id="candleTextForm" onkeyup="checkTextLength()" cols="24" rows="3" class="css_input_text_normal" style="width: 625px; height: 60px;"></textarea>'+
				'</div>'+
				'<div style="clear: both;"></div>'+
	            antyspam.get_code()+
                '<div class="centerBox" style="width: 630px; padding-top: 15px;">'+
                ' 	<center>'+
                ' 		<span class="redStar">*</span> - pola wymagane<br/><br/>'+
	            '        <input name="candleButtonForm" id="candleButtonForm" class="css_input_button" type="button" style="width: 120px;" value="Zapal znicz" onclick="javascript:addCandleForm()" />'+
	            '        &nbsp;&nbsp;<input class="css_input_button" type="reset" style="width: 150px;" value="Anuluj" onclick="closeDialog();" />'+
	            '       <input type="hidden" id="candleObituaryIdForm" name="candleObituaryIdForm" value="'+obituary_id+'" />'+
				'	</center>'+
                '</div></div><center><div id="candleBoxForm" style="font-weight: bold; padding: 5px 0;" class="dialogDivMessage"></div></center>';
    		initDialog(innerText, 'dialogDiv', 'show', 'closeDialog();');
    	}catch(err){
    		alert(err);
    	}
		return false;
    }
    
    /**
     * Dodawanie kondolencji
     */
    function add_condolence(){
    	try{
    		initDialog('<h1 class="t">Dodaj kondolencję</h1><p>wczytywanie...</p>', 'dialogDiv', 'show', 'closeDialog();');
    		
    		jQuery.post('index.php?do=showobituary&ajax=true&action=getDescribes', {}, function(r){
    			if(r && r. result && r.result == 1 && r.describes && r.describes.length > 0){
    				var innerText_describes = '';
    				for(var i = 0; i<r.describes.length; i++){
    					d = r.describes[i];
    					innerText_describes += '<option value="'+d.id+'">'+d.title+'</option>';
					}
    	    		var obituary_id = document.getElementById('oo_obituary_id').value;
    	    		var captcha_src = document.getElementById('oo_captcha_src').value;
    	    		var innerText = '<div class="add_form_outer"><h1 class="t">Dodaj kondolencję</h1>'+            
    	            		'<div class="centerBox" style="width: 630px;">'+
    	                    '<div class="fieldRow">'+
    	                   	'	<div class="fieldTitle left">'+
    	                   	'		Twoje imię i nazwisko: <span class="redStar">*</span>'+
    	                   	'	</div>'+
    	                   	'	<div class="fieldValue">'+
    			            '        <input name="condolenceName" id="condolenceName" class="css_input_text_normal" type="text" style="width: 440px;" value="" maxlength="100" />'+
    	                   	'	</div>'+
    						'</div>'+
    						'<div class="fieldRow">'+
    	                   	'	<div class="fieldTitle left" style="width: 255px">'+
    			            '        Podaj stopień relacji do osoby zmarłej:'+
    	                   	'	</div>'+
    	                   	'	<div class="fieldValue" style="width: 370px">'+
    			            '        <input name="condolenceRelation" id="condolenceRelation" class="css_input_text_normal" type="text" style="width: 360px;" value="" maxlength="100" />'+
    	                   	'	</div>'+
    						'</div>'+
    						'<div style="clear: both"></div>'+
    						'Podaj treść kondolencji: <span class="redStar">*</span><br />'+
    						'	<select name="formDescribeId" id="formDescribeId" onchange="return changeDescribe(this);" onkeyup="return changeDescribeKey(event, this);" class="css_input_text_normal" style="width: 624px; margin: 3px 0; line-height: 25px; height: 25px;"><option value="0" selected="selected">- własna -</option>';
    	    		innerText += innerText_describes;	
    				innerText += '	</select>'+
    						'	<textarea class="css_input_text_normal" name="condolenceText" id="condolenceText" cols="100" rows="5" style="width: 620px; height: 80px"></textarea>'+
    						'</div>'+
    						'<div style="clear: both"></div>'+
    						'<div class="centerBox">'+
    						'	<div style="width: 620px; margin: 10px auto; text-align: center" id="condolenceGraphics">'+
    						' 		Wybierz grafikę dla Twojej kondolencji:<br/><div id="condolenceGraphicsScroller"><div id="condolenceGraphicsScrollerContainer">';
    				
    				if(_cg && _cg.length > 0){
	    				for(var i = 0; i<_cg.length; i++){
	    					cg = _cg[i];
	    					innerText += '<span class="condolenceGraphic"><img src="'+cg.src+'" id="condolenceGraphicImg_'+cg.id+'" onclick="$(\'#condolenceGraphic_'+cg.id+'\').attr(\'checked\', true);" style="cursor: pointer;" class="zdjecie select" alt="grafika" /><br/><input type="radio" name="condolenceGraphicSelect" id="condolenceGraphic_'+cg.id+'" value="'+cg.id+'"/></span>';
	    				}
    				}
    								
    				innerText += '	<div class="clear"></div></div></div><input type="hidden" id="condolenceGraphic" name="condolenceGraphic" value="0" />'+
    						'	</div>'+
    					 	'</div>'+
    						'<div style="clear: both;"></div>'+
    						antyspam.get_code()+
    		                '<div class="centerBox" style="width: 630px; padding: 5px 0 5px 0;">'+
    		                ' 	<center>'+
    		                '        <input name="condolenceButton" id="condolenceButton" class="css_input_button" type="button" style="width: 160px;" value="Zamieść kondolencje" onclick="javascript:addCondolence()" />'+
    		                '        &nbsp;&nbsp;'+
    		                '        <input class="css_input_button" type="reset" style="width: 160px;" value="Anuluj" onclick="closeDialog();" />'+
    		                '        <input type="hidden" id="condolenceObituaryId" name="condolenceObituaryId" value="'+obituary_id+'" />'+
    		                ' 		<br/>'+
    		                ' 		<br/>'+
    		                ' 		<span class="redStar">*</span> - pola wymagane'+
    		                '    </center>'+
    		                '</div>'+
    		                '<div style="clear: both;"></div></div>'+
    						'<center><div id="condolenceBox" style="font-weight: bold; padding-bottom: 0;" class="dialogDivMessage"></div></center>';
    	    		initDialog(innerText, 'dialogDiv', 'show', 'closeDialog();');
    			}else{
    				initDialog('Błąd pobierania danych.', 'dialogDiv', 'show', 'closeDialog();');
    				setTImeout(function(){closeDialog();}, 2000);
    			}
    		}, "json");
    	}catch(err){
    		alert(err);
    	}
		return false;
    }
    

    
    /**
     * Dodawanie znicza
     */
    function add_friend(){
    	try{
    		var obituary_id = document.getElementById('oo_obituary_id').value;
    		var innerText = '<div class="add_form_outer"><h1 class="t">Pamiętamy... - dodaj się do listy</h1><div class="centerBox" style="width: 630px;">'+
    				'	<div style="text-align:left;padding:0 0 15px 0;">Wpisz poniżej swoje dane, aby dodać się do listy</div>'+
					'	<div class="fieldRow">'+
					'		<div class="fieldTitle left">Twoje imię i nazwisko:</div>'+
					'		<div class="fieldValue" style="text-align:left"><input name="pamietamyName" id="pamietamyName" class="css_input_text_normal" type="text" style="width: 400px; height: 18px; margin: 0; padding: 0 2px;" value="" maxlength="100" /></div>'+
					'	</div>'+
					'<div style="clear: both;"></div>'+
					'	<div style="text-align:left;margin:15px 0 25px 0;padding-left:180px;">'+
					'		<div style="margin:0 0 15px 0;"><input type="radio" name="pamietamySelectRadio" id="pamietamySelect_1" value="1" checked="checked" onclick="changePamietamyState(this);"/><label for="pamietamySelect_1">Udostępniam adres e-mail</label></div>'+
					''+
					'		<div><input type="radio" name="pamietamySelectRadio" id="pamietamySelect_0" value="0" onclick="changePamietamyState(this);"/><label for="pamietamySelect_0">Tylko wpis w "Pamiętamy"</label></div>'+
					'	</div>'+
					'	<div class="fieldRow" id="emailDiv">'+
					'		<div class="fieldTitle left">Twój adres e-mail:</div>'+
					'		<div class="fieldValue" style="text-align:left"><input name="pamietamyEmail" id="pamietamyEmail" class="css_input_text_normal" type="text" style="width: 400px; height: 18px; margin: 0; padding: 0 2px;" value="" maxlength="256" /></div>'+
					'	</div>'+
					'<div style="clear: both;"></div>'+
					antyspam.get_code()+
					'	<div class="policy_info" style="margin:35px 0 5px 0;">'+
					'		<input type="checkbox" name="pamietamyPolicyConfirm" id="pamietamyPolicyConfirm" value="0" onchange="this.value = (this.value == 0 ? 1 : 0);" /><label for="newsletterPolicyConfirm" class="opis-1">Przeczytałem i akceptuję <a href="javascript: return false;" onclick="window.open(\'/rules.php5\', \'_blank\', \'width=600,height=480,scrollbars=yes\');" class="opis-2" style="text-decoration: underline">Regulamin</a> serwisu KuPamieci.pl</label>'+
					'	</div>'+
					'<div style="clear: both;"></div>'+
					''+	
					'	<div class="buttons" style="margin:0 0 15px 0;">'+
					'		<input name="pamietamyButton" id="pamietamyButton" class="css_input_button" type="button" style="width: 70px;" value="Dodaj" onclick="addNewsletterJS()" />'+
					'		<input class="css_input_button" type="reset" style="width: 70px;" value="Anuluj" onclick="closeDialog();" />'+
					'	</div>'+
					'<div style="clear: both;"></div>'+
					'	<div id="pamietamyBox"></div>'+
					''+	
					'	<input type="hidden" id="pamietamySelect" name="pamietamySelect" value="1" />'+
					'	<input type="hidden" id="pamietamyObituaryId" name="pamietamyObituaryId" value="'+obituary_id+'" />'+
					'</div>';                                        
    		initDialog(innerText, 'dialogDiv', 'show', 'closeDialog();');
    	}catch(err){
    		alert(err);
    	}
		return false;
    }
	
	return {
		forward : forward,
		bookmark : add_bookmark,
		addcandle : add_candle,
		addcondolence : add_condolence,
		addfriend : add_friend
	}
}();


/**
 * 
 * ZAPALANIE ZNICZY
 * 
 * {
 * 
 */
	var isCandleForm = 0;
	// Send request to add edit capacity.
	function addCandleForm() {
		if(!validationForm())
			return false;
	
		var parameters = new Array('candleObituaryIdForm', 'candleNameForm', 'candleTextForm', 'antyspam_response_field', 'titleFormField', 'timeFormField', 'mathFormField');
		ajaxRequestMethod('obituarycandle', 'addCandleForm', parameters, addCandleFormResponse, 'candleButtonForm', 'candleBoxForm');
	}
	// Get response of add edit capacity.
	function addCandleFormResponse() {
		var response = ajaxResponseMethod('candleButtonForm');
		var message = '';
		var candleCode = new GetObject('antyspam_response_field');
		candleCode.obj.className = "css_input_text_normal";
	
		var thankBox = new GetObject('thankBoxCandle');
		if(thankBox.obj == null)
			var thankText = 'Zapalono znicz.';
		else
			var thankText = thankBox.obj.innerHTML;
	
		if(typeof(response) != "undefined"){
			var resp = evalJSON(response);
			//resp = response.evalJSON(true);
		
			// Add success.
		    if (resp.result > 0) {
		        message = '<font color="#33CC00">'+thankText+'</font><br/><br/><input class="css_input_button" type="reset" style="width: 150px;" value="Zamknij okno" onclick="showCandleForm();" />';
		        
		        if(thankText == 'Zapalono znicz.'){
		        	// set candle on fire...
		        	
		        	// check candle caount
		        	if(resp.count < 9){
		        		if($('#candle-banner-cell') && $('#candle-banner-cell').length > 0){
			        		// now set it on fire..
			        		$('#candle-banner-cell').css(
			        			{
			        				'backgroundImage' : 'url('+resp.newsrc+'?'+(Math.random()*Math.random())+')'
			        			}
			        		);
			        		
			        		$('#candle-banner').append( 
								'<div onmouseover="pokazZnicz('+resp.count+');" onmouseout="anulujPokazywanie();" id="burning_canlde_'+resp.count+'" class="candle-hover" style="display: none; left: '+resp.position.x+'px; top: '+resp.position.y+'px; width: '+resp.position.width+'px; height: '+resp.position.height+'px; background-image: url(\''+resp.burning+'\');">'+
									'<div class="inner" style="width: '+(resp.position.width-2)+'px; height: '+(resp.position.height-2)+'px;"></div>'+
								'</div>');
							$('#burning_canlde_'+resp.count).fadeIn(300);
							
							// przejść przez wszystkie i zaktualizować grafiki
							if(resp.count > 1){
								$('.candle-hover').each(
									function(index, item){
										$(item).css({
											'backgroundImage' : (index < 5 ? 'url(\'/gfx/candles/'+resp.count+'/'+resp.count+'z'+(index+1)+'.gif\')' : 'url(\'/gfx/candles/'+resp.count+'/'+resp.count+'z'+(index+1)+'sz'+(parseInt(resp.layout)+1)+'.gif\')')
										});
									}
								);
							}
		        		}
		        	}        	
		        	
		        }
		
				// prevent from sending the same candle again
		        clearCandleForm();
				$('#dialogDiv .add_form_outer').hide();
		    }
			// Add false.
			else if (resp.result == 0) {
				message = '<font color="#AA0000">Nie zapalono znicza!</font>';
				antyspam.reload();
			}
			// CAPTCHA false
			else if (resp.result == -1) {
				message = '<font color="#AA0000">Wpisano błędny wynik działania!</font>';
				antyspam.reload();
				candleCode.obj.className= 'css_input_text_error';
			}
			// Forbidden false
			else if (resp.result == -6) {
				message = '<font color="#AA0000">Formularz zawiera zakazana słowo!</font>';
				antyspam.reload();
			}
			
		}
	
		var messageBox = new GetObject('candleBoxForm');
		messageBox.obj.innerHTML = message;
	}
	// Valid form.
	// @return Bool True or false dependence on form valid.
	function validationForm() {
		if (!DHTML)
			return;
		var messageBox = new GetObject('candleBoxForm');
		var candleName = new GetObject('candleNameForm');
		if(!validValue(candleName, "isEmpty", messageBox))
			return false;
		if(!validValue(candleName, "isString:1:250", messageBox))
			return false;
		var candleText = new GetObject('candleTextForm');
		if(!validValue(candleText, "isString:0:200", messageBox))
			return false;
		var candleCode = new GetObject('antyspam_response_field');
		if(!validValue(candleCode, "isEmpty", messageBox, "test")) {
			messageBox.obj.innerHTML = '<font color="#AA0000">Wpisz wynik działania.</font>';
			antyspam.reload();
			candleCode.obj.className = "css_input_text_error";
			return false;
		}else{
			candleCode.obj.className = "css_input_text_normal";
		}
		if(!validValue(candleCode, "isString:1:100", messageBox))
			return false;
	
		return true;
	}
	// Show pages.
	// @param number Page to show.
	function showCandleForm(variant) {
		if (!DHTML)
			return;
	
		if(typeof(variant) == "undefined") variant = 0;
		
	    if (isCandleForm == 0) {
	    	closeDialog();
	        isCandleForm = 1;
	        if($('#boxForm input[name="do"]').val() == 'obituarycandle') window.location.reload();
	        return;
	    }
	    
	    if (isCandleForm == 1) {
	    	closeDialog();
	        isCandleForm = 0;
	        return;
	    }
	}
	// Get response of add edit capacity.
	function checkTextLength() {
		var candleTextForm = new GetObject('candleTextForm');
		var messageBox = new GetObject('candleBoxForm');
	        
	        if (candleTextForm.obj.value.length >= 200) {
	            messageBox.obj.innerHTML = '<font color="#AA0000">Treść znicza nie może przekroczyć 200 znaków!</font>';
	            candleTextForm.obj.value = candleTextForm.obj.value.substr(0, 200);
	        }
	        else {
	            if (messageBox.obj.innerHTML == '<font color="#AA0000">Treść znicza nie może przekroczyć 200 znaków!</font>') {
	                messageBox.obj.innerHTML = '';
	            }
	        }
	}
	// Clear candle form
	function clearCandleForm(){
		var candleName = new GetObject('candleNameForm');
		candleName.obj.value = '';
		var candleText = new GetObject('candleTextForm');
		candleText.obj.value = '';
		var candleCode = new GetObject('antyspam_response_field');
		candleCode.obj.value = '';
		antyspam.reload();
	}
/**
 * }
 */
	
	
	
/**
 * 
 * DODAWANIE KONDOLENCJI
 * 
 * {
 * 
 */
	var isCondolenceForm = 0;
	var tmphtml = '';

	// Show pages.
	// @param number Page to show.
	function showCondolenceForm(variant) {
		if (!DHTML)
			return;
			
		if(typeof(variant) == "undefined") variant = 0;

		// Value of page object.
		var condolenceForm = new GetObject('condolenceForm');
		var condolenceFormFrame = new GetObject('condolenceFormFrame');
	        
        if (isCondolenceForm == 0) {
        	closeDialog();
        	tmphtml = condolenceForm.obj.innerHTML;
        	condolenceForm.obj.innerHTML = '';
            isCondolenceForm = 1;
            return;
        }
        
        if (isCondolenceForm == 1) {
            closeDialog();
            if(variant == 0){
	            //condolenceForm.obj.innerHTML = tmphtml;
	            //tmphtml = '';
	            if($('#boxForm input[name="do"]').val() == 'obituarycondolence') window.location.reload();
            }
            isCondolenceForm = variant;
            return;
        }
	}

	// Send request to add edit capacity.
	function addCondolence() {
		var condolenceGraphic = new GetObject('condolenceGraphic');
		var condolenceGraphichs = document.getElementsByName('condolenceGraphicSelect');
		for (var i=0; i < condolenceGraphichs.length; i++) {
			if (condolenceGraphichs[i].checked) {
				condolenceGraphic.obj.value = condolenceGraphichs[i].value;
		   	}
		}
		
		if(!validationCondolence())
			return false;
		var parameters = new Array('condolenceObituaryId', 'condolenceName', 'condolenceRelation', 'condolenceText', 'condolenceGraphic', 'antyspam_response_field', 'titleFormField', 'timeFormField', 'mathFormField');
		ajaxRequestMethodPost('obituarycondolence', 'addCondolence', parameters, addCondolenceResponse, 'condolenceButton', 'condolenceBox');
	}

	// Get response of add edit capacity.
	function addCondolenceResponse() {
		var response = ajaxResponseMethod('condolenceButton');
		var message = '';
		var candleCode = new GetObject('antyspam_response_field');
		candleCode.obj.className = "css_input_text_normal";

		var thankBox = new GetObject('thankBoxCondolence');
		if(thankBox.obj == null)
			var thankText = 'Dodano kondolencje.';
		else
			var thankText = thankBox.obj.innerHTML;
		thankText += '<br/><br/><input class="css_input_button" type="reset" style="width: 160px;" value="Zamknij okno" onclick="showCondolenceForm();" />';
		
		// Add success.
	    if (response == 1) {
	    	antyspam.reload();
	        $('#dialogDiv .add_form_outer').hide();
	        message = '<font color="#33CC00"><b>'+thankText+'</b></font>';
	    }
		// Add false.
		else if (response == -1) {
			message = '<font color="#AA0000">Wpisano błędny wynik działania!</font>';
			antyspam.reload();
			candleCode.obj.className= 'css_input_text_error';
		}
		// Add false.
		else if (response == -2) {
			message = '<font color="#AA0000">Nie dodano kondolencji!</font>';
			antyspam.reload();
		}
		// Add false.
		else if (response == -6) {
			message = '<font color="#AA0000">Wpisałeś/wpisałaś zakazane słowo do formularza dodawania kondolencji!</font>';
			antyspam.reload();
		}

		var messageBox = new GetObject('condolenceBox');
		messageBox.obj.innerHTML = message;
	}

	// Valid form.
	// @return Bool True or false dependence on form valid.
	function validationCondolence() {
		if (!DHTML)
			return;

		// messageBoxObituary object
		var messageBox = new GetObject('condolenceBox');

		// formName object.
		var formName = new GetObject('condolenceName');

		// Valid formName object.
		if(!validValue(formName, "isEmpty", messageBox))
			return false;

		// Valid formName object.
		if(!validValue(formName, "isString:1:250", messageBox))
			return false;

			// formRelation object.
		var formRelation = new GetObject('condolenceRelation');

		// Valid formRelation object.
		if(validValue(formRelation, "isEmpty", messageBox, "test")) {
			// Valid formRelation object.
			if(!validValue(formRelation, "isString:1:100", messageBox))
				return false;
		}

		// formText object.
		var formText = new GetObject('condolenceText');

		// Valid formText object.
		if(!validValue(formText, "isEmpty", messageBox, "test")) {
			formText.obj.className = "css_input_text_error";
			messageBox.obj.innerHTML = '<font color="#AA0000">Pole z treścią jest puste!</font>';
			return false;
		}else{
			formText.obj.className = "css_input_text_normal";
		}
		
		var condolenceCode = new GetObject('antyspam_response_field');
		
		if(!validValue(condolenceCode, "isEmpty", messageBox, "test")) {
			messageBox.obj.innerHTML = '<font color="#AA0000">Wpisz wynik działania.</font>';
			antyspam.reload();
			condolenceCode.obj.className = "css_input_text_error";
			return false;
		}else{
			condolenceCode.obj.className = "css_input_text_normal";
		}

		// Valid candleName object.
		if(!validValue(condolenceCode, "isString:1:100", messageBox))
			return false;
			
		return true;
	}

	// Clear condolence form
	function clearCondolenceForm(){
		// formName object.
		var formName = new GetObject('condolenceName');
		formName.obj.value = '';

		// formRelation object.
		var formRelation = new GetObject('condolenceRelation');
		formRelation.obj.value = '';

		// formCode object.
		var formCode = new GetObject('antyspam_response_field');
		formCode.obj.value = '';
		antyspam.reload();
		formCode.obj.className = "css_input_text_normal";
		
		var formDescribeId = new GetObject('formDescribeId');
		formDescribeId.obj.value = 0;
		formDescribeId.obj.selectedIndex = 0;
		
		var condolenceGraphic = new GetObject('condolenceGraphic');
		condolenceGraphic.obj.value = 0;
		
		var condolenceGraphicSelect = document.getElementsByName('condolenceGraphicSelect');
		for(var i =0; i<condolenceGraphicSelect.length;i++){
			condolenceGraphicSelect[i].checked = false;
		}

		// formText object.
		var condolenceText = new GetObject('condolenceText');
		condolenceText.obj.value = '';

	}


	function changeDescribe(that){
		if(that.selectedIndex>0){
			var formDescribeId = new GetObject('formDescribeId');
			formDescribeId.obj.value = that.options[that.selectedIndex].value;

			var parameters = new Array('formDescribeId');
			//document.obituary.formDescribe.readOnly = true;
			ajaxRequestMethod('obituarycondolence', 'getDescribe', parameters, changeDescribeResponse, 'condolenceButton', 'condolenceBox');
		}else{
			//document.obituary.formDescribe.readOnly = false;
		}
	}

	function changeDescribeKey(e, that){
		var evt = e || window.event;
		// evt.keyCode
		// PAGE UP -> 33
		// PAGE DOWN -> 34
		// END -> 35
		// HOME -> 36
		// LEFT -> 37
		// UP -> 38
		// RIGHT -> 39
		// DOWN -> 40
		if(
		(
			( evt.keyCode >= 33 && evt.keyCode <= 40 )
			||
			( evt.keyCode >= 49 && evt.keyCode <= 77 )
			||
			( evt.keyCode >= 96 && evt.keyCode <= 110 )
			||
			( evt.keyCode >= 189 && evt.keyCode <= 221 )
		) &&	
			that.selectedIndex>0
		){
			var formDescribeId = new GetObject('formDescribeId');
			formDescribeId.obj.value = that.options[that.selectedIndex].value;

			var parameters = new Array('formDescribeId');
			//document.obituary.formDescribe.readOnly = true;
			ajaxRequestMethod('obituarycondolence', 'getDescribe', parameters, changeDescribeResponse, 'condolenceButton', 'condolenceBox');
		}else{
			//document.obituary.formDescribe.readOnly = false;
		}
	}

	function changeDescribeResponse(){
		var response = ajaxResponseMethod('condolenceButton');
		var message = '';

		// Request faild.
		if (response == -1) {
			message = '<font color="#aa0000">Nie znaleziono opisu!</font>';
		}else if (response == null) {
			
		}else{
			var condolenceText = new GetObject('condolenceText');
//			document.obituary.formDescribe.readOnly = false;
			condolenceText.obj.innerHTML = response;
			condolenceText.obj.value = response;
//			document.obituary.formDescribe.readOnly = true;
			message = '';
		}
		var messageBox = new GetObject('condolenceBox');
		messageBox.obj.innerHTML = message;
	}

/**
 * }
 */


	/**
	 * Boks logowania - ukrywanie okienka logowania
	 */
	var _login_box = (function(){
		var private = {
			_timer : null,
			
			_hide : function(){
				$('#logowanie_box').hide();
				$('#logowanie_box_trigger').css('position', 'relative').fadeIn('fast');
				private._disable_hide();
			},
			_enable_hide : function(){
				$('table.obituary_main').click(function(){
					public.hide(true);
					private._hide();
				});
			},
			_disable_hide : function(){
				$('table.obituary_main').unbind('click');
			}
		};

		var public = {
			show : function(that){
				var $t = $(that);
				$t.parent('div').css('position', 'absolute').hide();
				$('#logowanie_box').fadeIn('fast');
				$('#formLoginBox').focus();		
				private._enable_hide();
				return false;
			},
			hide : function(stop){
				if(typeof stop == "undefined") var stop = false;
				if(stop === true){
					clearTimeout(private._timer);
				}else{
					private._timer = setTimeout(function(){
						private._hide();
					}, 1000);
				}
			}
		}; 
		return public;
	})();
	


/**
 * AntySPAM
 */
var antyspam = (function(){
	var private = {
		ts : 0,
		gen_math : function(){
			var code;
			var t = (String)( (new Date()).getTime() );
			var n1 = parseInt(t.substr( (t.length - 1), 1 ));
			if(n1==0) n1 = 1;
			var n2 = parseInt(t.substr( (t.length - 2), 1 ));
			if(n2==0) n2 = 1;
			if(n2<n1){
				var _t = n2;
				n2 = n1;
				n1 = _t;
			}
			if(n2==n1){
				if(n2 != 9)
					n2 += 1;
				else
					n1 -= 1;
			}
			var _dA = ['+', '-']
			var _d = _dA[( n1 % 2 )];
			
			var _r = 0;
			if(_d == '+') _r = n2+n1;
			else if(_d == '-') _r = n2-n1;
			
			return n2+' '+_d+' '+n1;
		},
		get_math_code : function(){
			$.post('/', {'ajax':true, 'action':'getTS'}, function(data){
				private.ts = data.ts;
				$('#timeFormField').val(data.ts);
			},"json");
			var math_code = private.gen_math();
			var code =
				'   <div class="fieldRow" id="antyspam_math_form">'+
				'		<input type="hidden" name="timeFormField" id="timeFormField" value="'+private.ts+'" />'+
				'		<input type="hidden" name="mathFormField" id="mathFormField" value="'+math_code+'" />'+
	            '   	<div class="fieldTitle">Działanie:&nbsp;&nbsp;</div>'+
	            '   	<div class="fieldValue">'+
	            '			<b>'+math_code+'</b>'+
	            '		</div>'+
	            '		<div style="clear: both;"></div>'+
				'	</div>';
			return code;
		}
	};

	var public = {
		get_code : function(){
			var code = 
				'<div style="text-align:left;" id="antyspam_form">'+
				'	<input type="hidden" name="titleFormField" id="titleFormField" value="" />'+
				private.get_math_code()+
				'   <div class="fieldRow">'+
				'   	<div class="fieldTitle">Wpisz wynik działania: <span class="redStar">*</span></div>'+
				'   	<div class="fieldValue"><input type="text" maxlength="2" id="antyspam_response_field" name="antyspam_response_field" class="css_input_text_normal" style="width:40px" /></div>'+
				'		<div style="clear: both;"></div>'+
				'	</div><div style="clear: both;"></div>'+
				'</div>';
			return code;
		},
		reload : function(){
			$('#antyspam_response_field').val('');
			$('#antyspam_math_form').replaceWith( private.get_math_code() );
		}
	}; 
	return public;
})();
//]]>
