var sStaticURL = window.sStaticURL;

O = {
    Video: function(id, title, url, date, desc, image) { this.id = id; this.title = title; this.desc = desc; this.date = date; this.url = url; this.image = image * 1; },
    Flash: function(id, title, date, red) { this.id = id; this.title = title; this.red = red; this.date = date },
    News: function(id, title, date, image, author, replies) { this.id = id; this.date = date; this.image = image; this.title = title; this.replies = replies; this.author = author },
    User: function(id, name, online, image, org, sign) { this.id = id; this.name = name; this.online = online; this.sign = sign ? sign : ""; this.image = image },
    Picture: function(id, title, credit, date) { this.id = id; this.title = title; this.credit = credit; this.date = date } 
    
}
function DoNothing() {}
function GetImage(id, w, h) { if (w) return sStaticURL + "Resizer.ashx?source=news&image=" + id + "&a=" + w + "&b=" + h; return sStaticURL + "pictures/" + Math.floor(id / 1000) + "/" + id + ".jpg" }


Array.prototype.write = function() {document.write(this.join(""))}
Array.prototype.string = function() { return this.join("") }


//if (navigator.userAgent.indexOf("MSIE")>-1) Height = document.documentElement.clientHeight; else Height=window.innerHeight

String.prototype.write=function() {document.write(this)}
String.prototype.toNick=function() { return this.replaceStr("&","&amp;").replaceStr("<","&lt;").replaceStr(">","&gt;");}
String.prototype.toHTML=function(str) {str=this; if(!str) return ""; str+="";  return this.toNick().replaceStr('"',"&quot;").replaceStr("'","&#39;")}
String.prototype.toJS=function (str) {str=this; if(!str) return ""; str+=""; return str.replace('"',"\\\"").replace("'",'\\\'').replace("\n","\\n");}
String.prototype.replaceStr = function (oldValue,newValue) { return this.split(oldValue).join(newValue);}
String.prototype.removeStr = function(oldValue) { return this.replaceStr(oldValue,"")}
String.prototype.trim = function() { return this.replace(/^\s\s*/, '').replace(/\s\s*$/, ''); } 
/*
All things considered, this is probably the best all-around approach. Its speed advantage is most notable with long strings — when efficiency matters. The speed is largely due to a number of optimizations internal to JavaScript regex interpreters which the two discrete regexes here trigger. Specifically, the pre-check of required character and start of string anchor optimizations, possibly among others.
*/
String.prototype.toMysqlDate = function() {
    var temp = this.trim().split("/", 3);
    var str = temp[2].slice(0, 4) + temp[0] + temp[1] + temp[2].slice(5, 7) + temp[2].slice(8, 10)+ "00";
    return str;
}
String.prototype.fixLocaldate = function() {
    if (this.slice(2,3) != "/") {
        var a = this.slice(2,3);
        var temp = this.split(a);
		return temp.join("/");
    }
    return this;
}

