// CODICE PER GESTIONE IMMAGINI DETTAGLIO AUTO 
$(function() {	
	$('.dettaglioFoto').each(function(i,item){
		$(item).hover(
      	function () {
        	$(this).addClass( 'immagineAttiva' );
      	}, 
      	function () {
        	$(this).removeClass( 'immagineAttiva' ); 
      	}
    	);
		$(item).click(function () {
			$(".st_dt_foto > img").attr( 'src', this );
			removeClass();
			$(item).addClass( 'bordoImmagine' );
			return false;
		}); 
	});
});

function removeClass()
{
	$('.dettaglioFoto').each(function(i,item){	
		$(item).removeClass( 'bordoImmagine' ); 
	});
}

var imgCaricamento = " <img src=\"/img/loading.gif\" alt=\"caricamento\" />";
function caricaDati( p )
{
	extra = '';							
    $(".lCaricamento").html( imgCaricamento );
    $.ajax({
        type: "POST",
        url: "/public/caricaElementi.php",
        data: "w="+c+"&q="+q+"&p="+p+extra,
        success: function( ris )
        {
        	ris = ris.split( '#####' );
			$(".paginazione").html( ris[0] );        	
			$("#"+d).html( ris[1] );
            $(".lCaricamento").empty();
        }
    });
    return false;
}

function richiediInformazioni( id )
{
	$(".lCaricamento").html( imgCaricamento );
	$("#boxStrumenti").load("/public/richiediInformazioni.php", {step: 1, ida: id}, function(){

		$("#richiestaInformazioni").validate({		
			submitHandler: function(form) {
				ris = controllaCaptcha();
				if( ris == 1 )
				{
					$("#inviaModulo").attr( 'disabled', 'true' );				
					$(form).ajaxSubmit({
						target: "#boxStrumenti"
					});
				} else
				{
					var validator = $(".cmxform").validate();
					validator.showErrors({"captcha": "Il codice di controllo non è corretto."});				
				}				
				
				

			},
			onkeyup: false,
			onblur: false
		});		
		
		
		$(".lCaricamento").empty();
	});
}

function stampaAuto( p )
{
	var w = 780;
	var h = 780;
	var l = Math.floor((screen.width-w)/2);
	var t = Math.floor((screen.height-h)/2);
	window.open( p, "Stampa veicolo", "width=" + w + ",height=" + h + ",top=" + t + ",left=" + l + ',location=no,status=no,menubar=no,scrollbars=no,resizable=no' );
	return false;
}

function generaCaptcha()
{
	$.getJSON("/public/json.php", { w: "captcha" }, function(data){
		token = data.t;
		$("#imgCaptcha").attr( 'src', '/img/captcha.php?t='+token );
		$("#tCaptcha").val( token );		
	});
}

function controllaCaptcha()
{
	var ris;
	captcha = $("#captcha").val();
	$.ajax({
		type: "GET",
		async: false,
		dataType: "json",
		url: "/public/controllaCaptcha.php",
		data: "token="+token+"&captcha="+captcha,
		success: function( data ){
			ris = data.ris;
		}
	});
	return ris;
}