function switch_ton(total,current)
{
	for (i=1;i<=total;i++)
	{
		document.getElementById('commtt'+i).className="";
		document.getElementById('commtc'+i).style.display="none";
	}
	document.getElementById('commtt'+current).className="sel";
	document.getElementById('commtc'+current).style.display="";
	if (current==4)
	{
		if (document.getElementById('tfocus').style.visibility=='hidden')
			document.getElementById('tfocus').style.visibility='visible';
		document.getElementById('tfocus').focus();
	}
}

function display_tn(type,mode)
{
	new_tn_cur=eval(mode+"tn_cur");
	new_tn_total=eval(mode+"tn_total");
	mode=="s"?arr_left='images/arr_left_green.gif':arr_left='images/arr_left_red.gif';
	mode=="s"?arr_right='images/arr_right_green.gif':arr_right='images/arr_right_red.gif';	
	if (type==1)
	{
		document.getElementById(mode+'tnbut_1').onclick=new Function('return false;');
		if (new_tn_cur<new_tn_total)
		{
			opacity_(new_tn_cur, 100, 0, 200, 1, mode);
			new_tn_cur++;
			if (new_tn_cur==new_tn_total)
				document.getElementById(mode+'tnimg_1').src=img_path+'images/arr_right_red_d.gif';
			else
				document.getElementById(mode+'tnbut_1').onclick=new Function('display_tn(1,\''+mode+'\'); return false;');
			if (new_tn_cur>1)
			{
				document.getElementById(mode+'tnimg_2').src=img_path+arr_left;
				document.getElementById(mode+'tnbut_2').onclick=new Function('display_tn(2,\''+mode+'\'); return false;');
			}
		}
	}
	else if (type==2)
	{
		document.getElementById(mode+'tnbut_2').onclick=new Function('return false;');
		if (new_tn_cur>1)
		{
			opacity_(new_tn_cur, 100, 0, 200, 2, mode);
			new_tn_cur--;
			if (new_tn_cur==1)
				document.getElementById(mode+'tnimg_2').src=img_path+'images/arr_left_red_d.gif';
			else
				document.getElementById(mode+'tnbut_2').onclick=new Function('display_tn(2,\''+mode+'\'); return false;');
			if (new_tn_cur<new_tn_total)
			{
				document.getElementById(mode+'tnimg_1').src=img_path+arr_right;
				document.getElementById(mode+'tnbut_1').onclick=new Function('display_tn(1,\''+mode+'\'); return false;');
			}
		}
	}
	eval(mode+"tn_cur=new_tn_cur");
	eval(mode+"tn_total=new_tn_total");
}

function opacity_(id, opacStart, opacEnd, millisec, type, mode) {
    var speed = Math.round(millisec / 100);
    var timer = 0;

    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + "," + id + "," + type + ",'" + mode + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + "," + id + "," + type + ",'" + mode + "')",(timer * speed));
            timer++;
        }
    }
}

function changeOpac(opacity, id, type, mode) {
    var object = document.getElementById(mode+'tn'+id+'_').style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
    if (opacity==0 && type!=0)
    {
    	object.display='none';
    	if (type==1)
    	{
    		document.getElementById(mode+'tn'+(id+1)+'_').style.display='';
    		opacity_(id+1, 0, 100, 300, 0, mode);
    	}
    	else if (type==2)
    	{
    		document.getElementById(mode+'tn'+(id-1)+'_').style.display='';
    		opacity_(id-1, 0, 100, 300, 0, mode);
    	}
    }
}

function adauga_in_cos(produs,cantitate) 
{
	window.location=img_path+'cos.php?produs_id='+produs+'&cantitate='+cantitate+'&referer='+escape(window.location.href);
}

