// JavaScript Document

function handle_adocean_emission(b)
{
	if(b=='article')
	{
		if((window.innerWidth!=undefined && window.innerWidth<1370) || (document.documentElement.offsetWidth!=undefined && document.documentElement.offsetWidth<1370))
			Event.observe(window,'dom:loaded',function(){$('left_sigle').style.display = 'none';});
	}
	return false;
}
function handle_adocean_emission_empty(b)
{
	return false;
}


String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
    return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
    return this.replace(/\s+$/,"");
}
/* functie pentru pozitionarea submeniului*/
function position_submenu(a)
{
	margin_left = $('menu_'+a).offsetLeft;
	margin_left = margin_left - $('margined_submenu').offsetLeft;
	margin_left = margin_left - ($('margined_submenu').offsetWidth)/2;
	margin_left = margin_left - ($('menu_'+a).offsetWidth)/2;
	margin_left = parseInt(margin_left);
	if(margin_left>0 && margin_left<(960-parseInt($('margined_submenu').offsetWidth)))
	{
		$('margined_submenu').style.paddingLeft = margin_left+30+'px';
	}
	else if (margin_left>(960-parseInt($('margined_submenu').offsetWidth)))
	{
		$('margined_submenu').style.styleFloat = 'right';
	}
}
/* functie care face scroll la imagini */
/* autor Tudor */
var sto;
function scroll_pics(a,no,img_src)
{
	div_pics = $('chenar_scroll_'+no);
	if(a==0) return;
	else if(a<0)
	{
		$('sf_next').src = "/images/"+img_src+"nav_r_act.png";		
		if(div_pics.scrollLeft<=0) {
			$('sf_next').src = "/images/"+img_src+"nav_r_act.png";
			$('sf_prev').src = "/images/"+img_src+"nav_l.png";			
			return;
		}
	}
	else if(a>0)
	{
		$('sf_prev').src = "/images/"+img_src+"nav_l_act.png";
		if(div_pics.scrollLeft>=(div_pics.scrollWidth-310)) {
			$('sf_next').src = "/images/"+img_src+"nav_r.png";			
			return;
		}
	}
	div_pics.scrollLeft = div_pics.scrollLeft+a;
	sto=setTimeout('scroll_pics('+a+','+no+',"'+img_src+'")',30);
}

function stop_scroll_pics()
{
	clearTimeout(sto);
}

function open_window(url,width,height)
{
	xpoz=Math.round((screen.width-width)/2);
	ypoz=Math.round((screen.height-height)/2);
	if (xpoz<0) xpoz=10;
	if (ypoz<0) ypoz=10;
	newWindow=window.open (url ,'antena_window','toolbar=no,scrollbars=yes,width='+width+',height='+height+', left='+xpoz+', top='+ypoz);
	newWindow.focus();
	false;
}

/* alege-ti stirea*/
/* autor Tudor */
function alege_stirea(cat_id,articol_id){
	url = "/?section=articol&screen=ajax_alege_stirea";
	aj=new Ajax.Updater('alege_stirea_ajax',
						url, 
						{
							method:"post",
							parameters: {cat_id:cat_id,articol_id:articol_id},
							evalScripts: true
						}
					   );
}

/*
* DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
*/
function echeck(str) {
	//var alert_str='Adresa de email invalida';
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	  // alert(alert_str)
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   //alert(alert_str)
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		//alert(alert_str)
		return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
		//alert(alert_str)
		return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		//alert(alert_str)
		return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
		//alert(alert_str)
		return false
	 }
	
	 if (str.indexOf(" ")!=-1){
		//alert(alert_str)
		return false
	 }

	 return true					
}

/* verfica comentarii*/
/* autor Tudor */
function check_comentarii(){
    var err="";
   if (!$F("nume_com").trim() > " " || $F("nume_com").trim() == 'NUME') err += " - Numele dumneavoastra!\n";
	if (!$F("comentariu_articol").trim() > " " || $F("comentariu_articol").trim() == 'MESAJ') err += " - Comentariul dumneavoastra!\n";
    if (($F("email_com") > " ") && (echeck($('email_com').value)==false)) err += " - Email-ul dumneavoastra!\n";	
	if (err >" "){
        alert("Urmatoarele campuri nu sunt completate corect: \n"+err);
        return false;
    } else{
		$('date_valide').value="1";	
	}	
    return true;
}

function quote(id){
	$('object_parinte').value = id;
	new Effect.ScrollTo('add_comentariu');
}

var vote_semafor = 0;
var cur_tip=0;
function vote_object_when_comment(tip){
	if(cur_tip!=tip) vote_semafor = 0;
	cur_tip = tip;	
	if(tip==1) {
		if(vote_semafor==0){
			$('vote_up').src = "/images/articol/vote_up_colored.jpg";
			$('vote_down').src = "/images/articol/vote_down.jpg";
			$('vot_object').value = "1";
			vote_semafor = 1;
		} else{
			$('vote_up').src = "/images/articol/vote_up.jpg";
			$('vot_object').value = "0";
			vote_semafor = 0;
		}
	}else if(tip==2) {
		if(vote_semafor==0){		
			$('vote_down').src = "/images/articol/vote_down_colored.jpg";
			$('vote_up').src = "/images/articol/vote_up.jpg";
			$('vot_object').value = "-1";
			vote_semafor = -1;
		} else{
			$('vote_down').src = "/images/articol/vote_down.jpg";
			$('vot_object').value = "0";
			vote_semafor = 0;
		}
	}
}

