//Menu
function mainmenu(){
$(" #nav ul ").css({display: "none"}); // Opera Fix
$(" #nav li").hover(function(){
		$(this).find('ul:first').css({visibility: "visible",display: "none"}).show(200);
		},function(){
		$(this).find('ul:first').css({visibility: "hidden"});
		});
}

$(document).ready(function(){					
	mainmenu();
	v_check();
});

// Tiny Slider
var TINY={};

function T$(i){return document.getElementById(i)}
function T$$(e,p){return p.getElementsByTagName(e)}

TINY.slider=function(){
	first=false;
	function slide(n,p){this.n=n; this.init(p)}
	slide.prototype.init=function(p){
		var s=T$(p.id), u=this.u=T$$('ul',s)[0], c=T$$('li',u), l=c.length, i=this.l=this.c=0;
		if(p.navid&&p.activeclass){this.g=T$$('li',T$(p.navid)); this.s=p.activeclass}
		this.a=p.auto||0; this.p=p.resume||0; this.v=p.vertical||0; s.style.overflow='hidden';
		for(i;i<l;i++){if(c[i].parentNode==u){this.l++}}
		if(this.v){;
			u.style.top=0; this.h=p.height||c[0].offsetHeight; u.style.height=(this.l*this.h)+'px'
		}else{
			u.style.left=0; this.w=p.width||c[0].offsetWidth; u.style.width=(this.l*this.w)+'px'
		}
		this.pos(p.position||0,this.a?1:0)
	},
	slide.prototype.auto=function(){
		this.u.ai=setInterval(new Function(this.n+'.move(1,1)'),this.a*1000)
	},
	slide.prototype.move=function(d,a){
		var n=this.c+d, i=d==1?n==this.l?0:n:n<0?this.l-1:n; this.pos(i,a)
	},
	slide.prototype.pos=function(p,a){
		clearInterval(this.u.ai); clearInterval(this.u.si);
		var o=this.v?parseInt(this.u.style.top):parseInt(this.u.style.left),
		t=this.v?p*this.h:p*this.w, d=t>Math.abs(o)?1:-1; t=t*-1; this.c=p;
		if(this.g){for(var i=0;i<this.l;i++){this.g[i].className=i==p?this.s:''}}
		this.u.si=setInterval(new Function(this.n+'.slide('+t+','+d+','+a+')'),20)
	},
	slide.prototype.slide=function(t,d,a){
		var o=this.v?parseInt(this.u.style.top):parseInt(this.u.style.left);
		if(o==t){
			first=true; // Modifica
			clearInterval(this.u.si); if(a||(this.a&&this.p)){this.auto()}
		}else{
			// Modifica per l'aggiornamento contestuale del div
			if(document.getElementById('divScroll0') && first){
			  for(var i = 0; i < 5; i++){
			    if(i != this.c) document.getElementById('divScroll'+i).style.display = 'none';
			  }
			  document.getElementById('divScroll'+this.c).style.display = 'block';
				first = false;
			}
			//--------------------------------------------------
			var v=o-Math.ceil(Math.abs(t-o)*.10)*d+'px';
			this.v?this.u.style.top=v:this.u.style.left=v
		}
	};
	return{slide:slide}
}();

function showSideButtons(mouse){
  if(mouse == 'over'){
	  document.getElementById('sbl').style.display = document.getElementById('sbr').style.display = 'block';		
	}else{
	  document.getElementById('sbl').style.display = document.getElementById('sbr').style.display = 'none';		
	}
}


// process.js
var VImg = [];
var updateHtm = false;
var FLEET_BASE = 'V-Flotte BASE';
var FLEET_ADVANCED = 'V-Flotte AVANZATO';
var FLEET_ADVANCED_NAV = 'V-Flotte AVANZATO <i>Nav</i>';
var FLEET_ADVANCED_CAN = 'V-Flotte AVANZATO <i>CAN</i>';
var LOCATEME = 'Localizzami';
var LOCATEME_WEB = 'Localizzami WEB';
var PLANNING = 'V-Pianificazione';
var SECURITY = 'V-Sicurezza';
var TARSP_SPED = 'Trasporti e Spedizioni';
var MANUT_ASS = 'Manutenzione e Assistenza';
var VENDIT_COMM = 'Venditori e Commerciali';
var NELEGIO = 'Noleggio veicoli';
var RACC_RIFIUTI = 'Raccolta rifiuti';
var MEZZI_SOCC = 'Mezzi di soccorso';
var VIGILANZA = 'Vigilanza e Investigazioni';
var SERV_STAG = 'Servizi stagionali';
var MOV_TERRA = 'Movimento terra';
var slideshow = null;

