// JavaScript Document
<!--

function apri_div( targetId ){
  if (document.getElementById){
  		target = document.getElementById( targetId );
		//alert(target.style.display);
  			if (target.style.display == "none"){
  				target.style.display = "block";
  			} 
			else 
			{
				if (target.style.display == "block"){
					target.style.display = "none";
				} 
  			}
  	}
}

function apri_divnav(){
	var args=apri_divnav.arguments;
	for (i=0; i<(args.length); i++) 
	{ 
		val=(args[i]);
		//if (document.getElementById){
		if (val){
			target = document.getElementById( val );
  			if (target.style.display == "none"){
  				target.style.display = "block";
				
				id_trgt='id'+[i+1];
				id_trgt_e=document.getElementById(id_trgt);
				id_trgt_e.style.backgroundColor = "fff";
				id_trgt_e.style.borderTop = "1px solid fff";
  			} 
			else 
			{
				if (target.style.display == "block"){
					target.style.display = "none";
				id_trgt='id'+[i+1];
				id_trgt_e=document.getElementById(id_trgt);
				id_trgt_e.style.backgroundColor = "ccc";
				} 
  			}
		}
	} 

}

function apri(){
	var args=apri.arguments;
	for (i=0; i<(args.length); i++) 
	{ 
		val=MM_findObj(args[i]);
		//if (document.getElementById){
		if (val){
			target = document.getElementById( val.name );
  			if (target.style.display == "none"){
  				target.style.display = "block";
  			} 
			else 
			{
				if (target.style.display == "block"){
					target.style.display = "none";
				} 
  			}
		}
	} 

}

function validate_fld( tid,iix ) { //v4.0

	var tid,nm,iix,val,errori=''
	iix++;
	if (document.getElementById){
  		val = document.getElementById( tid );
		nm=val.name; if ((val=val.value)!="")
        if (isNaN(val)) errori+='il campo n° '+(iix)+' può essere solo numerico.\n';
		if ((val<0))  errori+='nel campo n° '+(iix)+' non può esserci un valore negativo.\n';
	} 
  if (errori) alert('Ci sono i seguenti errori: \n'+errori);
  document.MM_returnValue = (errori == '');
}

function check_pwd(test)
{
	pwd1 = document.SchedaPrsct.Password.value
	if (test.value != document.SchedaPrsct.Password.value )
	{
		alert("Attenzione, le password non coinidono!");
		test.value = "";
		test.focus();
		return false;
	}
	return true;
}

function check_mail(test)
{
	if ((test.value.length < 6 ) || (test.value.indexOf("@") == -1) || (test.value.indexOf(".") == -1))
	{
		alert("Attenzione, l'indirizzo email non e' corretto!");
		test.focus();
		return false;
	}
	
	return true;
}

function check_num(test)
{
	if (test.value > 0) 
	{
		return true;
	}
	
	str = new String(test.value);
	
	con = 0;
	cc = str.charAt(0);
	if(cc == " " || str.length < 4)
	{
		alert('Il campo numerico non contiene valori corretti');
		test.value = "";
		test.focus();
		return false;
	}
	else
	{
		for(k = 0; k < str.length; k++)
		{
			c = str.charAt(k);
			if (!(c >= '0' && c <= '9'))
			{
				con++;
			}
		}
		if(con > 0)
		{
			alert('Il valore inserito deve essere numerico e non negativo!');
			test.value = "";
			test.focus();
			return false;
		}
	}
	return true;
}
function check_euro(test)
{
	str = new String(test.value);
	
	con = 0;
	cc = str.charAt(0);
	if(cc == " " || str.length < 4 || (test.value.indexOf(".") != -1))
	{
		alert('Il campo non contiene valori corretti. \n Usare solo la , per separare le cifre decimali');
		test.value = "";
		test.focus();
		return false;
	}
	else
	{
		for(k = 0; k < str.length; k++)
		{
			c = str.charAt(k);
			if (!(c >= '0' && c <= '9' || c==',')) con++;
		}
		if(con > 0)
		{
			alert('Il campo non contiene valori corretti.');
			test.value = "";
			test.focus();
			return false;
		}
	}
	return true;
}
function check_txt(test)
{	
	str = new String(test.value);
	
	con = 0;
	cc = str.charAt(0);
	if(cc == " " || str.length < 4)
	{
		alert('Il campo  non contiene valori corretti');
		test.value = "";
		test.focus();
		return false;
	}
	else
	{
		for(k = 0; k < str.length; k++)
		{
			c = str.charAt(k);
			if ((c >= '0' && c <= '9'))
			{
				con++;
			}
		}
		if(con > 0)
		{
			alert('Il valore inserito può essere solo testo!');
			test.value = "";
			test.focus();
			return false;
		}
	}
	return true;
}
function check_tel(faxtel)
{
faxtel_v=faxtel.value
//var tel_reg_exp = /^([0-9]{2,})([0-9\s\.\-]{1})([0-9]{2,})+$/;
var tel_reg_exp = /^([0-9\s\.\-\+])+$/;
if (!tel_reg_exp.test(faxtel_v) || (faxtel_v == "") || (faxtel_v == "undefined")) {
		alert('Il campo  non contiene valori corretti\n il prefisso può essere separato solo con:  spazio,  . , -');
			faxtel.value = "";
			faxtel.focus();
			return false;
	}
}
function  (conversionString,inChar,outChar)
{
  var convertedString = conversionString.split(inChar);
  convertedString = convertedString.join(outChar);
  return convertedString;
}

