// custom ajax loading function
	function showAjaxLoading(element_id) {
		var height = document.getElementById(element_id).offsetHeight;
		document.getElementById(element_id).innerHTML = '<div style="height:' + height + 'px;"><img width="32" height="32" align="middle" alt="Loading..." style="padding-left:45%;padding-top:30%;" src="/static/gfx/community/ajax_loading.gif"></div>';
	}
// ivw & google tracker for dynamic/ajax reloads
function dynamicTracker(ivw_key) {
	// ivw
	var get_rand = "d=" + (Math.random()*100000);
	var get_referer = "r=" + escape(document.referrer);
	var countIVW = new Image();
	countIVW.src = "http://cynamite.ivwbox.de/cgi-bin/ivw/CP/" + ivw_key + ";?" + get_referer + "&" + get_rand;

	//google
	_gaq.push(['_trackPageview']);
}

/* globale defaults */
function MM_window(theURL,wname,features) { return window.open(theURL,wname,features);	}
function MM_preloadStyles() { var d=document; if(d.Styles){ if(!d.MM_p) d.MM_p=new Array(); var i,j=d.MM_p.length,a=MM_preloadStyles.arguments; for(i=0; i<a.length; i++) if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Style; d.MM_p[j++].src=a[i];}}}
function MM_ImgDetailCom(pk,fk) { MM_window('/static/community/galleries/detailcom.cfm?pk=' + pk + '&fk=' + fk,'BildPopup','width=900,height=720,resizable=yes,scrollbars=no'); }
function MM_ImgDetailGal(pk,fk,opv){if(!opv)opv='gal'; MM_window('/static/community/galleries/detail.cfm?pk=' + pk + '&fk=' + fk + '&opv=' + opv,'Galerie',''); }
function MM_UserNotify(pk) { MM_window('/static/community/user/notify.cfm?pk=' + pk,'Meldung','width=680,height=450,resizable=no,scrollbars=yes'); }
function MM_ClubNotify(pk) { MM_window('/static/community/clubs/notify.cfm?pk=' + pk,'Meldung','width=680,height=450,resizable=no,scrollbars=yes'); }
function MM_BlogNotify(pk) { MM_window('/static/community/blogs/notify.cfm?pk=' + pk,'Meldung','width=680,height=450,resizable=no,scrollbars=yes'); }
function MM_Colorpicker(formname,fieldname,fieldvalue)  { MM_window('/static/community/defaults/colorpicker.cfm?formname=' + formname + '&fieldname=' + fieldname + '&fieldvalue' + fieldvalue,'Farbwahl','width=298,height=155,resizable=no,scrollbars=no'); }
function MM_popup(URL,wname,features) { window.open(URL,wname,features); }
function ClearFormField(FF, FFValue) { if(FF.value == FFValue) { FF.value = ''; } else if(FF.value == '') { FF.value = FFValue; } }
function MM_CalenderDetail(pid,opv) { MM_window('/static/community/calender/detail.cfm?pid=' + pid + '&opv=' + opv,'CalenderDetailPopup','width=300,height=300,resizable=yes,scrollbars=yes'); }
function MM_ClubsMyClubs(pk,fk) { MM_window('/static/community/clubs/invite_user.cfm?pk=' + pk,'ClubList','width=480,height=300,resizable=yes,scrollbars=yes'); }
function MM_newtracker(fk,opv) { MM_window('/static/community/tracker/editTracker.cfm?fk=' + fk +'&opv=' + opv,'NewTracker','width=490,height=350,resizable=no,scrollbars=yes'); }
function MM_usertracker(fk,opv,op) { MM_window('/static/community/tracker/editTracker.cfm?fk=' + fk + '&opv=' + opv + '&op=' + op,'UserTracker','width=490,height=350,resizable=no,scrollbars=yes'); }
function MM_Hints(opv) { MM_window('/static/standardcontents/hints/hint.cfm?opv=' + opv,'Hints','width=490,height=350,resizable=no,scrollbars=yes'); }
function MM_CynamitePopup(pk) { MM_window('/static/standardcontents/cynamitepopup/cynamitepopup.cfm?pk=' + pk, 'Cynamitepopup','width=800,height=600,resizable=no,scrollbars=no'); }
function MM_LinkPopup(link) { MM_window(link, 'Cynamitepopup','width=800,height=600,resizable=no,scrollbars=yes'); }
function MM_blogpreview()
{
	if(document.BlogForm.BlogText.value != '')
	{
		var tmpWindow = MM_window('/static/community/blogs/blogpreview.cfm','blogpreview','width=665,height=590,resizable=yes,scrollbars=yes');
		document.BlogPreviewForm.PreviewContent.value = document.BlogForm.BlogText.value;
		document.BlogPreviewForm.submit();
		tmpWindow.focus();
	}
}
function MM_ClubBlogpreview()
{
	if(document.ClubCommentsForm.comment.value != '')
	{
		var tmpWindow = MM_window('/static/community/blogs/blogpreview.cfm','blogpreview','width=655,height=470,resizable=yes,scrollbars=yes');
		document.BlogPreviewForm.PreviewContent.value = document.ClubCommentsForm.comment.value;
		document.BlogPreviewForm.submit();
		tmpWindow.focus();
	}
}

