// JavaScript Document

var valore=0;
var mese=1;
var giorno=1;
var anno=1900;
var annobis=0;

function chkvuoto(str, strerr)
{
  if (str == "") 
    {
		alert("Campo Obbligatortio! Controllare " + strerr); 
        return false;
    } 

  return true;
}

function chkfill(str, strerr)
{
  if (str == "") 
    {
		 		alert("Campo Obbligatortio! Controllare " + strerr); 
        return false;
    } 
  for (var i = 0; i < str.length; i++) 
  { 
		var ch = str.substring(i, i + 1);
		if (ch < "0" || ch > "9") 
			{
			if (ch < "a" || ch > "z") 
				{
					if (ch < "A" || ch > "Z")
						{
							if (ch == "À" || ch == "È" || ch == "É" || ch == "Ì" || ch == "Ò" || ch == "Ù" || ch == "à" || ch == "è" || ch == "é" || ch == "ì" || ch == "ò" || ch == "ù")
  							{
									continue;
								}
							else
								{
								 	if (ch == " " || ch == "." || ch == "," || ch == "-" || ch == "(" || ch == ")" || ch == "/" || ch == "?")
  									 {
										 	continue;
										 }
									else
										{
									 		alert("Caratteri non validi! Controllare " + strerr); 
											return false;
										}
								}
						}
	      }
      }
  }
	return true;
}

function chklung(str, lungmin, lungmax, strerr)
{
  if (str == "") 
    {
		alert("Campo Obbligatortio! Controllare lunghezza " + strerr); 
        return false;
    }
	appo=str.length	 
  if (appo < lungmin || appo > lungmax)
    {
		alert("Campo Obbligatortio! Controllare lunghezza " + strerr); 
        return false;
    } 
  return true;
}

function chknumlung(str, min, max, lungmin, lungmax, strerr)
{
if (chknum(str, min, max, strerr) == false ) return false;
if (chklung(str, lungmin, lungmax, strerr) == false ) return false;
return true;
}

function chknum(str, min, max, strerr)
{
   if (strerr == "") strerr="Telefono e CAP.";
  
  if (str == "") 
    {
		alert("Campo Numerico Obbligatortio! Controllare valore " + strerr); 
        return false;
    } 
  for (var i = 0; i < str.length; i++) 
      { 
         var ch = str.substring(i, i + 1);
         if (ch < "0" || ch > "9")
              { 
	                alert("Inserire Valori Numerici! Controllare valore " + strerr); 
					return false;
               } 
      }
  var val = parseInt(str, 10); 
  if ((val < min) || (val > max)) 
    { 
		alert("Inserire Valori Corretti! Grazie."); 
		return false;
     } 
  return true;
}


function chkusrpass(str, strerr)
{
  if (str == "") 
    {
		alert("Campo Obbligatortio! Grazie." + strerr);
        return false;
    } 
  for (var i = 0; i < str.length; i++) 
      { 
		var ch = str.substring(i, i + 1);
		if (ch < "0" || ch > "9") 
			{
			if (ch < "a" || ch > "z") 
				{
					if (ch < "A" || ch > "Z")
						{
							if (ch == "!" || ch == "?" || ch == "@")
  								{
									continue;
								}
							else
								{
					                alert("Inserire Valori Corretti! Grazie." + strerr); 
									return false;
								}
						}
	        	}
        	}
      }
	return true;
}

function chkalf(str)
{
  if (str == "") 
    {
		alert("Campo Obbligatortio! Grazie."); 
        return false;
    } 
  for (var i = 0; i < str.length; i++) 
      { 
		var ch = str.substring(i, i + 1);
		if (ch < "a" || ch > "z") 
			{
				if (ch < "A" || ch > "Z")
					{
						if (ch == "À" || ch == "È" || ch == "É" || ch == "Ì" || ch == "Ò" || ch == "Ù" || ch == "à" || ch == "è" || ch == "é" || ch == "ì" || ch == "ò" || ch == "ù")
  							{
								continue;
							}
						else
							{
								alert("Inserire Valori Corretti! Grazie."); 
								return false;
							}
					}
	        }
      }
	return true;
}

