
function submit_form()   /* a function that submits the order form from forum.asp page */
{
	document.order.submit();
}

function post_message(msgId)
{
	document.post_message.msgId.value = msgId;
	document.post_message.submit();
}

function user_recommend(msgId){
	$.post('forum_include/user_recommend.asp', {msgId: msgId}, function(){
		$('#recommend_'+msgId).html('Recommended!').attr('onclick','');			
	});
}

function change_forum_output(Page,Order_By,RecordsInPage)
{
	document.change_forum_output.Page.value = Page;
	document.change_forum_output.Order_By.value = Order_By;
	document.change_forum_output.RecordsInPage.value = RecordsInPage;
	document.change_forum_output.submit();
}

function editMsg(Msg_num)
{
	document.post_message.editMsg.value = Msg_num;
	document.post_message.submit();
}

function displayMessage(id)
{
   var obj = document.getElementById(id);
   obj.style.display=(obj.style.display=="none"?"block":"none");
}

function del_message(msgId,subject)
{
	var result = confirm("Are you sure you want to delete this post?");
	
	if( result == true )
	{
		document.del_message.msg_num.value = msgId;
		document.del_message.submit();
	}
}

function recommend_message(msgId, forumId){
	$.post('forum_include/recommend_message.asp', {msgId:msgId, recommend:1, forumId:forumId}, function(){
			$('#msgTitle_'+msgId).addClass('recommended');
			$('#recommend_'+msgId).html('Remove reccomendation').unbind('click').attr('onclick','').click(function(){
				unrecommend_message(msgId, forumId);
			});
	});
}
function unrecommend_message(msgId, forumId){
	$.post('forum_include/recommend_message.asp', {msgId:msgId, recommend:0, forumId:forumId}, function(){
			$('#msgTitle_'+msgId).removeClass('recommended!');
			$('#recommend_'+msgId).html('Reccomend').unbind('click').attr('onclick','').click(function(){																	
					recommend_message(msgId, forumId);
			});
	});
}



/****************************************
 Function Name  : send_message
 Function Purpose : This function is used in the forums editory. It checks that 
 						the message chars are O.K (with the help of "Replace Quotes")
						as well its length and so on...
						As well the function calls replacing_bad_words to filter bad words
						from the message.
 ****************************************/
function send_message()   
{

	if(document.new_message.user_name.value.length<2)
	{
		alert("please enter username");
		document.new_message.user_name.focus();
		return(false);	
	}
	
	/* Checking that the message length isn't to long :  */
	if(document.new_message.message_content.value.length>=55000)   // size of Data Base if 64K but still...
	{
		alert("message is too long");
		return(false);
	}
	
	if(document.new_message.subject.value.length==0)   // If the subject is empty
		if(document.new_message.message_content.value.length!=0)    // And the message body is not empty
			if(document.new_message.message_content.value.length>16)   // and the message body is longer than 16 chars
				document.new_message.subject.value = document.new_message.message_content.value.substring(0,16)+"...";
				/* Then put into the messages subject its begining */
			else   // If the message body length is less than 17 chars but not 0 then :
			    document.new_message.subject.value = document.new_message.message_content.value;
		else  //  meaning the subject and the body_message are empty
		{
			alert("cannot enter blank message");
			document.new_message.message_content.focus();
			return(false);
		}	
//	$.post('forum_include/check_user_name.asp',{nick: $('.nick').val()}, function(data){
//			if(data==''){
				$('#new_message').submit();
//			}else{
//				alert('Nick name is in use. Please select another..');	
//			}
//	});
	//return false;
}

function check_add_manager_from()
{
	if(document.manager.private_name.value.length==0)
	{
		alert("חובה להזין שם פרטי");
		document.manager.private_name.focus();
		return false;
	}

	if(document.manager.family.value.length==0)
	{
		alert("חובה להזין שם משפחה");
		document.manager.family.focus();
		return false;
	}

	if(document.manager.user_name.value.length==0)
	{
		alert("חובה להזין שם משתשמש");
		document.manager.user_name.focus();
		return false;
	}

	if(document.manager.password.value.length==0)
	{
		alert("חובה להזין סיסמה");
		document.manager.password.focus();
		return false;
	}


	return true;
}

