// JavaScript Document
function initPreventivi()
{
	$('#auto input[type=radio]:checked').each(function() {
		$(this).attr('checked',false);
	});

	$('#moto input[type=radio]:checked').each(function() {
		$(this).attr('checked',false);
	});

	$('#auto input[type=radio]').click(function() {
		$('#moto .icon').attr('src','/seisicuro/pres/img/motoicon_off.png');
		$('#moto .button').attr('src','/seisicuro/pres/img//motobutton_off.png');

		$('#auto .icon').attr('src','/seisicuro/pres/img/autoicon_on.png');
		$('#auto .button').attr('src','/seisicuro/pres/img/autobutton_on.png');
		
		$('.c1').removeClass('nohl_1').addClass('nohl_2');
		$('.c2').removeClass('nohl').addClass('hl');
		$('.c1 input').removeAttr("disabled");
		$('.c2 input').removeAttr("disabled");

		checkPreventivi();
	});

	$('#moto input[type=radio]').click(function() {
		$('#auto .icon').attr('src','/seisicuro/pres/img//autoicon_off.png');
		$('#auto .button').attr('src','/seisicuro/pres/img//autobutton_off.png');

		$('#moto .icon').attr('src','/seisicuro/pres/img//motoicon_on.png');
		$('#moto .button').attr('src','/seisicuro/pres/img//motobutton_on.png');
		
		$('.c1').removeClass('nohl_1').addClass('nohl_2');
		$('.c2').removeClass('nohl').addClass('hl');
		$('.c1 input').removeAttr("disabled");
		$('.c2 input').removeAttr("disabled");
		
		checkPreventivi();
	});
}

function checkPreventivi()
{
	var d = new Date();
	var mm = $('#mm').val();
	var aaaa = $('#aaaa').val();

	//if ((isNaN(mm) || mm < 1 || mm > 12) || (isNaN(aaaa) || aaaa < 1900 || aaaa > d.getFullYear()) || (aaaa == d.getFullYear() && mm > d.getMonth()+1))
	if (isNaN(aaaa) || aaaa < 1900 || aaaa > d.getFullYear())
	{
		if ($('.c3 input').attr("disabled") != "disabled")
		{
			$('.c3').removeClass('hl').addClass('nohl');
			$('.c3 input').attr("disabled",true);
		}
	}
	else
	{
		$('.c3').removeClass('nohl').addClass('hl');
		$('.c3 input').removeAttr("disabled");
	}
}

function sendPreventivi()
{
	var d = new Date();
	var mm = $('#mm').val();
	var aaaa = $('#aaaa').val();

	//if ((isNaN(mm) || mm < 1 || mm > 12) || (isNaN(aaaa) || aaaa < 1900 || aaaa > d.getFullYear()) || (aaaa == d.getFullYear() && mm > d.getMonth()+1))
	if (isNaN(aaaa) || aaaa < 1900 || aaaa > d.getFullYear())
	{
		alert("L'anno d\'acquisto è sbagliato");
		return false;
	}
	else
	{

               

                var modulo = document.getElementById("frmPreventivi");
             
                var context ="";
               modulo.action=context + "/VehicleServlet";

               
		if (document.getElementById("tipo_prod1").checked){
			 modulo.action= context + "/VehicleServlet";

		}else if (document.getElementById("tipo_prod2").checked){
			modulo.action= context + "/BikeVehicleServlet";

		}else{
			modulo.action= context + "/CCarVehicleServlet";

		}

                $('#frmPreventivi').submit();
		return false;
	}
}

function cambia(){
    
    var newlink = document.getElementById('linkauto');
    newlink.setAttribute('href', '/preventivi/auto_az.jsp');







}
function cambia2(){

    var newlink = document.getElementById('linkauto');
    newlink.setAttribute('href', '/preventivi/auto.jsp');







}


function cambiaClasse() {
     var newlink = document.getElementById('center');
    newlink.setAttribute('class', 'stampa');


}