
// aggiornare le immagini della barra di navigazione al passaggio del mouse

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

var preloadFlag = false;
function preloadImages() {
	if (document.images) {
		linguait_over = newImage("images/lingua_it.jpg");
		linguaen_over = newImage("images/lingua_en.jpg");
		preloadFlag = true;
	}
}


//nascondere l'indirizzo di posta

function posta(utente, dominio)
{
  var email = utente + '@' + dominio;
  document.write('<a href="mailto:' + email + '">' + email + '</a>');
}

function postaComp(utente, dominio, oggetto)
{
  var email = utente + '@' + dominio + '?subject=' + oggetto;
  var emailWrite = utente + '@' + dominio;
  document.write('<a href="mailto:' + email + '">' + emailWrite + '</a>');
}

// visualizzare la data di oggi


function WebData() {
	var now = new Date();
	var year= now.getYear();if (year < 1000) year += 1900;
	nameDay = new Array('Domenica','Lunedi','Martedi','Mercoledi','Giovedi','Venerdi','Sabato');
	nameMth = new Array('Gennaio','Febbraio','Marzo','Aprile','Maggio', 'Giugno', 'Luglio', 'Agosto', 'Settembre', 'Ottobre', 'Novembre','Dicembre');
	document.write(nameDay[now.getDay()]+ ' ' + now.getDate() + " " + nameMth[now.getMonth()] + " " + year);
}

// aprire i popup

function popup(url, name, width, height)
	{
	settings=
		"toolbar=no,location=no,directories=no,"+
		"status=no,menubar=no,scrollbars=no,"+
		"resizable=no,channelmode=no,left=580,top=120,width="+width+",height="+height;

	MyNewWindow=window.open(url,name,settings);
	}
	
// popup grandi

function popupG(url, name, width, height)
	{
	settings=
		"toolbar=no,location=no,directories=no,"+
		"status=no,menubar=no,scrollbars=yes,"+
		"resizable=no,left=450,top=20,width="+width+",height="+height;

	MyNewWindow=window.open(url,name,settings);
	}

// aprire link PCTeknet

function linkPC(url, name)
	{
	settings=
		"toolbar=yes,location=yes,"+
		"status=yes,menubar=yes,scrollbars=yes,"+
		"resizable=yes";

	MyNewWindow=window.open(url,name,settings);
	}

// controllo form contatti

		function MM_findObj(n, d) { 
		  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_validateForm() {
      var myForm = document.formcontatti; 
		  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;

		  for (i=0; i<(args.length-2); i+=3) { 
          test=args[i+2]; val=MM_findObj(args[i]);		  
			    if (val) { 
              nm=val.title; 
              if ((val=val.value)!="") {
			           if (((myForm.email.value != "")) && (test.indexOf('isEmail')!=-1)) {                  
                    p=val.indexOf('@');
				            if (p<1 || p==(val.length-1)) errors+='- '+nm+' deve contenere un indirizzo e-mail valido.\n';
                  } else if (test!='R') { 
                    num = parseFloat(val);
				            if (isNaN(val)) errors+='- '+nm+' deve contenere un numero.\n';
				            if (test.indexOf('inRange') != -1) { 
                        p=test.indexOf(':');
				                min=test.substring(8,p); max=test.substring(p+1);
				                if (num<min || max<num) errors+='- '+nm+' deve contenere un numero compreso tra '+min+' e '+max+'.\n';
			               } 
                  }
              } else if (test.charAt(0) == 'R') errors += '- '+nm+' è obbligatorio.\n'; 
          }
      }
      if ((myForm.telefono.value == "") && (myForm.email.value == "")) errors+=' è obbligatorio inserire telefono o e-mail.\n';
      if (errors) alert('Compila i seguenti campi:\n'+errors);
		  document.MM_returnValue = (errors == '');
		}





//Per richiamare codice javascript

function MM_callJS(jsStr) {
  return eval(jsStr)
}

// Per resettare il form dei contatti
function resetForm() {
	document.formcontatti.reset();
}

// Per inviare i dati del form contatti
function submitForm() {
	if(document.formcontatti.onsubmit()) { 
		document.formcontatti.submit();
	}
}

