var ca_quiz_numberOfQuestions = 16;
function ca_quiz_hideAllPages()
{
	for( var i=1; i <= ca_quiz_numberOfQuestions; i++ )
		$('ca-quiz-question' + i).hide();
		
	$('ca-quiz-result-1').className = '';
	$('ca-quiz-result-2').className = '';
	$('ca-quiz-result-3').className = '';
	$('ca-quiz-results-explanation-1').className = '';
	$('ca-quiz-results-explanation-2').className = '';
	$('ca-quiz-results-explanation-3').className = '';
	$('ca-quiz-results').hide();
}

function ca_quiz_progressBar( percent )
{
	$('ca-quiz-gauge-img').style.width = (percent / 100) * 200 + 'px';
	$('ca-quiz-percent').innerHTML = percent + '%';
}

function ca_quiz_pageOpen( page )
{
	ca_quiz_hideAllPages();

	if( page == 'eredmeny' )
	{
		var score = 0;
		for( var i=1; i <= ca_quiz_numberOfQuestions; i++ )
		{
			for( var j = 0; j < $('ca-quiz-question' + i + '-form').length; j++ )
			{
				if( $('ca-quiz-question' + i + '-form')[j].checked )
					score += parseInt($('ca-quiz-question' + i + '-form')[j].value);
			}
		}
		if( score <= 5 )
		{
			$('ca-quiz-result-1').className = 'highlighted';
			$('ca-quiz-results-explanation-1').className = 'highlighted';
		}
		if( score > 5 && score <= 15 )
		{
			$('ca-quiz-result-2').className = 'highlighted';
			$('ca-quiz-results-explanation-2').className = 'highlighted';
		}
		if( score > 15 )
		{
			$('ca-quiz-result-3').className = 'highlighted';
			$('ca-quiz-results-explanation-3').className = 'highlighted';
		}
		$('ca-quiz-results-score').innerHTML = score;
		$('ca-quiz-results').show();
		ca_quiz_progressBar( 100 );
	}
	else
	{
		ca_quiz_progressBar( Math.round( ((page - 1) / ca_quiz_numberOfQuestions) * 100 ) );
		$('ca-quiz-question' + page).show();
	}
}

function ca_quiz_gotoPage( page )
{
	var currentPage = location.hash.replace(/%23/g,'#').split('#')[2];
	if( !currentPage )
		currentPage = 1;

	var checkedNum = 0;

	var back = 0;
	if( page != 'eredmeny' && page < currentPage ) // back button always works
		back = 1;

	for( var i = 0; i < $('ca-quiz-question' + currentPage + '-form').length; i++ )
	{
		if( $('ca-quiz-question' + currentPage + '-form')[i].checked )
			checkedNum++;
	}
	if( currentPage == 7 && checkedNum != 3 && !back )
	{
		alert( 'Válassz 3 lehetőséget!' );
		return;
	}
	if( !checkedNum && !back )
	{
		alert( 'Nem választottál a lehetséges válaszok közül!' );
		return;
	}
	location.hash = 'kviz#' + page;
}

function ca_quiz_reset()
{
	for( var i=1; i <= ca_quiz_numberOfQuestions; i++ )
	{
		for( var j = 0; j < $('ca-quiz-question' + i + '-form').length; j++ )
			$('ca-quiz-question' + i + '-form')[j].checked = false;
	}
	location.hash = 'kviz#1';
}

var ca_login_open = 0;
function ca_login()
{
	if( !ca_login_open )
	{
		new Effect.Appear( 'ca-login-other', { duration: 0.2 } );
		ca_login_open = 1;
		return;
	}

	$('ca-login-loading').show();
	$('ca-login-pass-error').hide();
	$('ca-login-email-error').hide();
    new Ajax.Request( '/ca-ajax/login/login.js.php', {
		method: 'post', parameters:	{
			email: $('ca-login-email').value,
			pass: $('ca-login-pass').value,
			store: ($('ca-login-store').checked ? '1' : '0')
		}
	} );
}

function ca_login_close()
{
	ca_login_open = 0;
	if( $('ca-login-other') )
		new Effect.Fade( 'ca-login-other', { duration: 0.2 } );
}

function ca_logout()
{
	$('ca-logout-loading').show();
    new Ajax.Request( '/ca-ajax/login/logout.js.php', {
		method: 'post', parameters:	{}
	} );
}

function ca_login_lostPassReset()
{
	$('ca-login-lostpass-loading').show();
	$('ca-login-lostpass-error').hide();
    new Ajax.Request( '/ca-ajax/login/lostpass-reset.js.php', {
		method: 'post', parameters:	{
			email: $('ca-login-lostpass-email').value
		}
	} );
}

function ca_login_lostPassResetDone()
{
	$('ca-login-lostpass-reset').hide();
	$('ca-login-lostpass-done').show();
}

function ca_login_lostPassOpen()
{
	$('ca-login-lostpass').show();
	$('ca-login-form').hide();
	$('ca-login-lostpass-reset').show();
	$('ca-login-lostpass-done').hide();
}

function ca_login_lostPassClose()
{
	if( $('ca-login-form') )
	{
		$('ca-login-form').show();
		$('ca-login-lostpass').hide();
	}
}

function ca_signup_pagesClose()
{
	for(var i = 1; $('ca-signup-page-'+i); i++ )
		$('ca-signup-page-'+i).hide();

	ca_signup_hideErrors();
}

function ca_signup_hideErrors()
{
	$('ca-signup-nickerror').hide();
	$('ca-signup-passerror').hide();
	$('ca-signup-emailerror').hide();
	$("ca-signup-error").hide();
}

var ca_signup_pageProgress = [];
ca_signup_pageProgress[1] = 0;
ca_signup_pageProgress[2] = 10;
ca_signup_pageProgress[3] = 20;
ca_signup_pageProgress[4] = 30;
ca_signup_pageProgress[5] = 40;
ca_signup_pageProgress[6] = 50;
ca_signup_pageProgress[7] = 60;
ca_signup_pageProgress[8] = 70;
ca_signup_pageProgress[9] = 70;
ca_signup_pageProgress[10] = 70;
ca_signup_pageProgress[11] = 80;
ca_signup_pageProgress[12] = 90;
ca_signup_pageProgress[13] = 100;
function ca_signup_pageOpen( pageNum )
{
	ca_signup_pagesClose();
	ca_signup_progressBar( ca_signup_pageProgress[pageNum] );
	if( $( 'ca-signup-page-' + pageNum ) )
		$( 'ca-signup-page-' + pageNum ).show();

	if( pageNum == 4 )
		ca_signup_generatePage4();
	if( pageNum == 7 )
		ca_signup_generatePage7();
	if( pageNum == 12 )
		ca_signup_generatePage12();
}

function ca_signup_gotoPage2()
{
	var signupContinue = 0;
	var signupContinueID = '';
	var urlData = location.pathname.split( '/' );
	if( urlData[1] == 'regisztraciofolytatas' )
	{
		signupContinue = 1;
		signupContinueID = urlData[2];
	}

	$('ca-signup-page-1-loading').show();
	ca_signup_hideErrors();

    new Ajax.Request( '/ca-ajax/signup/checkpage1.js.php', {
		method: 'post', parameters:
		{
			email: $('ca-signup-email').value,
			nick: $('ca-signup-nick').value,
			pass1: $('ca-signup-pass1').value,
			pass2: $('ca-signup-pass2').value,
			signupcontinueid: (signupContinue ? signupContinueID : '')
		}
    } );
}

function ca_signup_gotoPage4()
{
	$('ca-signup-firstsmoke-error').hide();
	$('ca-signup-smokingforyears-error').hide();
	var noError = 1;
	if( $('ca-signup-firstsmoke').value == '' || isNaN( $('ca-signup-firstsmoke').value ) )
	{
		$('ca-signup-firstsmoke-error').show();
		$('ca-signup-firstsmoke-error').innerHTML = 'Számot adj meg!';
		noError = 0;
	}
	if( $('ca-signup-smokingforyears').value == '' || isNaN( $('ca-signup-smokingforyears').value ) )
	{
		$('ca-signup-smokingforyears-error').show();
		$('ca-signup-smokingforyears-error').innerHTML = 'Számot adj meg!';
		noError = 0;
	}
	if( noError )
		location.href = '#regisztracio#4';
}

function ca_signup_locationChange()
{
	if( $('ca-signup-location').value == 'capital' )
		$('ca-signup-district-field').show();
	else
		$('ca-signup-district-field').hide();
}

function ca_signup_finish()
{
	var signupContinue = 0;
	var signupContinueID = '';
	var urlData = location.pathname.split( '/' );
	if( urlData[1] == 'regisztraciofolytatas' )
	{
		signupContinue = 1;
		signupContinueID = urlData[2];
	}

	$('ca-signup-loading').show();
	ca_signup_hideErrors();
    new Ajax.Request( '/ca-ajax/signup/signup-finish.js.php', {
		method: 'post', parameters:	{
			email: $('ca-signup-email').value,
			nick: $('ca-signup-nick').value,
			pass1: $('ca-signup-pass1').value,
			pass2: $('ca-signup-pass2').value,
			gender: $('ca-signup-gender').value,
			birthyear: $('ca-signup-birthyear').value,
			location: $('ca-signup-location').value,
			district: $('ca-signup-district').value,
			schooldone: $('ca-signup-schooldone').value,
			work: $('ca-signup-work').value,
			workother: $('ca-signup-work-other').value,
			profeelgood: ($('ca-signup-pro-feelgood').checked ? 'true' : 'false'),
			prorelax: ($('ca-signup-pro-relax').checked ? 'true' : 'false'),
			prolaugh: ($('ca-signup-pro-laugh').checked ? 'true' : 'false'),
			proother1: $('ca-signup-pro-other-1').value,
			proother2: $('ca-signup-pro-other-2').value,
			proother3: $('ca-signup-pro-other-3').value,
			proother4: $('ca-signup-pro-other-4').value,
			proother5: $('ca-signup-pro-other-5').value,
			connointerests: ($('ca-signup-con-nointerests').checked ? 'true' : 'false'),
			consmokingfriends: ($('ca-signup-con-smokingfriends').checked ? 'true' : 'false'),
			conparanoid: ($('ca-signup-con-paranoid').checked ? 'true' : 'false'),
			conother1: $('ca-signup-con-other-1').value,
			conother2: $('ca-signup-con-other-2').value,
			conother3: $('ca-signup-con-other-3').value,
			conother4: $('ca-signup-con-other-4').value,
			conother5: $('ca-signup-con-other-5').value,
			cutpromoreenergy: ($('ca-signup-cutpro-moreenergy').checked ? 'true' : 'false'),
			cutprohealthier: ($('ca-signup-cutpro-healthier').checked ? 'true' : 'false'),
			cutprodoother: ($('ca-signup-cutpro-doother').checked ? 'true' : 'false'),
			cutproother1: $('ca-signup-cutpro-other-1').value,
			cutproother2: $('ca-signup-cutpro-other-2').value,
			cutproother3: $('ca-signup-cutpro-other-3').value,
			cutproother4: $('ca-signup-cutpro-other-4').value,
			cutproother5: $('ca-signup-cutpro-other-5').value,
			cutconsleep: ($('ca-signup-cutcon-sleep').checked ? 'true' : 'false'),
			cutconmissmates: ($('ca-signup-cutcon-missmates').checked ? 'true' : 'false'),
			cutconanxious: ($('ca-signup-cutcon-anxious').checked ? 'true' : 'false'),
			cutconother1: $('ca-signup-cutcon-other-1').value,
			cutconother2: $('ca-signup-cutcon-other-2').value,
			cutconother3: $('ca-signup-cutcon-other-3').value,
			cutconother4: $('ca-signup-cutcon-other-4').value,
			cutconother5: $('ca-signup-cutcon-other-5').value,
			want: $('ca-signup-want').value,
			nomorejointsthan: $('ca-signup-nomorejointsthan').value,
			nosmokemonday: ($('ca-signup-nosmoke-monday').checked ? 'true' : 'false'),
			nosmoketuesday: ($('ca-signup-nosmoke-tuesday').checked ? 'true' : 'false'),
			nosmokewednesday: ($('ca-signup-nosmoke-wednesday').checked ? 'true' : 'false'),
			nosmokethursday: ($('ca-signup-nosmoke-thursday').checked ? 'true' : 'false'),
			nosmokefriday: ($('ca-signup-nosmoke-friday').checked ? 'true' : 'false'),
			nosmokesaturday: ($('ca-signup-nosmoke-saturday').checked ? 'true' : 'false'),
			nosmokesunday: ($('ca-signup-nosmoke-sunday').checked ? 'true' : 'false'),
			firstsmoke: $('ca-signup-firstsmoke').value,
			smokingforyears: $('ca-signup-smokingforyears').value,
			lastmondaysmoke: $('ca-signup-lastmondaysmoke').value,
			lasttuesdaysmoke: $('ca-signup-lasttuesdaysmoke').value,
			lastwednesdaysmoke: $('ca-signup-lastwednesdaysmoke').value,
			lastthursdaysmoke: $('ca-signup-lastthursdaysmoke').value,
			lastfridaysmoke: $('ca-signup-lastfridaysmoke').value,
			lastsaturdaysmoke: $('ca-signup-lastsaturdaysmoke').value,
			lastsundaysmoke: $('ca-signup-lastsundaysmoke').value,
			goals: $('ca-signup-goals').value,
			signupcontinueid: (signupContinue ? signupContinueID : '')
		}
    } );
}

function ca_signup_progressBar( percent )
{
	$('ca-signup-gauge-img').style.width = (percent / 100) * 200 + 'px';
	$('ca-signup-percent').innerHTML = percent + '%';
}

function ca_signup_generatePage4()
{
	var src = '/ca-images/graph-weekgraph/index.php?';
	for( var day = 1; day <= 7; day++ )
	{
		var dayName;
		switch( day )
		{
		case 1: dayName = 'monday'; break;
		case 2: dayName = 'tuesday'; break;
		case 3: dayName = 'wednesday'; break;
		case 4: dayName = 'thursday'; break;
		case 5: dayName = 'friday'; break;
		case 6: dayName = 'saturday'; break;
		case 7: dayName = 'sunday'; break;
		}

		if( day > 1 )
			src += '&';
		src += 'd' + day + 'j=' + $('ca-signup-last' + dayName + 'smoke').value;
	}
	$('ca-signup-lastweekgraph').src = src;
}

function ca_signup_generatePage7()
{
	$('ca-signup-sum-pro').innerHTML = '<ul>';
	if( $('ca-signup-pro-feelgood').checked )
		$('ca-signup-sum-pro').innerHTML += '<li>jó közérzetem lesz tőle</li>';
	if( $('ca-signup-pro-relax').checked )
		$('ca-signup-sum-pro').innerHTML += '<li>megnyugtat</li>';
	if( $('ca-signup-pro-laugh').checked )
		$('ca-signup-sum-pro').innerHTML += '<li>jókat nevetek a haverjaimmal</li>';
	if( $('ca-signup-pro-other-1').value != '' )
		$('ca-signup-sum-pro').innerHTML += '<li>' + $('ca-signup-pro-other-1').value + '</li>';
	if( $('ca-signup-pro-other-2').value != '' )
		$('ca-signup-sum-pro').innerHTML += '<li>' + $('ca-signup-pro-other-2').value + '</li>';
	if( $('ca-signup-pro-other-3').value != '' )
		$('ca-signup-sum-pro').innerHTML += '<li>' + $('ca-signup-pro-other-3').value + '</li>';
	if( $('ca-signup-pro-other-4').value != '' )
		$('ca-signup-sum-pro').innerHTML += '<li>' + $('ca-signup-pro-other-4').value + '</li>';
	if( $('ca-signup-pro-other-5').value != '' )
		$('ca-signup-sum-pro').innerHTML += '<li>' + $('ca-signup-pro-other-5').value + '</li>';
	$('ca-signup-sum-pro').innerHTML += '</ul>';

	$('ca-signup-sum-con').innerHTML = '<ul>';
	if( $('ca-signup-con-nointerests').checked )
		$('ca-signup-sum-con').innerHTML += '<li>nem érdekel semmi más</li>';
	if( $('ca-signup-con-smokingfriends').checked )
		$('ca-signup-sum-con').innerHTML += '<li>csak füves haverjaim vannak</li>';
	if( $('ca-signup-con-paranoid').checked )
		$('ca-signup-sum-con').innerHTML += '<li>néha paranoiás vagyok tőle</li>';
	if( $('ca-signup-con-other-1').value != '' )
		$('ca-signup-sum-con').innerHTML += '<li>' + $('ca-signup-con-other-1').value + '</li>';
	if( $('ca-signup-con-other-2').value != '' )
		$('ca-signup-sum-con').innerHTML += '<li>' + $('ca-signup-con-other-2').value + '</li>';
	if( $('ca-signup-con-other-3').value != '' )
		$('ca-signup-sum-con').innerHTML += '<li>' + $('ca-signup-con-other-3').value + '</li>';
	if( $('ca-signup-con-other-4').value != '' )
		$('ca-signup-sum-con').innerHTML += '<li>' + $('ca-signup-con-other-4').value + '</li>';
	if( $('ca-signup-con-other-5').value != '' )
		$('ca-signup-sum-con').innerHTML += '<li>' + $('ca-signup-con-other-5').value + '</li>';
	$('ca-signup-sum-con').innerHTML += '</ul>';

	$('ca-signup-sum-cutpro').innerHTML = '<ul>';
	if( $('ca-signup-cutpro-moreenergy').checked )
		$('ca-signup-sum-cutpro').innerHTML += '<li>több energiám lesz</li>';
	if( $('ca-signup-cutpro-healthier').checked )
		$('ca-signup-sum-cutpro').innerHTML += '<li>egészségesebbnek fogom érezni magam</li>';
	if( $('ca-signup-cutpro-doother').checked )
		$('ca-signup-sum-cutpro').innerHTML += '<li>más dolgokat is fogok tudni csinálni</li>';
	if( $('ca-signup-cutpro-other-1').value != '' )
		$('ca-signup-sum-cutpro').innerHTML += '<li>' + $('ca-signup-cutpro-other-1').value + '</li>';
	if( $('ca-signup-cutpro-other-2').value != '' )
		$('ca-signup-sum-cutpro').innerHTML += '<li>' + $('ca-signup-cutpro-other-2').value + '</li>';
	if( $('ca-signup-cutpro-other-3').value != '' )
		$('ca-signup-sum-cutpro').innerHTML += '<li>' + $('ca-signup-cutpro-other-3').value + '</li>';
	if( $('ca-signup-cutpro-other-4').value != '' )
		$('ca-signup-sum-cutpro').innerHTML += '<li>' + $('ca-signup-cutpro-other-4').value + '</li>';
	if( $('ca-signup-cutpro-other-5').value != '' )
		$('ca-signup-sum-cutpro').innerHTML += '<li>' + $('ca-signup-cutpro-other-5').value + '</li>';
	$('ca-signup-sum-cutpro').innerHTML += '</ul>';

	$('ca-signup-sum-cutcon').innerHTML = '<ul>';
	if( $('ca-signup-cutcon-sleep').checked )
		$('ca-signup-sum-cutcon').innerHTML += '<li>nem fogok jól aludni</li>';
	if( $('ca-signup-cutcon-missmates').checked )
		$('ca-signup-sum-cutcon').innerHTML += '<li>hiányozni fognak a füves haverjaim</li>';
	if( $('ca-signup-cutcon-anxious').checked )
		$('ca-signup-sum-cutcon').innerHTML += '<li>ideges leszek, ha nem szívhatok</li>';
	if( $('ca-signup-cutcon-other-1').value != '' )
		$('ca-signup-sum-cutcon').innerHTML += '<li>' + $('ca-signup-cutcon-other-1').value + '</li>';
	if( $('ca-signup-cutcon-other-2').value != '' )
		$('ca-signup-sum-cutcon').innerHTML += '<li>' + $('ca-signup-cutcon-other-2').value + '</li>';
	if( $('ca-signup-cutcon-other-3').value != '' )
		$('ca-signup-sum-cutcon').innerHTML += '<li>' + $('ca-signup-cutcon-other-3').value + '</li>';
	if( $('ca-signup-cutcon-other-4').value != '' )
		$('ca-signup-sum-cutcon').innerHTML += '<li>' + $('ca-signup-cutcon-other-4').value + '</li>';
	if( $('ca-signup-cutcon-other-5').value != '' )
		$('ca-signup-sum-cutcon').innerHTML += '<li>' + $('ca-signup-cutcon-other-5').value + '</li>';
	$('ca-signup-sum-cutcon').innerHTML += '</ul>';
}

