isMacOs = (navigator.appVersion.indexOf('Mac')>=0)?true:false;
isScreenOk = ((screen.height > 600)&&(screen.width > 800))?true:false;
isSafari = (navigator.userAgent.indexOf("Safari")!=-1)?true:false;
isIe = (navigator.userAgent.indexOf("MSIE")!=-1)?true:false;
isGecko = (navigator.userAgent.indexOf("Gecko")!=-1)?true:false;

////////////////////////////////////////

function openPopup(file,name,pWidth,pHeight,scroll)
{
 var scrollbars = "";
 var h = ((screen.height)-(pHeight))/2;
 var w = ((screen.width)-(pWidth))/2;
 if ( scroll == true ) { scrollbars=",scrollbars" }
 if (isMacOs) { pWidth = pWidth - 16; pHeight = pHeight - 16; }
 if ((isMacOs)&&(isSafari)) { pWidth = pWidth + 16; pHeight = pHeight + 16; }
 eval (name +"= window.open(file,name,'width='+ pWidth +',height='+ pHeight +',top='+h+',left='+w+''+scrollbars+'');")
}

/////////////////////////////////////
function MM_findObj(n, d) { //v4.0
			  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 && document.getElementById) x=document.getElementById(n); return x;
			}

function MM_validateForm() { //v4.0
  var validEmail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
  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) || !validEmail.exec(val)) 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 printDoc() {
  if (isMacOs) { alert("Attenzione!\nPer stampare il documento con un MacIntosh è necessario schiacciare MELA+P"); }
  else { self.print(); }
}

////////////////////////////////////////////////////////////////////////////////
//  ADD EVENTS
////////////////////////////////////////////////////////////////////////////////

function addEvent(obj, eventName, fn)
{
    var prev = obj[eventName];
    obj[eventName] = prev ? function() { fn() ; prev() } : fn;
}

//addEvent( window, "onunload", checkPlanExistence);

/////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////
function getMaxHeight(arrayDiv)
{
   var maxHeight = 0

   for (i = 0 ; i < arrayDiv.length ; ++i)
   {
	  singleHeight = 0
	  var curDiv = document.getElementById(arrayDiv[i])
	  if (curDiv)
	  {
	     singleHeight = curDiv.offsetHeight
	     //alert(arrayDiv[i] + "->" + singleHeight)
	  }
	 if(isNaN(singleHeight)){ singleHeight = 0 }
	  maxHeight = Math.max(maxHeight, singleHeight)
   }

   return maxHeight
}

function setHeight(arrayDiv, maxHeight)
{
   for (i = 0 ; i < arrayDiv.length ; ++i)
   {
	  var curDiv = document.getElementById(arrayDiv[i])
	  if (curDiv) { singleHeight = curDiv.style.height = maxHeight + "px" }
   }
}

//////////////////////////////////////////////////////////////
function posDiv(div,pixel,vis)
{
	if (isMacOs){
		if (isSafari){pixel = pixel+8}
	}
    document.getElementById(div).style.left = ((document.body.clientWidth/2)+(pixel))+"px"
	if (vis){document.getElementById(div).style.visibility = "visible"}
}
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////

function getDim(el){
	for (var lx=0,ly=0;el!=null;
		lx+=el.offsetLeft,ly+=el.offsetTop,el=el.offsetParent);
	return {x:lx,y:ly}
}


function adjustSchedaCols(){
if(document.getElementById("legenda")){
 var cols = new Array("col01","col02","col03")
 var cols2 = new Array("col01","col02","col03","text")
 var maxHeight = 0
 var minHeight = 400
 maxHeight = getMaxHeight(cols)
 if (maxHeight<minHeight){maxHeight=minHeight}
 setHeight(cols2,maxHeight)
}

}

/////////////////////////////////////////////////////////////////

  // this function is need to work around
  // a bug in IE related to element attributes
  function hasClass(obj) {
     var result = false;
     if (obj.getAttributeNode("class") != null) {
         result = obj.getAttributeNode("class").value;
     }
     return result;
  }

 function stripeAllTables() {
 // La tabella deve contenere almeno un TBODY
    var even = false;
    var tables = document.getElementsByTagName("table");
    if (! tables) { return; }
      for (var i = 0; i < tables.length; i++) {
      var tbodies = tables[i].getElementsByTagName("tbody");
      for (var h = 0; h < tbodies.length; h++) {
        var trs = tbodies[h].getElementsByTagName("tr");
        for (var i = 0; i < trs.length; i++) {
	      if (!hasClass(trs[i]) && ! trs[i].style.backgroundColor) {
            var tds = trs[i].getElementsByTagName("td");
            for (var j = 0; j < tds.length; j++) {
              var mytd = tds[j];
	          if (! hasClass(mytd) && ! mytd.style.backgroundColor) {
			    mytd.className += even ? 'even' : '';
              }
            }
          }
          even =  ! even;
        }
      }
	}
  }
