var cat = new Array();
function initPage()
{
	//constructCategs('cont_cat');
	initLightbox();
}

function constructCategs(id)
{
  cat = new Array()	;
	y = document.getElementById(id).childNodes;
	for (i=0;i<y.length;i++)
	 	if (y[i].tagName=="DIV") 
	   		if (y[i].id.substr(0,9)=='cont_cat_')
	   		{	
				cat.push(y[i].id);
			}
	return cat;	
}

function change_categ(id)
{
	for (i=0;i<cat.length;i++)
	  {
		y = document.getElementById(cat[i]);
		if (y.id=='cont_'+id)
		 y.style.display = 'block';
		else 
		 y.style.display = 'none';
	  }
}



function show_hide_form(id, cond)

{

	x = document.getElementById(id);

	if (cond==true) x.style.display = 'block';

	else x.style.display = 'none';

}



function doLogin()
{
	loginForm = $('login_form');
	if (isEmpty(loginForm.username.value))
		  {  
		    loginForm.username.focus();
			alert('Vezi \'Utilizator\'');
			return;
		  }
	if (isEmpty(loginForm.password.value))
		  {  
		    loginForm.password.focus();
			alert('Vezi \'Parola\'');
			return;
		  }
	loginForm.submit();
}

function doRegister()
{
	regForm = $('reg_form');
	    if (isEmpty(regForm.prenume.value))
		  {  
		    regForm.prenume.focus();
			alert('Vezi \'Preume\'');
			return;
		  }
	   if (isEmpty(regForm.nume.value))
		  {  
		    regForm.nume.focus();
			alert('Vezi \'Nume\'');
			return;
		  }
	   if (isEmpty(regForm.af_line1.value))
		  {  
		    regForm.af_line1.focus();
			alert('Vezi \'Adresa\'');
			return;
		  }
	  if (isEmpty(regForm.af_oras.value))
		  {  
		    regForm.af_oras.focus();
			alert('Vezi \'Oras\'');
			return;
		  }
		  
	  if ($('adr_liv').checked)
	   {
		   		if (isEmpty(regForm.al_line1.value))
				  {  
					regForm.al_line1.focus();
					alert('Vezi \'Adresa livrare\'');
					return;
				  }
				if (isEmpty(regForm.al_oras.value))
				  {  
					regForm.al_oras.focus();
					alert('Vezi \'Oras\' livrare');
					return;
				  }
	   }

	   if (isEmpty(regForm.telefon.value))
		  {  
		    regForm.telefon.focus();
			alert('Vezi \'Telefon\'');
			return;
		  }
	  if (isEmpty(regForm.email.value) || !isEMailAddr(regForm.email))
		  {  
		    regForm.email.focus();
			alert('Vezi \'Email\'');
			return;
		  }

      if (isEmpty(regForm.username.value))
		  {  
		    regForm.username.focus();
			alert('Vezi \'Utilizator\'');
			return;
		  }
	  if (isEmpty(regForm.password1.value) || isEmpty(regForm.password2.value) || regForm.password1.value!=regForm.password2.value)
		  {  
		    regForm.password1.focus();
			alert('Vezi \'Parola\'');
			return;
		  }

	regForm.submit();
}

function doSendMail()
{
	sendMailForm = $('send_mail_form');
	
	if (isEmpty(sendMailForm.nume.value))
	{
		sendMailForm.nume.focus();
		alert('Vezi \'Nume\'!');
		return;
	}
	
	if (isEmpty(sendMailForm.email.value) || !isEMailAddr(sendMailForm.email))
	{
		sendMailForm.email.focus();
		alert('Vezi \'Email\'!');
		return;
	}
	
	if (isEmpty(sendMailForm.message.value))
	{
		sendMailForm.message.focus();
		alert('Mesaj gol!');
		return;
	}
	
	sendMailForm.submit();
	alert('Mesajul a fost trimis. Veti primi un raspuns la adresa de e-mail mentionata.');
}

function newpass()
{
	if(!isEMailAddr(document.np_form.email))
	{
		alert('Adresa email invalida!');
		document.np_form.email.focus();
		return
	}
document.np_form.submit();	
}

function isEmpty(value)
{
	value=value.replace(/\s/g,"");
	if(value=='') return true;
	return false;
}

function isEMailAddr(elem) {
    var str = elem.value;
    var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,14}$/;
    if (!str.match(re)) {
        return false;
    } else {
		return true;
    }
}