function comentarii_abuse(id)
{
	url = "/index.php?section=articol&screen=comentarii_abuse&id="+id;
	new Ajax.Request(url,{
					 onComplete: function(resp) {
											   alert(resp.responseText);
											   }
	});
}

/* functii pentru voting object*/
/* autor Tudor */
function show_full_stars(i,total,object_type,img1_name,img2_name){
	for(j=1;j<=i;j++)
	{
		$(object_type+"_"+j).src="/images/"+img1_name+".jpg";
	}
	for(j=i+1;j<=total;j++)
	{
		$(object_type+"_"+j).src="/images/"+img2_name+".jpg";
	}
}
function hide_full_stars(i,total,object_type,img1_name,img2_name)
{
	for(j=1;j<=i;j++)
	{
		$(object_type+"_"+j).src="/images/"+img2_name+".jpg";
	}
	for(j=i+1;j<=total;j++)
	{
		$(object_type+"_"+j).src="/images/"+img2_name+".jpg";
	}
}
function vote_object(object_id,object_type,nota){
	var url="/?section=voting&screen=index&object_id="+object_id+"&object_type="+object_type+"&nota="+nota;
	new Ajax.Request(
		url,
		{
		onCreate: function() {$('votare').update("<div style='width:100px; font-size:12px; font-weight:bold'>Se incarca ...</div>");},
		onSuccess: function(resp) {$('votare').update(resp.responseText);}
		}
	);				
}

/* functie pentru resize text*/
//alert($('sapou'));
var sapou_orig_font = 12;
var art_txt_orig_font = 12;
function mareste_font(font_size){
	if(font_size==2){
		$('art_text').style.fontSize = (art_txt_orig_font+10)+'px';	
		$('sapou').style.fontSize = (sapou_orig_font+10)+'px';
	} else{
		$('art_text').style.fontSize = art_txt_orig_font+'px';	
		$('sapou').style.fontSize = sapou_orig_font+'px';			
	}
	new Effect.ScrollTo('articol_top');
}



/* change clapeta */
function change_clapeta(curent,total,id)
{
	for(i=1;i<=total;i++)
	{
		if($(id+'_clp_'+i).className=="item item_first item_act" || $(id+'_clp_'+i).className=="item item_act") //for up and down
			curent_now = i;
		if(i==1)
			$(id+'_clp_'+i).className="item item_first";
		else
			$(id+'_clp_'+i).className="item";
		$(id+'_cnt_'+i).style.display="none";
	}
	if(curent=='up' && curent_now<total) curent = curent_now+1;
	else if(curent=='up' && curent_now==total) curent=total;
	else if(curent=='down' && curent_now>1) curent = curent_now-1;
	else if(curent=='down' && curent_now==1) curent = 1;
	if(curent==1)
		$(id+'_clp_'+curent).className="item item_first item_act";
	else
		$(id+'_clp_'+curent).className="item item_act";
	$(id+'_cnt_'+curent).style.display="";
}
var ChangeClapetaEv = Class.create();
ChangeClapetaEv.prototype = {
	initialize: function(total,id,curent,evt) {
		this.total = total;
		this.id = id;
		this.curent = curent;
		this.evt = evt;
		if(this.evt=='mouseover')
			this.create_mouseover();
		else if(this.evt=='click')
			this.create_click();
	},
	create_mouseover: function() {
		Event.observe($(this.id+'_clp_'+this.curent),'mouseover',function() {
			this.to = setTimeout('change_clapeta('+this.curent+','+this.total+',"'+this.id+'")',250);
		}.bind(this));
		Event.observe($(this.id+'_clp_'+this.curent),'mouseout',function() {
			clearTimeout(this.to);
		}.bind(this));
	},
	create_click: function() {
		Event.observe($(this.id+'_clp_'+this.curent),'click',function() {
			change_clapeta(this.curent,this.total,this.id);
			var a = 1;
		}.bind(this));
	}
}
function change_clapeta_ev(curent,total,id,evt)
{
	if(curent!=0) change_clapeta(curent,total,id);
	for(i=1;i<=total;i++)
	{
		new ChangeClapetaEv(total,id,i,evt);
	}
	if($(id+'_clp_down')) new ChangeClapetaEv(total,id,'down',evt);
	if($(id+'_clp_up')) new ChangeClapetaEv(total,id,'up',evt);
}

function reseteaza_preview() {
	document.cookie = "editie_preview='';expires=Thu, 01-Jan-1970 00:00:01 GMT";
	window.location='/';
}