function ca_signup_generatePage12()
{
	if( $('ca-signup-want').value == 'cut' )
		$('ca-signup-sum-want').innerHTML = 'Csökkenteni szeretnéd az elszívott füves cigik számát és vállalod, ';
	else
		$('ca-signup-sum-want').innerHTML = 'Abba szeretnéd hagyni a füvezést és vállalod, ';

	if( $('ca-signup-nomorejointsthan').value > 0 )
		$('ca-signup-sum-want').innerHTML += 'hogy egyik nap sem szívsz többet ' + $('ca-signup-nomorejointsthan').value + ' füves ciginél.';
	else
		$('ca-signup-sum-want').innerHTML += 'hogy egyik nap sem szívsz füves cigit.';

	var src = '/ca-images/graph-weekgraph/index.php?';
	for( var day = 1; day <= 7; day++ )
	{
		var dayName;
		switch( day )
		{
		case 1: dayName = 'monday'; break;
		case 2: dayName = 'tuesday'; break;
		case 3: dayName = 'wednesday'; break;
		case 4: dayName = 'thursday'; break;
		case 5: dayName = 'friday'; break;
		case 6: dayName = 'saturday'; break;
		case 7: dayName = 'sunday'; break;
		}

		if( day > 1 )
			src += '&';
		src += 'd' + day + 'j=' + $('ca-signup-last' + dayName + 'smoke').value + '&d' + day + 't=' + ( $('ca-signup-nosmoke-' + dayName).checked ? '0' : $('ca-signup-nomorejointsthan').value );
	}
	$('ca-signup-goalgraph').src = src;
}

function ca_signup_abortSave()
{
	$('ca-signup-page-9-loading').show();
	ca_signup_hideErrors();
    new Ajax.Request( '/ca-ajax/signup/signup-abort.js.php', {
		method: 'post', parameters:	{
			email: $('ca-signup-email').value,
			nick: $('ca-signup-nick').value,
			pass1: $('ca-signup-pass1').value,
			pass2: $('ca-signup-pass2').value,
			gender: $('ca-signup-gender').value,
			birthyear: $('ca-signup-birthyear').value,
			location: $('ca-signup-location').value,
			district: $('ca-signup-district').value,
			schooldone: $('ca-signup-schooldone').value,
			work: $('ca-signup-work').value,
			workother: $('ca-signup-work-other').value,
			profeelgood: ($('ca-signup-pro-feelgood').checked ? 'true' : 'false'),
			prorelax: ($('ca-signup-pro-relax').checked ? 'true' : 'false'),
			prolaugh: ($('ca-signup-pro-laugh').checked ? 'true' : 'false'),
			proother1: $('ca-signup-pro-other-1').value,
			proother2: $('ca-signup-pro-other-2').value,
			proother3: $('ca-signup-pro-other-3').value,
			proother4: $('ca-signup-pro-other-4').value,
			proother5: $('ca-signup-pro-other-5').value,
			connointerests: ($('ca-signup-con-nointerests').checked ? 'true' : 'false'),
			consmokingfriends: ($('ca-signup-con-smokingfriends').checked ? 'true' : 'false'),
			conparanoid: ($('ca-signup-con-paranoid').checked ? 'true' : 'false'),
			conother1: $('ca-signup-con-other-1').value,
			conother2: $('ca-signup-con-other-2').value,
			conother3: $('ca-signup-con-other-3').value,
			conother4: $('ca-signup-con-other-4').value,
			conother5: $('ca-signup-con-other-5').value,
			cutpromoreenergy: ($('ca-signup-cutpro-moreenergy').checked ? 'true' : 'false'),
			cutprohealthier: ($('ca-signup-cutpro-healthier').checked ? 'true' : 'false'),
			cutprodoother: ($('ca-signup-cutpro-doother').checked ? 'true' : 'false'),
			cutproother1: $('ca-signup-cutpro-other-1').value,
			cutproother2: $('ca-signup-cutpro-other-2').value,
			cutproother3: $('ca-signup-cutpro-other-3').value,
			cutproother4: $('ca-signup-cutpro-other-4').value,
			cutproother5: $('ca-signup-cutpro-other-5').value,
			cutconsleep: ($('ca-signup-cutcon-sleep').checked ? 'true' : 'false'),
			cutconmissmates: ($('ca-signup-cutcon-missmates').checked ? 'true' : 'false'),
			cutconanxious: ($('ca-signup-cutcon-anxious').checked ? 'true' : 'false'),
			cutconother1: $('ca-signup-cutcon-other-1').value,
			cutconother2: $('ca-signup-cutcon-other-2').value,
			cutconother3: $('ca-signup-cutcon-other-3').value,
			cutconother4: $('ca-signup-cutcon-other-4').value,
			cutconother5: $('ca-signup-cutcon-other-5').value,
			firstsmoke: $('ca-signup-firstsmoke').value,
			smokingforyears: $('ca-signup-smokingforyears').value,
			lastmondaysmoke: $('ca-signup-lastmondaysmoke').value,
			lasttuesdaysmoke: $('ca-signup-lasttuesdaysmoke').value,
			lastwednesdaysmoke: $('ca-signup-lastwednesdaysmoke').value,
			lastthursdaysmoke: $('ca-signup-lastthursdaysmoke').value,
			lastfridaysmoke: $('ca-signup-lastfridaysmoke').value,
			lastsaturdaysmoke: $('ca-signup-lastsaturdaysmoke').value,
			lastsundaysmoke: $('ca-signup-lastsundaysmoke').value
		}
    } );
}

function ca_signup_workChange()
{
	if( $('ca-signup-work').value == 'other' )
		$('ca-signup-work-other').show();
	else
		$('ca-signup-work-other').hide();
}

function ca_signup_gotoPage3()
{
	if( ca_signup_birthYearCheck() )
		return;
	location.href = '#regisztracio#3';
}

function ca_signup_birthYearCheck()
{
	var currentDate = new Date();
	if( currentDate.getFullYear() - $('ca-signup-birthyear').value < 18 )
	{
		alert( 'Az oldalt 18 éven aluliak nem használhatják!' );
		return true;
	}
	return false;
}

function ca_signup_wantChange()
{
	if( $('ca-signup-want').value == 'stop' )
	{
		$('ca-signup-nomorejointsthan').value = 0;
		$('ca-signup-nosmoke-monday').checked = false;
		$('ca-signup-nosmoke-tuesday').checked = false;
		$('ca-signup-nosmoke-wednesday').checked = false;
		$('ca-signup-nosmoke-thursday').checked = false;
		$('ca-signup-nosmoke-friday').checked = false;
		$('ca-signup-nosmoke-saturday').checked = false;
		$('ca-signup-nosmoke-sunday').checked = false;

		$('ca-signup-nomorejointsthan').disabled = true;
		$('ca-signup-nosmoke-monday').disabled = true;
		$('ca-signup-nosmoke-tuesday').disabled = true;
		$('ca-signup-nosmoke-wednesday').disabled = true;
		$('ca-signup-nosmoke-thursday').disabled = true;
		$('ca-signup-nosmoke-friday').disabled = true;
		$('ca-signup-nosmoke-saturday').disabled = true;
		$('ca-signup-nosmoke-sunday').disabled = true;
	}
	else
	{
		$('ca-signup-nomorejointsthan').disabled = false;
		$('ca-signup-nosmoke-monday').disabled = false;
		$('ca-signup-nosmoke-tuesday').disabled = false;
		$('ca-signup-nosmoke-wednesday').disabled = false;
		$('ca-signup-nosmoke-thursday').disabled = false;
		$('ca-signup-nosmoke-friday').disabled = false;
		$('ca-signup-nosmoke-saturday').disabled = false;
		$('ca-signup-nosmoke-sunday').disabled = false;
	}
}

function ca_passmod_changePass()
{
	$('ca-passmod-currpass').disabled = 1;
	$('ca-passmod-newpass1').disabled = 1;
	$('ca-passmod-newpass2').disabled = 1;
	$('ca-passmod-loading').show();
	$('ca-passmod-error').hide();
    new Ajax.Request( '/ca-ajax/login/passmod.js.php', {
		method: 'post', parameters:	{
			currpass: $('ca-passmod-currpass').value,
			newpass1: $('ca-passmod-newpass1').value,
			newpass2: $('ca-passmod-newpass2').value
		}
	} );
}

function ca_about_pagesClose()
{
	var i = 1;
	while( $('ca-about-page-' + i) )
	{
		$('ca-about-page-' + i).hide();
		$('ca-about-menuitem-' + i).className = '';
		i++;
	}
}

function ca_about_pageOpen( pageNum )
{
	if( !pageNum )
		pageNum = 1;
	ca_about_pagesClose();
	if( $( 'ca-about-page-' + pageNum ) )
	{
		$( 'ca-about-page-' + pageNum ).show();
		$('ca-about-menuitem-' + pageNum).className = 'currentpage';
	}
}

function ca_sh_sums_pagesClose()
{
	var i = 1;
	while( $('ca-sh_sums-page-' + i) )
	{
		$('ca-sh_sums-page-' + i).hide();
		$('ca-sh-sums-pagemenu-' + i).className = $( 'ca-sh-sums-pagemenu-' + i ).className.replace( /selected/, '' );
		i++;
	}
}

function ca_sh_sums_pageOpen( pageNum )
{
	if( !pageNum )
		pageNum = 1;
	ca_sh_sums_pagesClose();
	if( $( 'ca-sh_sums-page-' + pageNum ) )
	{
		$( 'ca-sh_sums-page-' + pageNum ).show();
		$( 'ca-sh-sums-pagemenu-' + pageNum ).className = $( 'ca-sh-sums-pagemenu-' + pageNum ).className + 'selected';
	}
}

function ca_sh_sums_weekChange()
{
	if( !$('ca-sh-sums-week').value )
	{
		$("ca-sh-sums-weekgraph-noresults").show();
		return;
	}

	$('ca-sh-sums-week-loading').show();
    new Ajax.Request( '/ca-ajax/selfhelp/sums/weekgraphupdate.js.php', {
		method: 'post', parameters:	{
			week: $('ca-sh-sums-week').value.split('-')[1],
			year: $('ca-sh-sums-week').value.split('-')[0]
		}
	} );
}

var ca_sh_sums_hl_currentpage = 1;
function ca_sh_sums_hl_update()
{
    ca_sh_sums_hl_updatenavbar();

    new Ajax.Request( '/ca-ajax/selfhelp/sums/hl-update.js.php', {
		method: 'post', parameters: {
			page: ca_sh_sums_hl_currentpage,
			orderby: ca_sh_sums_hl_orderBy,
			order: ca_sh_sums_hl_order
		}
    } );
}

function ca_sh_sums_hl_erase()
{
    $('ca-sh-sums-hl-default').style.display = 'block';
    $('ca-sh-sums-hl-table').style.display = 'none';

    while( $('ca-sh-sums-hl-table-tbody').hasChildNodes() )
		$('ca-sh-sums-hl-table-tbody').removeChild( $('ca-sh-sums-hl-table-tbody').firstChild );
}

function ca_sh_sums_hl_additem( index, listindex, craving, amount, place, people, feelings, thoughts, alternative, date )
{
    if( $('ca-sh-sums-hl-default').style.display != 'none' )
    {
		// this workaround is needed because the browser won't automatically apply table style to the newly added rows
		setTimeout( "$('ca-sh-sums-hl-default').style.display = 'none'; $('ca-sh-sums-hl-table').style.display = 'block';", 0 );
    }

    var newRow = document.createElement( 'tr' );
    newRow.id = 'ca-sh-sums-hl-' + index;
    newRow.className = 'ca-sh-sums-hl-entry-' + ($('ca-sh-sums-hl-table-tbody').childNodes.length % 2 ? 'even' : 'odd');
    $('ca-sh-sums-hl-table-tbody').appendChild( newRow );

    var listIndexTD = document.createElement( 'td' );
    listIndexTD.id = newRow.id + '-listindex';
    listIndexTD.innerHTML = listindex;
    newRow.appendChild( listIndexTD );

    var cravingTD = document.createElement( 'td' );
    cravingTD.id = newRow.id + '-craving';
    cravingTD.innerHTML = craving;
    newRow.appendChild( cravingTD );

    var amountTD = document.createElement( 'td' );
    amountTD.id = newRow.id + '-amount';
    amountTD.innerHTML = amount;
    newRow.appendChild( amountTD );

    var placeTD = document.createElement( 'td' );
    placeTD.id = newRow.id + '-place';
    placeTD.innerHTML = place;
    newRow.appendChild( placeTD );

    var peopleTD = document.createElement( 'td' );
    peopleTD.id = newRow.id + '-people';
    peopleTD.innerHTML = people;
    newRow.appendChild( peopleTD );

    var feelingsTD = document.createElement( 'td' );
    feelingsTD.id = newRow.id + '-feelings';
    feelingsTD.innerHTML = feelings;
    newRow.appendChild( feelingsTD );

    var thoughtsTD = document.createElement( 'td' );
    thoughtsTD.id = newRow.id + '-thoughts';
    thoughtsTD.innerHTML = thoughts;
    newRow.appendChild( thoughtsTD );

    var alternativeTD = document.createElement( 'td' );
    alternativeTD.id = newRow.id + '-alternative';
    alternativeTD.innerHTML = alternative;
    newRow.appendChild( alternativeTD );

    var dateTD = document.createElement( 'td' );
    dateTD.id = newRow.id + '-date';
    dateTD.innerHTML = date;
    newRow.appendChild( dateTD );
}

function ca_sh_sums_hl_gotofirstpage()
{
    ca_sh_sums_hl_currentpage = 1;
    ca_sh_sums_hl_update();
}

function ca_sh_sums_hl_gotolastpage()
{
    ca_sh_sums_hl_currentpage = parseInt( $('ca-sh-sums-hl-allpages').innerHTML, 10 );
    ca_sh_sums_hl_update();
}

function ca_sh_sums_hl_decpage()
{
    ca_sh_sums_hl_currentpage--;
    ca_sh_sums_hl_update();
}

function ca_sh_sums_hl_incpage()
{
    ca_sh_sums_hl_currentpage++;
    ca_sh_sums_hl_update();
}

function ca_sh_sums_hl_updatenavbar()
{
    $('ca-sh-sums-hl-incpage-button').disabled = false;
    $('ca-sh-sums-hl-gotolastpage-button').disabled = false;
    $('ca-sh-sums-hl-decpage-button').disabled = false;
    $('ca-sh-sums-hl-gotofirstpage-button').disabled = false;
    if( ca_sh_sums_hl_currentpage >= parseInt($('ca-sh-sums-hl-allpages').innerHTML, 10) )
    {
		ca_sh_sums_hl_currentpage = parseInt($('ca-sh-sums-hl-allpages').innerHTML, 10);
		$('ca-sh-sums-hl-incpage-button').disabled = true;
		$('ca-sh-sums-hl-gotolastpage-button').disabled = true;
		$('ca-sh-sums-hl-decpage-button').disabled = false;
		$('ca-sh-sums-hl-gotofirstpage-button').disabled = false;
    }
    if( ca_sh_sums_hl_currentpage <= 1 )
    {
		ca_sh_sums_hl_currentpage = 1;
		$('ca-sh-sums-hl-incpage-button').disabled = false;
		$('ca-sh-sums-hl-gotolastpage-button').disabled = false;
		$('ca-sh-sums-hl-decpage-button').disabled = true;
		$('ca-sh-sums-hl-gotofirstpage-button').disabled = true;
    }
    if( parseInt($('ca-sh-sums-hl-allpages').innerHTML, 10) == 1 )
    {
		$('ca-sh-sums-hl-incpage-button').disabled = true;
		$('ca-sh-sums-hl-gotolastpage-button').disabled = true;
		$('ca-sh-sums-hl-decpage-button').disabled = true;
		$('ca-sh-sums-hl-gotofirstpage-button').disabled = true;
    }
}

var ca_sh_sums_hl_orderBy = 'date';
var ca_sh_sums_hl_order = 'desc';
function ca_sh_sums_hl_setorderby( fieldname )
{
	if( fieldname == ca_sh_sums_hl_orderBy )
		ca_sh_sums_hl_order = ( ca_sh_sums_hl_order == 'asc' ? 'desc' : 'asc' );

	ca_sh_sums_hl_orderBy = fieldname;
	ca_sh_sums_hl_update();
}

function ca_sh_sums_hl_currentpage_edit()
{
    $('ca-sh-sums-hl-currentpage').innerHTML = '<input id="ca-sh-sums-hl-currentpage-edit" type="text" class="textinput" ' +
		'onkeydown="javascript:if( event.keyCode == 13 ) ca_sh_sums_hl_currentpage_edit_finished( this );" ' +
		'value="' + ca_sh_sums_hl_currentpage + '" />';
    $('ca-sh-sums-hl-currentpage').onclick = '';
    $('ca-sh-sums-hl-currentpage-edit').focus();
}

function ca_sh_sums_hl_currentpage_edit_finished( inputbox )
{
    ca_sh_sums_hl_currentpage = parseInt( inputbox.value, 10 );
    if( !ca_sh_sums_hl_currentpage )
		ca_sh_sums_hl_currentpage = 1;
    $('ca-sh-sums-hl-currentpage').onclick = ca_sh_sums_hl_currentpage_edit;
    ca_sh_sums_hl_update();
}

function ca_sh_continue_pagesClose()
{
	$('ca-sh-continue-sums').hide();
	var pageNum = 1;
	while( $('ca-sh-continue-page-' + pageNum ) )
		$('ca-sh-continue-page-' + pageNum++ ).hide();
}

function ca_sh_continue_pageOpen( pageNum )
{
	ca_sh_continue_pagesClose();
	if( $( 'ca-sh-continue-page-' + pageNum ) )
		$( 'ca-sh-continue-page-' + pageNum ).show();
}

function ca_sh_continue_cancelNewCourse()
{
	$('ca-sh-continue-error').hide();
	$('ca-sh-continue-loading').show();
    new Ajax.Request( '/ca-ajax/selfhelp/continue/cancel.js.php', {
		method: 'post', parameters:	{}
	} );
}

function ca_sh_continue_startNewCourse()
{
	$('ca-sh-continue-error').hide();
	$('ca-sh-continue-loading').show();
    new Ajax.Request( '/ca-ajax/selfhelp/continue/start.js.php', {
		method: 'post', parameters:	{
			want: $('ca-sh-continue-want').value,
			nomorejointsthan: $('ca-sh-continue-nomorejointsthan').value,
			nosmokemonday: ($('ca-sh-continue-nosmoke-monday').checked ? 'true' : 'false'),
			nosmoketuesday: ($('ca-sh-continue-nosmoke-tuesday').checked ? 'true' : 'false'),
			nosmokewednesday: ($('ca-sh-continue-nosmoke-wednesday').checked ? 'true' : 'false'),
			nosmokethursday: ($('ca-sh-continue-nosmoke-thursday').checked ? 'true' : 'false'),
			nosmokefriday: ($('ca-sh-continue-nosmoke-friday').checked ? 'true' : 'false'),
			nosmokesaturday: ($('ca-sh-continue-nosmoke-saturday').checked ? 'true' : 'false'),
			nosmokesunday: ($('ca-sh-continue-nosmoke-sunday').checked ? 'true' : 'false'),
			goals: $('ca-sh-continue-goals').value
		}
	} );
}

function ca_sh_continue_weekChange()
{
	if( !$('ca-sh-continue-week').value )
	{
		$("ca-sh-continue-weekgraph-noresults").show();
		return;
	}

	$('ca-sh-continue-week-loading').show();
    new Ajax.Request( '/ca-ajax/selfhelp/continue/weekgraphupdate.js.php', {
		method: 'post', parameters:	{
			week: $('ca-sh-continue-week').value.split('-')[1],
			year: $('ca-sh-continue-week').value.split('-')[0]
		}
	} );
}

function ca_sh_diary_pagesClose()
{
	var i = 1;
	while( $('ca-sh_diary-page-' + i) )
	{
		$('ca-sh_diary-page-' + i).hide();
		$('ca-sh-diary-pagemenu-' + i).className = $( 'ca-sh-diary-pagemenu-' + i ).className.replace( /selected/, '' );
		i++;
	}
}

function ca_sh_diary_pageOpen( pageNum )
{
	if( !pageNum )
		pageNum = 1;
	ca_sh_diary_pagesClose();
	if( $( 'ca-sh_diary-page-' + pageNum ) )
	{
		$( 'ca-sh_diary-page-' + pageNum ).show();
		$( 'ca-sh-diary-pagemenu-' + pageNum ).className = $( 'ca-sh-diary-pagemenu-' + pageNum ).className + 'selected';
	}
}

var ca_sh_diary_calendar;
function ca_sh_diary_calendar_init()
{
	ca_sh_diary_calendar = new ca_calendar( 'ca-sh-diary-calendar-days' );
	ca_sh_diary_calendar.monthDisplay = 'ca-sh-diary-calendar-month';
	ca_sh_diary_calendar.yearDisplay = 'ca-sh-diary-calendar-year';
	ca_sh_diary_calendar.dayClickedCallBack = 'ca_sh_diary_calendar_dayClickedCallBack';
	ca_sh_diary_calendar.updateCallBack = 'ca_sh_diary_updateCallBack';
	ca_sh_diary_calendar.update();
	ca_sh_diary_calendar_dayClickedCallBack( ca_sh_diary_calendar.selectedDate.getDate() );
}

