// JavaScript Document

function validateSendCV(){

	var name = document.getElementById('nume').value;
	var email = document.getElementById('email').value;
	var file = document.getElementById('fisier').value;

	var err = "";
	if (name== "") err = err + "Trebuie sa adaugati numele!\n";
	if (email== "") err = err + "Trebuie sa adaugati adresa de e-mail!\n";
	if (file== "") err = err + "Trebuie sa atasati CV-ul!\n";
	if (err == "") {return true;}
	else {alert(err);return false}
}


function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		var eroare = "";
		if (str.indexOf(at)==-1){
			return "Adresa de email invalida\n";
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
			return "Adresa de email invalida\n";
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
			return "Adresa de email invalida\n";
		}

		 if (str.indexOf(at,(lat+1))!=-1){
			return "Adresa de email invalida\n";
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
			return "Adresa de email invalida\n";
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
			return "Adresa de email invalida\n";
		 }

		 if (str.indexOf(" ")!=-1){
		   return "Adresa de email invalida\n";
		 }
 		 return eroare;
	}

function validateSubscribeNewsletter(){
	var email = document.getElementById('email');
	var captcha = document.getElementById('captchaField').value;
	var err = "";
	if (email.value == "")
		err = err + "Trebuie sa adaugati adresa de e-mail!\n";
	else
	{
		if (echeck(email.value) != ""){
			err = err + echeck(email.value);
			email.value = "";
		}
	}
	if (captcha == "") err = err + "Trebuie sa introduceti codul din imagine!\n";
	if (err == "") {return true;}
	else {alert(err);return false}
}



function validateSendFeedback(){

	var name = document.getElementById('nume').value;
	var email = document.getElementById('email').value;


	var err = "";
	if (name== "") err = err + "Trebuie sa adaugati numele!\n";
	if (email== "") err = err + "Trebuie sa adaugati adresa de e-mail!\n";

	if (err == "") {return true;}
	else {alert(err);return false}
}

function showDiv(id){

	div1 = document.getElementById('first');
	div2 = document.getElementById('second');

	switch(id){
		case 1: {
			div1.style.display='block';
			div2.style.display='none';
			break;
		}
		case 2: {
			div1.style.display='none';
			div2.style.display='block';
			break;
		}

	}
}