function chkalfnum(str)
{
  if (str == "") 
    {
		alert("Campo Obbligatortio! Grazie."); 
        return false;
    } 
  for (var i = 0; i < str.length; i++) 
      { 
		var ch = str.substring(i, i + 1);
		if (ch < "0" || ch > "9") 
			{
			if (ch < "a" || ch > "z") 
				{
					if (ch < "A" || ch > "Z")
						{
							if (ch == "À" || ch == "È" || ch == "É" || ch == "Ì" || ch == "Ò" || ch == "Ù" || ch == "à" || ch == "è" || ch == "é" || ch == "ì" || ch == "ò" || ch == "ù")
  								{
									continue;
								}
							else
								{
					                alert("Inserire Valori Corretti! Grazie."); 
									return false;
								}
						}
	        	}
        	}
      }
	return true;
}

function chkprov(str)
{
  if (str == "") 
    {
		alert("Campo Alfabetico Obbligatortio! Controllare Sigla Provincia."); 
        return false;
    } 
  for (var i = 0; i < str.length; i++) 
      { 
		var ch = str.substring(i, i + 1);
		if (ch < "a" || ch > "z") 
			{
				if (ch < "A" || ch > "Z")
					{
						alert("Inserire Valori Alfabetici!  Controllare Sigla Provincia."); 
						return false;
					}
	        }
      }
	return true;
}

function chknome(str)
{
  if (str == "" || str.length == 0) 
    {
		alert("Campo Obbligatortio! Controllare Cognome, Nome o Comune."); 
        return false;
    } 
  for (var i = 0; i < str.length; i++) 
      { 
		var ch = str.substring(i, i + 1);
		if (ch < "a" || ch > "z") 
			{
				if (ch < "A" || ch > "Z")
					{
						if (ch == " " || ch == "À" || ch == "È" || ch == "É" || ch == "Ì" || ch == "Ò" || ch == "Ù" || ch == "à" || ch == "è" || ch == "é" || ch == "ì" || ch == "ò" || ch == "ù")
  							{
								continue;
							}
						else
							{
								alert("Inserire Valori Corretti! Controllare Cognome, Nome o Comune."); 
								return false;
							}
					}
	        }
      }
	return true;
}

function chkvia(str)
{
  if (str == "") 
    {
		alert("Campo Obbligatortio! Controllare Indirizzo."); 
        return false;
    } 
  for (var i = 0; i < str.length; i++) 
      { 
		var ch = str.substring(i, i + 1);
		if (ch < "0" || ch > "9") 
			{
			if (ch < "a" || ch > "z") 
				{
					if (ch < "A" || ch > "Z")
						{
							if (ch == " " || ch == "À" || ch == "È" || ch == "É" || ch == "Ì" || ch == "Ò" || ch == "Ù" || ch == "à" || ch == "è" || ch == "é" || ch == "ì" || ch == "ò" || ch == "ù" || ch == ",")
  								{
									continue;
								}
							else
								{
									alert("Inserire Valori Corretti! Controllare Indirizzo."); 
									return false;
								}
						}
	        	}
        	}
      }
	return true;
}

function chkcfiva(str)
{
  if (str == "") 
    {
		alert("Campo Obbligatortio! Controllare Codice Fiscale o Partita IVA."); 
        return false;
    } 
  if (str.length == 11) 
    {
		if (!chknum(str))
			{ 
				return false;
			}
		else
			{ 
				return true;  
			}
    } 
	else
    {
  		if (str.length != 16) 
    		{
				alert("Campo Obbligatortio! Controllare Codice Fiscale o Partita IVA."); 
        		return false;
    		}
		else	 
    		{
			 	for (var i = 0; i < str.length; i++) 
     				{ 
						var ch = str.substring(i, i + 1);
						if ( i == 6 || i == 7 || i == 9 || i == 10 || i == 12 || i == 13 || i == 14)
							{
								if (ch < "0" || ch > "9") 
									{
										alert("Campo Obbligatortio! Grazie."); 
        								return false;
									}
							}
						else
							{
								if (ch < "A" || ch > "Z") 
									{
										alert("Campo Obbligatortio! Grazie."); 
        								return false;
									}
							}
	    			}
				return true;
    		}
    } 
}

