﻿///<reference path="Jquery.IntelliSense.js" />
/// <reference name="Dates.js"/>
/// <reference name="Main.js"/>


function ReplySendPrint(type,item,title,visible, first,last,notprint){
	if(!first)first="";if(!last)last="";
	sHTML = "<div class=ReplySendPrint>" + first
	if (visible==1) sHTML += Replies.Icon("Replies.DisplayForm(false,"+item+")",49,"כתוב תגובה").replaceStr("Icon","Icon FIcon")//+Replies.Icon("AddBrifcase("+type+","+item+",\""+ title.toJS()+"\")",0,"שמור")
	sHTML += ""+Replies.Icon("Replies.ReDisplaySend(false,"+item+")",16,"שלח לחבר").replace("Icon","Icon F2Icon") + (!notprint? Replies.Icon("window.open('/Controls/SendFriend.ashx?print=1&type=" + type +"&item=" + item + "')",32,"הדפסה"):'')+last+"</div>\
			  <div  class=ReplyWin id=divNew" + item +" align=right style=display:none;><h4><img src="+sStaticURL+"images/icons/arrow.gif> כתוב תגובה</h4><div id=divWait"+type+"-"+item+" style=display:none class=Msg>אנא המתן בעת משלוח ההודעה...</div>\
			  <div style=display:none; id=spnNewReplySent"+item+" class=Msg><div style=font-weight:bold;margin-top:20px>תודה !</div>קיבלנו את תגובתך ונשתדל לפרסמה בקרוב, בכפוף לשיקולי המערכת. <div style=float:right;height:250px;margin-top:30px;margin-right:10px; id=divCADC250></div> <div style=float:left;margin-top:35px class=ReplyButton  onClick=Replies.DisplayForm(false,"+item+");setTimeout(function(){$('#spnNewReplySent"+item+"').hide();$('#divReplyWin"+item+"').show()},400)><span class=Icon style=font-size:10pt;float:right><span class=XClose></span></span><input style=text-align:right class=Button type=button value=סגור></div><div style=clear:both;margin-bottom:1px></div></div>\
			  <div id=divReplyWin" + item + "><div class=Msg> תגובות שיש בהם הסתה, גידופים ושפה לא מכובדת לא יפורסמו.</div>\
			  <div class=Name>שם:<br><input type=text id=NewReplyName"+item+" maxlength=20 size=16 value=\""+User.Name+"\"></div><div class=City>עיר:<br><input type=text id=NewReplyCity" +item+" maxlength=15 size=16></div>\
			  <div class=Title>כותרת:<br><input type=text id=NewReplyTitle"+item+" maxlength=60></div><div class=Content>הודעה:<br><textarea id=NewReplyContent" + item +" rows=6 onKeyUp=Replies.UpdateCount('spnNewCount" +item+"',this,900);></textarea><div style=font-weight:normal>נותרו <span id=spnNewCount"+item+">900</span> תווים.</div></div>\
			  <div style=float:right; class=ReplyButton  onClick='Replies.DisplayForm(false,"+item+");'><span class=Icon style=font-size:10pt;float:right><span class=XClose></span></span><input style=text-align:right class=Button type=button value=סגור></div> <div style=float:left; class=ReplyButton  onClick='Replies.SendReply("+type+","+item+");'><span class=Icon style=float:left><span class=Arrow></span></span><input class=Button style=text-align:left;float:left type=button value=שלח></div><div style=clear:both;margin-bottom:3px></div>\
			  <div style=clear:both;margin-bottom:3px></div></div></div>\
			  <div class=ReplyWin id=divSend" + item +" style='display:none;background-position: left -14px'><h4><img src="+sStaticURL+"images/icons/arrow.gif> שלח לחבר</h4><div class=Msg>עליך למלא את שמך, כתובת הדוא\"ל שלך וכתובתו של החבר</div><div class=Name>שלח לדוא\"ל:<br><input type=text id=SendFriend"+item+"eMail2></div><div class=City>שם השולח:<br><input type=text id=SendFriend"+item+"Name1></div><div  class=Title style=margin-top:10px>דוא\"ל של השולח:<br><input type=text id=SendFriend"+item+"eMail1></div><br>\
			  <div style=float:right; class=ReplyButton  onClick='Replies.ReDisplaySend(false,"+item+");'><span class=Icon style=font-size:10pt;float:right><span class=XClose></span></span><input style=text-align:right class=Button type=button value=סגור></div> <div style=float:left; class=ReplyButton  onClick='Replies.SendToFriend("+type+","+item+");'><span class=Icon style=float:left><span class=Arrow></span></span><input class=Button style=text-align:left;float:left type=button value=שלח></div><div style=clear:both;margin-bottom:3px></div>\
			  </div>"
	return sHTML;
}

