﻿this.mobile_mod=false;

function changefont(isize,thelink,updateajax){
    $("#bodyWarp").css("font-size", isize);
	$("#right").css("font-size", 'small');
	$('#left input').css('font-size', 'small');
	$('#left form').css('font-size', 'small');
	$('.leftnav').css('font-size', 12);
	if (updateajax==true){
	$.ajax({ 
  						type: 'get', 
  						url: '/scripts/fontsize.asp?a=2&size='+isize
	});	
	}
  $('a').removeClass('selectedfont');
  $(thelink).addClass('selectedfont');
};
function stip_click_check(stipid){
var checkstatus = $('#stip_check_'+stipid).attr('checked')?1:0;
var action
if (checkstatus==0){action='remove'}
else
{action='add'}
var url='/scripts/markstip.asp';
$.ajax({ 
  						type: 'get', 
  						url: url,
						data:'stipids='+stipid+'&action='+action,
  						success: function(msg){ 
						if (parseInt(msg)==0){
						//$('#marked_stips_right').slideUp('normal');	
		
						$('.marked_stips_count').html(msg);
						}
						else {
						//$('#marked_stips_right').slideDown('normal');	
						$('.marked_stips_count').html(msg);
						}
    						
    						}	
					});		
}
function remember_itemnum(num,type){
$.ajax({ 
  						type: 'get', 
  						url: '/scripts/itemnum.asp?num='+num,
  						success: function(msg){ 
							if (type=='search'){
	    							searchpage_send('check');
							}else{
							window.location.reload(false);
							}
    						}	
					});		
}			
function printsinglestip(stipid){
window.open("/singlestip.asp?printmod=yes&stipid="+stipid,null, "height=400,width=677,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes");
}
function redirect_page(url)
{
window.location.href=url;
}
$(document).ready(function() {
	$("#navigation li[class!='NavTab blueTab SelectedTab2']").mouseover(
		function(e){

			if (e.pageY<$(this).offset().top+32){
			$(this).siblings().attr("class","NavTab greenTab");
			$(this).attr("class","NavTab blueTab");
			$("#NavLine .navlinediv").hide();
			$("#NavLine .navlinediv").eq($("#navigation li").index(this)).show();
			}
		}
	);
	var topnavtimer
	$("#NavLine").mouseout(
		function(e){
			topnavtimer=setTimeout(
			function()
				{
					
					 check_navtop_active(e);
				},650
			)
		}
	)
	$("#NavLine").mouseover(
		function(e){
		clearTimeout(topnavtimer)
		}
	)
	
	function check_navtop_active(e){

	if(e.pageY>$("#NavLine").offset().top+$("#NavLine").height()){

				if ($("#NavLine .activelink").html().length<50) return false;
				$("#NavLine .unactivelink").fadeOut(400);
				$("#NavLine .activelink").fadeIn(400);
				var tabnum=$("#NavLine .navlinediv").index($("#NavLine .activelink")[0])
				setTimeout(
					function(){
						$("#navigation li").eq(tabnum).attr("class","NavTab blueTab");
						$("#navigation li").eq(tabnum).siblings().attr("class","NavTab greenTab");
					}
					,0
				);
			}
	}
	/*
	$("#navigation li[class!='NavTab blueTab SelectedTab']").mouseout(
		function(){
			$(this).attr("class","NavTab greenTab");
			$("#NavLine .unactivelink").hide();
			$("#NavLine .activelink").show();
		}
	)*/
		
	$("#search_top #search_top_term").focus(
		function(){
			if ($("#search_top #search_top_term").val()=='חיפוש בסטיפס...') {
				$("#search_top_term").val("");
				}
				$("#search_top_term").css("color","#000");;
		}
	)
	
	$("#search_top #search_top_term").blur(function(){
			$("#search_top_term").css("color","#aaa");
			if ($("#search_top #search_top_term").val()=='') {
				$("#search_top_term").val("חיפוש בסטיפס...");
			}
		}
	);
	
	$("#search_top #search_top_term_tag").focus(
		function(){
			if ($("#search_top #search_top_term_tag").val()==$("#search_top_term_tag_tmp_text").val()) {
				$("#search_top_term_tag").val("");
				}
				$("#search_top_term_tag").css("color","#000");;
		}
	);
	
	/*$("#search_top #search_top_term_tag").blur(function(){
			$("#search_top_term_tag").css("color","#bbb");
			if ($("#search_top #search_top_term_tag").val()=='') {
				$("#search_top_term_tag").val($("#search_top_term_tag_tmp_text").val());
			}
		}
	);*/
	


	$(".stipbody .stipdata a[href*='http']").attr("target","_blank");
}

);
var sponsertimer
var sponserflag
sponserflag=false;
function stips_sponser_click(url)
{	
	
	sponsertimer=setTimeout(function()
	{
		if (!sponserflag)
		{
			window.open(url);
		}
	}
	,100)
}

