var isNS4=document.layers?true:false;
var isIE=document.all?true:false;
var isNS6=!isIE&&document.getElementById?true:false;
var isDOM = (document.getElementById) ? true : false;


<!--
//v1.7
// Flash Player Version Detection
// Detect Client Browser type
// Copyright 2005-2008 Adobe Systems Incorporated.  All rights reserved.
var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
function ControlVersion()
{
	var version;
	var axo;
	var e;
	// NOTE : new ActiveXObject(strFoo) throws an exception if strFoo isn't in the registry
	try {
		// version will be set for 7.X or greater players
		axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		version = axo.GetVariable("$version");
	} catch (e) {
	}
	if (!version)
	{
		try {
			// version will be set for 6.X players only
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
			
			// installed player is some revision of 6.0
			// GetVariable("$version") crashes for versions 6.0.22 through 6.0.29,
			// so we have to be careful. 
			
			// default to the first public version
			version = "WIN 6,0,21,0";
			// throws if AllowScripAccess does not exist (introduced in 6.0r47)		
			axo.AllowScriptAccess = "always";
			// safe to call for 6.0r47 or greater
			version = axo.GetVariable("$version");
		} catch (e) {
		}
	}
	if (!version)
	{
		try {
			// version will be set for 4.X or 5.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = axo.GetVariable("$version");
		} catch (e) {
		}
	}
	if (!version)
	{
		try {
			// version will be set for 3.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = "WIN 3,0,18,0";
		} catch (e) {
		}
	}
	if (!version)
	{
		try {
			// version will be set for 2.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			version = "WIN 2,0,0,11";
		} catch (e) {
			version = -1;
		}
	}
	
	return version;
}
// JavaScript helper required to detect Flash Player PlugIn version information
function GetSwfVer(){
	// NS/Opera version >= 3 check for Flash plugin in plugin array
	var flashVer = -1;
	
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
			var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
			var descArray = flashDescription.split(" ");
			var tempArrayMajor = descArray[2].split(".");			
			var versionMajor = tempArrayMajor[0];
			var versionMinor = tempArrayMajor[1];
			var versionRevision = descArray[3];
			if (versionRevision == "") {
				versionRevision = descArray[4];
			}
			if (versionRevision[0] == "d") {
				versionRevision = versionRevision.substring(1);
			} else if (versionRevision[0] == "r") {
				versionRevision = versionRevision.substring(1);
				if (versionRevision.indexOf("d") > 0) {
					versionRevision = versionRevision.substring(0, versionRevision.indexOf("d"));
				}
			}
			var flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
		}
	}
	// MSN/WebTV 2.6 supports Flash 4
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
	// WebTV 2.5 supports Flash 3
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
	// older WebTV supports Flash 2
	else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
	else if ( isIE && isWin && !isOpera ) {
		flashVer = ControlVersion();
	}	
	return flashVer;
}
// When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision)
{
	versionStr = GetSwfVer();
	if (versionStr == -1 ) {
		return false;
	} else if (versionStr != 0) {
		if(isIE && isWin && !isOpera) {
			// Given "WIN 2,0,0,11"
			tempArray         = versionStr.split(" "); 	// ["WIN", "2,0,0,11"]
			tempString        = tempArray[1];			// "2,0,0,11"
			versionArray      = tempString.split(",");	// ['2', '0', '0', '11']
		} else {
			versionArray      = versionStr.split(".");
		}
		var versionMajor      = versionArray[0];
		var versionMinor      = versionArray[1];
		var versionRevision   = versionArray[2];
        	// is the major.revision >= requested major.revision AND the minor version >= requested minor
		if (versionMajor > parseFloat(reqMajorVer)) {
			return true;
		} else if (versionMajor == parseFloat(reqMajorVer)) {
			if (versionMinor > parseFloat(reqMinorVer))
				return true;
			else if (versionMinor == parseFloat(reqMinorVer)) {
				if (versionRevision >= parseFloat(reqRevision))
					return true;
			}
		}
		return false;
	}
}
function AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}
function AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
  var str = '';
  if (isIE && isWin && !isOpera)
  {
    str += '<object ';
    for (var i in objAttrs)
    {
      str += i + '="' + objAttrs[i] + '" ';
    }
    str += '>';

    for (var i in params)
    {
	 	if(i == 'movie') //alert(params[i]+'?'+embedAttrs['par'])
	      str += '<param name="' + i + '" value="' + params[i] +'?'+embedAttrs['par'] + '" /> ';
		else	
			str += '<param name="' + i + '" value="' + params[i] + '" /> ';
    }
    str += '</object>';
  }
  else
  {
    str += '<embed ';
    for (var i in embedAttrs)
    {
	 	if(i == 'src') 
 	      str += i + '="' + embedAttrs[i] +'?'+embedAttrs['par']+ '" ';
	 	else
	      str += i + '="' + embedAttrs[i] + '" ';
    }
    str += '> </embed>';
  }
  //alert(str)
  document.write(str);
}
function AC_FL_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}
function AC_SW_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
     , null
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}
function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    
	 //alert(currArg)
    switch (currArg){	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;	
      case "src":
      case "movie":	
        args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblclick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
      case "id":	  
        ret.objAttrs[args[i]] = args[i+1];
        break;
	   case "style":	
        ret.objAttrs[args[i]] = args[i+1];
		  ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
        break;			  
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}




