﻿
/* General functions, used in more then one location */

function searchMain()
{
	if (document.forms["searchForm"].searchString.value == null || document.forms["searchForm"].searchString.value == '' || document.forms["searchForm"].searchString.value.length < 3) 
	{
		alert("עליך להזין תוכן באורך של 3 תווים ומעלה");
		return;
	}
	document.forms["submitSearch"].searchString.value = document.forms["searchForm"].searchString.value;	
	document.getElementById("submitSearch").submit();
}

function addTopic()
{
	document.forms["submitPosting"].mode.value = 'topic';	
	document.getElementById("submitPosting").submit();
}

function showSurvey(id, winHeight)
{
	win = window.open('/jsp/moomoo/surveyResults.jsp?id=' + id,'survey','status=no,scrollbars=no,resizable=yes,left=0,top=0,width=400,height=' + winHeight);
	win.focus();
}

function favShortFullToggle(name)
{
	if (document.getElementById(name + "Short").style.display == "")
	{
			document.getElementById(name + "Short").style.display = "none";
			document.getElementById(name + "FullToggle").style.display = "none";
			document.getElementById(name + "Full").style.display = "";
			document.getElementById(name + "ShortToggle").style.display = "";
	}
	else 
	{
			document.getElementById(name + "Short").style.display = "";
			document.getElementById(name + "FullToggle").style.display = "";
			document.getElementById(name + "Full").style.display = "none";
			document.getElementById(name + "ShortToggle").style.display = "none";
	}
}


/* viewForum only: */
function manageLinks(forumId){
	win = window.open('/servlet/com.dic.forums.site.servletManageForumLinks?forumid=' + forumId,'survey','status=no,scrollbars=yes,resizable=yes,left=0,top=0,width=450,height=600');
	win.focus();
}

/* viewTopic only: */

function sendWarning(userId, userName)
{
	win = window.open('/jsp/moomoo/forums/sendWarning.jsp?userId=' + userId + '&userName=' + userName,'warning','status=no,scrollbars=yes,resizable=yes,left=0,top=0,width=450,height=600');
	win.focus();
}

function reportPost(postId)
{
	document.forms["submitReportPost"].postid.value = postId;
	document.getElementById("submitReportPost").submit();
}


function showSurveyResults(id, winHeight){
	win=window.open('/jsp/moomoo/users/survey/surveyResults.jsp?id=' + id,'survey','status=no,scrollbars=no,resizable=yes,left=0,top=0,width=400,height=' + winHeight);
	win.focus();
}

function addQuickReply()
{
	var content = tinyMCE.activeEditor.getContent();		
	if (content == null || content == '')  
	{
		alert("עליך להזין תוכן");
		tinyMCE.activeEditor.focus();
		return;
	}
	else if (isTextFloat(content, 100))
	{
		alert('.אנא המנעו מלהציף במילים ארוכות את הפורומים. תודה');	
		tinyMCE.activeEditor.focus();
		return;
	} 
	document.forms["submitQuickReply"].content.value = content;
	document.forms["submitQuickReply"].signature.value = document.forms["quickReply"].options.checked;	
	
	document.getElementById("sendBtn").style.display='none';
	document.getElementById("sendBtnWait").style.display='';
	
	document.getElementById("submitQuickReply").submit();
}


function addReply(topicId)
{
	document.forms["submitPosting"].mode.value = 'reply';	
	document.forms["submitPosting"].topicid.value = topicId;
	document.getElementById("submitPosting").submit();
}


function addQuote(topicId, id)
{
	document.forms["submitPosting"].mode.value = 'quote';	
	document.forms["submitPosting"].topicid.value = topicId;
	document.forms["submitPosting"].postid.value = id;
	document.getElementById("submitPosting").submit();
}

function editPost(topicId, id)
{
	document.forms["submitPosting"].mode.value = 'edit';	
	document.forms["submitPosting"].topicid.value = topicId;
	document.forms["submitPosting"].postid.value = id;
	document.getElementById("submitPosting").submit();
}

function deletePost(topicId, id)
{
	document.forms["submitPosting"].mode.value = 'delete';	
	document.forms["submitPosting"].topicid.value = topicId;
	document.forms["submitPosting"].postid.value = id;
	document.getElementById("submitPosting").submit();
}

function deleteTopic()
{
	document.forms["submitQuickControl"].mode.value = 'delete';
	document.getElementById("submitQuickControl").submit();
}

function quickControl()
{
	document.forms["submitQuickControl"].mode.value = document.forms["quickMod"].quickaction[document.forms["quickMod"].quickaction.selectedIndex].value;
	document.getElementById("submitQuickControl").submit();
}

function showPost(id)
{
	var c = 0, obj;
	for(; c < document.getElementsByTagName("tr").length; c++) 
	{
		obj = document.getElementsByTagName("tr").item(c);
		if(obj.id  == 'toggable' + id)
			obj.style.display = '';
	}
	document.getElementById("toggableLink" + id).innerHTML = '<a href="#" onclick="hidePost(' + id + '); return false;">הסתר תגובה</a>';
}

function hidePost(id)
{
	var c = 0, obj;
	for(; c < document.getElementsByTagName("tr").length; c++) 
	{
		obj = document.getElementsByTagName("tr").item(c);
		if(obj.id  == 'toggable' + id)
			obj.style.display = 'none';
	}	
	document.getElementById("toggableLink" + id).innerHTML = '<a href="#" onclick="showPost(' + id + '); return false;">הצג תגובה</a>';
}

function vote(surveyId)
{

	/** Get checked Icon */
	var option;
	var totalOptions = document.forms["survey"].option.length;
	for(var i = 0; i < totalOptions ; i++) 
	{
		if(document.forms["survey"].option[i].checked) 
		{
			option = document.forms["survey"].option[i].value;		
			break;
		}
	}
	if (option == null)
	{
		alert("עליך לבחור באחת האפשרויות");
		return;
	}
	
	setCookie('survey_' + surveyId, 'true', 1);
	document.getElementById("survey").submit();
}	