// JavaScript Document
/************************************************
*		Deschide o fereastra de dimensiuni     	*
*		width, height in centrul ecranului	   	*
*************************************************/
function get_style(el,styleProp)
{
	x = el;
	if (x.currentStyle)
	{
		var y = x.currentStyle[styleProp];
	}
	else if (window.getComputedStyle)
	{
		var y = window.getComputedStyle(x,null)[styleProp];
	}
	return y;
}
function open_url_center(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 ,'pozaWindow','toolbar=no,scrollbars=yes ,width='+width+',height='+height+', left='+xpoz+', top='+ypoz);
	newWindow.focus();
}	



var id_img=1;


var gizmo; 
function stopClock(){
  clearTimeout(gizmo);
}
 
function startClock(){
  var nd = new Date();
  var h, m;
  var s;
  var time = " ";
  h = nd.getHours();
  m = nd.getMinutes();
  s = nd.getSeconds();
  if (h <= 9) h = "0" + h;
  if (m <= 9) m = "0" + m;
  time += h + ":" + m;
  $('div_clock').innerHTML=time;
  gizmo = setTimeout("startClock()", 1000);
}


function chgind(idindice){
	if(document.getElementById('chart')) {
		document.getElementById('chart').src='panou.indpreview.chart.php?ind=' + idindice;
	}
	if(document.getElementById('chartlink')) {
		document.getElementById('chartlink').href='../indice_detalii.php?idindice=' + idindice;
	}
}


function deprecated_show_hide_banner(id)
{
	if (flag==1)
		document.getElementById(id).style.display='block';
	else
		document.getElementById(id).style.display='none';
}

function resize_banner(id, height)
{
          document.getElementById(id).style.height=height+'px';
}

function overflow_div(id, flag)
{
	if (flag==1)
		document.getElementById(id).style.overflow='hidden';
	else if (flag==0)
		document.getElementById(id).style.overflow='visible';	   
}

function show_content(curent,total,id_caseta)
{
	for(i=1;i<=total;i++)
	{
		if($("clapeta_"+i+"_"+id_caseta).className == "item" || $("clapeta_"+i+"_"+id_caseta).className == "item inside_act" || $("clapeta_"+i+"_"+id_caseta).className == "item act")
		{
			$("clapeta_"+i+"_"+id_caseta).className = "item";
		}
		else
		{
			if(i==1)
				$("clapeta_"+i+"_"+id_caseta).className = "item_spec";
			else
				$("clapeta_"+i+"_"+id_caseta).className = "item_spec spec_inside";
		}
		$("content_"+i+"_"+id_caseta).style.display = "none";
	}
	if(curent==1)
	{
		if($("clapeta_"+curent+"_"+id_caseta).className == "item")
			$("clapeta_"+curent+"_"+id_caseta).className = "item act";
		else 
			$("clapeta_"+curent+"_"+id_caseta).className = "item_spec act";
	}
	else
	{
		if($("clapeta_"+curent+"_"+id_caseta).className == "item_spec spec_inside")
			$("clapeta_"+curent+"_"+id_caseta).className = "item_spec inside_act spec_inside";
		else
			$("clapeta_"+curent+"_"+id_caseta).className = "item inside_act";
	}
	$("content_"+curent+"_"+id_caseta).style.display = "";
}

/* valideaza email */
/* autor Marius */
/*
function echeck(str)
{
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	//alert("Invalid E-mail ID")
		return false
	}
	
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	//alert("Invalid E-mail ID")
		return false
	}
	
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	//alert("Invalid E-mail ID")
		return false
	}
	
	if (str.indexOf(at,(lat+1))!=-1){
	//alert("Invalid E-mail ID")
		return false
	}
	
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	///alert("Invalid E-mail ID")
		return false
	}
	
	if (str.indexOf(dot,(lat+2))==-1){
	//alert("Invalid E-mail ID")
		return false
	}
	
	if (str.indexOf(" ")!=-1){
	//alert("Invalid E-mail ID")
		return false
	}
	
	return true					
}
*/

/* trimite mail*/
/* autor Marius modificata Tudor */

function trimite_mail(object_id, object_type){
	var a = echeck($('exp').value);
	var b = echeck($('dest').value);
	var c = $('comentariu').value;
	
	if ((a == true) && (b == true))
	{
		//alert('mesaj trimis');
		new Ajax.Request('/index.php?section=mail&ajax=1&object_id='+object_id+'&object_type='+object_type,
		{
			method:'post',
			parameters: {expeditor: $('exp').value, destinatar: $('dest').value, comentariu: $('comentariu').value, url: $('link').value},
			onSuccess: function(transport)
			{
				alert("Mesajul a fost trimis");
				form_mail_hide();
				$('exp').value=$('dest').value=$('comentariu').value="";
			}
		});
	}
	else
	{
		alert("Va rugam sa introduceti adrese de email valide");
	}
}