/** PRIVATE MESSAGES **/
var iCurrentPage = 1, sCurrentOrderBy = 'm.creadate', sCurrentOrderDirection = 'desc', sCurrentView = 'inbox', iCurrentUserFilter = 0, dCurrentFromFilter = '', dCurrentToFilter = '', iCurrentCustomFolderID = 0;
function initAjaxMessages() {
	oCynCom = new cynCommunity();
	oCynCom.setHTTPMethod('post');
}
function resetPMFilters() {
	iCurrentUserFilter = 0;
	dCurrentFromFilter = '';
	dCurrentToFilter = '';
}
function loadMessageView(iPage, sOrderBy, sOrderDirection, sView, sRecipient, iClubID) {
	showLoading('messageBoxAjax');
	iCurrentPage = iPage; sCurrentOrderBy = sOrderBy; sCurrentOrderDirection = sOrderDirection; sCurrentView = sView;
	//callback handler sets also async mode; in sync mode (without callback) loading anim is not visible in chrome and ie8/9
	oCynCom.setCallbackHandler(function(result) { 
		handleResponse(result, 'messageBoxAjax'); 
		if(sView != 'new') { 
			$('a.pnNew').attr('title', 'Nachricht in neuem Tab/Fenster öffnen');
		}
		if(iCurrentUserFilter > 0 || dCurrentFromFilter.length > 0 || dCurrentToFilter.length > 0) {
			$("#dFromFilter").datepicker();
			$("#dToFilter").datepicker();
		}
	});
	if(sView == 'new') {
		messageAction(0, 'new', sRecipient, iClubID)		
	}
	else {
		oCynCom.loadMessageView(iPage, sOrderBy, sOrderDirection, sView, iCurrentUserFilter, dCurrentFromFilter, dCurrentToFilter, iCurrentCustomFolderID);		
	}
	$('.NaviMessageCenter').removeClass('Active');
	$('#' + sView).addClass('Active');
}
function loadMessageOptions() {
	showLoading('messageBoxAjax');
	$.post('/webservices/community/cynamiteCommunity.cfc', { method:'loadMessageOptions' }, function(data) { 
		handleResponse(data, 'messageBoxAjax');
		$('.NaviMessageCenter').removeClass('Active');
		$('#' + sView).addClass('Active'); 
	});
}
function savePNOptions(){
	showSmallLoading('optionsLoading');
	$('#optionsSubmit').hide();
	$.post('/webservices/community/cynamiteCommunity.cfc', $("#pnOptions").serialize(), function(data) { 
		$('#optionsLoading').html('Optionen wurden gespeichert.');
	});		
}
function loadFilteredMessageView(iUserFilter, dFromFilter, dToFilter, iCustomFolderID) {		
	iCurrentUserFilter = iUserFilter; 
	dCurrentFromFilter = dFromFilter;
	dCurrentToFilter = dToFilter;
	iCurrentCustomFolderID = iCustomFolderID;
	loadMessageView(1, 'm.creadate', 'desc', sCurrentView);
}
function togglePMFilter() {
	$('#pmFilter').slideToggle('fast', function() {
		if($('#pmFilter').css('display') == 'block') {
			$('#pmFilterImg').attr('title', 'Filter-Optionen ausblenden');
			$("#dFromFilter").datepicker();
			$("#dToFilter").datepicker();
		}
		else {
			$('#pmFilterImg').attr('title', 'Filter-Optionen einblenden');
		}
	});	
}
function loadMD(iMessageID) {
	loadMessageDetail(iMessageID, iCurrentPage, sCurrentOrderBy, sCurrentOrderDirection, sCurrentView);
}
function loadMDNew(iMessageID) {
	window.open('/?menu=community&section=mysite&mysitesection=nachrichten&view=' + sCurrentView + '&page=' + iCurrentPage + '&order_by=' + sCurrentOrderBy + '&order_direction=' + sCurrentOrderDirection + '&iUserFilter=' + iCurrentUserFilter + '&dFromFilter=' + dCurrentFromFilter + '&dToFilter=' + dCurrentToFilter + '&message_id=' + iMessageID + '#profileNavi', 'PM' + iMessageID);
}
function loadMessageDetail(iMessageID, iPage, sOrderBy, sOrderDirection, sView) {
	showLoading('messageBoxAjax');
	oCynCom.loadMessageDetail(iMessageID, iPage, sOrderBy, sOrderDirection, sView);
	/* meaningful only if notification numbers would be pushed while using pm system 
	if(bUpdateNotifications == true) {
		//decrease number of notifications by 1
		$('#bp-adminbar-notifications-menu a span').html($('#bp-adminbar-notifications-menu a span').html()-1);
		//decrease number of new private messages by 1
		var iNewPrivateMessages = parseInt($('#bp-adminbar-notifications-menu ul li:first-child a').html())-1;
		if(iNewPrivateMessages == 1) {
			$('#bp-adminbar-notifications-menu ul li:first-child a').html('1 neue private Nachricht');
		}
		else {
			$('#bp-adminbar-notifications-menu ul li:first-child a').html(iNewPrivateMessages + ' neue private Nachrichten');
		}
	}*/
}
function messageAction(iMessageID, sAction, sRecipient, iClubID) {
	showLoading('messageBoxAjax');
	oCynCom.messageAction(iMessageID, sAction, sRecipient, iClubID);
}
function sendMessage() {
	$('#messageSubmit').hide();
	showSmallLoading('messageSubmitLoading');
	initAjaxMessages();
	oCynCom.setCallbackHandler(sendMessageResult);
	oCynCom.setForm('MsgForm');
	oCynCom.sendMessage();
}
function sendMessageResult(sResult) {
	//reset cfajaxproxy and load outbox view
	if(sResult == 'OK') {
		initAjaxMessages();
		oCynCom.setCallbackHandler(function(result) { handleResponse(result, 'messageBoxAjax'); });
		loadMessageView(1, 'm.creadate', 'desc', 'outbox', '');
	}
	//error handling
	else {
		$('#messageSubmitLoading').hide();
		$('#errorMessage').html(sResult);
		$('#errorMessage').show();
		$('#messageSubmit').show();		
	}
}
function deleteMessages(iMessageID) {
	var bConfirm = false;
	if(iMessageID > 0) {
		bConfirm = ConfDel('diese Nachricht');	
		if(bConfirm == true) {
			showLoading('messageBoxAjax');
			oCynCom.setCallbackHandler(function(result) { oCynCom.setCallbackHandler(function(result) { handleResponse(result, 'messageBoxAjax'); }); loadMessageView(iCurrentPage, sCurrentOrderBy, sCurrentOrderDirection, sCurrentView, iCurrentUserFilter, dCurrentFromFilter, dCurrentToFilter); });
			oCynCom.deleteMessages(iMessageID);						
		}
	}
	else {
		var aryCheckedMessages = $('.MessageBox input[name="delPM"]:checked');		
		if(aryCheckedMessages.length > 0) {
			bConfirm = ConfDel('diese Nachricht(en)');	
			if(bConfirm == true) {				
				oCynCom.setCallbackHandler(function(result) { oCynCom.setCallbackHandler(function(result) { handleResponse(result, 'messageBoxAjax'); }); loadMessageView(iCurrentPage, sCurrentOrderBy, sCurrentOrderDirection, sCurrentView, iCurrentUserFilter, dCurrentFromFilter, dCurrentToFilter); });
				oCynCom.setForm('delMessages');
				oCynCom.deleteMessages();
				showLoading('messageBoxAjax');
			}
		}
		else {
			alert('Du hast noch keine Nachricht(en) zum Löschen ausgewählt!');
		}
	}
}
var checkflag = false;
function CheckBoxes() {
	if(document.delMessages.elements.length == 1) {
		if(checkflag == false) {			
			document.delMessages.delPM.checked = true;
			checkflag = true;
		}
		else {
			document.delMessages.delPM.checked = false;
			checkflag = false;
		}
	}
	else {
		if(checkflag == false) {
			for (i=0; i < $('.MessageBox input[name="delPM"]').length; i++) {
				document.delMessages.delPM[i].checked = true;
			}
			checkflag = true;
		}
		else {
			for (i=0; i < $('.MessageBox input[name="delPM"]').length; i++) {
				document.delMessages.delPM[i].checked = false;
			}
			checkflag = false;
		}
	}
}
function createPMFolder(sFolderName) {
	if(sFolderName.length == 0) {
		alert('Bitte einen Namen für den Ordner eintragen (max. 30 Buchstaben)!');
	}
	else {
		showSmallLoading('createPMFolderInput');
		$.ajax({
			url: '/webservices/community/cynamiteCommunity.cfc',
			type: 'POST',
			data: { method:'createPMFolder', sFolderName:sFolderName },
			dataType: 'json',
			success: function(data) {											
				if(data[0] == 'Error') {
					alert(data[1]);							
				}
				else {							
					resetPMFilters();
					iCurrentCustomFolderID = data[1];
					loadMessageView(1, 'm.creadate', 'desc', 'custom');
				}
				getCustomFolderDropdown();
			}
		});	
	}
}
function moveMessages(iSourceFolderID, iTargetFolderID, iPosition) {
	var aryCheckedMessages = $('.MessageBox input[name="delPM"]:checked');
	if(aryCheckedMessages.length == 0) {
		alert('Du hast noch keine Nachricht(en) ausgewählt!');
	}
	else {
		showSmallLoading('pmMov' + iPosition);	
		$.ajax({
			url: '/webservices/community/cynamiteCommunity.cfc?method=moveMessages&iSourceFolderID=' + iSourceFolderID + '&iTargetFolderID=' + iTargetFolderID,
			type: 'POST',
			data: $('#delMessages').serialize(),
			dataType: 'json',
			success: function(data) {
				if(data[0] == 'Error') {
					alert(data[1]);			
					$('#pmMov' + iPosition).html('Nachricht(en) verschieben nach:');
				}
				else {
					resetPMFilters();
					//load custom folder
					if(iTargetFolderID > 0) {
						iCurrentCustomFolderID = iTargetFolderID;
						loadMessageView(1, 'm.creadate', 'desc', 'custom');
					}
					//load inbox
					else {
						iCurrentCustomFolderID = 0;
						loadMessageView(1, 'm.creadate', 'desc', 'inbox');
					}
					//reload custom folder dropdown to get current message counts
					getCustomFolderDropdown();
				}
			}
		});
	}
}
function deletePMFolder(iFolderID, iMessages) {
	var sConfirmMessage = 'Bist Du sicher?';
	if(iMessages > 0) {
		sConfirmMessage = 'Alle Nachrichten in diesem Ordner werden in den Posteingang verschoben. ' + sConfirmMessage;
	}
	if(confirm(sConfirmMessage)) {
		showLoading('messageBoxAjax');
		$.ajax({
			url: '/webservices/community/cynamiteCommunity.cfc',
			type: 'POST',
			data: { method:'deletePMFolder', iFolderID:iFolderID },
			dataType: 'text',
			success: function(data) {
				getCustomFolderDropdown();
				loadMessageView(1, 'm.creadate', 'desc', 'inbox');
			}
		});
	}
}
function getCustomFolderDropdown() {
	$.ajax({
		url: '/webservices/community/cynamiteCommunity.cfc',
		type: 'POST',
		data: { method:'getCustomFolderDropdown' },
		dataType: 'text',
		success: function(data) {
			$('#pmCFM').html(data);
		}
	});
}
function MM_msgpreview() {
	if(document.MsgForm.sMessage.value != '')	{
		var tmpWindow = MM_window('/static/community/messages/msgpreview.cfm','msgpreview','width=655,height=670,resizable=yes,scrollbars=yes');
		document.MsgPreviewForm.PreviewContent.value = document.MsgForm.sMessage.value;
		document.MsgPreviewForm.submit();
		tmpWindow.focus();
	}
}

