function goPage(start_at, pages,page, forumid, tracer) {
	tempHTML = ""
	tempHTML += "<select onchange=\"goPage(((this.value-1)*20)+1,"+pages+","+page+","+forumid+",this.value)\">";
	
	for(i=1;i < parseInt((pages/20)+0.99)+1;i++){
		tempHTML += "<option value=\""+i+"\"" 
		if(i == tracer){
			tempHTML += "selected";
		}
		tempHTML += ">";
		tempHTML += ((((i-1)*20)+20) + " - " +(((i-1)*20)+1))
	}
	tempHTML += "</select>&nbsp;&nbsp;&nbsp;<b>עמודים</b> &raquo; ";
	
	breaker = 0;
	for(i = start_at-"";i<start_at-""+20;i++){
		if(i>pages)break;
		if(breaker!=0){
			tempHTML = tempHTML + "&nbsp;|&nbsp;"
		}
		if(i+""==page+""){
			tempHTML = tempHTML + "<span class='onpage'>"+i+"</span>"
		}else{
			tempHTML = tempHTML + "<a href='forumNew.asp?p="+i+"&forumid="+forumid+"' class='urhere'>"+i+"</a>"
		}
		breaker++;
	}
	$('bottomNav').innerHTML = tempHTML
	$('topNav').innerHTML = tempHTML
	
	tempHTML = null;
	breaker = null;
}

function calc(num){
	valueL = mod(num,10)
	inTen = num - valueL
	if(mod(inTen,20)!=0){
		starter = num - valueL - 9
	}else{
		if(valueL==0){
			starter = num - valueL - 19
		}else{
			starter = num - valueL + 1
		}
	}
	//sum =  + 1
	return(starter);	
}

function mod(divisee,base) {
	return Math.round(divisee - (Math.floor(divisee/base)*base));
}

function stop(e) {
	if (!e) e = window.event;
	e.cancelBubble = true;
	if (e.stopPropagation) e.stopPropagation();
}

function showMessage(id){
	if($('item_'+id).style.display == "none"){
		if($('item_'+id).innerHTML != ""){
			$('item_'+id).style.display = "";
		}
	}else{
		if($('item_'+id).innerHTML != ""){
			$('item_'+id).style.display = "none";
		}
	}
}

function printMsg(id,forumid){
	location = "forumMessage.asp?id="+id+"&forumid="+forumid+"&p=1";
}

function addMsg(parentid, userid, usernick){
	if(userid==0){
		alert("חובה לבצע כניסה למערכת לפני הוספת תגובות בפורום");
	}else{
		$('reply_'+parentid).style.display = "";
		initTiny('MessageText'+parentid);
		whoClicked = $('MessageTitle'+parentid);
	}
}

function closeAddReply(id){
	$('reply_'+id).style.display = "none";
}

function closeD(id){
	$(id).style.display = "none";
}

function showDialog(id){
	$(id).style.display = "";
}

function chkAddMsg(parentid, userid){
	if(userid!="0"){
		if($('MessageTitle'+parentid).value.length<2){
			alert("אנא הזינו נושא הודעה");
		}else{
			$('MessageTitle').value = $('MessageTitle'+parentid).value;
			$('MessageText').value = tinyMCE.get('MessageText'+parentid).getContent();
			$('mpid').value = parentid;
			$('BigParentID').value = $('BigParentID'+parentid).value;
			if($('allowFollowUp'+parentid).checked==true){
				$('getFollowUp').value="1"
			}
			if($('allowEmail'+parentid).checked==true){
				$('showEmail').value="1";
			}
			$('frmAddReply').submit();
		}
	}
}

function initTiny(elm){
	tinyMCE.init({
		mode : "exact", 
		language : "he",
		elements : elm, 
		directionality : "rtl",
		theme : "advanced", 
		plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,inlinepopups, emotions,iespell,insertdatetime,Save,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
		theme_advanced_buttons1 : "fontsizeselect,|,forecolor,backcolor,|, bold,italic,underline,strikethrough,|,link,unlink,|,emotions,|,paste,pastetext,pasteword",
		theme_advanced_buttons2 : "", 
		theme_advanced_buttons3 : "", 
		theme_advanced_buttons4 : "", 
		
		theme_advanced_toolbar_location : "top", 
		theme_advanced_resizing : false
	});
}

whoClicked = 0;	
function storeCaret (textEl) {
	whoClicked = textEl
	if (textEl.createTextRange){
		textEl.caretPos = document.selection.createRange().duplicate();
	}
}

function insertAtCaret (text, parentid) {
	text = "|"+text+"|"
	textEl = whoClicked
	if (textEl.createTextRange && textEl.caretPos) {
		var caretPos = textEl.caretPos;
		caretPos.text =	caretPos.text.charAt(caretPos.text.length - 1) == ' ' ?
		text + ' ' : text;
	}else{
		textEl.value  = text;
	}
	textEl.focus();
	$('iconsHolder'+parentid).style.display = "none";
}

