// JavaScript Document

/* POP UP */

function Popup(apri, fh , fw) {
	var h = fh;
	var w = fw;
	var l = Math.floor((screen.width-w)/2);
	var t = Math.floor((screen.height-h)/2);
	var stile = "width=" + w + ",height=" + h + ",top=" + t + ",left=" + l + ", status=no, menubar=no, toolbar=no scrollbar=no";
	window.open(apri, "", stile);
  }
  
//Inizio funzione contatore caratteri nella textarea

var ns6=document.getElementById&&!document.all

function restrictinput(maxlength,e,placeholder){
if (window.event&&event.srcElement.value.length>=maxlength)
return false
else if (e.target&&e.target==eval(placeholder)&&e.target.value.length>=maxlength){
var pressedkey=/[a-zA-Z0-9\.\,\/]/ //detect alphanumeric keys
if (pressedkey.test(String.fromCharCode(e.which)))
e.stopPropagation()
}
}

function countlimit(maxlength,e,placeholder){
var theform=eval(placeholder)
var lengthleft=maxlength-theform.value.length
var placeholderobj=document.all? document.all[placeholder] : document.getElementById(placeholder)
if (window.event||e.target&&e.target==eval(placeholder)){
if (lengthleft<0)
theform.value=theform.value.substring(0,maxlength)
placeholderobj.innerHTML=lengthleft
}
}

function displaylimit(thename, theid, thelimit){
var theform=theid!=""? document.getElementById(theid) : thename
var limit_text='Caratteri rimanenti: <span id="'+theform.toString()+'">'+thelimit+'</span> '
if (document.all||ns6)
document.write(limit_text)
if (document.all){
eval(theform).onkeypress=function(){ return restrictinput(thelimit,event,theform)}
eval(theform).onkeyup=function(){ countlimit(thelimit,event,theform)}
}
else if (ns6){
document.body.addEventListener('keypress', function(event) { restrictinput(thelimit,event,theform) }, true); 
document.body.addEventListener('keyup', function(event) { countlimit(thelimit,event,theform) }, true); 
}
}

// Cambio Grandezza Testo

function setActiveStyleSheet(title, reset) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
  if (reset == 1) {
	  createCookie("nstile", title, 365);
  } 

}

function setStyle() {
	var style = readCookie("nstile");
	if (style != null) {
		setActiveStyleSheet(style, 0);
	}
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";

  document.cookie = name+"="+value+expires+"; path=/;";

}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

// Data & Ora

var dayarray=new Array("Domenica","Lunedi","Martedi","Mercoledi","Giovedi","Venerdi","Sabato")
var montharray=new Array("Gennaio","Febbraio","Marzo","Aprile","Maggio","Giugno","Luglio","Agosto","Settembre","Ottobre","Novembre","Dicembre")

function getthedate(){
    var mydate=new Date();
    var year=mydate.getYear();
    if (year < 1000) year+=1900;
    var day=mydate.getDay();
    var month=mydate.getMonth();
    var daym=mydate.getDate();
    if (daym < 10) daym="0"+daym;
    var hours=mydate.getHours();
    var minutes=mydate.getMinutes();
    var seconds=mydate.getSeconds();
    if (hours==0) hours=24;
    if (minutes<=9) minutes="0"+minutes;
    if (seconds<=9) seconds="0"+seconds;
    //change font size here
    var cdate=dayarray[day]+",&nbsp;"+daym+" "+montharray[month]+" "+year+"&nbsp;&nbsp;<strong>"+hours+":"+minutes+":"+seconds+"</strong>";
    if (document.layers) {
        // Netscape
        document.iclockNetsc.document.clockNetsc.document.write(cdate);
        document.iclockNetsc.document.clockNetsc.document.close();
    } else {
        // Others
        if (document.all) document.all.clock.innerHTML=cdate;
        else document.write(cdate);
    }
}

if (!document.all) getthedate();

function goforit(){
    if (document.layers) {
        setInterval("getthedate()",1000);
    } else {
        if (document.all) setInterval("getthedate()",1000);
    }
}

// -->