function validateForm(formId, questionsNo){
	var query = "";
	for (i = 0; i < questionsNo;i++){
		var name = "question"+i;
		var radioObj = $("input[name='"+name+"']:checked");
		if (radioObj.length == 0){
			if (query == ""){
				query = i+1;
			}else{
				query = query + " , " + (i+1);
			}
		}
	}
	if (query != ""){
		alert("Nem válaszolt az alábbi kérdésre: "+query);
	}else{
		$('#'+formId).submit();
	}
}
function validateVote(formId){
	var query = "";
	var name = "vote";
	var radioObj = $("input[name='"+name+"']:checked");
	if (radioObj.length == 0){
		query = "1";
	}
	if (query != ""){
		alert("Nem válaszotott osztályzatot!");
	}else{
		$('#'+formId).submit();
	}

}
function Invite_user(){
	$.post(
		'/!/sendinvitation.php',
		{name_0:$('#invite_name_0').val(), email_0:$('#invite_email_0').val()},
		function(html){

			var res = html.split(';');
			if(res[0] == 'error'){
				alert(res[1]);
			}else if(res[0]=="OK"){
				alert(res[1]);
				document.location.href="/";

			}
		}
	);

}
function Modify_user_data(newdata){
genreval='';
newsval='';
if(newdata=="new") loc='/!/registernewdata.php';
else loc='/!/registerdata.php';

	if($('#genre_male').is(':checked')){
	genreval="male";}
	else genreval="female";
	if($('#newsletter_yes').is(':checked')){
	newsval="yes";}
	else newsval="no";
	if($('#datahandling').is(':checked')){
	datahandling_val="accept";}
	else datahandling_val="no";
//alert($('#hostemail').val());
	$.post(
		loc,
		{email:$('#field_email').val(),
		 password:$('#field_password').val(),
		 lastname:$('#field_lastname').val(),
		 firstname:$('#field_firstname').val(),
		 genre:genreval,
		 birthday_year:$('#birthday_year').val(),
		 birthday_month:$('#birthday_month').val(),
		 birthday_day:$('#birthday_day').val(),
		 mobile_area:$('#field_mobile_area').val(),
		 mobile:$('#field_mobile').val(),
		 address_city:$('#field_address_city').val(),
		 address_street:$('#field_address_street').val(),
		 post_code:$('#field_post_code').val(),
		 country:$('#field_country').val(),
		 hostemail:$('#hostemail').val(),
		 captcha_reg:$('#captcha_reg').val(),
		 newsletter:newsval,
		 datahandling:datahandling_val
		 },
		function(html){

			var alertmessage='';
			var res = html.split(';');
			if(res[0] == 'error'){
				for(i=1;i<res.length;i++){
					alertmessage+=res[i]+'\n';
				}
				alert(alertmessage);
			}else{
				if(newdata=="new")
				alert("Köszönjük a regisztrációt. A rendszer egy hitelesítő emailt küldött Önnek, kérjük figyelje postaládáját.");
				else alert("Sikeresen módosította adatait!");
				if(html=="OK"  && newdata!="new"){document.location.reload();}
				else  {document.location.href="/";}

			}
		}
	);
}
function Login(){
	$.post(
		'/!/login.php',
		{email:$('#email').val(), password:$('#password').val()},
		function(html){
			var res = html.split(';');
			if(res[0] == 'error'){
				alert(res[1]);
			}else{

				if(html=="OK1"){document.location.reload();}
				else if(html=="OK2") {document.location.href="/registerdata.php";}
				else  {document.location.href="/";}

			}
		}
	);
}
function SendPass(){
	$.post(
		'/!/forgetpass.php',
		{email:$('#email').val()},
		function(html){

			var res = html.split(';');
			if(res[0] == 'error'){
				alert(res[1]);
			}else{

				if(html=="OK"){
				alert("Az új jelszót elküldtük megadott postafiókjába!")
				document.location.href="/";}


			}
		}
	);
}
function clear_input(id){
	document.getElementById(id).value="";
}
function fill_input(id,text){
	if(document.getElementById(id).value==""){
	document.getElementById(id).value=text;
	}
}
function isLeapYear(year){
	if ((year%4==0 && year%100!=0) || year%400==0){
		return true;
	}
	else{
		return false;
	}
}
function daycreate(formname,optionid,dayoptionid,yearoptionid){
		var month= document.getElementById(optionid).value;
		var dayselected=document.getElementById(dayoptionid).value;
		dayoptionobj=document.getElementById(dayoptionid);
		dayoptionobj.options.length=0

		if(month=='4' || month=='6' ||month=='9' ||month=='11'){
			createoption(dayoptionobj,30,dayselected);
		}
		else if(month=='2'){
			var daycount=28;
			if(isLeapYear(document.getElementById(yearoptionid).value)){
			daycount=29;
			}
			createoption(dayoptionobj,daycount,dayselected)
		}
		else{
			createoption(dayoptionobj,31,dayselected)
		}

}
function createoption(dayoptionobj,daycount,selected){
	for(i=1;i<=daycount;i++){
			if(i==selected){
			dayoptionobj.options[i]=new Option(i, i, false, true);
			}
			else{
				dayoptionobj.options[i]=new Option(i, i, false, false);
			}
		}
}
function keyfilter(filter, event) {
	if (!event) event=window.event;
	var c=getCharCode(event);
	if (c && !filter(c)) cancelEvent(event);
}
function getCharCode(event) {
	return typeof(event.charCode)=="undefined" ? (event.keyCode || event.which) : event.charCode;
}

function cancelEvent(event) {
	if (!event) event=window.event;
	if (event.preventDefault) event.preventDefault();
	else event.returnValue=false;
}
function keyfilter_Digit(event) {
	keyfilter(function(c) {return (c >= 48 && c <= 57) || c==13},event);
}
function SendMsg(){
	$.post(
		'/!/sendmsg.php',
		{
		nev:$('#id_nev').val(),
		msg:$('#id_msg').val(),
		email:$('#id_email').val()
		},
		function(html){

			var res = html.split(';');
			if(res[0] == 'error'){
				alert(res[1]);
			}else{

				if(html=="OK"){
				alert("Az üzenetet elküldtük!")
				document.location.href="/";}


			}
		}
	);
}