function openEmotions(id){
	if($('iconsHolder'+id).style.display == ""){
		$('iconsHolder'+id).style.display = "none"
	}else{
		$('iconsHolder'+id).style.display = ""
	}
}

function forumLogin(){
	tmpErr = ""; 
	if($('l_email').value.length<5 || $('l_email').value.indexOf("@")==-1 || $('l_email').value.indexOf(".")==-1){
		tmpErr += "<li>דואר אלקטרוני לא חוקי, אנא הכניסו דואר אלקטרוני חוקי</li>";
		$('l_email').focus();
	}
	if($('l_password').value.length<1){
		tmpErr += "<li>אנא הזינו סיסמה</li>";
	}
	if(tmpErr!=""){
		$('d_login_err').innerHTML = "<ul>"+tmpErr+"</ul>";
		return false;
	}else{
		$('frmForumLogin').submit();
	}
}

function getWindowSize(what){
	var x,y;
	if (self.innerHeight) // all except Explorer
	{
		x = self.innerWidth;
		y = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
		// Explorer 6 Strict Mode
	{
		x = document.documentElement.clientWidth;
		y = document.documentElement.clientHeight;
	}
	else if (document.body) // other Explorers
	{
		x = document.body.clientWidth;
		y = document.body.clientHeight;
	}
	if(what=="width"){
		return x;
	}else{
		return y;
	}
}

function initPage(p){
	switch (p){
		case "forum":
			whoClicked = $('MessageTitle');
			if(screen.width<1000){
				$('forum_left_side').style.display = "none";
			}
			//$('d_login').style.left = Math.round((getWindowSize("width")-255)/2) + "px";
			//$('d_login').style.top = Math.round((getWindowSize("height")-115)/2) + "px";
			//$('d_register').style.left = Math.round((getWindowSize("width")-255)/2) + "px";
			//$('d_register').style.top = Math.round((getWindowSize("height")-225)/2) + "px";
			//$('d_frgtpwd').style.left = Math.round((getWindowSize("width")-255)/2) + "px";
			//$('d_frgtpwd').style.top = Math.round((getWindowSize("height")-115)/2) + "px";
			//alert("width: " +Math.round((getWindowSize("width")-255)/2) + "px");
			//alert("height: " +Math.round((getWindowSize("height")-115)/2) + "px");
	}
}

function registerUser(){
	$('addUser_error').style.display = "none";
	tmpErr = "";
	if($('r_fname').value.length<2){
		tmpErr += "<li>שם פרטי קצר מידי</li>";
	}
	if($('r_lname').value.length<3){
		tmpErr += "<li>שם משפחה קצר מידי</li>";
	}
	if($('birthday').value=="0" || $('birthmonth').value=="0" || $('birthyear').value=="0"){
		tmpErr += "<li>אנא הזינו תאריך לידה</li>";
	}
	if($('r_email').value.length<5 || $('r_email').value.indexOf("@")==-1 || $('r_email').value.indexOf(".")==-1){
		tmpErr += "<li>אנא הזינו כתובת דואר אלקטרוני חוקית</li>";
	}
	if($('user_name').value.length<4){
		tmpErr += "<li>כינוי קצר מידי, יש להזין לפחות 4 תווים</li>";
	}
	if($('password').value.length<6){
		tmpErr +="<li>סיסמה חייבת להכיל מינימום 6 תווים</li>";
	}
	if($('password').value != $('repassword').value){
		tmpErr +="<li>סיסמה ואימות סיסמה לא זהים</li>";
	}
	if($('chkDisc').checked == false){
		tmpErr +="<li>חובה לקרוא ולהסכים לתנאי השימוש בפורומים</li>";
	}
	if(tmpErr!=""){
		$('addUser_error').innerHTML = "<ul>"+tmpErr+"</ul>";
		$('addUser_error').style.display = "";
		//return false;
	}else{
		$('addUser_error').innerHTML = "מבצע הרשמה, אנא המתינו...";
		$('addUser_error').style.display = "";
		$('user_name').value = $('user_name').value.replace(/^\s+|\s+$/g,"");
		$('r_fname').value = $('r_fname').value.replace(/^\s+|\s+$/g,"");
		$('r_lname').value = $('r_lname').value.replace(/^\s+|\s+$/g,"");
		$('frmForumRegister').submit();
	}
	
}

function registerUserReuslt(r){
	$('addUser_error').style.display = "none";
	tmpErr = "";
	if(r=="0A"){
		tmpErr = "כתובת הדואר האלקטרוני באמצעותה ניסית להרשם כבר קיימת אצלנו, <a href=\"\">שכחת סיסמה ?</a>";
	}
	if(r=="0B"){
		tmpErr = "הכינוי שבחרת כבר קיים במערכת, אנא בחר כינוי אחר";
	}
	if(r=="1"){
		$('d_reg_form').style.display = "none";
		tmpErr = "<b>הרשמתך בוצעה בהצלחה!</b><br>ברגעים אילו נשלחת הודעה עם קישור להפעלת חשבונך לדואר האלקטרוני שהזנת. אנא לחץ על הקישור בגוף ההודעה על מנת להפעיל את חשבונך.";
	}
	$('addUser_error').innerHTML = tmpErr;
	$('addUser_error').style.display = "";
}

function updateUserNick(){
	$('updateUser_error').style.display = "none";
	tmpErr = "";
	if($('u_user_name').value.length<4){
		tmpErr += "<li>כינוי קצר מידי, יש להזין לפחות 4 תווים</li>";
	}
	if(tmpErr!=""){
		$('updateUser_error').innerHTML = "<ul>"+tmpErr+"</ul>";
		$('updateUser_error').style.display = "";
		//return false;
	}else{
		$('user_name').value = $('user_name').value.replace(/^\s+|\s+$/g,"");
		$('frmForumUpdateNick').submit();
	}
}
function updateUserPwd(){
	$('updateUser_error').style.display = "none";
	tmpErr = "";
	if($('u_password').value.length<6){
		tmpErr +="<li>סיסמה חייבת להכיל מינימום 6 תווים</li>";
	}
	if($('u_password').value != $('u_repassword').value){
		tmpErr +="<li>סיסמה ואימות סיסמה לא זהים</li>";
	}
	if(tmpErr!=""){
		$('updateUser_error').innerHTML = "<ul>"+tmpErr+"</ul>";
		$('updateUser_error').style.display = "";
		//return false;
	}else{
		$('user_name').value = $('user_name').value.replace(/^\s+|\s+$/g,"");
		$('frmForumUpdatePassword').submit();
	}
}


function delMsgs(forumid){
	//Admin Del Msgs
	if(confirm("? מחק הודעות")==true){
		$('frmAdminMsgs').action = "http://www.geva.co.il/geva/include/ForumUserFuncs.asp?action=AdminDel&forumid="+forumid;
		$('frmAdminMsgs').submit();
	}
}

function hlMsgs(forumid){
	//Admin HighLight Msgs
	$('frmAdminMsgs').action = "http://www.geva.co.il/geva/include/ForumUserFuncs.asp?action=AdminHL&forumid="+forumid;
	$('frmAdminMsgs').submit();
}

function hlrMsgs(forumid){
	//Admin Undo HighLight Msgs
	$('frmAdminMsgs').action = "http://www.geva.co.il/geva/include/ForumUserFuncs.asp?action=AdminHLR&forumid="+forumid;
	$('frmAdminMsgs').submit();
}

function stickMsgs(forumid){
	//Admin Stick Msgs
	$('frmAdminMsgs').action = "http://www.geva.co.il/geva/include/ForumUserFuncs.asp?action=AdminStick&forumid="+forumid;
	$('frmAdminMsgs').submit();
}

function stickrMsgs(forumid){
	//Admin Stick Msgs
	$('frmAdminMsgs').action = "http://www.geva.co.il/geva/include/ForumUserFuncs.asp?action=AdminStickR&forumid="+forumid;
	$('frmAdminMsgs').submit();
}

function chkNick(w){
	if(w==1){
		if($('user_name').value!=""){
			$('nick').value = $('user_name').value
			$('frmCheckNick').submit();
		}
	}else{
		if($('u_user_name').value!=""){
			$('nick').value = $('u_user_name').value
			$('frmCheckNick').submit();
		}
	}
}

function chkNickResult(res){
	if(res=="1"){
		alert("הכינוי שבחרת פנוי");
	}else{
		alert("הכינוי שבחרת אינו פנוי, אנא בחר כינוי אחר");
		$('user_name').value = "";
	}
}

function frgtPwd(){
	if($('frgt_email').value!=""){
		$('frmForumPWD').submit();
	}
}

function frgtPwdResult(res){
	if(res=="1"){
		$('d_frgtpwd_err').innerHTML = "ברגעים אלה נשלחת הודעת דואר אלקטרוני לתיבת הדואר שלך עם פרטי ההתחברות למערכת הפורומים של יואל גבע";
	}else{
		$('d_frgtpwd_err').innerHTML = "לא נמצא משתמש עם כתובת הדואר האלקטרוני שהזנת במערכת הפורמים של יואל גבע";
	}
}



function chkSearch(){
	if($('txtSearch').value.length>2){
		return true;
	}else{
		return false;
	}
}