// JavaScript Document
function aggiornaPrezzo(prezzoCorrente,prezzo,id,totale)
{
   
  
  if($("#"+id+":checked").val()=='1')
  {
    
    prezzoDef=parseFloat(prezzoCorrente)+parseFloat(prezzo);
    $("#totale").html('<strong>'+totale+'</strong><br><strong>&euro;'+number_format(prezzoDef,2,'.')+'</strong>');
    $("#prezzo_corrente").val(prezzoDef);
  }
  else
  {
    
    prezzoDef=parseFloat(prezzoCorrente)-parseFloat(prezzo);
    $("#totale").html('<strong>'+totale+'</strong><br><strong>&euro;'+number_format(prezzoDef,2,'.')+'</strong>');
    $("#prezzo_corrente").val(prezzoDef);
  }
  
}

function prenota(valore)
{
  $('#ptype').val(valore);
  if(confirm("E\' consigliabile, prima di effettuare il pagamento, \rverificare la disponibilità dell\'auto con il nostro staff."))
  {
    $('#invio_dati').submit();
  }
}

function sendContatti()
{
   //loading immagine
   $('#contattiResults').html('<center><img src="images/loader.gif"></center>'); 
   pars=$("#form_mail").serialize();
   $.ajax({
   type: "POST",
   url: "sendContatti.php",
   cache: false,
   data: pars,
   
   success: function(html){
     
    $('#contattiResults').html(html);
       
   }

 });  
}

function number_format( number, decimals, dec_point, thousands_sep ) {
 
    var n = number, c = isNaN(decimals = Math.abs(decimals)) ? 2 : decimals;
    var d = dec_point == undefined ? "." : dec_point;
    var t = thousands_sep == undefined ? "," : thousands_sep, s = n < 0 ? "-" : "";
    var i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0;
    
    return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
}
function clearForm(ele) {

    $(ele).find(':input').each(function() {
        switch(this.type) {
            case 'password':
            case 'select-multiple':
            case 'select-one':
            case 'text':
            case 'textarea':
                $(this).val('');
                break;
            case 'checkbox':
            case 'radio':
                this.checked = false;
        }
    });

}