function _$(id){
  return document.getElementById(id);
}

function preloadImg(ids){
  //VImg[0] = new Image();
  //VImg[0].src = 'images/puzzle_a1_bg.png';
}

function getSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return [myWidth, myHeight]
}

function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}

function showFocus(obj){
  if(!document.getElementById) return;
  obj.style.border = "1px solid #FFCC66";
}

function showBlur(obj){
  if(!document.getElementById) return;
  obj.style.border = "1px solid #6699CC";
} 

function addLayer(id,cls,vis,htm){
  var d = document.createElement("DIV");
  d.setAttribute("id",id);
  if(cls){
    d.setAttribute("class",cls );
    d.setAttribute("className",cls);
  }
  d.innerHTML = htm;
  if(vis) d.style.display = vis;
  document.getElementsByTagName('body')[0].appendChild(d);     
}

function showPopWin(par,prod,path){
  var type = par || 'order';
	var width = document.getElementById('container').parentNode.offsetWidth;
  //var width = document.getElementById('page_bg').offsetWidth;
  var height = document.getElementById('container').offsetHeight+16;
  var size = getSize();
  var scroll = getScrollXY();
  var pageY = size[1]; 
  if(pageY > height) height = pageY;
  var scrollY = scroll[1];
  var popDiv = document.getElementById('PopWin');
	var p = v_getProduct(prod);
  var obj = v_getObj(par,p,path);
  popDiv.innerHTML = v_getOrderForm(v_getProduct(prod), obj.htm, obj.label, obj.closeIco);
  document.getElementById('anc_captcha').onclick = function(){v_captcha('img_captcha'); return false;};
  document.getElementById('anc_send').onclick = function(){v_submit(obj.type,prod); return false;};
  popDiv.style.width = 'auto';
  popDiv.style.height = 'auto';
  popDiv.style.top = parseInt((pageY-popDiv.offsetHeight)/2)+scrollY+'px';
  popDiv.style.left = parseInt((width-popDiv.offsetWidth)/2)+'px';
  addShadow('Shadow',width,height);
  document.getElementById('Shadow').style.visibility = 'visible';
  popDiv.style.visibility = 'visible';
}

function hidePopWin(){
  document.getElementById('Shadow').style.visibility = 'hidden';
  document.getElementById('Shadow').style.width = '1px';
  document.getElementById('PopWin').style.visibility = 'hidden';  
}

function addShadow(id,w,h){
  var obj = document.getElementById(id)
  obj.style.top = 0;
  obj.style.left = 0; 
  obj.style.width = w+'px';
  obj.style.height = h+'px';
  obj.style.opacity = .50;
  obj.style.filter = 'alpha(opacity=50)';
}

function v_getProduct(p){
  var prd = null;
  switch(p){
    case 'flotte_base': 
      prd = FLEET_BASE;
      break;
    case 'flotte_avanzato': 
      prd = FLEET_ADVANCED;
      break;
    case 'flotte_avanzato_nav': 
      prd = FLEET_ADVANCED_NAV;
      break;
    case 'flotte_avanzato_can': 
      prd = FLEET_ADVANCED_CAN;
      break;			
    case 'localizzami': 
      prd = LOCATEME; 
      break;
    case 'localizzami_web': 
      prd = LOCATEME_WEB; 
      break;
    case 'accessori': 
      prd = FLEET_ADVANCED; 
      break;  
    case 'planning': 
      prd = PLANNING; 
      break;
    case 'security': 
      prd = SECURITY; 
      break;	
    case 'trasporti_spedizioni': 
      prd = TARSP_SPED;
      break;
    case 'manutenzione_assistenza': 
      prd = MANUT_ASS;
      break;
    case 'venditori_rete_commericiale': 
      prd = VENDIT_COMM; 
      break;
    case 'noleggio_veicoli': 
      prd = NELEGIO; 
      break;
    case 'raccolta_rifiuti': 
      prd = RACC_RIFIUTI; 
      break;  
    case 'mezzi_soccorso': 
      prd = MEZZI_SOCC; 
      break;
    case 'vigilanza_investigazioni': 
      prd = VIGILANZA; 
      break;
    case 'servizi_stagionali': 
      prd = SERV_STAG; 
      break;	
    case 'movimento_terra': 
      prd = MOV_TERRA; 
      break;				
  }
  return prd;
}