function ca_sh_diary_calendar_dayClickedCallBack( dayNum )
{
	ca_sh_diary_calendar.dayClicked( dayNum );
	ca_sh_diary_calendar.update();

	location.hash = '#naplo#' + ca_sh_diary_calendar.selectedDate.getFullYear() + '#' + (ca_sh_diary_calendar.selectedDate.getMonth() + 1) + '#' + ca_sh_diary_calendar.selectedDate.getDate();
}

function ca_sh_diary_calendar_dayOpen( year, month, day )
{
	if( $('ca-sh-diary-loading') )
	{
		$('ca-sh-diary-loading').show();
		$('ca-sh-diary-error').hide();
		$('ca-sh-diary-text').disabled = 1;
	}

	month = ( month < 10 ? '0' + month : month );
	day = ( day < 10 ? '0' + day : day );

    new Ajax.Request( '/ca-ajax/selfhelp/diary/load.js.php', {
		method: 'post', parameters:	{
			date: year + '-' + month + '-' + day
		}
    } );
}

function ca_sh_diary_save()
{
	$('ca-sh-diary-loading').show();
	$('ca-sh-diary-error').hide();
	$('ca-sh-diary-text').disabled = 1;

    new Ajax.Request( '/ca-ajax/selfhelp/diary/save.js.php', {
		method: 'post', parameters:	{
			text: $('ca-sh-diary-text').value,
			date: ca_sh_diary_calendar.getSelectedDate(),
			hour: $('ca-sh-diary-hour').value,
			minute: $('ca-sh-diary-minute').value
		}
    } );
}

function ca_sh_diary_updateCallBack()
{
	if( $('ca-sh-diary-loading') )
	{
		$('ca-sh-diary-loading').show();
		$('ca-sh-diary-error').hide();
		$('ca-sh-diary-text').disabled = 1;
	}

    new Ajax.Request( '/ca-ajax/selfhelp/diary/update.js.php', {
		method: 'post', parameters:	{
			year: ca_sh_diary_calendar.displayedDate.getFullYear(),
			month: ca_sh_diary_calendar.displayedDate.getMonth()+1
		}
    } );
}

function ca_sh_diary_addDayEntry( date, text )
{
	var table = document.createElement( 'table' );
	var tr = document.createElement( 'tr' );
	var td = document.createElement( 'td' );
	td.innerHTML = date;
	td.className = 'ca-sh-diary-entrydate';
	tr.appendChild( td );
	table.appendChild( tr );
	tr = document.createElement( 'tr' );
	td = document.createElement( 'td' );
	td.innerHTML = text;
	tr.appendChild( td );
	table.appendChild( tr );
	$('ca-sh-diary-dayentries').appendChild( table );
}

function ca_sh_intro_pagesClose()
{
	var i = 1;
	while( $('ca-sh_intro-page-' + i) )
	{
		$('ca-sh_intro-page-' + i).hide();
		$('ca-sh-intro-pagemenu-' + i).className = $( 'ca-sh-intro-pagemenu-' + i ).className.replace( /selected/, '' );
		i++;
	}
}

function ca_sh_intro_pageOpen( pageNum )
{
	if( !pageNum )
		pageNum = 1;
	ca_sh_intro_pagesClose();
	if( $( 'ca-sh_intro-page-' + pageNum ) )
	{
		$( 'ca-sh_intro-page-' + pageNum ).show();
		$( 'ca-sh-intro-pagemenu-' + pageNum ).className = $( 'ca-sh-intro-pagemenu-' + pageNum ).className + 'selected';
	}
}

function ca_sh_forum_pagesClose()
{
	var i = 1;
	while( $('ca-sh_forum-page-' + i) )
	{
		$('ca-sh_forum-page-' + i).hide();
		$('ca-sh-forum-pagemenu-' + i).className = $( 'ca-sh-forum-pagemenu-' + i ).className.replace( /selected/, '' );
		i++;
	}
}

function ca_sh_forum_pageOpen( pageNum )
{
	if( !pageNum )
		pageNum = 1;
	ca_sh_forum_pagesClose();
	if( $( 'ca-sh_forum-page-' + pageNum ) )
	{
		$( 'ca-sh_forum-page-' + pageNum ).show();
		$( 'ca-sh-forum-pagemenu-' + pageNum ).className = $( 'ca-sh-forum-pagemenu-' + pageNum ).className + 'selected';
	}
}

var ca_sh_forum_newpost_replyTo = 0;
function ca_sh_forum_newpost()
{
	$('ca-sh-forum-newpost-text').disabled = 1;
	$('ca-sh-forum-newpost-loading').show();
	$('ca-sh-forum-newpost-error').hide();
    new Ajax.Request( '/ca-ajax/selfhelp/forum/newpost.js.php', {
		method: 'post', parameters:	{
			text: $('ca-sh-forum-newpost-text').value,
			replyto: ca_sh_forum_newpost_replyTo,
			topicindex: $('ca-sh-forum-topicindex').value
		}
	} );
}

function ca_sh_forum_dateOrderChange()
{
	$('ca-sh-forum-loading').show();
	$('ca-sh-forum-error').hide();
    new Ajax.Request( '/ca-ajax/selfhelp/forum/dateorderchange.js.php', {
		method: 'post', parameters:	{
			order: $('ca-sh-forum-orderby').value
		}
	} );
}

function ca_sh_forum_postsPerPageChange()
{
	$('ca-sh-forum-loading').show();
	$('ca-sh-forum-error').hide();
    new Ajax.Request( '/ca-ajax/selfhelp/forum/postsperpagechange.js.php', {
		method: 'post', parameters:	{
			postsperpage: $('ca-sh-forum-postsperpage').value
		}
	} );
}

var ca_sh_forum_currentPage = 1;
function ca_sh_forum_editCurrentPage()
{
	if( $('ca-sh-forum-currentpage').firstChild.tagName == 'INPUT' )
		return;
	ca_sh_forum_currentPage = $('ca-sh-forum-currentpage').innerHTML;
	$('ca-sh-forum-currentpage').innerHTML = '<input type="text" id="ca-sh-forum-currentpage-edit" value="' + ca_sh_forum_currentPage + '" onkeydown="javascript:if( event.keyCode == 13 ) ca_sh_forum_editCurrentPageFinish(); if( event.keyCode == 27 ) ca_sh_forum_editCurrentPageCancel();" />';
}

function ca_sh_forum_editCurrentPageFinish()
{
	if( !isNaN( $('ca-sh-forum-currentpage-edit').value ) )
	{
		location.href = '/onsegitoprogram/forum/' + $('ca-sh-forum-topicindex').value + '/' + $('ca-sh-forum-currentpage-edit').value + '/';
		return;
	}
}

function ca_sh_forum_editCurrentPageCancel()
{
	$('ca-sh-forum-currentpage').innerHTML = ca_sh_forum_currentPage;
}

var ca_sh_forum_replyToCurrentID = 0;
function ca_sh_forum_replyTo( id )
{
	if( id == 0 )
	{
		$('ca-sh-forum-newpost').hide();
		$('ca-sh-forum-newpost-cancelbutton').hide();
	}
	else
	{
		$('ca-sh-forum-replyto-' + id).hide();
		ca_sh_forum_replyToCurrentID = id;
	}

	var newPostEditor = $('ca-sh-forum-newpost-editor');
	newPostEditor.parentNode.removeChild( newPostEditor );
	if( id == 0 )
	{
		$('ca-sh-forum-newpost').appendChild( newPostEditor );
		$('ca-sh-forum-newpost').show();
		$('ca-sh-forum-newpost-editor').className = '';
		$('ca-sh-forum-replytolink-' + ca_sh_forum_replyToCurrentID).show();
		$('ca-sh-forum-newpost-text').focus();
	}
	else
	{
		$('ca-sh-forum-replyto-' + id).appendChild( newPostEditor );
		$('ca-sh-forum-replyto-' + id).show();
		$('ca-sh-forum-replytolink-' + id).hide();
		$('ca-sh-forum-newpost-cancelbutton').show();
		$('ca-sh-forum-newpost-text').value = $('ca-sh-forum-post-'+id+'-poster').innerHTML + " írta:\n\n\"" + $('ca-sh-forum-post-'+id+'-text').innerHTML.replace( /<br>/g, "\n" ) + "\"\n\n";
		$('ca-sh-forum-newpost-editor').className = 'replyto';
		$('ca-sh-forum-newpost-text').focus();
	}
}

function ca_sh_forum_newTopic()
{
	var title = prompt( 'Új téma neve:' );
	if( title == null || title == ''  )
		return;

	$('ca-sh-forum-loading').show();
	$('ca-sh-forum-error').hide();
    new Ajax.Request( '/ca-ajax/selfhelp/forum/newtopic.js.php', {
		method: 'post', parameters:	{
			title: title,
			parenttopic: $('ca-sh-forum-topicindex').value
		}
	} );
}

function ca_sh_forum_renameTopic( id )
{
	var newTitle = prompt( 'A téma új neve:' );
	if( newTitle == null || newTitle == '' )
		return;

	$('ca-sh-forum-loading').show();
	$('ca-sh-forum-error').hide();
    new Ajax.Request( '/ca-ajax/selfhelp/forum/renametopic.js.php', {
		method: 'post', parameters:	{
			newtitle: newTitle,
			topicindex: id
		}
	} );
}

function ca_sh_forum_closeTopicChange()
{
	if( !confirm( 'Biztosan változtatsz a zároláson?' ) )
		return;

	$('ca-sh-forum-loading').show();
	$('ca-sh-forum-error').hide();
    new Ajax.Request( '/ca-ajax/selfhelp/forum/closetopicchange.js.php', {
		method: 'post', parameters:	{
			topicindex: $('ca-sh-forum-topicindex').value
		}
	} );
}

function ca_sh_forum_deleteTopic( id )
{
	if( !confirm( 'Biztosan törlöd a témát?' ) )
		return;

	$('ca-sh-forum-loading').show();
	$('ca-sh-forum-error').hide();
    new Ajax.Request( '/ca-ajax/selfhelp/forum/deletetopic.js.php', {
		method: 'post', parameters:	{
			topicindex: id
		}
	} );
}

function ca_sh_forum_deletePost( id )
{
	if( !confirm( 'Biztosan törlöd a bejegyzést?' ) )
		return;

	$('ca-sh-forum-loading').show();
	$('ca-sh-forum-error').hide();
    new Ajax.Request( '/ca-ajax/selfhelp/forum/deletepost.js.php', {
		method: 'post', parameters:	{
			postindex: id
		}
	} );
}

function ca_sh_chat_pagesClose()
{
	var i = 1;
	while( $('ca-sh-chat-page-' + i) )
	{
		$('ca-sh-chat-page-' + i).hide();
		$('ca-sh-chat-pagemenu-' + i).className = $( 'ca-sh-chat-pagemenu-' + i ).className.replace( /selected/, '' );
		i++;
	}

	if( ca_sh_chat_updaterTimer )
	{
		clearInterval( ca_sh_chat_updaterTimer );
		ca_sh_chat_updaterTimer = 0;
	}
}

var ca_sh_chat_logs_alreadyInitialized = 0;
function ca_sh_chat_pageOpen( pageNum )
{
	if( !pageNum )
		pageNum = 1;
	ca_sh_chat_pagesClose();
	if( $( 'ca-sh-chat-page-' + pageNum ) )
	{
		$( 'ca-sh-chat-page-' + pageNum ).show();
		$( 'ca-sh-chat-pagemenu-' + pageNum ).className = $( 'ca-sh-chat-pagemenu-' + pageNum ).className + 'selected';
	}

	if( pageNum == 2 )
	{
		ca_sh_chat_init();
		$('ca-sh-chat-lines').scrollTop = 9999999;
	}

	if( pageNum == 3 )
	{
		if( !ca_sh_chat_logs_alreadyInitialized || $('ca-sh-chat-logs-dayselect').style.display == 'none' )
		{
			ca_sh_chat_logs_alreadyInitialized = 1;
			ca_sh_chat_logs_init();
		}
		else
			ca_sh_chat_logs_update();

		$('ca-sh-chat-logs-lines').scrollTop = 9999999;
	}
}

var ca_sh_chat_updaterTimer = 0;
function ca_sh_chat_disable()
{
	$('ca-sh-chat-input').disabled = 1;
	$('ca-sh-chat-sendbutton').disabled = 1;
}

function ca_sh_chat_enable()
{
	$('ca-sh-chat-input').disabled = 0;
	$('ca-sh-chat-sendbutton').disabled = 0;
}

function ca_sh_chat_getLastMessageIndex()
{
	var lastMessageIndex = 0;
	for(var i = 0; i < $('ca-sh-chat-lines').childNodes.length; i++ )
	{
		var index = parseInt( $('ca-sh-chat-lines').childNodes[i].id.replace('ca-sh-chat-line-',''), 10 );
		if( index > lastMessageIndex )
			lastMessageIndex = index;
	}
	return lastMessageIndex;
}

function ca_sh_chat_update()
{
	ca_sh_chat_setStatus( 'updating' );
    new Ajax.Request( '/ca-ajax/selfhelp/chat/update.js.php', {
		method: 'post', parameters: {
			lastmessageindex: ca_sh_chat_getLastMessageIndex()
		}
    } );
}

var ca_sh_chat_updatingTimeoutTimer = 0;
var ca_sh_chat_prevStatus = 'ok';
function ca_sh_chat_setStatus( status )
{
	if( ca_sh_chat_prevStatus == 'error' && status != 'ok' )
		return;

	switch( status )
	{
	case 'updating':
		if( ca_sh_chat_prevStatus != 'updating' )
		{
			if( ca_sh_chat_updatingTimeoutTimer )
				clearTimeout( ca_sh_chat_updatingTimeoutTimer );
			ca_sh_chat_updatingTimeoutTimer = setTimeout( "ca_sh_chat_setStatus( 'error' );", 5000 );
		}
		$('ca-sh-chat-status').src = '/ca-images/chatstatus-updating.png';
		break;
	case 'ok':
		if(ca_sh_chat_updatingTimeoutTimer)
		{
			clearTimeout( ca_sh_chat_updatingTimeoutTimer );
			ca_sh_chat_updatingTimeoutTimer = 0;
		}
		$('ca-sh-chat-status').src = '/ca-images/chatstatus-ok.png';
		break;
	default: $('ca-sh-chat-status').src = '/ca-images/chatstatus-error.png';
	}

	ca_sh_chat_prevStatus = status;
}

function ca_sh_chat_init()
{
	ca_sh_chat_disable();
	$('ca-sh-chat-statusmessage').innerHTML = 'lekérdezés...';

	if( ca_sh_chat_updaterTimer )
		clearInterval( ca_sh_chat_updaterTimer );
	ca_sh_chat_updaterTimer = setInterval( "ca_sh_chat_update();", 2000 );
	ca_sh_chat_update();
}

function ca_sh_chat_send()
{
	if( $('ca-sh-chat-input').value == '' )
		return;

	ca_sh_chat_setStatus( 'updating' );
    new Ajax.Request( '/ca-ajax/selfhelp/chat/send.js.php', {
		method: 'post', parameters: {
			msg: $('ca-sh-chat-input').value,
			lastmessageindex: ca_sh_chat_getLastMessageIndex()
		}
    } );
	$('ca-sh-chat-input').value = '';
}

function ca_sh_chat_addEvent( to, index, timestamp, msg )
{
	if( to == $('ca-sh-chat-lines') && $('ca-sh-chat-line-' + index) ) // line already added
		return;

	var newLine = document.createElement( 'div' );
	var ts = new Date(timestamp*1000);
	newLine.innerHTML = '(' + (ts.getHours() < 10 ? '0' + ts.getHours() : ts.getHours()) + ':' +
		(ts.getMinutes() < 10 ? '0' + ts.getMinutes() : ts.getMinutes()) + ') * ' + msg;
	if( to == $('ca-sh-chat-logs-lines') )
	{
		newLine.className = 'ca-sh-chat-logs-line event';
		newLine.id = 'ca-sh-chat-logs-line-' + index;
	}
	else
	{
		newLine.className = 'ca-sh-chat-line event';
		newLine.id = 'ca-sh-chat-line-' + index;
	}
	to.appendChild( newLine );
	to.scrollTop = 9999999;
	ca_sh_chat_recolorRows( to );
}

function ca_sh_chat_addMessage( to, index, timestamp, nick, msg )
{
	if( to == $('ca-sh-chat-lines') && $('ca-sh-chat-line-' + index) ) // line already added
		return;

	var newLine = document.createElement( 'div' );
	var ts = new Date(timestamp*1000);
	newLine.innerHTML = '(' + (ts.getHours() < 10 ? '0' + ts.getHours() : ts.getHours()) + ':' +
		(ts.getMinutes() < 10 ? '0' + ts.getMinutes() : ts.getMinutes()) + ') ' + nick + ': ' + msg;
	if( to == $('ca-sh-chat-logs-lines') )
	{
		newLine.className = 'ca-sh-chat-logs-line';
		newLine.id = 'ca-sh-chat-logs-line-' + index;
	}
	else
	{
		newLine.className = 'ca-sh-chat-line';
		newLine.id = 'ca-sh-chat-line-' + index;
	}
	to.appendChild( newLine );
	to.scrollTop = 9999999;
	ca_sh_chat_recolorRows( to );
}

function ca_sh_chat_deleteMessage( index )
{
	if( $('ca-sh-chat-line-' + index) )
	{
		$('ca-sh-chat-lines').removeChild( $('ca-sh-chat-line-' + index) );
		ca_sh_chat_recolorRows( $('ca-sh-chat-lines') );
	}

	if( $('ca-sh-chat-logs-line-' + index) )
	{
		$('ca-sh-chat-logs-lines').removeChild( $('ca-sh-chat-logs-line-' + index) );
		ca_sh_chat_recolorRows( $('ca-sh-chat-logs-lines') );
	}
}

function ca_sh_chat_recolorRows( lines )
{
	for(var i = 0; i < lines.childNodes.length; i++ )
	{
		lines.childNodes[i].className = lines.childNodes[i].className.replace(/ odd$/, '').replace(/ even$/, '');
		lines.childNodes[i].className += (i % 2 ? ' odd' : ' even');
	}
}

function ca_sh_chat_logs_init()
{
	$('ca-sh-chat-logs-lines').innerHTML = 'Lekérdezés...';

    new Ajax.Request( '/ca-ajax/selfhelp/chat/logsInit.js.php', {
		method: 'post', parameters: {}
    } );
}

function ca_sh_chat_logs_update()
{
    new Ajax.Request( '/ca-ajax/selfhelp/chat/logsUpdate.js.php', {
		method: 'post', parameters: {
			day: $('ca-sh-chat-logs-dayselect').value
		}
    } );
}

function ca_sh_chat_logs_eraseDaySelect()
{
    while( $('ca-sh-chat-logs-dayselect').hasChildNodes() )
		$('ca-sh-chat-logs-dayselect').removeChild( $('ca-sh-chat-logs-dayselect').firstChild );
}

function ca_sh_chat_logs_addToDaySelect( index, name )
{
    var newOption = document.createElement( 'option' );
    newOption.id = 'ca-sh-chat-logs-dayselect-' + index;
    newOption.value = index;
    newOption.innerHTML = name;
    $('ca-sh-chat-logs-dayselect').appendChild( newOption );
}

function ca_sh_chat_newRequestSend()
{
	$('ca-sh-chat-newrequest-text').disabled = 1;
	$('ca-sh-chat-newrequest-loading').show();
	$('ca-sh-chat-newrequest-error').hide();
    new Ajax.Request( '/ca-ajax/selfhelp/chat/newRequest.js.php', {
		method: 'post', parameters:	{
			text: $('ca-sh-chat-newrequest-text').value
		}
	} );
}

function ca_sh_goals_pagesClose()
{
	var i = 1;
	while( $('ca-sh_goals-page-' + i) )
	{
		$('ca-sh_goals-page-' + i).hide();
		$('ca-sh-goals-pagemenu-' + i).className = $( 'ca-sh-goals-pagemenu-' + i ).className.replace( /selected/, '' );
		i++;
	}
}

function ca_sh_goals_pageOpen( pageNum )
{
	if( !pageNum )
		pageNum = 1;
	ca_sh_goals_pagesClose();
	if( $( 'ca-sh_goals-page-' + pageNum ) )
	{
		$( 'ca-sh_goals-page-' + pageNum ).show();
		$( 'ca-sh-goals-pagemenu-' + pageNum ).className = $( 'ca-sh-goals-pagemenu-' + pageNum ).className + 'selected';
	}
}

