// JavaScript Document
activIttems = null;
activIttem = null;
element = null;
//preloading images in case that I want change background
bg_menuArray = new Array();
bg_menuArray[0] = new Image();
bg_menuArray[0].src = 'images/website/headers/plus.gif';
bg_menuArray[1] = new Image();
bg_menuArray[1].src = 'images/website/headers/minus.gif';
var scrollerwidth="100%"
var scrollerheight="100px"
var scrollerspeed=1
var scrollercontent=''
var pauseit=1
scrollerspeed=(document.all)? scrollerspeed : Math.max(1, scrollerspeed-1) //slow speed down by 1 for NS
var copyspeed=scrollerspeed
var iedom=document.all||document.getElementById
var actualheight=''
var cross_scroller, ns_scroller
var pausespeed=(pauseit==0)? copyspeed: 0

// INIZIO funzioni per la dim del font della pagina
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;
}

function setFontSize(size) {
	var body = document.getElementsByTagName('body')[0];
	var percentuale = "80%"; // default
	if (size == 1) percentuale = "70%";
	if (size == 2) percentuale = "80%";
	if (size == 3) percentuale = "100%";
	body.style.fontSize = percentuale;
	createCookie('FontSize',size,365);
}
// FINE funzioni per la dim del font della pagina

function populate(){
	size = readCookie('FontSize'); // fa parte delle funzioni per la dim del font della pagina
	setFontSize(size); // fa parte delle funzioni per la dim del font della pagina
	if (iedom){
		cross_scroller=document.getElementById? document.getElementById("iescroller") : document.all.iescroller
		cross_scroller.style.top=parseInt(scrollerheight)+8+"px"
		cross_scroller.innerHTML=scrollercontent
		actualheight=cross_scroller.offsetHeight
	}
	else if (document.layers){
		ns_scroller=document.ns_scroller.document.ns_scroller2
		ns_scroller.top=parseInt(scrollerheight)+8
		ns_scroller.document.write(scrollercontent)
		ns_scroller.document.close()
		actualheight=ns_scroller.document.height
	}
	lefttime=setInterval("scrollscroller()",25)
	}
	
function scrollscroller(){
	if (iedom){
		if (parseInt(cross_scroller.style.top)>(actualheight*(-1)+8))
			cross_scroller.style.top=parseInt(cross_scroller.style.top)-copyspeed+"px"
		else
			cross_scroller.style.top=parseInt(scrollerheight)+8+"px"
		}
		else if (document.layers){
			if (ns_scroller.top>(actualheight*(-1)+8))
				ns_scroller.top-=copyspeed
			else
				ns_scroller.top=parseInt(scrollerheight)+8
		}
}

function getObj(name)
{
  if (document.getElementById)
  {
  	element = document.getElementById(name);
  }
  else if (document.all)
  {
	element = document.all[name];
  }
  else if (document.layers)
  {
    element = document.layers[name];
  }
  return element;
}
/*
function show(idIttems,idIttem){
 if(activIttems){
	activIttems.style.display='none';
	activIttem.style.backgroundImage='url('+ bg_menuArray[0].src+')';
  }
  if(activIttems == getObj(idIttems)){
   	activIttems.style.display='none';
	activIttem.style.backgroundImage='url('+ bg_menuArray[0].src+')';
	activIttems = null;
   }else{
 	activIttems = getObj(idIttems);
 	activIttem = getObj(idIttem);
 	activIttem.style.backgroundImage='url('+bg_menuArray[1].src+')';
 	activIttems.style.display='block';
 }
}*/
var isNav4, isNav6, isIE4;
function setBrowser()
{
	/*if (navigator.appVersion.charAt(0) == "4")
    {
        if (navigator.appName.indexOf("Explorer") >= 0)
        {
            isIE4 = true;
        }
        else
        {
            isNav4 = true;
        }
    }
    else if (navigator.appVersion.charAt(0) > "4")
    {
        isNav6 = true;
    }*/
	if (document.getElementById)
  	{
  		isNav6 = true;
  	}
  	else if (document.all)
  	{
		 isIE4 = true;
  	}
  	else if (document.layers)
  	{
   	 	isNav4 = true;
  	}	
}

/*
 *
 * Given a selector string, return a style object
 * by searching through stylesheets. Return null if
 * none found
 *
 */
function getStyleBySelector( selector )
{
    if (!isNav6)
    {
        return null;
    }
    var sheetList = document.styleSheets;
    var ruleList;
    var i, j;
    /* look through stylesheets in reverse order that
       they appear in the document */
    for (i=sheetList.length-1; i >= 0; i--)
    {
        ruleList = sheetList[i].cssRules;
        for (j=0; j<ruleList.length; j++)
        {
            if (ruleList[j].type == CSSRule.STYLE_RULE &&
                ruleList[j].selectorText == selector)
            {
                return ruleList[j].style;
            }   
        }
    }
    return null;
}

/*
 *
 * Given an id and a property (as strings), return
 * the given property of that id.  Navigator 6 will
 * first look for the property in a tag; if not found,
 * it will look through the stylesheet.
 *
 * Note: do not precede the id with a # -- it will be
 * appended when searching the stylesheets
 *
 */
function getIdProperty( id, property )
{
    if (isNav6)
    {
        var styleObject = document.getElementById(id);
        if (styleObject != null)
        {
            styleObject = styleObject.style;
            if (styleObject[property])
            {
                return styleObject[ property ];
            }
        }
        styleObject = getStyleBySelector( "#" + id );
        return (styleObject != null) ?
            styleObject[property] :
            null;
    }
    else if (isNav4)
    {
        return document[id][property];
    }
    else
    {
		return document.all[id].style[property];
    }
}

/*
 *
 * Given an id and a property (as strings), set
 * the given property of that id to the value provided.
 *
 * The property is set directly on the tag, not in the
 * stylesheet.
 *
 */
function setIdProperty( id, property, value )
{
    
	if (isNav6)
    {
        var styleObject = document.getElementById( id );
        if (styleObject != null)
        {
            styleObject = styleObject.style;
            styleObject[ property ] = value;
        }
    }
    else if (isNav4)
    {
        document[id][property] = value;
    }
    else if (isIE4)
    {
         document.all[id].style[property] = value;
    }
}

function show(divNum, divsNum)
{	
	activIttem = getObj(divsNum);
    if (getIdProperty(divNum, "display") != "block" )
    {
        setIdProperty(divNum, "display", "block");
       	activIttem.style.backgroundImage='url('+bg_menuArray[1].src+')';
    }
    else
    {
        setIdProperty(divNum, "display", "none");
        activIttem.style.backgroundImage='url('+ bg_menuArray[0].src + ')';
		window.location.href="#top";
    }	
}

setBrowser();

function MM_openBrWindow(theURL,winName,features) { //v2.0
  popupWin = window.open(theURL,winName,features);
  popupWin.focus()
}

function MM_callJS(jsStr) { //v2.0
  return eval(jsStr)
}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

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_validateForm() { //v4.0
  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.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='Il campo '+nm+' non è un indirizzo e-mail valido.\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+='- il campo '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += 'Il campo '+nm+' è obbligatorio.\n'; }
  } if (errors) alert('Attenzione!!!\n'+errors);
  document.MM_returnValue = (errors == '');
}

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_setTextOfTextfield(objName,x,newText) { //v3.0
  var obj = MM_findObj(objName); if (obj) obj.value = newText;
}