function v_check(){
	addLayer('PopWin',null,false,'');
  addLayer('Shadow','shadow',false,'');	
	if(_$('scroller')){
    slideshow = new TINY.slider.slide('slideshow',{
      id:'scroller',
      auto:0,
      resume:false,
      vertical:false,
      navid:'buttons',
      activeclass:'current',
      position:0
    });	
  }
  if(document.form) document.form.btn.onclick = v_process;
  else if(_$('anc_info')){
   updateHtm = true;
   _$('anc_info').onclick = function(){v_hide('info','call','demo'); v_show('info'); return false;};
   _$('anc_call').onclick = function(){v_hide('info','call','demo'); v_show('call'); return false;};
   _$('anc_demo').onclick = function(){v_hide('info','call','demo'); v_show('demo'); return false;};
	 v_show('info');
  }
  if( _$('slider')){
		var s = T$('slider'), u = T$$('ul',s)[0], c = T$$('li',u), l = c.length;
		if(l > 1){
	    v_setOpacity('strip',60);
	    slideshow = new TINY.slider.slide('slideshow',{
        id:'slider',
        auto:5,
        resume:true,
        vertical:false,
        navid:'pagination',
        activeclass:'current',
        position:0
      });
      //preloadImg();
		}
  }
  setTimeout('v_setSocials()',1000);
}

function v_setSocials(){
  //PlusOne
  window.___gcfg = {lang: 'it'};
  (function() {
    var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
    po.src = 'https://apis.google.com/js/plusone.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
  })();
   //FaceBook
  (function(d, s, id) {
    var js, fjs = d.getElementsByTagName(s)[0];
    if (d.getElementById(id)) return;
    js = d.createElement(s); js.id = id;
    js.src = "//connect.facebook.net/it_IT/all.js#xfbml=1";
    fjs.parentNode.insertBefore(js, fjs);
  }(document, 'script', 'facebook-jssdk'));
	 //Twitter
	 !function(d,s,id){
		 var js,fjs=d.getElementsByTagName(s)[0];
		 if(!d.getElementById(id)){
			 js=d.createElement(s);
			 js.id=id;js.src="//platform.twitter.com/widgets.js";
			 fjs.parentNode.insertBefore(js,fjs);
		 }
	 }(document,"script","twitter-wjs");
}

function v_setOpacity(objId,x){
  _$(objId).style.opacity = parseFloat('.'+x);
  _$(objId).style.filter = 'alpha(opacity='+x+')';
}

function v_captcha(id){
  var r = Math.floor(Math.random()*1000);
  _$(id).src = 'http://www.illocalizzatore.it/coge/captcha.jpg?rnd='+r;
}

function v_hide(){
  if(arguments){
    for(var i = 0; i < arguments.length; i++){
      if(updateHtm) _$('div_'+arguments[i]).innerHTML = '';
      _$('div_'+arguments[i]).style.display = 'none';
			_$('anc_'+arguments[i]).className = '';
      //_$('btn_'+arguments[i]).src = VImg[arguments[i]].src;
    }
  }
}

function v_hide1(){
  if(arguments){
    for(var i = 0; i < arguments.length; i++){
      if(updateHtm) _$('div_'+arguments[i]).innerHTML = '';
      _$('div_'+arguments[i]).style.display = 'none';
      //_$('btn_'+arguments[i]).src = VImg['details'].src;
    }
  }
}

function v_show(id){
  if(id){
      if(updateHtm){
        var obj = v_getObj(id,'','');
        _$('div_'+id).innerHTML = obj.htm;
        _$('anc_captcha').onclick = function(){v_captcha('img_captcha'); return false;};
        _$('anc_send').onclick = function(){v_submit(obj.type,''); return false;};
      }
      _$('div_'+id).style.display = 'block';
			_$('anc_'+id).className = 'current';
      //_$('btn_'+arguments[i]).src = VImg[id+'_on'].src;
  }  
}

function v_show1(){
  if(arguments){
    for(var i = 0; i < arguments.length; i++){
      _$('div_'+arguments[i]).style.display = 'block';
     // _$('btn_'+arguments[i]).src = VImg['details_on'].src;
    }
  }  
}