function ca_sh_goals_save()
{
	$('ca-sh-goals-text').disabled = 1;
	$('ca-sh-goals-loading').show();
    new Ajax.Request( '/ca-ajax/selfhelp/goals/save.js.php', {
		method: 'post', parameters:	{
			text: $('ca-sh-goals-text').value
		}
	} );
}

function ca_sh_recordkeeping_pagesClose()
{
	var i = 1;
	while( $('ca-sh_recordkeeping-page-' + i) )
	{
		$('ca-sh_recordkeeping-page-' + i).hide();
		$('ca-sh-recordkeeping-pagemenu-' + i).className = $( 'ca-sh-recordkeeping-pagemenu-' + i ).className.replace( /selected/, '' );
		i++;
	}
}

function ca_sh_recordkeeping_pageOpen( pageNum )
{
	if( !pageNum )
		pageNum = 1;
	ca_sh_recordkeeping_pagesClose();
	if( $( 'ca-sh_recordkeeping-page-' + pageNum ) )
	{
		$( 'ca-sh_recordkeeping-page-' + pageNum ).show();
		$( 'ca-sh-recordkeeping-pagemenu-' + pageNum ).className = $( 'ca-sh-recordkeeping-pagemenu-' + pageNum ).className + 'selected';
	}
}

var ca_sh_recordkeeping_calendar;
function ca_sh_recordkeeping_calendar_init()
{
	ca_sh_recordkeeping_calendar = new ca_calendar( 'ca-sh-recordkeeping-calendar-days' );
	ca_sh_recordkeeping_calendar.monthDisplay = 'ca-sh-recordkeeping-calendar-month';
	ca_sh_recordkeeping_calendar.yearDisplay = 'ca-sh-recordkeeping-calendar-year';
	ca_sh_recordkeeping_calendar.dayClickedCallBack = 'ca_sh_recordkeeping_calendar_dayClickedCallBack';
	ca_sh_recordkeeping_calendar.window = 'ca-sh-recordkeeping-calendar';
	ca_sh_recordkeeping_calendar.update();
}

var ca_sh_recordkeeping_cravingRatingValue = 0;
function ca_sh_recordkeeping_cravingRating( rating )
{
	ca_sh_recordkeeping_cravingRatingValue = rating;
	for( var i = 0; i <= 10; i++ )
	{
		if( i <= ca_sh_recordkeeping_cravingRatingValue )
			$('ca-sh-recordkeeping-craving-rating-' + i).src = '/ca-images/craving-rating/' + i + '.png';
		else
			$('ca-sh-recordkeeping-craving-rating-' + i).src = '/ca-images/rating-u.png';
	}
	new Effect.Pulsate( 'ca-sh-recordkeeping-craving-rating-' + rating, { pulses: 1, duration: 0.2, from: 0.5 } );
}

function ca_sh_recordkeeping_cravingRatingMouseOver( rating )
{
	for( var i = 0; i <= 10; i++ )
	{
		if( i <= rating )
			$('ca-sh-recordkeeping-craving-rating-' + i).src = '/ca-images/craving-rating/' + i + '.png';
		else
			$('ca-sh-recordkeeping-craving-rating-' + i).src = '/ca-images/rating-u.png';
	}
	$('ca-sh-recordkeeping-craving-rating-text').innerHTML = rating;
}

function ca_sh_recordkeeping_cravingRatingMouseOut( event )
{
	var toElement;

	if( event.relatedTarget )
		toElement = event.relatedTarget;
	else
		if( event.toElement )
			toElement = event.toElement;

	if( toElement.tagName != 'DIV' )
	{
		for( var i = 0; i <= 10; i++ )
		{
			if( i <= ca_sh_recordkeeping_cravingRatingValue )
				$('ca-sh-recordkeeping-craving-rating-' + i).src = '/ca-images/craving-rating/' + i + '.png';
			else
				$('ca-sh-recordkeeping-craving-rating-' + i).src = '/ca-images/rating-u.png';
		}
		$('ca-sh-recordkeeping-craving-rating-text').innerHTML = ca_sh_recordkeeping_cravingRatingValue;
	}
}

function ca_sh_recordkeeping_cravingRatingReset()
{
	ca_sh_recordkeeping_cravingRatingValue = 0;
	for( var i = 1; i <= 10; i++ )
		$('ca-sh-recordkeeping-craving-rating-' + i).src = '/ca-images/rating-u.png';
	$('ca-sh-recordkeeping-craving-rating-0').src = '/ca-images/craving-rating/0.png';
	$('ca-sh-recordkeeping-craving-rating-text').innerHTML = 0;
}

function ca_sh_recordkeeping_doInsteadSmokingChange()
{
	if( $('ca-sh-recordkeeping-doinsteadsmoking').value == 'other' )
	{
		if( $('ca-sh-recordkeeping-doinsteadsmoking').selectedIndex < $('ca-sh-recordkeeping-doinsteadsmoking').length-1 )
			$('ca-sh-recordkeeping-doinsteadsmoking-other').value = $('ca-sh-recordkeeping-doinsteadsmoking')[$('ca-sh-recordkeeping-doinsteadsmoking').selectedIndex].text;
		else
			$('ca-sh-recordkeeping-doinsteadsmoking-other').value = '';
		$('ca-sh-recordkeeping-doinsteadsmoking-other').show();
	}
	else
	{
		$('ca-sh-recordkeeping-doinsteadsmoking-other').value = '';
		$('ca-sh-recordkeeping-doinsteadsmoking-other').hide();
	}
}

function ca_sh_recordkeeping_numberOfJointsChange()
{
	$('ca-sh-recordkeeping-doinsteadsmoking-other').hide();

	if( $('ca-sh-recordkeeping-numberofjoints').value == 0 )
	{
		$('ca-sh-recordkeeping-doinsteadsmoking').show();
		ca_sh_recordkeeping_doInsteadSmokingChange();
	}
	else
		$('ca-sh-recordkeeping-doinsteadsmoking').hide();
}

function ca_sh_recordkeeping_moodChange()
{
	if( $('ca-sh-recordkeeping-mood').value == 'other' )
	{
		if( $('ca-sh-recordkeeping-mood').selectedIndex < $('ca-sh-recordkeeping-mood').length-1 )
			$('ca-sh-recordkeeping-mood-other').value = $('ca-sh-recordkeeping-mood')[$('ca-sh-recordkeeping-mood').selectedIndex].text;
		else
			$('ca-sh-recordkeeping-mood-other').value = '';
		$('ca-sh-recordkeeping-mood-other').show();
	}
	else
	{
		$('ca-sh-recordkeeping-mood-other').value = '';
		$('ca-sh-recordkeeping-mood-other').hide();
	}
}

function ca_sh_recordkeeping_thoughtsChange()
{
	if( $('ca-sh-recordkeeping-thoughts').value == 'other' )
	{
		if( $('ca-sh-recordkeeping-thoughts').selectedIndex < $('ca-sh-recordkeeping-thoughts').length-1 )
			$('ca-sh-recordkeeping-thoughts-other').value = $('ca-sh-recordkeeping-thoughts')[$('ca-sh-recordkeeping-thoughts').selectedIndex].text;
		else
			$('ca-sh-recordkeeping-thoughts-other').value = '';
		$('ca-sh-recordkeeping-thoughts-other').show();
	}
	else
	{
		$('ca-sh-recordkeeping-thoughts-other').value = '';
		$('ca-sh-recordkeeping-thoughts-other').hide();
	}
}

function ca_sh_recordkeeping_withChange()
{
	if( $('ca-sh-recordkeeping-with').value == 'other' )
	{
		if( $('ca-sh-recordkeeping-with').selectedIndex < $('ca-sh-recordkeeping-with').length-1 )
			$('ca-sh-recordkeeping-with-other').value = $('ca-sh-recordkeeping-with')[$('ca-sh-recordkeeping-with').selectedIndex].text;
		else
			$('ca-sh-recordkeeping-with-other').value = '';
		$('ca-sh-recordkeeping-with-other').show();
	}
	else
	{
		$('ca-sh-recordkeeping-with-other').value = '';
		$('ca-sh-recordkeeping-with-other').hide();
	}
}

function ca_sh_recordkeeping_whereChange()
{
	if( $('ca-sh-recordkeeping-where').value == 'other' )
	{
		if( $('ca-sh-recordkeeping-where').selectedIndex < $('ca-sh-recordkeeping-where').length-1 )
			$('ca-sh-recordkeeping-where-other').value = $('ca-sh-recordkeeping-where')[$('ca-sh-recordkeeping-where').selectedIndex].text;
		else
			$('ca-sh-recordkeeping-where-other').value = '';
		$('ca-sh-recordkeeping-where-other').show();
	}
	else
	{
		$('ca-sh-recordkeeping-where-other').value = '';
		$('ca-sh-recordkeeping-where-other').hide();
	}
}

function ca_sh_recordkeeping_save()
{
	ca_sh_recordkeeping_calendar.close();
	$('ca-sh-recordkeeping-date').disabled = 1;
	$('ca-sh-recordkeeping-daypart').disabled = 1;
	$('ca-sh-recordkeeping-craving-rating-text').disabled = 1;
	$('ca-sh-recordkeeping-where').disabled = 1;
	$('ca-sh-recordkeeping-where-other').disabled = 1;
	$('ca-sh-recordkeeping-with').disabled = 1;
	$('ca-sh-recordkeeping-with-other').disabled = 1;
	$('ca-sh-recordkeeping-mood').disabled = 1;
	$('ca-sh-recordkeeping-mood-other').disabled = 1;
	$('ca-sh-recordkeeping-thoughts').disabled = 1;
	$('ca-sh-recordkeeping-thoughts-other').disabled = 1;
	$('ca-sh-recordkeeping-numberofjoints').disabled = 1;
	$('ca-sh-recordkeeping-doinsteadsmoking').disabled = 1;
	$('ca-sh-recordkeeping-doinsteadsmoking-other').disabled = 1;
	for( var i = 1; i <= 10; i++ )
		$('ca-sh-recordkeeping-craving-rating-' + i).disabled = 1;

	$('ca-sh-recordkeeping-error').hide();
	$('ca-sh-recordkeeping-loading').show();
    new Ajax.Request( '/ca-ajax/selfhelp/recordkeeping/save.js.php', {
		method: 'post', parameters:	{
			date: $('ca-sh-recordkeeping-date').value,
			daypart: $('ca-sh-recordkeeping-daypart').value,
			cravingrating: $('ca-sh-recordkeeping-craving-rating-text').innerHTML,
			where: $('ca-sh-recordkeeping-where').value,
			whereother: ($('ca-sh-recordkeeping-where').value == 'other' ? $('ca-sh-recordkeeping-where-other').value : ''),
			with1: $('ca-sh-recordkeeping-with').value,
			withother: ($('ca-sh-recordkeeping-with').value == 'other' ? $('ca-sh-recordkeeping-with-other').value : ''),
			mood: $('ca-sh-recordkeeping-mood').value,
			moodother: ($('ca-sh-recordkeeping-mood').value == 'other' ? $('ca-sh-recordkeeping-mood-other').value : ''),
			thoughts: $('ca-sh-recordkeeping-thoughts').value,
			thoughtsother: ($('ca-sh-recordkeeping-thoughts').value == 'other' ? $('ca-sh-recordkeeping-thoughts-other').value : ''),
			numberofjoints: $('ca-sh-recordkeeping-numberofjoints').value,
			doinsteadsmoking: $('ca-sh-recordkeeping-doinsteadsmoking').value,
			doinsteadsmokingother: ($('ca-sh-recordkeeping-doinsteadsmoking').value == 'other' ? $('ca-sh-recordkeeping-doinsteadsmoking-other').value : '')
		}
	} );
}

function ca_sh_recordkeeping_calendar_dayClickedCallBack( dayNum )
{
	ca_sh_recordkeeping_calendar.dayClicked( dayNum );

	$('ca-sh-recordkeeping-date').value = ca_sh_recordkeeping_calendar.getSelectedDate();
	ca_sh_recordkeeping_calendar.close();
}

var ca_sh_recordkeeping_confirmdialog_move_window;
var ca_sh_recordkeeping_confirmdialog_move_mouseX = -1;
var ca_sh_recordkeeping_confirmdialog_move_mouseY = -1;
var ca_sh_recordkeeping_confirmdialog_move_mouseTmpX = -1;
var ca_sh_recordkeeping_confirmdialog_move_mouseTmpY = -1;
function ca_sh_recordkeeping_confirmdialog_move( e )
{
    if( document.all ) // IE
    {
		ca_sh_recordkeeping_confirmdialog_move_mouseX = event.clientX + document.body.scrollLeft;
		ca_sh_recordkeeping_confirmdialog_move_mouseY = event.clientY + document.body.scrollTop;
    }
    else
    {
		ca_sh_recordkeeping_confirmdialog_move_mouseX = e.pageX;
		ca_sh_recordkeeping_confirmdialog_move_mouseY = e.pageY;
    }

    if( ca_sh_recordkeeping_confirmdialog_move_mouseX < 0 )
		ca_sh_recordkeeping_confirmdialog_move_mouseX = 0;
    if( ca_sh_recordkeeping_confirmdialog_move_mouseY < 0 )
		ca_sh_recordkeeping_confirmdialog_move_mouseY = 0;

    if( ca_sh_recordkeeping_confirmdialog_move_mouseTmpX != -1 && ca_sh_recordkeeping_confirmdialog_move_mouseTmpY != -1 )
    {
        ca_sh_recordkeeping_confirmdialog_move_window.style.left = ( parseInt( ca_sh_recordkeeping_confirmdialog_move_window.style.left, 10 ) + ( ca_sh_recordkeeping_confirmdialog_move_mouseX-ca_sh_recordkeeping_confirmdialog_move_mouseTmpX ) ) + 'px';
		ca_sh_recordkeeping_confirmdialog_move_window.style.top = ( parseInt( ca_sh_recordkeeping_confirmdialog_move_window.style.top, 10 ) + ( ca_sh_recordkeeping_confirmdialog_move_mouseY-ca_sh_recordkeeping_confirmdialog_move_mouseTmpY ) ) + 'px';
    }
    ca_sh_recordkeeping_confirmdialog_move_mouseTmpX = ca_sh_recordkeeping_confirmdialog_move_mouseX;
    ca_sh_recordkeeping_confirmdialog_move_mouseTmpY = ca_sh_recordkeeping_confirmdialog_move_mouseY;
}

function ca_sh_recordkeeping_confirmdialog_dragStart( e )
{
	if( document.all )
    {
        document.attachEvent( "onmousemove", ca_sh_recordkeeping_confirmdialog_move );
        document.attachEvent( "onmouseup", ca_sh_recordkeeping_confirmdialog_dragStop );
		window.event.cancelBubble = true;
		window.event.returnValue = false;
    }
    else
    {
		document.addEventListener( "mousemove", ca_sh_recordkeeping_confirmdialog_move, true );
		document.addEventListener( "mouseup", ca_sh_recordkeeping_confirmdialog_dragStop, true );
		e.preventDefault();
    }

    if( !ca_sh_recordkeeping_confirmdialog_move_window.style.left )
		ca_sh_recordkeeping_confirmdialog_move_window.style.left = '0px';
    if( !ca_sh_recordkeeping_confirmdialog_move_window.style.top )
		ca_sh_recordkeeping_confirmdialog_move_window.style.top = '0px';

    ca_sh_recordkeeping_confirmdialog_move_mouseTmpX = -1;
    ca_sh_recordkeeping_confirmdialog_move_mouseTmpY = -1;
}

function ca_sh_recordkeeping_confirmdialog_dragStop()
{
    if( document.all) // IE
    {
		document.detachEvent( "onmousemove", ca_sh_recordkeeping_confirmdialog_move );
        document.detachEvent( "onmouseup", ca_sh_recordkeeping_confirmdialog_dragStop );
    }
    else
    {
		document.removeEventListener( "mousemove", ca_sh_recordkeeping_confirmdialog_move, true );
		document.removeEventListener( "mouseup",   ca_sh_recordkeeping_confirmdialog_dragStop, true );
    }
}

function ca_sh_recordkeeping_confirmdialog_close()
{
	$('ca-sh-recordkeeping-confirmdialog').hide();
}

function ca_sh_recordkeeping_confirmdialog_open()
{
	var dayPart;
	switch( $('ca-sh-recordkeeping-daypart').value )
	{
	case 'morning': dayPart = 'reggel'; break;
	case 'afternoon': dayPart = 'délután'; break;
	case 'evening': dayPart = 'este'; break;
	case 'night': dayPart = 'éjjel'; break;
	}
	$('ca-sh-recordkeeping-confirmdialog-date').innerHTML = $('ca-sh-recordkeeping-date').value + ' ' + dayPart;

	for( var i = 0; i <= 10; i++ )
	{
		if( i <= $('ca-sh-recordkeeping-craving-rating-text').innerHTML )
			$('ca-sh-recordkeeping-confirmdialog-craving-rating-' + i).src = '/ca-images/craving-rating/' + i + '.png';
		else
			$('ca-sh-recordkeeping-confirmdialog-craving-rating-' + i).src = '/ca-images/rating-u.png';
	}
	$('ca-sh-recordkeeping-confirmdialog-craving-rating-text').innerHTML = $('ca-sh-recordkeeping-craving-rating-text').innerHTML;

	var where;
	switch( $('ca-sh-recordkeeping-where').value )
	{
	case 'home': where = 'otthon'; break;
	case 'street': where = 'utcán'; break;
	case 'club': where = 'szórakozóhelyen'; break;
	case 'schoolwork': where = 'iskolában/munkahelyen'; break;
	default: where = $('ca-sh-recordkeeping-where-other').value; break;
	}
	$('ca-sh-recordkeeping-confirmdialog-where').innerHTML = where;

	var with1;
	switch( $('ca-sh-recordkeeping-with').value )
	{
	case 'alone': with1 = 'egyedül'; break;
	case 'colleagues': with1 = 'kollégák'; break;
	case 'friends': with1 = 'barátok'; break;
	case 'partner': with1 = 'partner'; break;
	case 'relatives': with1 = 'rokonok'; break;
	default: with1 = $('ca-sh-recordkeeping-with-other').value; break;
	}
	$('ca-sh-recordkeeping-confirmdialog-with').innerHTML = with1;

	var mood;
	switch( $('ca-sh-recordkeeping-mood').value )
	{
	case 'satisfied': mood = 'elégedett'; break;
	case 'stressed': mood = 'feszült'; break;
	case 'tired': mood = 'fáradt'; break;
	case 'depressed': mood = 'lehangolt'; break;
	default: mood = $('ca-sh-recordkeeping-mood-other').value; break;
	}
	$('ca-sh-recordkeeping-confirmdialog-mood').innerHTML = mood;

	var thoughts;
	switch( $('ca-sh-recordkeeping-thoughts').value )
	{
	case '1': thoughts = 'semmi se jön össze'; break;
	case '2': thoughts = 'ha akarnék, beszívhatnék'; break;
	case '3': thoughts = 'egyébként is szívtam volna'; break;
	case '4': thoughts = 'egy spangli nem a világ'; break;
	default: thoughts = $('ca-sh-recordkeeping-thoughts-other').value; break;
	}
	$('ca-sh-recordkeeping-confirmdialog-thoughts').innerHTML = thoughts;

	if( $('ca-sh-recordkeeping-numberofjoints').value > 0 )
	{
		$('ca-sh-recordkeeping-confirmdialog-smoke').show();
		$('ca-sh-recordkeeping-confirmdialog-nosmoke').hide();
		$('ca-sh-recordkeeping-confirmdialog-numberofjoints').innerHTML = $('ca-sh-recordkeeping-numberofjoints').value;
	}
	else
	{
		$('ca-sh-recordkeeping-confirmdialog-smoke').hide();
		$('ca-sh-recordkeeping-confirmdialog-nosmoke').show();

		var doInsteadSmoking;
		switch( $('ca-sh-recordkeeping-doinsteadsmoking').value )
		{
		case 'relaxed': doInsteadSmoking = 'relaxáló gyakorlatok'; break;
		case 'chips': doInsteadSmoking = 'nassolás'; break;
		case 'call': doInsteadSmoking = 'telefonálás'; break;
		case 'music': doInsteadSmoking = 'zenehallgatás'; break;
		default: doInsteadSmoking = $('ca-sh-recordkeeping-doinsteadsmoking-other').value; break;
		}
		$('ca-sh-recordkeeping-confirmdialog-doinsteadsmoking').innerHTML = doInsteadSmoking;
	}

	ca_sh_recordkeeping_confirmdialog_move_window = $('ca-sh-recordkeeping-confirmdialog');
	$('ca-sh-recordkeeping-confirmdialog').show();

	ca_setCenterHorizontal( $('ca-sh-recordkeeping-confirmdialog') );
	ca_setCenterVertical( $('ca-sh-recordkeeping-confirmdialog') );
}

