
var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])
function fixPNG(myImage) 
{
    if ((version >= 5.5) && (version < 7) && (document.body.filters)) 
    {
       var imgID = (myImage.id) ? "id='" + myImage.id + "' " : ""
	   var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : ""
	   var imgTitle = (myImage.title) ? 
		             "title='" + myImage.title  + "' " : "title='" + myImage.alt + "' "
	   var imgStyle = "display:inline-block;" + myImage.style.cssText
	   var strNewHTML = "<span " + imgID + imgClass + imgTitle
                  + " style=\"" + "width:" + myImage.width 
                  + "px; height:" + myImage.height 
                  + "px;" + imgStyle + ";"
                  + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
                  + "(src=\'" + myImage.src + "\', sizingMethod='scale');\"></span>"
	   myImage.outerHTML = strNewHTML	  
    }
}
function MM_validateForm() { //v4.0
  if (document.getElementById){
    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=document.getElementById(args[i]);
      if (val) { nm=val.name; if ((val=val.value)!="") {
        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
          if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
        } else if (test!='R') { num = parseFloat(val);
          if (isNaN(val)) errors+='- '+nm+' must contain a number.\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+' must contain a number between '+min+' and '+max+'.\n';
      } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
    } if (errors) alert('The following error(s) occurred:\n'+errors);
    document.MM_returnValue = (errors == '');
} }
function setCheckboxes(the_form, the_field, do_check)
{
    var elts      =  typeof(document.forms[the_form].elements[the_field]);
    var elts_cnt  = typeof(elts.length);

    if (elts_cnt) {
        for (var i = 0; i < elts_cnt; i++) {
            elts[i].checked = do_check;
        } // end for
    } else {
        elts.checked        = do_check;
    } // end if... else

    return true;
} // end of the 'setCheckboxes()' function



function set_cookie(name, value)
{
	document.cookie= name + "=" + escape(value);
}

function get_cookie(name)
{
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);

	if (begin == -1)
	{
		begin = dc.indexOf(prefix);
		if (begin != 0)
		{
			return null;
		}
	}
	else
	{
		begin += 2;
	}

	var end = document.cookie.indexOf(";", begin);

	if (end == -1)
	{
		end = dc.length;
	}
	return unescape(dc.substring(begin + prefix.length, end));
}

function set_nodes_status()
{
	var divs = document.getElementsByTagName('div');
	var ids_str = '';

	for (i = 0; i < divs.length; i++)
	{
		if (divs[i].id.substring(0, 3) == 'div')
		{
			if (divs[i].style.display == '')
			{
				var id = divs[i].id.substring(3, divs[i].id.length);
				ids_str = ids_str + '[' + id + ']';
			}
		}
	}				
	set_cookie('node_status', ids_str);
}

function init_menu_nodes()
{
	var ids_str = get_cookie('node_status');
	var divs = document.getElementsByTagName('div');

	for (i = 0; i < divs.length; i++)
	{
		if (divs[i].id.substring(0, 3) == 'div')
		{
			var id = divs[i].id.substring(3, divs[i].id.length);

			if (ids_str.indexOf('[' + id + ']') != -1)
			{							
				var theImg = document.getElementById('img' + id);
					
				divs[i].style.display = '';
				theImg.src = 'img/down.gif';
			}
		}
	}				
}

function ocopen(node)
{
	var theDiv = document.getElementById('div' + node);
	var theImg = document.getElementById('img' + node);
	
	if (theDiv.style.display == 'none')
	{
		theDiv.style.display = '';
		theImg.src = 'img/down.gif';
	}
	else
	{
		theDiv.style.display = 'none';
		theImg.src = 'img/next.gif';
	}
	set_nodes_status();
}

function close_all()
{
	var divs = document.getElementsByTagName('div');

	for (i = 0; i < divs.length; i++)
	{
		if (divs[i].id.substring(0, 3) == 'div')
		{
			var id = divs[i].id.substring(3, divs[i].id.length);
			var theImg = document.getElementById('img' + id);
					
			divs[i].style.display = 'none';
			theImg.src = 'img/next.gif';
		}
	}
	set_nodes_status();
}      


function emailCheck (emailStr)
{
var emailPat=/^(.+)@(.+)$/
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
var validChars="\[^\\s" + specialChars + "\]"
var quotedUser="(\"[^\"]*\")"
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
var atom=validChars + '+'
var word="(" + atom + "|" + quotedUser + ")"
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
var matchArray=emailStr.match(emailPat)
if (matchArray==null) {
 	alert("L'indirizzo e-mail inserito è scorretto ")
	return false
}
var user=matchArray[1]
var domain=matchArray[2]
if (user.match(userPat)==null) {
    alert("Inserire il nome utente della mail.")
    return false
}
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
	        alert("L'indirizzo ip di destinazione è invalido!")
		return false
	    }
    }
    return true
}
var domainArray=domain.match(domainPat)
if (domainArray==null) {
	alert("Il nome del domino è scorretto.")
    return false
}
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 || 
    domArr[domArr.length-1].length>3) {
   alert("L'indirizzo deve terminare con due o tre lettere indicanti il dominio.")
   return false
}
if (len<2) {
   var errStr="This address is missing a hostname!"
   alert(errStr)
   return false
}
return true;
}

