function change_cl(id,cl)
{
 if(document.getElementById(id).className != 'b_men_ch')	
  document.getElementById(id).className = cl;	
}

function set_size(div_to,div_sz)
{
 document.getElementById(div_to).style.height=div_sz+'px';
}

function show_hide_elem(s_h,id)
{
 if(s_h)
  document.getElementById(id).style.display = 'block';
 else
  document.getElementById(id).style.display = 'none';
}

function trim(val)
{	
 return val.replace(/^\s*/, "").replace(/\s*$/, "");
}

function adm_act(act)
{
 alert_er="";
 if(act == 'ad' || act == 'mod')	
 {
  if(trim(document.getElementById('denumire').value) == "")
   alert_er = 'Introduceti o denumire pentru episod.\n';	 
	
  if(trim(document.getElementById('poza').value) == "")
   alert_er+= 'Introduceti o poza pentru episod.\n';
  
  if(trim(document.getElementById('fisier').value) == "")
   alert_er+= 'Introduceti calea filmului (completati campul: "fisier").';
 }	 
	 
 if((alert_er=="" && act!='del') || (act=='del' && confirm("Doriti sa stergeti episodul "+document.getElementById('denumire').value+" din seria "+document.getElementById('seria').value+" ?")))
 {	  
  document.getElementById('act').value = act;	 
  document.adm_form.submit();	 
 }
 else
  alert(alert_er);
}

var unit = 0;
var round = 0;

function contrl_round(i_d)
{
 if(i_d=='i')	
  round+=100;
 if(i_d=='d')	
  round-=100;
}

function contrl_cont(r_l,max_v)
{
 unit  = parseInt(unit);
 round = parseInt(round);
 
 if(round>max_v) round=max_v;	
 if(round<0) round=0;
 
 if(r_l=='l')
 {		 
  unit-=5;	
  document.getElementById('eps_itm_cont').style.left = "-"+unit+'px';
   if(unit>=round)
    setTimeout("contrl_cont('l','"+max_v+"')",25);
 }
 else
 {
  if(unit<=max_v)
  {
   unit+=5;	
   document.getElementById('eps_itm_cont').style.left = "-"+unit+'px'; 
   if(unit<=round)
    setTimeout("contrl_cont('r','"+max_v+"')",25);
  }
 }
}

function disable_file_but()
{
	var parx = window.parent.document;
	var div_poza=parx.getElementById("main_poze");
	nr=div_poza.getElementsByTagName('div').length;	
	//alert(nr);
		if(nr>3)
		{		
		 //alert("Nu puteti introduce mai multe poze.")
		 //if(document.getElementById('file'))	
		 document.getElementById('file').disabled = true;
		}				
}
var framex = 1;
function cancel_img()
{	
  if(confirm("Doriti sa stergeti poza deja incarcata?"))
  {  
  	while(window.frames[framex]!=null)
	{
	  ifr_picx = window.frames[framex];
	  ifr_picx.document.getElementById('file');
	  framex++;
	} 
	
	ifr_picx.document.getElementById('file').disabled = false;

	ifr_cont = document.getElementById('images_container');

	img_div = ifr_cont.getElementsByTagName('div')[1];
	
	img_div.parentNode.removeChild(img_div);
//    	try {
//             ifr_cont.removeChild(img_div);
//            } catch (e)
//            {
//             img_div.parentNode.removeChild(img_div);
//            } 
	
	
	
	document.getElementById('cancel_img').style.display='none';
	
	if(document.getElementById('for_show'))
	document.getElementById('for_show').style.display="block";
	
	//underbrowser('del_pic');
	
	if(document.getElementById('url_banner'))
	 document.getElementById('url_banner').value="URL";
	else
	if(document.getElementById('poza'))
	 document.getElementById('poza').value="";
	 
	 return true;
  }
  else
   return false;
}

function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
} 

function f_i_o(id, opacStart, opacEnd, millisec)
{
    var speed = Math.round(millisec / 100);
    var timer = 0;
    
    if(opacStart > opacEnd) 
    {
        for(i = opacStart; i >= opacEnd; i-=2) 
        {
         setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
         timer++;
        }
    } 
    else 
    if(opacStart < opacEnd) 
    {
        for(i = opacStart; i <= opacEnd; i+=2)
        {
         setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
         timer++;
        }
    }
}

function roll_change_pic(pic)
{
 document.getElementById('varza_roll').style.background = "no-repeat left url('images/"+pic+"')";	
}

function roll_up(x)
{
 r_pic = Math.floor((14-0)*Math.random()) + 1;
 
 f_i_o('varza_roll',100,0,400);
 setTimeout("roll_change_pic('poza"+r_pic+"_flip.jpg');",450);
 setTimeout("f_i_o('varza_roll',0,100,1500)",500);
  
 setTimeout("roll_up('10')", x*1000);
}

function send_varza()
{
 err="";	
 if(trim(document.getElementById('varza_msg').value)=="")
  err="Introduceti un mesaj.\n"; 	
 if(trim(document.getElementById('fcd').value)=="")
  err+="Introduceti codul de identificare. \n"; 
 if(trim(document.getElementById('nume_adr').value)=="")
  err+="Introduceti numele Dumneavoastra."; 

 
 if(err!="")
  alert(err);	 
 else
  document.varza_frm.submit();	 
}