function ca_sh_emergencies_pagesClose()
{
	var i = 1;
	while( $('ca-sh_emergencies-page-' + i) )
	{
		$('ca-sh_emergencies-page-' + i).hide();
		$('ca-sh-emergencies-pagemenu-' + i).className = $( 'ca-sh-emergencies-pagemenu-' + i ).className.replace( /selected/, '' );
		i++;
	}
}

function ca_sh_emergencies_pageOpen( pageNum )
{
	if( !pageNum )
		pageNum = 1;
	ca_sh_emergencies_pagesClose();
	if( $( 'ca-sh_emergencies-page-' + pageNum ) )
	{
		$( 'ca-sh_emergencies-page-' + pageNum ).show();
		$( 'ca-sh-emergencies-pagemenu-' + pageNum ).className = $( 'ca-sh-emergencies-pagemenu-' + pageNum ).className + 'selected';
	}
}

function ca_sh_emergencies_save()
{
	$('ca-sh-emergencies-loading').show();
	$('ca-sh-emergencies-error').hide();

	$('ca-sh-emergencies-other-workschoolend').disabled = 1;
	$('ca-sh-emergencies-other-reachedsomething').disabled = 1;
	$('ca-sh-emergencies-other-celebrating').disabled = 1;
	$('ca-sh-emergencies-other-cantsleep').disabled = 1;
	$('ca-sh-emergencies-other-alone').disabled = 1;
	$('ca-sh-emergencies-other-other-1').disabled = 1;
	$('ca-sh-emergencies-other-other-2').disabled = 1;
	$('ca-sh-emergencies-other-other-3').disabled = 1;
	$('ca-sh-emergencies-company-jointoffer').disabled = 1;
	$('ca-sh-emergencies-company-smokingaround').disabled = 1;
	$('ca-sh-emergencies-company-leavehome').disabled = 1;
	$('ca-sh-emergencies-company-partying').disabled = 1;
	$('ca-sh-emergencies-company-comeover').disabled = 1;
	$('ca-sh-emergencies-company-other-1').disabled = 1;
	$('ca-sh-emergencies-company-other-2').disabled = 1;
	$('ca-sh-emergencies-company-other-3').disabled = 1;
	$('ca-sh-emergencies-feelings-strained').disabled = 1;
	$('ca-sh-emergencies-feelings-alone').disabled = 1;
	$('ca-sh-emergencies-feelings-nosuccess').disabled = 1;
	$('ca-sh-emergencies-feelings-nervous').disabled = 1;
	$('ca-sh-emergencies-feelings-wanttobehappy').disabled = 1;
	$('ca-sh-emergencies-feelings-other-1').disabled = 1;
	$('ca-sh-emergencies-feelings-other-2').disabled = 1;
	$('ca-sh-emergencies-feelings-other-3').disabled = 1;
	$('ca-sh-emergencies-thoughts-wontsuccess').disabled = 1;
	$('ca-sh-emergencies-thoughts-cantharm').disabled = 1;
	$('ca-sh-emergencies-thoughts-nothingmatters').disabled = 1;
	$('ca-sh-emergencies-thoughts-thinkabout').disabled = 1;
	$('ca-sh-emergencies-thoughts-canttake').disabled = 1;
	$('ca-sh-emergencies-thoughts-other-1').disabled = 1;
	$('ca-sh-emergencies-thoughts-other-2').disabled = 1;
	$('ca-sh-emergencies-thoughts-other-3').disabled = 1;

	$('ca-sh-emergencies-other-workschoolend-rating').disabled = 1;
	$('ca-sh-emergencies-other-reachedsomething-rating').disabled = 1;
	$('ca-sh-emergencies-other-celebrating-rating').disabled = 1;
	$('ca-sh-emergencies-other-cantsleep-rating').disabled = 1;
	$('ca-sh-emergencies-other-alone-rating').disabled = 1;
	$('ca-sh-emergencies-other-other-1-rating').disabled = 1;
	$('ca-sh-emergencies-other-other-2-rating').disabled = 1;
	$('ca-sh-emergencies-other-other-3-rating').disabled = 1;
	$('ca-sh-emergencies-company-jointoffer-rating').disabled = 1;
	$('ca-sh-emergencies-company-smokingaround-rating').disabled = 1;
	$('ca-sh-emergencies-company-leavehome-rating').disabled = 1;
	$('ca-sh-emergencies-company-partying-rating').disabled = 1;
	$('ca-sh-emergencies-company-comeover-rating').disabled = 1;
	$('ca-sh-emergencies-company-other-1-rating').disabled = 1;
	$('ca-sh-emergencies-company-other-2-rating').disabled = 1;
	$('ca-sh-emergencies-company-other-3-rating').disabled = 1;
	$('ca-sh-emergencies-feelings-strained-rating').disabled = 1;
	$('ca-sh-emergencies-feelings-alone-rating').disabled = 1;
	$('ca-sh-emergencies-feelings-nosuccess-rating').disabled = 1;
	$('ca-sh-emergencies-feelings-nervous-rating').disabled = 1;
	$('ca-sh-emergencies-feelings-wanttobehappy-rating').disabled = 1;
	$('ca-sh-emergencies-feelings-other-1-rating').disabled = 1;
	$('ca-sh-emergencies-feelings-other-2-rating').disabled = 1;
	$('ca-sh-emergencies-feelings-other-3-rating').disabled = 1;
	$('ca-sh-emergencies-thoughts-wontsuccess-rating').disabled = 1;
	$('ca-sh-emergencies-thoughts-cantharm-rating').disabled = 1;
	$('ca-sh-emergencies-thoughts-nothingmatters-rating').disabled = 1;
	$('ca-sh-emergencies-thoughts-thinkabout-rating').disabled = 1;
	$('ca-sh-emergencies-thoughts-canttake-rating').disabled = 1;
	$('ca-sh-emergencies-thoughts-other-1-rating').disabled = 1;
	$('ca-sh-emergencies-thoughts-other-2-rating').disabled = 1;
	$('ca-sh-emergencies-thoughts-other-3-rating').disabled = 1;

	$('ca-sh-emergencies-other-other-1-text').disabled = 1;
	$('ca-sh-emergencies-other-other-2-text').disabled = 1;
	$('ca-sh-emergencies-other-other-3-text').disabled = 1;
	$('ca-sh-emergencies-company-other-1-text').disabled = 1;
	$('ca-sh-emergencies-company-other-2-text').disabled = 1;
	$('ca-sh-emergencies-company-other-3-text').disabled = 1;
	$('ca-sh-emergencies-feelings-other-1-text').disabled = 1;
	$('ca-sh-emergencies-feelings-other-2-text').disabled = 1;
	$('ca-sh-emergencies-feelings-other-3-text').disabled = 1;
	$('ca-sh-emergencies-thoughts-other-1-text').disabled = 1;
	$('ca-sh-emergencies-thoughts-other-2-text').disabled = 1;
	$('ca-sh-emergencies-thoughts-other-3-text').disabled = 1;

	$('ca-sh-emergencies-top5-text').disabled = 1;

    new Ajax.Request( '/ca-ajax/selfhelp/emergencies/save.js.php', {
		method: 'post', parameters:	{
			otherworkschoolend: ($('ca-sh-emergencies-other-workschoolend').checked ? 'true' : 'false'),
			otherreachedsomething: ($('ca-sh-emergencies-other-reachedsomething').checked ? 'true' : 'false'),
			othercelebrating: ($('ca-sh-emergencies-other-celebrating').checked ? 'true' : 'false'),
			othercantsleep: ($('ca-sh-emergencies-other-cantsleep').checked ? 'true' : 'false'),
			otheralone: ($('ca-sh-emergencies-other-alone').checked ? 'true' : 'false'),
			otherother1: ($('ca-sh-emergencies-other-other-1').checked ? 'true' : 'false'),
			otherother2: ($('ca-sh-emergencies-other-other-2').checked ? 'true' : 'false'),
			otherother3: ($('ca-sh-emergencies-other-other-3').checked ? 'true' : 'false'),
			companyjointoffer: ($('ca-sh-emergencies-company-jointoffer').checked ? 'true' : 'false'),
			companysmokingaround: ($('ca-sh-emergencies-company-smokingaround').checked ? 'true' : 'false'),
			companyleavehome: ($('ca-sh-emergencies-company-leavehome').checked ? 'true' : 'false'),
			companypartying: ($('ca-sh-emergencies-company-partying').checked ? 'true' : 'false'),
			companycomeover: ($('ca-sh-emergencies-company-comeover').checked ? 'true' : 'false'),
			companyother1: ($('ca-sh-emergencies-company-other-1').checked ? 'true' : 'false'),
			companyother2: ($('ca-sh-emergencies-company-other-2').checked ? 'true' : 'false'),
			companyother3: ($('ca-sh-emergencies-company-other-3').checked ? 'true' : 'false'),
			feelingsstrained: ($('ca-sh-emergencies-feelings-strained').checked ? 'true' : 'false'),
			feelingsalone: ($('ca-sh-emergencies-feelings-alone').checked ? 'true' : 'false'),
			feelingsnosuccess: ($('ca-sh-emergencies-feelings-nosuccess').checked ? 'true' : 'false'),
			feelingsnervous: ($('ca-sh-emergencies-feelings-nervous').checked ? 'true' : 'false'),
			feelingswanttobehappy: ($('ca-sh-emergencies-feelings-wanttobehappy').checked ? 'true' : 'false'),
			feelingsother1: ($('ca-sh-emergencies-feelings-other-1').checked ? 'true' : 'false'),
			feelingsother2: ($('ca-sh-emergencies-feelings-other-2').checked ? 'true' : 'false'),
			feelingsother3: ($('ca-sh-emergencies-feelings-other-3').checked ? 'true' : 'false'),
			thoughtswontsuccess: ($('ca-sh-emergencies-thoughts-wontsuccess').checked ? 'true' : 'false'),
			thoughtscantharm: ($('ca-sh-emergencies-thoughts-cantharm').checked ? 'true' : 'false'),
			thoughtsnothingmatters: ($('ca-sh-emergencies-thoughts-nothingmatters').checked ? 'true' : 'false'),
			thoughtsthinkabout: ($('ca-sh-emergencies-thoughts-thinkabout').checked ? 'true' : 'false'),
			thoughtscanttake: ($('ca-sh-emergencies-thoughts-canttake').checked ? 'true' : 'false'),
			thoughtsother1: ($('ca-sh-emergencies-thoughts-other-1').checked ? 'true' : 'false'),
			thoughtsother2: ($('ca-sh-emergencies-thoughts-other-2').checked ? 'true' : 'false'),
			thoughtsother3: ($('ca-sh-emergencies-thoughts-other-3').checked ? 'true' : 'false'),

			otherother1text: $('ca-sh-emergencies-other-other-1-text').value,
			otherother2text: $('ca-sh-emergencies-other-other-2-text').value,
			otherother3text: $('ca-sh-emergencies-other-other-3-text').value,
			companyother1text: $('ca-sh-emergencies-company-other-1-text').value,
			companyother2text: $('ca-sh-emergencies-company-other-2-text').value,
			companyother3text: $('ca-sh-emergencies-company-other-3-text').value,
			feelingsother1text: $('ca-sh-emergencies-feelings-other-1-text').value,
			feelingsother2text: $('ca-sh-emergencies-feelings-other-2-text').value,
			feelingsother3text: $('ca-sh-emergencies-feelings-other-3-text').value,
			thoughtsother1text: $('ca-sh-emergencies-thoughts-other-1-text').value,
			thoughtsother2text: $('ca-sh-emergencies-thoughts-other-2-text').value,
			thoughtsother3text: $('ca-sh-emergencies-thoughts-other-3-text').value,

			otherworkschoolendrating: $('ca-sh-emergencies-other-workschoolend-rating-value').value,
			otherreachedsomethingrating: $('ca-sh-emergencies-other-reachedsomething-rating-value').value,
			othercelebratingrating: $('ca-sh-emergencies-other-celebrating-rating-value').value,
			othercantsleeprating: $('ca-sh-emergencies-other-cantsleep-rating-value').value,
			otheralonerating: $('ca-sh-emergencies-other-alone-rating-value').value,
			otherother1rating: $('ca-sh-emergencies-other-other-1-rating-value').value,
			otherother2rating: $('ca-sh-emergencies-other-other-2-rating-value').value,
			otherother3rating: $('ca-sh-emergencies-other-other-3-rating-value').value,
			companyjointofferrating: $('ca-sh-emergencies-company-jointoffer-rating-value').value,
			companysmokingaroundrating: $('ca-sh-emergencies-company-smokingaround-rating-value').value,
			companyleavehomerating: $('ca-sh-emergencies-company-leavehome-rating-value').value,
			companypartyingrating: $('ca-sh-emergencies-company-partying-rating-value').value,
			companycomeoverrating: $('ca-sh-emergencies-company-comeover-rating-value').value,
			companyother1rating: $('ca-sh-emergencies-company-other-1-rating-value').value,
			companyother2rating: $('ca-sh-emergencies-company-other-2-rating-value').value,
			companyother3rating: $('ca-sh-emergencies-company-other-3-rating-value').value,
			feelingsstrainedrating: $('ca-sh-emergencies-feelings-strained-rating-value').value,
			feelingsalonerating: $('ca-sh-emergencies-feelings-alone-rating-value').value,
			feelingsnosuccessrating: $('ca-sh-emergencies-feelings-nosuccess-rating-value').value,
			feelingsnervousrating: $('ca-sh-emergencies-feelings-nervous-rating-value').value,
			feelingswanttobehappyrating: $('ca-sh-emergencies-feelings-wanttobehappy-rating-value').value,
			feelingsother1rating: $('ca-sh-emergencies-feelings-other-1-rating-value').value,
			feelingsother2rating: $('ca-sh-emergencies-feelings-other-2-rating-value').value,
			feelingsother3rating: $('ca-sh-emergencies-feelings-other-3-rating-value').value,
			thoughtswontsuccessrating: $('ca-sh-emergencies-thoughts-wontsuccess-rating-value').value,
			thoughtscantharmrating: $('ca-sh-emergencies-thoughts-cantharm-rating-value').value,
			thoughtsnothingmattersrating: $('ca-sh-emergencies-thoughts-nothingmatters-rating-value').value,
			thoughtsthinkaboutrating: $('ca-sh-emergencies-thoughts-thinkabout-rating-value').value,
			thoughtscanttakerating: $('ca-sh-emergencies-thoughts-canttake-rating-value').value,
			thoughtsother1rating: $('ca-sh-emergencies-thoughts-other-1-rating-value').value,
			thoughtsother2rating: $('ca-sh-emergencies-thoughts-other-2-rating-value').value,
			thoughtsother3rating: $('ca-sh-emergencies-thoughts-other-3-rating-value').value,
			top5text: $('ca-sh-emergencies-top5-text').value
		}
    } );
}

