
//------ LOGIC FOR STATES ----------------------------------------------------

//AA.States = new Hash();
//------ HOME ----------------------------------------------------------------

//Home State stuff
(function($){

	var self = {};
	$.extend( self, {
		form    : undefined,
		unknown : undefined,
		next    : undefined,
		plateNumber: undefined,

		init : function() {

			self.form = $('#processForm');
			self.unknown = $('#licenseunknownHome');
			self.next=$('#next');
			self.plateNumber=$("#license");

			if ( !self.form.length || !self.plateNumber.length ) return;

			// Remove all the action related to the objects
			self.unknown.unbind();

/*
 * 			if( !$.browser.msie )
				self.plateNumber.focus();
*/
		}
	});
	$.extend( AA.States , {home: self});


})(jQuery);


//--- QQREQUIRED -------------------------------------------------------------

(function($){

	var self = {};
	$.extend( self, {
		form: undefined,
		next: undefined,
		edition: undefined,
		unknown: undefined,
		reload:true,
		jsonEdition:null,
		inclusiveVAT: undefined,
		oldPostCode:undefined,

		getEdition: function() {

		if ( self.jsonEdition==null )return;

		if ( (self.edition.attr('selectedIndex')-1)<0 ){
			$('#listprice_inclusive').html( "&nbsp;");
			$('#listprice_exclusive').html("&nbsp;");
			$('#fuel_display').html("&nbsp;");
			$('#buildyear_display').html("&nbsp;");
			$('#price_display_exclusive').addClass(AA.Config.classNames['hide']);
			$('#price_display_inclusive').addClass(AA.Config.classNames['hide']);
			self.edition.title='';
			return;
		}

		var inclusive = $('#listprice_inclusive');
		var exclusive = $('#listprice_exclusive');
		var show = $('#price_display_inclusive');
		var hide = $('#price_display_exclusive');

		if ( !self.edition.length || !inclusive.length || !exclusive.length || !show.length ) return;

		$('#listprice_inclusive').html(self.jsonEdition.editions[self.edition.attr('selectedIndex')-1].inclusive );
		$('#listprice_exclusive').html(self.jsonEdition.editions[self.edition.attr('selectedIndex')-1].exclusive );
		$('#fuel_display').html(self.jsonEdition.editions[self.edition.attr('selectedIndex')-1].fuel );

		$('#buildyear_display').html(self.jsonEdition.editions[self.edition.attr('selectedIndex')-1].issuanceDate1); //TO CHECK
		self.edition.title = self.edition.attr('options')[self.edition.attr('selectedIndex')].title; //TO CHECK
		if ( show.hasClass(AA.Config.classNames['hide']) && hide.hasClass(AA.Config.classNames['hide']) ){
			self.showInclusive();
		}
	},

	showInclusive: function(ev) {
		if(ev) ev.stopImmediatePropagation();
		var show = $('#price_display_inclusive');
		var hide = $('#price_display_exclusive');
		if ( !show.length || !hide.length ) return;
		show.removeClass(AA.Config.classNames['hide']);
		hide.addClass(AA.Config.classNames['hide']);
		self.inclusiveVAT.attr('value', 'S');
	},

	showExclusive: function(ev) {
		if(ev) ev.stopImmediatePropagation();
		var show = $('#price_display_exclusive');
		var hide = $('#price_display_inclusive');
		if ( !show.length || !hide.length ) return;

		show.removeClass(AA.Config.classNames['hide']);
		hide.addClass(AA.Config.classNames['hide']);
		self.inclusiveVAT.attr('value', 'N');
	},

	toggleClaimsInfo: function(show) {

		var details = $('#secondarypolicyentry');

		if ( !details.length ) return;
		if (show) {
			details.removeClass(AA.Config.classNames['hide']);
		} else {
			details.addClass(AA.Config.classNames['hide']);
		}
	},

	showHelpCFY: function() {
		var details = $('#helpCFY');

		if ( !details.length ) return;

		if (details.hasClass(AA.Config.classNames['hide'])) {
			details.removeClass(AA.Config.classNames['hide']);
		} else {
			details.addClass(AA.Config.classNames['hide']);
		}

	},


	managmentLogged:function(){
		var show = self.flagDriverTrue.attr('checked');
		var completed = function(response) {
			if(!response)response=null;
			if (response.result=='true'){
				$('#postCode').attr('value', response.postCode);
				$('#male').attr('disabled',true);
				$('#female').attr('disabled',true);
				if (response.gender=="M")
					$('#male').attr('checked',true);
				else
					$('#female').attr('checked',true);

				$('#birthDateDay').attr('disabled',true);
				$('#birthDateDay').attr('value',response.birthDateDay);
				$('#birthDateMonth').attr('disabled',true);
				$('#birthDateMonth').attr('value',response.birthDateMonth);
				$('#birthDateYear').attr('disabled',true);
				$('#birthDateYear').attr('value',response.birthDateYear);
			}
		}
		if (show){
			//$('#postCode').val("");
			$('#male').attr('disabled',false);
			$('#male').attr('checked',false);
			$('#female').attr('disabled',false);
			$('#female').attr('checked',false);
			$('#birthDateDay').attr('disabled',false);
			$('#birthDateDay').attr('value','');
			$('#birthDateMonth').attr('disabled',false);
			$('#birthDateMonth').attr('value','01');
			$('#birthDateYear').attr('disabled',false);
			$('#birthDateYear').attr('value','');
		}else{

			var url = AA.Utils.updateFormAction( self.form , 'managmentLogged' ,null, true );
			AA.Utils.jsonCall( url, completed,'post',null,true );

		}

	},


	getCar: function(ev,force) {
		if ( (self.platenumber.attr('value').toLowerCase() == self.oldPlateNumber.toLowerCase()) && !force ) return;
		self.oldPlateNumber=self.platenumber.attr('value');
		var url = AA.Utils.updateFormAction( self.form , 'reloadByPlateNumber' , '&plateNumber=' + self.platenumber.attr('value') , true );

		AA.Utils.jsonCall( url, self.displayCar,null,null,true );
	},

	displayCar: function(car) {

		if( !$('#listprice_inclusive').length || !$('#listprice_exclusive').length ||
				!$('#fuel_display').length || !$('#buildyear_display').length || !$("#model_display").length ) return;

		self.modeldisplay = $('#model_display');

		$('#listprice_inclusive').html( "&nbsp;");
		$('#listprice_exclusive').html("&nbsp;");
		$('#fuel_display').html("&nbsp;");
		$('#model_display').html('&nbsp;');
		$('#buildyear_display').html("&nbsp;");
		AA.Utils.resetSelect(self.edition);

		/*
		 * MR -> 20101018
		 * Remove all the error from the page when an audascan search is called
		 */
		$( "#validationerrors" ).addClass( "hide" );
		( $( "#plateNumber" ).parent() ).removeClass( "error" );
		/*
		 * ******************************************************************
		 */

		if ( car == "" ) {
			return;
		}

		self.jsonEdition=car;

		$("#model_display").html('&nbsp;');

		if ( !(car.editions) ){
			$('#price_display_inclusive').addClass(AA.Config.classNames['hide']);
			$('#price_display_exclusive').addClass(AA.Config.classNames['hide']);

			return;
		}

		$.each( car.editions, function( index , element ){
			if (element['progModelBrand']!=""){

				var opt = $('<option></option>');
				opt.html(element['edition']);
				opt.attr('value',element['progModelBrand']);
				opt.attr('title', element['edition']);

				opt.appendTo(self.edition);
			}
		});

		try{

			if (self.indexEditionTmp!=null && self.indexEditionTmp > 0){
				self.edition.attr('selectedIndex',self.indexEditionTmp);
				self.edition.triggerHandler('change');
				self.indexEditionTmp=null;
			}else{
				if(self.edition.attr('options').length>1){
					/*Fat:
						  			bug fix for IE6:
						  			IE6 riconosce come errore JS il fatto di selezionare un option del combo.
						  			Sicuramente perche' il combo e' stato appena popolato, allora IE6 non sa bene come selezionare un valore.
						  			quindi uso il timeout per far si che IE6 respiri un po' in modo da raggirare il problema
					 */
					//Check if with ie6 this function works fine
					//window.setTimeout((function(){
					self.edition.attr('options')[1].selected='true';
					self.getEdition();
					//}).bind( self ),10);
				}
			}
		}catch(e){
		}
		self.modeldisplay.html(car.editions[0].make + ' ' +car.editions[0].model);
		self.platenumber[0].value = car.editions[0].plateNumber;
		self.zip.focus();

	},

	claimsFreeYearsSelected: function(ev){
		if($('#claimsFreeYears').attr('value')=='00')
			self.toggleClaimsInfo(true);
		else
			self.toggleClaimsInfo(false);

	},

	checkZIP:function(ev){

		ev.stopImmediatePropagation();
		if ( self.oldPostCode.toLowerCase()== self.zip.attr('value').toLowerCase() ){
			return;
		}
		self.oldPostCode = self.zip.attr('value');

		var ErrorClass=AA.Config.classNames['errorField_Quotation'];
		if(self.zip.attr('value')==""){
			return;
		}

		var regExpr = new RegExp(AA.Config.formFields["zip"].filter)
		if(!regExpr.test( self.zip.attr( 'value' ) ) ){
			AA.Utils.addError(self.zip,'zip');
		}else{
			var completed = function(response) {
				try{
					if(response.result=="true"){
						AA.Utils.removeError(self.zip,'zip');
					}else{
						AA.Utils.addError(self.zip,'zip');
					}
				}catch(ex){
					AA.Utils.addError(self.zip,'zip');
				}
			};
			var url = AA.Utils.updateFormAction( self.form , 'searchAddress' , '&postCode=' + self.zip.attr('value') , true );

			AA.Utils.jsonCall( url, completed,'get',null,false );
		}

	},



	init: function() {
		/*
		 * set all the object that should be used
		 */

		self.form    = $('#processForm');
		self.edition = $('#edition');
		self.unknown = $('#licenseunknown');
		self.platenumber = $('#plateNumber');
		self.vatinclusive = $('#vatinclusive');
		self.vatexclusive = $('#vatexclusive');
		self.helpCFYbutton = $('#helpCFYbutton');
		self.helpCFYbuttonDiv=$('#helpCFYbuttonDiv');
		self.inclusiveVAT=$('#VAT');
		self.claimsFreeYears=$('#claimsFreeYears');
		self.zip=$('#postCode');
		self.helpCFY = $('#helpCFY');
		self.flagDriverTrue=$('#flagDriverTrue');
		self.flagDriverFalse=$('#flagDriverFalse');

		if (!self.helpCFY.length || !self.form.length || !self.edition.length ||
				!self.unknown.length || !self.platenumber.length || !self.vatinclusive.length ||
				!self.vatexclusive.length || !self.helpCFYbutton.length) return;

		if (!self.oldPlateNumber)
			self.oldPlateNumber=self.platenumber.attr('value');
		if (!self.oldPostCode)
			self.oldPostCode=self.zip.attr('value');

		/*
		 * hide or show object
		 */
		self.helpCFY.addClass(AA.Config.classNames['hide']);
		self.helpCFYbuttonDiv.removeClass(AA.Config.classNames['hide']);

		/*
		 * remove all the event
		 */
		self.edition.unbind();
		//self.unknown.unbind();
		self.helpCFYbutton.unbind();
		self.vatinclusive.unbind();
		self.vatexclusive.unbind();
		self.claimsFreeYears.unbind();
		//self.zip.unbind();
		self.flagDriverTrue.unbind();
		self.flagDriverFalse.unbind();

		/*
		 * set the event of all the field
		 */
		self.helpCFYbutton.click(
				function(){
					self.showHelpCFYself();
				});

		self.vatinclusive.click(
				function(){
					self.showInclusive(self);
				});

		self.vatexclusive.click(
				function(){
					self.showExclusive(self);
				});

		self.edition.change(
				function(){
					self.getEdition(self);
				});

		self.platenumber.blur(
				function(){
					self.getCar(self);
				});

		self.claimsFreeYears.change(
				function(){
					self.claimsFreeYearsSelected(self);
				});

		self.zip.bind('blur',self.checkZIP);

		self.flagDriverTrue.click(
				function(){
					self.managmentLogged(self);
				});
		self.flagDriverFalse.click(
				function(){
					self.managmentLogged(self);
				});

		self.indexEditionTmp= self.edition.attr('selectedIndex');




		self.platenumber.focus();

		AA.Utils.jsonCall( contextPath_js + '/common/listMakeModelEditions.jsp',
				function( resp ){
					self.jsonEdition = resp;
				}
				,'get',null,false );

		AA.Utils.toolTipSelectIE6.initialize(
				{
					selectObj: '#edition',
					classTitle: 'editionTitle',
					event:{
					move: 'off'
				}
				}
		);

		//RM -> 2009051700
		//Enter Key Manager
		//In all the input[type=text] field in form, when you press enter key a submit event will happen,
		//then if all the field are compiled the system will go to the next page, else it will return to the same page
		//with error message
		$('input[type=text]',self.form).each(
				function(index, el){
					$(el).unbind('keydown').keydown(
							function(event){
								AA.Utils.eventEnterKey(self,event);
							}
					);
				}
		);

	}


	});
	$.extend( AA.States , {qqrequired: self});

})(jQuery);