/* deschide un popup centrat neresizeble*/
function print_article(url,width,height)
{
	xpoz=Math.round((screen.width-width)/2);
	ypoz=Math.round((screen.height-height)/2);
	if (xpoz<0) xpoz=10;
	if (ypoz<0) ypoz=10;
	newWindow=window.open (url ,'mywindow','toolbar=no, scrollbars=yes, resizable=no ,width='+width+',height='+height+', left='+xpoz+', top='+ypoz);
	newWindow.focus();
}
var MenuChange = Class.create();
MenuChange.prototype = {
	initialize: function(options)
	{
		this.options = options;
		this.old = 0;
		this.init();
		if(this.options.current>0)
		{
			this.current = this.options.current;
			this.go();
			}
	},
	init: function()
	{
		for(i=1;i<=this.options.total;i++)
		{
			if($(this.options.id+'_clp_'+i).className=='item act') this.current = i;
			Event.observe($(this.options.id+'_clp_'+i),'click',function(e){
				cur = e.target.parentNode.id.substr(1+e.target.parentNode.id.lastIndexOf('_'));
				this.old = this.current;
				this.current = cur;
				this.go();
			}.bind(this));
		}
	},
	redraw: function()
	{
		if(this.old>0)
			$(this.options.id+'_clp_'+this.old).className = 'item';
		$(this.options.id+'_clp_'+this.current).className = 'item act';
	},
	go: function()
	{
		this.redraw();
		if(this.options.mode=='inline')
		{
			if(this.old>0)
				$(this.options.id+'_cnt_'+this.old).style.display = 'none';
			$(this.options.id+'_cnt_'+this.current).style.display = '';
		}
		else if(this.options.mode=='ajax')
		{
			new Ajax.Updater(this.options.id+'_cnt',this.options.links[parseInt(this.current)-1], { method:'get',evalScripts: true});
		}
	}
}


/* slider move*/
//new SliderMove({id:'containers<?=$cid?>',maxMoves:<?=($i-2)?>,navLeft:'navLeft<?=$cid?>',navRight:'navRight<?=$cid?>',distanta:285,durata:0.5});

SliderMove = Class.create();
SliderMove.prototype = {
	initialize: function(options)
	{
		this.options = options;
	
		this.maxMoves = this.options.maxMoves;
		this.moves = 0;
		this.canMove = 1;
		this.id = this.options.id;
		
		if(!this.options.sb) this.options.sb = 0;
		this.sb = this.options.sb;
		
		this.navLeft = this.options.navLeft;
		this.navRight = this.options.navRight;
		
		this.distanta = this.options.distanta;
		this.durata = this.options.durata;
		
		if(!this.options.slide_frecv) this.options.slide_frecv = 0;
		this.slide_frecv = this.options.slide_frecv*1000;
		

		
		this.init();
		
	},
	init: function()
	{
		
		Event.observe(this.navLeft, 'click', function(){
													if(this.options.vertical==1) this.move("sus");
														else this.move("stanga");
													this.manualSlide();
													
													
											  }.bind(this));
		Event.observe(this.navRight, 'click', function(){
													if(this.options.vertical==1) this.move("jos");
														else this.move("dreapta");
													this.manualSlide();
													}.bind(this));
		
	
		this.autoSlide();
	
		
	},
	
	moveLeft: function()
	{
		if(this.moves >0){
			var directie = 0 + this.distanta; 
			this.moves --;
			new Effect.Move(this.id, {x:directie,y:0,duration:this.durata});
		}
			
		
	},
	
	moveRight: function()
	{
		if(this.moves < this.maxMoves){
			var directie = 0 - this.distanta; 
			this.moves ++;
			new Effect.Move(this.id, {x:directie,y:0,duration:this.durata});
		}
		else{
			if(this.sb==1) this.slideBack();
			
		}
		
		
	},
	
	
	moveUp: function()
	{
		
		if(this.moves >0){
			var directie = 0 + this.distanta; 
			this.moves --;
			new Effect.Move(this.id, {x:0,y:directie,duration:this.durata});
		}
		
	},
	
	moveDown: function()
	{//alert(1);
		if(this.moves < this.maxMoves){
			var directie = 0 - this.distanta; 
			this.moves ++;
			new Effect.Move(this.id, {x:0,y:directie,duration:this.durata});
		}
		
		
	},
	
	
	
	
	move: function(sens)
	{
		
		if(this.canMove == 1){
			this.canMove = 0;
			setTimeout(this.allowMove.bind(this),this.durata*1000+100);
			switch(sens)
			{
				case "stanga":
					this.moveLeft();
				break;
				
				case "dreapta":
					this.moveRight();
				break;
				
				case "sus":
					this.moveUp();
				break;
				
				case "jos":
					this.moveDown();
				break;
				
				default:
					if(this.options.vertical==1){this.moveDown();}
					else {this.moveRight();}
				break;
				
				
			}
			
			
		}
		
			
	},
	
	allowMove: function()
	{
		this.canMove=1;
	},
	
	slideBack: function()
	{
	
		if(this.moves >0)
			{
				var directie = 0 + this.distanta * this.maxMoves; 
				var dur = (this.durata * this.maxMoves)/2;
				this.moves =0;
				new Effect.Move(this.id, {x:directie,y:0,duration:dur});
			}	
	},
	
	
	
	
	autoSlide: function()
	{
		if(this.slide_frecv>0){
			this.interval =  setInterval(this.move.bind(this),this.slide_frecv);
		}
		
	},
	
	manualSlide: function()
	{
		if(this.interval) clearInterval(this.interval);
		
	}
	
	
	
}

//functii program TV
function PTVtv_do_move(nr){
	if (nr > 0) { PTVtv_q = PTVtv_q + 15; } else { PTVtv_q = PTVtv_q - 15; }
	if (PTVtv_q > 0) { PTVstop_tv_move_slide(); return; } 
	if (PTVtv_q < minLeft) { PTVstop_tv_move_slide(); return; }
	
	$('container_programe').style.marginLeft = PTVtv_q+'px';
	

	PTVtv_mv = setTimeout("PTVtv_do_move("+nr+")", 1);
	}