function ca_sh_emergencies_mark()
{
	if( $('ca-sh-emergencies-other-workschoolend').checked )
	{
		if( $('ca-sh-emergencies-top5-text').value.indexOf( '- ' + $('ca-sh-emergencies-other-workschoolend-label').innerHTML ) < 0 )
			$('ca-sh-emergencies-top5-text').value += '- ' + $('ca-sh-emergencies-other-workschoolend-label').innerHTML + "\n";
	}
	else
		$('ca-sh-emergencies-top5-text').value = $('ca-sh-emergencies-top5-text').value.replace( '- ' + $('ca-sh-emergencies-other-workschoolend-label').innerHTML + "\n", '' );

	if( $('ca-sh-emergencies-other-reachedsomething').checked )
	{
		if( $('ca-sh-emergencies-top5-text').value.indexOf( '- ' + $('ca-sh-emergencies-other-reachedsomething-label').innerHTML ) < 0 )
			$('ca-sh-emergencies-top5-text').value += '- ' + $('ca-sh-emergencies-other-reachedsomething-label').innerHTML + "\n";
	}
	else
		$('ca-sh-emergencies-top5-text').value = $('ca-sh-emergencies-top5-text').value.replace( '- ' + $('ca-sh-emergencies-other-reachedsomething-label').innerHTML + "\n", '' );

	if( $('ca-sh-emergencies-other-celebrating').checked )
	{
		if( $('ca-sh-emergencies-top5-text').value.indexOf( '- ' + $('ca-sh-emergencies-other-celebrating-label').innerHTML ) < 0 )
			$('ca-sh-emergencies-top5-text').value += '- ' + $('ca-sh-emergencies-other-celebrating-label').innerHTML + "\n";
	}
	else
		$('ca-sh-emergencies-top5-text').value = $('ca-sh-emergencies-top5-text').value.replace( '- ' + $('ca-sh-emergencies-other-celebrating-label').innerHTML + "\n", '' );

	if( $('ca-sh-emergencies-other-cantsleep').checked )
	{
		if( $('ca-sh-emergencies-top5-text').value.indexOf( '- ' + $('ca-sh-emergencies-other-cantsleep-label').innerHTML ) < 0 )
			$('ca-sh-emergencies-top5-text').value += '- ' + $('ca-sh-emergencies-other-cantsleep-label').innerHTML + "\n";
	}
	else
		$('ca-sh-emergencies-top5-text').value = $('ca-sh-emergencies-top5-text').value.replace( '- ' + $('ca-sh-emergencies-other-cantsleep-label').innerHTML + "\n", '' );

	if( $('ca-sh-emergencies-other-alone').checked )
	{
		if( $('ca-sh-emergencies-top5-text').value.indexOf( '- ' + $('ca-sh-emergencies-other-alone-label').innerHTML ) < 0 )
			$('ca-sh-emergencies-top5-text').value += '- ' + $('ca-sh-emergencies-other-alone-label').innerHTML + "\n";
	}
	else
		$('ca-sh-emergencies-top5-text').value = $('ca-sh-emergencies-top5-text').value.replace( '- ' + $('ca-sh-emergencies-other-alone-label').innerHTML + "\n", '' );

	if( $('ca-sh-emergencies-other-other-1').checked )
	{
		if( $('ca-sh-emergencies-top5-text').value.indexOf( '- ' + $('ca-sh-emergencies-other-other-1-text').value ) < 0 )
			$('ca-sh-emergencies-top5-text').value += '- ' + $('ca-sh-emergencies-other-other-1-text').value + "\n";
	}
	else
		$('ca-sh-emergencies-top5-text').value = $('ca-sh-emergencies-top5-text').value.replace( '- ' + $('ca-sh-emergencies-other-other-1-text').value + "\n", '' );

	if( $('ca-sh-emergencies-other-other-2').checked )
	{
		if( $('ca-sh-emergencies-top5-text').value.indexOf( '- ' + $('ca-sh-emergencies-other-other-2-text').value ) < 0 )
			$('ca-sh-emergencies-top5-text').value += '- ' + $('ca-sh-emergencies-other-other-2-text').value + "\n";
	}
	else
		$('ca-sh-emergencies-top5-text').value = $('ca-sh-emergencies-top5-text').value.replace( '- ' + $('ca-sh-emergencies-other-other-2-text').value + "\n", '' );

	if( $('ca-sh-emergencies-other-other-3').checked )
	{
		if( $('ca-sh-emergencies-top5-text').value.indexOf( '- ' + $('ca-sh-emergencies-other-other-3-text').value ) < 0 )
			$('ca-sh-emergencies-top5-text').value += '- ' + $('ca-sh-emergencies-other-other-3-text').value + "\n";
	}
	else
		$('ca-sh-emergencies-top5-text').value = $('ca-sh-emergencies-top5-text').value.replace( '- ' + $('ca-sh-emergencies-other-other-3-text').value + "\n", '' );

	if( $('ca-sh-emergencies-company-jointoffer').checked )
	{
		if( $('ca-sh-emergencies-top5-text').value.indexOf( '- ' + $('ca-sh-emergencies-company-jointoffer-label').innerHTML ) < 0 )
			$('ca-sh-emergencies-top5-text').value += '- ' + $('ca-sh-emergencies-company-jointoffer-label').innerHTML + "\n";
	}
	else
		$('ca-sh-emergencies-top5-text').value = $('ca-sh-emergencies-top5-text').value.replace( '- ' + $('ca-sh-emergencies-company-jointoffer-label').innerHTML + "\n", '' );

	if( $('ca-sh-emergencies-company-smokingaround').checked )
	{
		if( $('ca-sh-emergencies-top5-text').value.indexOf( '- ' + $('ca-sh-emergencies-company-smokingaround-label').innerHTML ) < 0 )
			$('ca-sh-emergencies-top5-text').value += '- ' + $('ca-sh-emergencies-company-smokingaround-label').innerHTML + "\n";
	}
	else
		$('ca-sh-emergencies-top5-text').value = $('ca-sh-emergencies-top5-text').value.replace( '- ' + $('ca-sh-emergencies-company-smokingaround-label').innerHTML + "\n", '' );

	if( $('ca-sh-emergencies-company-leavehome').checked )
	{
		if( $('ca-sh-emergencies-top5-text').value.indexOf( '- ' + $('ca-sh-emergencies-company-leavehome-label').innerHTML ) < 0 )
			$('ca-sh-emergencies-top5-text').value += '- ' + $('ca-sh-emergencies-company-leavehome-label').innerHTML + "\n";
	}
	else
		$('ca-sh-emergencies-top5-text').value = $('ca-sh-emergencies-top5-text').value.replace( '- ' + $('ca-sh-emergencies-company-leavehome-label').innerHTML + "\n", '' );

	if( $('ca-sh-emergencies-company-partying').checked )
	{
		if( $('ca-sh-emergencies-top5-text').value.indexOf( '- ' + $('ca-sh-emergencies-company-partying-label').innerHTML ) < 0 )
			$('ca-sh-emergencies-top5-text').value += '- ' + $('ca-sh-emergencies-company-partying-label').innerHTML + "\n";
	}
	else
		$('ca-sh-emergencies-top5-text').value = $('ca-sh-emergencies-top5-text').value.replace( '- ' + $('ca-sh-emergencies-company-partying-label').innerHTML + "\n", '' );

	if( $('ca-sh-emergencies-company-comeover').checked )
	{
		if( $('ca-sh-emergencies-top5-text').value.indexOf( '- ' + $('ca-sh-emergencies-company-comeover-label').innerHTML ) < 0 )
			$('ca-sh-emergencies-top5-text').value += '- ' + $('ca-sh-emergencies-company-comeover-label').innerHTML + "\n";
	}
	else
		$('ca-sh-emergencies-top5-text').value = $('ca-sh-emergencies-top5-text').value.replace( '- ' + $('ca-sh-emergencies-company-comeover-label').innerHTML + "\n", '' );

	if( $('ca-sh-emergencies-company-other-1').checked )
	{
		if( $('ca-sh-emergencies-top5-text').value.indexOf( '- ' + $('ca-sh-emergencies-company-other-1-text').value ) < 0 )
			$('ca-sh-emergencies-top5-text').value += '- ' + $('ca-sh-emergencies-company-other-1-text').value + "\n";
	}
	else
		$('ca-sh-emergencies-top5-text').value = $('ca-sh-emergencies-top5-text').value.replace( '- ' + $('ca-sh-emergencies-company-other-1-text').value + "\n", '' );

	if( $('ca-sh-emergencies-company-other-2').checked )
	{
		if( $('ca-sh-emergencies-top5-text').value.indexOf( '- ' + $('ca-sh-emergencies-company-other-2-text').value ) < 0 )
			$('ca-sh-emergencies-top5-text').value += '- ' + $('ca-sh-emergencies-company-other-2-text').value + "\n";
	}
	else
		$('ca-sh-emergencies-top5-text').value = $('ca-sh-emergencies-top5-text').value.replace( '- ' + $('ca-sh-emergencies-company-other-2-text').value + "\n", '' );

	if( $('ca-sh-emergencies-company-other-3').checked )
	{
		if( $('ca-sh-emergencies-top5-text').value.indexOf( '- ' + $('ca-sh-emergencies-company-other-3-text').value ) < 0 )
			$('ca-sh-emergencies-top5-text').value += '- ' + $('ca-sh-emergencies-company-other-3-text').value + "\n";
	}
	else
		$('ca-sh-emergencies-top5-text').value = $('ca-sh-emergencies-top5-text').value.replace( '- ' + $('ca-sh-emergencies-company-other-3-text').value + "\n", '' );

	if( $('ca-sh-emergencies-feelings-strained').checked )
	{
		if( $('ca-sh-emergencies-top5-text').value.indexOf( '- ' + $('ca-sh-emergencies-feelings-strained-label').innerHTML ) < 0 )
			$('ca-sh-emergencies-top5-text').value += '- ' + $('ca-sh-emergencies-feelings-strained-label').innerHTML + "\n";
	}
	else
		$('ca-sh-emergencies-top5-text').value = $('ca-sh-emergencies-top5-text').value.replace( '- ' + $('ca-sh-emergencies-feelings-strained-label').innerHTML + "\n", '' );

	if( $('ca-sh-emergencies-feelings-alone').checked )
	{
		if( $('ca-sh-emergencies-top5-text').value.indexOf( '- ' + $('ca-sh-emergencies-feelings-alone-label').innerHTML ) < 0 )
			$('ca-sh-emergencies-top5-text').value += '- ' + $('ca-sh-emergencies-feelings-alone-label').innerHTML + "\n";
	}
	else
		$('ca-sh-emergencies-top5-text').value = $('ca-sh-emergencies-top5-text').value.replace( '- ' + $('ca-sh-emergencies-feelings-alone-label').innerHTML + "\n", '' );

	if( $('ca-sh-emergencies-feelings-nosuccess').checked )
	{
		if( $('ca-sh-emergencies-top5-text').value.indexOf( '- ' + $('ca-sh-emergencies-feelings-nosuccess-label').innerHTML ) < 0 )
			$('ca-sh-emergencies-top5-text').value += '- ' + $('ca-sh-emergencies-feelings-nosuccess-label').innerHTML + "\n";
	}
	else
		$('ca-sh-emergencies-top5-text').value = $('ca-sh-emergencies-top5-text').value.replace( '- ' + $('ca-sh-emergencies-feelings-nosuccess-label').innerHTML + "\n", '' );

	if( $('ca-sh-emergencies-feelings-nervous').checked )
	{
		if( $('ca-sh-emergencies-top5-text').value.indexOf( '- ' + $('ca-sh-emergencies-feelings-nervous-label').innerHTML ) < 0 )
			$('ca-sh-emergencies-top5-text').value += '- ' + $('ca-sh-emergencies-feelings-nervous-label').innerHTML + "\n";
	}
	else
		$('ca-sh-emergencies-top5-text').value = $('ca-sh-emergencies-top5-text').value.replace( '- ' + $('ca-sh-emergencies-feelings-nervous-label').innerHTML + "\n", '' );

	if( $('ca-sh-emergencies-feelings-wanttobehappy').checked )
	{
		if( $('ca-sh-emergencies-top5-text').value.indexOf( '- ' + $('ca-sh-emergencies-feelings-wanttobehappy-label').innerHTML ) < 0 )
			$('ca-sh-emergencies-top5-text').value += '- ' + $('ca-sh-emergencies-feelings-wanttobehappy-label').innerHTML + "\n";
	}
	else
		$('ca-sh-emergencies-top5-text').value = $('ca-sh-emergencies-top5-text').value.replace( '- ' + $('ca-sh-emergencies-feelings-wanttobehappy-label').innerHTML + "\n", '' );

	if( $('ca-sh-emergencies-feelings-other-1').checked )
	{
		if( $('ca-sh-emergencies-top5-text').value.indexOf( '- ' + $('ca-sh-emergencies-feelings-other-1-text').value ) < 0 )
			$('ca-sh-emergencies-top5-text').value += '- ' + $('ca-sh-emergencies-feelings-other-1-text').value + "\n";
	}
	else
		$('ca-sh-emergencies-top5-text').value = $('ca-sh-emergencies-top5-text').value.replace( '- ' + $('ca-sh-emergencies-feelings-other-1-text').value + "\n", '' );

	if( $('ca-sh-emergencies-feelings-other-2').checked )
	{
		if( $('ca-sh-emergencies-top5-text').value.indexOf( '- ' + $('ca-sh-emergencies-feelings-other-2-text').value ) < 0 )
			$('ca-sh-emergencies-top5-text').value += '- ' + $('ca-sh-emergencies-feelings-other-2-text').value + "\n";
	}
	else
		$('ca-sh-emergencies-top5-text').value = $('ca-sh-emergencies-top5-text').value.replace( '- ' + $('ca-sh-emergencies-feelings-other-2-text').value + "\n", '' );

	if( $('ca-sh-emergencies-feelings-other-3').checked )
	{
		if( $('ca-sh-emergencies-top5-text').value.indexOf( '- ' + $('ca-sh-emergencies-feelings-other-3-text').value ) < 0 )
			$('ca-sh-emergencies-top5-text').value += '- ' + $('ca-sh-emergencies-feelings-other-3-text').value + "\n";
	}
	else
		$('ca-sh-emergencies-top5-text').value = $('ca-sh-emergencies-top5-text').value.replace( '- ' + $('ca-sh-emergencies-feelings-other-3-text').value + "\n", '' );

	if( $('ca-sh-emergencies-thoughts-wontsuccess').checked )
	{
		if( $('ca-sh-emergencies-top5-text').value.indexOf( '- ' + $('ca-sh-emergencies-thoughts-wontsuccess-label').innerHTML ) < 0 )
			$('ca-sh-emergencies-top5-text').value += '- ' + $('ca-sh-emergencies-thoughts-wontsuccess-label').innerHTML + "\n";
	}
	else
		$('ca-sh-emergencies-top5-text').value = $('ca-sh-emergencies-top5-text').value.replace( '- ' + $('ca-sh-emergencies-thoughts-wontsuccess-label').innerHTML + "\n", '' );

	if( $('ca-sh-emergencies-thoughts-cantharm').checked )
	{
		if( $('ca-sh-emergencies-top5-text').value.indexOf( '- ' + $('ca-sh-emergencies-thoughts-cantharm-label').innerHTML ) < 0 )
			$('ca-sh-emergencies-top5-text').value += '- ' + $('ca-sh-emergencies-thoughts-cantharm-label').innerHTML + "\n";
	}
	else
		$('ca-sh-emergencies-top5-text').value = $('ca-sh-emergencies-top5-text').value.replace( '- ' + $('ca-sh-emergencies-thoughts-cantharm-label').innerHTML + "\n", '' );

	if( $('ca-sh-emergencies-thoughts-nothingmatters').checked )
	{
		if( $('ca-sh-emergencies-top5-text').value.indexOf( '- ' + $('ca-sh-emergencies-thoughts-nothingmatters-label').innerHTML ) < 0 )
			$('ca-sh-emergencies-top5-text').value += '- ' + $('ca-sh-emergencies-thoughts-nothingmatters-label').innerHTML + "\n";
	}
	else
		$('ca-sh-emergencies-top5-text').value = $('ca-sh-emergencies-top5-text').value.replace( '- ' + $('ca-sh-emergencies-thoughts-nothingmatters-label').innerHTML + "\n", '' );

	if( $('ca-sh-emergencies-thoughts-thinkabout').checked )
	{
		if( $('ca-sh-emergencies-top5-text').value.indexOf( '- ' + $('ca-sh-emergencies-thoughts-thinkabout-label').innerHTML ) < 0 )
			$('ca-sh-emergencies-top5-text').value += '- ' + $('ca-sh-emergencies-thoughts-thinkabout-label').innerHTML + "\n";
	}
	else
		$('ca-sh-emergencies-top5-text').value = $('ca-sh-emergencies-top5-text').value.replace( '- ' + $('ca-sh-emergencies-thoughts-thinkabout-label').innerHTML + "\n", '' );

	if( $('ca-sh-emergencies-thoughts-canttake').checked )
	{
		if( $('ca-sh-emergencies-top5-text').value.indexOf( '- ' + $('ca-sh-emergencies-thoughts-canttake-label').innerHTML ) < 0 )
			$('ca-sh-emergencies-top5-text').value += '- ' + $('ca-sh-emergencies-thoughts-canttake-label').innerHTML + "\n";
	}
	else
		$('ca-sh-emergencies-top5-text').value = $('ca-sh-emergencies-top5-text').value.replace( '- ' + $('ca-sh-emergencies-thoughts-canttake-label').innerHTML + "\n", '' );

	if( $('ca-sh-emergencies-thoughts-other-1').checked )
	{
		if( $('ca-sh-emergencies-top5-text').value.indexOf( '- ' + $('ca-sh-emergencies-thoughts-other-1-text').value ) < 0 )
			$('ca-sh-emergencies-top5-text').value += '- ' + $('ca-sh-emergencies-thoughts-other-1-text').value + "\n";
	}
	else
		$('ca-sh-emergencies-top5-text').value = $('ca-sh-emergencies-top5-text').value.replace( '- ' + $('ca-sh-emergencies-thoughts-other-1-text').value + "\n", '' );

	if( $('ca-sh-emergencies-thoughts-other-2').checked )
	{
		if( $('ca-sh-emergencies-top5-text').value.indexOf( '- ' + $('ca-sh-emergencies-thoughts-other-2-text').value ) < 0 )
			$('ca-sh-emergencies-top5-text').value += '- ' + $('ca-sh-emergencies-thoughts-other-2-text').value + "\n";
	}
	else
		$('ca-sh-emergencies-top5-text').value = $('ca-sh-emergencies-top5-text').value.replace( '- ' + $('ca-sh-emergencies-thoughts-other-2-text').value + "\n", '' );

	if( $('ca-sh-emergencies-thoughts-other-3').checked )
	{
		if( $('ca-sh-emergencies-top5-text').value.indexOf( '- ' + $('ca-sh-emergencies-thoughts-other-3-text').value ) < 0 )
			$('ca-sh-emergencies-top5-text').value += '- ' + $('ca-sh-emergencies-thoughts-other-3-text').value + "\n";
	}
	else
		$('ca-sh-emergencies-top5-text').value = $('ca-sh-emergencies-top5-text').value.replace( '- ' + $('ca-sh-emergencies-thoughts-other-3-text').value + "\n", '' );
}

function ca_sh_emergencies_top5Save()
{
	$('ca-sh-emergencies-loading').show();
	$('ca-sh-emergencies-error').hide();
	$('ca-sh-emergencies-top5-text').disabled = 1;

    new Ajax.Request( '/ca-ajax/selfhelp/emergencies/top5save.js.php', {
		method: 'post', parameters:	{
			top5text: $('ca-sh-emergencies-top5-text').value
		}
    } );
}

function ca_sh_messages_pagesClose()
{
	var i = 1;
	while( $('ca-sh_messages-page-' + i) )
	{
		$('ca-sh_messages-page-' + i).hide();
		$('ca-sh-messages-pagemenu-' + i).className = $( 'ca-sh-messages-pagemenu-' + i ).className.replace( /selected/, '' );
		i++;
	}
}

function ca_sh_messages_pageOpen( pageNum )
{
	if( !pageNum )
		pageNum = 1;
	ca_sh_messages_pagesClose();
	if( $( 'ca-sh_messages-page-' + pageNum ) )
	{
		$( 'ca-sh_messages-page-' + pageNum ).show();
		$( 'ca-sh-messages-pagemenu-' + pageNum ).className = $( 'ca-sh-messages-pagemenu-' + pageNum ).className + 'selected';
	}
}

function ca_sh_messages_newMessageSend()
{
	$('ca-sh-messages-newmessage-text').disabled = 1;
	$('ca-sh-messages-newmessage-subject').disabled = 1;
	$('ca-sh-messages-newmessage-loading').show();
	$('ca-sh-messages-newmessage-error').hide();
    new Ajax.Request( '/ca-ajax/selfhelp/messages/newmessage.js.php', {
		method: 'post', parameters:	{
			subject: $('ca-sh-messages-newmessage-subject').value,
			text: $('ca-sh-messages-newmessage-text').value
		}
	} );
}

function ca_sh_messages_open( index )
{
	if( $('ca-sh-messages-' + index + '-body').style.display != 'none' )
		new Effect.BlindUp( $('ca-sh-messages-' + index + '-body'), { duration: 0.2 } );
	else
		new Effect.BlindDown( $('ca-sh-messages-' + index + '-body'), { duration: 0.2 } );
}

function ca_sh_messages_delete( index )
{
	if( !confirm( 'Biztosan törölni akarod az üzenetet?' ) )
		return;

	$('ca-sh-messages-list-loading').show();
	$('ca-sh-messages-list-error').hide();
    new Ajax.Request( '/ca-ajax/selfhelp/messages/deletemessage.js.php', {
		method: 'post', parameters:	{
			index: index
		}
	} );
}

function ca_sh_proscons_pagesClose()
{
	var i = 1;
	while( $('ca-sh_proscons-page-' + i) )
	{
		$('ca-sh_proscons-page-' + i).hide();
		$('ca-sh-proscons-pagemenu-' + i).className = $( 'ca-sh-proscons-pagemenu-' + i ).className.replace( /selected/, '' );
		i++;
	}
}

function ca_sh_proscons_pageOpen( pageNum )
{
	if( !pageNum )
		pageNum = 1;
	ca_sh_proscons_pagesClose();
	if( $( 'ca-sh_proscons-page-' + pageNum ) )
	{
		$( 'ca-sh_proscons-page-' + pageNum ).show();
		$( 'ca-sh-proscons-pagemenu-' + pageNum ).className = $( 'ca-sh-proscons-pagemenu-' + pageNum ).className + 'selected';
	}

	if( pageNum == 2 )
		ca_sh_proscons_generateSum();
}

function ca_sh_proscons_save()
{
	$('ca-sh-proscons-loading').show();
	$('ca-sh-proscons-error').hide();

	$('ca-sh-proscons-pro-feelgood').disabled = 1;
	$('ca-sh-proscons-pro-relax').disabled = 1;
	$('ca-sh-proscons-pro-laugh').disabled = 1;
	$('ca-sh-proscons-pro-other-1').disabled = 1;
	$('ca-sh-proscons-pro-other-2').disabled = 1;
	$('ca-sh-proscons-pro-other-3').disabled = 1;
	$('ca-sh-proscons-pro-other-4').disabled = 1;
	$('ca-sh-proscons-pro-other-5').disabled = 1;
	$('ca-sh-proscons-con-nointerests').disabled = 1;
	$('ca-sh-proscons-con-smokingfriends').disabled = 1;
	$('ca-sh-proscons-con-paranoid').disabled = 1;
	$('ca-sh-proscons-con-other-1').disabled = 1;
	$('ca-sh-proscons-con-other-2').disabled = 1;
	$('ca-sh-proscons-con-other-3').disabled = 1;
	$('ca-sh-proscons-con-other-4').disabled = 1;
	$('ca-sh-proscons-con-other-5').disabled = 1;

    new Ajax.Request( '/ca-ajax/selfhelp/proscons/save.js.php', {
		method: 'post', parameters:	{
			profeelgood: ($('ca-sh-proscons-pro-feelgood').checked ? 'true' : 'false'),
			prorelax: ($('ca-sh-proscons-pro-relax').checked ? 'true' : 'false'),
			prolaugh: ($('ca-sh-proscons-pro-laugh').checked ? 'true' : 'false'),
			proother1: $('ca-sh-proscons-pro-other-1').value,
			proother2: $('ca-sh-proscons-pro-other-2').value,
			proother3: $('ca-sh-proscons-pro-other-3').value,
			proother4: $('ca-sh-proscons-pro-other-4').value,
			proother5: $('ca-sh-proscons-pro-other-5').value,
			connointerests: ($('ca-sh-proscons-con-nointerests').checked ? 'true' : 'false'),
			consmokingfriends: ($('ca-sh-proscons-con-smokingfriends').checked ? 'true' : 'false'),
			conparanoid: ($('ca-sh-proscons-con-paranoid').checked ? 'true' : 'false'),
			conother1: $('ca-sh-proscons-con-other-1').value,
			conother2: $('ca-sh-proscons-con-other-2').value,
			conother3: $('ca-sh-proscons-con-other-3').value,
			conother4: $('ca-sh-proscons-con-other-4').value,
			conother5: $('ca-sh-proscons-con-other-5').value
		}
    } );
}