function change_search_type(checkedattr){
	if (checkedattr){
		$('.search_top_text').hide();
		//$('#search_top').addClass('search_top_orange');
		$('.search_top_tag_move').show();
		if($('#search_top_term').val()!=='חיפוש בסטיפס...'){
			$('#search_top_term_tag').val($('#search_top_term').val());
		}
		$('#search_top_term_tag').focus();
		}else{
			$('.search_top_tag_move').hide();
			$('.search_top_text').show();
			if ($("#search_top #search_top_term_tag").val()!=$("#search_top_term_tag_tmp_text").val()){
				$('#search_top_term').val($('#search_top_term_tag').val());
			}
			$('#search_top_term').focus();
		}
		r_e("top_search","change",checkedattr+'') 
		
}


function stips_sponser_clear(){sponserflag=true;
clearTimeout(sponsertimer)}

function change_left_box_view(displaytype,boxtype,page,changedisplay){
	var urlstring,leftbox
	if (boxtype=="asks") {
		leftbox=".left_box_ask_main"
	} else if (boxtype=="asks_noar") {
		leftbox=".left_box_ask_noar"
	} else {
		boxtype=="tips"
		leftbox=".left_box_tips"
	}

	urlstring="/scripts/print_box.asp?displaytype="+displaytype+"&boxstype="+boxtype+"&page="+page;
	
	$(leftbox+" .ok").hide();
	$(leftbox+" .loading").show();
		
	if (boxtype=="tips" || boxtype=="asks" || boxtype=="asks_noar"){
		$.ajax({
		url:urlstring,
		  success: function(data) {
		  
			if  (changedisplay){
				$(leftbox+" .more_back_div").hide();
				$(leftbox+" .ulcontainer").html('')

				$(leftbox+" .ulcontainer").append(data);
				$(leftbox+" .ulcontainer").animate({"right": "0px"}, "slow");
				$(leftbox+" .loading").hide();
				$(leftbox+" .ok").show();
			}
			else{
				$(leftbox+" .ulcontainer").append(data);
				setTimeout(function() {
					$(leftbox+" .ulcontainer").animate({"right": "-=302px"},
						{
							duration: 	"slow", 
							specialEasing: {right: 'linear'}
						}
					);
					$(leftbox+" .ulcontainer").width($(leftbox+" .ulcontainer").width()+350);
					if (page>1){
					$(leftbox+" .more_back_div").show();
					
					}else{
						$(leftbox+" .more_back_div").hide();
					}	
				$(leftbox+" .loading").hide();
				$(leftbox+" .ok").show();
				},100);
			}
			$(leftbox +" .hiddenpagecount").val(page);
			$(leftbox +" .hiddndisplaytype").val(displaytype);
			
		  }
		});
	}	

}

function change_left_box_view_next_back(boxtype,backflg){
	if (boxtype=="asks") {
		leftbox=".left_box_ask_main"
	} else if (boxtype=="asks_noar") {
		leftbox=".left_box_ask_noar"
	} else {
		boxtype=="tips"
		leftbox=".left_box_tips"
	}
	var page,displaytype
	displaytype
	displaytype=$(leftbox +" .hiddndisplaytype").val();
	page=parseInt($(leftbox +" .hiddenpagecount").val());
	if (backflg){
	page=page-1;
	} else {
	page=page+1;
	}
	if (page<1) {page=1}{
	}
	if (backflg){
		if (parseInt($(leftbox+" .ulcontainer").css("right"))>=-302){
			$(leftbox+" .more_back_div").hide();
		}
		if (parseInt($(leftbox+" .ulcontainer").css("right"))>=-301){
			$(leftbox+" .more_back_div").hide();
			return;
		}
		$(leftbox+" .ulcontainer").animate({"right": "+=302px"},
		 {
			duration: 	"slow", 
			specialEasing: {
			  right: 'linear'
			}, 
			complete: function() {
				if (parseInt($(leftbox+" .ulcontainer").css("right"))>0){
				$(leftbox+" .ulcontainer").css("right","0px");
				}
			}
		  });
	
		

	
	} else {
		change_left_box_view(displaytype,boxtype,page,false);
	
		
	}
	r_e("left_boxed",boxtype+"_next_back","page:"+page+" backflg"+backflg) 
}


/////////////////////////////////////////////////////////////////////

var FloatLayers       = new Array();
var FloatLayersByName = new Array();