function nicknameLiveSearch(sElementID, bMultiple, bExcludeSelected, callback) {
	$('#' + sElementID).live('keydown', function() {
		$(this)
			// don't navigate away from the field on tab when selecting an item
			.bind("keydown", function(event) {
				if(event.keyCode === $.ui.keyCode.TAB && $(this).data("autocomplete").menu.active ) {
					event.preventDefault();
				}
			})
			.autocomplete({
				source:function(request, response) {
					$.getJSON("/webservices/community/cynamiteCommunity.cfc?method=nicknameLiveSearch", {
						sSearchTerm:extractLast(request.term),
						lRecipients:$('#' + sElementID).attr('value'),
						bExcludeSelected:bExcludeSelected
					}, response);
				},
				search:function() {
					// custom minLength
					var term = extractLast(this.value);
					if(term.length < 3) {
						return false;
					}
				},
				focus:function() {
					// prevent value inserted on focus
					return false;
				},
				select:function(event, ui) {
					var terms = trimSplit(this.value);
					if(bMultiple == true) {
						// remove the current input
						terms.pop();
						// add the selected item
						terms.push(ui.item.value);					
						// add placeholder to get the comma-and-space at the end
						terms.push("");
						this.value = terms.join(", ");
					}
					else {
						this.value = ui.item.value;
					}
					if(typeof callback == 'function') {
						callback();
					}
					return true;
				}
		});
	});	
}

