﻿function spese(value, cart) {
	if (value == "ritiro")
		costo = 2.5;
	else
		costo = 5;
	text = "Totoale dei servizi richiesti iva compresa, da pagarsi in contrassegno al ritiro della merce &#8364; " + cart.toFixed(2) + " + &#8364; " + costo.toFixed(2) + " = &#8364; " + (costo + cart).toFixed(2);
	document.getElementById("spese").innerHTML=text;
	
}
function invisibleditmail() {
  if (document.dati.pass.type=="password") {
    (document.dati.pass.type="hidden");
    (document.dati.pass_repeat.type="hidden");
    (document.dati.old_pass.type="hidden");
  }
  else {
    (document.dati.pass.type="password");
    (document.dati.pass_repeat.type="password");
    (document.dati.old_pass.type="password");
  }
}	
/* my_account.php, bottone cancella */
function del_ordini(k)
{
  if (confirm("Siamo spiacenti!\nSperiamo che la cancellazione del servizio richiesto\nnon derivi da una nostra disattenzione!\nIn tal caso Vi preghiamo i contattarci\n\nEliminare definitivamente il servizio richiesto?")) {
    document.dati.idordini.value=k;
    document.dati.action="del_ordini.php";
    document.dati.submit();
  }
}

/* my_account.php, bottone cancella */
function dett_ordini(k)
{
weblink=window.open('dettordini'+k+'.php','_blank','toolbar=0, location=0, directories=0, status=0, scrollbars=0, resizable=0, copyhistory=0, menuBar=0, width=640, height=520'); 
}

function delete_multimail()
{
  if (confirm("Cancellare tutte le e-mail selezionate?")) {
    document.dati.action='delete_multimail.php';
    document.dati.submit();
  }
}

function userordini(k)
{
weblink=window.open('userordini.php?id='+k,'_blank','toolbar=0, location=0, directories=0, status=0, scrollbars=0, resizable=0, copyhistory=0, menuBar=0, width=640, height=520'); 
}

function apriemail(k, i)
{
weblink=window.open('dettemail.php?id='+i+'&email='+k,'_blank','toolbar=0, location=0, directories=0, status=0, scrollbars=0, resizable=0, copyhistory=0, menuBar=0, width=640, height=520'); 
}

/* prodotti.php, link  i == cod_prodotto) */
function apriprod(i)
{
  document.dati.product.value=i;
  window.open('dettprod'+i+'.php','_blank','toolbar=0, location=0, directories=0, status=0, scrollbars=0, resizable=0, copyhistory=0, menuBar=0, width=480, height=640');
}

function delete_mail(i)  {
  document.dati.id.value=i;
  document.dati.action="delete_mail.php";
  document.dati.submit();
}


function view_mail(i)  {
  document.dati.id.value=i;
  document.dati.action="view_mail.php";
  document.dati.submit();
}

/* pagina contact.php, bottone reset */
function contact_reset() {
  if (confirm("Stai cancellando tutti i dati\nSei sicuro di voler continuare?"))
	document.dati.reset();
}

