
//checks the valability of the code in image
function checkCode(){
	var code=document.getElementById('cod').value;
	var encrCode='';
	for(var i=0;i<code.length;i++){
		if(i)
			encrCode+='.';
		encrCode+=code.charCodeAt(i)
	}	
	if(document.getElementById('encrcode').value==encrCode)
		return true;
	alert('codul introdus nu este corect!');
	return false;
}

//checks that the contact message fields are filled
function checkContact(){
	var fields=new Array('cod','nume-contact','telefon-contact','email-contact');
	for(var i=0;i<fields.length;i++)
		if(document.getElementById(fields[i]).value==''){
			alert('Va rugam sa completati toate campurile formularului');
			return false;
		}
	return checkCode();		
}

function checkAppointaments(){
	var fields=new Array('cod','nume','telefon','email');
	for(var i=0;i<fields.length;i++)
		if(document.getElementById(fields[i]).value==''){
			alert('Va rugam sa completati toate campurile formularului');
			return false;
		}
	return checkCode();		
}

function checkCommand(){
	var fields=new Array('cod','nume','telefon','email','address','location','type','surface');
	for(var i=0;i<fields.length;i++)
		if((document.getElementById(fields[i]).value=='')){
			alert('Va rugam sa completati toate campurile formularului!');
			return false;
		}
		return checkCode();
}


//enable submit button if the condition and terms are accepted
function enableSubmit(){
	
	var checkbox= document.getElementById('accept');
	var button= document.getElementById('Trimite');
	if(checkbox.checked){
		button.disabled=false;
	}
	else{
		button.disabled=true;
	}
}


function checkForumLogin(){
	var fields=new Array('forum-username','forum-password');
	for(var i=0;i<fields.length;i++)
		if((document.getElementById(fields[i]).value=='')){
			alert('Nu ati completat userul si parola!');
			return false;
		}
}


function checkForumRegister(){
	var fields=new Array('forum-username', 'forum-email','forum-password', 'forum-confirm-password');
	var emailRegEx = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	var emailValue = document.getElementById('forum-email').value;
	var pass1 = document.getElementById('forum-password').value;
	var pass2 = document.getElementById('forum-confirm-password').value;
	
	for(var i=0;i<fields.length;i++){
	
		if((document.getElementById(fields[i]).value=='')){
			alert('Nu ati completat toate campurile!');
			return false;
		}
	}
	
	if(!emailValue.match(emailRegEx)){
		alert('Adresa de email nu este valida!');
		return false;
	}
	
	if(pass1 != pass2){
		alert('Parolele nu coincid!');
		return false;
	}	
}

function checkRecoverPasswordForm(){
	var email = document.getElementById('forum-forgot-password').value;
	var emailRegEx = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	
	if(email == ''){
		alert('Nu ati introdus adresa de email!');
		return false;
	}
	
	if(!email.match(emailRegEx)){
		alert('Adresa de email nu este valida!');
		return false;
	}
	
}