function PTVstop_tv_move_slide(){
	clearTimeout(PTVtv_mv);
}
function colorize(marcaj,clasa){
	var a = $$('div.emisiune');
	var o;
	var m = "alb-" + marcaj;
	var n = "galben-" + marcaj;
	for(el in a)
	{
		o = typeof($(a[el]));
		if(o === "object"){
			//alert(typeof($(a[el])));
			if($(a[el]).readAttribute('marcaj') == m){
			$(a[el]).removeClassName("alb");
			$(a[el]).addClassName(clasa);
			
			}
			
			else if($(a[el]).readAttribute('marcaj') == "alb-1" || $(a[el]).readAttribute('marcaj') == "alb-2" || $(a[el]).readAttribute('marcaj') == "alb-3" || $(a[el]).readAttribute('marcaj') == "alb-4" || $(a[el]).readAttribute('marcaj') == "alb-5" || $(a[el]).readAttribute('marcaj') == "alb-6"){
				
				$(a[el]).removeClassName("culori_stiri");
				$(a[el]).removeClassName("culori_filme");
				$(a[el]).removeClassName("culori_sport");
				$(a[el]).removeClassName("culori_seriale");
				$(a[el]).removeClassName("culori_talk");
				$(a[el]).removeClassName("culori_diver");
				$(a[el]).addClassName("alb");
			}
			
		}
		
		
	}
		
		
	for(el in a)
	{
		o = typeof($(a[el]));
		if(o === "object"){
			//alert(typeof($(a[el])));
			if($(a[el]).readAttribute('marcaj') == n ){
			$(a[el]).removeClassName("galben");
			$(a[el]).addClassName(clasa);
			
			}
			else if($(a[el]).readAttribute('marcaj') == "galben-1" || $(a[el]).readAttribute('marcaj') == "galben-2" || $(a[el]).readAttribute('marcaj') == "galben-3" || $(a[el]).readAttribute('marcaj') == "galben-4" || $(a[el]).readAttribute('marcaj') == "galben-5" || $(a[el]).readAttribute('marcaj') == "galben-6"){
				
				$(a[el]).removeClassName("culori_stiri");
				$(a[el]).removeClassName("culori_filme");
				$(a[el]).removeClassName("culori_sport");
				$(a[el]).removeClassName("culori_seriale");
				$(a[el]).removeClassName("culori_talk");
				$(a[el]).removeClassName("culori_diver");
				$(a[el]).addClassName("galben");
			}
			
		}
		
		
	}
	


}
	
function checkPatrat(el){
	$(el).show();
	if(el!="x_stiri") $("x_stiri").hide();
	if(el!="x_filme")$("x_filme").hide();
	if(el!="x_sport")$("x_sport").hide();
	if(el!="x_seriale")$("x_seriale").hide();
	if(el!="x_talk")$("x_talk").hide();
	if(el!="x_diver")$("x_diver").hide();

}

function changeVideos(page,cat_id){
	url = "/index.php?section=tv&screen=emisiune_videos&layout=ajax&cat_id="+cat_id+'&page='+page;
	new Ajax.Request(url,{
					 onComplete: function(resp){
											
											   $('thumbs_inner').innerHTML=resp.responseText;
											   }
});
}


/* functii showbiz homepage top*/
function decoloreazaCentrul(){
		for(var i=0;i<=a.length;i++){
			if($("con" + i) != null) $("con" + i).removeClassName("cactive");
			if($("img" + i) != null) $("img" + i).removeClassName("iactive");
		}
		
	}
	
function coloreazaCentrul(pozitie){
	decoloreazaCentrul();
	pozCentru = pozitie+1;
		
	if(pozCentru >= (a.length)) pozCentru = 0;
	else if(pozCentru <= 0) pozCentru = a.length-1;
	

	if($("con" + pozCentru) == null){
	//	alert(pozCentru)	;
		return;
	}
	else{
		$("con" + pozCentru).addClassName("cactive");
		$("img" + pozCentru).addClassName("iactive");
		
		
		hideImages();
		$("app"+pozCentru).appear({ duration: 1 });
		
		$("titlu").hide();
		$("titlu").innerHTML = titluri_mari[pozCentru];
		$("titlu").appear({ duration: 0.4 });
		
		$("ora").hide();
		$("ora").innerHTML = ore[pozCentru];
		$("ora").appear();
		$("text_s").hide();
		$("text_s").innerHTML = texte[pozCentru];
		$("text_s").appear();
		
		$("subtitlu1").fade({ duration: 0.1 });
		$("subtitlu2").fade({ duration: 0.1 });
		
		setTimeout('subtitluri()',200);
		
	}
	
}
	
function subtitluri(){
	var act1;
	var act2;
	
	var sub1;
	var sub2;
	
	
	if(!titluri[pozCentru-1]){
		act2 = a.length-1;
		sub1 =titluri[a.length-1];
	}
	else{
		act2=pozCentru-1;
		sub1 = titluri[pozCentru-1]
	};
	
	if(!titluri[pozCentru+1]){
		sub2 = titluri[0]; act1 = 0;
	}
	else {
		sub2 = titluri[pozCentru+1];
		act1 = pozCentru +1
	};
	
	
	
	$("subtitlu1").innerHTML =sub1;
	$("subtitlu2").innerHTML = sub2;
	
	$("subtitlu1").appear({ duration: 0.3 });
	$("subtitlu2").appear({ duration: 0.3 });
	
	$('con'+act1).setAttribute('onclick','if(movedr) clearInterval(movedr);moveDreapta("images_list")');
	
	$('con'+act2).setAttribute('onclick','if(movedr) clearInterval(movedr);moveStanga("images_list")');
}
	
	
	