function v_getObj(arg,prod,path){
  var obj = {type: null, label: '', htm: '<table border="0" cellspacing="5" cellpadding="0" >', closeIco: path+'images/closebox.png'};
  obj.htm +=
    '<tr>'+
      '<th align="right" scope="row">Ragione sociale</th>'+
      '<td><input id="name" name="name" style="width: 200px; padding-left: 3px;" /></td>'+
    '</tr>'+
    '<tr>'+
      '<th align="right" scope="row">Persona di riferimento</th>'+
      '<td><input id="reference" name="reference" style="width: 200px; padding-left: 3px;" /></td>'+
    '</tr>'+	
    '<tr>'+
      '<th align="right" scope="row">e-mail</th>'+
      '<td><input id="mail" name="mail" style="width: 280px; padding-left: 3px;" /></td>'+
    '</tr>'+	
    '<tr>'+
      '<th align="right" scope="row">Telefono</th>'+
      '<td><input id="phone" name="phone" style="width: 120px; padding-left: 3px;" /></td>'+
    '</tr>';    
  switch(arg){
    case 'info':
      obj.type = 1;
			obj.label = 'RICHIESTA INFORMAZIONI';
      obj.htm += 
          '<tr>'+
            '<th align="right" valign="top" style="padding-top: 3px" scope="row">Messaggio</th>'+
            '<td><textarea id="message" style="width: 320px; height: 100px; padding-left: 3px; padding-right:3px;"></textarea></td>'+
          '</tr>';
      break;
    case 'call': 
      obj.type = 2;
			obj.label = 'RICHIAMAMI';
      obj.htm += 
          '<tr>'+
            '<th align="right" scope="row">Appuntamento</th>'+
            '<td><input id="date" name="date" style="width: 120px; text-align:center" /> (gg/mm/aaaa hh.mm)</td>'+
          '</tr>'+
          '<tr>'+
            '<th align="right" valign="top" style="padding-top: 3px" scope="row">Messaggio</th>'+
            '<td><textarea id="message" style="width: 320px; height: 100px; padding-left: 3px; padding-right:3px;"></textarea></td>'+
          '</tr>';
      break;
    case 'demo':
      obj.type = 3;
			obj.label = 'PRENOTAZIONE DEMO';
      obj.htm += 
          '<tr>'+
            '<th align="right" scope="row">Appuntamento</th>'+
            '<td><input id="date" name="date" style="width: 120px; text-align:center" /> (gg/mm/aaaa hh.mm)</td>'+
          '</tr>'+
          '<tr>'+
            '<th align="right" valign="top" style="padding-top: 3px" scope="row">Messaggio</th>'+
            '<td><textarea id="message" style="width: 320px; height: 100px; padding-left: 3px; padding-right:3px;"></textarea></td>'+
          '</tr>';
      break;
    case 'order':
		  obj.type = 4;
			obj.label = 'ORDINE';
			obj.htm += '<tr>';
		  if(prod == PLANNING){
        obj.htm += 
				  '<th align="right" valign="top" style="padding-top: 3px" scope="row">Numero tecnici/autisti</th>'+
          '<td><input id="deviceNum" name="deviceNum" style="width: 40px; text-align:right; padding-right: 3px;" value="1" />';			
			}else{
        obj.htm += 
            '<th align="right" valign="top" style="padding-top: 3px" scope="row">Numero apparati</th>'+
            '<td><input id="deviceNum" name="deviceNum" style="width: 40px; text-align:right; padding-right: 3px;" value="1" />';
			}
			obj.htm += '<span style="margin-left:10px;"><b>Internazionale</b></span><input id="chk_roaming" name="chk_roaming" type="checkbox" value="" /></td></tr>';
			obj.htm += v_getOrderProduct(prod);
      break;
  }
  obj.htm +=
    '<tr>'+
      '<th align="right" valign="top" style="padding-top: 3px" scope="row">Inserire i caratteri nell\'immagine</th>'+
        '<td width="320">'+
          '<div><input id="captcha" name="capthcha" style="width: 80px; padding-left: 3px;" /></div>'+
          '<div style="margin-top:5px;"><a id="anc_captcha" href="#">Se non vedi i caratteri aggiorna l\'immagine</a></div>'+
          '<img id="img_captcha" src="'+path+'coge/captcha.jpg?rnd='+Math.floor(Math.random()*1000)+'" border="0" style="margin-top:5px;" alt="captcha"/>'+
        '</td>'+
      '</tr>'+
      '<tr>'+
        '<th> </th>'+
        '<td height="40" align="center" valign="bottom">'+
					'<div class="redButton" style="margin: 0 100px 15px;">'+
            '<a class="wLink" id="anc_send" href="#"><b>Invia &raquo;</b></a>'+
          '</div>'+
          '<div id="div_response" style="padding-top: 4px; margin-left: 140px; font-weight:bold;"></div>'+
        '</td>'+
      '</tr>'+
    '</table>';
  return obj;
}

