function ACTMENU(imgName, sPath)
{
/*
  if (document.images)
  {
      document.images["textomenu"+imgName].src =  sPath+"/bott_"+imgName+"_over.gif";
  }*/
}
function DESMENU(imgName,sPath)
{
/*  if (document.images)
  {	 
      document.images["textomenu"+imgName].src =  sPath+"/bott_"+imgName+".gif";
  }*/
}


function ACTSUBMENU(imgName,fila,imgSrc)
{
   MM_showHideLayers('desp'+imgName,'','show')

  if (document.images)
  {
    if (imgSrc != "none")
    {
		var el = "Filasubm" + imgName+fila;
	 	document.getElementById(el).className="td_sotto_menu_over";	
    }
	
  }
}
function DESSUBMENU(imgName,fila,imgSrc)
{
  MM_showHideLayers('desp'+imgName,'','show')
  if (document.images)
  {
    if (imgSrc != "none")
    {
	  var el = "Filasubm"+imgName+fila;
	  document.getElementById(el).className="td_sotto_menu_out";
	 //  eval("Filasubm"+imgName+fila).className="td_sotto_menu_out";
    }
//	document.images["textomenu"+imgName].src = "img/bott_"+imgName+".gif";
  }
}

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_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  var oItem;
  for (i=0; i<(args.length-2); i+=3) 
	if ((obj=MM_findObj(args[i]))!=null) 
		{ 
			v=args[i+2];
			if (obj.style) 
				{ 
					obj=obj.style; 
					v=(v=='show')?'visible':(v=='hide')?'hidden':v; 
				}
			if ( v=='visible')
			   {
		//		   alert("err "+ "textomenu"+args[0].replace('desp','')+ '  //  menu_'+args[0].replace('desp','')+'_cab');
			   // oItem = document.images["textomenu"+args[0].replace('desp','')];
				oItem = document.getElementById('textomenu'+args[0].replace('desp',''));
				
				larghezza_riga = findPosX(oItem);//oItem.width;
			//	obj.left = findPosX(oItem);
			
				var left_new = findPosX(document.getElementById('menu_'+args[0].replace('desp','')+'_cab'));
				var sum = parseInt(findPosX(document.getElementById('menu_'+args[0].replace('desp','')+'_cab'))) + parseInt(document.getElementById(args[0]).style.width);
				var val_max = 960;// parseInt(findPosX(document.getElementById("fototesta")) + 639);
			//	alert("width "+document.getElementById('tbl'+args[0].replace('desp','')).style.width);
			//	alert("pr: "+ findPosX(document.getElementById('menu_'+args[0].replace('desp','')+'_cab')) + " + sec: "+parseInt(findPosX(document.getElementById("fototesta"))) + "ter: "+ parseInt(document.getElementById(args[0]).style.width) +" sum: "+sum + "  "+args[0]);
		/*		if(sum > val_max)
				{
				//	alert("sborda di: "+ (sum - val_max));
				//	obj.left = obj.left - (sum - 780);
					left_new =  left_new - (sum - val_max) +2;
				}*/
				
				obj.left = left_new;
				
				altezza_riga = 20;//oItem.height + 8;
			//	altezza_riga = 26;
			// 
				obj.top =findPosY(oItem)+ altezza_riga+1;
			   }
			obj.visibility=v; 
		}
}
				
function findPosX(obj)
{
      var curleft = 0;
      if (obj.offsetParent)
      {
            while (obj.offsetParent)
            {
                  curleft += obj.offsetLeft
                  obj = obj.offsetParent;
            }
      }
      else if (obj.x)
            curleft += obj.x;
      return curleft; //-10;
}

function findPosY(obj)
{
      var curtop = 0;
      if (obj.offsetParent)
      {
            while (obj.offsetParent)
            {
                  curtop += obj.offsetTop
                  obj = obj.offsetParent;
            }
      }
      else if (obj.y)
            curtop += obj.y;
      return curtop;

}

function vedi_menu(elemento)
{	
	var selectValue = document.getElementById(elemento);

		selectValue.style.visibility = "visible";
		selectValue.style.position = "relative";
}

function nascondi_menu(elemento)
{	
		var selectValue = document.getElementById(elemento);
		selectValue.style.visibility = "hidden";
		selectValue.style.position = "absolute";
	
}

function vedi_disattivi(elemento)
{	
	var selectValue = document.getElementById(elemento);
//	alert("ele " + elemento +" "+ selectValue.style.visibility);
	if(selectValue.style.visibility=="hidden")
	{
		selectValue.style.visibility = "visible";
		selectValue.style.position = "relative";
	}
	else
	{
		selectValue.style.visibility = "hidden";
		selectValue.style.position = "absolute";
	}
//	alert("ele " + elemento +" "+ selectValue.style.visibility);
}
function vedi_url_ins(elemento,id_inserz,lingua_inserz)
{	
	var selectValue = document.getElementById(elemento);
	var valore_ins = id_inserz;
	if(selectValue.style.visibility=="hidden")
	{
		leggi_ajax_web_3(valore_ins,lingua_inserz,elemento);
		
		selectValue.style.visibility = "visible";
		selectValue.style.position = "relative";
	}
	else
	{
		selectValue.style.visibility = "hidden";
		selectValue.style.position = "absolute";
	}
}

