
function ingresso(){
         if (navigator.cookieEnabled == 0)
{
    var nick = prompt('Immetti il tuo nick name','');
    var pasw = prompt('Immetti la tua password (visitatori : AAAb293)','');
paswFor=pasw.substring(0,4); 
pswNome(pasw)   
loadMenu(paswFor)
 
}  	   
var now = new Date()
fixDate(now)
now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000)
var nome="cz1uhlk"
var visits = getCookie(nome)

if (!visits)
{
        visits = 1
var giorni = 90;
var now = new Date()
fixDate(now)
var errore = 1 

var nick = prompt('Immetti il tuo nick name','');
    pasw = prompt('Immetti la tua password (visitatori : AAAb293)','');
  
	if (pasw == "AAAb293") giorni = 3;
pswNome(pasw)
	if (errore == 0){
var id = nick + ":" + pasw.substring(0,4);
now.setTime(now.getTime() + giorni * 24 * 60 * 60 * 1000);
setCookie(nome, id, visits, now);
var user = nick;
welcome(user,visits);	
var paswFor=pasw.substring(0,4);
loadMenu(paswFor);
}				
}		
else
{
var visits = getCookie(nome)
    visits = parseInt(visits,10) + 1 
	var endUser = id.indexOf(":")
    var user = id.substring(0,endUser)
	var pasw=id.substring(endUser+1,id.lenght)
	var giorni = 90;
	if (pasw == "AAAb") giorni = 3;
var now = new Date()
fixDate(now)
now.setTime(now.getTime() + giorni * 24 * 60 * 60 * 1000)
setCookie(nome, id, visits, now)
welcome(user,visits)
loadMenu(pasw)
}

var caution = false
function setCookie(name, id, value, expires, path, domain, secure) {
        var curCookie = id + "/" + name + "=" + escape(value) +
                ((expires) ? "; expires=" + expires.toGMTString() : "") +
                ((path) ? "; path=" + path : "") +
                ((domain) ? "; domain=" + domain : "") +
                ((secure) ? "; secure" : "")
        if (!caution || (name + "=" + escape(value)).length <= 4000)
                document.cookie = curCookie
        else
                if (confirm("Cookie exceeds 4KB and will be cut!"))
                        document.cookie = curCookie
}


function getCookie(nome) {
       var fineId  = "/"
	   var n1 = document.cookie.indexOf(fineId)
	   id = document.cookie.substring(0,n1)
	   nome_2 = document.cookie.substring(n1+1,n1+8)
        if (nome_2 != nome)
		return null  
		var prefix = name + "="
        var cookieStartIndex = document.cookie.indexOf(prefix)
		        if (cookieStartIndex == -1)
                return null
        var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length)
        if (cookieEndIndex == -1)
               cookieEndIndex = document.cookie.length
         visits = unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex))
   
        return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex))
}


function deleteCookie(name, path, domain) {
        if (getCookie(name)) {
                document.cookie = name + "=" + 
                ((path) ? "; path=" + path : "") +
                ((domain) ? "; domain=" + domain : "") +
                "; expires=Thu, 01-Jan-07 00:00:01 GMT"
        }
}


function fixDate(date) {
        var base = new Date(0)
        var skew = base.getTime()
        if (skew > 0)
                date.setTime(date.getTime() - skew)
}


function pswNome(pasw){
errore = 1
    if (!pasw)
	     {
         alert("PASSWORD NON VALIDA")
		 location.href="errore.html"
		 } 
   else
  {
var somma = 0;
var len = pasw.length
var ceckA = Number(pasw.substring(4,len));
    for (j = 0; j<4; j++)
	       {   
       var car = pasw.charAt(j); 
       var value = pasw.charCodeAt(j);
       somma = somma + value 
            }
		sommaN = Number(somma)
      if (ceckA != sommaN)
	        {
	       alert(" LA PASSWORD NON E' CORRETTA")
		   location.href="errore.html"	
		    }
		else
		   errore = 0
		       return errore
    }	
}


function welcome(user,visits){
var time = new Date()
var ora = time.getHours()
var msg = " Buon giorno  "
      if (ora > 14)
	       msg = "Buon pomeriggio  "
	  if (ora > 19 )
	       msg = "Buona sera  " 	    
var userUp = user.toUpperCase()
document.write('<br><center><font size = "4" color ="#0000FF">' + msg + '</font>') 
document.write('<font size="5" color="#FF0000">' + userUp.bold() + '</font>')
document.write(' <font size = "3" color ="#0000FF"> questa è la tua visita n. ' + visits +'</font></center><br>')
}


function loadMenu(pasw){

document.write('<body bgcolor="#00FFFF">');

var file = '"iscritti/a06'+pasw+'.html" ';
var adr= '<iframe src=' + file;
document.write(adr)
document.write('align="center" width="100%" height="100%">')  
document.write("</iframe></center>")

document.write('<center>' + '<br>')
document.write('<a href="http://www.charterpesca.net">')
document.write(" Torna al Sito")
document.write('</a>')
}
}