/** for autocompletes **/
function trimSplit(val) {
	return val.split( /,\s*/ );
}
function extractLast(term) {
	return trimSplit(term).pop();
}

/* show fans/likes */
function showAllFans(sLikeType, iObjectID) {
	var sWindowname = sLikeType + 'Fans' + iObjectID;
	ColdFusion.Window.create(sWindowname, 'Alle Fans dieses ' + sLikeType + 's', '/webservices/community/cynamiteCommunity.cfc?method=getAllFans&sLikeType=' + sLikeType + '&iObjectID=' + iObjectID,
	{ width:330, height:400, modal:false, closable:true, draggable:true, resizable:false, center:true, initshow:true });	
	ColdFusion.Window.onHide(sWindowname, function() { ColdFusion.Window.destroy(sWindowname, true) });
}

/* globale Löschen-Rückfrage */
function ConfDel(sText) {
	check=confirm('Willst Du ' + sText + ' wirklich löschen?')
	if(check == false)
		return false;
	else 
		return true;
}

/* my collection: add/edit/remove products */
function editCollectionWindow(iEntityID) { 
	ColdFusion.Window.create('editProduct', 'Produkt aus der Sammlung bearbeiten', '/static/community/collections/iframe.cfm?fk=' + iEntityID,
	{ width:470, height:205, modal:false, closable:true, draggable:true, resizable:false, center:true, initshow:true });	
	ColdFusion.Window.onHide('editProduct', function() { ColdFusion.Window.destroy('editProduct', true) });
}
function addCollection(iEntityID, bEdit, sLocation) {
	$.ajax({
		type: 'POST',
		url: '/webservices/community/cynamiteCommunity.cfc?method=addCollection',
		data: 'iEntityID=' + iEntityID,
		success: function(){
			//product actions on product pages and articles
			if(sLocation == 'productActions') {
				iCollectionStatus = 2;
				setCollectionHTML();
			} 
			//search result
			else {
				$('#addColl' + iEntityID).hide();
				$('#delColl' + iEntityID).show();
			}
			
			if(bEdit == true) {
				editCollectionWindow(iEntityID);
			}
		}
	});	
}
function editCollection(iEntityID, sStatusType, iNewStatus) {	
	if(sStatusType == 'sell') {
		if(iNewStatus == 1) {
			$('#p' + iEntityID).show();
		}
		else if($('#p' + iEntityID).attr('value').length == 0) {
			$('#p' + iEntityID).hide();
		}
	}
	//oCynCom is created in webscripts/modules/profile/collection/overview.inc
	oCynCom.editCollection(iEntityID, sStatusType, iNewStatus);
	if(iNewStatus == 1) {
		//status is on: set edit link to off, image to on
		$('#a' + sStatusType + iEntityID).attr('onClick', 'editCollection(' + iEntityID + ', \'' + sStatusType + '\', 0);');
		$('#i' + sStatusType + iEntityID).attr('src', '/static/gfx/community/misc/box_on.gif');
	}
	else {
		//status is off: set edit link to on, image to off
		$('#a' + sStatusType + iEntityID).attr('onClick', 'editCollection(' + iEntityID + ', \'' + sStatusType + '\', 1);');
		$('#i' + sStatusType + iEntityID).attr('src', '/static/gfx/community/misc/box_off.gif');
	}
}
function editCollectionPrice(iEntityID, sPrice) {
	var fPrice = 0;
	if(sPrice.length > 0) {
		var fPrice = sPrice.replace(/,/,'.');
		if(isNaN(fPrice)) {
			alert('Bitte gib einen gültigen Preis an (Cent-Beträge mit Komma trennen)!');
			return false;
		}
	}
	oCynCom.editCollectionPrice(iEntityID, fPrice);
}
function removeCollection(iEntityID, sLocation) {
	var bConfirm = confirm('Willst Du dieses Produkt wirklich aus Deiner Sammlung entfernen?');
	if(bConfirm == true) {
		$.ajax({
			type: 'POST',
			url: '/webservices/community/cynamiteCommunity.cfc?method=removeCollection',
			data: 'iEntityID=' + iEntityID,
			success: function(){
				//product actions on product pages and articles
				if(sLocation == 'productActions') {
					iCollectionStatus = 1;
					setCollectionHTML();
				} 
				//my collection
				else if (sLocation == 'collection') {
					$('#tr' + iEntityID).remove();
					$('#collCount').html(parseInt($('#collCount').html())-1);
					if(parseInt($('#collCount').html()) == 1) {
						$('#collCountDesc').html('Eintrag');
					}
					//needed when coming from 1 entry -> 0 entries
					else {
						$('#collCountDesc').html('Einträge');
					}
				}
				//search result
				else {
					$('#delColl' + iEntityID).hide();
					$('#addColl' + iEntityID).show();
				}
			}
		});			
	}
}

