// JavaScript Document per caricamento immagini

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

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_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

// per formulario, ripreso da esercizio con Barenco ed adattato

// script per controllo mail preso da: http://free-script.it/post/Script_javascript_Controllo_validità_email-53.htm
// ed adattato

function controllomail(mail){	
	var espressione = /^[_a-z0-9+-]+(\.[_a-z0-9+-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+$/;	
	
	if (!espressione.test(mail))	{	    
	
	return false;	} return true; }

function emailCheck(_emailStr) {
	var emailPat=/^(.+)@(.+)$/;		
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	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) {
		return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];
	if (user.match(userPat)==null) {
		return false;
	}
	var domainArray=domain.match(domainPat);
	if (domainArray==null) {
		 return false;
	}
	return true;
}

function hideDiv(_id) {
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(_id).style.display = 'none';
	}	else {
		if (document.layers) { // Netscape 4
			document._id.display = 'none';
		}	else { // IE 4
			document.all._id.style.display = 'none';
		}
	}
}				

function showDiv(_id) {
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(_id).style.display = 'block';
	}	else {
		if (document.layers) { // Netscape 4
			document._id.display = 'block';
		}	else { // IE 4
			document.all._id.style.display = 'block';
		}
	}
}

function getField(_id) {
	if (document.getElementById) {
		return document.getElementById(_id);
	} else if (document.all) {
		return document.all[_id];
	}	else if (document.layers)	{
		return document.layers[_id];
	}
	return false;
}

function writeHTML(_id,_text) {
	if (document.getElementById) {
		x = document.getElementById(_id);
		x.innerHTML = '';
		x.innerHTML = _text;
	} else if (document.all) {
		x = document.all[_id];
		x.innerHTML = _text;
	}	else if (document.layers)	{
		x = document.layers[_id];
		x.document.open();
		x.document.write(_text);
		x.document.close();
	}
}

function isNull(_field) {
	if (_field.type == "text") {
		return ((_field.value.length==0) || (_field.value==null));
	} else if (_field.type == "radio" || _field.type == "checkbox") {
		return !_field.checked;
	} else if (_field.type == "select-one") {
		return (_field.options[_field.selectedIndex].value.length == 0 || _field.options[_field.selectedIndex].value == "");
	}
	return false;
}

function get(sid){

	if (document.all) {
	return document.all[sid];
	}
	else if (document.layers) {
	return document.layers[sid];
	}
	else if (document.getElementById) {
	return document.getElementById(sid);
	}
}


function controllaForm(_form)	{	// altra versione per il controllo del formulario
var Messaggio = "";		

if (get("cognome").value == "") {
Messaggio=(Messaggio+"Manca Cognome<br>");			
get("cognome").className='messerr';
}

if (get("nome").value=="") {
Messaggio=(Messaggio+"Manca Nome<br>");	
get("nome").className='messerr';
}

if (get("email").value=="") {
Messaggio=(Messaggio+"Manca E-mail<br>");
get("email").className='messerr';
}

if (!controllomail(get("email").value))	{
Messaggio=(Messaggio+"Controlla email<br>")	
get("email").className='messerr';
}

if (Messaggio=="") {
get('formsend').submit();
} else {	
showDiv('messaggio');	
get('messaggio').innerHTML = Messaggio;
}


}	

/* ================================================================ 
This copyright notice must be kept untouched in the stylesheet at 
all times.

The original version of this script and the associated (x)html
is available at http://www.stunicholls.com/menu/skeleton.html
Copyright (c) 2005-2007 Stu Nicholls. All rights reserved.
This script and the associated (x)html may be modified in any 
way to fit your requirements.
=================================================================== */

stuHover = function() {
	var cssRule;
	var newSelector;
	for (var i = 0; i < document.styleSheets.length; i++)
		for (var x = 0; x < document.styleSheets[i].rules.length ; x++)
			{
			cssRule = document.styleSheets[i].rules[x];
			if (cssRule.selectorText.indexOf("LI:hover") != -1)
			{
				 newSelector = cssRule.selectorText.replace(/LI:hover/gi, "LI.iehover");
				document.styleSheets[i].addRule(newSelector , cssRule.style.cssText);
			}
		}
	if (document.getElementById("nav")) {			// aggiunto questa riga all'originale
		var getElm = document.getElementById("nav").getElementsByTagName("LI");
		for (var i=0; i<getElm.length; i++) {
			getElm[i].onmouseover=function() {
				this.className+=" iehover";
			}
			getElm[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" iehover\\b"), "");
			}
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", stuHover);