function ridim(){
	var vp=Viewport();
	
	//alert('windowY: '+ vp.windowY + ' - scrollY:'+vp.scrollY + ' - pageY:'+vp.pageY)
	if(vp.pageY > vp.windowY)
		$('main_ex').style.height=vp.pageY+'px';
	else
		$('main_ex').style.height=vp.windowY+'px';
}




function Viewport(){ 
	this.windowX = (document.documentElement && document.documentElement.clientWidth) || window.innerWidth || self.innerWidth || document.body.clientWidth; 
	this.windowY = (document.documentElement && document.documentElement.clientHeight) || window.innerHeight || self.innerHeight || document.body.clientHeight; 
	this.scrollX = (document.documentElement && document.documentElement.scrollLeft) || window.pageXOffset || self.pageXOffset || document.body.scrollLeft; 
	this.scrollY = (document.documentElement && document.documentElement.scrollTop) || window.pageYOffset || self.pageYOffset || document.body.scrollTop; 
	this.pageX = (document.documentElement && document.documentElement.scrollWidth) ? document.documentElement.scrollWidth : (document.body.scrollWidth > document.body.offsetWidth) ? document.body.scrollWidth : document.body.offsetWidth; 
	this.pageY = (document.documentElement && document.documentElement.scrollHeight) ? document.documentElement.scrollHeight : (document.body.scrollHeight > document.body.offsetHeight) ? document.body.scrollHeight : document.body.offsetHeight;

	return this;
}

function menuOver(o){
	o.style.backgroundColor="#bbb";
}
function menuOut(o){
	o.style.backgroundColor="transparent";
}
function showImg(g,t){
	//alert(g+' - '+t)
	for(var i=1;i<=t;i++){
		if( $('im_'+i) ) 
			if(i==g){
				$('im_'+i).show();
				//$('im_'+i).appear();
				//new Effect.Appear('im'+i, { duration: .3 });
				$('bp_'+i).style.backgroundColor='#292929';
			}else{
				$('im_'+i).hide();
				$('bp_'+i).style.backgroundColor='#484a47';
			}
	}
}