function trim_in_out(inputString, removeChar) 
{
	var returnString = inputString;
	if (removeChar.length)
	{
	  while(''+returnString.charAt(0)==removeChar)
		{
		  returnString=returnString.substring(1,returnString.length);
		}
		while(''+returnString.charAt(returnString.length-1)==removeChar)
	  {
	    returnString=returnString.substring(0,returnString.length-1);
	  }
	}
	return returnString;
}

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_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];}
}


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_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,errori='',errori2='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  { 
  test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") 
	{
      if (test.indexOf('isEmail')!=-1) 
	  { 
	  p=val.indexOf('@');
      if (p<1 || p==(val.length-1)) errori+='- '+nm+' deve essere un indirizzo email valido.\n';
      } 
	  else if (test.indexOf('isLog')!=-1) 
	  { 
	  if (val.length<6) errori+='- '+nm+' deve essere di almeno 6 caratteri.\n';
      } 
	  else if (test.indexOf('isPIVA')!=-1) 
	  { 
	  if (val.length<11) errori+='- la Partita IVA deve contenere 11 numeri.\n';
      } 
	  else if (test.indexOf('isCAP')!=-1) 
	  { 
	  if (val.length<5) errori+='- il CAP deve contenere 5 numeri.\n';
      } 
	  else if (test.indexOf('isEuro')!=-1) 
	  { 
        if ((val<=0))  errori+='- '+nm+' non può essere negativo o nullo.\n';
      } 
	  else if (test!='R') 
	  { //num = parseFloat(val);
        if (isNaN(val)) errori+='- '+nm+' deve essere un numero.\n';
        if ((val<=0))  errori+='- '+nm+' non può essere negativo o nullo.\n';
    } } 
	else if (test.charAt(0) == 'R') errori += '- '+nm+' è obbligatorio.\n'; }
  } 
  //document.MM_returnValue = (errori == '');
  return errori
  
  
}