function vedi_stat_ins(elemento,id_inserz)
{	
	var selectValue = document.getElementById(elemento);
	var valore_ins = id_inserz;
	if(selectValue.style.visibility=="hidden")
	{
		leggi_ajax_web_4(valore_ins,elemento);
		
		selectValue.style.visibility = "visible";
		selectValue.style.position = "relative";
	}
	else
	{
		selectValue.style.visibility = "hidden";
		selectValue.style.position = "absolute";
	}
}
function update_form(val)
{
	if(val == 'P')
	{	
		document.registr.azi.disabled = true;
		document.registr.azi.className = 'textboxdisabled';
	    document.registr.piva.disabled = true;
		document.registr.piva.className = 'textboxdisabled';
		 
	}
	else
	{
		document.registr.azi.disabled = false;
		document.registr.azi.className = '';
	    document.registr.piva.disabled = false;
		document.registr.piva.className = '';	
		
	}
}
function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}

function disab(bott)
{
	bott.disabled = true;
	if(valid_form("1") == true)
	{
		return true;
	}
	else
	{
		bott.disabled = false;
		return false;
	}
}

function valid_form(view)
{
	var err=0;
	var msg='Sono stati riscontrati i seguenti errori di inserimento:\n\n';
	
	if (trim(document.registr.nome.value) == "")
		{
			err=1;
			var msg=msg+'- Nome non indicato'+'\n';		
		}
	if (trim(document.registr.cognome.value) == "")
		{
			err=1;
			var msg=msg+'- Cognome non indicato'+'\n';		
		}
	if (document.registr.privato.checked)
	{}
		var lencf = registr.code_fisc.value;	
		if ((trim(document.registr.code_fisc.value) == "") || (lencf.length < 16) || (lencf.indexOf(' ') > -1))
		{
			var err=1;
			var msg=msg+'- Codice fiscale non indicato o non corretto'+'\n';		
		}
	
	if (document.registr.azienda.checked)
	{
		if (trim(document.registr.azi.value) == "")
		{
			err=1;
			var msg=msg+'- Azienda non indicato'+'\n';		
		}
		var leniva = registr.piva.value;
		if ((trim(document.registr.piva.value) == "") || (leniva.length < 11))
			{
				var err=1;
				var msg=msg+'- Partita IVA non indicata o non corretta'+'\n';		
			}
		
	}
	if (trim(document.registr.indirizzo.value) == "")
		{
			var err=1;
			var msg=msg+'- Indirizzo non indicato'+'\n';		
		}
			
	if (trim(document.registr.cap.value) == "" || (document.registr.cap.value.length < 5))
		{
			var err=1;
			var msg=msg+'- CAP non indicato oppure non corretto'+'\n';		
		}
	if (trim(document.registr.citta.value) == "")
		{
			var err=1;
			var msg=msg+'- Citta non indicata'+'\n';		
		}	
		
	if (document.registr.prov.selectedIndex == 0)
		{
			var err=1;
			var msg=msg+'- Provincia non indicata'+'\n';		
		}
	if (document.registr.stato.selectedIndex == 0)
		{
			var err=1;
			var msg=msg+'- Stato di residenza non indicato'+'\n';		
		}	 
		
	if (trim(document.registr.telefono.value) == "" && trim(document.registr.cellulare.value) == "")
		{
			var err=1;
			var msg=msg+'- Indicare almeno un recapito telefonico fisso o cellulare'+'\n';		
		}
	if (trim(document.registr.email.value) == "")
		{
			var err=1;
			var msg=msg+'- Non hai indicato il tuo indirizzo eMail'+'\n';		
		}
	else
		{
			var x = document.registr.email.value;
			var filter  = /^([a-zA-Z0-9_\.\-\'])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/;
			if (filter.test(x)) var emailgiusto=1;
			else 
				{
					var err=1;
					var msg=msg+'- L\'indirizzo email ha un formato non corretto'+'\n';		
				
				}		
		}			

	view_old = view;
	if(view == 1)
	{
		if(!document.registr.pry.checked)
		{	
			var err=1;
			var msg=msg+'- Non e\' possibile accettare la registrazione se non viene dato il consenso al trattamento dei dati personali'+'\n';	
		}
	}
	else
	{		
		
		view = 1;
	}
	if (err == 0)
	{
		//alert(msg);	
		if(view_old==1)
		{
			document.registr.brg.disabled = true;
		}
		return true;	
	}
	else
	{
		var msg=msg+'\n'+'Corregere i dati prima di procedere';
		if(view == 1)
			alert(msg);
		return false;
	}	
}

function lettersOnly(evt) {
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : 
        ((evt.which) ? evt.which : 0));
    if (charCode > 31 && (charCode < 65 || charCode > 90) && 
        (charCode < 97 || charCode > 122)) {
        alert("Puoi inserire solo lettere!");
        return false;
    }
    return true;
}

function numeralsOnly(evt) {
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : 
        ((evt.which) ? evt.which : 0));
    if (charCode > 31 && (charCode < 48 || charCode > 57)) {
        alert("Puoi inserire solo numeri!");
        return false;
    }
    return true;
}
