// JavaScript Document
function emailvalid(checkThisEmail)//valideaza o adresa de email
{
	var myEMailIsValid = true;
	var myAtSymbolAt = checkThisEmail.indexOf('@');
	var myLastDotAt = checkThisEmail.lastIndexOf('.');
	var mySpaceAt = checkThisEmail.indexOf(' ');
	var myLength = checkThisEmail.length;
	if (myAtSymbolAt < 1 )
	{myEMailIsValid = false}
	if (myLastDotAt < myAtSymbolAt)
	{myEMailIsValid = false}
	if (myLength - myLastDotAt <= 2)
	{myEMailIsValid = false}
	if (mySpaceAt != -1)
	{myEMailIsValid = false}
	return myEMailIsValid;
}
function allTrim(sString)//elimina spatiile
{
	while (sString.substring(0,1) == ' ')
	{
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}
function Check_Contact(myform)//verifica daca formularul este completat
{
	nume = allTrim(myform.nume.value);
	email = (myform.email.value);
	mesaj = allTrim(myform.mesaj.value);
	
	if(mesaj == "")
		{
		alert("Introduceti un mesaj !");
		myform.mesaj.focus();		
		return false;
		}	
	if(nume == "")	
		{
		alert("Completati campul Nume !");
		myform.nume.focus();
		return false;
		}
	if(!emailvalid(email))
		{
		alert("Introduceti o adresa de email valida !");
		myform.email.focus();
		myform.email.select();
		return false;
		}		
	return true;
}
function Check_Order(myform)//verifica formularul de comanda
{
	nume = allTrim(myform.nume.value);
	prenume = allTrim(myform.prenume.value);
	strada = allTrim(myform.strada.value);
	localitate = allTrim(myform.localitate.value);
	email = myform.email.value;

	
	if(nume == "")
		{
		alert("Completati numele destinatarului !");
		myform.nume.focus();
		return false;
		}
	
	if(prenume == "")
		{
		alert("Completati prenumele destinatarului !");
		myform.prenume.focus();
		return false;
		}
	
		
	if(!emailvalid(email))
		{
		alert("Introduceti o adresa de email valida !");
		myform.email.focus();
		myform.email.select();
		return false;
		}
	if(localitate == "")
		{
		alert("Completati localitatea destinatarului !");
		myform.localitate.focus();
		return false;
		}
		
	
	if(strada == "" && eval(myform.expediere[0].checked==true))
		{
		alert("Completati strada destinatarului !");
		myform.strada.focus();
		return false;
		}
	return true;
}
function Check_Login(myform)
{
	email = allTrim(myform.email.value);
	parola = myform.parola.value;
	if(!emailvalid(email))
		{
		alert("Introduceti o adresa de email valida !");
		myform.email.focus();
		myform.email.select();
		return false;
		}
	if(parola == "")
		{
		alert("Introduceti parola !");
		myform.parola.focus();
		myform.parola.select();
		return false;
		}
	return true;
}
function PopUpImage(imagine,titlu)
{
	wnd = window.open('poza.php?poza='+imagine+'&titlu='+titlu+'','poza','width=0,height=0,toolbar=no,scrollbars=no,menubar=no,adressbar=no,statusbar=no');
}