function ca_sh_prosconscut_save()
{
	$('ca-sh-prosconscut-loading').show();
	$('ca-sh-prosconscut-error').hide();

	$('ca-sh-proscons-cutpro-moreenergy').disabled = 1;
	$('ca-sh-proscons-cutpro-healthier').disabled = 1;
	$('ca-sh-proscons-cutpro-doother').disabled = 1;
	$('ca-sh-proscons-cutpro-other-1').disabled = 1;
	$('ca-sh-proscons-cutpro-other-2').disabled = 1;
	$('ca-sh-proscons-cutpro-other-3').disabled = 1;
	$('ca-sh-proscons-cutpro-other-4').disabled = 1;
	$('ca-sh-proscons-cutpro-other-5').disabled = 1;
	$('ca-sh-proscons-cutcon-sleep').disabled = 1;
	$('ca-sh-proscons-cutcon-missmates').disabled = 1;
	$('ca-sh-proscons-cutcon-anxious').disabled = 1;
	$('ca-sh-proscons-cutcon-other-1').disabled = 1;
	$('ca-sh-proscons-cutcon-other-2').disabled = 1;
	$('ca-sh-proscons-cutcon-other-3').disabled = 1;
	$('ca-sh-proscons-cutcon-other-4').disabled = 1;
	$('ca-sh-proscons-cutcon-other-5').disabled = 1;

    new Ajax.Request( '/ca-ajax/selfhelp/proscons/savecut.js.php', {
		method: 'post', parameters:	{
			cutpromoreenergy: ($('ca-sh-proscons-cutpro-moreenergy').checked ? 'true' : 'false'),
			cutprohealthier: ($('ca-sh-proscons-cutpro-healthier').checked ? 'true' : 'false'),
			cutprodoother: ($('ca-sh-proscons-cutpro-doother').checked ? 'true' : 'false'),
			cutproother1: $('ca-sh-proscons-cutpro-other-1').value,
			cutproother2: $('ca-sh-proscons-cutpro-other-2').value,
			cutproother3: $('ca-sh-proscons-cutpro-other-3').value,
			cutproother4: $('ca-sh-proscons-cutpro-other-4').value,
			cutproother5: $('ca-sh-proscons-cutpro-other-5').value,
			cutconsleep: ($('ca-sh-proscons-cutcon-sleep').checked ? 'true' : 'false'),
			cutconmissmates: ($('ca-sh-proscons-cutcon-missmates').checked ? 'true' : 'false'),
			cutconanxious: ($('ca-sh-proscons-cutcon-anxious').checked ? 'true' : 'false'),
			cutconother1: $('ca-sh-proscons-cutcon-other-1').value,
			cutconother2: $('ca-sh-proscons-cutcon-other-2').value,
			cutconother3: $('ca-sh-proscons-cutcon-other-3').value,
			cutconother4: $('ca-sh-proscons-cutcon-other-4').value,
			cutconother5: $('ca-sh-proscons-cutcon-other-5').value
		}
    } );
}

function ca_sh_proscons_generateSum()
{
	$('ca-sh-proscons-sum-pro').innerHTML = '<ul>';
	if( $('ca-sh-proscons-pro-feelgood').checked )
		$('ca-sh-proscons-sum-pro').innerHTML += '<li>jó közérzetem lesz tőle</li>';
	if( $('ca-sh-proscons-pro-relax').checked )
		$('ca-sh-proscons-sum-pro').innerHTML += '<li>megnyugtat</li>';
	if( $('ca-sh-proscons-pro-laugh').checked )
		$('ca-sh-proscons-sum-pro').innerHTML += '<li>jókat nevetek a haverjaimmal</li>';
	if( $('ca-sh-proscons-pro-other-1').value != '' )
		$('ca-sh-proscons-sum-pro').innerHTML += '<li>' + $('ca-sh-proscons-pro-other-1').value + '</li>';
	if( $('ca-sh-proscons-pro-other-2').value != '' )
		$('ca-sh-proscons-sum-pro').innerHTML += '<li>' + $('ca-sh-proscons-pro-other-2').value + '</li>';
	if( $('ca-sh-proscons-pro-other-3').value != '' )
		$('ca-sh-proscons-sum-pro').innerHTML += '<li>' + $('ca-sh-proscons-pro-other-3').value + '</li>';
	if( $('ca-sh-proscons-pro-other-4').value != '' )
		$('ca-sh-proscons-sum-pro').innerHTML += '<li>' + $('ca-sh-proscons-pro-other-4').value + '</li>';
	if( $('ca-sh-proscons-pro-other-5').value != '' )
		$('ca-sh-proscons-sum-pro').innerHTML += '<li>' + $('ca-sh-proscons-pro-other-5').value + '</li>';
	$('ca-sh-proscons-sum-pro').innerHTML += '</ul>';

	$('ca-sh-proscons-sum-con').innerHTML = '<ul>';
	if( $('ca-sh-proscons-con-nointerests').checked )
		$('ca-sh-proscons-sum-con').innerHTML += '<li>nem érdekel semmi más</li>';
	if( $('ca-sh-proscons-con-smokingfriends').checked )
		$('ca-sh-proscons-sum-con').innerHTML += '<li>csak füves haverjaim vannak</li>';
	if( $('ca-sh-proscons-con-paranoid').checked )
		$('ca-sh-proscons-sum-con').innerHTML += '<li>néha paranoiás vagyok tőle</li>';
	if( $('ca-sh-proscons-con-other-1').value != '' )
		$('ca-sh-proscons-sum-con').innerHTML += '<li>' + $('ca-sh-proscons-con-other-1').value + '</li>';
	if( $('ca-sh-proscons-con-other-2').value != '' )
		$('ca-sh-proscons-sum-con').innerHTML += '<li>' + $('ca-sh-proscons-con-other-2').value + '</li>';
	if( $('ca-sh-proscons-con-other-3').value != '' )
		$('ca-sh-proscons-sum-con').innerHTML += '<li>' + $('ca-sh-proscons-con-other-3').value + '</li>';
	if( $('ca-sh-proscons-con-other-4').value != '' )
		$('ca-sh-proscons-sum-con').innerHTML += '<li>' + $('ca-sh-proscons-con-other-4').value + '</li>';
	if( $('ca-sh-proscons-con-other-5').value != '' )
		$('ca-sh-proscons-sum-con').innerHTML += '<li>' + $('ca-sh-proscons-con-other-5').value + '</li>';
	$('ca-sh-proscons-sum-con').innerHTML += '</ul>';

	$('ca-sh-proscons-sum-cutpro').innerHTML = '<ul>';
	if( $('ca-sh-proscons-cutpro-moreenergy').checked )
		$('ca-sh-proscons-sum-cutpro').innerHTML += '<li>több energiám lesz</li>';
	if( $('ca-sh-proscons-cutpro-healthier').checked )
		$('ca-sh-proscons-sum-cutpro').innerHTML += '<li>egészségesebbnek fogom érezni magam</li>';
	if( $('ca-sh-proscons-cutpro-doother').checked )
		$('ca-sh-proscons-sum-cutpro').innerHTML += '<li>más dolgokat is fogok tudni csinálni</li>';
	if( $('ca-sh-proscons-cutpro-other-1').value != '' )
		$('ca-sh-proscons-sum-cutpro').innerHTML += '<li>' + $('ca-sh-proscons-cutpro-other-1').value + '</li>';
	if( $('ca-sh-proscons-cutpro-other-2').value != '' )
		$('ca-sh-proscons-sum-cutpro').innerHTML += '<li>' + $('ca-sh-proscons-cutpro-other-2').value + '</li>';
	if( $('ca-sh-proscons-cutpro-other-3').value != '' )
		$('ca-sh-proscons-sum-cutpro').innerHTML += '<li>' + $('ca-sh-proscons-cutpro-other-3').value + '</li>';
	if( $('ca-sh-proscons-cutpro-other-4').value != '' )
		$('ca-sh-proscons-sum-cutpro').innerHTML += '<li>' + $('ca-sh-proscons-cutpro-other-4').value + '</li>';
	if( $('ca-sh-proscons-cutpro-other-5').value != '' )
		$('ca-sh-proscons-sum-cutpro').innerHTML += '<li>' + $('ca-sh-proscons-cutpro-other-5').value + '</li>';
	$('ca-sh-proscons-sum-cutpro').innerHTML += '</ul>';

	$('ca-sh-proscons-sum-cutcon').innerHTML = '<ul>';
	if( $('ca-sh-proscons-cutcon-sleep').checked )
		$('ca-sh-proscons-sum-cutcon').innerHTML += '<li>nem fogok jól aludni</li>';
	if( $('ca-sh-proscons-cutcon-missmates').checked )
		$('ca-sh-proscons-sum-cutcon').innerHTML += '<li>hiányozni fognak a füves haverjaim</li>';
	if( $('ca-sh-proscons-cutcon-anxious').checked )
		$('ca-sh-proscons-sum-cutcon').innerHTML += '<li>ideges leszek, ha nem szívhatok</li>';
	if( $('ca-sh-proscons-cutcon-other-1').value != '' )
		$('ca-sh-proscons-sum-cutcon').innerHTML += '<li>' + $('ca-sh-proscons-cutcon-other-1').value + '</li>';
	if( $('ca-sh-proscons-cutcon-other-2').value != '' )
		$('ca-sh-proscons-sum-cutcon').innerHTML += '<li>' + $('ca-sh-proscons-cutcon-other-2').value + '</li>';
	if( $('ca-sh-proscons-cutcon-other-3').value != '' )
		$('ca-sh-proscons-sum-cutcon').innerHTML += '<li>' + $('ca-sh-proscons-cutcon-other-3').value + '</li>';
	if( $('ca-sh-proscons-cutcon-other-4').value != '' )
		$('ca-sh-proscons-sum-cutcon').innerHTML += '<li>' + $('ca-sh-proscons-cutcon-other-4').value + '</li>';
	if( $('ca-sh-proscons-cutcon-other-5').value != '' )
		$('ca-sh-proscons-sum-cutcon').innerHTML += '<li>' + $('ca-sh-proscons-cutcon-other-5').value + '</li>';
	$('ca-sh-proscons-sum-cutcon').innerHTML += '</ul>';
}

function ca_aboutcannabis_pagesClose()
{
	var i = 1;
	while( $('ca-aboutcannabis-page-' + i) )
	{
		$('ca-aboutcannabis-page-' + i).hide();
		$('ca-aboutcannabis-menuitem-' + i).className = '';
		i++;
	}
}

function ca_aboutcannabis_pageOpen( pageNum )
{
	if( !pageNum )
		pageNum = 1;
	ca_aboutcannabis_pagesClose();
	if( $( 'ca-aboutcannabis-page-' + pageNum ) )
	{
		$( 'ca-aboutcannabis-page-' + pageNum ).show();
		$('ca-aboutcannabis-menuitem-' + pageNum).className = 'currentpage';
	}
}

function ca_calendar( parent )
{
	this.parent = parent;
	this.displayedDate = new Date();
	this.selectedDate = new Date();
	this.className = parent;
	this.updateCallBack = null;
	this.dayClickedCallBack = null;
	this.updateTimer = null;
	this.monthDisplay = null;
	this.yearDisplay = null;
	this.window = null;

	this.update = ca_calendar_update;
	this.getDaysInMonth = ca_calendar_getDaysInMonth;
	this.incMonth = ca_calendar_incMonth;
	this.decMonth = ca_calendar_decMonth;
	this.incYear = ca_calendar_incYear;
	this.decYear = ca_calendar_decYear;
	this.dayClicked = ca_calendar_dayClicked;
	this.getSelectedDate = ca_calendar_getSelectedDate;
	this.addToDayClassName = ca_calendar_addToDayClassName;
	this.dragStart = ca_calendar_dragStart;
	this.move = ca_calendar_move;
	this.close = ca_calendar_close;
	this.open = ca_calendar_open;

	this.table = document.createElement( 'table' );
	this.thead = document.createElement( 'thead' );
	var theadtr = document.createElement( 'tr' );
	this.thead.appendChild( theadtr );
	var dayName = document.createElement( 'td' );
	dayName.innerHTML = 'H';
	theadtr.appendChild( dayName );
	dayName = document.createElement( 'td' );
	dayName.innerHTML = 'K';
	theadtr.appendChild( dayName );
	dayName = document.createElement( 'td' );
	dayName.innerHTML = 'S';
	theadtr.appendChild( dayName );
	dayName = document.createElement( 'td' );
	dayName.innerHTML = 'C';
	theadtr.appendChild( dayName );
	dayName = document.createElement( 'td' );
	dayName.innerHTML = 'P';
	theadtr.appendChild( dayName );
	dayName = document.createElement( 'td' );
	dayName.innerHTML = 'S';
	theadtr.appendChild( dayName );
	dayName = document.createElement( 'td' );
	dayName.innerHTML = 'V';
	theadtr.appendChild( dayName );

	this.tbody = document.createElement( 'tbody' );
	this.table.appendChild( this.thead );
	this.table.appendChild( this.tbody );
	$(parent).appendChild( this.table );
	this.update();
}

function ca_calendar_getDaysInMonth( date )
{
	var fLeapYear = false;
	if( ( date.getFullYear() % 400 == 0 ) || ( date.getFullYear() % 100 != 0 && date.getFullYear() % 4 == 0 ) )
		fLeapYear = true;

	var nDaysInMonth = 31;
	switch( date.getMonth() )
	{
	case 3:
	case 5:
	case 8:
	case 10:
		nDaysInMonth = 30;
		break;
	case 1:
		if( fLeapYear )
			nDaysInMonth = 29;
		else
			nDaysInMonth = 28;
		break;
	}
	return nDaysInMonth;
}

function ca_calendar_update()
{
    // emptying date
    while( this.tbody.hasChildNodes() )
		this.tbody.removeChild( this.tbody.firstChild );

    var tmpDate = new Date();
    tmpDate.setFullYear( this.displayedDate.getFullYear() );
    tmpDate.setDate( 1 );
    tmpDate.setMonth( this.displayedDate.getMonth() );

    var nCurrDayNum = 1;
    var nRows = 1;
    var currRow = document.createElement( 'tr' );
    this.tbody.appendChild( currRow );

    // filling up the first cells with the previous month's days
    var nCurrDayOfWeek = tmpDate.getDay();
    if( nCurrDayOfWeek == 0 )
		nCurrDayOfWeek = 7;
    for( var i = 0; i < nCurrDayOfWeek-1; i++ )
    {
		var newTD = document.createElement( 'td' );
		currRow.appendChild( newTD );
    }

    var today = new Date();
    var nDaysInMonth = this.getDaysInMonth( tmpDate );
    while( nCurrDayNum <= nDaysInMonth )
    {
		if( nCurrDayOfWeek == 8 )
		{
			nCurrDayOfWeek = 1;
			nRows++;
			currRow = document.createElement( 'tr' );
			currRow.className = this.className + '-row-' + ( nRows % 2 ? 'odd' : 'even' );
			this.tbody.appendChild( currRow );
		}

		var newTD = document.createElement( 'td' );
		newTD.innerHTML = nCurrDayNum;
		newTD.className = this.className + '-dayFree';
		if(
			( // checking if current month is selected
				this.displayedDate.getMonth() == today.getMonth() &&
				this.displayedDate.getFullYear() == today.getFullYear() &&
				today.getDate() > nCurrDayNum
			)
			||
			(
				this.displayedDate.getFullYear() < today.getFullYear() ||
				(
					this.displayedDate.getMonth() < today.getMonth() &&
					this.displayedDate.getFullYear() <= today.getFullYear()
				)
			)
	    )
	    newTD.className = this.className + '-pastDay';

		if( today.getDate() == nCurrDayNum &&
			this.displayedDate.getMonth() == today.getMonth() &&
			this.displayedDate.getFullYear() == today.getFullYear() )
			newTD.className = this.className + '-currDay';
		if( this.selectedDate.getDate() == nCurrDayNum &&
			this.displayedDate.getMonth() == this.selectedDate.getMonth() &&
			this.displayedDate.getFullYear() == this.selectedDate.getFullYear() )
			newTD.className = this.className + '-selectedDay';
		/*if( this.displayedDate.getDate() == nCurrDayNum )
		{
			if( newTD.className != '' )
				newTD.className += '-displayedDay';
			else
				newTD.className = this.className + '-displayedDay';
		}*/

		if( newTD.className == this.className + '-pastDay-displayedDay' )
			newTD.className = this.className + '-displayedDay';

		newTD.id = this.className + '-day-' + nCurrDayNum;
		if( this.dayClickedCallBack )
			newTD.onclick = new Function( this.dayClickedCallBack + '(' + nCurrDayNum + ');' );
		currRow.appendChild( newTD );

		nCurrDayOfWeek++;
		nCurrDayNum++;
    }

    var sMonthName;
    switch( tmpDate.getMonth() )
    {
    case 0: sMonthName = 'január'; break;
    case 1: sMonthName = 'február'; break;
    case 2: sMonthName = 'március'; break;
    case 3: sMonthName = 'április'; break;
    case 4: sMonthName = 'május'; break;
    case 5: sMonthName = 'június'; break;
    case 6: sMonthName = 'július'; break;
    case 7: sMonthName = 'augusztus'; break;
    case 8: sMonthName = 'szeptember'; break;
    case 9: sMonthName = 'október'; break;
    case 10: sMonthName = 'november'; break;
    case 11: sMonthName = 'december'; break;
    }
    if( this.monthDisplay )
		$(this.monthDisplay).innerHTML = sMonthName;
    if( this.yearDisplay )
		$(this.yearDisplay).innerHTML = tmpDate.getFullYear();

	clearTimeout( this.updateTimer );
	this.updateTimer = setTimeout( this.update, 60000 );

    if( this.updateCallBack )
		new Function( this.updateCallBack + '();' )();
}

function ca_calendar_decMonth()
{
    var tmpDate = new Date();
    tmpDate.setFullYear( this.displayedDate.getFullYear() );
    tmpDate.setDate( 1 );
    tmpDate.setMonth( this.displayedDate.getMonth() );

    if( tmpDate.getMonth() == 0 )
    {
		tmpDate.setYear( tmpDate.getFullYear() - 1 );
		tmpDate.setMonth( 11 );
    }
    else
		tmpDate.setMonth( tmpDate.getMonth() - 1 );

    if( this.getDaysInMonth( tmpDate ) < this.getDaysInMonth( this.displayedDate ) )
		this.displayedDate.setDate( this.getDaysInMonth( tmpDate ) );

    this.displayedDate.setYear( tmpDate.getFullYear() );
    this.displayedDate.setMonth( tmpDate.getMonth() );

    this.update();
}

function ca_calendar_decYear()
{
    var nCurrYear = this.displayedDate.getFullYear();
    if( nCurrYear == 1 )
		return;

    this.displayedDate.setYear( nCurrYear - 1 );
    this.update();
}

function ca_calendar_incMonth()
{
    var tmpDate = new Date();
	tmpDate.setFullYear( this.displayedDate.getFullYear() );
    tmpDate.setDate( 1 );
	tmpDate.setMonth( this.displayedDate.getMonth() );

    if( tmpDate.getMonth() == 11 )
    {
		tmpDate.setYear( tmpDate.getFullYear() + 1 );
		tmpDate.setMonth( 0 );
    }
    else
		tmpDate.setMonth( tmpDate.getMonth() + 1 );

    if( this.getDaysInMonth( tmpDate ) < this.getDaysInMonth( this.displayedDate ) )
		this.displayedDate.setDate( this.getDaysInMonth( tmpDate ) );

    this.displayedDate.setYear( tmpDate.getFullYear() );
    this.displayedDate.setMonth( tmpDate.getMonth() );

    this.update();
}

function ca_calendar_incYear()
{
    this.displayedDate.setYear( this.displayedDate.getFullYear() + 1 );
    this.update();
}

function ca_calendar_dayClicked( dayNum )
{
    this.selectedDate.setDate( dayNum );
    this.selectedDate.setMonth( this.displayedDate.getMonth() );
    this.selectedDate.setFullYear( this.displayedDate.getFullYear() );
    this.displayedDate.setDate( dayNum );
}

function ca_calendar_getSelectedDate()
{
    var nMonth = this.selectedDate.getMonth()+1;
    var nDay = this.selectedDate.getDate();

    return this.selectedDate.getFullYear() + '-' +
		(nMonth < 10 ? '0' + nMonth : nMonth) + '-' +
		(nDay < 10 ? '0' + nDay : nDay);
}

// called by updatecalendar ajax scripts
function ca_calendar_addToDayClassName( day, className )
{
    day = parseInt( day, 10 ); // cutting off leading 0 character from day

    if( $(this.className + '-day-' + day ).className == '' )
		$(this.className + '-day-' + day ).className = this.className;

    if( $(this.className + '-day-' + day ).className != this.className + '-selectedDay' &&
		$(this.className + '-day-' + day ).className != this.className + '-selectedDay-displayedDay' &&
		$(this.className + '-day-' + day ).className.indexOf( className, 0 ) == -1 )
		$(this.className + '-day-' + day ).className += '-' + className;

    if( $(this.className + '-day-' + day ).className == this.className + '-pastDay-reservedDay' )
		$(this.className + '-day-' + day ).className = this.className + '-reservedDay';
    if( $(this.className + '-day-' + day ).className == this.className + '-pastDay-fullReservedDay' )
		$(this.className + '-day-' + day ).className = this.className + '-fullReservedDay';
    if( $(this.className + '-day-' + day ).className == this.className + '-currDay-reservedDay' )
		$(this.className + '-day-' + day ).className = this.className + '-reservedDay';
    if( $(this.className + '-day-' + day ).className == this.className + '-currDay-fullReservedDay' )
		$(this.className + '-day-' + day ).className = this.className + '-fullReservedDay';
    if( $(this.className + '-day-' + day ).className == this.className + '-dayFree-reservedDay' )
		$(this.className + '-day-' + day ).className = this.className + '-reservedDay';
    if( $(this.className + '-day-' + day ).className == this.className + '-dayFree-fullReservedDay' )
		$(this.className + '-day-' + day ).className = this.className + '-fullReservedDay';
    if( $(this.className + '-day-' + day ).className == this.className + '-dayFree-displayedDay-reservedDay' )
		$(this.className + '-day-' + day ).className = this.className + '-displayedDay-reservedDay';
    if( $(this.className + '-day-' + day ).className == this.className + '-dayFree-displayedDay-fullReservedDay' )
		$(this.className + '-day-' + day ).className = this.className + '-displayedDay-fullReservedDay';
    if( $(this.className + '-day-' + day ).className == this.className + '-reservedDay-fullReservedDay' )
		$(this.className + '-day-' + day ).className = this.className + '-fullReservedDay';
}