function addFloatLayer(n,offX,offY,spd){new FloatLayer(n,offX,offY,spd);}
function getFloatLayer(n){return FloatLayersByName[n];}
function alignFloatLayers(){for(var i=0;i<FloatLayers.length;i++)FloatLayers[i].align();}

function getXCoord(el) {
	x=0;
	while(el){
		x+=el.offsetLeft;
		el=el.offsetParent;
	}
	return x;
}
function getYCoord(el) {
	y=0;
	while(el){
		y+=el.offsetTop;
		el=el.offsetParent;
	}
	return y;
}

/////////////////////////////////////////////////////////////////////

FloatLayer.prototype.setFloatToTop=setTopFloater;
FloatLayer.prototype.setFloatToBottom=setBottomFloater;
FloatLayer.prototype.setFloatToLeft=setLeftFloater;
FloatLayer.prototype.setFloatToRight=setRightFloater;
FloatLayer.prototype.initialize=defineFloater;
FloatLayer.prototype.adjust=adjustFloater;
FloatLayer.prototype.align=alignFloater;

function FloatLayer(n, offX, offY, spd) {
	this.index=FloatLayers.length;

	FloatLayers.push(this);
	FloatLayersByName[n] = this;

	this.name    = n;
	this.floatX  = 0;
	this.floatY  = 0;
	this.tm      = null;
	this.steps   = spd;
	this.alignHorizontal=(offX>=0) ? leftFloater : rightFloater;
	this.alignVertical  =(offY>=0) ? topFloater : bottomFloater;
	this.ifloatX = Math.abs(offX);
	this.ifloatY = Math.abs(offY);
}

/////////////////////////////////////////////////////////////////////

function defineFloater(){
	this.layer  = document.getElementById(this.name);
	this.width  = this.layer.offsetWidth;
	this.height = this.layer.offsetHeight;
	this.prevX  = this.layer.offsetLeft;
	this.prevY  = this.layer.offsetTop;
}

function adjustFloater() {
	this.tm=null;
	if(this.layer.style.position!='absolute')return;

	var dx = Math.abs(this.floatX-this.prevX);
	var dy = Math.abs(this.floatY-this.prevY);

	if (dx < this.steps/2)
		cx = (dx>=1) ? 1 : 0;
	else
		cx = Math.round(dx/this.steps);

	if (dy < this.steps/2)
		cy = (dy>=1) ? 1 : 0;
	else
		cy = Math.round(dy/this.steps);

	if (this.floatX > this.prevX)
		this.prevX += cx;
	else if (this.floatX < this.prevX)
		this.prevX -= cx;

	if (this.floatY > this.prevY)
		this.prevY += cy;
	else if (this.floatY < this.prevY)
		this.prevY -= cy;

	this.layer.style.left = this.prevX;
	this.layer.style.top  = this.prevY;

	if (cx!=0||cy!=0){
		if(this.tm==null)this.tm=setTimeout('FloatLayers['+this.index+'].adjust()',50);
	}else
		alignFloatLayers();
}

function setLeftFloater(){this.alignHorizontal=leftFloater;}
function setRightFloater(){this.alignHorizontal=rightFloater;}
function setTopFloater(){this.alignVertical=topFloater;}
function setBottomFloater(){this.alignVertical=bottomFloater;}

function leftFloater(){this.floatX = document.body.scrollLeft + this.ifloatX;}
function topFloater(){this.floatY = document.body.scrollTop + this.ifloatY;}
function rightFloater(){this.floatX = document.body.scrollLeft + document.body.clientWidth - this.ifloatX - this.width;}
function bottomFloater(){this.floatY = document.body.scrollTop + document.body.clientHeight - this.ifloatY - this.height;}

function alignFloater(){
	if(this.layer==null)this.initialize();
	this.alignHorizontal();
	this.alignVertical();
	if(this.prevX!=this.floatX || this.prevY!=this.floatY){
		if(this.tm==null)this.tm=setTimeout('FloatLayers['+this.index+'].adjust()',50);
	}
}

function is_ie6(){
     return ((window.XMLHttpRequest == undefined) && (ActiveXObject != undefined));
}

