/* FORM VALIDATION */
function isEmailReg(who) {
	var email=/^[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*@[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*\.([A-Za-z]){2,4}$/i;
	return(email.test(who));
}

function isNumericReg(who) {
	var numericExpression = /^[0-9]+$/;
	return(numericExpression.test(who));
}

function validateForm() {
	
	str = document.fcomanda.bucati.value;
	if(str.length == 0) {
		alert("Va rugam completati numarul de produse!");
		document.fcomanda.bucati.focus();
		return false;
	}
	
	str = document.fcomanda.bucati.value;
	if(str < 10) {
		alert("Comanda minima este de 10 cartele!");
		document.fcomanda.bucati.focus();
		return false;
	}
	
	str = document.fcomanda.nume.value;
	if(str.length == 0) {
		alert("Va rugam completati numele!");
		document.fcomanda.nume.focus();
		return false;
	}
	
	str = document.fcomanda.prenume.value;
	if(str.length == 0) {
		alert("Va rugam completati prenumele!");
		document.fcomanda.prenume.focus();
		return false;
	}
	
	str = document.fcomanda.telefon.value;
	if(str.length == 0) {
		alert("Va rugam completati numarul de telefon la care puteti fi contactat!");
		document.fcomanda.telefon.focus();
		return false;
	}	
	
	str = document.fcomanda.email.value;
	if(str.length == 0) {
		alert("Va rugam completati adresa de email!");
		document.fcomanda.email.focus();
		return false;
	}	
	
	
	str = document.fcomanda.email.value;
	if (!isEmailReg(str)) {
		alert("Va rugam folositi o adresa valida de e-mail!");
		document.fcomanda.email.focus();
		return false;
	}
	
	
	
	str = document.fcomanda.persoana.value;
	if(str == 0) {
		
		str = document.fcomanda.firma.value;
		if(str.length == 0) {
			alert("Va rugam completati numele firmei!");
			document.fcomanda.firma.focus();
			return false;
		}
		
		str = document.fcomanda.adresaf1.value;
		if(str.length == 0) {
			alert("Va rugam completati adresa de facturare!");
			document.fcomanda.adresaf1.focus();
			return false;
		}
		
		str = document.fcomanda.cui.value;
		if(str.length == 0) {
			alert("Va rugam completati Codul Unic de Inregistrare (CUI)!");
			document.fcomanda.cui.focus();
			return false;
		}
		
		str = document.fcomanda.regcom.value;
		if(str.length == 0) {
			alert("Va rugam completati Nr. de inregistrare la Reg. Com.!");
			document.fcomanda.regcom.focus();
			return false;
		}
		
		str = document.fcomanda.banca.value;
		if(str.length == 0) {
			alert("Va rugam completati numele bancii!");
			document.fcomanda.banca.focus();
			return false;
		}
		
		str = document.fcomanda.cont.value;
		if(str.length == 0) {
			alert("Va rugam completati contul!");
			document.fcomanda.cont.focus();
			return false;
		}
	}
	
	str = document.fcomanda.ci.value;
	if(str.length == 0) {
		alert("Va rugam completati seria si numarul cartii de identitate!");
		document.fcomanda.ci.focus();
		return false;
	}
	
	str = document.fcomanda.adresal1.value;
	if(str.length == 0) {
		alert("Va rugam completati adresa de livrare!");
		document.fcomanda.adresal1.focus();
		return false;
	}
				
	return true;
}