//
function stripe(id) {
 // La tabella deve contenere almeno un TBODY
    var even = false;
    var evenColor = arguments[1] ? arguments[1] : "#fff"; // default color
    var oddColor = arguments[2] ? arguments[2] : "#eee"; // default color
    var table = document.getElementById(id);
    if (! table) { return; }
    var tbodies = table.getElementsByTagName("tbody");
    for (var h = 0; h < tbodies.length; h++) {
      var trs = tbodies[h].getElementsByTagName("tr");
      for (var i = 0; i < trs.length; i++) {
	    if (!hasClass(trs[i]) && ! trs[i].style.backgroundColor) {
          var tds = trs[i].getElementsByTagName("td");
          for (var j = 0; j < tds.length; j++) {
            var mytd = tds[j];
	        if (! hasClass(mytd) && ! mytd.style.backgroundColor) {
        	      mytd.style.backgroundColor = even ? evenColor : oddColor;
            }
          }
        }
        even =  ! even;
      }
    }
  }

  // example: stripe('playlist', '#fff', '#edf3fe');

/////////////////////////////////////////////////////////////////

startList = function() {
	if (document.all&&document.getElementById) {

		navRoot = document.getElementById("nav");
		if (!navRoot){ return; }
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className+=" over";
				}
				node.onmouseout=function() {
					this.className=this.className.replace(" over", "");
				}
			}
		}
	}
}


function swapImg (id,status){
	document.images[id].src = eval(id+"["+status+"].src")
}

function setSchemaWidths() {

	if(document.getElementById("legenda"))
		{
		var col01W = document.getElementById("col01").offsetWidth
		var col03W = document.getElementById("col03").offsetWidth
		col02W = 1000 - 35 - col01W - col03W
		col02L = 35 + col01W
		document.getElementById("col02").style.width = col02W+"px"
		document.getElementById("col02").style.left = col02L+"px"
		document.getElementById("legenda").style.left = (col02L-70)+"px"
		}
	}

	addEvent( window, "onload", setSchemaWidths);
	addEvent( window, "onload", adjustSchedaCols);

//addEvent( window, "onload", startList);
function selezionaCheckbox(idMagazzino){
	textqta = eval("document.WarehouseOrderForm.qta_idmagazzino_"+idMagazzino);
	if (textqta.value != "" && event.keyCode != 32){
		document.images["check_"+idMagazzino].src="/Site/img/checkOn.gif";
		//immagine di check ON
	}
	else{
		document.images["check_"+idMagazzino].src="/Site/img/check.gif";
		//immagine di check OFF
	}
}

/*****************************************************/
/*PARTE AGGIUNTA DA DARIO*/

addEvent( window, "onload", initFxHP);

function getElementsByClass(searchClass,node,tag) {
    var classElements = new Array();
    if ( node == null )
        node = document;
    if ( tag == null )
        tag = '*';
    var els = node.getElementsByTagName(tag);
    var elsLen = els.length;
    var pattern = new RegExp('(^|\\s)'+searchClass+'(\\s|$)');
    for (i = 0, j = 0; i < elsLen; i++) {
        if ( pattern.test(els[i].className) ) {
            classElements[j] = els[i];
            j++;
        }
    }
    return classElements;
}


counterFx = 0;
timerID = null;

function initFxHP(){
	if (document.getElementById('hp')){
	cases = getElementsByClass('hpCaseStudies',null,'div');
	for(i=0;i<cases.length;i++){
		caseFxInit = caseFx = new fx.Opacity(cases[i], {duration:2000});
		caseFxInit.setOpacity(0);
		}
		setEffectsHP();
	}
}


function setEffectsHP(){

			caseFx = new fx.Opacity(cases[counterFx], {duration:2000,onComplete:function(){window.setTimeout("caseFx.hide();setEffectsHP()",3500);}});
			counterFx++;
			caseFx.custom(0, 1);
			//caseFx.toggle();
			if (counterFx==cases.length){
				counterFx=0;
				}

	}
document.write(	'<script type="text/javascript" src="js/prototype.lite.js"></script><script type="text/javascript" src="js/moo.fx.js"></script><script type="text/javascript" src="js/moo.fx.pack.js"></script>');