function moveDreapta(divToMove){
	pozitie ++;
	if(pozitie>= a.length)	pozitie = 0;
		
	var directie = 0 - speed;
	new Effect.Move((divToMove), {x:directie,y:0,duration:c_duration,mode: 'relative',  transition: Effect.Transitions.sinoidal,queue: { position: 'end', scope: 'menuxscope' }});
	
	adauga_dreapta(pozitie);
	coloreazaCentrul(pozitie);

}
	
function adauga_dreapta(pozitie){
	
	var extremitate_dreapta = pozitie + 2;
	
	if(extremitate_dreapta>=(a.length))		extremitate_dreapta -= (a.length);

	var newDiv = document.createElement('div');
	newDiv.setAttribute('id','con'+extremitate_dreapta);
	//newDiv.setAttribute('onclick','moveDreapta("images_list")');
	newDiv.className = 'icontainer';
	$('images_list').appendChild(newDiv);
	$('con'+extremitate_dreapta).innerHTML =  b[extremitate_dreapta];  //'<img id="img'+extremitate_dreapta+'" src="/images/tv/homepage/'+extremitate_dreapta+'.jpg" class="iimage" >';//=pozit;

	//sterg primul copil
	$('images_list').removeChild($('images_list').firstChild);

	//si acum sa creasca leftu
	var left = $('images_list').getStyle('margin-left').replace("px","");
	left = parseInt(left) + parseInt(speed) + "px";
	$('images_list').style.marginLeft = left;
	
}
	
function moveStanga(divToMove){
	
	pozitie --;
	if(pozitie<0) pozitie = a.length-1;
		
	adauga_stanga(pozitie);
	
	coloreazaCentrul(pozitie);
	
	//sterg ultima din  dreapta
	setTimeout("$('images_list').removeChild($('images_list').lastChild)",1000);
}
	
	
function adauga_stanga(pozitie){
	var pozit = pozitie-1;
	if(pozit<0)	pozit = a.length-1;
	
	var newDiv = document.createElement('div');
	newDiv.setAttribute('id','con'+pozit);
	//newDiv.setAttribute('onclick','moveStanga("images_list")');
	newDiv.className = 'icontainer';
	$('images_list').insertBefore(newDiv,$('images_list').firstChild);
	
	$('con'+pozit).setStyle({ width:'0px'});
	$('con'+pozit).innerHTML =  b[pozit];//'<img id="img'+pozit+'" src="/images/tv/homepage/'+pozit+'.jpg" class="iimage" >';//=pozit;

	new Effect.Scale('con'+pozit, 100, {  transition: Effect.Transitions.sinoidal, duration:c_duration, scaleFrom:0, scaleY:false,  scaleMode: { originalHeight: 70, originalWidth: 75 } });

	
}
	
	
function initCarusel(){
	stopMove();
	var html = "";
	var x ;
	for(var i = pozitie-1;i<=pozitie+2;i++){
		x = i;
		if(i<0) x = a.length+i;
		if(i>=a.length) x = 0; 
		//alert(a[x]);
		html += a[x]; 
	}
		 
	$("images_list").innerHTML = html;	
	
	moveStanga("images_list");
	coloreazaCentrul(a.length-1);
	
	
	
}
	
function MoveF(){
	canMove=1;	
}

function stopMove()
{
	canMove=0;
	setTimeout('MoveF()',500);	
}

function hideImages(){
	for(var i=0;i<a.length;i++){
		if($("app" + i) != null) $("app" + i).hide();
	}

}


/* homepage stiri principale*/
function spChangeContent(i){
	
	for(var j=1;j<=atasate;j++){
		if(j!=i){
			$('itemsp'+j).removeClassName('item_act');
		}
	}
	
	$('itemsp'+i).addClassName('item_act');
	
	$('titlusp').innerHTML = titlurisp[i];
	$('hrefsp').href = hrefmare[i];
	$('textsp').innerHTML = textesp[i];
	$('imgsp').style.background = 'url('+ imaginisp[i] +') 0 0 no-repeat';
	
	
}

/*curs valutar*/
function calcValuta(field_din, field_in, field_suma, field_suma2){
	var k = $(field_din).value;
	m = $(field_in).value;
	var s = $( field_suma2).value *valute[k]["valoare"] / valute[m]["valoare"];
	var s2 =  s.toFixed(4);
//	s2=s2.replace(".", ",")
	if(s2 == 'NaN') s2='';
	$(field_suma).value = s2;
}

/*caseta agenda*/
function changeItem(el){
	if(el == 'astazi'){
		$("zile").hide();
		$("astazi").show();	
		$("item1").addClassName("iactive");	
		$("item2").removeClassName("iactive");	
	}	
	if(el == 'zile'){
		$("astazi").hide();
		$("zile").show();	
		$("item2").addClassName("iactive");	
		$("item1").removeClassName("iactive");	
	}	
}
/*cele mai comentate*/
function changeContentCom(cat_id){
	
	var url = "/index.php?section=ajax&screen=cele_mai_comentate&layout=ajax&cat_id="+cat_id;
	new Ajax.Request(url,{
					 onComplete: function(transport) {
								   $('content87').innerHTML =transport.responseText;
								 
								   }
	});
}

