function isEmailAddr(str) {
   if (window.RegExp) {
     var reg1str = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
     var reg2str = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$";
     var reg1 = new RegExp(reg1str);
     var reg2 = new RegExp(reg2str);
     if (!reg1.test(str) && reg2.test(str)) {
      return true;
     }
     return false;
   } else {
     if(str.indexOf("@") >= 0) return true;
     return false;
   }
}
function deschide_contact()
{
	Modalbox.show('module/contact.php', {title: '', width: 700});	
}
//newsletter
function text_abonare(n, camp)
{
	if(document.getElementById("nume_news").value=='' && n=='2' && camp=='1')
	{
		document.getElementById("nume_news").value='Nume';
	}
	if(document.getElementById("nume_news").value=='Nume' && n=='1' && camp=='1')
	{
		document.getElementById("nume_news").value='';
	}	
	if(document.getElementById("email_news").value=='' && n=='2' && camp=='3')
	{
		document.getElementById("email_news").value='E-mail';
	}
	if(document.getElementById("email_news").value=='E-mail' && n=='1' && camp=='3')
	{
		document.getElementById("email_news").value='';
	}
}
function abonare_newsletter()
{
	if(!isEmailAddr(document.getElementById('email_news').value))
	{
		alert("Completati adresa de email");
		return false;
		exit();
	}
	Modalbox.show('module/newsletter_ab.php', {title: 'Abonare Newsletter Quadra 2', params:Form.serialize('abn'), width: 500}); return false;
}

function contact(a)
{
	if($('email').value=='')
	{
		document.forms['abn'].elements['email'].focus();
		alert("Introduceti adresa de email!");
		return false;
		exit();
	}
	if(!isEmailAddr($("email").value))
	{
		alert("Verificati adresa de email!");
		document.forms['abn'].elements['email'].focus();
		return false;
		exit();
	}
	if(a=='contact')
	{
		Modalbox.show('module/contact.php', {title: '', params:Form.serialize('abn'), width: 700 }); return false;	
	}
	if(a=='infoclub')
	{
		Modalbox.show('module/infoclub.php', {title: '', params:Form.serialize('abn'), width: 700 }); return false;	
	}
}

function ri_color()
{	
	cate=$('nr_retete').value;
	if(a==1)
	{
		$('reteta'+cate).style.backgroundColor="";
		$('reteta'+a).style.backgroundColor="#244a8f";
		$('text_color'+cate).style.color="";
		$('text_color'+a).style.color="#E3F0FC";
		$('sageata_poza'+cate).src='img/sageata_ri_2.jpg'
		$('sageata_poza'+a).src='img/sageata_ri_3.jpg'
	}
	else
	{
		b=a-1;
		$('reteta'+b).style.backgroundColor="";
		$('reteta'+a).style.backgroundColor="#244a8f";
		$('text_color'+b).style.color="";
		$('text_color'+a).style.color="#E3F0FC";
		$('sageata_poza'+b).src='img/sageata_ri_2.jpg'
		$('sageata_poza'+a).src='img/sageata_ri_3.jpg'
	}
	if(a<cate)
	{
		a++;	
	}
	else
	{
		a=1;
	}	
}
function coloreaza()
{
	a=1;
	aaa=setInterval("ri_color()", 2500);
	cate=$('nr_retete').value;
	for(dd=1;dd<=cate;dd++)
	{
		$('reteta'+dd).style.backgroundColor="";	
		$('text_color'+dd).style.color="";
		$('sageata_poza'+dd).src='img/sageata_ri_2.jpg'
	}
}
function decoloreaza(fff)
{
	clearTimeout(aaa);
	cate=$('nr_retete').value;
	for(dd=1;dd<=cate;dd++)
	{
		$('reteta'+dd).style.backgroundColor="";	
		$('text_color'+dd).style.color="";
		$('sageata_poza'+dd).src='img/sageata_ri_2.jpg'
	}
	$('reteta'+fff).style.backgroundColor="#244a8f";
	$('text_color'+fff).style.color="#E3F0FC";
	$('sageata_poza'+fff).src='img/sageata_ri_3.jpg'
}

function trimite_reteta()
{	
	cmp_txt=Array("ingrediente", "preparare");
	mesaj_txt=Array("Introduceti ingredientele retetei!", "Introduceti modul de preparare a retetei!");
	for(aa=0;aa<cmp_txt.length;aa++)
	{
		var inst = FCKeditorAPI.GetInstance(cmp_txt[aa]);
		var sValue = inst.GetHTML();
		if(sValue=='<br />')
		{
			alert(mesaj_txt[aa]);
			return false;
			exit();
		}
	}
	

	nume=Array("titlu", "portii", "timp", "nume", "prenume", "serieci", "nrci", "email", "telefon", "localitate");
	mesaje=Array("Introduceti titlul retetei!", "Introduceti numarul de portii!", "Introduceti timpul de preparare!", "Introduceti numele!", "Introduceti prenumele!", "Introduceti seria CI!", "Introduceti numar CI!", "Introduceti adresa de email!", "Introduceti numarul de telefon!", "Introduceti localitatea!");
	for(aa=0;aa<nume.length;aa++)
	{
		if(document.forms['frm'].elements[nume[aa]].value=='')
		{
			alert(mesaje[aa]);
			document.forms['frm'].elements[nume[aa]].focus();
			return false;
			exit();
		}
	}
	if(document.forms['frm'].elements['poza'].value=='')
	{
		alert("Selectati un fisier de tip jpg.");
		return false;
		exit();
	}
	if(!isEmailAddr($("email").value))
	{
		alert("Verificati adresa de email!");
		return false;
		exit();
	}
	if(document.getElementById('categorie').options[0].selected)
	{
		alert("Selectati categoria!");
		return false;
		exit();
	}
	if(document.getElementById('varsta').options[0].selected)
	{
		alert("Selectati varsta!");
		return false;
		exit();
	}
	if(document.getElementById('judet').options[0].selected)
	{
		alert("Selectati judetul!");
		return false;
		exit();
	}
	if($('termeni').checked)
	{
		aaaaaa=1;
	}
	else
	{		
		alert("Trebuie sa fiti de acord cu termenii si conditiile concursului!")
		return false;
		exit();
	}
}

