/*{literal}*/
var nrg = 
{	// return AJAX loaded HTML , or insert into DIV's with ID=id
    timer_fadein	: false,
	timer_fade_opac : 0,
	lastfadetime    : 0,
	is_ie		    : (document.all && document.getElementById),   // Is internet Explorer
	is_moz		    : (!document.all && document.getElementById),  // Is Mozilla class navigators
	lightbox_trouble_divs :  Array(),
	form_elements: Array('INPUT','SELECT','TEXTAREA'),
	scroll_divs_count : 0,
	scroll_divs		  : Array(),

	echo		: function(url, id)
				  { if (window.XMLHttpRequest)
					{ req = new XMLHttpRequest();
					  req.open("GET", url ,false);
					  req.send(null);
					}    
					else
					{ req = new ActiveXObject("Microsoft.XMLHTTP");
					  req.open("GET", url ,false);
					  req.send();
					}
					var result_txt=''; if (req.readyState == 4) {  if (req.status == 200) { result_txt=req.responseText;}}
					if (id!=undefined&&document.getElementById(id)) document.getElementById(id).innerHTML=result_txt;
					else if (id==undefined) document.write(result_txt);
				  },				  
	echoOnLoad	: function (url, id)
				  {
					this.onBodyLoad(function(){nrg.echo(url, id)});
				  },
	$			: function (id){ return (document.getElementById(id)?document.getElementById(id):false) },
	jsonAjax	: function (url, variables, callbackFunc, options, returnJson)
				  {  var method="GET";
	
					 if (options!=undefined&&options['method']&&(options['method']=='post'||options['method']=='POST'))method="POST";
					 if (returnJson==undefined) returnJson=true;

					 if (window.XMLHttpRequest)
					 { req = new XMLHttpRequest();
					   req.open(method, url ,false);
 					   req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
					   req.send(variables);
					 }    
					 else
					 { req = new ActiveXObject("Microsoft.XMLHTTP");
					   req.open(method, url ,false);
   					   req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
					   req.send(variables);
					 }

					 if (options!=undefined&&options['debug']!=undefined&&options['debug']==1)
						alert(req.responseText);

					 if (returnJson)
					 {	 try {var ret_obj = eval('(' + req.responseText + ')'); } catch(err) {var ret_obj = false;}
						 if (callbackFunc!=undefined) errorcode = callbackFunc(ret_obj); else return ret_obj;
					 }
					 else 

					 {	 
						 if (callbackFunc!=undefined)
						 {  
						    callbackFunc(req.responseText); 
					     }
					 
					     else  return req.responseText; }
				  },
	isUser		: function (username){ return (!(this.getCookie('maariv_nrg')==undefined||this.getCookie('maariv_nrg')=='')); },
	getUserName	: function () 
				  {   var coo = this.getCookie('maariv_nrg',false);
					  try { var aa= coo.substr(0,coo.lastIndexOf('%'));return this.URLDecode(aa); }
					  catch (err){ return false;}
				  },
	getUserEncrId : function () 
				  {   var coo = this.getCookie('maariv_nrg', false);
					     try { var aa=coo.substr(coo.lastIndexOf('%')+1); return this.URLDecode(aa); }catch (err){ return false;}
				  },
	getRandom	: function (){},
	randomize	: function ()
				  {
				     return parseInt(Math.random()*99999999);
				  },
	setCookie   : function (name, value, expires, path, domain, secure) {
		expires instanceof Date ? expires = expires.toGMTString() : typeof(expires) == 'number' && (expires = (new Date(+(new Date) + expires * 1e3)).toGMTString());
		if (domain==undefined)domain='.nrg.co.il';
		var r = [name + "=" + this.URLEncode(value)], s, i;
		for(i in s = {expires: expires, path: path, domain: domain}){
			s[i] && r.push(i + "=" + s[i]);
		}
		return secure && r.push("secure"), document.cookie = r.join(";"), true;
	},
	/* Get cookies */
	getCookie	: function (c_name, escaped)
				  { if (escaped==undefined)escaped=true;
		            if (document.cookie.length>0)
					{ c_start=document.cookie.indexOf(c_name + "=");
					  if (c_start!=-1)
						{ 	c_start=c_start + c_name.length+1; 
							c_end=document.cookie.indexOf(";",c_start);
							if (c_end==-1) c_end=document.cookie.length;
							return (escaped?unescape(document.cookie.substring(c_start,c_end)):document.cookie.substring(c_start,c_end));
						} 
					  }
					return "";
				  },
	/* Attach Avent */
	addEvent	: function (elm,evType,fn,useCapture) 
				  { if(elm.addEventListener) {elm.addEventListener(evType,fn,useCapture);}
					else if (elm.attachEvent) {var r=elm.attachEvent('on' + evType,fn); }
					else {elm['on' + evType] = fn;}
				  },
	/* Remove Event */
	removeEvent	: function (elm,evType,fn,useCapture) 
				  {	if(elm.addEventListener) {elm.removeEventListener(evType,fn,useCapture); return true;}
					else if (elm.attachEvent) {var r=elm.detachEvent('on' + evType,fn);  return r;}
					else {elm['on' + evType] = '';}
				  },
	onBodyLoad	: function ( func )
				  {
				    this.addEvent(window,'load',func, true);
				  },
	loadJS		: function (filename)
				  { var fileref=document.createElement('script');
					fileref.setAttribute("type","text/javascript");
					fileref.setAttribute("src", filename);
					document.getElementsByTagName("head")[0].appendChild(fileref);
				  },
	loadCSS		: function (filename)
				  { var fileref=document.createElement("link");
					fileref.setAttribute("rel", "stylesheet");
					fileref.setAttribute("type", "text/css");
					fileref.setAttribute("href", filename);
				    document.getElementsByTagName("head")[0].appendChild(fileref);
				  },

	lightbox	: function (formName,doWhat) 
		          { if (!this.$('lightbox'))
				    { var div1 = document.createElement('DIV');var div2 = document.createElement('DIV');
					  div1.onclick="nrg.lightbox('','off')"; div1.id='lightbox';
					  div2.onclick="nrg.lightbox('','off')"; div2.id='dialog';
					  document.body.insertBefore(div2,document.body.firstChild);
					  document.body.insertBefore(div1,document.body.firstChild);
					 
					  // Also find and remove refresh meta tag 
					  var m = document.getElementsByTagName('meta'); var l=m.length;
					  while(l--) {
					 	if(m[l].httpEquiv=='REFRESH') {
						  m[l].content=null;
						  m[l].parentNode.removeChild(m[l]);
						}
					 }
				   }

			        var bg		= this.$("lightbox");
			        var dialog	= this.$("dialog");
					var margin=(document.body.offsetWidth-550)/2+"px";dialog.style.left=margin;
					if(doWhat=="off") // turn off
					{ bg.blur();
					  bg.style.display="none"; 
					  dialog.style.display="none"; 
					  for (var a=0;a<this.lightbox_trouble_divs.length;a++ )
					  {if (this.$(this.lightbox_trouble_divs[a]))this.$(this.lightbox_trouble_divs[a]).style.display='block';}

					  
					  if (typeof this.lightbox_run_after_close=='string'&&(this.lightbox_run_after_close!=undefined||this.lightbox_run_after_close!=''))
					  {  eval(this.lightbox_run_after_close);
					  }
					  return;
					} 

					if(doWhat!="resize") { // if not resize then load iframe and display
					   for (var a=0;a<this.lightbox_trouble_divs.length;a++ )
					   {if (this.$(this.lightbox_trouble_divs[a]))this.$(this.lightbox_trouble_divs[a]).style.display='none';}

				        scroll(0,0); 
						dialog.innerHTML="<iframe id=\"myIframe\" name=\"myIframe\" allowtransparency=\"true\" src=\"" + formName + "\" width=\"550\" height=\"960\" frameborder=\"0\" scrolling=\"no\"></iframe>";
						var a=screen.availHeight;
						var b=document.body.scrollHeight;
						var c=dialog.offsetHeight;
						var y;
						if(a>=b) {if(a>=c) y=a; else y=c;} else {if(b>=c) y=b; else y=c;}
						bg.style.height=(parseInt(y)+199)+"px";
						bg.style.display="block";
						dialog.style.display="block";
						// do myIframe.height = myIframe.scrollHeight
						//this.fadein('dialog',0,100,10,2);
					 }
				  },
    lightbox_AddTroubleDiv: function(div_id)
				  {
				     this.lightbox_trouble_divs[this.lightbox_trouble_divs.length]=div_id;
				  },

				  // check if lightbox is opened 
	is_lightbox : function ()
	              {
	                  if (this.$('lightbox'))
					  {
						 alert(this.$('lightbox').style.display);
						 return true;
					  }  
					  else return false;
	              },

                 // FadeIn , FadeOut by steps 
	fadein      : function (id, from, to, step, interval)
				  {  var d = new Date();
	                 var mno = 1;
					 if (!this.timer_fadein)
				     {	 this.timer_fadein    = setInterval("nrg.fadein('"+id+"','"+from+"','"+to+"','"+step+"','"+interval+"')", interval); 
						 this.timer_fade_opac = from; 
						 this.lastfadetime    = 0; 
					  }

					 if (from >to && this.timer_fade_opac>to || from<to&& this.timer_fade_opac<to ) 
					 {	 if (this.lastfadetime >0){mno = (d.getTime()-this.lastfadetime)/interval;}
						 this.timer_fade_opac=parseInt(this.timer_fade_opac)+(parseInt(step)*mno);
						 try{
						   // If las step of opacity bigger of needle value, set needle value 
						   var timer_fade_opac = this.timer_fade_opac; if (timer_fade_opac>to)timer_fade_opac =to;
						   if (this.is_ie)  nrg.$(id).filters.alpha.opacity = timer_fade_opac;
						   if (this.is_moz) nrg.$(id).style.MozOpacity = (parseInt(timer_fade_opac)/100);
						 }catch(err){}

					 } else { clearInterval(this.timer_fadein);this.timer_fadein=false;}

					 this.lastfadetime = d.getTime();

				  },
    lightbox_AddTroubleDiv: function(div_id)
				  {
				     this.lightbox_trouble_divs[this.lightbox_trouble_divs.length]=div_id;
				  },

	is_lightbox : function ()
	              {   if (this.$('lightbox')&&this.$('lightbox').style.display!='none')
					  { return true; }  
					  else return false;
	              },
                   // Real escape with hebrew support(for php urldecode), created by Alexey P.NRG Maariv 2008.
    URLEncode   : function (clearString) 
		          { clearString = escape(clearString);
					clearString = clearString.replace(/(\%(u05[A-Z0-9]{2}))/g, 
		            function(full, m1, m2) { return "%"+(parseInt(m2.replace('u',''),16) - 1264).toString(16).toUpperCase();})
					return clearString;
				  },
                  // Real unescape with hebrew support(from url encode), created by Alexey P.NRG Maariv 2008.
	URLDecode   : function (clearString) 
		          {    clearString = unescape(clearString);
					   var retval='';
					   for (a=0;a<clearString.length;a++)
						 if (clearString.charCodeAt(a)>=224&&clearString.charCodeAt(a)<=(224+26) )   // Hebrew
						   retval=retval+String.fromCharCode(clearString.charCodeAt(a)+1264);
						 else if (clearString.charCodeAt(a)==43) // Space
						   retval=retval+' ';
						 else
						   retval=retval+clearString.substr(a,1);
					   return retval;
				  },
				  // Filter pressed key, and return 
	 keyfilter  : function (event, keyCode, func )
				  {  
					 if(event.keyCode==keyCode) func();
				  },
	 addIframe  : function (src)
				  {  var iframe = document.createElement('IFRAME');
					 iframe.src = src;
					 iframe.style.visibility='hidden';
					 document.body.appendChild(iframe);
				  },
	 getStyle   :function(el)
	             {	var myObj=this.$(el);
					if(window.getComputedStyle)
						return window.getComputedStyle(myObj,null);
					else
						return myObj.currentStyle;
				  },
	 disableElements : function(el, flag)
				  {	var myObj=this.$(el);
					for (var a=0;a<this.form_elements.length;a++)
					{ var elms = myObj.getElementsByTagName(this.form_elements[a]);
					  for (var b=0;b<elms.length;b++)
					    elms[b].disabled=flag;
					}
				  },
	 				  
	 scrollDiv: function (wrapperId)
			 {
				var a = this.scroll_divs_count;
				this.scroll_divs[a] = new Object;
				
				this.scroll_divs[a].parent			= this.$(wrapperId);
				this.scroll_divs[a].parent.style.scroll_id = a;

				if (this.$(wrapperId).firstChild.nodeType!=3)
				  this.scroll_divs[a].container		= this.$(wrapperId).firstChild;
			    else 
				  this.scroll_divs[a].container		= this.$(wrapperId).childNodes[1];

				this.scroll_divs[a].lastscrolltime	= 0;
				this.scroll_divs[a].interval		= 90;
				this.scroll_divs[a].is_over			= false;
				this.scroll_divs[a].parentHeight	= this.scroll_divs[a].parent.clientHeight;
				this.scroll_divs[a].containerHeight	= this.scroll_divs[a].container.scrollHeight;
				this.scroll_divs[a].PosY			= this.scroll_divs[a].parentHeight-8;

				this.addEvent( this.scroll_divs[a].container ,'mouseover', function()
				{  eval("var a="+a);
				   nrg.scroll_divs[a].is_over = true;
				},true );

				this.addEvent( this.scroll_divs[a].container ,'mouseout', function(event)
				{  eval("var a="+a);
				   nrg.scroll_divs[a].is_over = false;
				},true );


				this.scroll_divs[a].container.style.marginTop = this.scroll_divs[a].parentHeight+"px";
				if (this.scroll_divs_count==0){setInterval('nrg._scrollMoove()',60);}
				this.scroll_divs_count++;
				
			 },
	  // Internal function of scrolling
	 _scrollMoove : function()
	 { // Run every scroll 
	   var d = new Date();var mno = 1;
	   for (var a=0;a<this.scroll_divs_count; a++)
	   { if (this.scroll_divs[a].is_over==false&&this.scroll_divs[a].parent.style.display!="none")
	 	 { if (this.scroll_divs[a].lastscrolltime >0)
		   mno = (d.getTime()-this.scroll_divs[a].lastscrolltime)/this.scroll_divs[a].interval;
		   this.scroll_divs[a].PosY=this.scroll_divs[a].PosY-parseInt(1)*mno;
		   this.scroll_divs[a].container.style.marginTop = this.scroll_divs[a].PosY+"px";
  		   if (this.scroll_divs[a].PosY<-this.scroll_divs[a].containerHeight)
		     this.scroll_divs[a].PosY = this.scroll_divs[a].parentHeight; 
		   this.scroll_divs[a].lastscrolltime = d.getTime(); 
		  }
		  else
		    this.scroll_divs[a].lastscrolltime = d.getTime();
		 }
      }
}


