/****************************************************************************************************************
Fisier care contine functiile js folosite in mod universal in sectiunea admin
****************************************************************************************************************/
//functie care verifica o adresa de mail pe partea client
function echeck(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){		   
	  return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){		   
	  return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){		    
	  return false
	}

	if (str.indexOf(at,(lat+1))!=-1){		    
		return false
	}

	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		return false
	}

	if (str.indexOf(dot,(lat+2))==-1){
		return false
	}
		
	if (str.indexOf(" ")!=-1){
		return false
	}

	return true					
}


function deschide(adresa,nume,w,h) {
   popupWindow=window.open(adresa,nume,'width='+w+',height='+h);
   popupWindow.focus();
}

function check_modificare() {
		var f = document.getElementById("form_modificare");
		var str = '';
		var corect=true;
	
		if(f.nume.value.length<3) {corect=false; str+='Nu ai introdus numele!\n'}		
		if(f.nume.value.length>40) {corect=false; str+='Numele este prea lung! (max. 40 car.)\n'}		
		if(f.prenume.value.length<3) {corect=false; str+='Nu ai introdus prenumele!\n'}
		if(f.prenume.value.length>40) {corect=false; str+='Prenumele este prea lung! (max. 40 car.)\n'}
		if(f.telefon.value.length<3) {corect=false; str+='Nu ai introdus numarul de telefon!\n'}
		if(f.parola.value.length<3) {corect=false; str+='Nu ai introdus parola!\n'}
		if(f.parola2.value.length<3) {corect=false; str+='Nu ai reintrodus parola!\n'}
		if(f.telefon.value.length>50) {corect=false; str+='Numarul de telefon este prea lung! (max. 50 car.)\n'}
		if(f.email.value.length<3) {corect=false; str+='Nu ai introdus adresa de email!\n'}
		else if(echeck(f.email.value)==false) {corect=false; str+='Adresa de email nu este corecta!\n'}
					
		if(!corect)
		    alert(str)
		 else
		    return f.submit();		
}

function check_reamintire() {
	var f = document.getElementById("form_login");
	var str = '';
	var corect=true;
	
	if(f.email_login.value.length<3) { corect=false; str+='Trebuie sa introduci adresa de email a contului pentru a-ti putea fi trimisa parola!\n'}
	else if(echeck(f.email_login.value)==false) {corect=false; str+='Trebuie sa introduci adresa de email a contului pentru a-ti putea fi trimisa parola!\n'}
	
	if(!corect) alert(str);
	else document.getElementById("link_reamintire").href += '?adresa='+f.email_login.value;
	
	return corect;
}


function check_reamintire_eng() {
	var f = document.getElementById("form_login");
	var str = '';
	var corect=true;
	
	if(f.email_login.value.length<3) { corect=false; str+='You must enter the email address for your account!\n'}
	else if(echeck(f.email_login.value)==false) {corect=false; str+='You must enter the email address for your account!\n'}
	
	if(!corect) alert(str);
	else document.getElementById("link_reamintire_eng").href += '?adresa='+f.email_login.value;
	
	return corect;
}

//functie care verifica formularul de inscriere in newsletter
function check_newsletter() {	
	var f = document.getElementById('form_newsletter');
	var str = '';
	var corect=true;
	
	if(f.email_newsletter.value.length<3) {corect=false; str+='Nu ai introdus adresa de email!\n'}
	else if(echeck(f.email_newsletter.value)==false) {corect=false; str+='Email incorect!\n'}		
		
	//daca sunt erori	
	if(!corect) alert(str);
	return corect;
}

function check_newsletter_eng() {	
	var f = document.getElementById('form_newsletter');
	var str = '';
	var corect=true;
	
	if(f.email_newsletter.value.length<3) {corect=false; str+='You must enter an email address!\n'}
	else if(echeck(f.email_newsletter.value)==false) {corect=false; str+='Incorrect email!\n'}		
		
	//daca sunt erori	
	if(!corect) alert(str);
	return corect;
}