function adauga()
{
	adresa=$('catre').value;	
	if(!isEmailAddr(adresa))
	{
		alert("Verificati adresa de email!");
		return false;
		exit();
	}
	$('adrese').value=$('adrese').value + adresa + '\r';
	$('adrese_inv').value=$('adrese_inv').value + adresa + '###';
	$('catre').value='';
}

function sterge()
{
	$('adrese').value='';
	$('adrese_inv').value='';
}

function recomanda(aaa)
{
	if(document.forms['frm'].elements['nume'].value=='')
	{
		alert('Completati numele!');
		document.forms['frm'].elements['nume'].focus();
		return false;
		exit();
	}
	if(document.forms['frm'].elements['prenume'].value=='')
	{
		alert('Completati prenumele!');
		document.forms['frm'].elements['prenume'].focus();
		return false;
		exit();
	}
	if(document.forms['frm'].elements['email'].value=='')
	{
		alert('Completati emailul!');
		document.forms['frm'].elements['email'].focus();
		return false;
		exit();
	}
	if(!isEmailAddr($("email").value))
	{
		alert("Verificati adresa de email!");
		document.forms['frm'].elements['email'].focus();
		return false;
		exit();
	}
	if(document.forms['frm'].elements['adrese'].value=='')
	{
		alert('Adaugati cel putin o adresa la care veti trimite mesajul de recomandare!');
		document.forms['frm'].elements['adrese'].focus();
		return false;
		exit();
	}
	if(aaa=="share")
	{
		Modalbox.show('module/share.php?aaa=1', {title: '', params:Form.serialize('frm'), width: 400 }); return false;
	}
}

function salt_in_pagina()
{
	location.href=$('nav_id').value+'~'+$('sari').value;	
}

function accept_form(a)
{
	if(a=='da')
	{
		$('accept_form').style.visibility='hidden';
		$('formular_ok').value='1';
	}
	if(a=='nu')
	{
		location.href='concurs';
	}
}

function chestionar()
{
	for(x=1;x<=10;x++)
	{
		a=0;
		for(var i = 0; i < document.forms['chest'].elements['intrebare'+x].length; i++) 
		{
			if(document.forms['chest'].elements['intrebare'+x][i].checked) 
			{
				a=1;
			}	
		}
		if(a==0)
		{
			alert('Selectati o varianta la intrebarea '+x);
			return false;
			exit();	
		}
	}
}
var pozitie_ani=0;
function muta_produse_slider(sens)
{
	var cate_thumbs_mut=document.getElementById('cate_thumbs_mut').value;
	if(sens=="stanga") 
	{ 
		document.getElementById('sageata_an_st').src='img/nou/stanga.jpg';
		if(pozitie_ani>(-(cate_thumbs_mut-5)))
		{
			$j("#container_thumbs_mutat").animate({ 
				marginLeft: "-=143px"
			}, 300 );
			pozitie_ani=pozitie_ani-1; 
		}
		if(pozitie_ani==(-(cate_thumbs_mut-5))) { document.getElementById('sageata_an_dr').src='img/nou/sageata_off.jpg'; }
	}	
	if(sens=="dreapta") 
	{ 
		document.getElementById('sageata_an_dr').src='img/nou/dreapta.jpg';
		if(pozitie_ani<0)
		{
			$j("#container_thumbs_mutat").animate({ 
				marginLeft: "+=143px"
			}, 300 );
			pozitie_ani=pozitie_ani+1; 
		}
		if(pozitie_ani==0) { document.getElementById('sageata_an_st').src='img/nou/sageata_off.jpg'; }
	}
	
}



function detect_dimensions()
{
	var site_width;
	var site_height;
	
	// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
	if (typeof window.innerWidth != 'undefined')
	{
		site_width = window.innerWidth,
		site_height = window.innerHeight
	}
	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
	else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth !='undefined' && document.documentElement.clientWidth != 0)
	{
		site_width = document.documentElement.clientWidth,
		site_height = document.documentElement.clientHeight
	}
	// older versions of IE
	else
	{
		site_width = document.getElementsByTagName('body')[0].clientWidth,
		site_height = document.getElementsByTagName('body')[0].clientHeight
	}
	document.getElementById('w').value=site_width;
	document.getElementById('h').value=site_height;
}
//////////////////////////////////////////////////////////////

detect_dimensions();
var site_width=document.getElementById('w').value;
var site_height=document.getElementById('h').value;