var tabz = {
  click:function(linkObj,tabsPrefix,tabNum,goToLink) 
  {  var myLI=linkObj.parentNode;
    while (myLI.tagName!="LI") {myLI=myLI.parentNode;}
    if(myLI.className=="active" && typeof goToLink != "undefined") return goToLink;

    var myUL=myLI.parentNode;
    var tabs=myUL.getElementsByTagName("li");
    for(var i=0;i<tabs.length;i++) {
    tabs[i].className="";
    nrg.$(tabsPrefix+(i+1)).style.display="none";
  }

  tabs[tabNum-1].className="active";
  nrg.$(tabsPrefix+tabNum).style.display="block";
  return false;
  }
};



function newClass(parent, prop) {
  // Dynamically create class constructor.
  var clazz = function() {
    // Stupid JS need exactly one "operator new" calling for parent
    // constructor just after class definition.
    if (clazz.preparing) return delete(clazz.preparing);
    // Call custom constructor.
    if (clazz.constr) {
      this.constructor = clazz; // we need it!
      clazz.constr.apply(this, arguments);
    }
  }
  clazz.prototype = {}; // no prototype by default
  if (parent) {
    parent.preparing = true;
    clazz.prototype = new parent;
    clazz.prototype.constructor = parent;
    clazz.constr = parent; // BY DEFAULT - parent constructor
  }
  if (prop) {
    var cname = "construct";
    for (var k in prop) {
      if (k != cname) clazz.prototype[k] = prop[k];
    }
    if (prop[cname] && prop[cname] != Object)
      clazz.constr = prop[cname];
  }
  return clazz;
}