/* cele mai citite*/
function changeContentCit(cat_id){
	var url = "/index.php?section=ajax&screen=cele_mai_citite&layout=ajax&cat_id="+cat_id;
	new Ajax.Request(url,{
					 onComplete: function(transport) {
								   $('content').innerHTML =transport.responseText;
								 
								   }
	});
}

/* deschidere sectiune*/
function changeInfo(poza,sageata_poz){
	if(atasate>=1)$("poza1").removeClassName("activ");
	if(atasate>=2)$("poza2").removeClassName("activ");
	if(atasate>=3)$("poza3").removeClassName("activ");
	if(atasate>=4)$("poza4").removeClassName("activ");
	if(atasate>=5)$("poza5").removeClassName("activ");
	
	if(atasate>=1)$("t1").removeClassName("tactiv");
	if(atasate>=2)$("t2").removeClassName("tactiv");
	if(atasate>=3)$("t3").removeClassName("tactiv");
	if(atasate>=4)$("t4").removeClassName("tactiv");
	if(atasate>=5)$("t5").removeClassName("tactiv");
	
	$("poza"+poza).addClassName("activ");
	$("t"+poza).addClassName("tactiv");
	
	$("sageata").style.marginLeft = sageata_poz + 'px';
	
	$("titlu").innerHTML = emisiuni[poza]["titlu"];
	$("poza_mare").innerHTML = emisiuni[poza]["poza_mare"];
	$("data").innerHTML = emisiuni[poza]["data"];
	$("descriere").innerHTML = decodeURIComponent(emisiuni[poza]["descriere"]).replace(/\+/g, ' ');
	$("more_text").href = emisiuni[poza]["href"];
	
	
}

function changep(){
	var a =poz;
	changeInfo(a,pozSag[a]);
	poz++;
	if(poz>atasate) poz = 1;
}
	
/* caseta acum la tv*/
function changeCanal(el,post_id,w){
	postSelectat = post_id;
	changeZi("zi"+w,w);
	$("post1").removeClassName('curent');
	$("post2").removeClassName('curent');
	$("post3").removeClassName('curent');
	$("post4").removeClassName('curent');
	$("post5").removeClassName('curent');
	
	$(el).addClassName('curent');
	
	
	new Ajax.Request('/index.php?section=ajax&screen=acum_la_tv&layout=ajax&post_id=' + post_id, 	
	{
		method:'get',
		onSuccess: function(transport){
				var d = transport.responseText;
				$('lista_emisiuni').innerHTML = d;
				

		}
	});

	
	
	
}
	
function changeZi(el,zi){
	$("zi1").removeClassName('curent');
	$("zi2").removeClassName('curent');
	$("zi3").removeClassName('curent');
	$("zi4").removeClassName('curent');
	$("zi5").removeClassName('curent');
	$("zi6").removeClassName('curent');
	$("zi7").removeClassName('curent');
	
	$(el).addClassName('curent');
	
	
	new Ajax.Request('/index.php?section=ajax&screen=acum_la_tv_recomandare&layout=ajax&post_id=' + postSelectat + '&zi=' + zi, 	
	{
		method:'get',
		onSuccess: function(transport){
				var d = transport.responseText;
				$('recomandare_text').innerHTML = d;

		}
	});
}

function form_mail()
{
	nume=document.getElementById('nume').value;
	email_to=document.getElementById('email_to').value;
	if ((email_to.length<5) || (email_to.search('@') == -1) || (email_to.search('.') == -1)) 
	{
		alert ("Email destinatar invalid");
		return false;
	}
	else if (nume.length==0) 
	{
		alert ("Introduceti numele");
		return false;
	}
	return true;
}

function aboneaza_newsletter(object_id, object_type){
	var a = echeck($('nl_input').value);

	if (a == true){
		//alert('mesaj trimis');
		new Ajax.Request('/index.php?section=articol&screen=newsletter',
		{
			method:'post',
			parameters: {mail: $F('nl_input')},
			onSuccess: function(transport)
			{
				if(transport.responseText==1){
					alert("V-ati abonat cu succes la newsletter!");
					$('abonare_newsletter').style.display='none';
				} else if(transport.responseText==2){
					alert("Aceasta adresa este deja abonata!");
				}
			}
		});
	}
	else
	{
		alert("Va rugam sa introduceti adrese de email valide!");
	}
}

function show_abonare(){
	Event.observe('icon_newsletter_form','mouseover',function(){
		$('abonare_newsletter').style.display='block';	
	});
}

function findPos(obj) {
	var curleft = curtop = 0;
	
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	
	return new Array(curleft,curtop);
}

function show_abonare_horoscop(el){
	/*var elPos = findPos(el);
	$('abonare_horoscop').style.top = elPos[0] + 'px';
	$('abonare_horoscop').style.left = elPos[1] + 'px';*/
	$('abonare_horoscop').style.display = "block";
}

function contains(node1, node2) 
{ 
	if(node2 == node1) { return true; } 
	if(node2 == null) { return false; } 
	else { return contains(node1, node2.parentNode); } 
}

