//Javascript

function chkmail(str)
{
var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
if (filter.test(str))
	return true;
else
	{
	alert("Indirizzo e-mail non valido.");
	return false;
	}
}

function chkdata(str,strerr)
{
var filter = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/
if (filter.test(str))
	{
	vetdata=str.split(/(\-|\/|\.)/);
	giorno=parseInt(vetdata[0], 10);
	mese=parseInt(vetdata[1], 10);
	anno=parseInt(vetdata[2], 10);
	if (giorno < 1 || giorno > 31 || mese < 1 || mese > 12 || anno < 1000 )
		{
		alert("Data non valida! Correggere " + strerr);
		return false;
		}
	switch (mese)
		{
		case 2: 
			maxgg=28;
			if (anno % 4 == 0 && (anno % 100 != 0 || anno % 400 == 0)) maxgg=29;
			if (giorno > maxgg)
				{
				alert("Data non valida! Correggere " + strerr);
				return false;
				}
			break
		default : 
			if ((mese == 4 || mese == 6 || mese == 9 || mese == 11) && ( giorno > 30))
				{
				alert("Data non valida! Correggere " + strerr);
				return false;
				}
		}
	return true;
	}
else
	{
	alert("Data non valida! Correggere " + strerr);
	return false;
	}
}

function chkcap(str,strerr)
{
var filter=/(^\d{5}$)/
if (filter.test(str))
	return true;
else
	{
	alert("CAP non valido! Correggere " + strerr);
	return false;
	}
}

function chknum(str,strerr)
{
var filter=/(^\d+$)/
if (filter.test(str))
	return true;
else
	{
	alert("Campo non numerico! Correggere " + strerr);
	return false;
	}
}

function chkdec(str,strerr)
{
var filter=/(^-*\d+$)|(^-*\d+\,\d+$)/
if (filter.test(str))
	return true;
else
	{
	alert("Campo non numerico! Correggere " + strerr);
	return false;
	}
}

function chkint(str,strerr)
{
var filter=/(^-*\d+$)/
if (filter.test(str))
	return true;
else
	{
	alert("Campo non numerico! Correggere " + strerr);
	return false;
	}
}

function chkalfnum(str,strerr)
{
var filter=/(^\w+$)/
var filter=/(^[a-z0-9]+$)/i
if (filter.test(str))
	return true;
else
	{
	alert("Caratteri non ammessi! Correggere " + strerr);
	return false;
	}
}

function chkalf(str,strerr)
{
var filter=/(^[a-z]+$)/i
if (filter.test(str))
	return true;
else
	{
	alert("Caratteri non ammessi! Correggere " + strerr);
	return false;
	}
}

function chklung(str, lungmin, lungmax, strerr)
{
  if (str.length == 0 || str == "") 
    {
		alert("Valore non valido! Controllare lunghezza " + strerr); 
        return false;
    }
  appo=str.length	 
  if (appo < lungmin || appo > lungmax)
    {
		alert("Valore non valido!! Controllare lunghezza " + strerr); 
        return false;
    } 
  return true;
}

function chkfill(str, strerr)
{
  if (str.length == 0 || str == "") 
    {
		alert("Campo Obbligatorio! Inserire" + strerr); 
        return false;
    }
  return true;
}

function chkval(str, valmin, valmax, ndigit, strerr)
{
  if (ndigit != 0)
    {
	  if (chklung(str, ndigit, ndigit, strerr) == false) return false;
    }
  if (chknum(str,strerr) == false ) return false;
  valore=parseInt(str, 10);
  minimo=parseInt(valmin, 10);
  massimo=parseInt(valmax, 10);
  if (valore < minimo || valore > massimo) 
    {
		alert("Valore non valido! Valori ammessi da " + valmin + " a " + valmax + ". Controllare " + strerr); 
        return false;
    }
  return true;
}

function chkamm(User, Passw)
{
if (chkalfnum(User, 'User') == false ) return false;
if (chklung(User, '8', '8', 'User') == false ) return false;
if (chkalfnum(Passw, 'Password') == false ) return false;
if (chklung(Passw, '8', '8', 'Password') == false ) return false;
return true;
}

function chknwl(IDKey, Titolo, Flink1)
{
if (chkval(IDKey, 1, 99, 2, 'Identificativo') == false ) return false;
if (chkfill(Titolo, 'Titolo news') == false ) return false;
if (chkfill(Flink1, 'Documento News Letter') == false ) return false;
return true;
}

function risposta(valore)
{
if (valore=="INSNEWSOK") alert('E-mail inserita nella Newsletter. Attendiamo conferma. Grazie.');
if (valore=="DELNEWSOK") alert('E-mail cancellata dalla NewsLetter. Attendiamo conferma. Grazie.');
if (valore=="LSTNEWSOK") alert('La lista e-mail di invio News Letters verrā recapitata via e-mail. Grazie.');
if (valore=="SNDNEWSOK") alert('La News Letters č stata recapitata alla sua casella di posta per la conferma definitiva. Grazie.');
if (valore=="SNDNEWSOKER01") alert('La News Letters č stata recapitata alla sua casella di posta per la conferma definitiva ma si rilevano errori di apertuta del Data Base. Contattare il Webmaster. Grazie.');
if (valore=="SNDNEWSOKER02") alert('La News Letters č stata recapitata alla sua casella di posta per la conferma definitiva ma si rilevano errori di accesso al Data Base. Contattare il Webmaster. Grazie.');
}

