function apre(pagina,dimx,dimy)
{
	//debug
	//window.alert(pagina)
	nomeObjFinestra = "Sceltaimmagine"
	if (pagina.toLowerCase().indexOf("tavolozza_")!=-1)
	{
		nomeObjFinestra = "finTavolozza"
	}
	pagina=window.open(pagina,nomeObjFinestra,"toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width="+dimx+",height="+dimy+",left=80,top=0");
	pagina.focus();
}
 
 //Percorso relativo generale delle immagini
var imgs_0 = "img/"

//carico nelle variabili i nomi dei file di immagine
var img_trasparente = "img/trasparente.gif"

//cartella HOMEPAGE
var img_0_1 = imgs_0 + "accapo.gif"
var img_0_2 = imgs_0 + "aggiungi.gif"
var img_0_3 = imgs_0 + "ancora.gif"
var img_0_4 = imgs_0 + "corsivo.gif"
var img_0_5 = imgs_0 + "elimina2.gif"
var img_0_6 = imgs_0 + "fondo_blu.gif"
var img_0_7 = imgs_0 + "fondo_giallo.gif"
var img_0_8 = imgs_0 + "freccia_dx.gif"
var img_0_9 = imgs_0 + "freccia_sx.gif"
var img_0_10 = imgs_0 + "go_on.gif"
var img_0_11 = imgs_0 + "grassetto.gif"
var img_0_12 = imgs_0 + "icona_articolo_off.GIF"
var img_0_13 = imgs_0 + "icona_articolo_on.GIF"
var img_0_14 = imgs_0 + "immagine.gif"
var img_0_15 = imgs_0 + "ingrandisci.gif"
var img_0_16 = imgs_0 + "matitina.gif"
var img_0_17 = imgs_0 + "modifica2.gif"
var img_0_18 = imgs_0 + "riduci_a_icona.gif"
var img_0_19 = imgs_0 + "sottolineato.gif"


//settaggio dei colori Canali

var Colore_1 = "#006600"
var Colore_2 = "#669999"
var Colore_3 = "#FFAC00"
var Colore_4 = "#009999"
var Colore_5 = "#0099FF"
var Colore_6 = "#009933"
var Colore_7 = "#FFCC00"
var Colore_8 = "#006666"
var Colore_9 = "#FFFFFF"
var Colore_10 = "#FFFF99"
var Colore_11 = "#FFFFCC"
var Colore_12 = "#DEE8FC"

var separatore_data = '-';
var separatore_currency = '.';
var separatore_currency_decimale = ',';
var punto_decimale = '.';
var virgola_decimale = ',';
var separatore_orario='.';
var INTEGER_LIM_INF=-2147483648;
var INTEGER_LIM_SUP=+2147483647;
var SMALLINT_LIM_INF=-32768;
var SMALLINT_LIM_SUP=+32767;


//POSIZIONE CARATTERI
//Nota: il carattere b prima di ! è blank
//                          'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxb!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_'abcdefghijklmnopqrstuvwxyz{|}~xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
var allowed_chars_ridotto='0000000000000000000000000000000010000000000000001111111111000000000000000000000000000000000000010111111111111111111111111110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';
var allowed_chars='0000000000100100000000000000000011100111111111111111111111111111111111111111111111111111111000010111111111111111111111111110000010000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000011000000110011000011000001100000';
var textarea_chars='0000000000100100000000000000000011100111111111111111111111111111111111111111111111111111111000010111111111111111111111111110000010000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000011000000110011000011000001100000';
var  folder_chars='0000000000000000000000000000000011011111110111101111111111010100111111111111111111111111111000011111111111111111111111111110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';
var giorni_per_mese = new Array(13);
giorni_per_mese[1] = 31;
giorni_per_mese[2] = 29;   
giorni_per_mese[3] = 31;
giorni_per_mese[4] = 30;
giorni_per_mese[5] = 31;
giorni_per_mese[6] = 30;
giorni_per_mese[7] = 31;
giorni_per_mese[8] = 31;
giorni_per_mese[9] = 30;
giorni_per_mese[10] = 31;
giorni_per_mese[11] = 30;
giorni_per_mese[12] = 31;

