function formValidator(){
	// Make quick references to our fields
	var firstname = document.getElementById('nume');
	var username = document.getElementById('user');
	var email = document.getElementById('mail');
	var password = document.getElementById('parola');	
	var password2 = document.getElementById('parola2');	
	var termeni = document.getElementById('termeni');	
	
	// Check each input in the order that it appears in the form!
	if(isAlphanumeric(firstname, "Introduceti doar caractere in campul Nume")){
	if(lengthRestriction(firstname, 3, 25,"Numele trebuie sa contina intre ")){
	if(lengthRestriction(username, 3, 25,"Username-ul trebuie sa contina intre ")){
	if(emailValidator(email, "Introduceti o adresa de email valida")){
	if(lengthRestriction(password, 6, 12,"Parola trebuie sa contina intre ")){
	if(lengthRestriction(password2, 6, 12,"Parola trebuie sa contina intre ")){	
	if(BothFieldsIdenticalCaseSensitive()){
	if(madeSelection(termeni, "Puteti folosi acest site doar daca sunteti de acord cu termenii si conditiile site-ului"))
	{
											return true;
					}
				}
			}
		}
	}
	}
	}
	}
	return false;
	
}

function notEmpty(elem, helperMsg){
	if(elem.value.length == 0){
		alert(helperMsg);
		elem.focus(); // set the focus to this input
		return false;
	}
	return true;
}

function isNumeric(elem, helperMsg){
	var numericExpression = /^[0-9]+$/;
	if(elem.value.match(numericExpression)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function BothFieldsIdenticalCaseSensitive() {
			if((document.getElementById('parola').value!="")&&(document.getElementById('parola2').value!=""))			

			if(document.getElementById('parola').value==document.getElementById('parola2').value!=""){
			return true;
	}else{
		alert("Campurile parola trebuie sa fie identice");
		return false;
	}
}

function isAlphabet(elem, helperMsg){
	var alphaExp = /^[a-zA-Z]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isAlphanumeric(elem, helperMsg){
	var alphaExp = /^[0-9a-zA-Z .]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function lengthRestriction(elem, min, max, mesaj){
	var uInput = elem.value;
	if(uInput.length >= min && uInput.length <= max){
		return true;
	}else{
		alert(mesaj+min+ " si " +max+ " caractere");
		elem.focus();
		return false;
	}
}


function madeSelection(elem, helperMsg){

 if(!elem.checked){
		alert(helperMsg);
		elem.focus();
		return false;
	}else{
		return true;
	}
}

function emailValidator(elem, helperMsg){
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(elem.value.match(emailExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}
function formValidatorcomment(){
	// Make quick references to our fields
	var firstname = document.getElementById('nume');
	
	
	// Check each input in the order that it appears in the form!
	if(isAlphanumeric(firstname, "Introduceti doar caractere in campul Nume")){
											return true;
					}
	return false;
	
}