﻿

function OnFormSubmit()
{
	var oTextBoxUserName = document.getElementById('txtUserName');
	var oTextBoxMsgTitle = document.getElementById('txtMsgTitle');
	var oTextBoxFileUpload = document.getElementById('fileUploadImage');
	
	var strUserName = '';
	if(oTextBoxUserName)
	{
		strUserName = oTextBoxUserName.value;
	}
	var strMsgTitle = oTextBoxMsgTitle.value;
	var strFileUpload = oTextBoxFileUpload.value;
	
	if(oTextBoxUserName && !TextHandler.TotalTrim(strUserName))
	{
		alert('חסר שם');
		oTextBoxUserName.focus();
		oTextBoxUserName.value = '';
		return false;
	}
	
	if(!TextHandler.TotalTrim(strMsgTitle))
	{
		alert('חסר נושא');
		oTextBoxMsgTitle.focus();
		oTextBoxMsgTitle.value = '';
		return false;
	}
	
	
	if(strFileUpload && !IsValidImageFile(strFileUpload))
	{
		alert('קובץ לא חוקי');
		oTextBoxFileUpload.focus();
		return false;
	}
	
	document.getElementById('btnSubmit').disabled = true;
	return true;
}



var Forum = 
{
	ShowMsg : function(iIndex)
	{
		var oDiv = document.getElementById('divContent' + iIndex);
		
		 Effect.toggle(oDiv,'blind');
		//oDiv.style.display = oDiv.style.display == 'none' ? 'block' : 'none';
	},
	
	ConfirmDeleteMsg : function(iMID,iForumID)
	{
		if(confirm('? האם למחוק את ההודעה וכל התגובות להודעה'))
		{
			location.assign('forumaction.asp?action=delete&mid=' + iMID + '&fid=' + iForumID);
		}
	},
	
	OnSubmitForm : function()
	{
		this.SetInputHiddenSearch();
		return true;
	},
	
	SetInputHiddenSearch : function()
	{
		document.getElementById('hidFreeSearch').value = document.getElementById('txtFreeSearch').value;
	},
	
	SubmitForm : function(strURL)
	{
		var oFrmMain = document.getElementById('frm');	
		oFrmMain.action = strURL;
		oFrmMain.submit();
	},
	
	OnClickPaging : function(iForumID,iIndex)
	{
		var strURL = 'forum.asp?fid=' + iForumID + '&num=' + iIndex;
		this.SubmitForm(strURL);
	}
}




var ForumSearch = 
{
	OnClickCheckBox : function(oCheckBox,strIdentifier)
	{	

		var oTextBox = document.getElementById('txt' + strIdentifier);
		oTextBox.style.visibility = oCheckBox.checked ? 'visible' : 'hidden';
		
		if(oCheckBox.checked)
		{
			oTextBox.focus();
		}
		else
		{
			oTextBox.value = '';
		}
		
	},
	
	OnSubmitForm : function(oForm)
	{
		this.SetInputHiddenSearch();
		oForm.action = 'forum.asp?fid=' + document.getElementById('cmbForums').value;
		
		return true;
	},
	
	SetInputHiddenSearch : function()
	{
		document.getElementById('hidUserName').value = document.getElementById('txtUserName').value;
		document.getElementById('hidSubject').value = document.getElementById('txtSubject').value;
		document.getElementById('hidText').value = document.getElementById('txtText').value;
		
		document.getElementById('hidDateFrom').value = this.GetComboDate('cmbFromDay','cmbFromMonth','cmbFromYear');
		document.getElementById('hidDateTo').value = this.GetComboDate('cmbToDay','cmbToMonth','cmbToYear');
	},
	
	GetComboDate : function(strDayComboID,strMonthComboID,strYearComboID)
	{
		
		var oComboDay	= document.getElementById(strDayComboID);
		var oComboMonth = document.getElementById(strMonthComboID);
		var oComboYear	= document.getElementById(strYearComboID);
		
		var strDay		= oComboDay.options[oComboDay.selectedIndex].value;
		var strMonth	= oComboMonth.options[oComboMonth.selectedIndex].value;
		var strYear		= oComboYear.options[oComboYear.selectedIndex].value;
		
		//for the asp query it should be MM/DD/YYYY
		return strMonth + '/' + strDay + '/' + strYear;
	}
}


