	function changeWidth(id,level){
		var post = document.getElementById('p_'+id);
		var content = document.getElementById('c_'+id)
		var postWidth = parseInt(post.style.width) - level*10;
		post.style.width = postWidth + "px";
		var contentWidth = parseInt(content.style.width)-level*10;
		content.style.width=contentWidth+"px";
	}
	
	var savedPostId = 0;

	function showAnswerForm(postId,isThread) {
		resetUserActionBox();
		resetPostsForms();
		var element = $('formArea'+postId);
		element.style.height = $('answerFormBox').getHeight() + 'px';
		
		$('answerFormBox').style.top = element.offsetTop + 'px';
		if (!isThread){
			$('postId').value = postId;
		} else {
			$('postId').value = "";
		}
		
		$('answerButton'+postId).hide();
		$('answerFormBox').show();
		savedPostId = postId;		
	}
	
	
	function showAnswerFormWithSubject(postId,sub,isThread) {
		resetUserActionBox();
		resetPostsForms();
		
		var element = $('formArea'+postId);
		element.style.height = $('answerFormBox').getHeight() + 'px';
		
		$('answerFormBox').style.top = element.offsetTop + 'px';
		if (!isThread){
			$('postId').value = postId;
		} else {
			$('postId').value = "";
		}
		
		if (!sub.startsWith("Re:") && !sub.startsWith("re:")){
			sub = "Re: " + sub;
		}
		$('answerSubject').value = sub;
		
		$('answerButton'+postId).hide();
		$('answerFormBox').show();
		savedPostId = postId;
	}
	
	function closeForm(postId,message,counter){
		resetPostsForms();
		clearForm(postId);
		clearTextareaCounter(message,counter);
	}
	
	function clearTextareaCounter(message,counter){
		$('bodyCounterMsg').update(message);
		$('bodyCounter').update(counter);
	}
	
	function showBreachRegulationForm(postId,isThread) {
		resetUserActionBox();
		resetPostsForms();
		var element = $('formArea'+postId);
		element.style.height = $('breachFormBox').getHeight() + 'px';
		$('breachFormBox').style.top = element.offsetTop + 'px';
		if (!isThread){
			$('breachPostId').value = postId;
		} else {
			$('breachPostId').value = "";
		}
		$('breachButton'+postId).hide();
		$('breachFormBox').show();
		savedPostId = postId;
	}
	
	function showConfigurationForm(postId,isThread) {
		resetUserActionBox();
		resetPostsForms();
		if (!isThread){
			$('confirmationIsThread').value = false;
			$('textForThread').hide();
			$('textForPost').setStyle({display: 'block'});
			$('buttonForThread').hide();
			$('buttonForPost').setStyle({display: 'block'});
		} else {
			$('confirmationIsThread').value = true;
			$('textForThread').setStyle({display: 'block'});
			$('textForPost').hide();
			$('buttonForThread').setStyle({display: 'block'});
			$('buttonForPost').hide();
		}
		$('confirmationElementId').value =postId;
		$('confirmationButton'+postId).hide();
		$('confirmationFormBox').show();
		var element = $('formArea'+postId);
		element.style.height = $('confirmationFormBox').getHeight() + 'px';
		$('confirmationFormBox').style.top = element.offsetTop + 'px';
		savedPostId = postId;
	}
	
	
	function resetPostsForms() {
		if($('answerFormBox')!=null){
			$('answerFormBox').hide();
		}
		if($('breachFormBox')!=null){
			$('breachFormBox').hide();
		}
		if($('confirmationFormBox')!=null){
			$('confirmationFormBox').hide();
		}
		clearAllFormsAreas();
		showAllButtons();
	}
	
	function showAllButtons() {
		var elements = document.getElementsByClassName('answer_button');
		for (i=0; i<elements.length; i++){
			elements[i].show();
		}
		
		var elements = document.getElementsByClassName('breach_button');
		for (i=0; i<elements.length; i++){
			elements[i].show();
		}
		
		var elements = document.getElementsByClassName('confirmation_button');
		for (i=0; i<elements.length; i++){
			elements[i].show();
		}

		var elements = document.getElementsByClassName('confirmation_thr_button');
		for (i=0; i<elements.length; i++){
			elements[i].show();
		}
	}
	
	function clearAllFormsAreas() {
		var elements = document.getElementsByClassName('form_area');
		for (i=0; i<elements.length; i++){
			elements[i].style.height = '0';
		}
	}
	
	function clearForm(postId,message,counter) {
		clearAnswerFormFields();
		clearBreachFormFields();
		clearFormError();
		clearTextareaCounter(message,counter);
	}
	
	function clearFormError() {
		//wyrzucic warstwy z alertami
		var alerts = document.getElementsByClassName('error_info');
		for (i=0; i<alerts.length; i++){
			if (alerts[i]){
				alerts[i].hide();
			}
		}
	
		//wyczyscic style alertow
		var alerts = document.getElementsByClassName('form_item');
		for (i=0; i<alerts.length; i++){
				
			if (alerts[i]){
				alerts[i].removeClassName('error');
			}
		}
	}
	
	function clearAnswerFormFields() {
		$('answerSubject').value = "";
		$('answerBody').value = "";
	}
	
	function clearBreachFormFields() {
		if($('breachDescription')!=null){
			$('breachDescription').value = "";
		}
	}
	
	function clearNewThreadForm() {
		$('threadSubject').value = "";
		$('threadBody').value = "";
		clearFormError();
	}
	
	function hideAddThreadBox() {
		$('add_thread_box').hide();
		$('add_thread_area').hide();
		$('add_thread_area').removeClassName('layer');
		hideShadowLayer();
	}
	
	function showAddThreadBox() {
		resetUserActionBox();
		resetPostsForms();
		hideAddThreadBox();
		$('add_thread_area').setStyle({display: 'block'});
		$('add_thread_area').addClassName('layer');
		$('add_thread_box').setStyle({display: 'block'});
		showShadowLayer();
	}
	
	function clearThreadForm() {
		$('subject').value = "";
		$('body').value = "";
		clearFormError();
	}
	
	function showUpdateThreadForm(sub) {
		resetUserActionBox();
		
		$('threadUpdateFormBox').hide();
		if (sub != null && sub != ""){
			$('subject').value = sub;	
		}
		$('threadUpdateButton').hide();
		$('threadUpdateFormBox').show();
	}
	
	function showAddPostConfirmBox() {
		$('confirm_add_breach_box').hide();
		$('forum_action_confirm_area').setStyle({display: 'block'});
		$('forum_action_confirm_area').addClassName('layer');
		$('confirm_add_post_box').setStyle({display: 'block'});
		showShadowLayer();
	}
	
	function showAddBreachConfirmBox() {
		$('confirm_add_post_box').hide();
		$('forum_action_confirm_area').setStyle({display: 'block'});
		$('forum_action_confirm_area').addClassName('layer');
		$('confirm_add_breach_box').setStyle({display: 'block'});
		showShadowLayer();
	}
	
	function hideForumActionConfirmBox() {
		$('confirm_add_post_box').hide();
		$('confirm_add_breach_box').hide();
		$('forum_action_confirm_area').hide();
		$('forum_action_confirm_area').removeClassName('layer');
		hideShadowLayer();
	}
	
	function resetUserActionBox() {
		if ($('user_action_box') != null) {
			$('user_action_box').hide();
			$('user_action_box').removeClassName('layer');
		}
		hideShadowLayer();
	}