//====================================================================================================================================
function menuClass(){
	this.incorso=false;
	this.m1='';
	this.m2='';
	
	//menu selezionati FIX
	this.sel_m1='';
	this.sel_m2='';
	
	//prodotti
	this.id=0;
	
	//###############################################	
	this.show=function(mn,mode){
		
		if(this.incorso){
			//alert('this.incorso')
			//return;
		} 	
		
		var mn_array=mn.split('_');
		
		if(mn_array.length == 1){
			this.m1=mn;
			this.m2='';
		}else if(mn_array.length == 2){
			this.m1=mn.substring(0,1);
			this.m2=mn;			
		}

		//ripristino il menu principale togliendo l'immagine di lato....
		var m=$$('#menu li');
		for(var i=0;i<m.length;i++){
			var link=m[i].select('img.rollover');
			if(link.length){
				m[i].removeChild(link[0])	
			}
		}	
		
		//evidenzio menu1 aggiungendo l'immagine di lato!
		if($('m1_'+this.m1)){
			var selImg=new Element('IMG');
			selImg.src='gui/images/menu/rollover.gif';
			selImg.className='rollover';
			$('m1_'+this.m1).appendChild(selImg);
			
		}	
		
		//controllo che il menu 1° liv esista!
		if( !$('m2_'+this.m1) ) return;			
		

		

		var h=8;
		this.incorso=true;	
		
		//verifico che il menu 1° livello non sia già aperto		
		if(this.m1==this.sel_m1){
			//alert(this.m1+'-'+this.sel_m1)
			if(this.m2!='') myMenu.show2();
			return;
		}
		
		
		
		//ritiro i sottomenu' 2 livello	
		var m=$$('div.menu2');	
		for(var i=0;i<m.length;i++){
			m[i].style.display='none';
		}		
		
		//ritiro i sottomenu' 1 livello
		var m=$$('div.menu1');	
		for(var i=0;i<m.length;i++){
			//new Effect.Move(m[i], { x: 0, y: h, mode: 'absolute', duration: 0.3, queue: { position: 'front', scope: 'menu2' }});				
			m[i].style.left=0+'px';
		}		
		


		
		//apro i menu di 1° livello
		if( $('m2_'+this.m1) ){
						
			if(mode=='fix'){
				new Effect.Move($('m2_'+this.m1), { x: 160, y: h, mode: 'absolute', duration: 0, queue: { position: 'end', scope: 'menu2' },
						afterFinish: function(){
							//memorizzo nella classe il menu selezionato
							myMenu.sel_m1=myMenu.m1;						
							if(this.m2!='') myMenu.show2('fix');
						}  
					});
			}else
				new Effect.Move($('m2_'+this.m1), { x: 160, y: h, mode: 'absolute', duration: 0.3, queue: { position: 'end', scope: 'menu2' },
						afterFinish: function(){
							//memorizzo nella classe il menu selezionato
							myMenu.sel_m1=myMenu.m1;
							//alert(myMenu.m1)					
							if(this.m2!='') myMenu.show2();
						}  
					});	
		}else{
			this.incorso=false;
		}					
	}
	

	//###############################################
	this.show2=function(mode){

		var h=8;
	
		//ritiro i sottomenu' 2° livello	
		var m=$$('div.menu2');	
		for(var i=0;i<m.length;i++){
			m[i].style.display='none';
		}		
	
		//prima rimuovo la classe sel dai menu di #2 livello
		var m=$$('#m2_'+this.m1+' li');
		for(var i=0;i<m.length;i++){
			m[i].className='';
		}	
		//poi evidenzio quello selezionato
		//alert('m2____' + this.m2)
		if ($('m2_' + this.m2)) {
			$('m2_' + this.m2).className='sel';
	   }
				
		if( $('m3_'+this.m2) ){
			//alert('-'+this.m1+'-'+this.m2)
			if(mode=='fix'){
				$('m3_'+this.m2).style.left= '319px';
				$('m3_'+this.m2).style.top= h+'px';
				$('m3_'+this.m2).style.display='block';
				this.incorso=false;
			}else{
				//alert('m3_'+this.m2)			
				new Effect.BlindRight(
					$('m3_'+this.m2), 
					{ 	
						duration: 0.3, 
						queue: { position: 'end', scope: 'menu2' },
						afterFinish: function(){
							//incorso=false;
							//alert($('m3_'+menu).style.left + '-' + $('m3_'+menu).style.top);
						}  
					});	
			}
		}	
		if(this.m2=='3_1')
			loadHTML('listRicambi&id='+this.id,'list_ricambi');
		if(this.m2=='3_2')
			loadHTML('listMolle&id='+this.id,'list_molle');			
		if(this.m2=='3_3')
			loadHTML('listDec&id='+this.id,'list_dec');		
		if(this.m2=='5_2'){
			var lis=$$('#m3_5_2 li');
			for(var i=0;i<lis.length;i++){
				if (lis[i].innerHTML.indexOf(pag) > 0) {
					lis[i].className = 'sel';
					lis[i].firstDescendant().style.color='#000';
				}else{
					lis[i].className = '';
				} 
					
			}
		}	
		this.incorso=false;	
	}	
	
}

var myMenu=new menuClass();

//====================================================================================================================================