function v_getOrderProduct(prod){
  var htm = '';
	var nav = false;
	var can = false;
	var acc = false;
  switch(prod){
    case FLEET_ADVANCED_NAV:
		  nav = true;
			acc = true;
			break;
    case FLEET_ADVANCED_CAN:
		  can = true;
			acc = true;
			break;			
	  case FLEET_ADVANCED:
      acc = true;
      break;
  }
	if(acc) htm +=
    '<tr>'+
      '<th align="right" style="padding-top: 3px" scope="row">Accessori</th>'+
      '<td></td>'+
    '</tr>'+
    '<tr>'+
      '<td colspan="2">'+v_getAccessories(nav,can)+'</td>'+
    '</tr>';
	else htm += '';
  return htm;
}

function v_getAccessories(nav,can){
  var htm =
    '<table border="0" cellspacing="5" cellpadding="0" style="margin-left: 135px; background-color:#eeeeee">'+
		(nav ? '' : 
      '<tr>'+
        '<th align="right" >Navigatore</th>'+
        '<td><input id="chk_nav" name="chk_nav" type="checkbox" value="" /></td>'+
      '</tr>')+
      '<tr>'+
        '<th align="right" >Blocco avviamento</th>'+
        '<td><input id="chk_lock" name="chk_lock" type="checkbox" value="" /></td>'+
      '</tr>'+
      '<tr>'+
        '<th align="right" >Pulsante SOS</th>'+
        '<td><input id="chk_sos" name="chk_sos" type="checkbox" value="" /></td>'+
      '</tr>'+
			'<tr>'+
        '<th align="right" >Gestione Avvisi e Allarmi</th>'+
        '<td><input id="chk_warn" name="chk_warn" type="checkbox" value="" /></td>'+
      '</tr>'+
			'<tr>'+
			(can ? '' :
        '<th align="right" >CAN BUS</th>'+
        '<td><input id="chk_can" name="chk_can" type="checkbox" value="" /></td>'+
      '</tr>')+			
      '<tr>'+
        '<th align="right" >Carburante</th>'+
        '<td><input id="chk_fuel" name="chk_fuel" type="checkbox" value="" /></td>'+
      '</tr>'+
      '<tr>'+
        '<th align="right" >Pianificazione</th>'+
        '<td><input id="chk_planning" name="chk_planning" type="checkbox" value="" /></td>'+
      '</tr>'+
      '<tr>'+
        '<th align="right" >Attivit&agrave;</th>'+
        '<td><input id="chk_activity" name="chk_activity" type="checkbox" value="" /></td>'+
      '</tr>'+
      '<tr>'+
        '<th align="right" >Contatti</th>'+
        '<td><input id="chk_contacts" name="chk_contacts" type="checkbox" value="" /></td>'+
      '</tr>'+
      '<tr>'+
        '<th align="right" >Filtro Privacy</th>'+
        '<td><input id="chk_privacy" name="chk_privacy" type="checkbox" value="" /></td>'+
      '</tr>'+
      '<tr>'+
        '<th align="right" >Sicurezza</th>'+
        '<td><input id="chk_security" name="chk_security" type="checkbox" value="" /></td>'+
      '</tr>'+	  
      '<tr>'+
        '<th align="right" valign="top" style="padding-top: 3px" scope="row">Riconoscimento autista</th>'+
        '<td><input id="chk_driver" name="chk_driver" style="width: 40px; text-align:right; padding-right: 3px;" value="0" /></td>'+
      '</tr>'+
   '</table>';
  return htm;
}

function v_getOrderForm(prd,txt,lb,ico){
  var htm =
    '<div style="background-color:#ffffff; padding:15px;">'+
      '<div style="position: absolute; right: -11px; top: -10px;">'+
        '<a href="#" id="anc_close" onclick="hidePopWin();return false;"><img border="0" src="'+ico+'" alt="closebox"/></a>'+
      '</div>'+
      '<h3>'+lb+': '+prd+(prd == PLANNING ? ' (software indipendente, senza localizzatori GPS)' : '')+'</h3>'+
			txt+
    '</div>';
  return htm;
}