function deleteRatings(rating_type, object_id) {
	var bConfirm = confirm('Willst Du wirklich alle Bewertungen löschen?');
	if(bConfirm == true) {
		$('#ratingStars_' + rating_type).html('');
		$('#ratingStars_' + rating_type).css('height', '11px');
		$('#ratingStars_' + rating_type).css('padding-top', '0px');
		showSmallLoading('ratingStars_' + rating_type);
		$.ajax({
			type: 'POST',
			url: '/webservices/community/cynamiteCommunity.cfc?method=deleteAllpurposeRatings',
			data: 'sRatingType=' + rating_type + '&iObjectID=' + object_id,
			success: function(result){
				if(result != 'failed') {
					$('#ratingDelete').remove();
					$('#ratingHead').css('width', '100%');
					$('#ratingStars_' + rating_type).html('');
					$('#ratingStars_' + rating_type).css('height', 'inherit');
					$('#ratingStars_' + rating_type).css('padding-top', '');
					eval('getRating_' + rating_type + '()');					
				}
			}
		});		
	}
}

/*** community admin/mod functions ***/
function loadWarningTool(iCurrentUserID) {
	loadLayer();
	showLoading('editbox');
	$.post('/webservices/community/cynamiteCommunityAdmin.cfc', { method:'getWarningToolHTML', iCurrentUserID:iCurrentUserID }, function(data) { handleResponse(data, 'editbox'); nicknameLiveSearch('warnedUser', false, false); nicknameLiveSearch('sFilterNickname', false, false, getFilteredWarningLogHTML); }, 'text');
}
function getWarningLogHTML(page, iFilterID, sFilterNickname) {
	showLoading('warningLog');
	$.post('/webservices/community/cynamiteCommunityAdmin.cfc', { method:'getWarningLogHTML', page:page, iFilterID:iFilterID, sFilterNickname:sFilterNickname }, function(data) { handleResponse(data, 'warningLog'); }, 'text');
}
function addWarnedUser(sWarnedUser, iWarningPoints, sWarningReason, sForumPost) {
	if(sWarnedUser.length == 0) {
		alert('Bitte einen Usernamen angeben!');
	}
	else if(sWarningReason.length == 0 && sForumPost.length == 0) {
		alert('Bitte einen Grund angeben oder ein Foren-Posting eintragen!');
	}
	else {
		showSmallLoading('addWarnLoading');
		$.post('/webservices/community/cynamiteCommunityAdmin.cfc', { method:'addWarnedUser', sWarnedUser:sWarnedUser, iWarningPoints:iWarningPoints, sWarningReason:sWarningReason, sForumPost:sForumPost }, function(data) { 
			if(data != 'OK') {
				alert(data);
			}
			else {
				getWarningLogHTML(1, 0, '');
			}
			$('#addWarnLoading').html('');
		}, 'text');
	}
}
function deleteUserWarning(iLogID, page, iFilterID, sFilterNickname) {
	if(confirm('Bist Du sicher?')) {
		showLoading('warningLog');
		$.post('/webservices/community/cynamiteCommunityAdmin.cfc', { method:'deleteUserWarning', iLogID:iLogID }, function(data) { getWarningLogHTML(page, iFilterID, sFilterNickname); }, 'text');	
	}
}
function getFilteredWarningLogHTML() {
	getWarningLogHTML(1, 0, $('#sFilterNickname').val());
}
function loadModeratorLog() {
	loadLayer();
	showLoading('editbox');
	handleResponse(cynComAdmin.getModeratorLogHTML(), 'editbox');
}
function loadModLogPage(page_no) {
	showLoading('modlog');
	handleResponse(cynComAdmin.getModLogTableHTML(page_no), 'modlog');
}
function showTemporaryBannedUsers() {
	loadLayer();
	showLoading('editbox');
	handleResponse(cynComAdmin.getTemporaryBannedUsersHTML(), 'editbox');
}
function loadTempBanPage(page_no) {
	showLoading('temp_banned_table');
	handleResponse(cynComAdmin.getTemporaryBannedUsersTableHTML(page_no), 'temp_banned_table');
}
function addToCommunityTeaser(teaser_id, content_id, content, status, user_id) {
	handleResponse(cynComAdmin.addToCommunityTeaser(teaser_id, content_id, content, status, user_id), "adminbar-community-teaser");
}			