/* clock with running seconds eitan 04.10.09 */

var diff_clock_time=null;

function doClock(firsttime) {

	var clock=new Date();

	if (firsttime==true)
	{  	var real_time = nrg.jsonAjax ('/cache/banners/gettime.php' , null, undefined ,undefined, true);
   		var real_clock=new Date();
   		real_clock.setHours(real_time[0]);
   		real_clock.setMinutes(real_time[1]);
   		real_clock.setSeconds(real_time[2]);
   		diff_clock_time = clock*1-real_clock*1;
   		//alert(diff_clock_time );
   
   		if (nrg.$('heb_date') 	)nrg.$('heb_date').innerHTML		= '&middot; '+real_time['heb_date']+',';
   		if (nrg.$('foreign_date')) nrg.$('foreign_date').innerHTML	= real_time['foreign_date'];
   
   
 	}

 	// Update difference between server time and client time
 	clock.setTime(clock*1-diff_clock_time*1);

 	var hours=clock.getHours();
 	var minutes=clock.getMinutes();
 	var seconds=clock.getSeconds();

 	if (hours<10)   hours="0" + hours;
 	if (minutes<10) minutes="0" + minutes;
 	if (seconds<10) seconds="0" + seconds;

 	if (diff_clock_time!=null) nrg.$("time").innerHTML = hours+":"+minutes+":"+seconds;
 	setTimeout('doClock()',500);
}

