function ShowBBCode() {
	window.open('bbcode.php','','width=590,height=370,resizable=no,scrollbars=yes');
	return false;
};

function CategoryDelete(id) {
	if (confirm('Biztosan törli ezt a kategóriát?')) window.location = 'categoryDelete.php?id='+id;
};

function CategoryEdit(id) {
	window.open('categoryEdit.php?id='+id,'','width=600,height=160,resizable=no,scrollbars=no');
	return false;
};

function ProgramDelete(id) {
	if (confirm('Biztosan törli ezt a programot?')) window.location = 'programDelete.php?id='+id;
};

function ProgramEdit(id) {
	window.open('programEdit.php?id='+id,'','width=620,height=560,resizable=no,scrollbars=yes');
	return false;
};

function ShowOrHideObject(id) {
	s = $('#'+id).style.display;
	$('#'+id).style.display = ((s=='none')?'block':'none');
	return false;
};

function DeletePost(id) {
	if (confirm('Egészen biztos, hogy törli ezt a bejegyzést?\r\n\r\nVisszaállíthatatlanul elvesznek az adatok.')) window.location = 'post_delete.php?id='+id;
}

function DeleteUploadedFile(id) {
	if (confirm('Biztosan törli ezt a fájlt? Törlés után nem állítható vissza.')) {
		$.ajax('fajlManage_delete.php', {
			type: "POST",
			cache: false,
			data: {id: id},
			dataType: "text",
			success: function(data) {
				$('#uploadedFile'+id).remove();
			},
		    error: function() {
		    	alert('Kapcsolati hiba történt a törlés során.');
			}
		});
		/*new Ajax.Request('fajlManage_delete.php?'+Math.random(), {
			method: 'post',
			parameters: {id: id},
			onSuccess: function() {
				$('#uploadedFile'+id).remove();
			},
		    onFailure: function() {
		    	alert('Kapcsolati hiba történt a törlés során.');
			}
		});*/
	};
	return false;
};

function SetRankHover(postid,i) {
	for (x=1;x<=5;x++) $('#rankStar'+postid+'_'+x).attr("class", ((x<=i)?'hover1':'hover0'));
};

function SetRank(postid,i) {
	$.ajax('post_voteRank.php', {
		type: "POST",
		cache: false,
		data: {postid: postid, v: i},
		dataType: "text",
		success: function(data) {
			alert(data);
			$('#rankDiv'+postid).html(data);
		}
	});
};

function Letolt(id) {
	window.open('download.php?id='+id,'','width=400,height=150,left=200,top=150,resizable=no,scrollbars=no');
	return false;
};

function LetoltNoStat(id) {
	window.open('download.php?id='+id+'&nostat=1','','width=400,height=150,left=200,top=150,resizable=no,scrollbars=no');
	return false;
};

function LetoltesEdit(id) {
	window.open('fajlManageEdit.php?id='+id,'','width=600,height=170,left=180,top=150,resizable=no,scrollbars=no');
	return false;
};

function PostCommentEdit(id) {
	window.open('post_commentEdit.php?id='+id,'','width=600,height=200,left=180,top=150,resizable=no,scrollbars=no');
	return false;
};

function PostCommentDelete(id) {
	if (! confirm('Biztosan törli ezt a kommentet?')) return false;
	$.ajax('post_commentDelete.php', {
		type: "POST",
		cache: false,
		data: {id: id},
		dataType: "text",
		success: function(data) {
			$('#postComment'+id).remove();
		},
	    error: function() {
	    	alert('Kapcsolati hiba történt a törlés során.');
		}
	});
	return false;
};

function IsValidUsername(mezo,strAlert) {
	var reg = /^[a-z0-9]+$/i;
	var valid = reg.test( mezo.value );
	if ((! valid) && (strAlert != '')) alert(strAlert);
	return valid;
};

function openLostPassword() {
	window.open('lostpass.php','','width=600,height=200,left=180,top=150,resizable=no,scrollbars=no');
	return false;
};

function NewsletterEdit(id) {
	window.open('newsletter_edit.php?id='+id,'','width=600,height=410,left=180,top=110,resizable=no,scrollbars=no');
	return false;
};

function NewsletterSend(id) {
	window.open('newsletter_beforeSend.php?id='+id,'','width=500,height=160,left=180,top=140,resizable=no,scrollbars=no');
	return false;
};