String.prototype.toHTMLS = function (sString)
{	if (!sString) return "";
	
	function rxescape (str) {return str.replace(/[-[\]{}()*+?.\\^$|,#\s]/g, "\\$&");} 
	sString = sString.replace(/target=_top/g,"").replace(/(<A |<a)/g,"<A target=_blank ").replace(/<\/?\w+:[^>]*>/gi, "");

	var a = [[":-)","smile"],[":-D","vhappy"],[";-(","boche"],[":-(","sad"],[":-P","tongue"],[";-)","wink"],["(ישן)","k"],["(מחשב)","computer"],["(כוכב)","star"],["(בלון)","balon"]];

	for (var i=0;i<a.length;i++){
	var sSmile=rxescape(a[i][0]); sString = sString.replace(new RegExp("("+sSmile+"|"+sSmile.replace("\\-","")+")","gi"),"<img src=\"/Forum/images/smilies/"+a[i][1]+".gif\">")}
	
	sString = sString.replace(/<IMG src=\"http:\/\/forumpics.a7.org\/\?file=(.*?)\"[^>]*>/g, "<a href=http://forumpics.a7.org/?file=$1 target=_blank><IMG  src=\"/Tolaim/ResizeImg.aspx?image=$1&a=760&save=1\"$2></a>")
	return sString;
}
var Log=[];
function LogIt(act,value)
{
	if (!window.NUCONOMY) Log.push([act,value]);
	else ActualLog(act,value);
}
function ActualLog(act,value) {NUCONOMY.ActivityParameter1=value; NUCONOMY.Logger.LogActivity(User.Name,"",location.href,act);}

var Info = {aIDs:[], aZones:[],View:{aIDs:[],aZones:[],aClients:[]}, Add:function(zone,id){Info.aIDs.push(id);Info.aZones.push(zone);},Remove:function(id) {for(var i=0;i<Info.aIDs.length;i++)if(Info.aIDs[i]==id){Info.aIDs.remove(i);Info.aZones.remove(i)}},
	HTML: function(i,bid,cid,zone,type,url,file,ver,height,width,append) {
		var newurl = "http://click.inn.co.il/php/a"+"d";
		var newurle = ".php?bannerid="+bid+"&zoneid="+zone+"&clientid="+cid+"&dest="+url;
		var fileurl ='http://click.inn.co.il/info_en/'+file;
		var clickurl= newurl+"click"+newurle;
		var logurl= newurl+"log"+newurle;
		var code="";
		switch (type) {
			case "jpeg":case "png":case "gif":
			code="<a href="+clickurl+" target=_blank><img width="+width+" height="+height+" src="+fileurl+">"+append+"</a>";
			break;
			case "swf":
			var v="";
			fileurl += "?alink1="+escape(clickurl)+"&atar1=_blank"; if (zone==17||zone==71) v = "<PARAM NAME=WMode VALUE=Transparent>";
			code = "<OBJECT codeBase=http://fpdownload.adobe.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0 height="+height+" width="+width+" classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000>"+v+"<param name=\"flashvars\" value=\"alink="+fileurl+"\" /><PARAM NAME=Movie VALUE='"+fileurl+"'><PARAM NAME=Src VALUE='"+fileurl+"'><PARAM NAME=Menu VALUE=-1><PARAM NAME=AllowScriptAccess VALUE=never><PARAM NAME=AllowFullScreen VALUE=false><embed src='"+fileurl+"' quality=high wmode='opaque' width='"+width+"' height='"+height+"' type='application/x-shockwave-flash' pluginspace='http://www.adobe.com/go/getflashplayer' allowScriptAccess='never' FlashVars=\"alink="+escape(fileurl)+"\"></embed></OBJECT>";	break;
			case "html":
			code=file.replaceStr("{target}","_blank").replaceStr("{source}","").replaceStr("{zoneid}",zone).replaceStr("{bannerid}",bid).replaceStr("{url_prefix}",newurl);
		}
		return code;
	},
	Insert : function (i,bid,cid,zone,type,url,file,ver,height,width,append) {
	var code = Info.HTML(i,bid,cid,zone,type,url,file,ver,height,width,append)
	var v= Info.View
	v.aIDs.push(bid);v.aClients.push(cid); v.aZones.push(zone);
	$("#"+Info.aIDs[i]).append(code);
	},
	Reload: function() {
	for (var i=0;i<Info.aIDs.length;i++) _(Info.aIDs[i]).innerHTML="";
	Info.Final(true);},
	Log: function() {ExectueUrl("http://click.inn.co.il/infol.php?clients="+Info.View.aClients.join(",")+"&zones="+Info.View.aZones.join(",")+"&b="+Info.View.aIDs.join(","));},
	
	ReloadTO: function (timeout) {window.setTimeout(TReload,timeout)},
	Final: function(nottrim) {ExectueJS("http://click.inn.co.il/infonew.php?zones_list=" + Info.aZones.join(",") + "&"+new Date().getTime());
	if (!nottrim&&window.aAdSource&&location.pathname!="/") if (aAdSource[2]) document.write ("<sc"+"ript src=http://ww.inn.co.il/pop.asp?"+new Date() +"></scr"+"ipt>")}
	
}
if(!window.jQuery) jQuery = {};
jQuery.findPos = function(obj) {
		var curleft = curtop = 0;
		if (obj.offsetParent) {
			curleft = obj.offsetLeft;
			curtop = obj.offsetTop;
			while (obj = obj.offsetParent) {
				var origcurleft = curleft;
				curleft += obj.offsetLeft;
				if (curleft < 0) { 
					curleft = origcurleft;
				}
				curtop += obj.offsetTop;
			}
		}
		return {x:curleft,y:curtop};
	}
jQuery.getMouseCoordsWithinEvent= function(event)
{
	var coords = {x: 0, y: 0};
	if(!event)
	{	event = window.event;
		coords.x = event.offsetX;
		coords.y = event.offsetY;	}
	else
	{
		var e = jQuery.findPos(event.target)
		coords.x = event.pageX - e.x;
		coords.y = event.pageY - e.y;	}
	 return coords;
}

function ExectueJS(url, func) {
    var scriptElem = document.createElement('script');
    scriptElem.setAttribute('src', url + (func ? "&func=" + func : ""));
    $('head')[0].appendChild(scriptElem);
    }
    function ExectueUrl(url) { var i = document.createElement("img"); i.src = url + "&_" + new Date(); i.style.display = "none"; _("divMain").appendChild(i); }
    /*function ExecuteUrl(url) { var i = document.createElement("img"); i.src = url + "&_" + new Date().getTime(); i.style.display = "none"; _("divMain").appendChild(i); } */
window.ExecuteJS = ExectueJS;

Windows = {
Login: function (ref,msg)
{
	if(!ref) ref= location.href;
	if(msg) msg = "<div style=color:red;text-align:right>"+msg+"</div>"; else msg="";
    var div = document.createElement("div"); div.className='InfoWin'
	div.innerHTML="<div class=Inner><span class=X onclick=this.parentNode.parentNode.parentNode.removeChild(this.parentNode.parentNode);></span><div class=Top><div class=Ttl style=padding-top:6px>כניסה למערכת</div><div style=width:180px>כדי לבצע פעולה זו עליך להיות משתמש רשום.</div></div><div class=White>"+msg+"<form method=post action=/Login.aspx><input type=hidden name=ref value='" + ref +"'><span>שם:</span><INPUT class=t name=Username><BR><span>סיסמא:</span><INPUT type=password class=t  name=Password><INPUT class=s type=image src="+sStaticURL+"images/forum/login.gif></form></div><div class=Gray><img src="+sStaticURL+"images/forum/arrow.gif><span style=display:inline-block;margin-bottom:3px;margin-right:4px> משתמש חדש? <a href=/Register.aspx id=Register>הירשם עכשיו!</a></span></div></div>";
	div.style.backgroundImage="url("+sStaticURL+"images/forum/screen.gif)"

    document.body.appendChild(div); $(div).css("position","absolute").css("left",$(window).width()/2-200+"px").css("top",document.body.scrollTop+160+"px").fadeIn()
}, Audio: function (append) {if(!append) append="";	open("/Radio/Player.htm"+append,"INNAudio","width=500,height=464,status=1,resizable=0",true);}
}

//function openULWindow(sender) {popupWin = window.open('/Special/Upload.aspx?sender='+sender,'new_page','width=700,height=600')}
//d=document.getElementById("AddUser");d.parentNode.removeChild(d);

User = {ActiveUsers:[],ID:0,Name:"",Email:"",Level:0,ForumLevel:0,Forums:[],
 Add: function (id) { ExectueUrl("/Forum/IM/lmf_Msg_Down.aspx?act=add&user="+id)},
 DelBlockUser: function(id){if(!confirm("בלחיצת אישור, לא תקבל עוד הודעות מהמשתמש")) return false; ExectueUrl("/Forum/IM/lmf_Msg_Down.aspx?act=removeblock&status=1&user="+id)},
 IgnoreUser: function(id){ExectueUrl("/Forum/IM/lmf_Msg_Down.aspx?act=ignore&user="+id)},
 OpenIM: function(name){if(!name) name="";else name="#"+escape(name);PopLeft.Audio.im=false;  window.open("/Forum/IM/lmf_.aspx"+name,"INNIMnew","height=570,width=730,,status=1,resizable=1")},
 RemoveCalAlert: function (id) {ExectueUrl("/My/Calendar/DateData.aspx?act=remove&id="+id)},
 inCal :(location.href.substring(location.href.length-9).toLowerCase()=="calendar/")
}


PopLeft = {Checked:false,Audio:{im:false,mail:false},
	Show: function (div){div.style.float="left";_("divMsgSource").childNodes[0].appendChild(div); $(div).css("display","none").slideDown(1200);},
	ShowMsg: function (click,close,ttl,msg,btns,user,uname,img)
	{	var onc="",closeF="this.parentNode.parentNode.parentNode.removeChild(this.parentNode.parentNode);"; if (click) {onc=";cursor:pointer";click+=closeF}
		div = document.createElement("div"); div.className='InfoWin'
		div.innerHTML="<div class=Inner><span class=X onclick='"+closeF+close+"'></span><div class=Top "+click+" style='"+onc+"'><div class=Ttl>"+ttl+"</div><div style=width:180px><b>"+ (!click?("<a href=/Forum/lmf_Profile.aspx/"+user+" style=color:#354564;text-decoration:none>"+uname.toHTML()+"</a>"):uname.toHTML())+"</b> "+msg+"</div></div><div "+click+" style='"+onc+"' class=White align=center>"+btns+"</div></div>";
		if (img) image = sStaticURL +"/Resizer.ashx?source=user&a=54&b=54&user="+user; else image = "/Forum/IM/images/imw.png";
		div.style.backgroundImage="url("+image+")";
		return div},
	Play: function(sound)
		{if ($.browser.mozilla > -1) sPlayer = '<object id=Player width="1" height="1"  type="application/x-ms-wmp"><PARAM NAME="stretchToFit" VALUE="false"><param name=URL value="'+sStaticURL+"/audio/"+sound+'"><PARAM NAME="autoStart" VALUE="true"></OBJECT>';
		if ($.browser.msie) sPlayer =  '<object id=Player classid=CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6 width="1" height="1"><PARAM NAME="enableContextMenu" VALUE="false"><PARAM NAME="stretchToFit" VALUE="false"><param name=url value="'+sStaticURL+"/audio/"+sound+'"><PARAM NAME="autoStart" VALUE="true"></OBJECT>'
		_("divMsgSource").childNodes[1].innerHTML = sPlayer;
		},
	
	AddUser: function(name,id,img)
		{	div = PopLeft.ShowMsg("","IgnoreUser("+id+")","הוספת חבר"," ביקש לצרף אותך כחבר","<span class=Link onclick=ActualAddUser("+id+")>הוסף</span> | <span class=Link onclick=IgnoreUser("+id+")>התעלם</span> | <span class=Link onclick=ActualDelBlockUser("+id+")>חסום</span>",id,name,img);
		div.id="AddUser";PopLeft.Show(div);},
	ShowPB: function(sUser,id,img,msg) {PopLeft.Show(PopLeft.ShowMsg("onclick=location.href='/My/PrivateBox/lmb_Folder.aspx?folder=1';","","מסר חדש","כותב/ת לך",msg.substring(0,38),id,sUser,img));},
	ReadIM :function (id) {ExectueUrl("/Forum/IM/lmf_Msg_Down.aspx?act=unnew&user="+id)},
	ShowIM: function(sUser,id,img,msg,sound) {PopLeft.Show(PopLeft.ShowMsg("onclick=User.OpenIM();","IMReadMsg("+id+")", "שיחה חדשה","כותב/ת לך",msg.replace(/\[file:.*?\]/g,"קובץ מצורף").substring(0,38)+"...",id,sUser,img)); if(sound&&!this.Audio.im){PopLeft.Play("msg.wma");this.Audio.im=true;}},
	ShowMail: function(number,sound) {
		if(sound==1) if(location.href.toLowerCase().indexOf("/my/mail")==-1) if(sound) opLeft.Show(PopLeft.ShowMsg("onclick=location.href='/My/Mail';","","הודעה חדשה","יש לך דואר אלקטרוני חדש","",0,"",0))
		if(sound==2) CheckPlaySound("msg.wma");
		d=_("divMailMsgs"); if(d) d.innerHTML = number +" הודעות חדשות"
	},
	RemoveCalAlert: function (id) {
		User.RemoveCalAlert(id); if (User.inCal) {ChangeView(ActiveView,true);LoadToday()}
		if (PopLeft.iActiveCalPopup<PopLeft.aCalItems.length) {PopLeft.ShowCalAlert(PopLeft.aCalItems[PopLeft.iActiveCalPopup][0],aCalItems[PopLeft.iActiveCalPopup][1]); PopLeft.iActiveCalPopup++}
		else PopLeft.iActiveCalPopup--},
	OpenCalItem: function (id) {if(User.inCal) GetItem(id); else {location.href="/My/Calendar/?item="+id;}},
	iActiveCalPopup:0,aCalItems:[],
	ShowCal: function (arr)
	{	PopLeft.aCalItems =arr;
		if (PopLeft.iActiveCalPopup<arr.length) {PopLeft.ShowCalAlert(arr[PopLeft.iActiveCalPopup][0],arr[PopLeft.iActiveCalPopup][1],arr[PopLeft.iActiveCalPopup][2]); PopLeft.iActiveCalPopup++}
	},
	ShowCalAlert: function (id,title,repeat) {
		var onc="",closeF="removeAlert("+id+")";
		div = document.createElement("div"); div.className='InfoWin'
		div.innerHTML="<div class=Inner><span class=X onclick='this.parentNode.parentNode.parentNode.removeChild(this.parentNode.parentNode);"+closeF+"'></span><div class=Top ><div class=Ttl>יומן ערוץ 7 - <font color=red>תזכורת</font></div><div style=width:180px>"+title.substring(0,40).toHTML()+"</div></div><div class=White align=center><span class=Link onclick=OpenCalItem("+id+")>ערוך</a> | <span class=Link onclick='this.parentNode.parentNode.parentNode.parentNode.parentNode.removeChild(this.parentNode.parentNode.parentNode.parentNode);"+closeF+"'>בטל</span></div></div>";
		div.style.backgroundImage="url(/Forum/images/cal.png)"
		PopLeft.Show(div)},
	Check: function() {if (User.ID&&!PopLeft.Checked) ExectueJS("/My/Checker.ashx?page="+ escape(location.href.substring(location.href.substring(7).indexOf('/')+7))+"&_t="+new Date()); PopLeft.Checked=false; setTimeout(PopLeft.Check,60000);},
	FinalCheck: function (r)
	{	if(!r)_('divMsgSource').childNodes[0].innerHTML='';
		var d=_("divOnline")
		if(d) {var s="<b>חברים מחוברים:</b> ";
			for (var i=0;i<User.ActiveUsers.length;i++)
				s+= '<a style=display:inline-block; href=/Forum/lmf_profile.aspx/'+User.ActiveUsers[i].id+'>'+User.ActiveUsers[i].name+'</a>, ';
			d.innerHTML=s; }}
}

document.write("<script>$(document).ready(PopLeft.Check);</script><div id=divMsgSource style=z-index:1;position:fixed;_position:absolute;width:210px;left:1px;bottom:2px;><div style=position:absolute;bottom:2px;left:1px></div><div style=display:none></div></div>");
//if (jQuery.browser.msie&& jQuery.browser.version*1==6) window.setTimeout(function(){ UpdateWin(document.getElementById("divMsgSource"),Height-1)},1000);
if ($.browser.mozilla)  $(document).ready(function() {document.body.className="Firefox"})

function Tabs (divTabs, divContent,enableX){this.divTabs=divTabs; this.divContent=divContent; $(divTabs).addClass("Tabs"); $(divContent).addClass("TabsContent"); this.enableX=enableX;}
var iAutoNum=0;
Tabs.prototype = {Tabs: [],Active:-1,
	Add: function (title,image)
	{
	var div = document.createElement("div"); 
	div.className="TabContent";
	var tab = this.Tabs.length;
	this.Tabs[tab] = {id:++iAutoNum,title:title}
	var oTab=this.Tabs[tab]
	this.divContent.appendChild(div);	
	oTab.div = div;
	var th = this;
	div = document.createElement("span"); div.id='tab'; div.innerHTML = "<span class=tab01></span><span class=tabcontent>"+(image?"<img src="+sStaticURL+image+">":"")+"<span>"+title+"</span>" +(this.enableX?"<span class=X onclick=RemoveTab(GetTabById("+Tabs[tab].id+"))></span>":"")+"</span><span class=tab02></span>";
	div.onclick= function(d) {return function() {th.SetActive(th.GetTabById(d))};}(oTab.id)
	oTab.divTab = div;
	this.divTabs.appendChild(div);
	return oTab;
	},

	Remove : function(id)
	{
	var tab = this.Tabs[id]
	tab.div.parentNode.removeChild(tab.div);
	tab.divTab.parentNode.removeChild(tab.divTab);
	Tabs.Tabs.remove(id);
	if (this.Tabs.length>1) this.SetActive(id);
	if(id>0&&this.Active==id)id--;
	},
	SetActive: function(tab)
	{	 var t=this;
	for (i=0;i<this.Tabs.length;i++) { if(i!=tab) $(t.Tabs[i].div).fadeOut(200); this.Tabs[i].divTab.className=this.Tabs[i].flash ? 'Flash':'';}
	
	this.Active=tab;
	if (this.Tabs[tab]) {
		this.Tabs[tab].flash=0; $(this.Tabs[tab].divTab).attr("class","selected"); setTimeout(function() { $(t.Tabs[tab].div).fadeIn()},200)
		}
	},
	GetTabById: function(id) { for (i=0;i<this.Tabs.length;i++) if (this.Tabs[i].id==id) return i; return -1}
}

View = {LastToolbar:-1, Toolbar:  [
		["ראשי","/",[["דף הבית","/"],["מבזקים","/News/Flashes.aspx"]]],
		["רדיו","/Radio/",[["תוכניות מוקלטות","/Radio/"],["תיבת נגינה","/Radio/Jukebox.aspx"],["מצעד חסידי","/Radio/Parade.aspx"]]],
		["וידאו","/TV/",[["וידאו","/TV/"]]],
		["פורומים","/Forum/",[["עדכני","/Forum/lmf_Active.aspx"],["אישי","/My/"]]]
		],
Top: function() {
var s=["<div id=divTopAd></div><div class=BTop><div class=BSD>בס\"ד, <span>"+dDate.hebDate()+", "+ dDate.greDate()+"</span></div><div class=Langs></div><div class=Loggged>"]
	if (User.ID) s.push("<b>שלום " +User.Name+"</b> | <span class=Link onclick=User.OpenIM()>שיחה אישית</span> | <a href='/My/PrivateBox/'>מסרים אישיים</a>");
	else s.push("<b>שלום אורח</b> <a href=/Login.aspx>התחבר</a>/<a href=/Register.aspx>הרשם</a>");
	s.push("</div></div><table class=TableTop><Tr><Td class=Logo><a href='/'>logo</a></td><td class=Toolbar><div id=divToolbar>");
	for (var i=0;i<View.Toolbar.length;i++)
		s.push("<a class=T onmouseover=View.MoveToolbar("+i+") href="+View.Toolbar[i][1]+">"+View.Toolbar[i][0]+"</a>");
	s.push("</div><div id=divToolbar2><a></a></div></td><td>c</td></tr></table>");
	s.write();View.MoveToolbar(0); if ($.browser.mozilla) $(document).ready(function(){ document.body.className="Firefox";})},
MoveToolbar: function(id) {var t = View.Toolbar[id][2]; var s=[""];
	for (var i=0;i<t.length;i++) s.push("<a href='"+t[i][1]+"'>"+t[i][0]+"</a>");
	var o= $("#divToolbar2"); 
	if(View.LastToolbar!=id){var o2= $("#divToolbar2 a"); o2.fadeOut(300,function(){_("divToolbar2").innerHTML = s.string(); $("a",o).fadeIn(300)});View.LastToolbar=id}},
WriteFlashes: function(arr) {var s="<marquee class=Flashes direction=up scrollamount=1 scrolldelay=60 onmouseover=this.stop() onmouseout=this.start();><ul class=RightList>";
	for(var i=0;i<arr.length;i++) s+="<li><a href=/News/Flash.aspx/"+arr[i].id+">"+arr[i].title+"</a>"+arr[i].date+"</li>";return s+"</ul></marquee><div class=More><a href=/News/AllFlashes.aspx>עוד מבזקים <b>&#9668;</b></a></div>";},
	AddZero: function(time) { if (time>10) return time; else return "0"+time},
	PaseTime: function(time){return Math.floor(View.AddZero(time/60)) + ":" + View.AddZero(Math.floor(time-(Math.floor(time/60))*60))}
}