function removeCommunityItem(contend_id, content, action, user_id) {
	if(action == "offline") {
		bConfirm = confirm("Bist Du sicher?");		
	}
	else {
		bConfirm = confirm("Bist Du sicher? Gelöschte Daten können nicht wiederhergestellt werden!");
	}
	if(bConfirm == true) {
		sResultMessage = cynComAdmin.removeCommunityItem(contend_id, content, action, user_id);	
		alert(sResultMessage);
		document.location.reload();
	}
}

function loadUserEditor(user_id) {
	loadLayer();
	showLoading('editbox');
	handleResponse(cynComAdmin.getUserEditorHTML(user_id), 'editbox');
}

function checkUserStatus(selected_status) {
	if(selected_status == -1) {
		$('#userStatus').css('width', '160px');
		$("div[id*='banned']").show();
	}
	else {
		$('#userStatus').css('width', '232px');
		$("div[id*='banned']").hide();			
	}		
}

function loadClubEditor(club_id) {
	loadLayer();
	showLoading('editbox');
	handleResponse(cynComAdmin.getClubEditorHTML(club_id), 'editbox');
}

function saveUserData(user_id) {	
	var bDoSave = true;

	if($('#userStatus').attr('value') == -1) {
		if(!(isValidDate($('#banned_end_date').attr('value'), 'DMY'))) {
			alert('Bitte ein gültiges Entsperrdatum eingeben!');
			bDoSave = false;
		}
		else if($('#banned_reason').attr('value').length < 20) {
			alert('Bitte einen aussagekräftigen Grund für die Sperre angeben!');
			bDoSave = false;
		}
	}
	
	if(bDoSave == true) {
		cynComAdmin.setForm('user_accountdata');
		sSuccess = cynComAdmin.saveUserData();
		if(sSuccess != "OK") {		
			handleResponse(sSuccess, 'editbox');
		}
		else {
			handleResponse(cynComAdmin.getUserEditorHTML(user_id), 'editbox');
		}
	}
}