function chkmail(str)
{
  var indok = 0;
  var indp = 0;
  var indat = 0;
  if (str == "") 
    {
		alert("Campo Obbligatortio! Controllare indirizzo e-mail."); 
        return false;
    } 
  for (var i = 0; i < str.length; i++) 
      { 
		var ch = str.substring(i, i + 1);
		if (ch < "0" || ch > "9") 
			{
			if (ch < "a" || ch > "z") 
				{
					if (ch < "A" || ch > "Z")
						{
							if (ch == "." || ch == "@"  || ch == "_"  || ch == "-")
  								{
									if (ch == ".") 
									{
										indp++;
										indok=str.length - i;
										indok--;
										if (indok < 2) indat=2;
									}
									if (ch == "@")
									{
										indat++;
										indok=str.length - i;
										indok--;
										if (indok < 4) indat=2;
									}
								}
							else
								{
					                alert("Inserire Valori Corretti! Controllare indirizzo e-mail."); 
									return false;
								}
						}
	        	}
        	}
      }
	if (indp != 0 && indat == 1)
	{
		return true;
	}
	else
	{
        alert("Inserire Valori Corretti! Controllare indirizzo e-mail."); 
		return false;
	}
}

function chksex(str, val1, val2)
{
  if (str == "") 
    {
       return true;
    } 
  if (str !=val1 && str !=val2)
    { 
       alert("Inserire solo i valori ammessi ! Controllare campo sesso."); 
       return false;
     } 
  return true;
}

function chkmese(val)
{
  mese=val+1;
  if (chkbisesto()) 
       return true 
    else 
       return false;
}

function chkgiorno(val)
{
giorno=val+1;
if (chkbisesto()) 
       return true
   else 
       return false;
}

function chkanno(val)
{
anno=val;
if (chkbisesto()) 
       return true 
   else 
       return false;
}

function chkdata()
{
if (chkbisesto()) 
    {
       valore=1;
       return true; 
    }
   else 
    {
       valore=2;
       return false; 
    }
}

function chkbisesto()
{
  if (giorno == 1 && mese == 1 && anno == 1900) 
     return true;
  if (giorno == 0 || mese == 0 || anno == 0) 
   {
      alert ("Impostare correttamente la data !! oppure valorizzarla con Gennaio 01 1900 "); 
      return false;
   }
  if ((mese == 4 || mese ==6 || mese == 9 || mese == 11) && giorno > 30) 
   {
      alert ("Impostare correttamente la data !! oppure valorizzarla con Gennaio 01 1900 "); 
      return false;
   }
  if (mese == 2 && giorno > 29) 
   {
      alert ("Impostare correttamente la data !! oppure valorizzarla con Gennaio 01 1900 "); 
      return false;
   }
if (mese == 2) 
   {
      annobis=(anno/4);
      annobis=parseInt(annobis, 10); 
      annobis=(annobis*4);

      if (annobis < anno && giorno > 28)  
       {
         alert ("Impostare correttamente la data !! oppure valorizzarla con Gennaio 01 1900 "); 
         return false;
       }
   }
 return true;
}

