// functii de validare primare pt. campuri din formular

function eObligatoriu(numecamp,mesaj){
	valcamp = document.getElementById(numecamp).value ;
	if (valcamp.length < 1){
		document.getElementById(numecamp).focus();
		alert(mesaj);
		return false;
	}else{
		return true;
	}
}


function eSelectat(numecamp,mesaj){
	valcamp = document.getElementById(numecamp).value ;
	if (valcamp == "-1"){
		document.getElementById(numecamp).focus();
		alert(mesaj);
		return false;
	}else{
		return true;
	}
}

function validareTelefon(numecamp,mesaj1){
		valcamp = document.getElementById(numecamp).value;
		if (isNaN(valcamp)){
				document.getElementById(numecamp).focus();
				alert(mesaj2);
				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 == "") {
		alert(mesaj);
		document.getElementById(numecamp).focus();
		return false;
		}
	if (mailLength < 6) {
		alert(mesaj);
		document.getElementById(numecamp).focus();
		return false;
		}
	if ((atPos <= 0) || (stopPos == -1)) {
		alert(mesaj);
		document.getElementById(numecamp).focus();
		return false;
		}
	if (stopPos < atPos) {
		alert (mesaj);
		document.getElementById(numecamp).focus();
		return false;
		}
	if (stopPos - atPos == 1) {
		alert(mesaj);
		document.getElementById(numecamp).focus();
		return false;	
		}
	if (email.indexOf(at,(atPos+1)) != -1) {
		alert(mesaj);
		document.getElementById(numecamp).focus();
		return false;	
		}
	if (email.indexOf(" ") != -1) {
		alert(mesaj);
		document.getElementById(numecamp).focus();
		return false;	
		}
	if ( mailLength - stopPos < 3) {
		alert(mesaj);
		document.getElementById(numecamp).focus();
		return false;
		}
	if (carNeutre(email) == false) {
		alert(mesaj);
		document.getElementById(numecamp).focus();
		return false;
		}
	else {
		return true;
		}
}

function validareURL(numecamp,mesaj) {
     var theUrl=document.getElementById(numecamp).value;
     var toMatchExtended = /http:\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/
     if (!toMatchExtended.test(theUrl)) {
     	alert(mesaj);
        document.getElementById(numecamp).focus();
        return false;
     } else {
     	 return true;
     }
}