//====================================================================================================================================
function selDownCat(sel){
	var m=$$('li.downCat');
	//alert(m.length)
	for(var i=0;i<m.length;i++){
		m[i].style.cssText='';
		if(sel==i) m[i].style.cssText='background-color:#ec7c3a;';
	}	
}
//====================================================================================================================================
Effect.BlindRight = function(element) {
  element = $(element);
  var elementDimensions = element.getDimensions();
  return new Effect.Scale(element, 100, Object.extend({
    scaleContent: false,
    scaleY: false,
    scaleFrom: 0,
    scaleMode: {originalHeight: elementDimensions.height, originalWidth: elementDimensions.width},
    restoreAfterFinish: true,
    afterSetup: function(effect) {
      effect.element.makeClipping().setStyle({
        width: '0px',
        height: effect.dims[0] + 'px'
      }).show();
    },
    afterFinishInternal: function(effect) {
      effect.element.undoClipping();
    }
  }, arguments[1] || { }));
};

//====================================================================================================================================
inElaborazione=false;
function systemBusy(status){
   //alert(status)
   if(status){
      inElaborazione=true;
      //$('footer').innerHTML='<div style="font-size:10px;"><img src="'+gui_path+'/images/loading5.gif"/></div>';
   }else{
      inElaborazione=false;
      //$('footer').innerHTML='Status: ready.';   
   }
}

function loadHTML(cosa,dove){
   
   // verifico che il sistema non sia occupato in altro...
   //attendo che l'elaborazione sia finita!
   if(inElaborazione)
      return;
   //#####################################
   
   //pongo lo stato del sistema in busy
   systemBusy(true);
   
   
   var pars = 'pag=' + cosa;

   if(dove==undefined){
      alert('non trovo -dove-');
   }
           
   //alert(pars);

   var myAjax = new Ajax.Updater( 
      dove, 
      'index.php', 
      { 
         method: 'get', 
         parameters: pars,
         onComplete: successo,
			onFailure: errore,
			onException: errore         
      }
   );   
}

function errore(dati,exception){
  alert('err. r.198 :'+exception)
}
	
function successo(originalRequest){

   if(originalRequest.responseText.substr(0,4)=='msg:' ){
      mostra_messaggio(originalRequest.responseText.substr(4));
      //$('msgWindow_foot').innerHTML='<input type="button" value="OK" onclick="close_msg();"/>';
      
   }else if(originalRequest.responseText=='session_timeout' ){
      mostra_messaggio('La sessione � terminata per inattivit�!<br>Si prega di rieseguire il login!');
      //$('msgWindow_foot').innerHTML='<input type="button" value="OK" onclick="window.location=\'index.php\'"/>';
      
   }
   systemBusy(false);
}

//mostra finestra messaggio ############################################
function mostra_messaggio(s){  
   alert(s)
}




/*
 * ############################################  CONFIGURATORE  ############################################
 */

var valoriConfiguratore=null;

var matData=[
	{kg:"1-15",cu:"20-120",val:"A",text:"12 - 4"},
	{kg:"2-35",cu:"20-250",val:"B",text:"15 - 6"},
	{kg:"10-70",cu:"20-350",val:"C",text:"19 - 8"},
	{kg:"10-110",cu:"40-500",val:"D",text:"22 - 10"},
	{kg:"20-110",cu:"100-550",val:"E",text:"28 - 10"},
	{kg:"20-280",cu:"100-550",val:"F",text:"28 - 14"}
]

function openConfig(){
	var myWnd= window.open ("index.php?pag=configuratore", "configuratore","location=1,status=1,scrollbars=1,width=1000,height=700");
	//myWnd.moveTo(0,0);
}


function hidePassi(){
	//var passi=new Array('login','passo1','passo2','passo3','passo4','passo5','passo6','passo7','passo8','passo9');
	var passi=new Array('login','passo1','passo2','passo3','passo4','passo5','passo6','passo7','passo8','passo9','passo10','passo11','passo12');	
	passi.each(function(e){
		if($(e)) $(e).hide();	
	})	
}	
				