function IsDigit()
{
  return (((event.keyCode >= 48) && (event.keyCode <= 57))||(event.keyCode == 46))
}

function check_data(fake)
	{
		//window.alert('entrata in java_controlla_data');
		
		var giorno='';
		giorno = fake.substring(0,2);
		//window.alert('giorno:' + giorno);
		
		var mese='';
		mese = fake.substring(3,5);
		//window.alert('mese:' + mese);

		var anno='';
		anno = fake.substring(6,10);
		if (anno <= 1000) {anno=''}
		//window.alert('anno:' + anno);

		data_inserita='';
		data_inserita=giorno + '/' + mese + '/' + anno
		var newDateObj = new Date(mese + '/' + giorno + '/' + anno);

		if (isNaN(newDateObj)) 
			{
				//window.alert('Inserire la Data nel formato GG/MM/AAAA');
				data_oggi = new Date();

				giorno='';
				giorno = data_oggi.getDate()
				giorno = '00' + giorno
				m = giorno.length
				giorno = giorno.substring(m-2,m)

				mese='';
				mese = data_oggi.getMonth() + 1
				mese = '00' + mese
				m = mese.length
				mese = mese.substring(m-2,m)

				anno='';
				anno = data_oggi.getFullYear()
				anno = '0000' + anno
				m = anno.length
				anno = anno.substring(m-4,m)
				
				uscita='';
 				uscita = giorno + '/' + mese + '/' + anno
				return false
			}
		else
			{
				giorno='';
				giorno = newDateObj.getDate()
				giorno = '00' + giorno
				m = giorno.length
				giorno = giorno.substring(m-2,m)

				mese='';
				mese = newDateObj.getMonth() + 1
				mese = '00' + mese
				m = mese.length
				mese = mese.substring(m-2,m)

				anno='';
				anno = newDateObj.getFullYear()
				anno = '0000' + anno
				m = anno.length
				anno = anno.substring(m-4,m)
				
				uscita='';
 				uscita = giorno + '/' + mese + '/' + anno

				if (uscita!=data_inserita)
					{
						//window.alert('Inserire la Data nel formato GG/MM/AAAA');
						//window.alert('data_inserita:'+data_inserita);
						//window.alert('uscita:'+uscita);
						data_oggi = new Date();

						giorno='';
						giorno = data_oggi.getDate()
						giorno = '00' + giorno
						m = giorno.length
						giorno = giorno.substring(m-2,m)

						mese='';
						mese = data_oggi.getMonth() + 1
						mese = '00' + mese
						m = mese.length
						mese = mese.substring(m-2,m)

						anno='';
						anno = data_oggi.getFullYear()
						anno = '0000' + anno
						m = anno.length
						anno = anno.substring(m-4,m)
				
						uscita='';
		 				uscita = giorno + '/' + mese + '/' + anno
						return false
					}
			}
		//mod
		//window.alert(uscita);
		return true;
	}

function errore (campo) {
        campo.focus();
        if ((campo.type=='text')||(campo.type=='textarea'))  campo.select();
        return false;
}

function errore_new (campo) {
        return false;
}

function vuoto (stringa) {
  return ((stringa == null)||(stringa.length==0))
}

function compatta (stringa) {
  s = new String('');
  for (i = 0; (stringa.charAt(i)==' ')&&(i<stringa.length); i++);
  for (j = stringa.length-1; (stringa.charAt(j)==' ')&&(j>=0); j--);
  s = stringa.substr(i,j-i+1);  
  return s;
}

function cifra (c) {
  return ((c >= '0') && (c <= '9'));
}

function StrToInt(stringa) {
    
 for (i = 0; i < stringa.length; i++) {   
  c = stringa.charAt(i);
  if (!cifra(c)) return -1;
 }
 i_stringa = parseInt(stringa,10);
 return i_stringa;
}

