function SetNotifi(Type,ElementID,Value,Elem,Class,NewText) {
	$.ajax({
		type: 'GET',
		url: '/forum/extensions/Notifi/ajax.php',
		data: 'PostBackAction=ChangeNotifi&Type='+Type+'&ElementID='+ElementID+'&Value='+Value,
		success: function(r) {
			if (Type === "ALL" && Elem === "NotifiAllCont") {
				if (Value === 1) {
					$('.NotifiOwnCont').hide();
					$('.NotifiCommentCont').hide();
					$('.categoriesContainer').hide();
					$('.discussionsContainer').hide();
				} else if (!Value) {
					$('.NotifiOwnCont').show();
					$('.NotifiCommentCont').show();
					$('.categoriesContainer').show();
					$('.discussionsContainer').show();
				}
			}
			if (Type === "COMMENT" && Elem === "NotifiCommentCont") {
				if (Value === 1) {
					$('.NotifiOwnCont').hide();
				} else if (!Value) {
					$('.NotifiOwnCont').show();
				}
			}
			if (Elem === "SetNotifiAll" || Elem === "SetNotifiDiscussion_"+ElementID || Elem === "SetNotifiCategory_"+ElementID) {
				$(Element).removeClass(Elem,Class);
				if (NewText) {
					$('#'+Elem).text(NewText);
				}
				$('#'+Elem).text(NewText);
			} else {
				$(Element).removeClass(Elem,Class);
				if (NewText) {
					$('#'+Elem).text(NewText);
				}
			}
		},
		dataType: "text"
	});
}

function NotifiCat(CategoryID) {
	$(this).addClass('NotifiCatCont_'+CategoryID,'PreferenceProgress');
	if ($('#NotifiCat_'+CategoryID).attr('checked')) Value = 1;
	else Value = 0;
	SetNotifi('CATEGORY',CategoryID,Value,'NotifiCatCont_'+CategoryID,'PreferenceProgress','');
}

function NotifiDiscussion(DiscussionID) {
	$(this).addClass('NotifiDiscussionCont_'+DiscussionID,'PreferenceProgress');
	if ($('#NotifiDiscussion_'+DiscussionID).attr('checked')) Value = 1;
	else Value = 0;
	SetNotifi('DISCUSSION',DiscussionID,Value,'NotifiDiscussionCont_'+DiscussionID,'PreferenceProgress','');
}

function PNotifiAll(SetText,UnSetText) {
	$(this).addClass('SetNotifiAll','Progress');
	if ($('#SetNotifiAll').innerHTML == SetText) {
		Value = 1;
		NewText = UnSetText;
	} else {
		Value = 0;
		NewText = SetText;
	}
	SetNotifi('ALL',0,Value,'SetNotifiAll','Progress',NewText);
}

function PNotifiCategory(CategoryID,SetText,UnSetText) {
	$(this).addClass('SetNotifiCategory_'+CategoryID,'Progress');
	if ($('#SetNotifiCategory_'+CategoryID).text() == SetText) {
		Value = 1;
		NewText = UnSetText;
	} else {
		Value = 0;
		NewText = SetText;
	}
	SetNotifi('CATEGORY',CategoryID,Value,'SetNotifiCategory_'+CategoryID,'Progress',NewText);
}

function PNotifiDiscussion(DiscussionID,SetText,UnSetText) {
	$(this).addClass('SetNotifiDiscussion_'+DiscussionID,'Progress');
	if ($('#SetNotifiDiscussion_'+DiscussionID).text() == SetText) {
		Value = 1;
		NewText = UnSetText;
	} else {
		Value = 0;
		NewText = SetText;
	}
	SetNotifi('DISCUSSION',DiscussionID,Value,'SetNotifiDiscussion_'+DiscussionID,'Progress',NewText);
}

function NotifiAll() {
	$(Element).addClass('NotifiAllCont','PreferenceProgress');
	if ($('#NotifiAllField').attr('checked')) Value = 1;
	else Value = 0;
	SetNotifi('ALL',0,Value,'NotifiAllCont','PreferenceProgress','');
}

function NotifiOwn() {
	$(Element).addClass('NotifiOwnCont','PreferenceProgress');
	if ($('#NotifiOwnField').attr('checked')) Value = 1;
	else Value = 0;
	SetNotifi('OWN',0,Value,'NotifiOwnCont','PreferenceProgress','');
}

function NotifiComment() {
	$(Element).addClass('NotifiCommentCont','PreferenceProgress');
	if ($('#NotifiCommentField').attr('checked')) Value = 1;
	else Value = 0;
	SetNotifi('COMMENT',0,Value,'NotifiCommentCont','PreferenceProgress','');
}

function KeepEmailing() {
	$(Element).addClass('KeepEmailingCont','PreferenceProgress');
	if ($('#KeepEmailingField').attr('checked')) Value = 1;
	else Value = 0;
	SetNotifi('KEEPEMAILING',0,Value,'KeepEmailingCont','PreferenceProgress','');
}