function chkord(IDKey, Ordine, Titolo, Descrizione, Immagine)
{
if (chkval(IDKey, 1, 99, 2, 'Identificativo') == false ) return false;
if (chkval(Ordine, 1, 99, 2, 'Ordine News') == false ) return false;
if (chkfill(Titolo, 'Titolo news') == false ) return false;
if (chkfill(Descrizione, 'Descriczione breve news') == false ) return false;
return true;
}

function chkgare(IDKey, Ordine, Titolo, Descrizione, Immagine, DescLink, UrlLink, DescLinkDoc, UrlLinkDoc)
{
if (chkord(IDKey, Ordine, Titolo, Descrizione, Immagine) == false ) return false;

if (DescLink != "" || UrlLink != "")
	{
		if (chkfill(DescLink, 'Descrizione testuale Link a pagina Internet') == false ) return false;
		if (chkfill(UrlLink, 'Link a pagina Internet') == false ) return false;
	}


if (DescLinkDoc != "" || UrlLinkDoc != "")
	{
		if (chkfill(DescLinkDoc, 'Descrizione testuale Link a Documento Office') == false ) return false;
		if (chkfill(UrlLinkDoc, 'Link a Documento Office') == false ) return false;
	}

return true;
}

function chkall(IDKey, Ordine, Titolo, Descrizione, Immagine, DescLink, UrlLink, DescLinkDoc, UrlLinkDoc, DescLinkDocUno, UrlLinkDocUno, DescLinkPg, TitPg, DescPg, ImgPg)
{
if (chkgare(IDKey, Ordine, Titolo, Descrizione, Immagine, DescLink, UrlLink, DescLinkDoc, UrlLinkDoc) == false ) return false;

if (DescLinkDocUno != "" || UrlLinkDocUno != "")
	{
		if (chkfill(DescLinkDocUno, 'Descrizione testuale Link a ultertiore Documento Office') == false ) return false;
		if (chkfill(UrlLinkDocUno, 'Link a ultertiore Documento Office') == false ) return false;
	}

if (DescLinkPg != "" || TitPg != "" || DescPg != "")
	{
		if (chkfill(DescLinkPg, 'Descrizione testuale Link a pagina ulteriore') == false ) return false;
		if (chkfill (TitPg, 'Titolo pagina ulteriore') == false ) return false;
		if (chkfill(DescPg, 'Testo pagina ulteriore') == false ) return false;
	}

return true;
}

function chkfoto(IDKey, Ordine, Titolo, Descrizione, Nome, Numero)
{
if (chkval(IDKey, 1, 99, 2, 'Identificativo') == false ) return false;
if (chkval(Ordine, 1, 99, 2, 'Ordine Fotografie') == false ) return false;
if (chkfill(Titolo, 'Titolo Album') == false ) return false;
if (chkfill(Descrizione, 'Descrizione Album Fotografico') == false ) return false;
if (chklung(Nome, '5', '5','Prefisso Album Fotografie') == false ) return false;
if (chkalf(Nome, 'Prefisso Album Fotografie') == false ) return false;
if (chkval(Numero, 1, 100, 3, 'Numero di Fotografie') == false ) return false;

return true;
}

function chknomefoto(PFoto, GFoto, Nome, Tipo, Numero)
{
if (PFoto.length == 0) return false;
if (GFoto.length == 0) return false;

Nome = Nome.toUpperCase();
Tipo = Tipo.toUpperCase();
Numero = Numero.toUpperCase();

PFoto = PFoto.toUpperCase();
Ind = PFoto.lastIndexOf("\\");
Ind++;
Appo = PFoto.substr(Ind, 1);
if (Appo != "P") return false; 
Ind++;
Appo = PFoto.substr(Ind, 5);
if (Appo != Nome) return false; 
Ind = Ind + 5;
Appo = PFoto.substr(Ind, 3);
if (Appo.length != 3) return false;
if (Appo < "001" || Appo > Numero) return false; 
Pun = PFoto.lastIndexOf(".");
Ind = Ind + 3;
if (Ind != Pun) return false; 
Ind++;
Ilen=PFoto.length;
Ilen=Ilen - Ind;
Appo = PFoto.substr(Ind, Ilen);
if (Appo != Tipo) return false; 

GFoto = GFoto.toUpperCase();
Ind = GFoto.lastIndexOf("\\");
Ind++;
Appo = GFoto.substr(Ind, 1);
if (Appo != "G") return false; 
Ind++;
Appo = GFoto.substr(Ind, 5);
if (Appo != Nome) return false; 
Ind = Ind + 5;
Appo = GFoto.substr(Ind, 3);
if (Appo.length != 3) return false;
if (Appo < "001" || Appo > Numero) return false; 
Pun = GFoto.lastIndexOf(".");
Ind = Ind + 3;
if (Ind != Pun) return false; 
Ind++;
Ilen=GFoto.length;
Ilen=Ilen - Ind;
Appo = GFoto.substr(Ind, Ilen);
if (Appo != Tipo) return false; 

return true;
}

function win(pw, ph) {
    var larghezza = pw;
	var altezza = ph;
	if (document.singola)
		{
		var adjlarghezza = 70;
		var adjaltezza = 150;
		var larghezza = document.singola.width + adjlarghezza;
		var altezza = document.singola.height + adjaltezza;
		}
		window.resizeTo(larghezza,altezza);
		cx = (screen.width/2)-(larghezza/2);
		cy = (screen.height/2)-(altezza/2);	
		window.moveTo(cx,cy);
    	window.focus();
	}
