//<!--
function init()
{
	if (navigator.appName == "Netscape")
		{
			layerStyleRef="layer.";
			layerRef="document.layers[";
			styleSwitch="].visibility";
			//typeVis = "'show'";
			typeVis = "'visible'";
			typeHide = "'hide'";
		} 
	else 
	    {				
			layerStyleRef="layer.style.";
			layerRef="document.all.";
 			styleSwitch=".style.visibility";
			typeVis = "'visible'";
			typeHide = "'hidden'";
		}
}

function controllaemail(campo)
{
  if (campo.value.length != 0)
  {
	errore = 2;
	x = 0;
	stringa = campo.value.length;
			
	 for (y=0 ;y < stringa ; y++)
	 { 	
	 	if (campo.value.charAt(y).valueOf() != "@")
      	{
			errore = 1 ;			
		}
		else
		{	
			errore = 0;
			x = y;
			y = 1000;
		}
	 }
	 	
	if (errore > 0)
	 	{
				alert("Indirizzo E-MAIL non valido.");  
				campo.focus();
		        return false;
		}
			 
	 for (y=x ;y < stringa ; y++)
	 {
	 	if (campo.value.charAt(y).valueOf() != ".")
      	{
			errore = 1 ;
		}
		else
		{	
            if (y == (stringa - 1))
            { 
                errore = 1 ; 
            }
            else
            {   
                if (campo.value.charAt(y + 1).valueOf() == ".")
                {
                    errore = 1 ; 
                }
                else
                {
                   	errore = 0;
	        	    y = 1000;
                }
            }
		}
	 }
     if (errore > 0)
	{
		alert("Indirizzo E-MAIL non valido.");  
		campo.focus();
	    return false;
	}
	 return true;
  }
}
function AddEmail(campo)
{
	var pos;
	var email;
	var id;
	var frm = document.forms[1];
	
	for (var i = 0; i < campo.options.length; i++)
	{
		pos = campo.value.indexOf("|");
		id = campo.value.substr(0,pos);
		email = campo.value.substr(pos+1);
		if ((campo.options[i].index == true) && (campo.options[i].value != '*'))
		{
			if (frm.MailTo.value.length==0)
			{frm.MailTo.value = email;}
			else if (frm.MailCC.value.length==0)
			{frm.MailCC.value = email;}
			else
			{frm.MailCC.value = frm.MailCC.value+';'+email;}
		}
	}
}
function SetCountryProvince(campo)
{
	
	var txtcampo = eval("document.forms[1]."+campo.name+".options[document.forms[1]."+campo.name+".options.selectedIndex].text");
	if (txtcampo.toLowerCase() != "italia") {document.forms[1].Province.options.selectedIndex = 0;}
}

function RemoveSelValue(selname)
{
	var selMName = eval("document.forms[1]."+selname);
	if (selMName.options.selectedIndex > 0)
	{
		if (selMName.options[selMName.options.selectedIndex].value.length > 0)
		{
			for (var i = 0; i < selMName.options.length; i++)
			{
					if (selMName.options[i].selected == true)
					{selMName.options[i] = null;}
			}
		}
	}
	else
	{
	 	alert("Selezionare un valore da eliminare!")
		selMName.focus();
	 }
}
function controllanum(campo)
{
	if (isNaN(campo.value))
	{
		alert("Inserire un valore numerico!");
		campo.value = '';
		campo.focus();
        return false;
	}
}

