//--Funzioni orario
  var dayarray=new 
    Array("Domenica","Lunedì","Martedì","Mercoledì","Giovedì","Venerdì","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<=9)
      hours="0"+hours

    if (minutes<=9)
      minutes="0"+minutes

    if (seconds<=9)
      seconds="0"+seconds

    var cdate="<font color='000080' face='Tahoma' size='1'>"
    var cdate=cdate+dayarray[day]+", "+daym+" "+montharray[month]+" "+year+", ore "
    var cdate=cdate+hours+":"+minutes+":"+seconds+"</font>"

    document.getElementById("clock").innerHTML=cdate
  }
           
  getthedate()
              
  function goforit()
  {
    setInterval("getthedate()",1000)
  }
//---------------------------------------------------------------------

//--Status Bar
var scrtxt="byluciani.com - soluzioni ASP/VBScript - FREE ASP script";
//statusbar();

function statusbar(){
  window.status = scrtxt;
  setTimeout("statusbar()",150);
  return true;
}
//---------------------------------------------------------------------

//--Setta come homepage
function home() {  
  //if(document.all)
    //document.body.style.behavior='url(#default#homepage)';
    document.body.setHomePage('http://www.byluciani.com');
}
//---------------------------------------------------------------------

//--Funzioni per guestbook
function byluciani() {
	return;
}	

function formatotesto(code, promptText, InsertText) {

	if (code != "") {
		insertCode = prompt(promptText + "\n[" + code + "]xxx[/" + code + "]", InsertText);
			if ((insertCode != null) && (insertCode != "")){
				document.firma.testo.value += "[" + code + "]" + insertCode + "[/"+ code + "] ";
			}
	}		
	document.firma.testo.focus();
}

function emoticon(tipo) {	
		document.firma.testo.value += tipo;
		document.firma.testo.focus();
}
//---------------------------------------------------------------------

//--Funzione per gestire le POPUP      
function DoPopUp(URL,Name,X,Y,Center,Resizable,ScrollBars){

  //Center = yes or no
  //Resizable = yes or no
  //ScrollBars = yes or no

  if (Center == 'yes'){
    var PopUpX = (screen.width/2)-(parseInt(X)/2);
    var PopUpY = (screen.height/2)-(parseInt(Y)/2);
    var pos = ",left="+PopUpX+",top="+PopUpY;
  }else{
    var pos = "";
  }
  PopUpWindow = window.open(URL,Name,'scrollbars='+ScrollBars+',resizable='+Resizable+',width='+X+',height='+Y+pos);
}
//--------------------------------------------------------------------

//--Esecuzione di un form (submit)
function go(frm){
  frm.submit();
}
//--------------------------------------------------------------------

//--Gestione rollover
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//--------------------------------------------------------------------


//--Calcolo del residuo caratteri delle textarea
function residuo(info, n, max) 
{
  Lunghezza = info.value.length;
  if (Lunghezza > max ) {
    info.value = info.value.substring(0,max);
  }
  n.value = max - info.value.length;    
}
//--------------------------------------------------------------------


//--Funzioni per gestire UBBCode delle news
function x () {
  return;
}

function DoPrompt(action, casellatesto) {
	var revisedMessage;
	var currentMessage = casellatesto.value;

	if (action == "url") {
	  var thisURL = prompt("Inserite l'url completa dell'indirizzo che desiderate aggiungere.", "http://");
    if((thisURL!="")&&(thisURL!=null)){
      var urlUBBCode = "[URL]"+thisURL+"[/URL]";
	    revisedMessage = currentMessage+urlUBBCode;
	    casellatesto.value=revisedMessage;
	  }
	  casellatesto.focus();
	  return;
	}

	if (action == "email") {
  	var thisEmail = prompt("Inserite l'indirizzo e-mail che desiderate aggiungere.", "");
    if((thisEmail!="")&&(thisEmail!=null)){  	
	    var emailUBBCode = "[URL]"+thisEmail+"[/URL]";
	    revisedMessage = currentMessage+emailUBBCode;
	    casellatesto.value=revisedMessage;
	  }	    
	  casellatesto.focus();
	  return;
	}

	if (action == "bold") {
	  var thisBold = prompt("Inserite il testo che desiderate in grassetto.", "");
    if((thisBold!="")&&(thisBold!=null)){	  
	    var boldUBBCode = "[B]"+thisBold+"[/B]";
	    revisedMessage = currentMessage+boldUBBCode;
	    casellatesto.value=revisedMessage;
	  }	    
	  casellatesto.focus();
	  return;
	}

	if (action == "italics") {
	  var thisItal = prompt("Inserite il testo che desiderate in corsivo.", "");
    if((thisItal!="")&&(thisItal!=null)){	  
	    var italUBBCode = "[I]"+thisItal+"[/I]";
	    revisedMessage = currentMessage+italUBBCode;
	    casellatesto.value=revisedMessage;
	  }	    
	  casellatesto.focus();
	  return;
	}
}
//--------------------------------------------------------------------

//--Funzione per Poll
function OneOptionChecked()
{
		var i;
		
		for (i = 0; i < document.frmPoll.radPoll.length; i++)
			if (document.frmPoll.radPoll[i].checked) return true;
		
		alert("Devi scegliere una risposta prima di votare");
		return false;
}
//--------------------------------------------------------------------

//--Funzione per NewsLetters
function Trim(stringa)
{
   reTrim=/\s+$|^\s+/g;
   return stringa.replace(reTrim,"");
}