function trimite_mail_1(object_id, object_type){
	var a = echeck($('exp_1').value);
	var b = echeck($('dest_1').value);
	var c = $('comentariu_1').value;
	
	if ((a == true) && (b == true))
	{
		//alert('mesaj trimis');
		new Ajax.Request('/index.php?section=mail&ajax=1&object_id='+object_id+'&object_type='+object_type,
		{
			method:'post',
			parameters: {expeditor: $('exp_1').value, destinatar: $('dest_1').value, comentariu: $('comentariu_1').value, url: $('link_1').value},
			onSuccess: function(transport)
			{
				alert("Mesajul a fost trimis");
				//form_mail_hide();
				$('trimite_mail_').hide();
				$('exp_1').value=$('dest_1').value=$('comentariu_1').value="";
			}
		});
	}
	else
	{
		alert("Va rugam sa introduceti adrese de email valide");
	}
}

function form_mail_show(){
	$('trimite_mail').show();
	//Effect.BlindDown('trimite_mail');
}

function form_mail_hide()
{
	$('trimite_mail').hide();
	//Effect.BlindUp('trimite_mail');
}

/* functii pt section cautare si articol*/
/* autor Tudor */

/* functie folosita pentru submit la paginatie */
function proxy_form_submit(page){
	$('page').value=page;
	$('proxyForm').submit();
}

/* functie folosita pentru curatat caractere din autocomplete */
function curata_2_spec(cnt_input){
	return cnt_input;
	//alert("Curata");
	var chars = new Array();

	chars["["] = "s";
	chars["{"] = "&#0258;";
	chars["]"] = "&#0238;";
	chars["}"] = "&#0206;";
	chars["="] = "&#0226;";
	chars["+"] = "&#0194;";
	//chars['\\'] = "";
	chars["&#259"] = "&#0259;";
	chars["&#258"] = "&#0258;";
	chars["&#238"] = "&#0238;";
	chars["&#206"] = "&#0206;";
	chars["&#226"] = "&#0226;";
	chars["&#194"] = "&#0194;";
	chars["&#351"] = "&#0351;";
	chars["&#350"] = "&#0350;";
	chars["&#355"] = "&#0355;";
	chars["&#354"] = "&#0354;";
	var cnt_fin = "";
	var chr = "";
	var cnt = cnt_input;//$("continut").value;
	for(var i=0;i<cnt.length;i++)
	{
		chr = cnt.substring(i, i+1);
		//alert(chr.charCodeAt(0));
		if(chars[("&#"+chr.charCodeAt(0))]!=undefined) cnt_fin += chars["&#"+chr.charCodeAt(0)];
		else cnt_fin += chr;
	}
	
	return cnt_fin;
}

/* functie folosita pentru incarcat autocomplete */
function loaddata_search() 
{
	if($("inp_autor").value.length<3)
	{
		$("inp_autor_div").style.display="none";
		return false;
	}
	url = "/?section=cautare&screen=autor_sugest&ajax=1&text=" + escape(curata_2_spec($("inp_autor").value));
	aj = new Ajax.Request(url, {onSuccess:ajax_search});
}
/* functie folosita pentru incarcat autocomplete */
function ajax_search(ob) 
{
	resp = ob.responseText;
	if (resp != "")
	{
		$("inp_autor_div").style.display = "";
	}
	else
	{
		$("inp_autor_div").style.display = "none";
	}
	$("inp_autor_div").innerHTML = resp;
}

function search_over_td(a)
{
	$("search_td"+a).style.backgroundColor="#eef7fe";
}
function search_out_td(a)
{
	$("search_td"+a).style.backgroundColor="#e9ecee";
}

function search_click_td(a,b)
{
	//search_add(b,a);
	$("inp_autor").value=a;
	$("autor_id").value=b;
	//alert($('autor_id').value);
	$("inp_autor_div").style.display="none";
}

/* functie care seteaza parintele pentru un comentariu */
/* autor Tudor */
function raspunde_comentariu(parinte){
	$('object_parinte').value=parinte;
}

/* functie care seteaza anul din cautare automat */
/* autor Tudor */
function seteaza_an(id, an){
	//alert($(id).options[$(id).selectedIndex].value);
	if($F(id)!=0);
	else {
		for(i=0;i<$(id).options.length;i++)
		{
			if($(id).options[i].value==an) $(id).options[i].selected=true;
		}		
	}
}

/* functie care face scroll la imagini */
/* autor Tudor */
var sto;
function scroll_pics(a,no)
{
	div_pics = $('scroll_box_'+no);
	if(a==0) return;
	else if(a<0)
	{
		if(div_pics.scrollLeft<=0) return;
	}
	else if(a>0)
	{
		if(div_pics.scrollLeft>=div_pics.scrollWidth) return;
	}
	div_pics.scrollLeft = div_pics.scrollLeft+a;
	sto=setTimeout('scroll_pics('+a+','+no+')',30);
}
function stop_scroll_pics()
{
	clearTimeout(sto);
}

/* functii pentru voting object*/
/* autor Tudor */