function check_srch_(id)
{
	if (id==1)
		if (!document.form_cauta.cauta.value || document.form_cauta.cauta.value=="Cauta in site")
		{
			alert("Nu poti face o cautare fara nici un cuvant cheie!");
			document.form_cauta.cauta.focus();
			return false;
		}
	if (id==2)
		if (!document.form_cauta2.cauta.value || document.form_cauta2.cauta.value=="Cauta in site")
		{
			alert("Nu poti face o cautare fara nici un cuvant cheie!");
			document.form_cauta2.cauta.focus();
			return false;
		}
	return true;
}

function toggle_cat(id)
{
	if (document.getElementById('toggl_img_'+id).src.indexOf('/arr_dn.gif')!=-1)
	{
		document.getElementById('toggl_img_'+id).src=img_path+"images/arr_up.gif";
		if (document.getElementById('toggl_'+id))
			document.getElementById('toggl_'+id).style.display="";
	}
	else
	{
		document.getElementById('toggl_img_'+id).src=img_path+"images/arr_dn.gif";
		if (document.getElementById('toggl_'+id))
			document.getElementById('toggl_'+id).style.display="none";
	}
}

function reseteaza_filtre(link)
{
	window.open(link,'_self');
 	return true;
}

function trimite_filtre(link)
{
	doc=document.criterii;
	add='';
	for (i=1;i<=6;i++)
		if (eval('doc.filtru_'+i))
			if (eval('doc.filtru_'+i+'.value!=0'))
				if (add)
					eval('add+="&filtru_'+i+'='+urlencode(eval('doc.filtru_'+i+'.value'))+'"');
				else
					eval('add+="?filtru_'+i+'='+urlencode(eval('doc.filtru_'+i+'.value'))+'"');
	window.open(link+add,'_self');
	return true;
}

function sterge_search()
{
	if (document.form_cauta)
		if (document.form_cauta.cauta.value=="Cauta in site")
			document.form_cauta.cauta.value="";
	if (document.form_cauta2)
		if (document.form_cauta2.cauta.value=="Cauta in site")
			document.form_cauta2.cauta.value="";
}

function erase_value()
{
	if (document.login.user_log.value=="Adresa email")
	{
		document.login.user_log.value="";
		document.login.password_log.value="";
	}
}

function verifica_trimite_opinie() 
{
	doc=document.form_add_comment;
 	if (doc.nume_opinie.value=='') 
 	{
 		alert('Numele este obligatoriu!');
 		doc.nume_opinie.focus();
 		return false;
 	}
 	if (doc.mail_opinie.value=='') 
 	{
 		alert('Emailul este obligatoriu!');
 		doc.mail_opinie.focus();
 		return false;
 	}
 	if (!isValidEmail(doc.mail_opinie.value)) 
 	{
 		alert('Adresa de email invalida!');
 		doc.mail_opinie.focus();
 		return false;
 	}
 	if (doc.comment_opinie.value.length<20) 
 	{
 		alert('Opinia ta trebuie sa aiba minim 20 caractere!');
 		doc.comment_opinie.focus();
 		return false;
 	}
  	return true;
}

function verifica_cere()
{
	doc=document.form_cere_detalii;
  	if (doc.numele_cer.value=="") 
  	{
  		alert('Numele tau este obligatoriu!');
  		doc.numele_cer.focus();
  		return false;
  	}
  	if (doc.emailul_cer.value=="")
  	{
  		alert('Emailul este obligatoriu!');
  		doc.emailul_cer.focus();
  		return false;
  	}
  	if (!isValidEmail(doc.emailul_cer.value)) 
  	{
  		alert('Emailul nu este valid!');
  		doc.emailul_cer.focus();
  		return false;
  	}
  	if (doc.mesaj_cer.value.length<1) 
  	{
 		alert('Te rugam sa scrii un mesaj!');
 		doc.mesaj_cer.focus();
 		return false;
 	}
  	return true;
}

