
//controllo form
function controlloForm(campi) {
	var stringa = campi;
	var splitted = stringa.split("[]");
	for (i in splitted) {
		obj = document.getElementById(splitted[i]);
		if (obj.value == "" || obj.value == "Campo obbligatorio / Required field") {
			obj.style.border = "1px solid #C00";
			obj.style.color = "#C00";
			obj.value = "Campo obbligatorio / Required field";
			obj.focus();
			return false;
		} else {
			obj.style.border = "1px solid #CCC";
			obj.style.color = "#333";
		}
	}
}

function controlloFormRegistrazione(campi) { 
	var stringa = campi;
	var splitted = stringa.split("[]");
	var mailControllo = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
	var passControllo = /^[a-zA-Z0-9]+(([\'\,\.\- ][a-zA-Z0-9 ])?[a-zA-Z0-9]*)*$/;
	var mail = document.getElementById('email').value;
	var passw = document.getElementById('pass').value;
	var pri = document.getElementById('privacy').checked;
	for (i in splitted) {
		obj = document.getElementById(splitted[i]);
		if (obj.value == "" || obj.value == "Obbligatorio / Required") {
			obj.style.border = "1px solid #C00";
			obj.style.color = "#C00";
			obj.value = "Obbligatorio / Required";
			obj.focus();
			return false;
		} else {
			obj.style.border = "1px solid #CCC";
			obj.style.color = "#333";
			
			if(!mail.match(mailControllo)) {
				alert ("E-Mail inserita non corretta.\nE-mail address is not correct.");
				return false;
			}
			if(passw.length < 6) {
				alert ("La Password deve avere almeno 6 caratteri.\nPasswords must be at least 6 characters.");
				return false;
			}  
			if(!passw.match(passControllo)) {
				alert ("Password con caratteri non ammessi (aA..zZ, 0..9)\nPassword characters are not allowed (aA..zZ, 0..9)");
				return false;
			}
			if (pri == false) {
				alert ("Conferma la privacy per registrarti\nConfirm your privacy to register");
				return false;
			}
		}
	}
}


function controlloFormContatti(campi) {
	var stringa = campi;
	var splitted = stringa.split("[]");
	var mailControllo = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
	var mail = document.getElementById('email').value;
	var pri = document.getElementById('privacy').checked;
	for (i in splitted) {
		obj = document.getElementById(splitted[i]);
		if (obj.value == "" || obj.value == "Obbligatorio / Required") {
			obj.style.border = "1px solid #C00";
			obj.style.color = "#C00";
			obj.value = "Obbligatorio / Required";
			obj.focus();
			return false;
		} else {
			obj.style.border = "1px solid #CCC";
			obj.style.color = "#333";
			
			if(!mail.match(mailControllo)) {
				alert ("E-Mail inserita non corretta.\nE-mail address is not correct.");
				return false;
			}
			if (pri == false) {
				alert ("Conferma la privacy\nConfirm your privacy");
				return false;
			}
		}
	}
}


function controlloRadio(campo) {
	obj = document.getElementById(campo).checked;
	if (obj == false) {
		alert ("Conferma la privacy per registrarti\nConfirm your privacy to register");
		return false;
	}
}


function controlloLogin(campi) {
	var stringa = campi;
	var splitted = stringa.split("[]");
	var mailControllo = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
	var passControllo = /^[a-zA-Z0-9]+(([\'\,\.\- ][a-zA-Z0-9 ])?[a-zA-Z0-9]*)*$/;
	email = document.getElementById(splitted[0]);
	password = document.getElementById(splitted[1]);
	var mail = email.value;
	var pass = password.value;
	if(!mail.match(mailControllo)) {
		alert ("E-Mail inserita non corretta.\nE-mail address is not correct.");
    	return false;
    }
	if(pass.length < 6) {
		alert ("La Password deve avere almeno 6 caratteri.\nPasswords must be at least 6 characters.");
		return false;
    }  
    if(!pass.match(passControllo)) {
		alert ("Password con caratteri non ammessi (aA..zZ, 0..9)\nPassword characters are not allowed (aA..zZ, 0..9)");
		return false;
    }
}


//VotaProd
function VotaProd(stella) {
	for (i=1; i<=5; i++){
		foto = document.getElementById("stella_"+i);
		immagine = '../img/stella_0.gif';
		foto.setAttribute('src',immagine);
		}
	for (j=0; j<stella; j++){
		k=j+1
		foto = document.getElementById("stella_"+k);
		immagine = '../img/stella_1.gif';
		foto.setAttribute('src',immagine);
		votoDato = document.getElementById("voto_dato");
		votoDato.value=k*2;	
		}
}


//cancellaAccount()
function cancellaAccount() {
	if (confirm("Sei certo di voler eliminare il tuo account?\nAre you sure you want to delete your account?")==true) {
		if (confirm("Sara' possibile registrarsi in qualsiasi momento\nClicca ok per confermare la cancellazione dell'account:\nClick OK to confirm the deletion")==true) {
			location.href="index.php?login=cancella_acconut";
		}else{
			return false;
		}
	}else{
		return false;
	}
}


//pop calendario
function calendarioPopUp(id_div) {
	//chiudi tutto
	var div_pop=document.getElementById('calendario').getElementsByTagName('div');
	  for(var k=0,l=div_pop.length;k<l;k++){
		if (div_pop[k].className=="calendario_popup") {
			div_pop[k].style.visibility = "hidden";
		}
	  }	
	popup = document.getElementById(id_div);
	popup.style.visibility = "visible";
}
function calendarioPopUp_chiudi(id_div) {
	popup = document.getElementById(id_div);
	popup.style.visibility = "hidden";
	
}

//controlloFormTestimonianze
function controlloFormTestimonianze(campi) {
	var stringa = campi;
	var splitted = stringa.split("[]");
	var pri = document.getElementById('dichiaro').checked;
	var video = document.getElementById('video').value;
	var foto = document.getElementById('foto').value;
	for (i in splitted) {
		obj = document.getElementById(splitted[i]);
		if (obj.value == "" || obj.value == "Obbligatorio / Required") {
			obj.style.border = "1px solid #C00";
			obj.style.color = "#C00";
			obj.value = "Obbligatorio / Required";
			obj.focus();
			return false;
		} else {
			obj.style.border = "1px solid #CCC";
			obj.style.color = "#333";
			
			if (video == "" && foto == "") {
				alert ("Inserire almeno un video o una foto\nAdd a video or photo");
				return false;
			}			
			if (pri == false) {
				alert ("Conferma la nota legale\nConfirm the legal notice");
				return false;
			} 
		}
	}
}