function zoom(file) {
var finestra = null;
bName=navigator.appName;
finestra=window.open('../../scripts/img.php?file='+file,'zoom','toolbar=no,location=no,directories=no,status=no,scrollbars=no,menubar=no,resizable=yes,width=50,height=50');
finestra.focus();
}

function zoomvideo(file) {
var finestra = null;
bName=navigator.appName;
finestra=window.open('../../scripts/video.php?file='+file,'video','toolbar=no,location=no,directories=no,status=no,scrollbars=no,menubar=no,resizable=yes,width=425,height=355');
finestra.focus();
}

function dettagli(id,file) {
var finestra = null;
bName=navigator.appName;
finestra=window.open('newsletter/'+file+'.php?id='+id,'','toolbar=no,location=no,directories=no,status=no,scrollbars=yes,menubar=no,resizable=yes,width=500,height=350');
if (bName=="Netscape") { finestra.focus(); }
}

function apriPopupCentrata(nome, titolo, lar, alt, feat){
        var wdt = screen.width;
        var hgt = screen.height;
        var x = Math.round( (wdt / 2) - (lar / 2) );
        var y = Math.round( (hgt / 2) - (alt / 2) );
        window.open(nome, titolo, 'width=' + lar + ',height=' + alt + ',left=' + x + ',screenX=' + x + ',top=' + y + ',screenY=' + y + ',' + feat);
}

function guida(dir,file) {
    var guida = null;    

    x_g=300;
    x=screen.availWidth-x_g;
    y=screen.availHeight;
    self.moveTo(0,0);
    self.resizeTo(x-10,y);

    guida=window.open('guida.php?file='+file+'&dir='+dir,'guida','toolbar=yes,location=no,directories=no,status=no,scrollbars=yes,menubar=no,resizable=yes,width='+x_g+',height='+y+',left='+(x));
    guida.focus();

}

function loadGuida(dir,file) {
    guida.location='guida.php?file='+file+'&dir='+dir;
}

function cancella(url)
{
if (confirm("Confermi la cancellazione?")){
 redir(url);
 return true;
 }
return false;
}

function conferma(txt)
{
if (confirm(txt)){
 return true;
 }
return false;
}

function nuovalingua(id) {
  var url = String(window.location) ;
  set_cookie('lang', id);
  var index2 = url.indexOf('#');
	
  a=url.split('#');
  url=a[0];
  
  var index = url.indexOf('?');
  
  
  conc=(index == -1)?"?":"&";
  //conc2=(a[1] <>'')?"#"+a[1]:"";  
  
  
  url = url + conc+"lang="+id;
  //alert (url);
  window.location=url;
}

function redir(url)
{
window.location=url;
}