function vaiPasso(passo){
	//console.log('passo:'+passo)
	hidePassi();
	
	if($(passo)) $(passo).show();
	
	if(passo!='login'){		
		$('config_sunto').show();
		
		
		
		new Ajax.Request(
			'index.php', {
				method: 'post',
				parameters: {c:'getPassiData',p:passo},
				onSuccess: function(transport) {
					//console.log(transport.responseText)
					
					var data = transport.responseJSON;
					valoriConfiguratore=data;
					
					//SUNTO #1
					$('sunto1').innerHTML=data.kg+' kg';
					$('val1').value=data.kg;
					
					//SUNTO #2
					$('sunto2').innerHTML=data.cu+' mm' ;	
					$('val2').value=data.cu;

					if (passo == 'passo2') {
						var out=controllaValori(data.kg,null);
						$('formMsg2').innerHTML='La corsa deve essere compresa tra '+out.cu_min+' e '+out.cu_max+' mm';
						$('formMsg2').style.color=null;
					}					
					
					//SUNTO #3
					$('sunto3').innerHTML=data.descr_mat
					$('val3').value=data.materiale;
					
					//SUNTO #4
					$('sunto4').innerHTML=data.descr_diametri

					//SUNTO #4B
					
					if(data.lta!='')
						$('sunto4B').innerHTML=data.lta+' mm'
										
					//costruisco combobox passo 4
					if(data.kg!='-' && data.cu!='-'){						
						var h='<select class="field2" name="val" id="val4">';
						h+='<OPTION VALUE="" ></OPTION>';
						//console.log(matData.length)
						matData.each(function(v){
							//console.log(v)
							var kg=v.kg.split('-');
							var cu=v.cu.split('-');
							data.kg=parseInt(data.kg);
							data.cu=parseInt(data.cu);
							if( ( data.kg >= parseInt(kg[0]) && data.kg <= parseInt(kg[1])) && ( data.cu >= parseInt(cu[0]) && data.cu <= parseInt(cu[1]))){
								h+='<OPTION VALUE="'+v.val+'" >'+v.text+'</OPTION>';
							}
						})
						h+='</select>';
						$('passo4_inputCell').innerHTML=h;
						
						if(data.diametri!='-'){
							$('val4').value=data.diametri;
						}
					}		
								

					//SUNTO #5
					$('sunto5').innerHTML=data.descr_fren;
					if(data.fr!='-'){
						if(data.fr=='') data.fr='A1';
						$('val5').value=data.fr;
					}
					
					
					$('sunto6').innerHTML=data.name_c;
					$('sunto7').innerHTML=data.name_s;
										
					//costruisco la lista attacchi passo6
					if(passo=='passo6'){
						//console.log('listTopClick(this,cor,'+data.uic_iniziali+')')
						listTopClick($('cor_'+data.uic_iniziali),'cor',data.uic_iniziali)
					}
					
					//costruisco la lista attacchi passo7
					if(passo=='passo7'){
						//console.log('listTopClick(this,ste,'+data.uis_iniziali+')')
						listTopClick($('ste_'+data.uis_iniziali),'ste',data.uis_iniziali)
					}
										
					$('listaAttacchi').hide();
					$('config_howto').show();
					
					if(passo=='passo8')
						getDisTec(2);
					
					//dimensione finestra
					var h=685;
					//alert(passo)
					switch(passo){
						case 'passo6':					
						case 'passo7':
						case 'passo8':
							h=1200;
							break;
						default:
							
					}
					$('config_div').style.height=h+'px';
				}
			});		
		

	}else{
		if(isIE)
			$('config_div').style.height='672px';
		else
			$('config_div').style.height='685px';
	} 
}

function altezzaConfig(h){
	if(isIE)
		$('config_div').style.height=(h-13)+'px';
	else
		$('config_div').style.height=h+'px';
}

function controllaValori(spinta,corsa){
	var out=null;
	
	if(corsa==null){
		matData.each(function(v){
			var kg=v.kg.split('-');
			var cu=v.cu.split('-');
			if( parseInt(spinta) >= parseInt(kg[0]) && parseInt(spinta) <= parseInt(kg[1]) ) {
				out={
					'cu_max':parseInt(cu[1]),
					'cu_min':parseInt(cu[0])
				};
			}
		})	
		return out;	
	}
	
	matData.each(function(v){
		var kg=v.kg.split('-');
		var cu=v.cu.split('-');
		if( parseInt(spinta) >= parseInt(kg[0]) && parseInt(spinta) <= parseInt(kg[1]) && parseInt(corsa) >= parseInt(cu[0]) && parseInt(corsa) <= parseInt(cu[1])) {
			out=v
		}
	})
		
	return out;
}