//functie pentru schimbarea versiunii
function schimba_versiune(versiune) {
	var f = document.getElementById('form_versiune');
	f.noua_versiune.value = versiune;
	if(f.noua_versiune.value=='romana'||f.noua_versiune.value=='engleza') f.submit();
}

function check_inscriere_firma() {	
	var f = document.getElementById('form_inscriere');
	var str = '';
	var corect=true;
			
		if(f.tip.value=='') {corect=false; str+='Nu ai ales tipul firmei!\n'}
		if(f.denumire.value.length<3) {corect=false; str+='Nu ai introdus denumirea firmei!\n'}
		if(f.telefon.value.length<3) {corect=false; str+='Nu ai introdus numarul de telefon!\n'}
		if(f.email.value.length<3) {corect=false; str+='Nu ai introdus adresa de email!\n'}
		else if(echeck(f.email.value)==false) {corect=false; str+='Adresa de email nu este corecta!\n'}

	 
	 //daca sunt erori	
	if(!corect) alert(str);
	else f.submit();
}

function check_inscriere_firma_eng() {	
	var f = document.getElementById('form_inscriere');
	var str = '';
	var corect=true;	 
			
		if(f.tip.value=='') {corect=false; str+='You must choose the company\'s type!\n'}
		if(f.denumire.value.length<3) {corect=false; str+='You must enter your company\'s name!\n'}
		if(f.telefon.value.length<3) {corect=false; str+='You must enter a telephone number!\n'}
		if(f.telefon.value.length>50) {corect=false; str+='Telephone number too long! (max. 50 car.)\n'}
		if(f.email.value.length<3) {corect=false; str+='You must enter an email address!\n'}
		else if(echeck(f.email.value)==false) {corect=false; str+='Incorrect email address!\n'}


	//daca sunt erori	
	if(!corect) alert(str);
	else f.submit();
}	

function check_schimba_parola() {
	var f = document.getElementById("form_schimba_parola");
	var str = '';
	var corect=true;
	if(f.parola_schimba.value.length<6) {corect=false; str+='Nu ai ales parola! (min. 6 car.)\n'}
	if(f.parola_schimba.value.length>20) {corect=false; str+='Parola este prea lunga! (max. 20 car.)\n'}
	if(f.parola_schimba.value!=f.parola_schimba2.value) {corect=false; str+='Parolele nu coincid!\n'}
	if(!corect) alert(str);
	return corect;		
}

function check_schimba_parola_eng() {
	var f = document.getElementById("form_schimba_parola_eng");
	var str = '';
	var corect=true;
	if(f.parola_schimba.value.length<6) {corect=false; str+='You must enter the password! (min. 6 car.)\n'}
	if(f.parola_schimba.value.length>20) {corect=false; str+='The password is too long! (max. 20 car.)\n'}
	if(f.parola_schimba.value!=f.parola_schimba2.value) {corect=false; str+='Passwords are not the same!\n'}
	
	if(!corect) alert(str);
    else f.submit();		
}

function check_modificare_eng() {
		var f = document.getElementById("form_modificare_eng");
		var str = '';
		var corect=true;
	
		if(f.nume.value.length<3) {corect=false; str+='You must enter your first name!\n'}		
		if(f.nume.value.length>40) {corect=false; str+='The name is too long! (max. 40 car.)\n'}		
		if(f.prenume.value.length<3) {corect=false; str+='You must enter your last name!\n'}
		if(f.prenume.value.length>40) {corect=false; str+='Your last name is too long! (max. 40 car.)\n'}
		if(f.telefon.value.length<3) {corect=false; str+='You must enter telephone number!\n'}
		if(f.parola.value.length<3) {corect=false; str+='You must enter the password!\n'}
		if(f.parola2.value.length<3) {corect=false; str+='You must retype your password!\n'}
		if(f.telefon.value.length>50) {corect=false; str+='Telephone number is too long! (max. 50 car.)\n'}
		if(f.email.value.length<3) {corect=false; str+='You must enter your email address!\n'}
		else if(echeck(f.email.value)==false) {corect=false; str+='Incorrect email address!\n'}
					
		if(!corect)
		    alert(str)
		 else
		    return f.submit();		
}