// -----------------------------------------------------------------------------
// --- Controllo dei dati nel form di richiesta informazioni
// -----------------------------------------------------------------------------
function controllo_richiesta()
{	
	var risultato = true;
	var ragione_sociale = document.forms['informazioni'].ragione.value;
	var nome = document.forms['informazioni'].nome_.value;
	var cognome = document.forms['informazioni'].cognome_.value;
	var telefono = document.forms['informazioni'].telefono_.value;
	var email = document.forms['informazioni'].email_.value;
	
	if (ragione_sociale == '')
	{
		document.getElementById('td_ragione').style.color = '#FF0033';
		document.getElementById('td_ragione').style.fontWeight = 'bold';
		risultato = false;
	}
	else
	{
		document.getElementById('td_ragione').style.color = '';
		document.getElementById('td_ragione').style.fontWeight = '';
	}
	if (cognome == '')
	{
		document.getElementById('td_cognome').style.color = '#FF0033';
		document.getElementById('td_cognome').style.fontWeight = 'bold';
		risultato = false;
	}
	else
	{
		document.getElementById('td_cognome').style.color = '';
		document.getElementById('td_cognome').style.fontWeight = '';
	}
	
	if (nome == '')
	{
		document.getElementById('td_nome').style.color = '#FF0033';
		document.getElementById('td_nome').style.fontWeight = 'bold';
		risultato = false;
	}
	else
	{
		document.getElementById('td_nome').style.color = '';
		document.getElementById('td_nome').style.fontWeight = '';
	}

	var tel_re = /^\d+$/;
	if ((telefono == '') || (!telefono.match(tel_re)))
	{
		document.getElementById('td_telefono').style.color = '#FF0033';
		document.getElementById('td_telefono').style.fontWeight = 'bold';
		risultato = false;
	}
	else
	{
		document.getElementById('td_telefono').style.color = '';
		document.getElementById('td_telefono').style.fontWeight = '';
	}

	var email_re = /^[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*@[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*\.([A-Za-z]){2,4}$/;
  if ((email == '') || (!email.match(email_re)))
	{
		document.getElementById('td_email').style.color = '#FF0033';
		document.getElementById('td_email').style.fontWeight = 'bold';
		risultato = false;
	}
	else
	{
		document.getElementById('td_email').style.color = '';
		document.getElementById('td_email').style.fontWeight = '';
	}
	
	if (risultato == false)
	{
		alert('Sono stati rilevati dei campi non validi. Ricontrollare i campi evidenziati in rosso.');
	}

	return risultato;
}

//sostituisce testo ad emoticon
function replaceText(box) {
// no support
if(!document.getElementById) {
return;
}

bodyText = document.getElementById(box);
theText = bodyText.innerHTML;

// replace
theText = theText.replace(/;\)/g,'<img style="border:none;vertical-align:middle" src="forum/img/wink.gif" alt=";)" />');
theText = theText.replace(/;-\)/g,'<img style="border:none;vertical-align:middle" src="forum/img/wink.gif" alt=";-)" />');
theText = theText.replace(/:D/g,'<img style="border:none;vertical-align:middle" src="forum/img/biggrin.gif" alt=":D" />');
theText = theText.replace(/:-D/g,'<img style="border:none;vertical-align:middle" src="forum/img/biggrin.gif" alt=":-D" />');
theText = theText.replace(/B\)/g,'<img style="border:none;vertical-align:middle" src="forum/img/cool.gif" alt="B)" />');
theText = theText.replace(/B-\)/g,'<img style="border:none;vertical-align:middle" src="forum/img/cool.gif" alt="B-)" />');
theText = theText.replace(/:x/g,'<img style="border:none;vertical-align:middle" src="forum/img/mad.gif" alt=":x" />');
theText = theText.replace(/:X/g,'<img style="border:none;vertical-align:middle" src="forum/img/mad.gif" alt=":X" />');
theText = theText.replace(/:-x/g,'<img style="border:none;vertical-align:middle" src="forum/img/mad.gif" alt=":-x" />');
theText = theText.replace(/:-X/g,'<img style="border:none;vertical-align:middle" src="forum/img/mad.gif" alt=":-X" />');
theText = theText.replace(/:-\(/g,'<img style="border:none;vertical-align:middle" src="forum/img/sad.gif" alt=":-(" />');
theText = theText.replace(/:\(/g,'<img style="border:none;vertical-align:middle" src="forum/img/sad.gif" alt=":(" />');
theText = theText.replace(/:o/g,'<img style="border:none;vertical-align:middle" src="forum/img/ohmy.gif" alt=":o" />');
theText = theText.replace(/:O/g,'<img style="border:none;vertical-align:middle" src="forum/img/ohmy.gif" alt=":O" />');
theText = theText.replace(/:-o/g,'<img style="border:none;vertical-align:middle" src="forum/img/ohmy.gif" alt=":-o" />');
theText = theText.replace(/:-O/g,'<img style="border:none;vertical-align:middle" src="forum/img/ohmy.gif" alt=":-O" />');
theText = theText.replace(/:p/g,'<img style="border:none;vertical-align:middle" src="forum/img/tongue.gif" alt=":p" />');
theText = theText.replace(/:-p/g,'<img style="border:none;vertical-align:middle" src="forum/img/tongue.gif" alt=":-p" />');
theText = theText.replace(/:-P/g,'<img style="border:none;vertical-align:middle" src="forum/img/tongue.gif" alt=":-P" />');
theText = theText.replace(/:P/g,'<img style="border:none;vertical-align:middle" src="forum/img/tongue.gif" alt=":P" />');
theText = theText.replace(/:-\)/g,'<img style="border:none;vertical-align:middle" src="forum/img/smile.gif" alt=":-)" />');
theText = theText.replace(/:\)/g,'<img style="border:none;vertical-align:middle" src="forum/img/smile.gif" alt=":)" />');
theText = theText.replace(/:@/g,'<img style="border:none;vertical-align:middle" src="forum/img/mad.gif" alt=":@" />');
theText = theText.replace(/:-@/g,'<img style="border:none;vertical-align:middle" src="forum/img/mad.gif" alt=":-@" />');
theText = theText.replace(/:\|/g,'<img style="border:none;vertical-align:middle" src="forum/img/neutral.gif" alt=":|" />');
theText = theText.replace(/:-\|/g,'<img style="border:none;vertical-align:middle" src="forum/img/neutral.gif" alt=":-|" />');
theText = theText.replace(/:\'\(/g,'<img style="border:none;vertical-align:middle" src="forum/img/cry.gif" alt=":\'(" />');
theText = theText.replace(/:\'-\(/g,'<img style="border:none;vertical-align:middle" src="forum/img/cry.gif" alt=":\'-(" />');

bodyText.innerHTML = theText;
}//replaceText
function showDiv(liv) {
	if (gettrailobj(liv).visibility=="visible") {
		vis = "hidden";
	}else{
		vis = "visible";
	}
		gettrailobj(liv).visibility=vis;	
}
//showtrail
function gettrailobj(idt)
{
	if (document.getElementById) return document.getElementById(idt).style
	else if (document.all) return document.all.trailimagid.style
}

function truebody()
{
	return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function hidetrail()
{
	document.onmousemove=""
	document.getElementById('tcont').innerHTML=""
	gettrailobj("trailimageid").visibility="hidden"
	gettrailobj("trailimageid").left=-1000
	gettrailobj("trailimageid").top=0
}


function showtrail(width,height,file)
{
	if(navigator.userAgent.toLowerCase().indexOf('opera') == -1 && navigator.userAgent.toLowerCase().indexOf('safari') == -1)
	{
		w=width
		h=height
		
		// followmouse()
	
		gettrailobj("trailimageid").visibility="visible"
		gettrailobj("trailimageid").width=w+"px"//gettrailobj("tcont").width//
		gettrailobj("trailimageid").height=gettrailobj("tcont").height//h+"px"
		document.getElementById('tcont').innerHTML=file
		document.onmousemove=followmouse
	}
}


function followmouse(e)
{

	if(navigator.userAgent.toLowerCase().indexOf('opera') == -1 && navigator.userAgent.toLowerCase().indexOf('safari') == -1)
	{

		var xcoord=20
		var ycoord=20

		if (typeof e != "undefined")
		{
			xcoord+=e.pageX
			ycoord+=e.pageY
		}
		else if (typeof window.event !="undefined")
		{
			xcoord+=truebody().scrollLeft+event.clientX
			ycoord+=truebody().scrollTop+event.clientY
		}

		var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
		var docheight=document.all? Math.max(truebody().scrollHeight, truebody().clientHeight) : Math.max(document.body.offsetHeight, window.innerHeight)

		if (xcoord+w+3>docwidth)
		xcoord=xcoord-w-(20*2)

		if (ycoord-truebody().scrollTop+h>truebody().clientHeight)
		ycoord=ycoord-h-20;

		gettrailobj("trailimageid").left=xcoord+"px"
		gettrailobj("trailimageid").top=ycoord+"px"

	}

}
function aggiungiColore(colore,livello) {
	codice = document.getElementById(livello).innerHTML + '<div class="color" style="background-color:#'+colore+';" onClick="rimuoviColore(\''+colore+'\');" name = "'+colore+'"></div>';
	document.getElementById(livello).innerHTML = codice;
	codice = document.getElementById("esadecimali").value;
	if (codice != "")  codice += ",";
	codice += colore;
	document.getElementById("esadecimali").value = codice;
}

function rimuoviColore(colore,togli,livello) {
	if (confirm("eliminare il colore " + colore + "?")) {
	var mem = "";
	var col = "";
  	var myDiv = document.getElementById("divcolori"); 
  	var myChildren = myDiv.childNodes; 
  for (var i = 0; i < myChildren.length; i++) { 
    if (myChildren[i].nodeType == 1){ 
	col = myChildren[i].getAttribute("name");
	if (col==colore){
		myDiv.removeChild(myChildren[i]);
		i-=1;
	} else {
		if (mem!="") mem +=",";
		mem += col;
	}
      // element node
    };
  }
	document.getElementById("esadecimali").value = mem;
	}
}
function selTutti(idCont){
  var selezionati = false;
  var myDiv = document.getElementById(idCont); 
  var myChildren = myDiv.getElementsByTagName("input"); 
  if (document.getElementById("seltutti"+idCont).style.display == "inline") 
  selezionati = true;
  else selezionati = false;
  for (var i = 0; i < myChildren.length; i++) { 
    if (myChildren[i].nodeType == 1){ 
	if (selezionati){
	myChildren[i].setAttribute("checked","checked");
	document.getElementById("seltutti"+idCont).style.display = "none";
	document.getElementById("desel"+idCont).style.display = "inline";
	}else{
		//per IE
	myChildren[i].setAttribute("checked",false);
		//per FF
	myChildren[i].removeAttribute("checked");
	document.getElementById("seltutti"+idCont).style.display = "inline";
	document.getElementById("desel"+idCont).style.display = "none";
	}
    };
  }
}
//end showtrail
// -----------------------------------------------------------------------------