function verifica_reg() 
{	
	doc=document.forms["reg_form"];
	if (doc["reg[username]"].value=="") 
	{
		alert('Nu ati introdus o adresa de email!');
		doc["reg[username]"].focus();
		return false;
	}
	if (!isValidEmail(doc["reg[username]"].value)) 
	{
		alert('Nu ati introdus o adresa valida de email!');
		doc["reg[username]"].focus();
		return false;
	}
	if (doc["reg[parola]"].value=="") 
	{
		alert('Nu ati introdus o parola!');
		doc["reg[parola]"].focus();
		return false;
	}
	if (doc["reg[parola]"].value.length<3) 
	{
		alert('Parola trebuie sa aiba minim 3 caractere!');
		doc["reg[parola]"].focus();
		return false;
	}
	if (doc["reg[parola_2]"].value=="") 
	{
		alert('Va rugam confirmati parola');
		doc["reg[parola_2]"].focus();
		return false;
	}
	if (doc["reg[parola]"].value!=doc["reg[parola_2]"].value) 
	{
		alert('Parola nu corespunde!');		
		return false;
	}
	if (doc["terms"].checked==false) 
	{
		alert('Trebuie sa fii de acord cu termenii si conditiile!');
		return false;
	}
	//doc["reg[parola]"].value=hex_md5(doc["reg[parola]"].value);
	return true;
}

function verifica_schimba_parola()
{
	if (document.getElementById('parola_pass_vechi').value=="") 
	{
		document.getElementById('parola_pass_vechi').focus();
		alert('Pentru a schimba parola trebuie sa o introduceti pe cea actuala!')
		return false;
	}
	if (document.getElementById('parola_pass_nou').value=="") 
	{
		document.getElementById('parola_pass_nou').focus();
		alert('Nu ati introdus o parola noua!');
		return false;
	}
	if (document.getElementById('parola_pass_nou').value.length<6) {
		document.getElementById('parola_pass_nou').focus();
		alert('Parola noua trebuie sa aiba minim 6 caractere!');
		return false;
	}
	if (document.getElementById('parola_pass_nou').value!=document.getElementById('parola_pass_nou_repet').value)
	{
		alert('Introduceti va rugam de doua ori parola noua!');
		return false;
	}
	return true;
}

function verifica_contact()
{
	if (document.getElementById('contact_nume').value=="") 
	{
		alert("Trebuie sa completati un nume!");
		document.getElementById('contact_nume').focus();
		return false;
	}
	if (document.getElementById('contact_email').value=="")
	{
		alert("Trebuie sa completati un email!");
		document.getElementById('contact_email').focus();
		return false;
	}
	if (!isValidEmail(document.getElementById('contact_email').value)) {
		alert("Nu ati completat o adresa de email valida!");
		document.getElementById('contact_email').focus();
		return false;
	}
	if (document.getElementById('contact_subiect').value=="") 
	{
		alert("Trebuie sa completati subiectul!");
		document.getElementById('contact_subiect').focus();
		return false;
	}
	if (document.getElementById('contact_mesaj').value=="")
	{
		alert("Mesajul nu poate fi gol!");
		document.getElementById('contact_mesaj').focus();
		return false;
	}
	if (document.getElementById('contact_mesaj').value.length<20) {
 		alert('Mesajul trebuie sa aiba minim 20 caractere!');
 		document.getElementById('contact_mesaj').focus();
 		return false;
 	}
	return true;
}

function check_login()
{
	if (document.login2)
 		var doc=document.login2;
 	else
 		var doc=document.login;
 	
 	if (doc.user_log.value=="")
 	{
		alert("Introduceti emailul!");
		doc.user_log.focus();
		return false;
	}
 		
	if (!isValidEmail(doc.user_log.value)) 
	{
		alert("Nu ati introdus un email valid!");
		doc.user_log.focus();
		return false;
	}
	if (doc.password_log.value=="")
	{
		alert("Introduceti parola!");
		doc.password_log.focus();
		return false;
	}
 		
  	//doc.password_log.value=hex_md5(doc.password_log.value);     
	doc.submit();
	return true;
}