function v_checkForm(){
  return true;
}

function v_getOrderInfo(prod){
	var nav = false;
	var can = false;
	var acc = false;
	var roam = false;
  switch(prod){
    case FLEET_ADVANCED_CAN:
		  acc = true;
		  roam = true;
		  can = true;
		  break;
    case FLEET_ADVANCED_NAV:
		  acc = true;
		  roam = true;
		  nav = true;
		  break;
    case FLEET_ADVANCED:
		  acc = true;
		  roam = true;
		  break;
	  case FLEET_BASE: 
		  roam = true;
		  break;
   }
	 var txt = 
	   'Prodotto: '+prod+'; Numero apparati: '+_$('deviceNum').value+
		 '; Accessori: '+
		 (nav ? '' : (_$('chk_nav').checked ? 'Navigatore; ' : ''))+
		 (can ? '' : (_$('chk_can').checked ? 'CAN BUS; ' : ''))+
		 (_$('chk_lock').checked ? 'Blocco avviamento; ' : '')+
		 (_$('chk_sos').checked ? 'Pulsante SOS; ' : '')+
		 (_$('chk_warn').checked ? 'Avvisi; ' : '')+
	   (_$('chk_fuel').checked ? 'Fuel; ' : '')+
     (_$('chk_planning').checked ? 'Pianificazione; ' : '')+
     (_$('chk_activity').checked ? 'Attivitą; ' : '')+
     (_$('chk_contacts').checked ? 'Contatti; ' : '')+
     (_$('chk_privacy').checked ? 'Filtro privacy; ' : '')+
		 (_$('chk_security').checked ? 'Sicurezza; ' : '')+
     (_$('chk_driver').value > 0 ? 'Riconoscimento autista '+_$('chk_driver').value : '');		 
		 (roam ? (_$('chk_roaming').checked ? '; +Roaming; ' : '') : '');
   return txt;
}
function v_submit(type,prod){
  if(v_checkForm()){
		var p = v_getProduct(prod);
    var info = type == 4 ? v_getOrderInfo(p) : (prod ? 'Prodotto: '+prod+'; ' : '')+_$('message').value;
    var url = '../../coge/addContact?'+
      'name='+_$('name').value+' - '+_$('reference').value+
      '&email='+_$('mail').value+
      '&phoneNumber='+_$('phone').value+
      '&date='+(_$('date') ? _$('date').value : '')+
      '&note='+info+
      '&captchaText='+_$('captcha').value+
      '&typeID='+type+
      '&sendMail=true'+
      '&rnd='+Math.floor(Math.random()*1000);
    _$('div_response').innerHTML = 'Invio in corso...';
    ajax.get(url);
  }
}

function v_process(){
  var c1 = 0.05;
  var c2 = 0.12;
  var n = document.form.num.value;
  var c = document.form.cost.value;
  var k = document.form.km.value;
  if(n != '' && c != '' && k != ''){
    c = parseFloat(c.replace(/,/, '.'));
    document.form.res0.value = (n*c*k).toFixed(2);
    document.form.res1.value = (n*c*k*c1).toFixed(2);
    document.form.res2.value = (n*c*k*c2).toFixed(2);
  }
}

var ajax = {
  get: function(url){
    try{    
      var xmlObj = null;
      if(window.XMLHttpRequest) xmlObj = new XMLHttpRequest();
      else if(window.ActiveXObject) xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
      else return;
      xmlObj.onreadystatechange = function(){if(xmlObj.readyState == 4) ajax.parse(xmlObj);};
      xmlObj.open ('GET', url, true);
      xmlObj.send ('');
    }catch(e){
      alert(e.message);
    }       
  },

  parse: function(xmlObj){
    try{
      if(xmlObj.responseXML){
        var element = xmlObj.responseXML.getElementsByTagName('element')[0];
        if(element.getElementsByTagName('error').length > 0){
          var code = element.getElementsByTagName('error')[0].getAttribute('code');
          if(code == '1') _$('div_response').innerHTML = 'Caratteri dell\'immagine non corretti!';          
          else _$('div_response').innerHTML = 'Invio fallito! Controlla i dati insetiti.';
        }else{
          _$('div_response').innerHTML = 'Invio completato! Grazie.';
          v_captcha('img_captcha');
        }
      }else{
        alert(xmlObj.responseText);
      }
    }catch(e){
      alert(e.message);
    }
  }
}