function saveClubData(club_id) {
	cynComAdmin.setForm('club_data');
	sSuccess = cynComAdmin.saveClubData();
	if(sSuccess != "OK") {		
		handleResponse(sSuccess, 'editbox');
	}
	else {
		handleResponse(cynComAdmin.getClubEditorHTML(club_id), 'editbox');
	}
}

function saveClubMemberData(club_id, form_id, page_no) {
	cynComAdmin.setForm(form_id);
	sSuccess = cynComAdmin.saveClubMemberData();
	if(sSuccess != "OK") {		
		handleResponse(sSuccess, 'editbox');
	}
	else {
		loadClubMemberPage(club_id, page_no);
	}
}

function loadClubMemberPage(club_id, page_no) {
	showLoading('club_memberdatatable');
	handleResponse(cynComAdmin.getClubMembersHTML(club_id, page_no), 'club_memberdatatable');
}

function deleteClubCategory(club_id, category_id) {
	showLoading('editbox');
	bDelete = cynComAdmin.deleteClubCategory(club_id, category_id);
	handleResponse(cynComAdmin.getClubEditorHTML(club_id), 'editbox');
}

function deleteUserImage(content_id, category_id, image_id) {
	sSuccess = cynComAdmin.deleteUserImage(content_id, category_id, image_id);
	if(sSuccess != "OK") {
		handleResponse(sSuccess, 'editbox');
	}
	else {
		switch(category_id) {
			//avatar, wallpaper, gallery -> user
			case 1:
			case 3:
			case 5:
				handleResponse(cynComAdmin.getUserEditorHTML(content_id), 'editbox');			
			break;
			//club-teaser, club-detail -> club
			case 7:
			case 8:
				handleResponse(cynComAdmin.getClubEditorHTML(content_id), 'editbox');			
			break;
		}
	}
}