function ctrl_obbl(campo, label)
{
    s = compatta(campo.value);
    if (vuoto(s)) 
    {
      alert('Il campo '+label+' non puo\' essere lasciato vuoto');
      return errore(campo);
    }
    return true;
}

function ctrl_obbl_new(campo, label)
{
    s = compatta(campo.value);
    if (vuoto(s)) 
    {
      return 'Il campo '+label+' non puo\' essere lasciato vuoto\n'
    }
    return "";
}


function ctrl_caratteri (campo) {
    if (campo.type=='textarea')
        chars=textarea_chars;
    else
        chars=allowed_chars;
    for (i = 0; i < campo.value.length; i++){
        c = campo.value.charCodeAt(i);
        if (chars.charAt(c) == '0')
        {
        alert('L\'utilizzo del carattere '+campo.value.charAt(i)+' non e\' consentito');
        return errore(campo);
        }
    }
    return true;
  }

function ctrl_caratteri_ridotto (campo) {
    for (i = 0; i < campo.value.length; i++){
        c = campo.value.charCodeAt(i);
        if (allowed_chars_ridotto.charAt(c) != '1')
        {
        alert('Sono consentiti solo: lettere minuscole, cifre e il carattere "_"');
        return errore(campo);
        }
    }
    return true;
  }
  
function ctrl_spazi (campo, label) {
    
    for (i = 0; i < campo.value.length; i++){
        
        c = campo.value.charAt(i);
        if (c == ' ')
        {
        alert('Il campo '+label+' non puo\' contenere spazi');
        return errore(campo);
        }
    }
    return true;
  }

function is_integer (campo) { 
    s = compatta(campo.value);
    campo.value = s;
    if (!vuoto(s)) {
      if (s.charAt(0)=='+') {
        j = 1;
        campo.value = s.substr(1,s.length-1); 
      }
      else if (s.charAt(0)=='-')
        j = 1;
      else j = 0;
      for (i = j; i < s.length; i++)
      {   
        c = s.charAt(i);
        if (!cifra(c)) {
            alert('Il valore inserito non e\' un numero intero');
            return errore(campo);
        }
      }
      num = parseInt(s,10);
      if ((num<INTEGER_LIM_INF) || (num>INTEGER_LIM_SUP)) {
        alert('Il valore inserito non e\' compreso tra '+INTEGER_LIM_INF+' e '+INTEGER_LIM_SUP);
          return errore(campo);
      }    
    }
  return true;
}

function is_integer_compreso (campo, a, b, label)
{
  if((label=='') || (label==null)) label=''; else label=label+' ';
    if (!is_integer(campo)) return false;
    s=campo.value;
    if (!vuoto(s)) {
      num = parseInt(campo.value,10);
      if ((num<a) || (num>b)) {
        alert('Il valore del campo ' + label + 'non e\' compreso tra '+a+' e '+b);
        return errore(campo);
      }    
    }
  return true;
}

function is_integer_positivo (campo,flag_no_zero, label) {   
    if (!is_integer(campo)) 
         return errore(campo);

    s=campo.value;
    if (!vuoto(s)) {
      num = parseInt(campo.value,10);
      if (num<0) {
        alert(label+' deve essere un numero intero positivo.');
        return errore(campo);
      }    
      if ((flag_no_zero) && (num==0)) {
        alert('Il valore zero non e\' ammesso per '+label);
        return errore(campo);
      }    
    }
  return true;
}

