var del_posts_confirm_win;

function mark_post(type,postid) {
	if(type == 'delete') {
		if(document.getElementById('delpost-' + postid).value & 1)
			document.getElementById('delpost-' + postid).value -= 1;
		else
			document.getElementById('delpost-' + postid).value += 1;

		if(document.getElementById('delpost-' + postid).value & 1) {
			animate(document.getElementById('p' + postid),'opacity',1,0.5,250);
			document.getElementById('a-del-post-' + postid).style.textDecoration = 'line-through';
		} else {
			animate(document.getElementById('p' + postid),'opacity',0.5,1,250);
			document.getElementById('a-del-post-' + postid).style.textDecoration = '';
		}
		
		inputfields = document.getElementsByTagName('input');
		hinputfields = '';
		posts_to_delete = 0;
		for(f in inputfields) {
			if(typeof(inputfields[f].id)!='undefined' && inputfields[f].id.match(/^delpost-([0-9])+$/) && inputfields[f].value == 1) {
				posts_to_delete++;
				pid = inputfields[f].id.replace(/^delpost-/,'');
				hinputfields += '<input type="hidden" value="'+pid+'" name="dp['+pid+']" />';
			}
		}
		
		if(posts_to_delete == 0) {
			if(typeof(del_posts_confirm_win)!='undefined')
				del_posts_confirm_win.closeWin();
				del_posts_confirm_win.destroy();
		} else {
			if(typeof(del_posts_confirm_win)=='undefined') {
				del_posts_confirm_win = new sitePEWin({close:false, resizable:false, enlarge:false});
				del_posts_confirm_win.setTitle('L&ouml;schen?');
				del_posts_confirm_win.setHeight(80);
				del_posts_confirm_win.setWidth(300);
			}
			
			if(del_posts_confirm_win.top < scrollTop || del_posts_confirm_win.top > scrollTop+20) {
				del_posts_confirm_win.setTop(scrollTop+50);
			}

			winText = '<div><form enctype="multipart/form-data" method="post" id="dpForm" action="">';
			if(posts_to_delete == 1)
				winText += 'Den ausgew&auml;hlten Post wirklich l&ouml;schen?';
			else
				winText += 'Die '+posts_to_delete+' ausgew&auml;hlten Posts wirklich l&ouml;schen?';
			winText += hinputfields;
			winText += '<div style="text-align: center"><input type="button" value="Abbrechen" onclick="abort_del_post();" /> <input type="hidden" name="subdelposts" value="L&ouml;schen" /> <input type="button" onclick="subDelPosts()" value="L&ouml;schen" /></div>';
			winText += '</form></div>';
			
			del_posts_confirm_win.setContent(winText);
		}
	}
}

function subDelPosts() {
	sRL = new serverRequestLayer(document.getElementById('dpForm').submit);
}

function abort_del_post() {
	inputfields = document.getElementsByTagName('input');
	for(f in inputfields) {
		if(typeof(inputfields[f].id)!='undefined' && inputfields[f].id.match(/^delpost-([0-9])+$/) && inputfields[f].value == 1) {
			pid = inputfields[f].id.replace(/^delpost-/,'');
			mark_post('delete',pid);
		}
	}
}