var ca_calendar_move_window;
var ca_calendar_move_mouseX = -1;
var ca_calendar_move_mouseY = -1;
var ca_calendar_move_mouseTmpX = -1;
var ca_calendar_move_mouseTmpY = -1;
function ca_calendar_move( e )
{
    if( document.all ) // IE
    {
		ca_calendar_move_mouseX = event.clientX + document.body.scrollLeft;
		ca_calendar_move_mouseY = event.clientY + document.body.scrollTop;
    }
    else
    {
		ca_calendar_move_mouseX = e.pageX;
		ca_calendar_move_mouseY = e.pageY;
    }

    if( ca_calendar_move_mouseX < 0 )
		ca_calendar_move_mouseX = 0;
    if( ca_calendar_move_mouseY < 0 )
		ca_calendar_move_mouseY = 0;

    if( ca_calendar_move_mouseTmpX != -1 && ca_calendar_move_mouseTmpY != -1 )
    {
        ca_calendar_move_window.style.left = ( parseInt( ca_calendar_move_window.style.left, 10 ) + ( ca_calendar_move_mouseX-ca_calendar_move_mouseTmpX ) ) + 'px';
		ca_calendar_move_window.style.top = ( parseInt( ca_calendar_move_window.style.top, 10 ) + ( ca_calendar_move_mouseY-ca_calendar_move_mouseTmpY ) ) + 'px';
    }
    ca_calendar_move_mouseTmpX = ca_calendar_move_mouseX;
    ca_calendar_move_mouseTmpY = ca_calendar_move_mouseY;
}

function ca_calendar_dragStart( e )
{
	ca_calendar_move_window = $(this.window);

	if( document.all )
    {
        document.attachEvent( "onmousemove", ca_calendar_move );
        document.attachEvent( "onmouseup", ca_calendar_dragStop );
		window.event.cancelBubble = true;
		window.event.returnValue = false;
    }
    else
    {
		document.addEventListener( "mousemove", ca_calendar_move, true );
		document.addEventListener( "mouseup", ca_calendar_dragStop, true );
		e.preventDefault();
    }

    if( !$(this.window).style.left )
		$(this.window).style.left = '0px';
    if( !$(this.window).style.top )
		$(this.window).style.top = '0px';

    ca_calendar_move_mouseTmpX = -1;
    ca_calendar_move_mouseTmpY = -1;
}

function ca_calendar_dragStop()
{
    if( document.all) // IE
    {
		document.detachEvent( "onmousemove", ca_calendar_move );
        document.detachEvent( "onmouseup", ca_calendar_dragStop );
    }
    else
    {
		document.removeEventListener( "mousemove", ca_calendar_move, true );
		document.removeEventListener( "mouseup",   ca_calendar_dragStop, true );
    }
}

function ca_calendar_close()
{
	$(this.window).hide();
}

function ca_calendar_open( dateInput )
{
	this.selectedDate = ca_parseDate( $(dateInput).value );
	this.displayedDate.setDate( this.selectedDate.getDate() );
	this.displayedDate.setMonth( this.selectedDate.getMonth() );
	this.displayedDate.setFullYear( this.selectedDate.getFullYear() );
	this.update();

    dateInputPos = ca_findObjectPos( $(dateInput) );
    $(this.window).style.left = dateInputPos[0] + 'px';
    $(this.window).style.top = (dateInputPos[1] + $(dateInput).offsetHeight) + 'px'; 

	$(this.window).show();
}

function ca_init()
{
	setInterval( ca_checkHash, 100 );
}

var ca_currentHash = '';
var ca_hash = '';
function ca_checkHash()
{
	ca_hash = document.location.hash.replace(/%23/g,'#');
	if( ca_hash != ca_currentHash )
	{
		ca_currentHash = ca_hash;
		ca_pageOpen( ca_hash );
	}
}

function ca_pageOpen( hash )
{
	switch( hash.split('#')[1] )
	{
	case 'admin':
		ca_admin_pageOpen( hash.split('#')[2] );
		if( hash.split('#')[2] == 3 )
		{
			ca_admin_chat_init( hash.split('#')[3] );
			$('ca-admin-chat-lines').scrollTop = 9999999;
		}
		if( hash.split('#')[2] == 4 )
		{
			$('ca-admin-logs-lines').scrollTop = 9999999;
			ca_admin_logs_init( hash.split('#')[3] );
		}
		break;
	case 'folytatas':
		ca_sh_continue_pageOpen( hash.split('#')[2] );
		break;
	case 'forum':
		ca_sh_forum_pageOpen( hash.split('#')[2] );
		break;
	case 'chat':
		ca_sh_chat_pageOpen( hash.split('#')[2] );
		break;
	case 'statisztikak':
		ca_sh_sums_pageOpen( hash.split('#')[2] );
		break;
	case 'uzenetek':
		ca_sh_messages_pageOpen( hash.split('#')[2] );
		break;
	case 'veszelyhelyzetek':
		ca_sh_emergencies_pageOpen( hash.split('#')[2] );
		break;
	case 'celok':
		ca_sh_goals_pageOpen( hash.split('#')[2] );
		break;
	case 'elonyokhatranyok':
		ca_sh_proscons_pageOpen( hash.split('#')[2] );
		break;
	case 'recordkeeping':
		ca_sh_recordkeeping_pageOpen( hash.split('#')[2] );
		break;
	case 'onsegitoprogrambevezeto':
		ca_sh_intro_pageOpen( hash.split('#')[2] );
		break;
	case 'kannabiszrol':
		ca_aboutcannabis_pageOpen( hash.split('#')[2] );
		break;
	case 'rolunk':
		ca_about_pageOpen( hash.split('#')[2] );
		break;
	case 'regisztracio':
		ca_signup_pageOpen( hash.split('#')[2] );
		break;
	case 'elvesztettjelszo':
		if( hash.split('#')[2] == 'done' )
			ca_login_lostPassResetDone();
		else
			ca_login_lostPassOpen();
		break;
	case 'naplo':
		if( !hash.split('#')[3] )
			ca_sh_diary_pageOpen( hash.split('#')[2] );
		else
			ca_sh_diary_calendar_dayOpen( hash.split('#')[2], hash.split('#')[3], hash.split('#')[4] );
		break;
	case 'kviz':
		ca_quiz_pageOpen( hash.split('#')[2] );
		break;
	default:
		ca_login_lostPassClose();
	}
}

function ca_AJAXException( object, exception )
{
	$('ca-error-message').show();
	if( $('ca-error-message').innerHTML )
		$('ca-error-message').innerHTML += '<br/>';
	$('ca-error-message').innerHTML += 'AJAX exception (' + exception.name + '): ' + exception.message;
}

function ca_print( id, title )
{
	window.open( 'print.php?onload=ca_print_callback&id=' + id + '&title=' + title );
}

function ca_print_callback( caller, id )
{
  	caller.document.getElementById( 'content' ).innerHTML = $( id ).innerHTML;

	caller.print();
}

function ca_saveContent( id )
{
	var ed = tinyMCE.get( 'ca-' + id + '-content' );

	ed.setProgressState(1);

    new Ajax.Request( '/ca-ajax/savecontent.js.php', {
		method: 'post', parameters:	{
			content: ed.getContent(),
			id: id
		}
    } );
}

function ca_getWindowHeight()
{
	var windowHeight = 0;
	if( typeof( window.innerHeight ) == 'number')
		windowHeight = window.innerHeight;
	else
	{
		if( document.documentElement && document.documentElement.clientHeight )
			windowHeight = document.documentElement.clientHeight;
		else
		{
			if( document.body && document.body.clientHeight )
				windowHeight = document.body.clientHeight;
		}
	}
	return windowHeight;
}

function ca_getWindowWidth()
{
	var windowWidth = 0;
	if( typeof( window.innerWidth ) == 'number')
		windowWidth = window.innerWidth;
	else
	{
		if( document.documentElement && document.documentElement.clientWidth )
			windowWidth = document.documentElement.clientWidth;
		else
		{
			if( document.body && document.body.clientWidth )
				windowWidth = document.body.clientWidth;
		}
	}
	return windowWidth;
}

function ca_setCenterVertical( contentElement )
{
	if( document.getElementById )
	{
		var windowHeight = ca_getWindowHeight();
		if( windowHeight > 0 )
		{
			var contentHeight = contentElement.offsetHeight;
			if( windowHeight - contentHeight > 0 )
				contentElement.style.top = ( (windowHeight / 2) - (contentHeight / 2) ) + 'px';
			else
				contentElement.style.position = 'static';
		}
	}
}

function ca_setCenterHorizontal( contentElement )
{
	if( document.getElementById )
	{
		var windowWidth = ca_getWindowWidth();
		if( windowWidth > 0 )
		{
			var contentWidth = contentElement.offsetWidth;
			if( windowWidth - contentWidth > 0 )
				contentElement.style.left = ( (windowWidth / 2) - (contentWidth / 2) ) + 'px';
			else
				contentElement.style.position = 'static';
		}
	}
}

function ca_body_onClick( e )
{
	var target = ( e && e.target ) || ( event && event.srcElement ); 
	if( ca_checkParent( target, $('ca-login') ) )
		ca_login_close();
} 

function ca_checkParent( node, searchFor )
{
	while( node.parentNode )
	{ 
		if( node == searchFor )
			return false;
		node = node.parentNode;
	}
	return true ;
}

function ca_setCookie( name, value, expireAt )
{
	var date = new Date( expireAt * 1000 );
	document.cookie = name + "=" + escape( value ) + '; expires=' + date.toUTCString() + '; path=/';
}

function ca_slideRater( id, rating )
{
	$(id+'-value').value = rating;
	for( var i = 0; i <= 10; i++ )
	{
		if( i <= $(id+'-value').value )
			$(id + '-' + i).src = '/ca-images/slider-rating/' + i + '.png';
		else
			$(id + '-' + i).src = '/ca-images/slider-rating/empty.png';
	}
	new Effect.Pulsate( id + '-' + rating, { pulses: 1, duration: 0.2, from: 0.5 } );
}

function ca_slideRaterMouseOver( id, rating )
{
	for( var i = 0; i <= 10; i++ )
	{
		if( i <= rating )
			$(id + '-' + i).src = '/ca-images/slider-rating/' + i + '.png';
		else
			$(id + '-' + i).src = '/ca-images/slider-rating/empty.png';
	}
	$(id + '-text').innerHTML = rating;
}

function ca_slideRaterMouseOut( id, event )
{
	var toElement;

	if( event.relatedTarget )
		toElement = event.relatedTarget;
	else
		if( event.toElement )
			toElement = event.toElement;

	if( toElement.tagName != 'DIV' )
	{
		for( var i = 0; i <= 10; i++ )
		{
			if( i <= $(id + '-value').value )
				$(id + '-' + i).src = '/ca-images/slider-rating/' + i + '.png';
			else
				$(id + '-' + i).src = '/ca-images/slider-rating/empty.png';
		}
		$(id + '-text').innerHTML = $(id + '-value').value;
	}
}

function ca_sliderRaterReset( id )
{
	$(id + '-value').value = 0;
	for( var i = 1; i <= 10; i++ )
		$(id + '-' + i).src = '/ca-images/slider-rating/empty.png';
	$(id + '-0').src = '/ca-images/slider-rating/0.png';
	$(id + '-text').innerHTML = 0;
}

function ca_parseDate( dateString )
{
    var sDate = dateString.split(' ')[0];
    var sTime = dateString.split(' ')[1];
    var currDate = new Date();
    var nYear;
    var nMonth;
    var nDay;
    var nHour;
    var nMinute;

    nYear = parseInt(sDate.split('-')[0], 10);
    nMonth = parseInt(sDate.split('-')[1], 10);
    nDay = parseInt(sDate.split('-')[2], 10);
    if( !sTime )
    {
		nHour = currDate.getHours();
		nMinute = currDate.getMinutes();
    }
    else
    {
		nHour = parseInt(sTime.split(':')[0], 10);
		nMinute = parseInt(sTime.split(':')[1], 10);
    }

    if( !nYear && !nMonth && !nDay )
    {
        nHour = currDate.getHours();
        nMinute = currDate.getMinutes();
    }

    if( isNaN( nYear ) || !nYear )
        nYear = currDate.getFullYear();
    if( isNaN( nMonth ) || !nMonth )
        nMonth = currDate.getMonth();
    else
		nMonth--;
    if( isNaN( nDay ) || !nDay )
        nDay = currDate.getDate();
    if( isNaN( nHour ) )
        nHour = currDate.getHours();
    if( isNaN( nMinute ) )
        nMinute = currDate.getMinutes();

    var result = new Date();
    result.setFullYear( nYear );
    result.setMonth( nMonth );
    result.setDate( nDay );
    result.setHours( nHour );
    result.setMinutes( nMinute );
    return result;
}

function ca_findObjectPos( obj )
{
    var curleft = curtop = 0;
    if( obj.offsetParent )
    {
    	do
		{
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while( obj = obj.offsetParent );
    }
    return [curleft,curtop];
}

function ca_admin_pagesClose()
{
	var i = 1;
	while( $('ca-admin-page-' + i) )
	{
		$('ca-admin-page-' + i).hide();
		$('ca-admin-menuitem-' + i).className = '';
		i++;
	}
}

function ca_admin_pageOpen( pageNum )
{
	if( !pageNum )
		pageNum = 1;
	ca_admin_pagesClose();
	if( $( 'ca-admin-page-' + pageNum ) )
	{
		$( 'ca-admin-page-' + pageNum ).show();
		$('ca-admin-menuitem-' + pageNum).className = 'currentpage';
	}
}

var ca_admin_ul_search_gobutton_oldvalue;
var ca_admin_ul_currentpage = 1;
function ca_admin_ul_update()
{
    clearTimeout( ca_admin_ul_updatetimer );

    var pattern = $('ca-admin-ul-search-pattern').value.replace( '*', '%' );
    if( pattern == '' )
		pattern = '%';

    ca_admin_ul_updatenavbar();

    $('ca-admin-ul-search-gobutton').value = 'Folyamatban...';

    new Ajax.Request( '/ca-ajax/admin/ul-update.js.php', {
		method: 'post', parameters: {
			pattern: pattern,
			page: ca_admin_ul_currentpage
		}
    } );
}

var ca_admin_ul_updatetimer;
function ca_admin_ul_delayedupdate()
{
    clearTimeout( ca_admin_ul_updatetimer );
    ca_admin_ul_updatetimer = setTimeout( "ca_admin_ul_update();", 500 );
}

function ca_admin_ul_erase()
{
    $('ca-admin-ul-default').style.display = 'block';
    $('ca-admin-ul-table').style.display = 'none';

    while( $('ca-admin-ul-table-tbody').hasChildNodes() )
		$('ca-admin-ul-table-tbody').removeChild( $('ca-admin-ul-table-tbody').firstChild );
}

function ca_admin_ul_additem( listindex, email, nick, admin, index )
{
    if( $('ca-admin-ul-default').style.display != 'none' )
    {
		// this workaround is needed because the browser won't automatically apply table style to the newly added rows
		setTimeout( "$('ca-admin-ul-default').style.display = 'none'; $('ca-admin-ul-table').style.display = 'block';", 0 );
    }

    var newRow = document.createElement( 'tr' );
    newRow.id = 'ca-admin-ul-' + index;
    newRow.className = 'ca-admin-ul-entry-' + ($('ca-admin-ul-table-tbody').childNodes.length % 2 ? 'even' : 'odd');
    $('ca-admin-ul-table-tbody').appendChild( newRow );

    var listIndexTD = document.createElement( 'td' );
    listIndexTD.id = newRow.id + '-listindex';
    listIndexTD.innerHTML = listindex;
    newRow.appendChild( listIndexTD );

	var emailTD = document.createElement( 'td' );
	emailTD.id = newRow.id + '-email';
	emailTD.innerHTML = email;
	newRow.appendChild( emailTD );

	var nickTD = document.createElement( 'td' );
	nickTD.id = newRow.id + '-nick';
	nickTD.innerHTML = nick;
	newRow.appendChild( nickTD );

    var adminTD = document.createElement( 'td' );
    adminTD.id = newRow.id + '-admin';
	adminTD.innerHTML = '<input type="checkbox"' + (admin == 1 ? ' checked' : '') + ' id="' + newRow.id + '-admin" ' +
    	    'onclick="javascript:ca_admin_changeAdmin( ' + index + ' );" />';
    newRow.appendChild( adminTD );

    var deleteTD = document.createElement( 'td' );
    deleteTD.id = newRow.id + '-delete';
	deleteTD.innerHTML = '<input type="button" class="button" value="Törlés" id="' + newRow.id + '-deletebutton" ' +
    	    'onclick="javascript:ca_admin_delete( ' + index + ' );" />';
    newRow.appendChild( deleteTD );
}

function ca_admin_ul_gotofirstpage()
{
    ca_admin_ul_currentpage = 1;
    ca_admin_ul_update();
}

function ca_admin_ul_gotolastpage()
{
    ca_admin_ul_currentpage = parseInt( $('ca-admin-ul-allpages').innerHTML, 10 );
    ca_admin_ul_update();
}

function ca_admin_ul_decpage()
{
    ca_admin_ul_currentpage--;
    ca_admin_ul_update();
}

function ca_admin_ul_incpage()
{
    ca_admin_ul_currentpage++;
    ca_admin_ul_update();
}

function ca_admin_ul_updatenavbar()
{
    $('ca-admin-ul-incpage-button').disabled = false;
    $('ca-admin-ul-gotolastpage-button').disabled = false;
    $('ca-admin-ul-decpage-button').disabled = false;
    $('ca-admin-ul-gotofirstpage-button').disabled = false;
    if( ca_admin_ul_currentpage >= parseInt($('ca-admin-ul-allpages').innerHTML, 10) )
    {
		ca_admin_ul_currentpage = parseInt($('ca-admin-ul-allpages').innerHTML, 10);
		$('ca-admin-ul-incpage-button').disabled = true;
		$('ca-admin-ul-gotolastpage-button').disabled = true;
		$('ca-admin-ul-decpage-button').disabled = false;
		$('ca-admin-ul-gotofirstpage-button').disabled = false;
    }
    if( ca_admin_ul_currentpage <= 1 )
    {
		ca_admin_ul_currentpage = 1;
		$('ca-admin-ul-incpage-button').disabled = false;
		$('ca-admin-ul-gotolastpage-button').disabled = false;
		$('ca-admin-ul-decpage-button').disabled = true;
		$('ca-admin-ul-gotofirstpage-button').disabled = true;
    }
    if( parseInt($('ca-admin-ul-allpages').innerHTML, 10) == 1 )
    {
		$('ca-admin-ul-incpage-button').disabled = true;
		$('ca-admin-ul-gotolastpage-button').disabled = true;
		$('ca-admin-ul-decpage-button').disabled = true;
		$('ca-admin-ul-gotofirstpage-button').disabled = true;
    }
}

function ca_admin_ul_currentpage_edit()
{
    $('ca-admin-ul-currentpage').innerHTML = '<input id="ca-admin-ul-currentpage-edit" type="text" class="textinput" ' +
		'onkeydown="javascript:if( event.keyCode == 13 ) ca_admin_ul_currentpage_edit_finished( this );" ' +
		'value="' + ca_admin_ul_currentpage + '" />';
    $('ca-admin-ul-currentpage').onclick = '';
    $('ca-admin-ul-currentpage-edit').focus();
}

function ca_admin_ul_currentpage_edit_finished( inputbox )
{
    ca_admin_ul_currentpage = parseInt( inputbox.value, 10 );
    if( !ca_admin_ul_currentpage )
		ca_admin_ul_currentpage = 1;
    $('ca-admin-ul-currentpage').onclick = ca_admin_ul_currentpage_edit;
    ca_admin_ul_update();
}

function ca_admin_changeAdmin( index )
{
    new Ajax.Request( '/ca-ajax/admin/changeAdmin.js.php', {
		method: 'post', parameters: {
			index: index
		}
    } );
}

function ca_admin_delete( index )
{
	if( !confirm( 'Valóban törlöd a felhasználót?' ) )
		return;

    new Ajax.Request( '/ca-ajax/admin/delete.js.php', {
		method: 'post', parameters: {
			index: index
		}
    } );
}