function controllaData(campo) {
	var fake = compatta(campo.value)
	if (vuoto(fake))
	{
		alert('La data immessa non è valida.');
		return errore(campo);
	}
	else
	{
		
		var giorno='';
		giorno = fake.substring(0,2);
		
		var mese='';
		mese = fake.substring(3,5);

		var anno='';
		anno = fake.substring(6,10);
		if (anno <= 1000) {anno=''}

		data_inserita='';
		data_inserita=giorno + '/' + mese + '/' + anno
		var newDateObj = new Date(mese + '/' + giorno + '/' + anno);

		if (isNaN(newDateObj)) 
		{
			alert('La data immessa non è valida.');
			return errore(campo);
		}
		else
		{
			giorno='';
			giorno = newDateObj.getDate()
			giorno = '00' + giorno
			m = giorno.length
			giorno = giorno.substring(m-2,m)

			mese='';
			mese = newDateObj.getMonth() + 1
			mese = '00' + mese
			m = mese.length
			mese = mese.substring(m-2,m)

			anno='';
			anno = newDateObj.getFullYear()
			anno = '0000' + anno
			m = anno.length
			anno = anno.substring(m-4,m)
			
			uscita='';
			uscita = giorno + '/' + mese + '/' + anno
			//alert(uscita)
			//alert(data_inserita)
			if (uscita!=data_inserita)
			{
				alert('La data immessa non è valida.');
				return errore(campo);
				
			}
		}
	}
	return true;
}

function is_time (campo)
{
    //alert(campo)
	s = compatta(campo.value);
    if (!vuoto(s)) 
    {
      s = s.replace(/\.|:/gi,separatore_orario); // aggiungere i ':' e togliere quello che non serve
      h = s.indexOf(separatore_orario);
      if (h!=-1) {
       ora = s.substr(0,h);
       min = s.substr(h+1,s.length);
       if (min=='') min = '00';
      } else {
       ora = s;
       min = '00';
      }
      ora_i = StrToInt(ora);
      min_i = StrToInt(min);
      if ((ora_i<0) || (ora_i>24)) {
        alert('Ora non valida');
        return errore(campo);
      }
      if ((min_i<0) || (min_i>59)) {
        alert('Minuti non validi');
        return errore(campo);
      }
      if ((ora_i==24) && (min_i>0)) {
        alert('Minuti non validi');
        return errore(campo);
      }
      if ((ora_i<10) && (ora.length < 2)) ora='0'+ora;    
      if ((min_i<10) && (min.length < 2)) min='0'+min;    
      campo.value = ora+separatore_orario+min;
    }
  return true;
}

function is_time_valore (campo)
{
    //alert(campo)
	s = compatta(campo.value);
	if (!vuoto(s)) 
    {
      s = s.replace(/\.|:/gi,separatore_orario); // aggiungere i ':' e togliere quello che non serve
      h = s.indexOf(separatore_orario);
      if (h!=-1) {
       ora = s.substr(0,h);
       min = s.substr(h+1,s.length);
       if (min=='') min = '00';
      } else {
       ora = s;
       min = '00';
      }
      ora_i = StrToInt(ora);
      min_i = StrToInt(min);
      if ((ora_i<0) || (ora_i>24)) {
        return false;
      }
      if ((min_i<0) || (min_i>59)) {
        return false;
      }
      if ((ora_i==24) && (min_i>0)) {
        return false;
      }
      if ((ora_i<10) && (ora.length < 2)) ora='0'+ora;    
      if ((min_i<10) && (min.length < 2)) min='0'+min;    
      campo.value = ora+separatore_orario+min;
    }
  return true;
}