//--- LICENSE UNKNOWN --------------------------------------------------------

(function($){

	var self = {};
	$.extend( self, {

		form:    undefined,
		brand:   undefined,
		model:   undefined,
		edition: undefined,
		jsonUnknown: undefined,

		getMake: function() {
		var spinner = $('#model_spinner');

		var IssuanceDateAMonth=$('#IssuanceDateAMonth');
		var IssuanceDateAYear=$('#IssuanceDateAYear');
		var IssuanceDateADay=$('#IssuanceDateADay');

		var fuel=$('#fuel');

		if (!self.make.length || !self.model.length || !spinner.length  ||
				(IssuanceDateADay.attr("value")=="")||(IssuanceDateAYear.attr("value").length!=4) || !(fuel.length && fuel.attr('selectedIndex')>0))
			return;

		if ((self.make.attr('options')[self.make.attr('selectedIndex')]).value==""){
			AA.Utils.resetSelect(self.model);
			AA.Utils.resetSelect(self.edition);

			var show = $('#price_display_inclusive');
			var hide = $('#price_display_exclusive');

			show.addClass(AA.Config.classNames['hide']);
			hide.addClass(AA.Config.classNames['hide']);

			return;
		}
		var completed = function(response){
			if(response!="ModelError"){
				var tmpDiv = $('<div></div>');
				$(tmpDiv).html(response);
				var myHidden=($(tmpDiv).find("select[id=model]"));
				$( myHidden ).find( 'option' ).each(
						function( index, optionlabel ) {
							$( optionlabel ).appendTo( self.model );
						}
				);
				self.model.attr('selectedIndex',0);

			}
			spinner.addClass(AA.Config.classNames['hide']);
		};
		spinner.removeClass(AA.Config.classNames['hide']);

		var params = '&make=' +  encodeURIComponent(self.make.attr('options')[self.make.attr('selectedIndex')].value) +"&IssuanceDateADay=" + IssuanceDateADay.attr("value") +
		"&IssuanceDateAMonth=" + IssuanceDateAMonth.attr('options')[IssuanceDateAMonth.attr('selectedIndex')].value +
		"&IssuanceDateAYear=" + IssuanceDateAYear.attr("value") + "&fuel=" + fuel.attr('options')[fuel.attr('selectedIndex')].value;

		var url = AA.Utils.updateFormAction( self.form , 'bindModel' , params , true );

		var options = {
				url : url,
				success : completed
		};


		$.ajax( options );



		AA.Utils.resetSelect(self.edition);
		AA.Utils.resetSelect(self.model);
		$('#price_display_inclusive').addClass(AA.Config.classNames['hide']);
		$('#price_display_exclusive').addClass(AA.Config.classNames['hide']);
	},

	getModel: function() {

		var spinner = $('#edition_spinner');
		var IssuanceDateAMonth=$('#IssuanceDateAMonth');
		var IssuanceDateAYear=$('#IssuanceDateAYear');
		var IssuanceDateADay=$('#IssuanceDateADay');

		var fuel=$('#fuel');

		if (!self.model.length || !self.edition.length || !spinner.length) return;

		if(!((IssuanceDateADay.attr("value")!="")&&
				(IssuanceDateAYear.attr("value").length==4)&&
				(fuel && fuel.attr('selectedIndex')>0)&&
				(self.model.attr('selectedIndex')>0)))return;

		var DateUrl=	"&IssuanceDateADay=" + IssuanceDateADay.attr("value") +
		"&IssuanceDateAMonth=" + IssuanceDateAMonth.attr('options')[IssuanceDateAMonth.attr('selectedIndex')].value +
		"&IssuanceDateAYear=" + IssuanceDateAYear.attr('value') +
		"&fuel=" + fuel.attr('options')[fuel.attr('selectedIndex')].value +
		"&make=" + encodeURIComponent(self.make.attr('options')[self.make.attr('selectedIndex')].value);

		var completed = function(response){
			// reset model
			AA.Utils.resetSelect(self.edition);
			if (response!="EditionError"){
				// populate model with response
				$(response.editions).each(function(index,element){
					if ( element.progModelBrand != '' ){
						var opt = $( '<option></option>' );
						opt.html( element.edition );
						opt.attr( 'value' , element.progModelBrand );
						opt.title= element.edition ; //Fat: add title
						opt.appendTo( self.edition );
					}
				});
			}
			jsonUnknown=response;
			self.edition.attr('selectedIndex',0);
			$('#price_display_inclusive').addClass(AA.Config.classNames['hide']);
			$('#price_display_exclusive').addClass(AA.Config.classNames['hide']);
			spinner.addClass(AA.Config.classNames['hide']);
		};

		spinner.removeClass(AA.Config.classNames['hide']);


		var params = '&model=' +  encodeURIComponent(self.model.attr('options')[self.model.attr('selectedIndex')].text) + DateUrl;

		var url = AA.Utils.updateFormAction( self.form , 'bindEdition' , params , true );
		AA.Utils.jsonCall( url, completed,'get',null,true );
	},

	getEdition: function() {
		var inclusive = $('#listprice_inclusive');
		var exclusive = $('#listprice_exclusive');
		var show = $('#price_display_inclusive');
		var hide = $('#price_display_exclusive');
		if (!self.edition || !inclusive.length || !exclusive.length || !show.length) return;

		if ( ((self.edition.attr('selectedIndex'))-1)<0 ){
			$('#listprice_inclusive').html( "&nbsp;");
			$('#listprice_exclusive').html("&nbsp;");
			$('#price_display_exclusive').addClass(AA.Config.classNames['hide']);
			$('#price_display_inclusive').addClass(AA.Config.classNames['hide']);
			self.edition.attr('title',''); //Fat: add title
			self.inclusiveVAT.attr('value','');
			return;
		}
		inclusive.html(jsonUnknown.editions[(self.edition.attr('selectedIndex'))-1].inclusive );
		exclusive.html(jsonUnknown.editions[(self.edition.attr('selectedIndex'))-1].exclusive );
		self.edition.title = self.edition.attr("options")[self.edition.attr('selectedIndex')].title; //Fat: add title

		if ( show.hasClass(AA.Config.classNames['hide']) && hide.hasClass(AA.Config.classNames['hide']) ){
			self.showInclusive();
		}


	},

	showInclusive: function(ev) {
		if (ev)new Event(ev).stop();
		var show = $('#price_display_inclusive');
		var hide = $('#price_display_exclusive');
		if (!show.length || !hide.length) return;

		show.removeClass(AA.Config.classNames['hide']);
		hide.addClass(AA.Config.classNames['hide']);
		self.inclusiveVAT.attr('value','S');
	},

	showExclusive: function(ev) {
		new Event(ev).stop();
		var show = $('#price_display_exclusive');
		var hide = $('#price_display_inclusive');
		if (!show.length || !hide.length) return;
		show.removeClass(AA.Config.classNames['hide']);
		hide.addClass(AA.Config.classNames['hide']);
		self.inclusiveVAT.attr('value','N');
	},

	showHelpCFY: function() {
		var details = $('#helpCFY');
		if (!details.length) return;

		if (details.hasClass(AA.Config.classNames['hide'])) {
			details.removeClass(AA.Config.classNames['hide']);
		} else {
			details.addClass(AA.Config.classNames['hide']);
		}
	},

	toggleClaimsInfo: function(show) {
		var details = $('#secondarypolicyentry');

		if (!details.length) return;

		if (show) {
			$(details).removeClass(AA.Config.classNames['hide']);
		} else {
			$(details).addClass(AA.Config.classNames['hide']);
		}
	},
	claimsFreeYearsSelected: function(){
		if($('#claimsFreeYears').attr("value")=='00')
			self.toggleClaimsInfo(true);
		else
			self.toggleClaimsInfo(false);
	},

	managmentLogged:function(){
		var show = self.flagDriverTrue.attr("checked");

		var completed = function(response) {
			if(!response)response=null;
			if (response.result=='true'){

				$('#postalcode').attr('value',response.postCode);
				$('#gender').attr("disabled",true);
				$('#female').attr("disabled",true);
				if (response.gender=="M")
					$('#gender').attr("checked",true);
				else
					$('#female').attr("checked",true);

				$('#birthday').attr('disabled',true);
				$('#birthday').attr('value',response.birthDateDay);
				$('#birthmonth').attr('disabled',true);
				$('#birthmonth').attr('value',response.birthDateMonth);
				$('#birthyear').attr('disabled',true);
				$('#birthyear').attr('value',response.birthDateYear);
			}
		}
		if (show){

			//$('#postalcode').attr('value','');
			$('#gender').attr('disabled',false);
			$('#gender').attr('checked',false);
			$('#female').attr('disabled',false);
			$('#female').attr('checked',false);
			$('#birthday').attr('disabled',false);
			$('#birthday').attr('value','');
			$('#birthmonth').attr('disabled',false);
			$('#birthmonth').attr('value','');
			$('#birthyear').attr('disabled',false);
			$('#birthyear').attr('value','');
		}else{

			var url = AA.Utils.updateFormAction( self.form , 'managmentLogged' , null,true );

			AA.Utils.jsonCall.apply( self, [url, completed,'post',null,true]);
		}

	},
	oldPostcode:undefined,
	checkZIP:function(ev){
		if ( self.oldPostCode.toLowerCase() == self.zip.attr("value").toLowerCase() )
			return;
		self.oldPostCode= self.zip.attr("value");

		var ErrorClass=AA.Config.classNames['errorField_Quotation'];
		if(self.zip.attr("value")==""){
			return;
		}

		var regExpr = new RegExp(AA.Config.formFields["zip"].filter)
		if(!regExpr.test( self.zip.attr( 'value' ) ) ){
			AA.Utils.addError(self.zip,'zip');
		}else{
			var completed = function(response) {
				try{
					if(response.result=="true"){
						AA.Utils.removeError(self.zip, 'zip');
					}else{
						AA.Utils.addError(self.zip, 'zip');
					}
				}catch(ex){
					AA.Utils.addError(self.zip, 'zip');
				}
			}
			var url = AA.Utils.updateFormAction( self.form , 'searchAddress' , '&postCode=' + self.zip.attr("value") , true );

			AA.Utils.jsonCall.apply( self, [url, completed,'get',null,false]);
		}

	},


	init : function() {
		// get necessary elements, abort if any are missing
		self.form    = $('#processForm');
		self.make    = $('#make');
		self.model   = $('#model');
		self.edition = $('#edition');
		self.vatinclusive = $('#vatinclusive');
		self.vatexclusive = $('#vatexclusive');
		var IssuanceDateADay=$('#IssuanceDateADay');
		var IssuanceDateAMonth=$('#IssuanceDateAMonth');
		var IssuanceDateAYear=$('#IssuanceDateAYear');

		self.helpCFYbutton = $('#helpCFYbutton');

		var fuel=$('#fuel');
		self.inclusiveVAT=$('#VAT');
		self.claimsFreeYears=$('#claimsFreeYears');

		self.flagDriverTrue=$('#flagDriverTrue');
		self.flagDriverFalse=$('#flagDriverFalse');
		self.zip = $('#postalcode');

		if (!self.zip.length || !self.form.length || !self.make.length || !self.model.length || !self.edition.length || !self.vatinclusive.length || !self.vatexclusive.length || !self.helpCFYbutton.length ) return;
		$('#helpCFY').addClass(AA.Config.classNames['hide']);
		$('#helpCFYbuttonDiv').removeClass(AA.Config.classNames['hide']);
		self.oldPostCode='';


		self.make.unbind('change');
		self.zip.unbind('blur');
		self.model.unbind('change');
		self.edition.unbind('change');
		self.helpCFYbutton.unbind('click');
		self.vatinclusive.unbind('click');
		self.vatexclusive.unbind('click');
		self.claimsFreeYears.unbind('change');
		self.flagDriverTrue.unbind('click');
		self.flagDriverFalse.unbind('click');

		// add events to elements
		self.make.change(function(){self.getMake(self)});
		self.model.change(function(){self.getModel(self)});
		self.edition.change(function(){self.getEdition(self)});
		IssuanceDateADay.blur(function(){self.getMake(self)});
		IssuanceDateAYear.blur(function(){self.getMake(self)});
		IssuanceDateAMonth.change(function(){self.getMake(self)});
		self.zip.blur(function(){self.checkZIP(self)});



		fuel.change(function(){self.getMake(self)});
		self.claimsFreeYears.change(function(){self.claimsFreeYearsSelected(self)});
		//self.claimsFreeYearsSelected();
		self.helpCFYbutton.click(function(){self.showHelpCFY(self)});

		self.vatinclusive.click(function(){self.showInclusive(self)});
		self.vatexclusive.click(function(){self.showExclusive(self)});

		self.flagDriverTrue.click(function(){self.managmentLogged(self)});
		self.flagDriverFalse.click(function(){self.managmentLogged(self)});


		//BugFix select IE6
		AA.Utils.toolTipSelectIE6.initialize(
				{
					selectObj: 'edition',
					classTitle: 'editionTitle',
					event:{
					move: 'off'
				}
				});

	}
	});
	$.extend( AA.States , {qqlicenseunknown: self});

})(jQuery);