// a function to check the update admins table from 'forum_ManageAll' page
function check_manage_form()
{
	var tomer=new Array
	tomer[0]="private_name"
	tomer[1]="family"
	tomer[2]="user_name"
	tomer[3]="password"
	
	return ChkFrm('document.manage_list',tomer);

}

// a function to check the update forums table from 'forum_ManageAll' page
function update_forums_form()
{
	var forum_colums = new Array
	forum_colums[0] = "forumDesc"
	forum_colums[1] = "welcomeMessage"

	return ChkFrm('document.forums_manage',forum_colums);
}
	
	function ChkFrm(form_name,my_array)
	{
		FrmObj = eval(form_name)
		Flag=0
		if(isNaN(FrmObj.ids.length)) // there is only 1 value
		{
			for(j=0;j<my_array.length;j++)
			{
				InputObj=eval("FrmObj."+my_array[j]+"_"+FrmObj.ids.value)
				if(InputObj.value.length==0)
				{
					ColorInput(InputObj,"#ffffa0")
					Flag=1
				}	
				else{ColorInput(InputObj,"#ffffff")}
			}
		}

		if(Flag==1)
		{
			alert("חובה למלא את כל השדות")
			return false;
		}

		Len=document.manage_list.ids.length

		for(i=0;i<Len;i++)
		{
			for(j=0;j<my_array.length;j++)
			{
				InputObj=eval("FrmObj."+my_array[j]+"_"+FrmObj.ids[i].value)
				if(InputObj.value.length==0)
				{
					ColorInput(InputObj,"#ffffa0")
					InputObj.focus()
					Flag=1
				}
				else
				{
					ColorInput(InputObj,"#ffffff")			
				}
			}
		}
		
		if(Flag==1)
		{
			alert("חובה למלא את כל השדות")
			return false;
		}
		
		return true;
		
	}

	function ColorInput(Obj,CellColor)
	{
		Obj.style.backgroundColor=CellColor
	}

//Start added for upload file
var pop
function popup(url,p) { //opens a winow in pop up with param: p
	if(pop!=null && !pop.closed) pop.close()
	pop=window.open(url,"pop",p)
	pop.focus()
    }
 
 function upload_file(id){
	 popup('upload_forum_files.asp?forumId='+id,'width=540,height=190, scrollbars=yes');
 }
 
 function emoticon(text) {
	text = ' ' + text + ' ';
	//alert(document.new_message.message_content.focus())
	
	document.new_message.message_content.value  += text;
	document.new_message.message_content.focus();

}

  function MailUser(sEmail)
  {
   location='mailto:'+sEmail.replace("^","@");
  }
 
 // ******************* Inserting html tags ito the textarea ****************************//
 // ******** taken from http://parentnode.org/javascript/working-with-the-cursor-position/
  	function insert_text(element_id, type, param, no_wrap){	 
		no_wrap = no_wrap | false;
	    var obj = document.getElementById(element_id);
		if(document.selection) { 
			obj.focus();
			var range = document.selection.createRange(); 
			if(range.parentElement() != obj) { 
				return false; 
			} 						
			var orig = obj.value.replace(/rn/g, "n"); 
 
			range.text =  no_wrap?(range.text+type):('['+type+param+']'+range.text + '[/'+type+']'); 
			var actual = tmp = obj.value.replace(/rn/g, "n"); 
			for(var diff = 0; diff < orig.length; diff++) { 
				if(orig.charAt(diff) != actual.charAt(diff)) break; 
			} 
			for(var index = 0, start = 0; 
				tmp.match(text) 
					&& (tmp = tmp.replace(text, "")) 
					&& index <= diff; 
				index = start + text.length 
			) { 
				start = actual.indexOf(text, index); 
			} 
		} else { 
			var start = obj.selectionStart; 
			var end   = obj.selectionEnd; 
			if(no_wrap)
				obj.value = obj.value.substr(0, start) + obj.value.substr(start, end-start) + type + obj.value.substr(end, obj.value.length);	
			else
				obj.value = obj.value.substr(0, start) + '['+type+param+']'+ obj.value.substr(start, end-start) + '[/'+type+']'+ obj.value.substr(end, obj.value.length);			
		} 
	}
	
 //*************************************************************************//
  