function doPassi(passo){
	
	//controllo la correttezza dei dati
	if(passo==2){
		var corsa=$('passo2Form')['val'].getValue();
		var out=controllaValori(valoriConfiguratore.kg,corsa);
		//console.log(out)
		if(out==null){
			$('formMsg2').style.color='#f00';
			$('val2').focus();
			$('val2').select();
			return;
		}
	}

	//aggiunto text del combo box 
	if (passo == 3) {
		$('desc3').value=$('val3').options[$('val3').selectedIndex].text;
	}
	if (passo == 4) {
		$('desc4').value=$('val4').options[$('val4').selectedIndex].text;
	}
	if (passo == 5) {
		$('desc5').value=$('val5').options[$('val5').selectedIndex].text;
	}	
		
	//alert( $('passo'+passo+'Form').serialize() );return;
	new Ajax.Request(
		'index.php', {
			method: 'post',
			parameters: $('passo'+passo+'Form').serialize(true),
			onSuccess: function(transport) {
				//alert(transport.responseText)
				//console.log('passo:'+passo)
				if(transport.responseText.substr(0,3)=='ok:'){
					
					switch(transport.responseText.substr(3)){
						case 'pdf':
							//alert('pdf')
							window.location = "/configuratore/passo7.php"
							break;
						default:
							vaiPasso('passo'+(passo+1));
					}
					
					//$('sunto'+passo).innerHTML=transport.responseText.substr(3)
				}else{
					
					//gestione dell'errore
					if(transport.responseText.substr(0,4)=='err1'){
						switch(passo){
							case 4:
							case 3:
								$('val'+passo).focus();
								$('val'+passo).selectedIndex=0;
								$('val'+passo).style.borderColor="#f00";
								break;
							case 8:
								if( transport.responseText.substr(6,1)=='C' ){
									$('val8').focus();
									$('val8').style.borderColor="#f00";									
								}
								if( transport.responseText.substr(6,1)=='T' ){
									$('val9').focus();
									$('val9').style.borderColor="#f00";									
								}
								break;								
							case 6:
								break;
							default:
								$('val'+passo).value='';
								$('val'+passo).focus();
								$('val'+passo).style.borderColor="#f00";
								//alert();
						}
						
						if(transport.responseText.length>5) alert(transport.responseText.substr(5))	
					}
				}
			}
		});
}

function doLogin(){
	//alert($('loginForm').getElements()[0]);return;
	new Ajax.Request(
		'index.php', {
			method: 'post',
			parameters: $('loginForm').serialize(true),
			onSuccess: function(transport) {
				if(transport.responseText=='si'){
					$('login').hide();
					$('passo1').show();
					$('config_sunto').show();
				}else
					$('login_log').innerHTML='Attenzione! Login errato!!';
				
			}
		});
}

function resend(){
	//alert($('loginForm').getElements()[0]);return;
	new Ajax.Request(
		'index.php', {
			method: 'post',
			parameters: $('resendForm').serialize(true),
			onSuccess: function(transport) {
				//alert(transport.responseText)
				if(transport.responseText=='si'){
					$('resendForm').login.clear();						
					$('resend_log').innerHTML='Abbiamo inviato nella vostra casella di posta elettronica la vostra passord';
					
				}else{
					$('resendForm').login.focus();
					$('resendForm').login.select();	
					$('resend_log').innerHTML='Errore! Utente non registrato.<br>La vostra mail non è stata trovata, dovete registrarvi di nuovo.';
				}
					
				
			}
		});
}

function checkMail(src) {
	var emailReg = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$";
	var regex = new RegExp(emailReg);
	return regex.test(src);
}