function ChBoxLstCountUpd(azon,obj) {
	azon += + (obj.checked?1:-1);
	obj.html(azon);
};

function SubmitVote(voteId,answerId) {
	$('#voteAnswersDiv').html('<img src="style/ajax.gif" alt="betöltés..." class="ajaxLoad">');
	$.ajax('vote.php', {
		type: "POST",
		cache: false,
		data: {voteId: voteId, answerId: answerId},
		dataType: "text",
		success: function(data) {
			$('#voteAnswersDiv').html(data);
		},
	    error: function() {
	    	$('#voteAnswersDiv').html('');
		}
	});
	return true;
};

function ChangeVoteWork(id) {
	$.ajax('voteWorkChange.php', {
		type: "POST",
		cache: false,
		data: {id: id},
		dataType: "text",
		beforeSend: function() {
			$('#chgWork'+id).html('<img src="style/ajax.gif" alt="betöltés..." class="ajaxLoad">');
			return true;
		},
		success: function(data) {
			$('#chgWork'+id).html(data);
		},
	    error: function() {
	    	$('#chgWork'+id).html('Kapcsolati hiba');
		}
	});
	return true;
};

function VoteAnswerTextChange1(id) {
	regi = $('#voteTextSpan'+id).html();
	$('#voteAnswerText'+id).html('<input type="text" value="'+regi+'" id="voteTextInput'+id+'" onkeyup="VoteAnswerTextChangeKeyUp('+id+',event)" onblur="VoteAnswerTextChange2('+id+',this.value)" maxlength="40">');
	elem = $('#voteTextInput'+id)[0];
	elem.focus();
	elem.value = regi;
};

function VoteAnswerTextChangeKeyUp(id,e) {
	if (!e) e = window.event;
	if (e.keyCode) {
		code = e.keyCode;
	} else {
		if (e.which) code = e.which;
	};
	if (code != 13) return false;
	VoteAnswerTextChange2(id,$('#voteTextInput'+id)[0].value);
};

function VoteAnswerTextChange2(id,nev) {
	$.ajax('voteAnswerChange.php', {
		type: "POST",
		cache: false,
		data: {id: id, nev: nev},
		dataType: "text",
		beforeSend: function() {
			$('#voteAnswerText'+id).html('<img src="style/ajax.gif" alt="mentés..." class="ajaxLoad">')
			return true;
		},
		success: function(data) {
			var elem = $('#voteAnswerDetails'+id).prev();
			elem.next().remove();
			$(data).insertAfter(elem);
			
		},
	    error: function() {
	    	alert('Kapcsolati hiba történt. A lap frissülni fog.');
	    	window.refresh;
		}
	});
	return true;
};

function VoteAnswerAdd(id) {
	var rnd = Math.random();
	var elem = $('#noVoteAnswers'+id);
	if (elem) elem.remove();
	var elem = jQuery('<div></div>', {
		id: 'voteAnswerDetails'+rnd
	}).addClass('voteAnswerLine').html('<img src="style/ajax.gif" alt="létrehozás..." />');
	$.ajax('voteAnswerAdd.php', {
		type: "POST",
		cache: false,
		data: {id: id},
		dataType: "text",
		beforeSend: function() {
			elem = elem.appendTo('#voteDetails'+id);
		},
		success: function(data) {
			elem.remove();
			$('#voteDetails'+id).append(data);
			if (++voteanswers[id] >= 2) $('#chgWork'+id).css('visibility','visible');
		},
	    error: function() {
	    	alert('Kapcsolati hiba történt. A lap frissülni fog.');
	    	window.refresh;
		}
	});
	return false;
};

function VoteDelete(id) {
	if (! confirm('Biztosan törli ezt a szavazást? A hozzá tartozó válaszok automatikusan törlődni fognak.')) return false;
	$.ajax('voteDelete.php', {
		type: "POST",
		cache: false,
		data: {id: id},
		dataType: "text",
		success: function(data) {
			$('#voteDetails'+id).remove();
		},
	    error: function() {
	    	alert('Kapcsolati hiba történt a törlés során.');
		}
	});
	return false;
};

function VoteAnswerDelete(id) {
	if (confirm('Biztosan törli ezt a választ?')) window.location = 'voteAnswerDelete.php?id='+id;
};

function VoteEdit(id) {
	window.open('voteEdit.php?id='+id,'','width=610,height=150,resizable=no,scrollbars=yes');
	return false;
};