function chkall(IDKey, Ordine, Titolo, Descrizione, Immagine, DescLink, UrlLink, DescLinkDoc, UrlLinkDoc, DescLinkPg, TitPg, DescPg, ImgPg)
{
if (chknumlung(IDKey, '01', '99', '2', '2', 'Identificativo') == false ) return false;
if (chknumlung(Ordine, '01', '99', '2', '2', 'Ordine News') == false ) return false;
if (chkfill(Titolo, 'Titolo news') == false ) return false;
if (chkfill(Descrizione, 'Descriczione breve news') == 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;
	}

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 chkord(IDKey, Ordine, Titolo, Descrizione)
{
if (chknumlung(IDKey, '01', '99', '2', '2', 'Identificativo') == false ) return false;
if (chknumlung(Ordine, '01', '99', '2', '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 chknwl(IDKey, Titolo, Flink1)
{
if (chknum(IDKey, '01', '99', 'Identificativo') == false ) return false;
if (chkfill(Titolo, 'Titolo news') == false ) return false;
if (chkvuoto(Flink1, 'Documento News Letter') == false ) return false;

return true;
}

function chkallalb(IDKey, Ordine, Titolo, Descrizione, Nome, Tipo, Numero)
{
if (chknumlung(IDKey, '01', '99', '2', '2', 'Identificativo') == false ) return false;
if (chknumlung(Ordine, '01', '99', '2', '2', 'Ordine News') == false ) return false;
if (chkfill(Titolo, 'Titolo news') == false ) return false;
if (chkfill(Descrizione, 'Descriczione breve news') == false ) return false;

if (chklung(Nome, '5', '5', 'Nome Album') == false ) return false;
if (chklung(Tipo, '3', '4', 'Formato') == false ) return false;
if (chknum(Numero, '1', '100', 'Numero fotografie') == false ) return false;
	
return true;
}

function chkamm(User, Passw)
{

if (chkusrpass(User, 'User') == false ) return false;
if (chklung(User, '8', '8', 'User') == false ) return false;
if (chkusrpass(Passw, 'Password') == false ) return false;
if (chklung(Passw, '8', '8', 'Password') == false ) return false;

return true;
}

function chkfoto(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 chkbank(Ric, Ris, Shoplogin)
{
if (Ric.length == 0) return false;
if (Ris.length == 0) return false;
Ric = Ric.toUpperCase();
Ris = Ris.toUpperCase();

Slc = Ric.lastIndexOf("\\");
Pun = Ric.lastIndexOf(".");
Pun++;
Slc++;
Len = 0;
NomeRic = ""
ExtRic = ""
for (ind = Slc; ind <= Pun; ind++)
{
	if (Ric.substr(ind, 1) == "_" )
	{
		if (Len == 0) Len = ind;
	}
} 
if (Len > Slc) 
{
	Len = Len - Slc;
	NomeRic = Ric.substr(Slc, Len);
}
Len = Ric.length;
if (Len > Pun) 
{
	Len = Len - Pun;
	ExtRic = Ric.substr(Pun, Len);
}
if (ExtRic != "RIC") return false;
if (NomeRic == "") return false;

Slc = Ris.lastIndexOf("\\");
Pun = Ris.lastIndexOf(".");
Pun++;
Slc++;
Len = 0;
NomeRis = ""
ExtRis = ""
for (ind = Slc; ind <= Pun; ind++)
{
	if (Ris.substr(ind, 1) == "_" )
	{
		if (Len == 0) Len = ind;
	}
} 
if (Len > Slc) 
{
	Len = Len - Slc;
	NomeRis = Ris.substr(Slc, Len);
}
Len = Ris.length;
if (Len > Pun) 
{
	Len = Len - Pun;
	ExtRis = Ris.substr(Pun, Len);
}
if (ExtRis != "RIS") return false;
if (NomeRis == "") return false;

if (NomeRic != Shoplogin) return false;
if (NomeRis != Shoplogin) return false;
return true; 
}

function chkgare(IDKey, Ordine, Titolo, Descrizione, Immagine, DescLink, UrlLink, DescLinkDoc, UrlLinkDoc)
{
if (chknumlung(IDKey, '01', '99', '2', '2', 'Identificativo') == false ) return false;
if (chknumlung(Ordine, '01', '99', '2', '2', 'Ordine News') == false ) return false;
if (chkfill(Titolo, 'Titolo news') == false ) return false;
if (chkfill(Descrizione, 'Descriczione breve news') == 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 fchknome(str)
{
  if (str == "" || str.length == 0) return true;
  if (chknome(str) == false ) return false;
  return true;
}

function fchkmail(str)
{
  if (str == "" || str.length == 0) return true;
  if (chkmail(str) == false ) return false;
  return true;
}

function fchknum(str)
{
  if (str == "" || str.length == 0) return true;
  for (var i = 0; i < str.length; i++) 
      { 
         var ch = str.substring(i, i + 1);
         if (ch < "0" || ch > "9")
              { 
	                alert("Inserire Valori Numerici! Controllare valore ShopID"); 
					return false;
               } 
      }
  return true;
}

function chkfil(Ric, Ris)
{
if (Ric.length == 0) return false;
if (Ris.length == 0) return false;
Ric = Ric.toUpperCase();
Ris = Ris.toUpperCase();
Len = Ric.length;
Slc = Ric.lastIndexOf("\\");
Slc++;
Nomearch = "";
if (Len > Slc) 
{
	Len = Len - Slc;
	Nomearch = Ric.substr(Slc, Len);
}
  
if (Nomearch != Ris) return false;
return true; 
}