function is_time_compreso (campo,orainf,orasup,flag_no_estremi,label)
{
  if((label=='') || (label==null)) label=''; else label=label + ' ';
    if (orainf=='' || orainf==null) {orainf='00.00'; i_orainf=0; }
    else i_orainf=parseInt(orainf.substr(0,2) + orainf.substr(3,2),10);
    if (orasup=='' || orasup==null) {orasup='24.00'; i_orasup=2400; }
    else { 
     if (orasup=='00.00') i_orasup=2400;// sono le 00.00 cioe' le 24.00
     else i_orasup=parseInt(orasup.substr(0,2) + orasup.substr(3,2),10);
    }
    if (is_time(campo)) Icampo=parseInt(campo.value.substr(0,2) + campo.value.substr(3,2),10); else return false;
     s = campo.value;
     if (!vuoto(s)) {
      if ((Icampo<i_orainf) || (Icampo>i_orasup)) {
          if ((i_orainf!=0) && (i_orasup!=2400)) alert('Il valore del campo '+ label +'non e\' compreso tra '+ orainf +' e '+ orasup);
          if ((i_orainf==0) && (i_orasup!=2400)) alert('Il valore del campo ' + label + 'non e\' inferiore a '+ orasup);
          if ((i_orainf!=0) && (i_orasup==2400)) alert('Il valore del campo ' + label + 'non e\' superiore a '+ orainf);
          return errore(campo);
      }
      if (flag_no_estremi) {
        if (Icampo==i_orainf) {
          alert('Il valore del campo ' + label + 'non e\' superiore a '+ orainf);
          return errore(campo);
        }
        if (Icampo==i_orasup) {
          alert('Il valore del campo ' + label + 'non e\' inferiore a ' + orasup);
          return errore(campo);
        }
       }
     }
  return true;
} 

function is_decimal (campo, cifre, decimali)
{
    s = compatta(campo.value);
    campo.value = s;
    if (!vuoto(s)) {
      if (s.charAt(0)=='+') {
        j = 1;
        campo.value = s.substr(1,s.length-1); 
      }
      else if (s.charAt(0)=='-')
        j = 1;
      else j = 0;
      h = s.indexOf(punto_decimale);
      k = s.indexOf(virgola_decimale);
      if ((h > -1) && (k > -1))
         {
          alert('Il valore inserito non e\' numerico');
          return errore(campo);
         } 
      else
         {     
          if (k > -1) {
              h=k;
              s=s.substr(0, k)+punto_decimale+s.substr(k+1, s.length);
          }  
          for (i = j; i < s.length; i++) {
            if (i!=h) {
               c = s.charAt(i);
               if (!cifra(c)) {
                  alert('Il valore inserito non e\' numerico');
                  return errore(campo);
                  }
               } 
            }
          }
      if (h==-1) 
      {
        if (s.length-j>(cifre-decimali)) {
          alert('Il valore inserito e\' un intero con piu\' di '+(cifre-decimali)+' cifre');
          return errore(campo);
        }
      }
      else     
      {
         intero = s.substr(j,h);
         decimale = s.substr(h+1, s.length-h-1);
         if (s.length-1-j>cifre) {
           alert('Il valore inserito ha piu\' di '+cifre+' cifre');
           return errore(campo);
         }
        if (intero.length>(cifre-decimali)) {
          alert('Il valore inserito ha piu\' di '+(cifre-decimali)+' cifre per la parte intera');
          return errore(campo);
        }
        if (decimale.length>decimali) {
          alert('Il valore inserito ha piu\' di '+decimali+' cifre decimali');
          return errore(campo);
        }
      }
    }
  return true;
}

function is_decimal_positivo (campo, cifre, decimali, flag_no_zero) {   
    if (!is_decimal(campo, cifre, decimali)) return errore(campo);
    s = campo.value;
    if (!vuoto(s)) {
      num = parseFloat(campo.value);
      cond = (num >= 0);
      if (num<0) {
        alert('Il valore inserito non e\' positivo');
        return errore(campo);
      }    
      if ((flag_no_zero) && (num==0)) {
        alert('Il valore zero non e\' ammesso per questo campo');
        return errore(campo);
      }    
    }
  return true;
}

function is_char (campo, lunghezza, label) {
    cond = (campo.value.length<=lunghezza);
    if (!cond) 
      if (confirm('Il campo '+label+' supera la lunghezza consentita ('+lunghezza+' caratteri)\nDevo troncarlo ?')) {
        campo.value = campo.value.substr(0,lunghezza);
        cond = true;
      }
    if (!cond) return errore(campo);
  return true;
}

function is_char_esatto (campo, lunghezza, label) {
  if (campo.value.length!=lunghezza) {
    alert('Il campo '+label+' deve essere lungo '+lunghezza+' caratteri')
    return errore(campo);
  }
  return true;
}