function checkMail(act)
{
	if (Trim(document.newsletters.mail.value)==""){
		alert("Devi inserire una E-Mail.\nbyluciani.com")
	}else{
    with (document.newsletters)
    {	
      apos=mail.value.indexOf("@"); 
      dotpos=mail.value.lastIndexOf(".");
      lastpos=mail.value.length-1;	
      if(apos<1 || dotpos-apos<2 || lastpos-dotpos>3 || lastpos-dotpos<2){
        alert("L'indirizzo E-Mail inserito non è valido.\nbyluciani.com")
      }else{
        if(act==1){
          action.value="iscrivi"
        }else{
          action.value="cancella"
        }  
  	    submit()
  	  }
	  }
  }
}
//--------------------------------------------------------------------

//--Funzione generali per convalida form
function isInteger(s){
	var i;
  for (i = 0; i < s.length; i++){   
    var c = s.charAt(i);
    if (((c < "0") || (c > "9"))) return false;
  }
  return true;
}

function stripCharsInBag(s, bag){
	var i;
  var returnString = "";
  for (i = 0; i < s.length; i++){   
    var c = s.charAt(i);
    if (bag.indexOf(c) == -1) returnString += c;
  }
  return returnString;
}

function daysInFebruary (year){
  return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
  } 
  return this
}

function validDate(formField, dtCh){
  var minYear=2003;
  var maxYear=2100;
  var dtStr = formField.value;
	var daysInMonth = DaysArray(12);
	var pos1=dtStr.indexOf(dtCh);
	var pos2=dtStr.indexOf(dtCh,pos1+1);
	var strDay=dtStr.substring(0,pos1);
	var strMonth=dtStr.substring(pos1+1,pos2);
	var strYear=dtStr.substring(pos2+1);
	strYr=strYear;
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth);
	day=parseInt(strDay);
	year=parseInt(strYr);
	if (pos1==-1 || pos2==-1 || dtStr.length<10){
		alert("Prego inserire una data valida\nLa data deve essere nel formato: gg/mm/aaaa");
		formField.focus();
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Prego inserire un giorno valido (2 cifre gg)\nErrato: "+strDay);
		formField.focus();
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Prego inserire un mese valido (2 cifre mm)\nErrato: "+strMonth);
		formField.focus();
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Prego inserire un anno valido tra "+minYear+" e "+maxYear+" (4 cifre aaaa)\nErrato: "+strYear);
		formField.focus();
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Prego inserire una data valida\nLa data deve essere nel formato: gg/mm/aaaa");
		formField.focus();
		return false
	}
return true
}

function validTime(formField, tmCh){
  var tmStr = formField.value;
	var pos1=tmStr.indexOf(tmCh);
	var pos2=tmStr.indexOf(tmCh,pos1+1);
	var strHour=tmStr.substring(0,pos1);
	var strMinute=tmStr.substring(pos1+1,pos2);
	var strSecond=tmStr.substring(pos2+1);
	if (strHour.charAt(0)=="0" && strHour.length>1) strHour=strHour.substring(1)
	if (strMinute.charAt(0)=="0" && strMinute.length>1) strMinute=strMinute.substring(1)
	if (strSecond.charAt(0)=="0" && strSecond.length>1) strSecond=strSecond.substring(1)	
	hour=parseInt(strHour);
	minute=parseInt(strMinute);
	second=parseInt(strSecond);
	if (pos1==-1 || pos2==-1 || tmStr.length<8){
		alert("Prego inserire un orario valido\nL'ora deve essere nel formato: hh.mm.ss");
		formField.focus();
		return false
	}
	if (strHour.length<1 || hour>23){
		alert("Prego inserire una ora valida tra 00 e 23 (2 cifre hh)\nErrato: "+strHour);
		formField.focus();
		return false
	}
	if (strMinute.length<1 || minute>59){
		alert("Prego inserire un minuto valido tra 00 e 59 (2 cifre mm)\nErrato: "+strMinute);
		formField.focus();
		return false
	}
	if (strSecond.length<1 || second>59){
		alert("Prego inserire un secondo valido tra 00 e 59 (2 cifre ss)\nErrato: "+strSecond);
		formField.focus();
		return false
	}
	if (tmStr.indexOf(tmCh,pos2+1)!=-1 || isInteger(stripCharsInBag(tmStr, tmCh))==false){
		alert("Prego inserire un orario valido\nL'ora deve essere nel formato: hh.mm.ss");
		formField.focus();
		return false
	}
return true
}

function validRequired(formField,fieldLabel)
{
	var result = true;
	
	if(Trim(formField.value) == "")
	{
		alert('Prego inserire un valore per il campo "' + fieldLabel +'"');
		formField.focus();
		result = false;
	}
	return result;
}

function validNumber(formField,fieldLabel)
{
	var result = true;
	
	if(!isInteger(formField.value))
	{
		alert('Prego inserire un numero per il campo "' + fieldLabel +'"');
		formField.focus();
		result = false;
	}
	return result;
}
//--------------------------------------------------------------------

//--Funzione per form amministrazione ASP
function validateFormASP(theForm){
	if(!validRequired(theForm.titolo,"Titolo"))
		return false;
	if(!validRequired(theForm.testo,"Testo"))
		return false;
	if(!validDate(theForm.data, '/'))
		return false;
	if(!validNumber(theForm.letta, "Letta"))
		return false;		
	if(!validNumber(theForm.totalevoti, "Totale Voti"))
		return false;	
	if(!validNumber(theForm.totalevotazioni, "Totale Votazioni"))
		return false;			
	return true;
}
//--------------------------------------------------------------------

//--Funzione per form OpenForum
function validateFormOpenForum(theForm){
	if(!validRequired(theForm.txtTitle,"Oggetto"))
		return false;
	if(!validRequired(theForm.txtBody,"Messaggio"))
		return false;
	if(!validRequired(theForm.txtUser,"Firma"))
		return false;		
	return true;
}
//--------------------------------------------------------------------