/*<!--
#
# This software is designed, developed, tested and deployed by e-Ring IT
# All rights reserved
# Please don't steal it, it's honest work of honest people working...
# Please feel free to contact us for each desired implementation, licence, or 
# modification you will need. We'll be happy to give you our best support.
# e-ring IT Pisa Italy
# Christian Biancu
# www.e-ring.it
# info@e-ring.it
#
# (C) 2003 Copyright by e-Ring IT, Pisa, Italy
# (C) 2003 Copyright by Christian Biancu, Pisa, Italy
#
-->*/


function isEmail(t) {//(C)2003 e-Ring.IT
	var s= new String(t);
	var n = s.length;
	if (s.length<=5) return false;
	else if (s.indexOf(' ')>-1) return false;
	else if (s.indexOf('@')<=1) return false;
	else if (s.lastIndexOf('.')<s.indexOf('@')) return false;
	else if (s.lastIndexOf('@')!=s.indexOf('@')) return false;
	else if (s.lastIndexOf('.')<=s.indexOf('@')+1) return false;
	else if (s.lastIndexOf('.')==s.length-1) return false;
	else return true;
}

function getValue(x) {
	return document.all[x].value; 
}

function checkForm(t){
	result='';
	var s= new String(t);
	var c,d= new Array;
	c=s.split(";");
	for (var i=0; i<c.length;i++){
		s=c[i];
		d=s.split(",");
		switch (d[1]) {
		case 'R':
			if (getValue(d[0]).length==0) result+='- '+d[0]+' è obbligatorio\n';
		break;
		case 'N':        
			var n= ((getValue(d[0]).length>0)?parseFloat(getValue(d[0])):0); alert (n);if (isNaN(n)) result+='- '+d[0]+' deve essere un numero\n';
		break;
		case 'E':
			if (!isEmail(getValue(d[0]))) result+='- '+d[0]+' deve essere una email valida\n';
		break;
		case 'NR':
			var n= ((getValue(d[0]).length>0)?parseFloat(getValue(d[0])):'abc'); if (getValue(d[0]).length==0 || isNaN(n)) result+='- '+d[0]+' è obbligatorio e deve essere un numero\n';
		break;
		case 'ER':
			if (getValue(d[0]).length==0 || !isEmail(getValue(d[0]))) result+='- '+d[0]+' è obbligatorio e deve essere una email valida\n';
		break
		}
	}
	if (result=='') return true;
		else alert(result);
		return false;
}


var lastOpened='';
var lastOpened2='';


function menuEringToggle(elementName) {
	//alert('-'+lastOpened+ ' -'+ elementName);
	if ((lastOpened != '') && (lastOpened!=elementName)) { totoggle= lastOpened; lastOpened='';menuEringToggle(totoggle);}
	
	if (lastOpened==elementName) lastOpened=''; else lastOpened=elementName;

	var HeaderElement = null;
	var BodyElement = null; 
	if(document.getElementsByName) {
		HeaderElement = document.getElementsByName(elementName+"Header");
		BodyElement = document.getElementsByName(elementName+"Body");
		UpImage = document.getElementsByName(elementName+"Up");
		DownImage = document.getElementsByName(elementName+"Down");
		if(BodyElement) {
			if(BodyElement[0].style.display == "none") {
				BodyElement[0].style.display = "block";
				HeaderElement[0].className = "menuEringHeader";
				UpImage[0].style.display = "block";
				DownImage[0].style.display = "none";
			} else {
				BodyElement[0].style.display = "none";
				HeaderElement[0].className = "menuEringHeaderClosed";
				UpImage[0].style.display = "none";
				DownImage[0].style.display = "block";
			}
		}	
	}
	window.event.cancelBubble = true;
	return false;

}

function menuEringToggle2(elementName) {
	//alert('-'+lastOpened+ ' -'+ elementName);
	if ((lastOpened2 != '') && (lastOpened2!=elementName)) { totoggle= lastOpened2; lastOpened2='';menuEringToggle2(totoggle);}
	
	if (lastOpened2==elementName) lastOpened2=''; else lastOpened2=elementName;

	var HeaderElement = null;
	var BodyElement = null; 
	if(document.getElementsByName) {
		HeaderElement = document.getElementsByName(elementName+"Header");
		BodyElement = document.getElementsByName(elementName+"Body");
		UpImage = document.getElementsByName(elementName+"Up");
		DownImage = document.getElementsByName(elementName+"Down");
		if(BodyElement) {
			if(BodyElement[0].style.display == "none") {
				BodyElement[0].style.display = "block";
				HeaderElement[0].className = "menuEringHeader";
				UpImage[0].style.display = "block";
				DownImage[0].style.display = "none";
			} else {
				BodyElement[0].style.display = "none";
				HeaderElement[0].className = "menuEringHeaderClosed";
				UpImage[0].style.display = "none";
				DownImage[0].style.display = "block";
			}
		}	
	}
	window.event.cancelBubble = true;
	return false;

}

// this function is needed 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 stripe(id) {
    // the flag we'll use to keep track of 
    // whether the current row is odd or even
    var even = false;
  
    // if arguments are provided to specify the colours
    // of the even & odd rows, then use the them;
    // otherwise use the following defaults:
    var evenColor = arguments[1] ? arguments[1] : "#fff";
    var oddColor = arguments[2] ? arguments[2] : "#eee";
  
    // obtain a reference to the desired table
    // if no such table exists, abort
    var table = document.getElementById(id);
    if (! table) { return; }
    
    // by definition, tables can have more than one tbody
    // element, so we'll have to get the list of child
    // &lt;tbody&gt;s 
    var tbodies = table.getElementsByTagName("tbody");

    // and iterate through them...
    for (var h = 0; h < tbodies.length; h++) {
    
     // find all the &lt;tr&gt; elements... 
      var trs = tbodies[h].getElementsByTagName("tr");
      
      // ... and iterate through them
      for (var i = 0; i < trs.length; i++) {

        // avoid rows that have a class attribute
        // or backgroundColor style
        if (! hasClass(trs[i]) &&
            ! trs[i].style.backgroundColor) {
 		  
          // get all the cells in this row...
          var tds = trs[i].getElementsByTagName("td");
        
          // and iterate through them...
          for (var j = 0; j < tds.length; j++) {
        
            var mytd = tds[j];

            // avoid cells that have a class attribute
            // or backgroundColor style
            if (! hasClass(mytd) &&
                ! mytd.style.backgroundColor) {
        
              mytd.style.backgroundColor =
                even ? evenColor : oddColor;
            
            }
          }
        }
        // flip from odd to even, or vice-versa
        even =  ! even;
      }
    }
  }
