$(document).ready(function(){
	if ( $.BMMessagesAlert ) {
		bmAlert($.BMMessagesAlert, 'info', true);
	}

	if ( $.BMMessagesError ) {
		bmAlert($.BMMessagesError, 'error', true);
	}
});

function bmAlert( message, type, sticky ) {
	if ( type == 'error' )  {
		image = 'icon_warning.gif';
		color = 'white';
	}
	else {
		image = 'icon_info.gif';
		color = 'white';
	}

	text = '<table style="border-spacing:6px;" cellspacing="6"><tr><td><img src="/misc/'+image+'" width="24"></td> <td style="color:'+color+'">'+message+'</td></tr></table>'
	$('#BMmessages').jGrowl(text, {
		sticky: sticky,
		glue: 'before',
		speed: 600,
		easing: 'easeInOutExpo',
		animateOpen: { 
			height: "show",
			width: "show"
		},
		animateClose: { 
			height: "hide",
			width: "show"
		}
	});
}


function replaceAjaxModuleBox( div, module, other, nobuild ) {

	if ( nobuild || !checkBuildModule() ) {

		ajaxStart();
		if ( !nobuild )
			startBuildModule( div );

		$.post(document.URL, { ajax_from_template: module, moduleID: div.substr(1), other: other },
			function ( data ) {
				$('#'+div).html(data);
				replaceInit();
		});
		ajaxEnd();
	}

}

function checkVotingForm( id ) {
	lista = document.forms['sbVoting_'+id].elements['answer'];
	
	checked = false;
	for ( i=0; i<lista.length; i++ ) {
		if ( lista[i].checked == true )
			checked = true;
	}
	
	if ( checked == false ) {
		bmAlert('Kérem először válasszon a megadott lehetőségek közül!', 'error');
		return false;
	}
	else
		return true;
}

function checkWplUserEmail( input ) {
	$.post(document.URL, {ajaxFunction: 'checkWplUserEmail', ajaxFile: '_ajax.php', email: input.value },
		function ( data ) {
			if ( data == 'IS' ) {
				bmAlert('Az e-mail cím (<b>'+input.value+'</b>) már regisztrálva van oldalunkon!');
				input.value = '';
				$(input).css('background', $.formErrorBg);
			}	
	});
}

function checkWplNluEmail( input ) {
	$.post(document.URL, {ajaxFunction: 'checkWplNluEmail', ajaxFile: '_ajax.php', email: input.value },
		function ( data ) {
			if ( data == 'IS' ) {
				bmAlert('Az e-mail cím (<b>'+input.value+'</b>) már fel van iratkozba hírlevelünkre!');
				input.value = '';
				$(input).css('background', $.formErrorBg);
			}	
	});
}