function is_email (campo)
{
  s = compatta(campo.value);
  if (!vuoto(s)) {
    h = s.indexOf('@');
    if (h==-1) {
      alert('e-mail non valida');
      return errore(campo);
  }
  else {
    i = s.length
    if ((i==h) || (h==0)) {          /* se è stata omessa la user */
      alert('e-mail non valida'); 
      return errore(campo);
    }
    else {
      dominio = compatta(s.substr(h+1,i-(h+1)));
      k = dominio.indexOf('.');
      if (k == -1) {                 /* dominio non valido */
        alert('e-mail non valida');  /* non rispetta il    */ 
        return errore(campo);        /* formato "yyyy.xx"  */
      }
      else
        if (k == 0) {                      /* dominio di secondo */
          alert('e-mail non valida');   /* livello non valido */
          return errore(campo);         /* manca "yyyy."       */
        }
        else { 
          dominio2 = compatta(dominio.substr(k+1,dominio.length-(k+1)));
          
          if (dominio2.length < 2) {        /* dominio non valido */
            alert('e-mail non valida');     /* manca ".xxx"       */
            return errore(campo);
          }
        }
      }
    }
  }
  return true;
}

function is_folder (campo)
{
  for (i = 0; i < campo.value.length; i++){
        c = campo.value.charCodeAt(i);
        if (folder_chars.charAt(c) == '0')
        {
        alert('L\'utilizzo del carattere '+campo.value.charAt(i)+' non e\' consentito');
        return errore(campo);
        }
    }
    return true;
}

function in_euro (campo) {   
    euro = Math.floor (campo.value / 19.3627);
    eurodec = euro / 100;
    return eurodec;
    }

function in_lire (campo) {   
    
    s=compatta(campo.value);
    k = s.indexOf(virgola_decimale);
    if (k > -1)
        s=s.substr(0, k)+punto_decimale+s.substr(k+1, s.length);
    lire = Math.round (s * 1936.27);
    return lire;
    }

function ctrl_piva (campo, label) {
    if (is_numeric(campo,label))
        {
        if (campo.value.length < 11) 
            {
            alert('Il campo '+label+' non puo\' essere minore di 11 cifre');
            return errore(campo);
            }
        return true;
        }
    }
        

function ctrl_cap (campo, label) {
    if (is_numeric(campo,label))
        {
        if (campo.value.length < 5) 
            {
            alert('Il campo '+label+' non puo\' essere minore di 5 cifre');
            return errore(campo);
            }
        return true;
        }
    }

        
function is_numeric (campo, label) { 
    s = compatta(campo.value);
    campo.value = s;
    if (!vuoto(s)) {
      for (i = 0; i < s.length; i++)
      {   
        c = s.charAt(i);
        if (!cifra(c)) {
            alert('Il campo '+label+' ammette solo cifre');
            return errore(campo);
        }
        else {
            
        }
      }
    }
    num = parseInt(s,10);
    if (num==0) {
        alert('Il valore zero non e\' ammesso per il campo '+label);
        return errore(campo);
    }
    return true;
}

function MM_openBrWindow(theURL,winName,features) 
{ 
	var window_width = (screen.width/2)+150;
	var window_height = (screen.height/2)+130;	
	var window_top = (screen.height-window_height)/2;
	var window_left = (screen.width-window_width)/2;
	var newfeatures = features+",width="+window_width+",height="+window_height+",top="+window_top+",left="+window_left
	winName = window.open(theURL,winName,newfeatures);
	winName.focus();
}



function AddFavorite(theTit) 
{
	// Copyright (c) 1998 by Kevin Bartz. All rights reserved. This site has been enhanced by one of Kevin Bartz's behaviours! Mail him at kevinbartz@geocities.com! This line must remain in the script.
	IE4=(document.all)? 1 : 0
	if (IE4) {
	theSite=window.location
	window.external.AddFavorite(theSite,theTit)
	}
}