//functie ce returneaza numarul caractere available la un moment la un comentariu
/* autor Tudor */
function comentariu_change()
{
	max_length = 1000;
	length_val = $('comentariu_articol').value.length;
	$('comentariu_status').value = max_length-length_val;
	if(length_val>max_length)
	{
		$('comentariu_articol').value = $('comentariu_articol').value.substr(0,max_length);
		$('comentariu_status').value = 0;
		$('comentariu_articol').scrollTop = $('comentariu_articol').scrollHeight;
	}
	if($('comentariu_status').value==0) $('comentariu_status').style.color = "#CA0002";
	else $('comentariu_status').style.color = "#777777";
}


//timp liber
function populateList(name,city_id)
{
	//alert(city_id);
	if(name.length>=3)
	{
		url = "/index.php?section=timp_liber&screen=lista_locatii&name="+name+"&city_id="+city_id;
		new Ajax.Request(url,{
						 onComplete: function(resp) {
												   $('lista_locatii').show();
												   $('lista_locatii').innerHTML = resp.responseText;
												   }
		});
	}

	
}

function populateListHP(name,city_id)
{
	//alert(city_id);
	if(name.length>=3)
	{
		url = "/index.php?section=timp_liber&screen=lista_locatii_hp&name="+name+"&city_id="+city_id;
		new Ajax.Request(url,{
						 onComplete: function(resp) {
												   $('lista_locatii').show();
												   $('lista_locatii').innerHTML = resp.responseText;
												   }
		});
	}

	
}


function changeText(text)
{
	if(text=='') $('cauta_locatia').value = '';
	if(text=='cauta locatia...' && $('cauta_locatia').value == '' ) $('cauta_locatia').value = text;
}
		

function strstr (haystack, needle, bool) {
    // Finds first occurrence of a string within another  
    // 
    // version: 1006.1915
    // discuss at: http://phpjs.org/functions/strstr    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Onno Marsman
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: strstr('Kevin van Zonneveld', 'van');
    // *     returns 1: 'van Zonneveld'    // *     example 2: strstr('Kevin van Zonneveld', 'van', true);
    // *     returns 2: 'Kevin '
    // *     example 3: strstr('name@example.com', '@');
    // *     returns 3: '@example.com'
    // *     example 4: strstr('name@example.com', '@', true);    // *     returns 4: 'name'
    var pos = 0;
    
    haystack += '';
    pos = haystack.indexOf( needle );    if (pos == -1) {
        return false;
    } else{
        if (bool){
            return haystack.substr( 0, pos );        } else{
            return haystack.slice( pos );
        }
    }
}



//google maps timp liber
function addMarker(address, title, icon,content,markersArray) {
//geocoder.geocode({ 'address': address}, function(results, status){
	//if (status == google.maps.GeocoderStatus.OK)
	//{
	  var	marker = new google.maps.Marker({
				position: address,//results[0].geometry.location,
				map: map,
				title:title,
				icon:icon
			});
		marker.setMap(null);
		
		
		google.maps.event.addListener(marker, 'click', function(){
			if (infowindow) infowindow.close();
			infowindow = new google.maps.InfoWindow({
				content: content
			});
			infowindow.open(map,marker);
		});
		markersArray.push(marker);
		return marker;
//	} 
//});
}


// Removes the overlays from the map, but keeps them in the array
function clearOverlays(markersArray) {
if (markersArray) {
for (i in markersArray) {
	if(typeof(markersArray[i]) == 'object'){
		markersArray[i].setMap(null);
	}
 
}
}
}

// Shows any overlays currently in the array
function showOverlays(markersArray) {
if (markersArray) {
for (i in markersArray) {
	if(typeof(markersArray[i]) == 'object'){
		markersArray[i].setMap(map);
	}
}
}
}

// Deletes all markers in the array by removing references to them
function deleteOverlays(markersArray) {
if (markersArray) {
for (i in markersArray) {
	if(typeof(markersArray[i]) == 'object'){
		markersArray[i].setMap(null);
	}
}
markersArray.length = 0;
}
}


function checkboxClicked(active, markersArray)
{
if(active == true) showOverlays(markersArray);
else clearOverlays(markersArray);

}

function checkBox(boxId,active)
{
if(active == true) $(boxId).checked = true;
else $(boxId).checked = false;

if(boxId != 'restaurante') 		$('restaurante').checked=false;
if(boxId != 'cinematografe') 	$('cinematografe').checked=false;
if(boxId != 'cluburi') 			$('cluburi').checked=false;
if(boxId != 'teatre') 			$('teatre').checked=false;
if(boxId != 'hoteluri') 		$('hoteluri').checked=false;
if(boxId != 'sport') 			$('sport').checked=false;
if(boxId != 'alte_locatii') 	$('alte_locatii').checked=false;


}

function moveToCity(city,zoom)
{
var city_name = cities[city];
geocoder.geocode({ 'address': city_name}, function(results, status){ 
	// map.panTo(new google.maps.LatLng(37.4569, -122.1569));
	var point = results[0].geometry.location;
	map.setCenter(point, zoom);
});	

}

function moveToArea(aid)
{

 map.panTo(new google.maps.LatLng(area_latitude[aid], area_longitude[aid]));
 if(aid == 0 ) map.setZoom(12);
 else map.setZoom(15);
}