function ctrl_frm1() { //v1.0

	errori=MM_validateForm('Login','','RisLog','Password','','RisLog','ConfermaPwd','','RisLog','Email','','RisEmail','RagioneSociale','','R','Indirizzo','','R','PIVA','','isPIVA','CAP','','RisCAP','Citta','','R','Telefono','','R','Fax','','R','RespUffComm','','R');
	if( document.SchedaPrsct.Provincia.options[document.SchedaPrsct.Provincia.selectedIndex].value == '' ) 
	{ 
	errori+='- Selezionare una Provincia\n';
	}
	if( document.SchedaPrsct.Regione.options[document.SchedaPrsct.Regione.selectedIndex].value == '' )
	{ 
	errori+='- Selezionare una Regione\n';
	//alert('Regione= '+document.SchedaPrsct.Regione.options[document.SchedaPrsct.Regione.selectedIndex].value)
	}
	if ( document.SchedaPrsct.TipologiaAttivita.options[document.SchedaPrsct.TipologiaAttivita.selectedIndex].value == 'Concessionario' )
	{ 
		if( document.SchedaPrsct.SitoInternet.value == '' )
		{
		errori+='-indicare un indirizzo internet\n';
		}
	}

	if( document.SchedaPrsct.TipologiaAttivita.options[document.SchedaPrsct.TipologiaAttivita.selectedIndex].value == '' )
	{ 
	errori+='- Selezionare una Tipologia di Attivita\n';
	}
	
	if ( document.SchedaPrsct.TipologiaAttivita.options[document.SchedaPrsct.TipologiaAttivita.selectedIndex].value!= 'Concessionario' )
	{ 			
			errori2=MM_validateForm('PIVA','','RisPIVA','Titolare','','R','RespUffTech','','R','NumDipendenti','','RisNum');
	}
	
	if (errori)
	{	
		alert('Ci sono i seguenti errori:\n\n'+errori);		
	}
	else
	{
		apri_div('area1');//document.MM_returnValue = (errori == '');
		apri_div('area2');//document.MM_returnValue = (errori == '');

		if(document.SchedaPrsct.V_Ind.checked) {
			apri('V_Ind_desc');
			apri_div('gamma_txt');
		}
		if(document.SchedaPrsct.Conces_chkbx.checked) apri('ConColl1','ConColl2','ConColl3','ConColl4','ConColl5');
		
		var i,p,q,nm,test,args=ctrl_frm1.arguments;
			chk=0; chk2=0;

		for (i=0; i<(args.length); i++) 
			{ 
				val=MM_findObj(args[i]);
				vv2=args[i]+'_d1';
				vv3=args[i]+'_d2';
				val2=MM_findObj(vv2);
				val3=MM_findObj(vv3);
				if (val) 
				{ 
					nm=val.name;
					nm2=val2.name;
					nm3=val3.name;
					val_2=val2.value;
					val_3=val3.value;
					
					//if ((val=val.value)!="")
					if (val.checked) 
					{
						//alert(nm+' è flaggato');
						val2.style.display = "block";
						val3.style.display = "block";
						if (nm == "Altro"){ 
							vv0=args[i]+'_d0';
							val0=MM_findObj(vv0);
							val0.style.display = "block";			
						}
					}
				}
			}
	}

}
function rew_frm2() { //v1.0
		apri_div('area1');//document.MM_returnValue = (errori == '');
		apri_div('area2');//document.MM_returnValue = (errori == '');
		//apri_div('area3');//document.MM_returnValue = (errori == '');
}
function rew_frm3() { //v1.0
		//apri_div('area1');//document.MM_returnValue = (errori == '');
		apri_div('area2');//document.MM_returnValue = (errori == '');
		apri_div('area3');//document.MM_returnValue = (errori == '');
}
function ctrl_frm2() { //v1.0
		if ( document.SchedaPrsct.TipologiaAttivita.options[document.SchedaPrsct.TipologiaAttivita.selectedIndex].value != 'Concessionario' )
		{
			
			errori=MM_validateForm('Fatturato_Anno','','RisNum','Fatturato_UA','','RisEuro','NumVeicAllest_UA','','RisNum','NumVeicMBAll_UA','','RisNum');
			//errori+=errori2
		
			var i,p,q,nm,test,args=ctrl_frm2.arguments;
			chk=0; chk2=0;

			for (i=0; i<(args.length); i++) 
			{ 
				val=MM_findObj(args[i]);
				vv2=args[i]+'_d1';
				vv3=args[i]+'_d2';
				val2=MM_findObj(vv2);
				val3=MM_findObj(vv3);
				if (val) 
				{ 
					nm=val.name;
					nm2=val2.name;
					nm3=val3.name;
					val_2=val2.value;
					val_3=val3.value;
					
					//if ((val=val.value)!="")
					if (val.checked) 
					{
						//alert(nm+' è flaggato');
						val2.style.display = "block";
						val3.style.display = "block";
						
						if ((val_2="" || val_2==0) && (val_3="" || val_3==0)) errori+='\n- Nel campo '+nm+' i valori non possono essere entrambi nulli.\n';
						else  chk2=1;
					}
					if (!(val.checked))  chk++;
		 
				}
			} 
			//**********************************
			if(!(document.SchedaPrsct.Conces_chkbx.checked)){
				cc_chk=0;
				for (i=1; i<=5; i++)
				{ 
					cbi='ConColl'+i
					obj_i = MM_findObj(cbi);
					if (obj_i.value != '') cc_chk++;
					//alert('obj_i.value: '+obj_i.value+'--i: '+cc_chk)
				}	
				if (cc_chk==0) errori+='\n- Selezionare almeno un concessionario\n';
			}
			
			if (chk>0 && chk2!=1)  errori+='\n- Selezionare almeno un campo attività\n';
			
			// gamma interesse
			if(!document.SchedaPrsct.V_Comm.checked && !document.SchedaPrsct.V_Ind.checked)
			{
					errori+='\n- Selezionare almeno una gamma di interesse\n';
			}
			else 
			if(document.SchedaPrsct.V_Ind.checked)
			{
				if(document.SchedaPrsct.V_Ind_desc.value == '' )
				{ 
				errori+='\n- Indicare almeno un intervallo di M.T.T. per i veicoli industriali\n';
				}
			}
			
		}
	
		if (errori)
		{	
			alert('Ci sono i seguenti errori:\n\n'+errori);		
		}
		else
		{
			//apri_div('area1');//document.MM_returnValue = (errori == '');
			apri_div('area2');//document.MM_returnValue = (errori == '');
			apri_div('area3');//document.MM_returnValue = (errori == '');
		}

}

function ctrl_frm3() { //v1.0


	autherr=0;
	errori='';
		
	if(document.SchedaPrsct.check_auth1[1].checked)	autherr++;
	if(document.SchedaPrsct.check_auth2[1].checked)	autherr++;
	if(document.SchedaPrsct.check_auth3[1].checked)	autherr++;
	if(document.SchedaPrsct.check_auth4[1].checked)	autherr++;
	
	if (autherr>0) errori+='\n- Occorrono tutti i consensi per procedere.\n';
	if (errori)	alert('Ci sono i seguenti errori:\n\n'+errori);
	document.MM_returnValue = (errori == '');

}