function updatePointActions(user_id) {
	showLoading('pointsinnertable');	
	$("#pointsbutton").attr("disabled", "true");	
	$("#pointsbutton").html("Bitte warten...");
	cynComAdmin.setForm('pointsform');
	bSuccess = handleResponse(cynComAdmin.getUserPointActionsHTML(user_id), 'pointstable');	
	$("#pointsbutton").html("Aktualisieren");	
	$("#pointsbutton").removeAttr("disabled");		
}
	
/* für Community-Startseite */
function topen(name) {
  var n1 = name+"1", n2 = name+"2", n3 = name+"3", n4 = name+"4", n5 = name+"5", n6 = name+"6";
  document.getElementById(n1).style.display = "none"; document.getElementById(n2).style.display = "inline"; document.getElementById(n3).style.display = "inline";
  document.getElementById(n4).style.display = "none"; document.getElementById(n5).style.display = "inline"; document.getElementById(n6).style.display = "inline";
  expires = new Date();
  expires.setTime(expires.getTime() + 87765);
  cookiename = "cycom_open_"+n1;
  set_cookie(cookiename, "1", expires);
}

function tclose(name) {
  var n1 = name+"1", n2 = name+"2", n3 = name+"3", n4 = name+"4", n5 = name+"5", n6 = name+"6";
  document.getElementById(n1).style.display = "inline"; document.getElementById(n2).style.display = "none"; document.getElementById(n3).style.display = "none";
  document.getElementById(n4).style.display = "inline"; document.getElementById(n5).style.display = "none"; document.getElementById(n6).style.display = "none";
  cookiename = "cycom_open_"+n1;
  delete_cookie(cookiename);
}

// ex-topnavi; wird noch gebraucht für community-subnavi, ev. an anderern stellen?
var preloadFlag = true;
function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}
function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}