function OpenWin(page,windowWidth,windowHeight)
{
	var win;
	var menu = 'no';
	//var windowWidth = 500;
	//var windowHeight = 250;
	var locX = ( screen.width - windowWidth ) / 2;
	var locY = ( screen.height - windowHeight ) / 2;

	var windowFeatures = "width=" + windowWidth
	                   + ",height=" + windowHeight
	                   + ",screenX=" + locX
	                   + ",screenY=" + locY
	                   + ",left=" + locX
	                   + ",top=" + locY
					   + ",toolbar=no"
					   + ",location=no"
					   + ",directories=no"
					   + ",status=yes"
					   + ",menubar=" + menu
					   + ",scrollbars=yes"
					   + ",resizable=yes";

	win = open(page,"EdileMultiServizi", windowFeatures);
}
function Vai(url,id,flag)
{
	var frm = document.forms[id];
	var trovato = 0;
	var checkfrm = false;
	var countradio = 0;
	var countradiof = 0;
	var countradiot = 0;
	var countradio1 = 0;
	var counttext = 0;
	var counttext1 = 0;
	var countselect = 0;
	var countselect1 = 0;
	var countselectM = 0;
	var countselectM1 = 0;
	var n;
	var v;
	var mess;
	
	for(var i=0; i <= frm.elements.length-1; i++) 
	{
		n = frm.elements[i].name;
		v = frm.elements[i].value;
		if (frm.elements[i].type == "select-one")
		{
			countselect += 1;
			if (frm.elements[i].value.length == 0)
			{
				alert("Il campo "+n+" è obbligatorio!");
				frm.elements[i].focus();
				return false;
			}
			else
			{
				checkfrm = true;
				countselect1 += 1;
			}
		}
		else if (frm.elements[i].type == "text")
		{
			if ((n.toLowerCase() == "ragione") && (v.length == 0))
			{
				if ((frm.nome.value.length == 0) || (frm.cognome.value.length == 0))
				{
					mess = "Selezionare almeno uno tra Ragione sociale e/o Nome e Cognome!";
					trovato = 1;
				}
			}
			else if ((n.toLowerCase() == "ragione") && (v.length > 0))
			{
				if ((frm.nome.value.length > 0) || (frm.cognome.value.length > 0))
				{
					mess = "Selezionare uno tra Ragione sociale e/o Nome e Cognome!";
					trovato = 1;
				}
			}
			else if ((n.toLowerCase() != "ragione") && (n.toLowerCase() != "nome") && (n.toLowerCase() != "cognome"))
			{
				counttext += 1;
				if (frm.elements[i].value.length == 0)
				{
					alert("Il campo "+n+" è obbligatorio!");
					frm.elements[i].focus();
					return false;
				}
				else
				{
					checkfrm = true;
					counttext1 += 1;
				}
			}
			if (trovato ==1)
			{
				alert(mess);
				frm.elements[i].focus();
				return false;
			}
		}
	}
	
	if ((checkfrm == true) && (countselect == countselect1) && (counttext == counttext1))
	{
		frm.action = url;
		frm.submit();
		return true;
	}
}
function Elimina(url,id)
{
	var frm = document.forms[id];
	
	if (confirm("Sei sicuro di voler continuare?")) 
		{
			frm.action=url;			
			frm.submit();
		}
}
function trim(a)
{	
  return a.replace(/^\s+/,'').replace(/\s+$/,'')
}
function ShowModulo()
{	
	if (navigator.appName == "Netscape")
	{
		if (document.layers['infoSpan'].visibility == 'hide')
		{
			document.layers['infoSpan'].visibility = 'visible';
		}
		else
		{
			document.layers['infoSpan'].visibility = 'hide';
		}
	}
	else
	{
		if (document.all['infoSpan'].style.visibility == 'hidden')
		{
			document.all['infoSpan'].style.visibility = 'visible';
		}
		else
		{
			document.all['infoSpan'].style.visibility = 'hidden';
		}
	}	
}

function RicaricaFrm(page)
{
	document.forms[1].action = page;
	document.forms[1].submit();
}
function NonAbilitata()
{
	alert('Area in costruzione!');
	return false;
}
function Vai2(url)
{
	var frm = document.forms[1];
	var checkfrm = false;
	var counttext = 0;
	var counttext1 = 0;
	var countselect = 0;
	var countselect1 = 0;
	var n;
	var v;
	
	for(var i=0; i <= frm.elements.length-1; i++) 
	{
		n = frm.elements[i].name;
		v = frm.elements[i].value;
		if (frm.elements[i].type == "select-one")
		{
			countselect += 1;
			if (v.length == 0)
			{
				alert("Il campo "+n+" è obbligatorio!");
				frm.elements[i].focus();
				return false;
			}
			else
			{
				checkfrm = true;
				countselect1 += 1;
			}
		}
		else if (frm.elements[i].type == "text")
		{
			counttext += 1;
			if (v.length == 0)
			{
					alert("Il campo "+n+" è obbligatorio!");
					frm.elements[i].focus();
					return false;
			}
			else
			{
					checkfrm = true;
					counttext1 += 1;
			}
		}
	}

	if ((checkfrm == true) && (countselect == countselect1) && (counttext == counttext1))
	{
				alert(url);
		frm.action = url;
		frm.submit();
		return true;
	}
}

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_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) { //v3.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); return x;
}

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];}
}

//-->