//--- QQCALCULATE ------------------------------------------------------------

(function($){

	var self = {};
	$.extend( self, {
		form: undefined,
		selectPayment:undefined,
		isPremieNL:false,
		ajaxPremieNL:undefined,

		finishRequest : function ( response ) {

		try{
			var tmpDiv = $('<div></div>');
			tmpDiv.html(response);
			var actualPage = $( '#processForm' );
			tmpDiv.find('form').each ( function ( index , item ) {
				if ( item.id == 'processForm' ) {
					$( actualPage ).html( $(item).html() );
					$( actualPage ).attr( 'action' , $( item ).attr( 'action' ));
				}
			});
			self.init();
			window.updatePremiumList(jQuery);
			window.updateNavForm(jQuery);
		}catch(e){}
	},

	setBoxes: function() {
		var parentClass = self;

		//Nel caso ci sia attivo il servizio di premieNL non esegue le successive chiamate

		var getRecalcQuote = function(ev) {
			self.form     = $('#processForm');
			if (!self.form) return;
			var url = AA.Utils.updateFormAction( self.form , 'recalculate' ,null , false );
			AA.Utils.resetFormAction  (self.form, url );
			AA.Utils.submitForm(self.form,ev,self.finishRequest );
		};
		var getUpdateQuote = function ( ev ) {
			self.form     = $('#processForm');
			if (!self.form) return;

			var url = AA.Utils.updateFormAction( self.form , 'update' , null , false );
			AA.Utils.resetFormAction  (self.form, url );
			AA.Utils.submitForm(self.form,ev,self.finishRequest);
		};


		//imposto il ricalcolo sul campo del frazionamento
		self.selectPayment.change(
				function(){
					getRecalcQuote(self);
				}
		);


		//Fat: imposto il ricalcolo sui campi radio
		var radiobuttons = self.form.find('input[name=selectedOffer]');
		radiobuttons.each ( function ( index , el ) {
			$ ( el ).unbind('click').click ( function ( e ) {
				radiobuttons.each ( function ( index , el ) {
					var row = $(el).parent();

					while (row[0].tagName.toLowerCase() != 'dt') {
						row = row.parent();
					}
					if ( $(el).checked ) row.addClass('checked'); else row.removeClass('checked');
				});
				getUpdateQuote(e);
			});
		});

		//Fat: imposto il ricalcolo sui checkbox
		var checkboxes = self.form.find('#guarantiesTable input');
		checkboxes.each ( function ( index , el ) {
			$(el).unbind('click').click ( function ( e ) {
				var row = $(el).parent();

				while (row[0].tagName.toLowerCase() != 'dt') {
					row = row.parent();
				}
				if ($(el).checked) row.addClass('checked'); else row.removeClass('checked');
				getRecalcQuote(e);
			});
		});

		var checkboxesdisabled = self.form.find('.calc_checkbox_disabled input');
		checkboxesdisabled.each ( function ( index , el ) {
			$(el).unbind('click').click ( function ( e ) {
				$(e).checked = false;
			});
		});


		//Fat: imposto il ricalcolo sul combo delle limitazioni
		var limitSelect = self.form.find('div.divLimitationClass select');
		limitSelect.each ( function ( index , el ) {
			$ ( el ).unbind('change').change ( function ( e ) {
				getRecalcQuote(e);
			} );
		});
	},

	init: function() {

		self.form     = $('#processForm');

		self.selectPayment = $('#payment');

		self.setBoxes();


		self.form.find('.toggleExplanationLink').each(
				function ( index , el ) {
					$ ( el ).click( AA.Utils.toggleExplanationLink( el ) );
				}
		) ;


		/*
		 * MR -> 29-06-2010
		 * if the object exinting in page remove the previous event add the popup event on it
		 */
		if ( $('#premie_dot_nl').length ){

			$('#premie_dot_nl').unbind();
			$('#premie_dot_nl').colorbox({
				href: contextPath_js + '/autoverzekering/premieNLajaxWait.jsp',
				width: 550,
				height: 450,
				title: ' '
			}, function() {
				$.get(contextPath_js + '/do/processCar011Ajax?method=premieNL', function(data){
					$('#cboxLoadedContent').html(data);
				});
			});
		}

		self.form.find('.whatFitsBest a').unbind('click').click(function() {
			if ($(this).handleMethod()) return false;
		});
	}

	});
	$.extend( AA.States , {qqcalculate: self});

})(jQuery);




//--- QQEXISTACCOUNT -----------------------------------------------------------------


(function($){

	var self = {};
	$.extend( self, {
		username:undefined,
		password:undefined,
		form:undefined,

		init: function() {

		self.form = $('#processForm');
		self.username = $('#userName');
		self.password = $('#password');

		if ( !self.form.length || !self.username.length || !self.password.length ) return;

	}
	});
	$.extend( AA.States , {qqexistaccount: self});

})(jQuery);


//--- QQCREATEACCOUNT -----------------------------------------------------------------


(function($){

	var self = {};
	$.extend( self, {
		mailAddress:undefined,
		form:undefined,

		toggleHerhaalAccount: function() {
		var show = true;
		var next =$('#next');

		if (!self.form.length ||  !self.mailAddress.length) return;

		next.removeClass(AA.Config.classNames['hide']);

	},

	init: function() {

		self.form = $('#processForm');
		self.mailAddress = $('#mailAddress');

		if (!self.form.length ||  !self.mailAddress.length) return;

		self.toggleHerhaalAccount();

	}

	});
	$.extend( AA.States , {qqcreateaccount: self});

})(jQuery);