//nrg.onBodyLoad(function(){doClock(true)});

function setTraklinCount()
{
	var vars ="board_num=1175&URL=#traklinBottom";
	var options={'method':'post','debug':0}
	nrg.jsonAjax('http://www.nrg.co.il/luach_nrg/owa/count_hit?', vars, undefined, options, false);

	smoothScroll('ban105');
}

function currentYPosition()
{
    // Firefox, Chrome, Opera, Safari
    if (self.pageYOffset) return self.pageYOffset;
    // Internet Explorer 6 - standards mode
    if (document.documentElement && document.documentElement.scrollTop)
        return document.documentElement.scrollTop;
    // Internet Explorer 6, 7 and 8
    if (document.body.scrollTop) return document.body.scrollTop;
    return 0;
}


function elmYPosition(eID)
{
    var elm = document.getElementById(eID);
    var y = elm.offsetTop;
    var node = elm;
    while (node.offsetParent && node.offsetParent != document.body) {
        node = node.offsetParent;
        y += node.offsetTop;
    } return y;
}


function smoothScroll(eID)
{
    var startY = currentYPosition();
    var stopY = elmYPosition(eID);
    var distance = stopY > startY ? stopY - startY : startY - stopY;
    if (distance < 100) {
        scrollTo(0, stopY);
        return;
    }
    var speed = Math.round(distance / 100);
    var step = Math.round(distance / 45);
    var leapY = stopY > startY ? startY + step : startY - step;
    var timer = 0;
    if (stopY > startY) {
        for ( var i=startY; i<stopY; i+=step ) {
            setTimeout("window.scrollTo(0, "+leapY+")", timer * speed);
            leapY += step; if (leapY > stopY) leapY = stopY; timer++;
        } return;
    }
    for ( var i=startY; i>stopY; i-=step ) {
        setTimeout("window.scrollTo(0, "+leapY+")", timer * speed);
        leapY -= step; if (leapY < stopY) leapY = stopY; timer++;
    }
}


/* a fix function for the mondial - live page */
function fix_height_mondial_live()
{
    var h = nrg.$('contentWindow-1').scrollHeight;
    h = h + 33;
    nrg.$('contentWindow-1').style.height = h + 'px';
}
if(nrg.$('contentWindow-1')) {
    if(nrg.is_ie) {
        window.onload = fix_height_mondial_live;
    }
}

/*{/literal}*/