/* pagina contact.php, bottone invia */
function contact_control() {
	var expRegEmail = /^[a-zA-Z.\-\_0-9]+[@][a-z.\-\_A-Z0-9]+[.][a-zA-Z]{2,3}$/;
	var expRegNome = /^[a-zA-Z][a-z\' àèéìòùA-Z]*[a-zàèéìòùA-Z]$/;
	var errore= "Errori: \n ";
	var ok = true;

	if (!document.dati.nome.value.match(expRegNome)) {
		errore += "\nIl campo nome non è valido!\n";
		ok = false;
	}

	if (!document.dati.email.value.match(expRegEmail)) {
		errore += "\nIl campo email non è valido!\n";
		ok = false;
	}

	if (!document.dati.oggetto.value.match(expRegNome)) {
		errore += "\nIl campo oggetto non è valido!\n";
		ok = false;
	}

	if (document.dati.testo.value=="") {
		errore += "\nIl testo non è valido!\n";
		ok = false;
	}

	if (!ok) 
		alert(errore);
	else
		document.dati.submit();
}
/* private.php, bottone Accedi */
function private_control() {
	var expRegUser = /^[a-z A-Z.\-\_0-9]+$/;
	var expRegPass = /[^']+$/;
	var errore= "Errori: \n ";
	var ok = true;

	if (!document.dati.username.value.match(expRegUser)) {
		errore += "\nIl campo Username non è valido!\n--> Caratteri consentiti: a-z A-Z 0-9 . _ -\n";
		ok = false;
	}

	if (!document.dati.password.value.match(expRegPass)) {
		errore += "\nIl campo password non è valido!\n--> Carattere apice (') non è consentito\n";
		ok = false;
	}
	
	if (!ok)
		alert(errore);
	else
		document.dati.submit();
}

function Modifica_Servizio(p) {
	document.dati.servizio.value=p;
	document.dati.action="modifica_servizio.php";
	document.dati.submit();
}

function Rimuovi_Servizio(p) {
	document.dati.servizio.value=p;
	if (confirm("Rimuovere il servizio cod "+ p + "?")) {
		document.dati.action="rimuovi_servizio.php";
		document.dati.submit();
	}
}

function delcart(i) {
	document.dati.delserv.value=i;
	document.dati.action="show_cart.php";
	document.dati.submit();
}

function addcart() {
	document.dati.action="show_cart.php";
	document.dati.submit();
}

function Modifica_Prodotto(p) {
	document.dati.product.value=p;
	document.dati.action="modifica_prodotto.php";
	document.dati.submit();
}

function Duplica_Prodotto(p) {
	document.dati.product.value=p;
	if (confirm("Duplicare il prodotto cod "+ p + "?")) {
		document.dati.action="duplica_prodotto.php";
		document.dati.submit();
	}
}

function Rimuovi_Prodotto(p) {
	document.dati.product.value=p;
	if (confirm("Rimuovere il prodotto cod "+ p + "?")) {
		document.dati.action="rimuovi_prodotto.php";
		document.dati.submit();
	}
}

function servizio_control(i) {
	var errore= "Errori: \n ";
	var ok = true;

	if (document.dati.nome.value=="") {
		errore += "\nIl campo Nome non è stato compilato\n";
		ok = false;
	}

	if ((document.dati.euro.value=="0") && (document.dati.cent.value=="00")) {
		errore += "\nIl campo Prezzo è nullo\n";
		ok = false;
	}

	if ((i==1) && (document.dati.image.value=="")) {
		errore += "\nIl campo Foto non è stato compilato\n";
		ok = false;
	}

	if (document.dati.descrizione.value=="") {
		errore += "\nIl campo Descrizione non è stato compilato\n";
		ok = false;
	}

	if (!ok)
		alert(errore);
	else
		document.dati.submit();
}

function prodotto_control(i) {
	var errore= "Errori: \n ";
	var ok = true;

	if (document.dati.nome.value=="") {
		errore += "\nIl campo Nome non è stato compilato\n";
		ok = false;
	}

	if (document.dati.tipo.value=="") {
		errore += "\nIl campo Tipo non è stato compilato\n";
		ok = false;
	}

	if ((document.dati.euro.value=="0") && (document.dati.cent.value=="00")) {
		errore += "\nIl campo Prezzo è nullo\n";
		ok = false;
	}

	if ((i==1) && (document.dati.image.value=="")) {
		errore += "\nIl campo Foto non è stato compilato\n";
		ok = false;
	}

	if (document.dati.descrizione.value=="") {
		errore += "\nIl campo Descrizione non è stato compilato\n";
		ok = false;
	}
	if (!ok)
		alert(errore);
	else
		document.dati.submit();
}

/*
chiamata funzione register()
*/
function controlAnagraphicDate() {

	var expRegNome = /^[a-zA-Z\' ]+$/; //valido anche per indirizzo e citta
	var expRegCognome = /^[a-zA-Z]+[\' ]{0,1}[a-zA-Z]+$/;
	var expRegCivico = /^[a-zA-Z0-9\/]+$/;
	var expRegCap = /^[0-9]{5}$/;
	var errore= "";
        if (!document.dati.nome.value.match(expRegNome)) 
                errore += "\nIl campo Nome non è valido \n";
        if (!document.dati.cognome.value.match(expRegCognome)) 
                errore += "\nIl campo Cognome non è valido \n";
        if (!document.dati.indirizzo.value.match(expRegNome)) 
                errore += "\nIl campo Indirizzo non è valido \n";
        if (!document.dati.civico.value.match(expRegCivico))
                errore += "\nIl campo N. Civico non è valido \n";
        if (!document.dati.citta.value.match(expRegNome))
                errore += "\nIl campo Città non è valido \n";
        if (document.dati.prov.value == "")
                errore += "\nIl campo Provincia non è valido \n";
        if (!document.dati.cap.value.match(expRegCap))
                errore += "\nIl campo Cap non è valido \n";
	return errore;
}
/* new_account.php, bottone register */
function register() {
	var expRegTel = /^[0-9]+$/;
	var expRegPass = /^[a-zA-Z0-9.\-\_!$%&\/]{4,}$/;
	var expRegEmail = /^[a-zA-Z.\-\_0-9]+[@][a-z.\-\_A-Z0-9]+[.][a-zA-Z]{2,3}$/;
	var errore = "Errori: \n ";
	var ok = true;
	if (controlAnagraphicDate() != "") {
		ok = false;
		errore += controlAnagraphicDate();
	}
	if (!document.dati.email.value.match(expRegEmail)) {
		errore += "\nIl campo E-Mail non è valido \n";
		ok = false;
	}

        if (!document.dati.pass.value.match(expRegPass)) {
                errore += "\nIl campo Password non è valido:\n\tcarateri speciali .-_!$%&/ almeno 4 char";
                ok = false;
        }

	if (!document.dati.trattamento[0].checked) {
		errore  +="\nIl trattamento dei dati non è stato accettato!";
		ok = false;
	}

	if (!document.dati.contratto[0].checked) {
		errore  +="\nIl contratto non è stato accettato!";
		ok = false;
	}

	if (!document.dati.telefono.value.match(expRegTel)) {
                errore += "\nIl campo Telefono non è valido\n";
		ok = false;
	}

	if (!ok)
		alert(errore);
	else
		document.dati.submit();
}

/*
navigation.php, bottone accedi
login.php, bottone accedi
*/
function login_fun(i) {
	var expRegPass = /^[a-zA-Z0-9.\-\_!$%&*\/]{4,}$/;
	var expRegEmail = /^[a-zA-Z.\-\_0-9]+[@][a-z.\-\_A-Z0-9]+[.][a-zA-Z]{2,3}$/;
	var errore= "Errori: \n ";
	var ok = true;

	if (i==0) {
		if (!document.dati.mail.value.match(expRegEmail)) {
			errore += "\nIl campo E-Mail non è valido \n";
			ok = false;
		}

		if (!document.dati.pwd.value.match(expRegPass)) {
			errore += "\nIl campo password non è valido - min 4 caratteri";
			ok = false;
		}
	}
	else {
		if (!document.dati.email.value.match(expRegEmail)) {
			errore += "\nIl campo E-Mail non è valido \n";
			ok = false;
		}

		if (!document.dati.pass.value.match(expRegPass)) {
			errore += "\nIl campo password non è valido - min 4 caratteri";
			ok = false;
		}
	}

	if (!ok)
		alert(errore);
	else {
		document.dati.action="access.php";
		document.dati.submit();
	}
}
function edit_profile() {
	var expRegTel = /^[0-9]+$/;
	var expRegPass = /^[a-zA-Z0-9.\-\_!$%&*\/]{4,}$/;
	var errore = "Errori: \n ";
	var ok = true;
	if (controlAnagraphicDate() != "") {
		ok = false;
		errore += controlAnagraphicDate();
	}

	if (document.dati.editpass.checked) {
        	if ((!document.dati.old_pass.value.match(expRegPass))||
         	(!document.dati.pass.value.match(expRegPass))) {
         	       errore += "\nIl campo Password non è valido:\n\tcarateri speciali .-_!$%&/ almeno 4 char";
         	       ok = false;
        	}
		else
        	if (document.dati.pass.value != document.dati.pass_repeat.value) {
        	        errore += "\nLe password digitate non corrispondono\n";
			ok = false;
		}
	}

	if (!ok)
		alert(errore);
	else
		document.dati.submit();
}
function confirm_order() {
	var expRegTel = /^[0-9]+$/;
	var errore = "Errori: \n ";
	var ok = true;
	var i=0;
	if (controlAnagraphicDate() != "") {
		ok = false;
		errore += controlAnagraphicDate();
	}
	while (i<24 && document.dati.orario && !document.dati.orario[i].checked)i++;

	if (i==24 || !document.dati.orario) {
		ok = false;
		errore += "\nNessun orario presente, premere il giorno desiderato e selezionare l'ora";
	}
	if (!document.dati.telefono.value.match(expRegTel)) {
                errore += "\nIl campo Telefono non è valido\n";
		ok = false;
	}
	if (!ok)
		alert(errore);
	else
		document.dati.submit();
}

