// functii de validare primare pt. campuri din formular

function eObligatoriu(numecamp,mesaj){
	valcamp = document.getElementById(numecamp).value ;
	if (valcamp.length < 1){
		alert(mesaj);
		try {
			document.getElementById(numecamp).focus();
		} catch(er) {
			
		}
		return false;
	}else{
		return true;
	}
}

function eObligatoriu2(numecamp1,numecamp2,mesaj){
	valcamp1 = document.getElementById(numecamp1).value;
	valcamp2 = document.getElementById(numecamp2).value;
	if ((valcamp1.length < 1) && (valcamp2.length < 1)){
		alert(mesaj);
		try {
			document.getElementById(numecamp1).focus();
		} catch(er) {
			
		}
		return false;
	}else{
		return true;
	}
}

function eSelectat(numecamp,mesaj){
	valcamp = document.getElementById(numecamp).value ;
	if (valcamp == "-1"){
		alert(mesaj);
		try {
			document.getElementById(numecamp).focus();
		} catch(er) {
			
		}
		return false;
	}else{
		return true;
	}
}

function validareAn(numecamp,mesaj){
	valcamp = document.getElementById(numecamp).value;
	if (isNaN(valcamp)){
		alert(mesaj);
		try {
			document.getElementById(numecamp).focus();
	} catch(er) {
		
	}
		return false;
	}else{
		return true;
	}
}

function validareInterventie (numecamp,length, mesaj) {
	var rezultat = false;
	for (var counter=1; counter<=length; counter++) {
		temp = numecamp + "_" + counter;
		inputs = document.getElementById(temp).checked;
		if (inputs == true) {
			rezultat = true;
			break;
		}
	}
	if (rezultat == false){
		alert (mesaj);
	}
	return rezultat;
}

function Email(numecamp,mesaj){
		valcamp = document.getElementById(numecamp).value;
		if ((valcamp.length > 0)&&((valcamp.length < 6) || (valcamp.indexOf("@") < 1) || (valcamp.indexOf(".") < 3))){
			alert(mesaj);
			try {
				document.getElementById(numecamp).focus();
			} catch(er) {
				
			}
			return false;
		}else{
	return true;
	}
}

function eParola(numecamp1,numecamp2){
	ecompletat = eObligatoriu(numecamp1, "Completati parola!");
	if (!ecompletat){
		return;
	}
	ecompletat = eObligatoriu(numecamp2, "Reintroduceti parola!");
	if (!ecompletat){
		return;
	}
	valcamp1 = document.getElementById(numecamp1).value;
	valcamp2 = document.getElementById(numecamp2).value;
	if (valcamp1 != valcamp2 ){
		alert("Parola reintrodusa nu este acceasi!");
		try {
			document.getElementById(numecamp2).focus();
		} catch(er) {
			
		}
		return false;
	}else{
		return true;
	}
}

var car_neutru = '!#$^&*()+|}{[]?><~%:;/,=`"\'';
function carNeutre(s) {   
	var i;
	var char="";
		for (i = 0; i < s.length; i++) {
			var c = s.charAt(i);
		if(i>0) lchar=s.charAt(i-1);
			if (car_neutru.indexOf(c) != -1 || (char=="." && c==".")) return false;
			}
		return true;
}


function eEmail(numecamp,mesaj){
	email = document.getElementById(numecamp).value;
	mailLength = email.length;
	dot = ".";
	at = "@";
	atPos = email.indexOf(at);
	stopPos = email.lastIndexOf(dot);
	if (email != "") {
		if (mailLength < 6) {
			alert(mesaj);
			try {
				document.getElementById(numecamp).focus();
			} catch(er) {
				
			}
			return false;
			}
		if ((atPos <= 0) || (stopPos == -1)) {
			alert(mesaj);
			try {
				document.getElementById(numecamp).focus();
			} catch(er) {
				
			}
			return false;
			}
		if (stopPos < atPos) {
			alert (mesaj);
			try {
				document.getElementById(numecamp).focus();
			} catch(er) {
				
			}
			return false;
			}
		if (stopPos - atPos == 1) {
			alert(mesaj);
			try {
				document.getElementById(numecamp).focus();
			} catch(er) {
				
			}
			return false;	
			}
		if (email.indexOf(at,(atPos+1)) != -1) {
			alert(mesaj);
			try {
				document.getElementById(numecamp).focus();
			} catch(er) {
				
			}
			return false;	
			}
		if (email.indexOf(" ") != -1) {
			alert(mesaj);
			try {
				document.getElementById(numecamp).focus();
			} catch(er) {
				
			}
			return false;	
			}
		if ( mailLength - stopPos < 3) {
			alert(mesaj);
			try {
				document.getElementById(numecamp).focus();
			} catch(er) {
				
			}
			return false;
			}
		if (carNeutre(email) == false) {
			alert(mesaj);
			try {
				document.getElementById(numecamp).focus();
			} catch(er) {
				
			}
			return false;
			}
		else {
			return true;
		}
	} else {
		return true;
	}
}