function registrazione(){
	
	//alert($('loginForm').getElements()[0]);return;
	var els=$('registrazioneForm').getElements();
	for(var i=0;i<els.length;i++) els[i].style.border='';
	$('registrazioneForm').privacy.parentNode.style.color='';

	var campi=new Array('nome','azienda','indirizzo','cap','citta','prov','naz','tel');
	var myF=$('registrazioneForm');
	for(var i=0;i<campi.length;i++){
		if(myF[campi[i]].value==''){
			myF[campi[i]].style.border='solid 1px #f00';
			return false;
		}
	}
	
		
	if($('registrazioneForm').email.value=='' || !checkMail($('registrazioneForm').email.value)) {
		$('registrazioneForm').email.style.border='solid 1px #f00';
		$('registrazioneForm').email.focus();
		return false;
	}
		
	if($('registrazioneForm').remail.value=='' || $('registrazioneForm').remail.value != $('registrazioneForm').email.value ) {
		$('registrazioneForm').remail.style.border='solid 1px #f00';
		$('registrazioneForm').remail.select();
		$('registrazioneForm').remail.focus();
		return false;
	}
	
	if( !$('registrazioneForm').privacy.checked ) {
		$('registrazioneForm').privacy.parentNode.style.color='#f00';
		$('registrazioneForm').privacy.focus();
		return false;
	}	



	$('regLoading').show();
	
	
	new Ajax.Request(
		'index.php', {
			method: 'post',
			parameters: $('registrazioneForm').serialize(true),
			onSuccess: function(transport) {
				//alert(transport.responseText)
				$('regLoading').hide();
				if(transport.responseText=='si'){
								
					$('reg_log').innerHTML='Utente registrato correttamente!<br>La password è stata inviata al vostro account posta.';
					$('registrazioneForm').reset();
				}else{
					switch(transport.responseText.substr(3)){
						case '1':
							$('registrazioneForm').captcha.focus();
							$('registrazioneForm').captcha.style.border='solid 1px #f00';
							$('reg_log').innerHTML='Codice di convalida non errato';
							break;
						case '2':
							$('registrazioneForm').email.focus();
							$('registrazioneForm').email.style.border='solid 1px #f00';
							$('reg_log').innerHTML='Dominio E-Mail non valido';
							break;	
						case '3':
							$('registrazioneForm').email.focus();
							$('registrazioneForm').email.style.border='solid 1px #f00';
							$('reg_log').innerHTML="Utente gi&#224; registrato!!!<br>Vi preghiamo di usare un'altra email o richiedere la password";
							break;	
						default:
							$('reg_log').innerHTML=	transport.responseText.substr(3);					
					}
				}
					
				//rigenero captcha
				var tt=new Date;
				$('captcha_img').innerHTML='<img src="configuratore/securimage/securimage_show.php?sid='+tt.getTime()+'">';
				$('captcha').clear();
			}
		});
}

function listTopClick(el, lato_a, tipo){
	//alert(el.parentNode)
	
	if(isIE){
		var els = el.parentNode.getElementsByTagName("IMG");
		//alert(els.length)
	}else
		var els = el.parentNode.childElements();
	
	
	for(var i=0;i<els.length;i++){
		if(els[i].nodeName=='IMG') els[i].className='';
	}

	el.className='sel';
	
	//carica lista attacchi
	new Ajax.Updater('listaAttacchi', 'index.php', {
		method: 'post',
		parameters: { c: 'listaAttacchi', iniziali: tipo, lato:lato_a, dim_lato: (lato_a=='cor'?valoriConfiguratore.dic:valoriConfiguratore.dis) },
		onSuccess: function(transport){
			//alert(transport.responseText)
			$('config_howto').hide();
			$('listaAttacchi').show();
		}
	});
}

function getDisTec(p){
	if(p==2){
		dove='disTecPlace2';
	}else
		dove='disTecPlace';
		
	new Ajax.Updater(dove, 'index.php', {
		method: 'post',
		parameters: { c: 'getDisTec'},
		onSuccess: function(transport){
			//console.log('getDisTec: ok')
		}
	});	
}

function setAttacco(el,lato,id_attacco,nome_attacco){
	if(isIE){
		var els = el.parentNode.getElementsByTagName("IMG");
	}else
		var els = el.parentNode.childElements();
	
	
	for(var i=0;i<els.length;i++){
		if(els[i].nodeName=='TD') els[i].className='';
	}
		
/*
	var els = el.parentNode.childElements();
	els.each(function(e){
		if(e.nodeName=='TD') e.className='';
	})
*/
	el.className='sel';
	
	//nome in sunto
	if(lato=='cor') $('sunto6').innerHTML=nome_attacco;
	if(lato=='ste') $('sunto7').innerHTML=nome_attacco;
	
	//salvo l'attacco scelto
	new Ajax.Request(
		'index.php', {
			method: 'post',
			parameters: { c: 'setAttacco', lato:lato, id:id_attacco, nome:nome_attacco},
			onSuccess: function(transport) {
				getDisTec();
			}
		});
}



				