function show_full_stars(i,total,object_type,img1_name,img2_name)
{
	for(j=1;j<=i;j++)
	{
		curent="left";
		if(j%2==0) curent="right";
		$(object_type+"_"+j).src="/images/"+img1_name+"_"+curent+".gif";
	}
	for(j=i+1;j<=total;j++)
	{
		curent="left";
		if(j%2==0) curent="right";
		$(object_type+"_"+j).src="/images/"+img2_name+"_"+curent+".gif";
	}
}
function hide_full_stars(total,object_type,img2_name)
{
	for(j=1;j<=total;j++)
	{
		curent="left";
		if(j%2==0) curent="right";
		$(object_type+"_"+j).src="/images/"+img2_name+"_"+curent+".gif";
	}
}
function vote_object(object_id,object_type,nota){
	var url="/?section=voting&screen=index&ajax=1&object_id="+object_id+"&object_type="+object_type+"&nota="+nota;
	new Ajax.Request(
		url,
		{
		onLoading: function() {$('votare').update("<div style='width:320px'>Se incarca ...</div>");},
		onSuccess: function(resp) {$('votare').update(resp.responseText);}
		}
	);				
}
function vote_object_imagine(object_id,object_type,nota){
	var url="/?section=voting&screen=index&ajax=1&object_id="+object_id+"&object_type="+object_type+"&nota="+nota;
	new Ajax.Request(
		url,
		{
		onLoading: function() {$('votare_'+object_id).update("Se incarca ...");},
		onSuccess: function(resp) {$('votare_'+object_id).update(resp.responseText);}
		}
	);				
}

/* functie pentru schimbare font articol*/
/* autor Tudor */

var original_font = '';
function change_article_font(){
	var size = parseInt($('art_text').style.fontSize.replace("px",""));
	if(original_font=='') original_font = size;
	if(size==original_font) size = 20;
	else size = original_font;
	$('art_text').style.fontSize=size+"px";	
}

/* functie care schimba fisierul video principal in articol cu video atasat */
/* autor Tudor */

function change_main_video(articol_id){
	new Ajax.Updater('active_video','/index.php?section=ajax&screen=video_in_articol&ajax=1&articol_id='+articol_id,{evalScripts:true,method:"get"});
	for(i=0;i<video_atasate.length;i++) $('small_video_'+video_atasate[i]).style.display = "block";
	$('small_video_'+articol_id).style.display = "none";
}

/* Functiile casetei cu tab-uri foto-video-infografice, autor Dan*/
var old_id=0;

function ch_foto_video(tab)
{
	$('video').className='item';
	$('foto').className='item';
	//$('infografice').className='item';
	$(tab).className='item act';
	
	$('cont_video').className='video_section nodsplay';
	$('cont_foto').className='video_section nodsplay';
	//$('cont_infografice').className='video_section nodsplay';
	$('cont_'+tab).className='video_section';
}

function change_video(id,caseta)
{
	$('video_item_'+id).className='item hidden_tag';
	$('video_item_'+old_id).className='item';
	old_id=id;
	
	new Ajax.Updater('player_'+caseta,'/index.php?section=ajax&screen=caseta_video_flash&id='+id+'&caseta='+caseta,{evalScripts:true,method:"get"});
	
}
/************************Sfarsit functiile casetei cu tab-uri foto-video-infografice ******************************/

/* functie pentru calendar*/
/* autor Marius */

function calendar(anul, luna_din_an, ziua)
{
	new Ajax.Updater('calendar_container', 'index.php?section=calendar&ajax=1',
	{
		method:'get',
		parameters: {data_calendar: anul+'-'+luna_din_an+'-'+ziua},
		onSuccess: function() { $('calendar_container').innerHTML = response; }
	});
}
/************* fictii pentru add/remove NL ************/

/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

function echeck(str) {
		//var alert_str='Adresa de email invalidă';
		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					
	}


function verifica_email()
{
	var email=$('email').value;
	if (email=='') {
		alert ('Va rugam introduceti o adresa de email');
		return false
	}
	return echeck(email);
}
function comentariu_change(my_ta) {
	max_length = 1000;
	length_val = my_ta.value.length;
	//$("comentariu_status").value = max_length - length_val;
	if (length_val > max_length) {
		my_ta.value = my_ta.value.substr(0, max_length);
		//$("comentariu_status").value = 0;
		my_ta.scrollTop = my_ta.scrollHeight;
	}
	/*if ($("comentariu_status").value == 0) {
		$("comentariu_status").style.color = "red";
	} else {
		$("comentariu_status").style.color = "green";
	}*/
}


function check_lalert(){
    var err="";
    if (!$F("suport_nume") > " ") err += " - Numele dumneavoastra!\n";
	if (!$F("suport_email") > " ") err += " - Email-ul\n";
    if (!$F("suport_so") > " ") err += " - Sistemul de operare\n";
    if (!$F("suport_oras") > " ") err += " - Orasul\n";
    if (!$F("suport_problema") > " ") err += " - Problema dumneavoastra!\n";
	if (err >" "){
        alert("Urmatoarele campuri nu sunt completate corect: \n"+err);
        return false;
    } else{
		$('date_valide').value="1";	
	}	
    return true;
}

function update_check()
{
	if (!$F('com_nume') > " " && !$F('com_subiect') > " " && !$F('com_text') > " ")
	{
		alert ('Nu ati completat toate campurile');
		return false;
	} else{
		$('date_valide').value="1";	
	}
	return true;
}