function check_login_eng() {	
	var f = document.form_login;
	var str = '';
	var corect=true;
			
	if(f.email_login.value.length<3) {corect=false; str+='You must enter your email address!\n'}
	else if(echeck(f.email_login.value)==false) {corect=false; str+='Incorrect email address!\n'}		
	if(f.parola_login.value.length<3) {corect=false; str+='You must enter a password!\n'}
	
	if(!corect) alert(str);
	else f.submit();
}

function check_login() {	
	var f = document.form_login;
	var str = '';
	var corect=true;
			
	if(f.email_login.value.length<3) {corect=false; str+='Nu ai introdus adresa de email!\n'}
	else if(echeck(f.email_login.value)==false) {corect=false; str+='Adresa de email nu este corecta!\n'}		
	if(f.parola_login.value.length<3) {corect=false; str+='Nu ai introdus parola!\n'}
	
	if(!corect) alert(str);
	else f.submit();
}

//functie care verifica formularul de adaugare
function check_form() {	
	var f = document.getElementById('form');
	var str = '';
	var corect=true;
	var i;
	
	if(f.nume.value.length<4) {corect=false; str+='Nu ai introdus numele!\n'}
	if(f.telefon.value.length<4) {corect=false; str+='Nu ai introdus numarul de telefon!\n'}
	if(f.email.value.length<4) {corect=false; str+='Nu ai introdus adresa de email!\n'}
	if(f.continut.value.length<4) {corect=false; str+='Nu ai introdus continutul!\n'}
		
	//daca sunt erori	
	if(!corect) alert(str);
	return corect;
}

//functie care verifica formularul de adaugare
function check_form_eng() {	
	var f = document.getElementById('form');
	var str = '';
	var corect=true;
	var i;
	
	if(f.nume.value.length<4) {corect=false; str+='You must enter your name name!\n'}
	if(f.telefon.value.length<4) {corect=false; str+='You must enter your phone number!\n'}
	if(f.email.value.length<4) {corect=false; str+='You must enter your email address!\n'}
	if(f.continut.value.length<4) {corect=false; str+='You must enter the content!\n'}
		
	//daca sunt erori	
	if(!corect) alert(str);
	return corect;
}

//pentru fisierul "laborator.php"
function check_adaugare() {
		var f = document.getElementById("form_adaugare");
		var str = '';
		var corect=true;
	
		if(f.denumire.value.length<3) {corect=false; str+='Nu ai introdus denumirea/ numele!\n'}		
		if(f.denumire.value.length>40) {corect=false; str+='Denumirea / Numele este prea lung! (max. 40 car.)\n'}	
		if(f.judet.value=='') {corect=false; str+='Trebuie sa alegi judetul!\n'}
		if(f.adresa.value.length<3) {corect=false; str+='Nu ai introdus adresa!\n'}
					
		if(!corect) alert(str);
		
		return corect;		
}

//pentru fisierul "laborator.php"
function check_adaugare_eng() {
		var f = document.getElementById("form_adaugare_eng");
		var str = '';
		var corect=true;
	
		if(f.denumire.value.length<3) {corect=false; str+='You must enter the name!\n'}		
		if(f.denumire.value.length>40) {corect=false; str+='The name is too large! (max. 40 car.)\n'}		
		if(f.judet.value=='') {corect=false; str+='You must choose the district!\n'}
		if(f.adresa.value.length<3) {corect=false; str+='You must enter the address!\n'}
					
		if(!corect) alert(str);

	    return corect;		
}