function Replies(type,id,replies,datefunc)
{
	if (!datefunc) datefunc = "numGreDate"
	this.Type =type; this.Item = id; this.Replies= replies;this.DateFunc = datefunc;Replies.Rep[type+"-"+id]= replies;
}
Replies.Opened=0;Replies.InfoZone=211
Replies.prototype =  {sLastTitle:"",bRA: location.href.indexOf("News.aspx")>-1,
HTML: function (reply,num) {
	var onclick = "Replies.DisplayReply(" + reply.id + ")"
	if (reply.content == "") {reply.title += " (ל\"ת)"; onclick = "";}
	var content = reply.content.replace(/\n/g,"<br>")
	var s=["<Div id=divReply" + reply.id + " class=ReplyTitle><span class=ReplyNum>" + num + ". </span><Span class=ReplyLink onClick=" + onclick + ">" + reply.title + "</span><div style=display:none class=ReplyContent>" + reply.content + ""]
	s.push("</div><div  class=ReplyName>" + reply.name + ", " + reply.city + " (" + reply.date.hebDate()+ ", "+reply.date.numGreDate() + ")</div> <div class=ReplyInf id=repAd"+reply.id+"></div></div>");
	return s.string();
},
Write: function(){
	var s=[""];
	if(sLinkData) s[0]= "<a href='"+sLinkData.replace("New","")+"List.aspx?act=replies&type="+this.Type+"&item="+this.Item+"'>ניהול תגובות</a>"
	s =["<h4 class=RepliesTitle><span onclick=Replies.OpenAll(" + this.Type + "," + this.Item + ") id=spnOpenAll" + this.Type + "-" + this.Item + " class=OpenAll>פתיחת כל התגובות</span> תגובות &nbsp; <span>(" + this.Replies.length + ")</span></h4>\
	<input type=hidden name=NewReplyType value=" + this.Type + "><input type=hidden id=NewReplyItem value=" + this.Item + ">"+(window.sLinkData!=""?"<a href=/a7Admin/Lists.aspx?act=replies&type="+this.Type+"&item="+this.Item+">ניהול תגובות</a>":"")+"<Div class=RepliesOuter>"];
	
	for (var i=0;i<this.Replies.length;i++) s.push(this.HTML(this.Replies[i],i+1));
	s.push("</div>")

	return s.string();
}}
Replies= $.extend(Replies,{Rep:{}, AddBrifcase : function(type,item,title)
{	if (!User.ID) {ShowLoginWindow(location.href); return false}
	// dhtml
	sTitle=prompt("כותרת שלי",title)
	if(!sTitle)return false;
	ExecuteUrl("/My/Brifcase.aspx?act=add&type="+type+"&item="+item+"&title="+title)
	// תודה רבה
},
UpdateCount: function(id,obj,count)
{
	id = _(id);
	str = obj.value;
	strlen = str.length;
	id.innerHTML = count - strlen
	if ((count - strlen) < 20) id.style.color = "red";
	else  id.style.color = "";
	if (strlen>count) obj.value = obj.value.substring(0,count);
},
SendReply: function(type,item)
{
	
	if (Replies.bPosted && Replies.sLastTitle==_("NewReplyTitle"+item).value) {return false;}
	bPosted = true;
	this.sLastTitle = _("NewReplyTitle"+item).value;
	if ($.trim(Replies.sLastTitle)=="") {alert("עליך לכתוב כותרת"); return false}
	$("#divWait"+type+"-"+item+"").show();
	$("#divReplyWin"+item).slideUp();
 	var ajax= $.ajax({url:"/Controls/AjaxForm.ashx?action=reply",type:"POST",data:{type:type,item:item,title: _("NewReplyTitle"+item).value,content:_("NewReplyContent"+item).value,name:_("NewReplyName"+item).value,city:_("NewReplyCity"+item).value},
 	success:function (d){$("#divWait"+type+"-"+item+"").hide();$("#divNew"+item+" input[type=text], #divNew"+item+" textarea").val(""); $("#spnNewReplySent"+item).slideDown();Info.LoadOne(74,'divCADC250');  $("#divReplyWin"+item).slideUp();},error:function(d){_("divWait"+type+"-"+item+"").innerHTML=""; alert("אירעה שגיאה במשלוח התגובה");}})
},
DisplayReply: function(id,openClose) {
	var div = _("divReply" + id);
	var d2= $(".ReplyContent","#divReply" + id);
	var open = d2[0].style.display == "none"||openClose==1;
	if (open)
	{
		d2.slideDown();
		if(!Replies.disableBG) $(div).css("background-color","#ffffff").animate({backgroundColor:"#eeeeee"},150);
		$(div).attr("class","ReplyBody");
	
		if (location.href.indexOf("/News")>-1||location.href.indexOf("/Cart")>-1||location.href.indexOf("/Album")>-1||location.href.indexOf("/Recipe")>-1||location.href.indexOf("/Besheva")>-1||location.href.indexOf("/Poll")>-1||location.href.indexOf("/Articles")>-1||location.href.indexOf("/TV")>-1) Info.LoadOne(Replies.InfoZone,"repAd"+id,1)
		else $("#repAd"+id).hide();
		}
	else
	{ $("#repAd"+id).hide(); if(!Replies.disableBG) $(div).animate({backgroundColor:"#ffffff"},300); d2.slideUp(300, function() {$(div).attr("class","ReplyTitle");}) }
},
DisplayForm: function(isMessage,div){
	$("#divSend"+div).slideUp();
	var div = $("#divNew"+div);
	div.slideToggle()	
},
ReDisplaySend: function(isMessage,div) {	
	$("#divSend"+div).slideToggle();
	$("#divNew"+div).slideUp()
},
Print: function (type,id) {
	url = "/PrintReplies.aspx?type=" + type + "&id=" + id 
	w=465;h=420;
	l=(screen.width - w)/2;t=(screen.availHeight - h)/2;props = 'width='+w+',height='+h+',left='+l+',top='+t+',scrollbars=yes';
	var x = window.open(url,'',props)
},
SendToFriend: function (type,item)
{
	var s = "";
	if (_("SendFriend"+item+"Name1").value == "")
		s += "עליך לכתוב את שמך\n";
	if (!checkEmail(_("SendFriend"+item+"eMail1").value)||!checkEmail(_("SendFriend"+item+"eMail2").value))
		s += "עליך לכתוב כתובת מייל חוקית\n";
		
	if (s != "") {	alert(s); return false;}
	else $.get("/Controls/SendFriend.ashx",{type:type,item:item,Name1:_("SendFriend"+item+"Name1").value,email1:_("SendFriend"+item+"eMail1").value,email2:_("SendFriend"+item+"eMail2").value},function (d){$("#divSend"+item).slideUp(1000); })
	
},
OpenAll: function(type,item){
 var r= Replies.Rep[type+"-"+item];
for (var i=0;i<r.length;i++) if(r[i].content) {
	
	var div = _("divReply" + r[i].id);
	var d2= $(".ReplyContent","#divReply" + r[i].id);
	if (!r.opened){
		d2.show();
		if(!Replies.disableBG) $(div).css("background-color","#eeeeee").attr("class","ReplyBody");
		else $(div).attr("class","ReplyBody"); }
	else
		{ if(!Replies.disableBG) $(div).css("background-color","#ffffff");
		$(div).attr("class","ReplyTitle"); d2.hide() }	
}
 r.opened=!r.opened;
 _("spnOpenAll"+type+"-"+item).innerHTML=(!r.opened?"פתיחת":"סגירת")+" כל התגובות"
 },
 Icon: function(click,pos,title) { return "<span class=Item><span class=Link onmouseout=\"this.firstChild.style.backgroundPosition='-19px -"+pos+"px'\" onmouseover=\"this.firstChild.style.backgroundPosition='0px -"+pos+"px'\" onclick='"+click.toHTML()+"'><span class='Icon' style='background-position: -19px -"+pos+"px'></span>"+title+"</span></span>"; }
})