//functii faze
function showRollover(n)
	{
		//Effect.Grow('rollover'+n);
		$('rollover'+n).style.display='block';
		
	}
		
	function hideRollover(n)
	{
		//Effect.Shrink('rollover'+n);
		$('rollover'+n).hide();
		
	}
	
	function setHeight() {
	
	 	var lk = ($('main_body').getDimensions());
		$('overlay').setStyle({   height:  lk['height']+'px'});  
		
		pageLoaded = 1;
	 
	}
	
	function insertIvmIntoId(guid,id,width,height) {
//        document.getElementById('playButton').style.display = 'none';
//        activeHighlights = 0;
 //       var elem = document.getElementById('homePlayer');
//        elem.innerHTML = '';
//        elem.style.display = 'block';
        var script = document.createElement('script');
        script.setAttribute("type","text/javascript");
        var src = 'http://ivm.inin.ro/js/embed.js?width='+width+'&height='+height+'&id='+guid + '&div_id='+id;
        script.setAttribute("src", src);
      //  document.getElementById('highlightsImage' + selectedHighlight).style.display = 'none';
        document.getElementsByTagName('head')[0].appendChild(script); 
	}

		
	function showFaza(id)
	{
		
		$('overlay').show();
		url = "/index.php?section=ajax&screen=faze&id="+id;
		//alert(url);
		aj=new Ajax.Updater('overlay',
						url, 
						{
							method:"get",
							parameters: {},
							evalScripts: true,
							onComplete:function(){  Position.CenterPage($('faze_popup')); }
						}
					   );
	
	}
//end functii faze



Position.getWindowSize = function(w) {
     var width, height;
     w = w ? w : window;
     width = w.innerWidth || (w.document.documentElement.clientWidth || w.document.body.clientWidth);
     height = w.innerHeight || (w.document.documentElement.clientHeight || w.document.body.clientHeight);
     
     return { width: width, height: height };
}
Position.Center = function(element, parent) {
        var w, h, pw, ph;
        var d = Element.getDimensions(element);
        w = d.width;
        h = d.height;
        Position.prepare();
        if (!parent) {
                var ws = Position.GetWindowSize();
                pw = ws[0];
                ph = ws[1];
        } else {
                pw = parent.offsetWidth;
                ph = parent.offsetHeight;
        }
        element.style.top = (ph/2) - (h/2) -  Position.deltaY + "px";
        element.style.left = (pw/2) - (w/2) -  Position.deltaX + "px";
}
Position.CenterPage = function(element) {
        var w, h, pw, ph;
        var d = Element.getDimensions(element);
        w = d.width;
        h = d.height;

          y = (window.innerHeight?window.innerHeight:(document.documentElement.clientHeight?document.documentElement.clientHeight:document.body.clientHeight))/2+(document.documentElement.scrollTop?document.documentElement.scrollTop:document.body.scrollTop);
          x = (window.innerWidth?window.innerWidth:(document.documentElement.clientWidth?document.documentElement.clientWidth:document.body.clientWidth))/2+(document.documentElement.scrollLeft?document.documentElement.scrollLeft:document.body.scrollLeft);
        element.style.top = y - (h/2) + "px";
        element.style.left = x - (w/2) + "px";
}


function show_more_news(articol_id,directie)
{

   if( ((inti<80 && directie<0) || (inti>0 && directie>0)) && canmove )
   {
	 
	   canmove=0;
	   url = "/?section=articol&screen=ajax_alege_stirea2";
	   limit +=10;
	
	   new Ajax.Request(url,{
				 method:"post",
				 parameters: {cat_id:cat_id,articol_id:articol_id,last_articol_id:last_articol_id,limit:limit,inti:inti},
				 onSuccess: function(transport)
				 {
					 
					  
					  
					
				},
				 onComplete: function(transport)
				 {
					 
					  if(directie<0){
						$('alege_stirea_ajax2').innerHTML +=transport.responseText;
						 inti++;
					  }
					  else{
						inti--;  
					  }
					  
					  if(inti > 0) $('sg_sus').src = '/images/sg_sus.png';
					  else  $('sg_sus').src = '/images/sg2_sus.png';
					  
					  if(inti < 80) $('sg_jos').src = '/images/sg_jos.png';
					  else  $('sg_jos').src = '/images/sg2_jos.png';
					 
					  new Effect.Move('alege_stirea_ajax2', {x:0,y:directie,duration:1, afterFinish: function() {canmove=1 }     });
					 
				}
	   
		});
	   
   }
   
}

function reset_news(cid,articol_id)
{
	
	//last_articol_id = <?=$lid?>;
	limit = 0;
	canmove=1;
	inti=0;
	cat_id  =cid;
	
	$('sg_sus').src = '/images/sg2_sus.png';
	$('alege_stirea_ajax2').style.top=0;
	$('sg_jos').src = '/images/sg_jos.png';
	
	 url = "/?section=articol&screen=ajax_alege_stirea2";
	 new Ajax.Request(url,{
				 method:"post",
				 parameters: {cat_id:cat_id,articol_id:articol_id,last_articol_id:last_articol_id,limit:limit,inti:inti},
				 onComplete: function(transport)
				 {
					 
					$('alege_stirea_ajax2').innerHTML =transport.responseText;
					
				}
	   
		});
	
	
	
}


function set_sigle()
{
	
	var viewport = document.viewport.getDimensions(); // Gets the viewport as an object literal
var width = viewport.width; // Usable window width
var height = viewport.height; // Usable window height
	if(height>800)
	{
		$('main_body').addClassName('high_rez');
	}
	else
	{
		$('main_body').removeClassName('high_rez');
	}	
}