var ns = (navigator.appName.indexOf("Netscape") != -1);
var d = document;
function JSFX_FloatDiv(id, sx, sy)
{
	var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
	var px = document.layers ? "" : "px";
	window[id + "_obj"] = el;
	if(d.layers)el.style=el;
	el.cx = el.sx = sx;el.cy = el.sy = sy;
	el.sP=function(x,y){this.style.left=x+px;this.style.top=y+px;};

	el.floatIt=function()
	{
		var pX, pY;
		pX = (this.sx >= 0) ? 0 : ns ? innerWidth : 
		document.documentElement && document.documentElement.clientWidth ? 
		document.documentElement.clientWidth : document.body.clientWidth;
		pY = ns ? pageYOffset : document.documentElement && document.documentElement.scrollTop ? 
		document.documentElement.scrollTop : document.body.scrollTop;
		if(this.sy<0) 
		pY += ns ? innerHeight : document.documentElement && document.documentElement.clientHeight ? 
		document.documentElement.clientHeight : document.body.clientHeight;
		this.cx += (pX + this.sx - this.cx)/8;this.cy += (pY + this.sy - this.cy)/8;
		this.sP(this.cx, this.cy);
		setTimeout(this.id + "_obj.floatIt()", 40);
	}
	return el;
}

	function linklinesnav(navigation_id)
	{
		// creates the target paths
		var list_elements = navigation_id + " li:not(.linklistright_tab_selected)";
		var link_elements = list_elements + " a";
		var old_list_elements = navigation_id + " li.linklistright_tab_selected a";

		// creates the hover-slide effect for all link elements 
		$(link_elements).unbind();
		$(link_elements).each(function(i)
		{
			$(this).hover(
			function()
			{
		
				$(this).animate({ width: 174,paddingRight:10 }, 150);
				$(this).parent().addClass("linklistright_tab_selected")
				
			},		
			function()
			{
				$(this).animate({ width: 174,paddingRight:2}, 150);
				$(this).parent().removeClass("linklistright_tab_selected")
			});
		});
		;
	}
	function r_e(c,a,l) {
  //עוקב אחרי ארועים
_gaq.push(['_trackEvent', c, a, l]);
}

function toggle_msgs_box(boxtype){
	$(".top_msgs_icon_"+boxtype).blur();
	$("#tooltip").remove();
	$(".top_msgs_box:not(.top_msgs_box_"+boxtype+")").hide();
	$(".top_msgs_icon:not(.top_msgs_icon_"+boxtype+")").removeClass("open");
	$(".top_msgs_icon_"+boxtype).toggleClass("open");
	if ($(".top_msgs_icon_"+boxtype).hasClass("open")) {
		$(".top_msgs_box_"+boxtype+" .box_content").html('<div align="center"><br/>טוען...<br/><br/><img src="/images/ajax-loader.gif"><br/><br/></div>')
		$(".top_msgs_box_"+boxtype).fadeIn(200);
		$(".top_msgs_box_"+boxtype+" .box_content").load("/scripts/print_top_box.asp?boxtype="+boxtype);	
		if (boxtype=="alerts") {
			update_box_count(boxtype,0)
		}
	}
	else{
		$(".top_msgs_box_"+boxtype).fadeOut(200);
	}
	r_e("top_icon","toggle_msgs_box",boxtype); 
}

function update_box_count(boxtype,count){
	var counttext;

	if (boxtype=="alerts") {
		counttext="חדשה"
		if (count>1) counttext="חדשות"
	} else {
		counttext="חדש"
		if (count>1) counttext="חדשים"
	}
	
		$(".top_msgs_icon_"+boxtype+" .top_msgs_count").html(""+count) //חייבים זה יהיה סטרינג אחרת הערך נהיה ריק
	if (count==0){
		$(".top_msgs_icon_"+boxtype+" .top_msgs_count").fadeOut(200);
		$(".top_msgs_icon_"+boxtype+" img").attr("src","/images/top_"+boxtype+"_empty.png")
		$("."+boxtype+"_text_count").fadeOut(200)
		
		if (boxtype=="msgs") {
			$(".top_msgs_icon_"+boxtype).attr("title","אין מסרים חדשים")
		} else{
			$(".top_msgs_icon_"+boxtype).attr("title","אין התראות חדשות")
		}	

	}
	if (count>0){
		$(".top_msgs_icon_"+boxtype+" .top_msgs_count").show();
		$(".top_msgs_icon_"+boxtype+" img").attr("src","/images/top_"+boxtype+"_full.png")
		$("."+boxtype+"_text_count").html(" ("+count+" "+counttext+")")
		$("."+boxtype+"_text_count").fadeIn(200)
		
		if (boxtype=="msgs") {
			$(".top_msgs_icon_"+boxtype).attr("title","מחכים לך "+count+" מסרים חדשים")
		} else{
			$(".top_msgs_icon_"+boxtype).attr("title",count+" התראות חדשות")
		}	
	}

}
$(document).ready(function(){
	$(document).click(function(){
		$(".top_msgs_box").fadeOut(50);
		$(".top_msgs_icon").removeClass("open");
	});
	$(".top_msgs_box").add(".top_msgs_icon").click(function(e){
		e.stopPropagation();
		});

});	

function are_cookies_enabled(){
	var cookieEnabled = (navigator.cookieEnabled) ? true : false;
	return (cookieEnabled);
}


	