O.Reply = function(id,title,name,city,date,content){this.id=id;this.name=name;this.title=title; this.city=city;this.date=date;this.content=content;}

function checkEmail(strEmail){return /^(([A-Za-z0-9]+_+)|([A-Za-z0-9]+\-+)|([A-Za-z0-9]+\.+)|([A-Za-z0-9]+\++))*[A-Za-z0-9]+@((\w+\-+)|(\w+\.))*\w{1,63}\.[a-zA-Z]{2,6}$/.test(strEmail); } 

RandN = {Items:[],Page:0,URLStart:"",HTMLUnder:"",
	Update: function(page) {var s=["<table><tr>"];
	 for(var i=page*3;i<(page+1)*3;i++){ s.push("<td><a onmousedown=Info.LogC(-1,2,"+this.Items[i].id+",4) href="+this.URLStart+this.Items[i].id+"><img src="+GetImage(this.Items[i].image)+">"+this.Items[i].title+(this.Items[i].icon?this.Items[i].icon:"")+"</a></td>");}
	 s.push("</td></tr></table>");
	 _("divRandN2").innerHTML = ("<div class=BackNextButtons><span class='Button' style=float:left;"+(page==Math.floor(this.Items.length/3-1)?"color:gray":" onclick=RandN.Update(RandN.Page+1);Info.LogC(-1,2,5)")+" >&#9668;</span><span class='Button' style=float:right;"+(page==0?"color:gray":" onclick=RandN.Update(RandN.Page-1);Info.LogC(-1,2,5)")+">&#9658;</span> </div><Div class=C>"+this.HTMLUnder+"</div>");
	 var d=_("divRandN");
	 $(d).animate({marginRight:this.Page>page?-300:300,opacity:0},500,(function(page) {return function () {
	 d.innerHTML=s.string();$(d).css("margin-right",RandN.Page<page?-300:300).animate({marginRight:0,opacity:1}); RandN.Page=page;}})(page))
	}
};

