  window.onerror = null;
  var undefined;

  // ----------------------------------------------------------------------

  function getParentNodeByName(obj, tag) {
    if (!obj.parentNode) { return false; }

    if (obj.parentNode.nodeName.toLowerCase() == tag.toLowerCase()) {
      return obj.parentNode;
    }

    return getParentNodeByName(obj.parentNode, tag);
  }

  // ----------------------------------------------------------------------

  function getPrevSiblingNodeByName(obj, tag) {
    if (!obj.previousSibling) { return false; }

    if (obj.previousSibling.nodeName.toLowerCase() == tag.toLowerCase()) {
      return obj.previousSibling;
    }

    return getPrevSiblingNodeByName(obj.previousSibling, tag);
  }

  // ----------------------------------------------------------------------

  function getNextSiblingNodeByName(obj, tag) {
    if (!obj.nextSibling) { return false; }

    if (obj.nextSibling.nodeName.toLowerCase() == tag.toLowerCase()) {
      return obj.nextSibling;
    }

    return getNextSiblingNodeByName(obj.nextSibling, tag);
  }

  // ----------------------------------------------------------------------

  function fireClickEvent(nodeId) {
    if (document.getElementById) {
      if (obj = document.getElementById(nodeId)) {
        obj.click();
      }
    }
  }

  // ----------------------------------------------------------------------

  function fireClickEventOnChild(obj, tag) {
    if (obj.hasChildNodes) {
      for (i=0; i<obj.childNodes.length; i++) {
        if (obj.childNodes[i].nodeName.toLowerCase() == tag.toLowerCase()) {

          if (obj.childNodes[i].click) {
            obj.childNodes[i].click();
            break;
          }

        }
      }
    }
  }

  // ----------------------------------------------------------------------

  function mover(obj, color) {
    if (color == undefined) {
      obj.style.backgroundColor = '#59666C';
    } else {
      obj.style.backgroundColor = color;
    }
  }

  // ----------------------------------------------------------------------

  function mout(obj, color) {
    if (color == undefined) {
      obj.style.backgroundColor = '#BCAE79';
    } else {
      obj.style.backgroundColor = color;
    }
  }

  // ----------------------------------------------------------------------

  function moverOnParentName(obj, tag, color) {
    newObj = getParentNodeByName(obj, tag);
    if (!newObj) { return; }

    if (color == undefined) {
      mover(newObj);
    } else {
      mover(newObj, color);
    }
  }

  // ----------------------------------------------------------------------

  function moutOnParentName(obj, tag, color) {
    newObj = getParentNodeByName(obj, tag);
    if (!newObj) { return; }

    if (color == undefined) {
      mout(newObj);
    } else {
      mout(newObj, color);
    }
  }

  // ----------------------------------------------------------------------

  function moverOnPrevSiblingName(obj, tag, color) {
    newObj = getPrevSiblingNodeByName(obj, tag);
    if (!newObj) { return; }

    if (color == undefined) {
      mover(newObj);
    } else {
      mover(newObj, color);
    }
  }

  // ----------------------------------------------------------------------

  function moutOnPrevSiblingName(obj, tag, color) {
    newObj = getPrevSiblingNodeByName(obj, tag);
    if (!newObj) { return; }

    if (color == undefined) {
      mout(newObj);
    } else {
      mout(newObj, color);
    }
  }

  // ----------------------------------------------------------------------

  function moverOnNextSiblingName(obj, tag, color) {
    newObj = getNextSiblingNodeByName(obj, tag);
    if (!newObj) { return; }

    if (color == undefined) {
      mover(newObj);
    } else {
      mover(newObj, color);
    }
  }

  // ----------------------------------------------------------------------

  function moutOnNextSiblingName(obj, tag, color) {
    newObj = getNextSiblingNodeByName(obj, tag);
    if (!newObj) { return; }

    if (color == undefined) {
      mout(newObj);
    } else {
      mout(newObj, color);
    }
  }

  function checkContatto(){

    if(document.contattaci.mittente.value == ''){
        alert("Il campo indirizzo e-mail mittente e' obbligatorio");
        return;
    }
    if(!isValidEmail(document.contattaci.mittente.value)){
        alert("Inserire un indirizzo e-mail valido");
        return;
    }
    if(document.contattaci.nome.value == ''){
        alert("Il campo nome e cognome e' obbligatorio");
        return;
    }
    if(document.contattaci.indirizzo.value == ''){
        alert("Il campo indirizzo e' obbligatorio");
        return;
    }

    document.contattaci.submit();
  }

  function isValidEmail(Email_address) {
	//if (!(isOnlyChars(Email_address,'\'"')))
	//	return false;
	emaillength = Email_address.length
    //alert(emaillength)
    if ((emaillength < 1) || (Email_address.indexOf(" ") != -1)) 
		return false
	var i = 1
    while ((i < emaillength) && (Email_address.charAt(i) != "@")) 
		i++
	restOfString = Email_address.substring(i+1,emaillength)
	if(restOfString.indexOf("@") != -1)
		return false
	else if ((i >= emaillength) || (Email_address.charAt(i) != "@") || (Email_address.charAt(i-1) == " ") || (Email_address.charAt(i+1) == " ") ) 
		return false
	else
		i++
    while ((i < emaillength) && (Email_address.charAt(i) != "."))
		i++
    if ((i >= emaillength - 1) || (Email_address.charAt(i) != ".")) 
		return false
	else 
		return true
  }
  
  function isOnlyChars(myString, strAllowedChars) {
	var searchChar, i, loopChar;
	if (myString == "") 
		return true;
	for (loopChar = 1; loopChar <= myString.length; loopChar++) {
		searchChar = myString.charAt(loopChar - 1)
		i = strAllowedChars.indexOf(searchChar);
		if (i == -1)
			return false;
	}
	return true;
  }