(function(jQuery){
jQuery.each(['backgroundColor', 'borderBottomColor', 'borderLeftColor', 'borderRightColor', 'borderTopColor', 'color', 'outlineColor'], function(i,attr){
jQuery.fx.step[attr] = function(fx){
			if ( fx.state == 0 ) {fx.start = getColor(fx.elem, attr);	fx.end = getRGB(fx.end);}
			fx.elem.style[attr] = "rgb(" + [Math.max(Math.min(parseInt((fx.pos*(fx.end[0]-fx.start[0]))+fx.start[0]),255),0),Math.max(Math.min(parseInt((fx.pos*(fx.end[1]-fx.start[1]))+fx.start[1]),255),0),Math.max(Math.min(parseInt((fx.pos*(fx.end[2]-fx.start[2]))+fx.start[2]),255),0)].join(",") + ")";
		}
	});
	// By Blair Mitchelmore http://jquery.offput.ca/highlightFade/

	function getRGB(color) {
		var result;

		if ( color && color.constructor == Array && color.length == 3) return color;

		// Look for rgb(num,num,num)
		if (result = /rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(color))	return [parseInt(result[1]), parseInt(result[2]), parseInt(result[3])];

		// Look for rgb(num%,num%,num%)
		if (result = /rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(color))return [parseFloat(result[1])*2.55, parseFloat(result[2])*2.55, parseFloat(result[3])*2.55];

		// Look for #a0b1c2
		if (result = /#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(color)) return [parseInt(result[1],16), parseInt(result[2],16), parseInt(result[3],16)];

		// Look for #fff
		if (result = /#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(color)) return [parseInt(result[1]+result[1],16), parseInt(result[2]+result[2],16), parseInt(result[3]+result[3],16)];
	}
	
	function getColor(elem, attr) {
		var color;

		do { color = jQuery.curCSS(elem, attr);
			if (color!=''&&color != 'transparent'||jQuery.nodeName(elem, "body")) break; 
			attr = "backgroundColor";
		} while (elem = elem.parentNode);

		return getRGB(color);
	};})(jQuery);

Ranks = [];
function Rank(type,item,rank,words)
{
	var iRank = Ranks.length;
	Ranks.push(this);
	
	var s="<span class=RRank id=RRank"+iRank+" onmousemove=this.t=0 onmouseout=\"var v=this;this.t=1;setTimeout(function(){if(v.t)Ranks["+iRank+"].Move(Ranks["+iRank+"].Rank);v.t=0},500);\">";
	for (var i=0;i<5;i++) s+="<b onmouseover=Ranks["+iRank+"].Move("+(i+1)+") onclick=Ranks["+iRank+"].Set("+(i+1)+")></b>";
	s+= "<span id=RRanked"+iRank+">"+(words?words[rank]:"")+"</span></span>";
		
	this.Type=type;this.Item=item;this.Rank=rank;this.ID=iRank;this.Words=words;
	this.str=s;
}

Rank.prototype = {Set: function(rank) {
	if(this.ranked) {_("RRanked"+this.ID).innerHTML="<span style=color:red>כבר דירגת</span>"; return;}
	_("RRanked"+this.ID).innerHTML="מדרג...";
	this.Rank=rank;var t=this;
	$.post("/Controls/AjaxForm.ashx?action=rank",{type:this.Type,item:this.Item,rank:rank},function(){_("RRanked"+t.ID).innerHTML=this.Words?this.Words[rank]:'הדירוג בוצע';t.ranked=true}); this.Move(rank)
},Move: function(rank){$("#RRank"+this.ID+" b").removeClass("sel").length; if(this.Words) _("RRanked"+this.ID).innerHTML=this.Words[rank]; $("#RRank"+this.ID+" :lt("+(Math.floor(rank))+")").addClass("sel"); },
Writed: function() {this.Move(this.Rank)}
};
