if (!window.Car) {
    var Car = new Object();
}

Car.ToggleRadio = Class.create({
	initialize : function(container, openRadioButton, closeRadioButton) {
		this.container 			= $(container);
		this.openRadioButton  	= $(openRadioButton); 
		this.closeRadioButton	= $(closeRadioButton);
		
		if (!this.openRadioButton.checked) { 
			this.container.hide();
		}

		Event.observe(this.openRadioButton, 'click', this.click.bind(this,this.openRadioButton));
		Event.observe(this.closeRadioButton, 'click', this.click.bind(this,this.closeRadioButton));		
		
		
	},
	
	click : function(radio) { 
		if (radio==this.openRadioButton && this.openRadioButton.checked) {
			Effect.BlindDown(this.container);			
		} else {
			Effect.BlindUp(this.container);
		}
	}
});


Car.Calculator = Class.create({
	initialize : function(form,urlPrefix) {		
		this.form = $(form);
		this.urlPrefix = urlPrefix;
		this.privateOwner = true;
		this.coOwnerExisting = false;
		this.youngestOtherDriverExisting = false;
		this.needDateCheckOwner = true;
		this.needDateCheckCoOwner = true;
		this.needDateCheckYoungestOtherDriver = true;
		this.needFirstRegCheck = true;
		
		this.questionMarks = this.form.getElementsBySelector('img[alt="quest"]');
		this.infoBoxes = this.form.getElementsBySelector('[class="infoBox"]');
		for (var i=0; i<this.questionMarks.length; i++) {
			Event.observe(this.questionMarks[i], 'click', this.toggleInfoBox.bind(this,i));
			try {
				Event.observe(this.infoBoxes[i], 'click', this.hide.bind(this,this.infoBoxes[i])); 
				this.infoBoxes[i].hide();
			} catch (err) {
				//console.log(i);
			}
		}
		
		for (var i=2; i < 35; i++) {
			if ($('insurer_sub_oc_' + i) != null) {
				$('insurer_sub_oc_' + i).hide();
			}
			if ($('insurer_sub_ac_' + i) != null) {
				$('insurer_sub_ac_' + i).hide();
			}
			if ($('insurer_sub_oc_co_' + i) != null) {
				$('insurer_sub_oc_co_' + i).hide();
			}
			if ($('insurer_sub_ac_co_' + i) != null) {
				$('insurer_sub_ac_co_' + i).hide();
			}
		}
		if ($('previousInsurerOc') != null) {
			if ($('previousInsurerOc').value != "" && $('previousInsurerOc').value != "1") { 
				$('insurer_sub_oc_' + $('previousInsurerOc').value).show();
			} 
		}
		
		if ($('previousInsurerAc') != null) {
			if ($('previousInsurerAc').value != "" && $('previousInsurerAc').value != "1") {
				//$('insurer_sub_' + $('previousInsurerOc').value).show();
				$('insurer_sub_ac_' + $('previousInsurerAc').value).show();
			} 

		}
		
		if ($('previousInsurerOcCo') != null) {
			if ($('previousInsurerOcCo').value != "" && $('previousInsurerOcCo').value != "1") {
				//$('insurer_sub_' + $('previousInsurerOc').value).show();
				$('insurer_sub_oc_co_' + $('previousInsurerOcCo').value).show();
			} 

		}
		
		if ($('previousInsurerAcCo') != null) {
			if ($('previousInsurerAcCo').value != "" && $('previousInsurerAcCo').value != "1") {
				//$('insurer_sub_' + $('previousInsurerOc').value).show();
				$('insurer_sub_ac_co_' + $('previousInsurerAcCo').value).show();
			} 

		}
		
//		if ($('previousInsurerAcCo') != null && $('previousInsurerAcCo').value != "" && $('previousInsurerAcCo').value != "1") {
//			$('insurer_sub_ac_co_' + $('previousInsurerAcCo').value).show();
//		}
		
		if ($('previousInsurerOc') != null && $('previousInsurerOc').value != "13" && $('previousInsurerOc').value != "14") {
			$('container_3').hide();
		}
		
		if ($('previousInsurerAc') != null && $('previousInsurerAc').value != "13" && $('previousInsurerAc').value != "14") {
			$('container_4').hide();
		}
		
		if ($('previousInsurerOcCo') != null && $('previousInsurerOcCo').value != "13" && $('previousInsurerOcCo').value != "14") {
			$('container_5').hide();
		}
		
		if ($('previousInsurerAcCo') != null && $('previousInsurerAcCo').value != "13" && $('previousInsurerAcCo').value != "14") {
			$('container_6').hide();
		}
		
		if ($('formCarPage2') != null) {
			//this.changePrivateFirmData();
		}	
		
		//this.changeDriverLicenseFields();
	},
	
	initStartOfInsuranceDate : function() {
		var startDay = $('start.day');
		var startMonth = $('start.month');
		var startYear = $('start.year');
		var endDay = $('end.day');
		var endMonth = $('end.month');
		var endYear = $('end.year');
		
		var now = new Date();
		var nowAbsolute = now.getTime();
		var tomorrow = new Date();
		var tomorrowAbsolute;
		
		// distinguish between only Oc(diff == 0) and Oc + other insurance types(diff == 2)
		if (diff == 0) {
			tomorrowAbsolute = nowAbsolute + (24 * 60 * 60 * 1000);
		} else {
			tomorrowAbsolute = nowAbsolute + (3 * 24 * 60 * 60 * 1000);
		}
		tomorrow.setTime(tomorrowAbsolute);
		
		// update start date
		startDay.options[tomorrow.getDate()-1].selected = true;
		startMonth.options[tomorrow.getMonth()].selected = true;
		if (now.getFullYear() != tomorrow.getFullYear()) {
			startYear.options[startYear.selectedIndex+1].selected = true;
		} else {
			startYear.options[startYear.selectedIndex].selected = true;
		}
		
		// update end date
		this.updateEndOfInsuranceDate();
		
	},
	
	setHiddenFieldsPage1 : function() {
		$('regDay.hidden').value = $F('regDay');
		$('regMonth.hidden').value = $F('regMonth');
		$('regYear.hidden').value = $F('regYear');
	},
	
	setFirstRegistrationFields : function() {
		$('regDay').value = $F('regDay.hidden');
		$('regMonth').value = $F('regMonth.hidden');
		$('regYear').value = $F('regYear.hidden');
	},
	
	// set hidden driver licence date fields
	setHiddenFieldsPage2 : function () {
		$('date2.day.hidden').value = $F('date2.day');
		$('date2.month.hidden').value = $F('date2.month');
		$('date2.year.hidden').value = $F('date2.year');
		$('date4.day.hidden').value = $F('date4.day');
		$('date4.month.hidden').value = $F('date4.month');
		$('date4.year.hidden').value = $F('date4.year');
		$('date6.day.hidden').value = $F('date6.day');
		$('date6.month.hidden').value = $F('date6.month');
		$('date6.year.hidden').value = $F('date6.year');
	},
	
	setDriverLicenceFields : function () {
		$('date2.day').value = $F('date2.day.hidden');
		$('date2.month').value = $F('date2.month.hidden');
		$('date2.year').value = $F('date2.year.hidden');
		$('date4.day').value = $F('date4.day.hidden');
		$('date4.month').value = $F('date4.month.hidden');
		$('date4.year').value = $F('date4.year.hidden');
		$('date6.day').value = $F('date6.day.hidden');
		$('date6.month').value = $F('date6.month.hidden');
		$('date6.year').value = $F('date6.year.hidden');
	},
	
	setHiddenPrevInsurerSubCat : function(selectBox, prevInsurerSubCatHidden) {
		$(prevInsurerSubCatHidden).value = $F(selectBox);
	},
	
	setPrevInsurerSubCat : function(number, prevInsurer, prevInsurerSubCatHidden) {
		if (number == 1) {
			$('sub_cat_owner_oc_' + $(prevInsurer).value).value = $F(prevInsurerSubCatHidden);
		}
		if (number == 2) {
			$('sub_cat_owner_ac_' + $(prevInsurer).value).value = $F(prevInsurerSubCatHidden);
		}
		if (number == 3) {
			$('sub_cat_coOwner_oc_' + $(prevInsurer).value).value = $F(prevInsurerSubCatHidden);
		}
		if (number == 4) {
			$('sub_cat_coOwner_ac_' + $(prevInsurer).value).value = $F(prevInsurerSubCatHidden);
		}
	},
	
	cleanPrevInsurerSubCat : function(number, prevInsurerSubCatHidden) {
		if (number == 1) {
			for (var i=2; i < 35; i++) {
				if ($('insurer_sub_oc_' + i) != null) {
					$('sub_cat_owner_oc_' + i).options.selectedIndex = 0;
				}
			}
		}
		if (number == 2) {
			for (var i=2; i < 35; i++) {
				if ($('insurer_sub_ac_' + i) != null) {
					$('sub_cat_owner_ac_' + i).options.selectedIndex = 0;
				}
			}
		}
		if (number == 3) {
			for (var i=2; i < 35; i++) {
				if ($('insurer_sub_oc_co_' + i) != null) {
					$('sub_cat_coOwner_oc_' + i).options.selectedIndex = 0;
				}
			}
		}
		if (number == 4) {
			for (var i=2; i < 35; i++) {
				if ($('insurer_sub_ac_co_' + i) != null) {
					$('sub_cat_coOwner_ac_' + i).options.selectedIndex = 0;
				}
			}
		}
		$(prevInsurerSubCatHidden).value = "";
	},
	
	hide : function(element) {
		element.hide();
	}, 
	
	isEmpty : function(x) {
		return  ((v == null) || (v.length == 0));
	},
	
	isNumber : function(x) {
		return (!isNaN(v) && !/^\s+$/.test(v));
	},
	
	isNewCar : function(element,radio) {		
		if ($(radio).type=='radio') {
			if ($(radio).checked) {
				if (element.options.selectedIndex > 1) {
					element.options.selectedIndex = 1;
				}
			}
		} else {
			$(radio).options.selectedIndex = 0;
		}
	},
		
	back : function(url) {
		this.form.stopObserving('submit');
		this.form.action = this.urlPrefix + url;
		this.form.submit();			
	},
	
	isValidDate : function(day, month, year, err) {
		var day = $(day);
		var month = $(month);
		var year = $(year);
		var err = $(err);
		
	    /* check for empty vars */
	    if (day == null || month == null || year == null) {
	    	$(err).appear();
	    	return false;
	    }
	    /* check for number */
		if (isNaN(day.value) || isNaN(month.value) || isNaN(year.value)) {
			$(err).appear();
			return false;
		}
		/* year is wrong if year < 1900 */
		if (year.value < 1900) {
			$(err).appear();
			return false;
		}
		/* Validation of month*/
		if ((month.value < 1) || (month.value > 12)) {
			$(err).appear();
			return false;
		}
		/* Validation of day*/
		if (day.value < 1) {
			$(err).appear();
			return false;
		}
		/* Validation leap-year / february / day */
 		var leap = 0;
		if ((year.value % 4 == 0) || (year.value % 100 == 0) || (year.value % 400 == 0)) {
			leap = 1;
		}
		if ((month.value == 2) && (leap == 1) && (day.value > 29)) {
			$(err).appear();
			return false;
		}
		if ((month.value == 2) && (leap != 1) && (day.value > 28)) {
			$(err).appear();
			return false;
		}
		/* Validation of other months */
		if ((day.value > 31) && ((month.value == 1) || (month.value == 3) || (month.value == 5) || (month.value == 7) || (month.value == 8) || (month.value == 10) || (month.value == 12))) {
			$(err).appear();
			return false;
		}
		if ((day.value > 30) && ((month.value == 4) || (month.value == 6) || (month.value == 9) || (month.value == 11))) {
			$(err).appear();
			return false;
		}

		$(err).hide();
		return true;
	},
	
	compareDates : function(date1,date2,difference,coOwner,err) {
		var coOwner = $(coOwner);
		var err = $(err);
		var formCarPage2 = $('formCarPage2');
		
		if (coOwner != null && coOwner) {
			if ((!formCarPage2.radio41.checked && !formCarPage2.radio42.checked) ||
				(!formCarPage2.radio41.checked && formCarPage2.radio42.checked))	{
				$(err).hide();
				return true;
			}
		} 
		//console.log((date2.getYear()-(date1.getYear())+"#"+difference));	
		if ((date2.getYear()-date1.getYear())<=difference) {
			//console.log(date2.getYear()+'#'+date1.getYear());	
			if ((date2.getYear()-(date1.getYear())==difference)) {	
				if (date1.getMonth() >= date2.getMonth()) {
					//console.log(date2.getMonth()+'#'+date1.getMonth());
					if (date1.getMonth() == date2.getMonth()) {
						//console.log(date2.getDate()+'#'+date1.getDate());
						if (date1.getDate()<=date2.getDate()) {
							//console.log("Day<=");	
							$(err).hide();
							return true;		
						} else {
							$(err).appear();
							return false;
						}
					} else {
						$(err).appear();
						return false;
					}
				}
				$(err).hide();
				return true;
			} 
			$(err).appear();
			return false;
		} 
		$(err).hide();
		return true;		
	},
	
	dateIsNotGreaterThanToday : function(date,today,err) {
		var err = $(err);
		
		if (date.getYear() <= today.getYear()) {
			if (date.getYear() == today.getYear()) {
				if (date.getMonth() <= today.getMonth()) {
					if (date.getMonth() == today.getMonth()) {
						if (date.getDate() <= today.getDate()) {
							$(err).hide();
							return true;
						} else {
							$(err).appear();
							return false;
						}
					} else {
						$(err).hide();
						return true;
					}
				} else {
					$(err).appear();
					return false;
				}
			} else {
				$(err).hide();
				return true;
			}
		} else {
			$(err).appear();
			return false;
		}
	},
	
	validatePage1 : function() {
		
		var val1;
		var val2;
		var val3;
		var val4;
		
		if (this.needFirstRegCheck) {
			val1 = this.checkFirstReg('regDay','regMonth','regYear','productionYear','errorDate');
			val2 = this.isValidDate('regDay','regMonth','regYear','errorDate2');
		} else {
			val1 = true;
			val2 = true;
		}
		//var val3 = this.disableProductionYear('newCar');
		val3 = this.checkInsuranceTypes();
		val4 = this.checkSaleYear('saleYear', 'productionYear', 'errorDate3');
		val5 = this.validateDataPage1();
		
		this.setHiddenFieldsPage1();
		
		return (val1 && val2 && val3 && val4 && val5);
	},
	
	validateDataPage1 : function() {
		var val1=false;
		var val2 = validateForm.validate();
	
		if ($('profile.oc').checked == true || $('profile.ac').checked == true || $('profile.nnw').checked == true || $('profile.miniAssistance').checked == true ||
			$('profile.assistance').checked == true || $('profile.kglass').checked == true || $('profile.pop').checked == true) {
			$('errorNoInsuranceType').hide();
			val1 = true;
			if(val2==true){
				$('errorNoAllFields').hide();
				scroll(0,0);
			}
			else{
				val1 = true;
				$('errorNoAllFields').show();
				scroll(0,0);
			}
		}
		else{
				val1=false;
				scroll(0,0);
				$('errorNoInsuranceType').show();
				if(val2==true){
					$('errorNoAllFields').show();
				}
				else{
					$('errorNoAllFields').show();
				}
		}
		return (val1 && val2);
		
	},
	
	checkAllData:  function() {
		var val = validateForm.validate();
		
		if(val==true){
			$('errorNoAllFields').hide();
		}
		else{
			$('errorNoAllFields').show();
		}
		scroll(0,0);
		
		return (val);
	},
	
	validateDatesPage2 : function() {
		var date1 = new Date($F('date1.year'), $F('date1.month')-1, $F('date1.day'));
		var date2 = new Date($F('date2.year'), $F('date2.month')-1, $F('date2.day'));
		var date3 = new Date($F('date3.year'), $F('date3.month')-1, $F('date3.day'));
		var date4 = new Date($F('date4.year'), $F('date4.month')-1, $F('date4.day'));
		var date5 = new Date($F('date5.year'), $F('date5.month')-1, $F('date5.day'));
		var date6 = new Date($F('date6.year'), $F('date6.month')-1, $F('date6.day'));
		var today = new Date();
		
		var ownerIsValid = true;
		var coOwnerIsValid = true;
		var youngestOtherDriverIsValid = true;
		
		//validate owner data:
		
		var val1_1;
		var val1_2;
		var val1_3;
		var val1_4;
		var val1_5;
		var val1_6;
		
		if (this.needDateCheckOwner) {
			val1_1 = this.compareDates(date1,date2,16,null,'errorDate'); 	
		} else {
			val1_1 = true;
		}
		
		if (this.privateOwner) {
			val1_2 = this.isValidDate('date1.day', 'date1.month', 'date1.year', 'errorDate2');
		} else {
			val1_2 = true;
		}
		
		if (this.needDateCheckOwner) {
			val1_3 = this.isValidDate('date2.day', 'date2.month', 'date2.year', 'errorDate3');
		} else {
			val1_3 = true;
		}
		
		if (this.privateOwner) {
			val1_4 = this.compareDates(date1,today,18,null,'errorDate7');
		} else {
			val1_4 = true;
		}
		
		if (this.needDateCheckOwner) {
			val1_5 = this.dateIsNotGreaterThanToday(date2, today, 'errorDate3');
		} else {
			val1_5 = true;
		}
		
		ownerIsValid = val1_1 && val1_2 && val1_3 && val1_4 && val1_5;
		
		//validate co-owner data
		
		var val2_1;
		var val2_2;
		var val2_3;
		
		if (this.needDateCheckCoOwner) {
			val2_1 = this.compareDates(date3,date4,16,true,'errorDate6');
		} else {
			val2_1 = true;
		}

		if (this.coOwnerExisting) {
			val2_2 = this.isValidDate('date3.day', 'date3.month', 'date3.year', 'errorDate4');
			val2_3 = this.isValidDate('date4.day', 'date4.month', 'date4.year', 'errorDate5');
		} else {
			val2_2 = true;
			val2_3 = true;
		}
		
		coOwnerIsValid = val2_1 && val2_2 && val2_3;
		
		// validate youngest other driver
		
		var val3_1;
		var val3_2;
		var val3_3;
		
		if (this.youngestOtherDriverExisting && this.needDateCheckYoungestOtherDriver) {
			val3_1 = this.compareDates(date5,date6,16,null,'errorDate34');
		} else {
			val3_1 = true;
		}
		
		if (this.youngestOtherDriverExisting) {
			val3_2 = this.isValidDate('date5.day', 'date5.month', 'date5.year', 'errorDate31');
			val3_3 = this.isValidDate('date6.day', 'date6.month', 'date6.year', 'errorDate33');
		} else {
			val3_2 = true;
			val3_3 = true;
		}
		
		youngestOtherDriverIsValid = val3_1 && val3_2 && val3_3;
		
		this.setHiddenFieldsPage2();
		
		val1_6 = this.checkAllData();
		//var val8 = this.compareDates(date1,today,18,null,'errorDate8');
		
	//	alert(ownerIsValid && coOwnerIsValid && youngestOtherDriverIsValid);
		return (ownerIsValid && coOwnerIsValid && youngestOtherDriverIsValid && val1_6);
	},
	
	validateDatesPage3 : function() {
		
		var val1 = this.checkStartDate('start.day','start.month','start.year', diff, this);
		var val2 = this.isValidDate('start.day', 'start.month', 'start.year', 'errorDate2');
		var val3 = this.checkAllData();
//		alert(val1 +","+ val2)
		return (val1 && val2 && val3);
	},
	
	checkStartDate : function(day, month, year, difference, form) {
		var now = new Date();

		var startDay = $(day);
		var startMonth = $(month);
		var startYear = $(year);
		
		var startDate = new Date(startYear.value, (startMonth.value-1), startDay.value);				
		startDate.setDate(startDate.getDate() - difference);
		
		if (startDate < now) {
			$('errorDate').appear();
			return false;
		} else {
			$('errorDate').hide();
			return true;
		}
		
//		$('errorDate').hide();
		
	},
	
	checkFirstReg : function(regDay, regMonth, regYear, productionYear, err) {
		var regDay = $F(regDay);
		var regMonth = $F(regMonth);
		var regYear= $F(regYear);
		var productionYear = $F(productionYear);
		
		// 7 (Tage) * 24 * 60 * 60 * 1000
//		var legalDayInMillSec = 604800000;
		
		// 8 (Tage) * 24 * 60 * 60 * 1000
//		var legalDayInMillSec = 691200000;	
//		var date = new Date(regYear, regMonth-1, regDay).getTime();
//		var today = new Date().getTime();
//		
//		if ($('radio2.1').checked) {			
//			if ((today-date)>legalDayInMillSec) {
//				$(err).appear();
//				return false;
//			} 
//		} else if (productionYear>regYear){
//			$(err).appear();
//			return false;
//		} 
	
		if (productionYear > regYear) {
			$(err).appear();
			return false;
		}
		$(err).hide();
		return true;
	},
	
	checkSaleYear : function(sYear, pYear, err) {
		var saleYear = $F(sYear);
		var productionYear = $F(pYear);
			
		if (productionYear > saleYear) {
			$(err).appear();
			return false;
		}
		$(err).hide();
		return true;
		
	},
	
	updateEndOfInsuranceDate : function() {
		var startDay = $('start.day');
		var startMonth = $('start.month');
		var startYear = $('start.year');
		var endDay = $('end.day');
		var endMonth = $('end.month');
		var endYear = $('end.year');
		var endDayHidden = $('end.day.hidden');
		var endMonthHidden = $('end.month.hidden');
		var endYearHidden = $('end.year.hidden');
		var days = 364;
		var startLeapYearDate;
		var endLeapYearDate;
		
		var startDate = new Date(startYear.value, startMonth.value-1, startDay.value);
		var endDate = new Date();
		var startDateAbsolute = startDate.getTime();
		var endDateAbsolute;
		
		if (this.isValidDate(startDay, startMonth, startYear, 'errorDate2')) {
		
			// if start year is a leap year
			if ((startYear.value % 4 == 0) || (startYear.value % 100 == 0) || (startYear.value % 400 == 0)) {
				startLeapYearDate = new Date(startYear.value, 1, 29);
				if (startDate <= startLeapYearDate) {
					days = 365;
				}
			} 
			
			// if end year is a leap year
			var endYearValue = parseInt(startYear.value) + 1;
			if ((endYearValue % 4 == 0) || (endYearValue % 100 == 0) || (endYearValue % 400 == 0)) {
				endLeapYearDate = new Date(endYearValue, 1, 29);
				endDate = new Date(startYear.value, startMonth.value-1, startDay.value);
				endDate.setFullYear(endDate.getFullYear()+1);
				if (endDate > endLeapYearDate) {
					days = 365;
				}
			}
			
			endDateAbsolute = startDateAbsolute + (days * 24 * 60 * 60 * 1000);
			endDate.setTime(endDateAbsolute);
			endDay.options[endDate.getDate()-1].selected = true;
			endMonth.options[endDate.getMonth()].selected = true;
			if (startDate.getFullYear() != endDate.getFullYear()) {
				endYear.options[startYear.selectedIndex+1].selected = true;
			} else {
				endYear.options[startYear.selectedIndex].selected = true;
			}	
			endYearHidden.value = endDate.getFullYear();
			endMonthHidden.value = endDate.getMonth() + 1;
			endDayHidden.value = endDate.getDate();
		
		}
	
	},
	
	disableSecondOc : function() {
		var yearsWithoutAccidentsOc = $('yearsWithoutAccidentsOc');
		var accidentsLastYearOc = $('accidentsLastYearOc');
		var formCarPage3 = $('formCarPage3');
		
		if (!yearsWithoutAccidentsOc) return;
		if (yearsWithoutAccidentsOc.value > 0) {
			formCarPage3.accidentsLastYearOc.disabled = true;
		} else {
			formCarPage3.accidentsLastYearOc.disabled = false;
		}

	},
	
	disableSecondOcCo : function() {
		var yearsWithoutAccidentsOcCo = $('yearsWithoutAccidentsOcCo');
		var accidentsLastYearOcCo = $('accidentsLastYearOcCo');
		var formCarPage3 = $('formCarPage3');
		
		if (!yearsWithoutAccidentsOcCo) return;
		if (yearsWithoutAccidentsOcCo.value > 0) {
			formCarPage3.accidentsLastYearOcCo.disabled = true;
		} else {
			formCarPage3.accidentsLastYearOcCo.disabled = false;
		}
	},
	
	disableSecondAc : function() {
		var yearsWithoutAccidentsAc = $('yearsWithoutAccidentsAc');
		var accidentsLastYearAc = $('accidentsLastYearAc');
		var formCarPage3 = $('formCarPage3');
		
		if (!yearsWithoutAccidentsAc) return;
		if (yearsWithoutAccidentsAc.value > 0) {
			formCarPage3.accidentsLastYearAc.disabled = true;
		} else {
			formCarPage3.accidentsLastYearAc.disabled = false;
		}

	},
	
	disableSecondAcCo: function() {
		var yearsWithoutAccidentsAcCo = $('yearsWithoutAccidentsAcCo');
		var accidentsLastYearAcCo = $('accidentsLastYearAcCo');
		var formCarPage3 = $('formCarPage3');
		
		if (!yearsWithoutAccidentsAcCo) return;	
		if (yearsWithoutAccidentsAcCo.value > 0) {
			formCarPage3.accidentsLastYearAcCo.disabled = true;
		} else {
			formCarPage3.accidentsLastYearAcCo.disabled = false;
		}
	},
	
	changePrivateFirmData : function() {
		var radio11 = $('radio1.1');
		var radio12 = $('radio1.2');
		
		if (radio11.checked) {
			this.privateOwner = true;
			this.needDateCheckOwner = true;
			Effect.BlindUp($('firmData'));
			Effect.BlindDown($('privateData'));
		}
		
		if (radio12.checked) {
			this.privateOwner = false;
			this.needDateCheckOwner = false;
			Effect.BlindUp($('privateData'));
			Effect.BlindDown($('firmData'));
		}
	},
	
	changeOwnerDriverLicenseFields : function() {
		var radio31 = $('radio3.1');
		var radio32 = $('radio3.2');
		var driverLicDay = $('date2.day');
		var driverLicMonth = $('date2.month');
		var driverLicYear = $('date2.year');
		
		if (radio31.checked) {
			driverLicDay.disabled = false;
			driverLicMonth.disabled = false;
			driverLicYear.disabled = false;
			this.needDateCheckOwner = true;
//			this.setDriverLicenceFields();
//			this.setHiddenFieldsPage2();
		}
		
		if (radio32.checked) {
			driverLicDay.disabled = true;
			driverLicMonth.disabled = true;
			driverLicYear.disabled = true;
			this.needDateCheckOwner = false;
			$('errorDate').hide();
			$('errorDate3').hide();
//			this.setDriverLicenceFields();
//			this.setHiddenFieldsPage2();
		}
		
	},
	
	changeCoOwnerDriverLicenseFields : function() {
		var radio61 = $('radio6.1');
		var radio62 = $('radio6.2');
		var driverLicDay = $('date4.day');
		var driverLicMonth = $('date4.month');
		var driverLicYear = $('date4.year');
		
		if (radio61.checked) {
			driverLicDay.disabled = false;
			driverLicMonth.disabled = false;
			driverLicYear.disabled = false;
			this.needDateCheckCoOwner = true;
//			this.setDriverLicenceFields();
//			this.setHiddenFieldsPage2();
		}
		
		if (radio62.checked) {
			driverLicDay.disabled = true;
			driverLicMonth.disabled = true;
			driverLicYear.disabled = true;
			this.needDateCheckCoOwner = false;
			$('errorDate6').hide();
			$('errorDate5').hide();
//			this.setDriverLicenceFields();
//			this.setHiddenFieldsPage2();
		}
		
	},
	
	changeYoungestOtherDriverLicenseFields : function() {
		var radio101 = $('radio10.1');
		var radio102 = $('radio10.2');
		var driverLicDay = $('date6.day');
		var driverLicMonth = $('date6.month');
		var driverLicYear = $('date6.year');
		
		if (radio101.checked) {
			driverLicDay.disabled = false;
			driverLicMonth.disabled = false;
			driverLicYear.disabled = false;
			this.needDateCheckYoungestOtherDriver = true;
//			this.setDriverLicenceFields();
//			this.setHiddenFieldsPage2();
		}
		
		if (radio102.checked) {
			driverLicDay.disabled = true;
			driverLicMonth.disabled = true;
			driverLicYear.disabled = true;
			this.needDateCheckYoungestOtherDriver = false;
			$('errorDate34').hide();
//			this.setDriverLicenceFields();
//			this.setHiddenFieldsPage2();
		}
		
	},
	
	changeCarFirstRegFields : function() {
		var radio21 = $('radio2.1');
		var radio22 = $('radio2.2');
		var firstRegDay = $('regDay');
		var firstRegMonth = $('regMonth');
		var firstRegYear = $('regYear');
		
		if (radio21.checked) {
			firstRegDay.disabled = true;
			firstRegMonth.disabled = true;
			firstRegYear.disabled = true;
			this.needFirstRegCheck = false;
			$('errorDate').hide();
			$('errorDate2').hide();
		}
		
		if (radio22.checked) {
			firstRegDay.disabled = false;
			firstRegMonth.disabled = false;
			firstRegYear.disabled = false;
			this.needFirstRegCheck = true;			
		}	
	},
	
	toggleCoOwnerExisting : function(exists) {
		if (exists) {
			this.coOwnerExisting = true;
		} else {
			this.coOwnerExisting = false;
		}
	},
	
	toggleYoungestOtherDriverExisting : function(exists) {
		if (exists) {
			this.youngestOtherDriverExisting = true;
		} else {
			this.youngestOtherDriverExisting = false;
		}
	},
	
	checkPreviousInsurer : function(selectBox, container) {
		var selectBox = $(selectBox);
		var container = $(container);
		
		if (selectBox.value == "13" || selectBox.value == "14") {
			Effect.BlindDown(container);
		} else {
			Effect.BlindUp(container);
		}
		
	},
	
	checkPreviousInsurerSubCatOc : function() {
		for (var i=2; i < 35; i++) {
			if ($('insurer_sub_oc_' + i) != null) {
				$('insurer_sub_oc_' + i).hide();
				//Effect.BlindUp($('insurer_sub_' + i));
			}
		}
		if ($('previousInsurerOc').value != "" && $('previousInsurerOc').value != "1") {
			//$('insurer_sub_' + $('previousInsurerOc').value).show();
			Effect.BlindDown($('insurer_sub_oc_' + $('previousInsurerOc').value));
			$('previousInsurerOcContainer').show();
			Effect.BlindDown($('previousInsurerOcContainer'));
		} else{
			$('previousInsurerOcContainer').hide();
			Effect.BlindUp($('previousInsurerOcContainer'));
		}
		
	},
	
	checkPreviousInsurerSubCatAc : function() {
		for (var i=2; i < 35; i++) {
			if ($('insurer_sub_ac_' + i) != null) {
				$('insurer_sub_ac_' + i).hide();
				//Effect.BlindUp($('insurer_sub_' + i));
			}
		}
		if ($('previousInsurerAc').value != "" && $('previousInsurerAc').value != "1") {
			//$('insurer_sub_' + $('previousInsurerOc').value).show();
			Effect.BlindDown($('insurer_sub_ac_' + $('previousInsurerAc').value));
			$('previousInsurerAcContainer').show();
			Effect.BlindDown($('previousInsurerAcContainer'));
		} else{
			$('previousInsurerAcContainer').hide();
			Effect.BlindUp($('previousInsurerAcContainer'));
		}

	},
	
	checkPreviousInsurerSubCatOcCo : function() {
		for (var i=2; i < 35; i++) {
			if ($('insurer_sub_oc_co_' + i) != null) {
				$('insurer_sub_oc_co_' + i).hide();
				//Effect.BlindUp($('insurer_sub_' + i));
			}
		}
		if ($('previousInsurerOcCo').value != "" && $('previousInsurerOcCo').value != "1") {
			//$('insurer_sub_' + $('previousInsurerOc').value).show();
			Effect.BlindDown($('insurer_sub_oc_co_' + $('previousInsurerOcCo').value));
		} 
		
	},
	
	checkPreviousInsurerSubCatAcCo : function() {
		for (var i=2; i < 35; i++) {
			if ($('insurer_sub_ac_co_' + i) != null) {
				$('insurer_sub_ac_co_' + i).hide();
				//Effect.BlindUp($('insurer_sub_' + i));
			}
		}
		if ($('previousInsurerAcCo').value != "" && $('previousInsurerAcCo').value != "1") {
			//$('insurer_sub_' + $('previousInsurerOc').value).show();
			Effect.BlindDown($('insurer_sub_ac_co_' + $('previousInsurerAcCo').value));
		} 

	},
	
	checkInsuranceTypes : function() {
		
		if ($('profile.oc').checked == true || $('profile.ac').checked == true || $('profile.nnw').checked == true || $('profile.miniAssistance').checked == true ||
			$('profile.assistance').checked == true || $('profile.kglass').checked == true || $('profile.pop').checked == true) {
			$('errorNoInsuranceType').hide();
			return true;
		}
		scroll(0,0);
		$('errorNoInsuranceType').show();
		
		return false;
	},
	
	replaceComma : function(input) {
		var i = $(input);
		
		i.value = i.value.replace(/,/,".");
	},
	
	toggleInfoBox : function(number) {
		var element = this.infoBoxes[number];
		
		if (element.style.display=="none") {
			element.show();			
		} else {
			element.hide();
		}
	}
	
});



Car.Postcode = Class.create({
	initialize : function(namePrefix,urlPrefix,validator) { 
		this.namePrefix		= namePrefix + ".";
		this.urlPrefix 		= urlPrefix;		
		this.url 			= urlPrefix + "/service/geo?zip=";
		this.form	 		= validator.form;
		this.timeout 		= null;
		this.validator		= validator;		
				
		
		if (this.namePrefix!=".") {
			this.element 		= $(this.namePrefix + "zip");
			
			Event.observe(this.element, 'blur', this.update.bind(this));
			//Event.observe(this.element, 'keyup', this.checkInput.bind(this));
			Event.observe(this.element, 'keyup', this.change.bind(this));
			
			if ($('cell.borough').innerHTML=="") {
				//this.element.value="";
			}
			//$('ajaxLoaderTiny').hide();
			if (this.element.value == "") {
				//this.clear();
			} 
		}		
		Event.observe(this.form, 'submit', this.send.bind(this));
	},  
	
	clear : function() {
		this.element.value = "";		
		$(this.namePrefix + 'id').value="";		
       	$('cell.borough').innerHTML="";
       	$('cell.district').innerHTML="";
       	$('cell.federalState').innerHTML="";		
	},
	
	change : function() { 
		if (/^[0-9]{2}-[0-9]{3}$/.test(this.element.value)) {
			$('errorZip').hide();
			new Ajax.Request(this.url + this.element.value, {
				method: 'post',
				parameters: this.url,
				onSuccess: this.showResponse.bind(this),
				onLoading: function(){
					$('ajaxLoaderTiny').show();	  				
				},
				onFailure: function(){
					$('ajaxLoaderTiny').hide();
				}
			});
		}
		else if (/^.{6}$/.test(this.element.value)) {
			$('errorZip').appear();
		}
	},
	
	update : function() { 
		if (/^[0-9]{2}-[0-9]{3}$/.test(this.element.value)) {
			$('errorZip').hide();
			new Ajax.Request(this.url + this.element.value, {
				method: 'post',
				parameters: this.url,
				onSuccess: this.showResponse.bind(this),
				onLoading: function(){
					$('ajaxLoaderTiny').show();	  				
				},
				onFailure: function(){
					$('ajaxLoaderTiny').hide();
				}
			});
		}
		else {
			this.clear();
			this.element.focus();
		}	
	},
	
	showResponse : function(transport) { 
		$('ajaxLoaderTiny').hide();
		if (transport.responseText=="NO_SUCH_ZIP" || transport.responseText=="AN_ERROR_OCCURED"){
			$('errorZip').appear();			
			this.clear();
			this.element.focus();
		} else {			
			try {
				var result = transport.responseText.evalJSON();
		    	$(this.namePrefix + 'id').value=result.id;
		    	$('cell.borough').innerHTML=result.borough;
		    	$('cell.district').innerHTML=result.district;
		    	$('cell.federalState').innerHTML=result.federalState;
			} catch (err) {
				//alert("error");
			}
		}
	    $('ajaxLoaderTiny').hide();
	    $('btnSubmit').disabled = "";
	},
	
	send : function() {		
		try {
			clearTimeout(this.timeout);
			if ($('ajaxLoaderTiny') && $('ajaxLoaderTiny').style.display!="none" || $('cell.district').innerHTML=="") {			 
				this.timeout = setTimeout(this.submit.bind(this),1000);
			} else {
				if (this.validator.validate()) {
					this.form.submit();
				}
			}	
		} catch (err) {
			if (this.validator.validate()) {
				this.form.submit();
			}
		}	
	},
	
	checkInput : function() { 
		//console.log('keyup');
		if (this.element.value.length>5) {
			$('btnSubmit').focus();
		}
	}
});

Car.Individuals = Class.create({
	initialize : function(urlPrefix) { 
	    this.carType				= $('profile.car.carType');
		this.selectVendor			= $('profile.car.vehicle.vendor.id');
		this.selectModel 			= $('profile.car.vehicle.model.id');
		this.selectVehicle 			= $('profile.car.vehicle.id');
		this.selectNumberOfSeats	= $('profile.car.customNumberOfSeats');
		this.purposeOfCar			= $('profile.car.carPurpose');
		this.productionYear         = $('productionYear');
		
		this.url = urlPrefix + "/service/car/individuals";
		
		$('ajaxLoaderTiny').hide();
		
		Event.observe(this.carType, 'change', this.update.bind(this,this.carType,this.selectVendor));
		Event.observe(this.selectVendor, 'change', this.update.bind(this,this.selectVendor,this.selectModel));
		Event.observe(this.selectModel, 'change', this.update.bind(this,this.selectModel,this.selectVehicle));
		//Event.observe(this.selectVehicle, 'change', this.update.bind(this,this.selectVehicle,selectNumberOfSeats));
		Event.observe(this.selectVehicle, 'change', this.update.bind(this,this.selectVehicle,this.productionYear));
		
		if (this.selectVendor.disabled) { 
			this.carType.selectedIndex = 0;
		}
	}, 
	
	update : function(parent,child) {
		switch (parent) {
		
			case this.carType		: this.selectVendor.disabled = "disabled"; 	
			                         // this.selectVendor.selectedIndex = 0;
		                              this.selectModel.disabled = "disabled"; 		                              
			                          this.selectVehicle.disabled = "disabled";	
			                          this.selectNumberOfSeats.disabled = "disabled";
			                          this.purposeOfCar.disabled = "disabled";	
			                          this.productionYear.disabled = "disabled";
			                         
		                              break;
			case this.selectVendor	: this.selectModel.disabled = "disabled"; 
									  this.selectVehicle.disabled = "disabled";
									  this.selectNumberOfSeats.disabled = "disabled";
									  this.purposeOfCar.disabled = "disabled";
									  this.productionYear.disabled = "disabled";
									  //this.carType.disabled = "disabled";
									  //this.purposeOfCar.disabled = "disabled";
									  //this.cleanList(this.selectModel);
									  //this.cleanList(this.selectVehicle);
			case this.selectModel	: this.selectVehicle.disabled = "disabled";
									  this.selectNumberOfSeats.disabled = "disabled";
			                          this.purposeOfCar.disabled = "disabled";
			                          this.productionYear.disabled = "disabled";
									  //this.carType.disabled = "disabled";
									  //this.purposeOfCar.disabled = "disabled";
									  //this.cleanList(this.selectVehicle);
		    						  break;
			case this.selectVehicle : this.selectNumberOfSeats.disabled = "";
									  this.purposeOfCar.disabled = "";
									  this.productionYear.disabled = "disabled";
									  break;
		
			
		}
		if (parent.value!='') {
			//alert(parent.value);			
			//parent.options.remove[0];
			child.disabled = "";
			child.className = "required";
			
			if (child == this.productionYear) {
				child.className = "required date";
			}
				var url = this.url + "?" + parent.id + "=" + parent.value;	
				new Ajax.Updater(child, url);
			
			
		}
	},
	
	cleanList : function(element) {
		for (var i=element.length-1; i>-1; i--) {
      		element.remove(i);
    	}
    	element.className = "";
    	//alert(element.className);
    	var el = 'advice-required-'+element.id;    	
    	if ($(el)!=null) {
    		$(el).style.display = "none";
    	}
	}
});


Car.Resultpage = Class.create({
	
	initialize: function(contextPath, carProviderIds, carSearchProfileId, resultTxtProperties, providerLogoPath, providerLogoEnding){
		this.totalCosts = new Array();
		this.contextPath = contextPath;
		this.carProviderIds = carProviderIds;
		this.carSearchProfileId = carSearchProfileId;
		this.resultTxtProperties = resultTxtProperties;
		this.providerLogoPath = providerLogoPath;
		this.providerLogoEnding = providerLogoEnding;
		this.preloadResultList();
		//this.extendedRater = new ExtendedRater();
		
	},
	changeTotalCost4Offer: function(){
		
	},
	addCost: function(cost){
		this.totalCosts[this.totalCosts.length] = cost;
	},
	getCost: function(elementId,index){
//		alert($(index.id).selectedIndex);
		var priceElement = 'price_' + elementId;
		$(priceElement).innerHTML = this.totalCosts[$(index.id).selectedIndex];
	},
	preloadResultList: function(){
		
		this.returnedResponses = 0;
		this.mbankProviderId;
		this.mbankRowId;
		this.personalId = -1;
		this.instalments = 1;
		this.personalIdInserted = false;
		
		$('installments_id').selectedIndex = 0;
		
		for (var i=0; i < this.carProviderIds.length; i++){
			if (this.carProviderIds[i] == 6) {
				this.buildInputField(i);
				this.mbankProviderId = 6;
				this.mbankRowId = i;
			} else {
				this.sendAjaxRequest(this.carProviderIds[i],i,this.personalId,this.instalments);
			}
		}
	},
	changeRate : function(instalments) {
		
		$('resultListTable').innerHTML = '&nbsp;';
		Effect.BlindDown($('ruler'));
		
		this.returnedResponses = 0;
		this.instalments = $(instalments).value;
		
		for (var i=0; i < this.carProviderIds.length; i++){
			if (this.carProviderIds[i] == 6 && this.personalId == -1) {
				this.buildInputField(i);
				this.mbankProviderId = carProviderIds[i];
				this.mbankRowId = i;
			} else {
				this.sendAjaxRequest(this.carProviderIds[i],i,this.personalId,this.instalments);
			}
		}
	},
	sendAjaxRequest : function(providerId, id, personalId, instalments) {
		var url = this.contextPath + "/service/insuranceOffer?providerId=" + providerId + '&carSearchProfileId=' + this.carSearchProfileId + '&rowId=' + id + '&personalId=' + personalId + '&instalments=' + instalments;
		new Ajax.Request(url, {
			method: 'post',
			parameters: url,
			onSuccess: this.showAjaxResponse.bind(this),
			onLoading: function(){      
		},
		onFailure: function(){
			this.returnedResponses += 1;
			if(this.returnedResponses >= this.carProviderIds.length){
				Effect.BlindUp($('ruler'));
			}
//			$('ajaxLoaderTinyTest').hide();
		}
		});
	},
	showAjaxResponse : function(transport) { 
		//$('ajaxLoaderTinyTest').hide();
		if (transport.responseText=="NO_SUCH_RESULT" || transport.responseText=="AN_ERROR_OCCURED"){
			//$('errorZipTest').appear();   
		} else {   
			try 
			{
			    var response = transport.responseText.evalJSON();   
			    if (response.providerId != 6 || this.personalIdInserted) 
			    {
				    if (response.providerId == 4) 
				    {
		    			var providerLogoStatic = "http://cms.placemniej.pl/images/stories/car_provider_aviva.jpg";
			    	    this.staticResultList(response.price, response.averageRanking, response.rankingCount, response.rowId, response.purchaseUrl, this.getProviderPdf(response.providerId), providerLogoStatic);
					    
					    //important for sorting
					    $('providerPrice_' + response.rowId).value = response.price;
					    
					    $('info_' + response.providerId).style.display='block';
					    this.setTemplate4Details(response);
				    
				    } else
				    if (response.providerId == 8)
				    {
				    	var providerLogoStatic = "http://cms.placemniej.pl/images/stories/liberty direct.gif";
				    	this.staticResultList(response.price, response.averageRanking, response.rankingCount, response.rowId, response.purchaseUrl, this.getProviderPdf(response.providerId), providerLogoStatic);
					    
					    //important for sorting
					    $('providerPrice_' + response.rowId).value = response.price;
					    
					    $('info_' + response.providerId).style.display='block';
					    this.setTemplate4Details(response);
				    } else
				    	if (response.providerId == 11)
					    {
					    	var providerLogoStatic = "http://cms.placemniej.pl/images/stories/pzu.gif";
					    	this.staticResultList(response.price, response.averageRanking, response.rankingCount, response.rowId, response.purchaseUrl, this.getProviderPdf(response.providerId), providerLogoStatic);
						    
						    //important for sorting
						    $('providerPrice_' + response.rowId).value = response.price;
						    
						    $('info_' + response.providerId).style.display='block';
						    this.setTemplate4Details(response);
					    } 
				    	else
					    	if (response.providerId == 12)
						    {
						    	var providerLogoStatic = "http://cms.placemniej.pl/images/stories/axa.gif";
						    	this.staticResultList(response.price, response.averageRanking, response.rankingCount, response.rowId, response.purchaseUrl, this.getProviderPdf(response.providerId), providerLogoStatic);
							    
							    //important for sorting
							    $('providerPrice_' + response.rowId).value = response.price;
							    
							    $('info_' + response.providerId).style.display='block';
							    this.setTemplate4Details(response);
						    } 
				    	else
					    	if (response.providerId == 10)
						    {
						    	var providerLogoStatic = "http://cms.placemniej.pl/images/stories/alianzdirect.jpg";
						    	this.staticResultList(response.price, response.averageRanking, response.rankingCount, response.rowId, response.purchaseUrl, this.getProviderPdf(response.providerId), providerLogoStatic);
							    
							    //important for sorting
							    $('providerPrice_' + response.rowId).value = response.price;
							    
							    $('info_' + response.providerId).style.display='block';
							    this.setTemplate4Details(response);
						    } else
				    if (response.providerId == 3)
				    {
				    	
				    	if (response.price != parseInt('0') || response.price != parseFloat('0.0') || response.price != parseFloat('0.00')) 
				    	{
				    		this.createResultList(response.price, response.averageRanking, response.rankingCount, response.rowId, response.purchaseUrl, this.getProviderPdf(response.providerId));
				    		//this.commingSoonResultList(response.price, response.averageRanking, response.rankingCount, response.rowId, response.purchaseUrl, this.getProviderPdf(response.providerId));
				    	}
				    	
					    //important for sorting
					    $('providerPrice_' + response.rowId).value = response.price;
					    
					    $('info_' + response.providerId).style.display='block';
					    this.setTemplate4Details(response);
				    } 
				    else 
				    {
				    	if (response.price != parseInt('0') || response.price != parseFloat('0.0') || response.price != parseFloat('0.00')) 
				    	{
				    		this.createResultList(response.price, response.averageRanking, response.rankingCount, response.rowId, response.purchaseUrl, this.getProviderPdf(response.providerId));
				    	}
					    
					    //important for sorting
					    $('providerPrice_' + response.rowId).value = response.price;
					    
					    $('info_' + response.providerId).style.display='block';
					    this.setTemplate4Details(response);
				    } 
			    } 
			    else
			    {
			    	if (response.price != parseInt('0') || response.price != parseFloat('0.0') || response.price != parseFloat('0.00')) {
			    		this.rebuildResultRow(response.price, response.averageRanking, response.rankingCount, response.rowId, response.purchaseUrl, this.getProviderPdf(response.providerId));
			    	} else {
			    		//alert("price = 0");
			    		$('personalIdError').innerHTML=this.resultTxtProperties[12];
			    		setTimeout(function () {Effect.BlindUp($('resultListTable').firstChild);}, 4000);
			    		setTimeout(function () {$('resultListTable').removeChild($('resultListTable').firstChild);}, 5000);	    		
			    	}
			    
			    	if (this.personalId != -1) {
			    		this.personalIdInserted = true;
			    	}
			    	
			    	 //important for sorting
				    $('providerPrice_' + response.rowId).value = response.price;
			    	
			    	$('info_' + response.providerId).style.display='block';
			    	this.setTemplate4Details(response);
			    }
			   this.sortResults();
			   } catch (err) {
				//alert(err);
			} finally {
				this.returnedResponses += 1;
				if(this.returnedResponses >= this.carProviderIds.length){
					Effect.BlindUp($('ruler'));
				}
			}
		}
		//$('ajaxLoaderTinyTest').hide();
		//$('btnSubmit').disabled = "";
	},
	createResultList : function(price, ranking, count, id, url, providerPdf){
		//alert(this.carProviderIds[id] + ", " + ranking/10);
		//$('resultListTable').innerHTML = $('resultListTable').innerHTML
			var newRow =  '<div id=\"provider_' + id +'\" >'
				+ '<input type=\"hidden\" id=\"providerPrice_' + id +'\" value=\"\" />'
				+'<hr/>'
				+ '<table cellpadding=\"0\" cellspacing=\"0\">'
						+ '<tr id=\"row_' + id +'\" class=\"rowHeight\">'
							+ '<td class=\"logo\">'
								+ '<img src=\"' + this.providerLogoPath + this.carProviderIds[id] + this.providerLogoEnding + '\" alt=\"logo\" />'
							+ '</td>'
							+ '<td class=\"installments\">'
								+ '&nbsp;'
							+ '</td>'
							+ '<td class=\"ranking\">'
								+ '<div id=\"rater_' + this.carProviderIds[id] + '_' + id + '\" class=\"rater\"></div>'
								+ '<div id=\"rater_' + this.carProviderIds[id] + '_' + id + '_status\" class=\"raterStatus\">' + this.resultTxtProperties[4] + ':&nbsp;' + count + '&nbsp;' + this.resultTxtProperties[5] + '</div>'
//								+ '<script type=\"text/javascript\">'
//								+ 'new Rater($(\'rater_' + this.carProviderIds[id] + '_' + id + '\'), raterLayout.stars,{width:110,height:22,ratingto: function(obj, score){ extendedRater.updateRating4Provider(' + this.carProviderIds[id] + ',score); },fg:\"' + this.contextPath + '/images/star_over.gif\", bg:\"' + this.contextPath + '/images/star_empty.gif\", fg_rated:\"' + this.contextPath + '/images/star_over.gif\", reratable: false },' + ranking/10 + ');'
//								+ '</script>'
							+ '</td>'
							+ '<td class=\"price\" colspan=\"3\">'
								+ '<table cellpadding=\"0\" cellspacing=\"0\">'
									+ '<tr>'
										+ '<td class=\"price\">'
											+ '<div id=\"field2_' + id + '\" class=\"info\" align=\"center\">'
											+ this.formatNumber2Price(price)
											+ '&nbsp;'
											+ this.resultTxtProperties[6]
											+ '&nbsp;'
											+ '</div>'
										+ '</td>'
										+ '<td class=\"button\">'
											+ '<input type=\"submit\" id=\"forwardSubmit' + this.carProviderIds[id] + '\" name=\"forward\" style=\"display:none;\" />'
											+ '<a href=\"javascript:void(0)\" target=\"_blank\" class=\"btnResultPage\" onclick=\"click2Submit(\'formCarPage4\', \'' + this.contextPath + '\', \'' + this.resultTxtProperties[1] + '\', \''+ url + '\', \'' + this.carProviderIds[id] + '\', true, null, null, null); return false;\"></a>'
										+ '</td>'
									+ '</tr>'
									+ '<tr>'
										+ '<td class=\"details\">'
										+ '<div class=\"displayInl paddingTop2\" id=\"info_' + this.carProviderIds[id] + '\" onclick=\"offerDetails(\'details_' + this.carProviderIds[id] + '\')\" style=\"padding-top: 1px; text-align: center; display: none; cursor:help;\">'+ this.resultTxtProperties[11]+'</div>'
										+ '</td>'
										+ '<td class=\"gt\">'
											+ '<a href=\"' + providerPdf + '" target=\"_blank\">'
											+ this.resultTxtProperties[3]+ '&nbsp;'
											+ this.resultTxtProperties[7]
											+ '</a>'
										+ '</td>'
										
									+ '</tr>'
								+ '</table>'
							+ '</td>'
						+ '</tr>'
					+ '</table>'				
				+ '</div>';
		
			$('resultListTable').insert(newRow, content);	
		
		initializeRater(id, this.carProviderIds[id], ranking);
				
	},
	commingSoonResultList : function(price, ranking, count, id, url, providerPdf){
		//alert(this.carProviderIds[id] + ", " + ranking/10);
		//$('resultListTable').innerHTML = $('resultListTable').innerHTML
		var newRow =  '<div id=\"provider_' + id +'\" >'
		+ '<input type=\"hidden\" id=\"providerPrice_' + id +'\" value=\"\" />'
		+'<hr/>'
		+ '<table cellpadding=\"0\" cellspacing=\"0\">'
				+ '<tr id=\"row_' + id +'\" class=\"rowHeight\">'
					+ '<td class=\"logo\">'
						+ '<img src=\"' + this.providerLogoPath + this.carProviderIds[id] + this.providerLogoEnding + '\" alt=\"logo\" />'
					+ '</td>'
					+ '<td class=\"installments\">'
						+ '&nbsp;'
					+ '</td>'
					+ '<td class=\"ranking\">'
						+ '<div id=\"rater_' + this.carProviderIds[id] + '_' + id + '\" class=\"rater\"></div>'
						+ '<div id=\"rater_' + this.carProviderIds[id] + '_' + id + '_status\" class=\"raterStatus\">' + this.resultTxtProperties[4] + ':&nbsp;' + count + '&nbsp;' + this.resultTxtProperties[5] + '</div>'
//						+ '<script type=\"text/javascript\">'
//						+ 'new Rater($(\'rater_' + this.carProviderIds[id] + '_' + id + '\'), raterLayout.stars,{width:110,height:22,ratingto: function(obj, score){ extendedRater.updateRating4Provider(' + this.carProviderIds[id] + ',score); },fg:\"' + this.contextPath + '/images/star_over.gif\", bg:\"' + this.contextPath + '/images/star_empty.gif\", fg_rated:\"' + this.contextPath + '/images/star_over.gif\", reratable: false },' + ranking/10 + ');'
//						+ '</script>'
					+ '</td>'
					+ '<td class=\"price\" colspan=\"3\">'
						+ '<table cellpadding=\"0\" cellspacing=\"0\">'
							+ '<tr>'
								+ '<td class=\"price\">'
									+ '<div id=\"field2_' + id + '\" class=\"info\" align=\"center\">'
									+ this.formatNumber2Price(price)
									+ '&nbsp;'
									+ this.resultTxtProperties[6]
									+ '&nbsp;'
									+ '</div>'
								+ '</td>'
								+ '<td class=\"commingSoon\" rowspan=\"2\">'
								+ '<img src=\"images/comming_soon.jpg\" width=\"77px\" height=\"58px\" alt=\"Comming Soon\" />'+ '</td>'
							+ '</tr>'
							+ '<tr>'
							+ '<td class=\"details\">'
							+ '<div class=\"displayInl paddingTop2\" id=\"info_' + this.carProviderIds[id] + '\" onclick=\"offerDetails(\'details_' + this.carProviderIds[id] + '\')\" style=\"padding-top: 1px; text-align: center; display: none; cursor:help;\">'+ this.resultTxtProperties[11]+'</div>'
							+ '</td>'
							+ '</tr>'
						+ '</table>'
					+ '</td>'
				+ '</tr>'
			+ '</table>'				
		+ '</div>';
		
			$('resultListTable').insert(newRow, content);	
		
		initializeRater(id, this.carProviderIds[id], ranking);
				
	},
	staticResultList : function(price, ranking, count, id, url, providerPdf, providerLogoStatic){
		//alert(this.carProviderIds[id] + ", " + ranking/10);
		//$('resultListTable').innerHTML = $('resultListTable').innerHTML
		var newRow =  '<div id=\"provider_' + id +'\" >'
		+ '<input type=\"hidden\" id=\"providerPrice_' + id +'\" value=\"\" />'
		+'<hr/>'
		+ '<table cellpadding=\"0\" cellspacing=\"0\">'
				+ '<tr id=\"row_' + id +'\" class=\"rowHeight\">'
				+ '<td class=\"logo\">'
					+ '<img src=\"' + providerLogoStatic + '\" alt=\"logo\" />'
				+ '</td>'
					+ '<td class=\"installments\">'
						+ '&nbsp;'
					+ '</td>'
					+ '<td class=\"ranking\">'
						+ '<div id=\"rater_' + this.carProviderIds[id] + '_' + id + '\" class=\"rater\"></div>'
						+ '<div id=\"rater_' + this.carProviderIds[id] + '_' + id + '_status\" class=\"raterStatus\">' + this.resultTxtProperties[4] + ':&nbsp;' + count + '&nbsp;' + this.resultTxtProperties[5] + '</div>'
//						+ '<script type=\"text/javascript\">'
//						+ 'new Rater($(\'rater_' + this.carProviderIds[id] + '_' + id + '\'), raterLayout.stars,{width:110,height:22,ratingto: function(obj, score){ extendedRater.updateRating4Provider(' + this.carProviderIds[id] + ',score); },fg:\"' + this.contextPath + '/images/star_over.gif\", bg:\"' + this.contextPath + '/images/star_empty.gif\", fg_rated:\"' + this.contextPath + '/images/star_over.gif\", reratable: false },' + ranking/10 + ');'
//						+ '</script>'
					+ '</td>'
					+ '<td class=\"price\" colspan=\"3\">'
						+ '<table cellpadding=\"0\" cellspacing=\"0\">'
							+ '<tr>'
								+ '<td class=\"price\" rowspan=\"2\">'
									+ '<div id=\"field2_' + id + '\" class=\"info\" align=\"center\">'
										+ this.resultTxtProperties[0]
									+ '</div>'
								+ '</td>'
								+ '<td class=\"button\">'
									+ '<input type=\"submit\" id=\"forwardSubmit' + this.carProviderIds[id] + '\" name=\"forward\" style=\"display:none;\" />'
									+ '<a href=\"javascript:void(0)\" target=\"_blank\" class=\"btnResultPage\" onclick=\"click2Submit(\'formCarPage4\', \'' + this.contextPath + '\', \'' + this.resultTxtProperties[1] + '\', \''+ url + '\', \'' + this.carProviderIds[id] + '\', true, null, null, null); return false;\"></a>'
								+ '</td>'
							+ '</tr>'
							+ '<tr>'
								+ '<td class=\"gt\">'
									+ '<a href=\"' + providerPdf + '" target=\"_blank\">'
									+ this.resultTxtProperties[3]+ '&nbsp;'
									+ this.resultTxtProperties[7]
									+ '</a>'
								+ '</td>'
								
							+ '</tr>'
						+ '</table>'
					+ '</td>'
				+ '</tr>'
			+ '</table>'				
		+ '</div>';
		
			$('resultListTable').insert(newRow, content);	
		
		initializeRater(id, this.carProviderIds[id], ranking);
				
	},
	buildInputField : function(id){
		$('resultListTable').innerHTML = $('resultListTable').innerHTML 
				+ '<div id=\"provider_' + id +'\" >'
				+ '<input type=\"hidden\" id=\"providerPrice_' + id +'\" value=\"1000000000\" />'
				+'<hr/>'
				+ '<table cellpadding=\"0\" cellspacing=\"0\">'
					+ '<tr id=\"row_' + id +'\" class=\"rowHeight\">'
						+ '<td class=\"logo\">'
							+ '<img src=\"' + this.providerLogoPath + this.carProviderIds[id] + this.providerLogoEnding + '\" alt=\"logo\" />'
						+ '</td>'
						+ '<td id=\"loader\" class=\"installments\">'
							+ '&nbsp;'
						+ '</td>'
						+ '<td colspan=\"4\">'
						
						+ '<table cellpadding=\"0\" cellspacing=\"0\">'
							+ '<tr >'
								+ '<td colspan=\"3\" style=\"border-top-width: 0px;\">'
									+ '<div style=\"padding-bottom:5px;\">' + this.resultTxtProperties[8] + '</div>'
								+ '</td>'
							+ '</tr>'
							
							+ '<tr>'
								+ '<td style=\"border-top-width: 0px;\">'
										+ '<div style=\"width:100px;\"><input id=\"personalNumber\" type=\"text\" size="11" maxlength="11" value=""></div>'
								+ '</td>'
								+ '<td style=\"border-top-width: 0px;\">'
									+ '<div id=\"personalIdError\" class=\"validation-advice\">&nbsp;</div>'
								+ '</td>'
								+ '<td style=\"border-top-width: 0px;\">'
									+ '<div style=\"width:30px;\"><a href=\"javascript:void(0)\" class=\"btnResultPageSend\" onclick=\"resultPage.sendPersonalId();\"></a></div>'
								+ '</td>'
							+ '</tr>'
						+ '</table>'								
							+ '</td>'
					+ '</tr>'
				+ '</table>'	
				+ '</div>';
		this.returnedResponses += 1;
		
	},
	rebuildResultRow : function(price, ranking, count, id, url, providerPdf){
		var newInnerHtml =  
			'<input type=\"hidden\" id=\"providerPrice_' + id +'\" value=\"\" />'
			+'<hr/>'
			+ '<table cellpadding=\"0\" cellspacing=\"0\">'
				+ '<tr id=\"row_' + id +'\" class=\"rowHeight\">'
					+ '<td class=\"logo\">'
						+ '<img src=\"' + this.providerLogoPath + this.carProviderIds[id] + this.providerLogoEnding + '\" alt=\"logo\" />'
					+ '</td>'
					+ '<td class=\"installments\">'
						+ '&nbsp;'
					+ '</td>'
					+ '<td class=\"ranking\">'
						+ '<div id=\"rater_' + this.carProviderIds[id] + '_' + id + '\" class=\"rater\"></div>'
						+ '<div id=\"rater_' + this.carProviderIds[id] + '_' + id + '_status\" class=\"raterStatus\">' + this.resultTxtProperties[4] + ':&nbsp;' + count + '&nbsp;' + this.resultTxtProperties[5] + '</div>'
						+ '<script type=\"text/javascript\">'
						+ 'new Rater($(\'rater_' + this.carProviderIds[id] + '_' + id + '\'), raterLayout.stars,{width:110,height:22,ratingto: function(obj, score){ extendedRater.updateRating4Provider(' + this.carProviderIds[id] + ',score); },fg:\"' + this.contextPath + '/images/star_over.gif\", bg:\"' + this.contextPath + '/images/star_empty.gif\", fg_rated:\"' + this.contextPath + '/images/star_over.gif\", reratable: false },' + ranking/10 + ');'
						+ '</script>'
					+ '</td>'
					+ '<td class=\"price\" colspan=\"3\">'
					+ '<table cellpadding=\"0\" cellspacing=\"0\">'
						+ '<tr>'
							+ '<td class=\"price\">'
								+ '<div id=\"field2_' + id + '\" class=\"info\" align=\"center\">'
								+ this.formatNumber2Price(price)
								+ '&nbsp;'
								+ this.resultTxtProperties[6]
								+ '&nbsp;'
								+ '</div>'
							+ '</td>'
							+ '<td class=\"button\">'
								+ '<input type=\"submit\" id=\"forwardSubmit' + this.carProviderIds[id] + '\" name=\"forward\" style=\"display:none;\" />'
								+ '<a href=\"javascript:void(0)\" target=\"_blank\" class=\"btnResultPage\" onclick=\"click2Submit(\'formCarPage4\', \'' + this.contextPath + '\', \'' + this.resultTxtProperties[1] + '\', \''+ url + '\', \'' + this.carProviderIds[id] + '\', true, null, null, null); return false;\"></a>'
							+ '</td>'
						+ '</tr>'
						+ '<tr>'
						+ '<td class=\"details\">'
						+ '<div class=\"displayInl paddingTop2\" id=\"info_' + this.carProviderIds[id] + '\" onclick=\"offerDetails(\'details_' + this.carProviderIds[id] + '\')\" style=\"padding-top: 1px; text-align: center; display: none; cursor:help;\">'+ this.resultTxtProperties[11]+'</div>'
						+ '</td>'
							+ '<td class=\"gt\">'
								+ '<a href=\"' + providerPdf + '" target=\"_blank\">'
								+ this.resultTxtProperties[3]+ '&nbsp;'
								+ this.resultTxtProperties[7]
								+ '</a>'
							+ '</td>'
						+ '</tr>'
					+ '</table>'
				+ '</td>'
				+ '</tr>'
			+ '</table>';
			
		$('provider_' + id).innerHTML = newInnerHtml;
		
		initializeRater(id, this.carProviderIds[id], ranking);

	},
	sendPersonalId : function() {
		if (!this.personalIdInserted && /^[0-9]{11}$/.test($('personalNumber').value)) {
			$('personalIdError').innerHTML='&nbsp;';
			$('loader').className = 'installmentsLoader';
			this.personalId = $('personalNumber').value;
			this.sendAjaxRequest(this.mbankProviderId, this.mbankRowId, this.personalId, this.instalments);
		} else {
			$('personalIdError').innerHTML=this.resultTxtProperties[9];
		} 
	},
	setTemplate4Details : function(response){
		$('details_' + response.providerId).innerHTML = '&nbsp;';
		
		// prepare the template DIVs
		if (response.searchProfile.owner.previousInsurerOc != 'brak') {
			$('ownerOcNotOnlyBrak').style.display='block';
		} else {
			$('ownerOcNotOnlyBrak').style.display='none';
		}
		
		if (response.searchProfile.fullKasko) {
			$('caseFullKasko').style.display='block';
			$('ownerAcExisting').style.display='block';
			$('uniqaAcOver').style.display='none';
			$('uniqaWarning').style.display='none'; 
			if (response.searchProfile.owner.previousInsurerAc != 'brak') {
				$('ownerAcNotOnlyBrak').style.display='block';
			}
			if (response.providerId == 3)
			{
				if(!response.searchProfile.car.newCar)
				{
					$('uniqaWarning').style.display='block'; 
					$('uniqaAcOver').style.display='none';
					$('mBankSource').style.display='none';
					$('mBankPurpose').style.display='none';
					$('mBankAge').style.display='none';
					$('mBankValueTooHigh').style.display='none';
				}
			}
				
		} 
		else {
			if (response.providerId == 6){
				$('uniqaAcOver').style.display='none';
				$('uniqaWarning').style.display='none';
				if(response.searchProfile.insuranceSumAc > parseFloat(150000)) 
				{ 
					$('mBankValueTooHigh').style.display='block'; 
					}
				else if(response.searchProfile.carAge > parseInt('10')) 
				{ 	
					$('mBankAge').style.display='block'; 
				}
				else if(response.searchProfile.car.carPurposeId != parseInt('1')) 
				{ 	
					$('mBankPurpose').style.display='block'; 
					}
				else if(response.searchProfile.car.vehicleSourceId == parseInt('3') || response.searchProfile.car.vehicleSourceId == parseInt('4')) 
				{ 
					$('mBankSource').style.display='block'; 
					}
			} 
			else 
			{
			if (response.providerId == 3)
				{
					$('uniqaAcOver').style.display='none'; 
					//alert(response.searchProfile.isuranceAcOver);
							if(response.searchProfile.isuranceAcOver) 
								{ 
									$('uniqaAcOver').style.display='block'; 
									$('mBankSource').style.display='none';
									$('mBankPurpose').style.display='none';
									$('mBankAge').style.display='none';
									$('mBankValueTooHigh').style.display='none'; 
								}
					}
			}
			
			$('caseFullKasko').style.display='none';
			$('ownerAcExisting').style.display='none';
			$('ownerAcNotOnlyBrak').style.display='none';
		}
		if (response.providerId == 6) {
			$('caseProviderId6').style.display='block';
			$('caseProviderIdOtherwise').style.display='none';
		} else {
			$('caseProviderIdOtherwise').style.display='block';
			$('caseProviderId6').style.display='none';
		}
		if (response.searchProfile.deductible) {
			$('deductible').style.display='block';
		} else {
			$('deductible').style.display='none';
		}
		if (response.searchProfile.coveredForDepreciation) {
			$('coveredForDepreciation').style.display='block';
		} else {
			$('coveredForDepreciation').style.display='none';
		}
		if (response.searchProfile.liability) {
			$('liability').style.display='block';
			$('ownerNnwExisting').style.display='block';
		} else {
			$('liability').style.display='none';
			$('ownerNnwExisting').style.display='none';
		}
		if (response.searchProfile.assistance) {
			$('assistance').style.display='block';
		} else {
			$('assistance').style.display='none';
		}
		if (response.searchProfile.pop) {
			$('pop').style.display='block';
			$('ownerPopNotOnlyBrak').style.display='block';
		} else {
			$('pop').style.display='none';
			$('ownerPopNotOnlyBrak').style.display='none';
		}
		if (response.searchProfile.kglass) {
			$('kglass').style.display='block';
		} else {
			$('kglass').style.display='none';
		}
		if (response.searchProfile.coOwnerExisting) {
			$('coOwnerExisting').style.display='block';
			$('coOwnerExisting2').style.display='block';
			if (response.searchProfile.coOwner.previousInsurerOc != 'brak') {
				$('coOwnerOcNotOnlyBrak').style.display='block';
			} 
			if (response.searchProfile.fullKasko) {
				$('coOwnerAcExisting').style.display='block';
				if (response.searchProfile.coOwner.previousInsurerAc != 'brak') {
					$('coOwnerAcNotOnlyBrak').style.display='block';
				}
			}
		} else {
			$('coOwnerExisting').style.display='none';
			$('coOwnerExisting2').style.display='none';
			$('coOwnerOcNotOnlyBrak').style.display='none';
			$('coOwnerAcExisting').style.display='none';
			$('coOwnerAcNotOnlyBrak').style.display='none';
		}
		
		if (response.searchProfile.youngestOtherDriverExisting) {
			//$('youngestOtherDriverExisting').style.display='block';
		} else {
			//$('youngestOtherDriverExisting').style.display='none';
		}
		
		// copy template and fill the content
		var container = $('detailsTemplate').innerHTML;
		container = container.replace('#car_provider_id#', response.providerId);
		container = container.replace('#response.price#',this.formatNumber2Price(response.price));
		container = container.replace('#response.searchProfile.startOfInsuranceFormat#',response.searchProfile.startOfInsuranceFormat);
		container = container.replace('#response.searchProfile.instalments#',response.searchProfile.instalments);
		container = container.replace('#response.searchProfile.endOfInsuranceFormat#',response.searchProfile.endOfInsuranceFormat);
		if (response.searchProfile.partlyKasko) {
			container = container.replace('#response.searchProfile.partlyKasko#', '<img src="images/blocks/small/checked.jpg" alt="tak" />');
		} else {
			container = container.replace('#response.searchProfile.partlyKasko#', '<img src="images/blocks/small/not_checked.jpg" alt="nie" />');
		}
		if (response.searchProfile.fullKasko) {
			container = container.replace('#response.searchProfile.fullKasko#', '<img src="images/blocks/small/checked.jpg" alt="tak" />');
			container = container.replace('#response.searchProfile.getStartOfInsurance#',response.searchProfile.startOfInsuranceFormat);
			
			//container = container.replace('<div id="caseFullKasko" style="display: none;">', '<div id="caseFullKasko" style="display: block;">');
			container = container.replace('#response.searchProfile.insuranceSumAdditionalEquip#',response.searchProfile.insuranceSumAdditionalEquip);
			container = container.replace('#response.searchProfile.owner.typeAc#',response.searchProfile.owner.typeAc);
			
			if (response.providerId == 6) {
				//container = container.replace('<div id="caseProviderId6" style="display: none;">', '<div id="caseProviderId6" style="display: block;">');
				container = container.replace('#response.searchProfile.insuranceSumAc#', response.searchProfile.insuranceSumAc);
			} else {
				//container = container.replace('<div id="caseProviderIdOtherwise" style="display: none;">', '<div id="caseProviderIdOtherwise" style="display: block;">');
				container = container.replace('#response.searchProfile.insuranceSumAc2#', response.searchProfile.insuranceSumAc);
			}
			if (response.searchProfile.deductible) {
				container = container.replace('#response.searchProfile.deductible#', '<img src="images/blocks/small/ico_confirm.png" alt="tak" />');
				//container = container.replace('<div id="deductible" style="display: none;">','<div id="deductible" style="display: block;">');
				container = container.replace('#response.searchProfile.owner.ownParticipation#',response.searchProfile.owner.ownParticipation);
			} else {
				container = container.replace('#response.searchProfile.deductible#', '<img src="images/blocks/small/ico_error.png" alt="nie" />');
			}
			if (response.searchProfile.coveredForDepreciation) {
				container = container.replace('#response.searchProfile.coveredForDepreciation#', '<img src="images/blocks/small/ico_confirm.png" alt="tak" />');
				//container = container.replace('<div id="coveredForDepreciation" style="display: none;">','<div id="coveredForDepreciation" style="display: block;">');
				container = container.replace('#response.searchProfile.owner.yearsOfDepreciation#',response.searchProfile.owner.yearsOfDepreciation);
			} else {
				container = container.replace('#response.searchProfile.coveredForDepreciation#', '<img src="images/blocks/small/ico_error.png" alt="nie" />');
			}
			if (response.searchProfile.decreaseInsuranceSum) {
				container = container.replace('#response.searchProfile.owner.decreaseInsuranceSum#', '<img src="images/blocks/small/ico_confirm.png" alt="tak" />');
			} else {
				container = container.replace('#response.searchProfile.owner.decreaseInsuranceSum#', '<img src="images/blocks/small/ico_error.png" alt="nie" />');
			}
			
		} else {
			container = container.replace('#response.searchProfile.fullKasko#', '<img src="images/blocks/small/not_checked.jpg" alt="nie" />');
		}
		
		if (response.searchProfile.liability) {
			container = container.replace('#response.searchProfile.liability#', '<img src="images/blocks/small/checked.jpg" alt="tak" />');
			//container = container.replace('<div id="liability" style="display: none;">','<div id="liability" style="display: block;">');
			container = container.replace('#response.searchProfile.costOfInsuranceNnw#',response.searchProfile.costOfInsuranceNnw);
		} else {
			container = container.replace('#response.searchProfile.liability#', '<img src="images/blocks/small/not_checked.jpg" alt="nie" />');
		}
		
		if (response.searchProfile.assistance) 
		{
			container = container.replace('#response.searchProfile.assistance#', '<img src="images/blocks/small/checked.jpg" alt="tak" />');

			if (response.providerId == 3 || response.providerId == 9) 
			{
				container = container.replace('#response.searchProfile.owner.assistanceInsuranceType#',response.searchProfile.customAssistanceType);
			}
			else
			{
				//container = container.replace('<div id="assistance" style="display: none;">','<div id="assistance" style="display: block;">');
				container = container.replace('#response.searchProfile.owner.assistanceInsuranceType#',response.searchProfile.owner.assistanceInsuranceType);
			}
		} 
		else 
		{
			container = container.replace('#response.searchProfile.assistance#', '<img src="images/blocks/small/not_checked.jpg" alt="nie" />');
		}
	
		if (response.searchProfile.miniAssistance) {
			container = container.replace('#response.searchProfile.miniAssistance#', '<img src="images/blocks/small/checked.jpg" alt="tak" />');
		} else {
			container = container.replace('#response.searchProfile.miniAssistance#', '<img src="images/blocks/small/not_checked.jpg" alt="nie" />');
		}

		if (response.searchProfile.pop) {
			container = container.replace('#response.searchProfile.pop#', '<img src="images/blocks/small/checked.jpg" alt="tak" />');
			//container = container.replace('<div id="pop" style="display: none;">','<div id="pop" style="display: block;">');
			container = container.replace('#response.searchProfile.insuranceSumPop#',response.searchProfile.insuranceSumPop);
			container = container.replace('#response.searchProfile.owner.legalProtection#',response.searchProfile.owner.legalProtection);
			
			if (response.searchProfile.owner.ownShareInDamages) {
				container = container.replace('#response.searchProfile.owner.ownShareInDamages#', '<img src="images/blocks/small/ico_confirm.png" alt="tak" />');
			} else {
				container = container.replace('#response.searchProfile.owner.ownShareInDamages#', '<img src="images/blocks/small/ico_error.png" alt="nie" />');
			}

			container = container.replace('#response.searchProfile.owner.previousInsurerPOP#',response.searchProfile.owner.previousInsurerPOP);			
			container = container.replace('#response.searchProfile.owner.numbersOfPoliciesWithoutDamagesPop#',response.searchProfile.owner.numbersOfPoliciesWithoutDamagesPop);
			container = container.replace('#response.searchProfile.owner.numbersOfDamagesCoveredPop#',response.searchProfile.owner.numbersOfDamagesCoveredPop);
		} else {
			container = container.replace('#response.searchProfile.pop#', '<img src="images/blocks/small/not_checked.jpg" alt="nie" />');
		}
		
		if (response.searchProfile.kglass) {
			container = container.replace('#response.searchProfile.kglass#', '<img src="images/blocks/small/checked.jpg" alt="tak" />');
			//container = container.replace('<div id="kglass" style="display: none;">','<div id="kglass" style="display: block;">');
			container = container.replace('#response.searchProfile.insuranceSumKglass#',response.searchProfile.insuranceSumKglass);
		} else {
			container = container.replace('#response.searchProfile.kglass#', '<img src="images/blocks/small/not_checked.jpg" alt="nie" />');
		}
		
		container = container.replace('#response.searchProfile.car.vehicleVendorName#',response.searchProfile.car.vehicleVendorName);
		container = container.replace('#response.searchProfile.car.vehicleModelName#',response.searchProfile.car.vehicleModelName);
		container = container.replace('#response.searchProfile.car.vehicleSizeOfEngine#',response.searchProfile.car.vehicleSizeOfEngine);
		container = container.replace('#response.searchProfile.car.customNumberOfSeats#',response.searchProfile.car.customNumberOfSeats);
		container = container.replace('#response.searchProfile.car.vehicleHorsepower#',response.searchProfile.car.vehicleHorsepower);
		container = container.replace('#response.searchProfile.car.vehicleNumberOfDoors#',response.searchProfile.car.vehicleNumberOfDoors);
		container = container.replace('#response.searchProfile.car.carType#',response.searchProfile.car.carType);
		container = container.replace('#response.searchProfile.car.carPurpose#',response.searchProfile.car.carPurpose);
		container = container.replace('#response.searchProfile.car.vehicleSource#',response.searchProfile.car.vehicleSource);
		container = container.replace('#response.searchProfile.car.mileage#',response.searchProfile.car.mileage);
		container = container.replace('#response.searchProfile.car.forecastMileage#',response.searchProfile.car.forecastMileage);
		container = container.replace('#response.searchProfile.car.productionYear#',response.searchProfile.car.productionYear);
		container = container.replace('#response.searchProfile.car.saleYear#',response.searchProfile.car.saleYear);
		container = container.replace('#response.searchProfile.car.firstRegistrationFormat#',response.searchProfile.car.firstRegistrationFormat);
		if (response.searchProfile.car.newCar) {
			container = container.replace('#response.searchProfile.car.newCar#', '<img src="images/blocks/small/ico_confirm.png" alt="tak"/>');
		} else {
			container = container.replace('#response.searchProfile.car.newCar#', '<img src="images/blocks/small/ico_error.png" alt="nie" />');
		}
		if (response.searchProfile.car.techRevision) {
			container = container.replace('#response.searchProfile.car.techRevision#', '<img src="images/blocks/small/ico_confirm.png" alt="tak" style="padding-top:3px;" />');
		} else {
			container = container.replace('#response.searchProfile.car.techRevision#', '<img src="images/blocks/small/ico_error.png" alt="nie" style="padding-top:3px;" />');
		}
		container = container.replace('#response.searchProfile.owner.zip#',response.searchProfile.owner.zip);
		container = container.replace('#response.searchProfile.owner.district#',response.searchProfile.owner.district);
		container = container.replace('#response.searchProfile.owner.borough#',response.searchProfile.owner.borough);
		container = container.replace('#response.searchProfile.owner.federalState#',response.searchProfile.owner.federalState);
		container = container.replace('#response.searchProfile.owner.birthdayFormat#',response.searchProfile.owner.birthdayFormat);
		container = container.replace('#response.searchProfile.owner.gender#',response.searchProfile.owner.gender);
		container = container.replace('#response.searchProfile.owner.maritalStatus#',response.searchProfile.owner.maritalStatus);
		container = container.replace('#response.searchProfile.owner.driverLicenseFormat#',response.searchProfile.owner.driverLicenseFormat);
		
		if (response.searchProfile.coOwnerExisting) {
			container = container.replace('#response.searchProfile.coOwnerExisting#', '<img src="images/blocks/small/ico_confirm.png" alt="tak" style="padding-top:3px;" />');
			//container = container.replace('<div id="coOwnerExisting" style="display: none;">','<div id="coOwnerExisting" style="display: block;">');
			container = container.replace('#response.searchProfile.coOwner.birthdayFormat#',response.searchProfile.coOwner.birthdayFormat);
			container = container.replace('#response.searchProfile.coOwner.gender#',response.searchProfile.coOwner.gender);
			container = container.replace('#response.searchProfile.coOwner.zip#',response.searchProfile.coOwner.zip);
			container = container.replace('#response.searchProfile.coOwner.borough#',response.searchProfile.coOwner.borough);
			container = container.replace('#response.searchProfile.coOwner.district#',response.searchProfile.coOwner.district);
			container = container.replace('#response.searchProfile.coOwner.federalState#',response.searchProfile.coOwner.federalState);
			container = container.replace('#response.searchProfile.coOwner.driverLicenseFormat#',response.searchProfile.coOwner.driverLicenseFormat);
		} else {
			container = container.replace('#response.searchProfile.coOwnerExisting#', '<img src="images/blocks/small/ico_error.png" alt="nie" style="padding-top:3px;" />');
		}

		if (response.searchProfile.youngestOtherDriverExisting) {
			container = container.replace('#response.searchProfile.youngestOtherDriverExisting#', '<img src="images/blocks/small/ico_confirm.png" alt="tak" style="padding-top:3px;" />');
			
//			if (response.searchProfile.youngestOtherDriverUnder26) {
//				container = container.replace('#response.searchProfile.youngestOtherDriverUnder26#', '<img src="images/blocks/small/ico_confirm.png" alt="tak" style="padding-top:3px;" />');
//			} else {
//				container = container.replace('#response.searchProfile.youngestOtherDriverUnder26#', '<img src="images/blocks/small/ico_error.png" alt="nie" style="padding-top:3px;" />');
//			}
		} else {
			container = container.replace('#response.searchProfile.youngestOtherDriverExisting#', '<img src="images/blocks/small/ico_error.png" alt="nie" style="padding-top:3px;" />');
		}

		container = container.replace('#response.searchProfile.owner.previousInsurerOc#',response.searchProfile.owner.previousInsurerOc);
		container = container.replace('#response.searchProfile.owner.yearsWithoutAccidentsOc#',response.searchProfile.owner.yearsWithoutAccidentsOc);
		container = container.replace('#response.searchProfile.owner.discountOrRiseOcStringValue#',response.searchProfile.owner.discountOrRiseOcStringValue);
		container = container.replace('#response.searchProfile.owner.numbersOfPoliciesWithoutDamagesOc#',response.searchProfile.owner.numbersOfPoliciesWithoutDamagesOc);
		container = container.replace('#response.searchProfile.owner.accidentsLastYearOc#',response.searchProfile.owner.accidentsLastYearOc);
		container = container.replace('#response.searchProfile.owner.previousInsurerAc#',response.searchProfile.owner.previousInsurerAc);
		container = container.replace('#response.searchProfile.owner.yearsWithoutAccidentsAc#',response.searchProfile.owner.yearsWithoutAccidentsAc);
		container = container.replace('#response.searchProfile.owner.discountOrRiseAcStringValue#',response.searchProfile.owner.discountOrRiseAcStringValue);
		container = container.replace('#response.searchProfile.owner.numbersOfPoliciesWithoutDamagesAc#',response.searchProfile.owner.numbersOfPoliciesWithoutDamagesAc);
		container = container.replace('#response.searchProfile.owner.accidentsLastYearAc#',response.searchProfile.owner.accidentsLastYearAc);
		container = container.replace('#response.searchProfile.owner.accidentsLastYearNnw#',response.searchProfile.owner.accidentsLastYearNnw);
		
		if (response.searchProfile.coOwnerExisting) {
			//container = container.replace('<div id="coOwnerExisting2" style="display: none;">','<div id="coOwnerExisting2" style="display: block;">');
			container = container.replace('#response.searchProfile.coOwner.previousInsurerOc#',response.searchProfile.coOwner.previousInsurerOc);
			container = container.replace('#response.searchProfile.coOwner.yearsWithoutAccidentsOc#',response.searchProfile.coOwner.yearsWithoutAccidentsOc);
			container = container.replace('#response.searchProfile.coOwner.discountOrRiseOcStringValue#',response.searchProfile.coOwner.discountOrRiseOcStringValue);
			container = container.replace('#response.searchProfile.coOwner.accidentsLastYearOc#',response.searchProfile.coOwner.accidentsLastYearOc);
			container = container.replace('#response.searchProfile.coOwner.previousInsurerAc#',response.searchProfile.coOwner.previousInsurerAc);
			container = container.replace('#response.searchProfile.coOwner.yearsWithoutAccidentsAc#',response.searchProfile.coOwner.yearsWithoutAccidentsAc);
			container = container.replace('#response.searchProfile.coOwner.discountOrRiseAcStringValue#',response.searchProfile.coOwner.discountOrRiseAcStringValue);
			container = container.replace('#response.searchProfile.coOwner.accidentsLastYearAc#',response.searchProfile.coOwner.accidentsLastYearAc);
		}
		
		$('details_' + response.providerId).innerHTML = container;
		
		
	},
	getProviderPdf : function(carProviderId) {
		if (carProviderId == 1) {
			return this.contextPath + "/downloads/benefia24.pdf";
		}
		if (carProviderId == 2) {
			return this.contextPath + "/downloads/generali.pdf";
		}
		if (carProviderId == 3) {
			return this.contextPath + "/downloads/uniqa.pdf";
		}
		if (carProviderId == 4) {
			return this.contextPath + "/downloads/aviva.pdf";
		}
		if (carProviderId == 6) {
			return this.contextPath + "/downloads/mbank.pdf";
		}
		if (carProviderId == 7) {
			return this.contextPath + "/downloads/PZU.pdf";
		}
		if (carProviderId == 8) {
			return this.contextPath + "/downloads/LD.pdf";
		}
		if (carProviderId == 9) {
			return this.contextPath + "/downloads/HDI.pdf";
		}
		if (carProviderId == 10) {
			return this.contextPath + "/downloads/AD.pdf";
		}
		if (carProviderId == 11) {
			return this.contextPath + "/downloads/PZU.pdf";
		}
		if (carProviderId == 12) {
			return this.contextPath + "/downloads/axa.pdf";
		}
		return "";
	},
	formatNumber2Price : function(number){ 
		var price = number.toFixed(2);
		var price = price.toString();
		var price = price.replace('.', ',');
		return price;		
	},
	swap : function(element1, element2) {
		
		if(element1 && element2) { //nodes found
			var parent = element1.parentNode;

			if (parent.lastChild == element2) {
				var nextOfElement1 = element1.nextSibling;
				parent.appendChild(element1);
				parent.insertBefore(element2, nextOfElement1);
			} else {
				var nextOfElement1 = element1.nextSibling;
				var nextOfElement2 = element2.nextSibling;
				parent.insertBefore(element1, nextOfElement2);
				parent.insertBefore(element2, nextOfElement1);
			}
		}
			
	},
	sortResults : function(){
		var parent = $('resultListTable');
		
		for (var i = 0; i < parent.childElements().length; i++) {
			for (var j = i; j < parent.childElements().length; j++) {
				if(parent.childElements()[i].childElements()[0].value != "" && parent.childElements()[j].childElements()[0].value != "" && 
				   parseFloat(parent.childElements()[i].childElements()[0].value) > parseFloat(parent.childElements()[j].childElements()[0].value)){
					this.swap(parent.childElements()[i], parent.childElements()[j]);
				}	
			}
		}
		
	}
});

Car.ResultpageExtended = Class.create({
	
	initialize: function(contextPath, carProviderIds, carSearchProfileId, resultTxtProperties, providerLogoPath, providerLogoEnding){
		this.totalCosts = new Array();
		this.contextPath = contextPath;
		this.carProviderIds = carProviderIds;
		this.carSearchProfileId = carSearchProfileId;
		this.resultTxtProperties = resultTxtProperties;
		this.providerLogoPath = providerLogoPath;
		this.providerLogoEnding = providerLogoEnding;
		this.preloadResultList();
		//this.extendedRater = new ExtendedRater();
		
	},
	changeTotalCost4Offer: function(){
		
	},
	addCost: function(cost){
		this.totalCosts[this.totalCosts.length] = cost;
	},
	getCost: function(elementId,index){
//		alert($(index.id).selectedIndex);
		var priceElement = 'price_' + elementId;
		$(priceElement).innerHTML = this.totalCosts[$(index.id).selectedIndex];
	},
	preloadResultList: function(){
		
		this.returnedResponses = 0;
		this.mbankProviderId;
		this.mbankRowId;
		this.personalId = -1;
		this.instalments = 1;
		this.personalIdInserted = false;
		
		$('installments_id').selectedIndex = 0;
		
		for (var i=0; i < this.carProviderIds.length; i++){
			if (this.carProviderIds[i] == 6) {
				this.buildInputField(i);
				this.mbankProviderId = 6;
				this.mbankRowId = i;
			} else {
				this.sendAjaxRequest(this.carProviderIds[i],i,this.personalId,this.instalments);
			}
		}
	},
	changeRate : function(instalments) {
		
		$('resultListTable').innerHTML = '&nbsp;';
		Effect.BlindDown($('ruler'));
		
		this.returnedResponses = 0;
		this.instalments = $(instalments).value;
		
		for (var i=0; i < this.carProviderIds.length; i++){
			if (this.carProviderIds[i] == 6 && this.personalId == -1) {
				this.buildInputField(i);
				this.mbankProviderId = carProviderIds[i];
				this.mbankRowId = i;
			} else {
				this.sendAjaxRequest(this.carProviderIds[i],i,this.personalId,this.instalments);
			}
		}
	},
	sendAjaxRequest : function(providerId, id, personalId, instalments) {
		var url = this.contextPath + "/service/insuranceOffer?providerId=" + providerId + '&carSearchProfileId=' + this.carSearchProfileId + '&rowId=' + id + '&personalId=' + personalId + '&instalments=' + instalments;
		new Ajax.Request(url, {
			method: 'post',
			parameters: url,
			onSuccess: this.showAjaxResponse.bind(this),
			onLoading: function(){      
		},
		onFailure: function(){
			this.returnedResponses += 1;
			if(this.returnedResponses >= this.carProviderIds.length){
				Effect.BlindUp($('ruler'));
			}
//			$('ajaxLoaderTinyTest').hide();
		}
		});
	},
	showAjaxResponse : function(transport) { 
		//$('ajaxLoaderTinyTest').hide();
		if (transport.responseText=="NO_SUCH_RESULT" || transport.responseText=="AN_ERROR_OCCURED"){
			//$('errorZipTest').appear();   
		} else {   
			try 
			{
			    var response = transport.responseText.evalJSON();   
			    if (response.providerId != 6 || this.personalIdInserted) 
			    {
				    if (response.providerId == 4) 
				    {
		    			var providerLogoStatic = "http://cms.placemniej.pl/images/stories/car_provider_aviva.jpg";
			    	    this.staticResultList(response.price, response.averageRanking, response.rankingCount, response.rowId, response.purchaseUrl, this.getProviderPdf(response.providerId), providerLogoStatic, response.searchProfile.insType);
					    
					    //important for sorting
					    $('providerPrice_' + response.rowId).value = response.price;
					    
					    $('info_' + response.providerId).style.display='block';
					    this.setTemplate4Details(response);
				    
				    } else
				    if (response.providerId == 8)
				    {
				    	var providerLogoStatic = "http://cms.placemniej.pl/images/stories/liberty direct.gif";
				    	this.staticResultList(response.price, response.averageRanking, response.rankingCount, response.rowId, response.purchaseUrl, this.getProviderPdf(response.providerId), providerLogoStatic, response.searchProfile.insType);
					    
					    //important for sorting
					    $('providerPrice_' + response.rowId).value = response.price;
					    
					    $('info_' + response.providerId).style.display='block';
					    this.setTemplate4Details(response);
				    } else
				    	if (response.providerId == 11)
					    {
					    	var providerLogoStatic = "http://cms.placemniej.pl/images/stories/pzu.gif";
					    	this.staticResultList(response.price, response.averageRanking, response.rankingCount, response.rowId, response.purchaseUrl, this.getProviderPdf(response.providerId), providerLogoStatic, response.searchProfile.insType);
						    
						    //important for sorting
						    $('providerPrice_' + response.rowId).value = response.price;
						    
						    $('info_' + response.providerId).style.display='block';
						    this.setTemplate4Details(response);
					    } else
					    	if (response.providerId == 10)
						    {
						    	var providerLogoStatic = "http://cms.placemniej.pl/images/stories/alianzdirect.jpg";
						    	this.staticResultList(response.price, response.averageRanking, response.rankingCount, response.rowId, response.purchaseUrl, this.getProviderPdf(response.providerId), providerLogoStatic, response.searchProfile.insType);
							    
							    //important for sorting
							    $('providerPrice_' + response.rowId).value = response.price;
							    
							    $('info_' + response.providerId).style.display='block';
							    this.setTemplate4Details(response);
						    } else
						    	if (response.providerId == 12)
							    {
							    	var providerLogoStatic = "http://cms.placemniej.pl/images/stories/axa.gif";
							    	this.staticResultList(response.price, response.averageRanking, response.rankingCount, response.rowId, response.purchaseUrl, this.getProviderPdf(response.providerId), providerLogoStatic, response.searchProfile.insType);
								    
								    //important for sorting
								    $('providerPrice_' + response.rowId).value = response.price;
								    
								    $('info_' + response.providerId).style.display='block';
								    this.setTemplate4Details(response);
							    }
			     else
					if (response.providerId == 13)
				{
					var providerLogoStatic = "http://cms.placemniej.pl/images/stories/link4.gif";
					this.staticResultList(response.price, response.averageRanking, response.rankingCount, response.rowId, response.purchaseUrl, this.getProviderPdf(response.providerId), providerLogoStatic, response.searchProfile.insType);
	    
					//important for sorting
					$('providerPrice_' + response.rowId).value = response.price;
	    
					$('info_' + response.providerId).style.display='block';
					this.setTemplate4Details(response);
				}
					    	else
						    	if (response.providerId == 3)
						    		{
						    		if (response.price != parseInt('0') || response.price != parseFloat('0.0') || response.price != parseFloat('0.00')) 
						    		{
				    		this.createResultList(response.price, response.averageRanking, response.rankingCount, response.rowId, response.purchaseUrl, this.getProviderPdf(response.providerId), response.searchProfile.insType);
				    		//this.commingSoonResultList(response.price, response.averageRanking, response.rankingCount, response.rowId, response.purchaseUrl, this.getProviderPdf(response.providerId), response.searchProfile.insType);
				    	}
				    	
					    //important for sorting
					    $('providerPrice_' + response.rowId).value = response.price;
					    
					    $('info_' + response.providerId).style.display='block';
					    this.setTemplate4Details(response);
				    } 
				    else 
				    {
				    	if (response.price != parseInt('0') || response.price != parseFloat('0.0') || response.price != parseFloat('0.00')) 
				    	{
				    		this.createResultList(response.price, response.averageRanking, response.rankingCount, response.rowId, response.purchaseUrl, this.getProviderPdf(response.providerId), response.searchProfile.insType);
				    	}
					    
					    //important for sorting
					    $('providerPrice_' + response.rowId).value = response.price;
					    
					    $('info_' + response.providerId).style.display='block';
					    this.setTemplate4Details(response);
				    } 
			    } 
			    else
			    {
			    	if (response.price != parseInt('0') || response.price != parseFloat('0.0') || response.price != parseFloat('0.00')) {
			    		this.rebuildResultRow(response.price, response.averageRanking, response.rankingCount, response.rowId, response.purchaseUrl, this.getProviderPdf(response.providerId), response.searchProfile.insType);
			    	} else {
			    		//alert("price = 0");
			    		$('personalIdError').innerHTML=this.resultTxtProperties[12];
			    		setTimeout(function () {Effect.BlindUp($('resultListTable').firstChild);}, 4000);
			    		setTimeout(function () {$('resultListTable').removeChild($('resultListTable').firstChild);}, 5000);	    		
			    	}
			    
			    	if (this.personalId != -1) {
			    		this.personalIdInserted = true;
			    	}
			    	
			    	 //important for sorting
				    $('providerPrice_' + response.rowId).value = response.price;
			    	
			    	$('info_' + response.providerId).style.display='block';
			    	this.setTemplate4Details(response);
			    }
			   this.sortResults();
			   } catch (err) {
				//alert(err);
			} finally {
				this.returnedResponses += 1;
				if(this.returnedResponses >= this.carProviderIds.length){
					Effect.BlindUp($('ruler'));
				}
			}
		}
		//$('ajaxLoaderTinyTest').hide();
		//$('btnSubmit').disabled = "";
	},
	createResultList : function(price, ranking, count, id, url, providerPdf, insType){
		//alert(this.carProviderIds[id] + ", " + ranking/10);
		//$('resultListTable').innerHTML = $('resultListTable').innerHTML
			var newRow =  '<div id=\"provider_' + id +'\" >'
				+ '<input type=\"hidden\" id=\"providerPrice_' + id +'\" value=\"\" />'
				+'<hr/>'
				+ '<table cellpadding=\"0\" cellspacing=\"0\">'
						+ '<tr id=\"row_' + id +'\" class=\"rowHeight\">'
							+ '<td class=\"logo\">'
								+ '<img src=\"' + this.providerLogoPath + this.carProviderIds[id] + this.providerLogoEnding + '\" alt=\"logo\" />'
							+ '</td>'
							+ '<td class=\"installments\">'
								+ '&nbsp;'
							+ '</td>'
							+ '<td class=\"ranking\">'
								+ '<div id=\"rater_' + this.carProviderIds[id] + '_' + id + '\" class=\"rater\"></div>'
								+ '<div id=\"rater_' + this.carProviderIds[id] + '_' + id + '_status\" class=\"raterStatus\">' + this.resultTxtProperties[4] + ':&nbsp;' + count + '&nbsp;' + this.resultTxtProperties[5] + '</div>'
//								+ '<script type=\"text/javascript\">'
//								+ 'new Rater($(\'rater_' + this.carProviderIds[id] + '_' + id + '\'), raterLayout.stars,{width:110,height:22,ratingto: function(obj, score){ extendedRater.updateRating4Provider(' + this.carProviderIds[id] + ',score); },fg:\"' + this.contextPath + '/images/star_over.gif\", bg:\"' + this.contextPath + '/images/star_empty.gif\", fg_rated:\"' + this.contextPath + '/images/star_over.gif\", reratable: false },' + ranking/10 + ');'
//								+ '</script>'
							+ '</td>'
							+ '<td class=\"type\">'
							+ insType
							+ '</td>'
							+ '<td class=\"price\" colspan=\"3\">'
								+ '<table cellpadding=\"0\" cellspacing=\"0\">'
									+ '<tr>'
										+ '<td class=\"price\">'
											+ '<div id=\"field2_' + id + '\" class=\"info\" align=\"center\">'
											+ this.formatNumber2Price(price)
											+ '&nbsp;'
											+ this.resultTxtProperties[6]
											+ '&nbsp;'
											+ '</div>'
										+ '</td>'
										+ '<td class=\"button\">'
											+ '<input type=\"submit\" id=\"forwardSubmit' + this.carProviderIds[id] + '\" name=\"forward\" style=\"display:none;\" />'
											+ '<a href=\"javascript:void(0)\" target=\"_blank\" class=\"btnResultPage\" onclick=\"click2Submit(\'formCarPage4\', \'' + this.contextPath + '\', \'' + this.resultTxtProperties[1] + '\', \''+ url + '\', \'' + this.carProviderIds[id] + '\', true, null, null, null); return false;\"></a>'
										+ '</td>'
									+ '</tr>'
									+ '<tr>'
										+ '<td class=\"details\">'
										+ '<div class=\"displayInl paddingTop2\" id=\"info_' + this.carProviderIds[id] + '\" onclick=\"offerDetails(\'details_' + this.carProviderIds[id] + '\')\" style=\"padding-top: 1px; text-align: center; display: none; cursor:help;\">'+ this.resultTxtProperties[11]+'</div>'
										+ '</td>'
										+ '<td class=\"gt\">'
											+ '<a href=\"' + providerPdf + '" target=\"_blank\">'
											+ this.resultTxtProperties[3]+ '&nbsp;'
											+ this.resultTxtProperties[7]
											+ '</a>'
										+ '</td>'
									+ '</tr>'
								+ '</table>'
							+ '</td>'
						+ '</tr>'
					+ '</table>'				
				+ '</div>';
		
			$('resultListTable').insert(newRow, content);	
		
		initializeRater(id, this.carProviderIds[id], ranking);
				
	},
	commingSoonResultList : function(price, ranking, count, id, url, providerPdf, insType){
		//alert(this.carProviderIds[id] + ", " + ranking/10);
		//$('resultListTable').innerHTML = $('resultListTable').innerHTML
		var newRow =  '<div id=\"provider_' + id +'\" >'
		+ '<input type=\"hidden\" id=\"providerPrice_' + id +'\" value=\"\" />'
		+'<hr/>'
		+ '<table cellpadding=\"0\" cellspacing=\"0\">'
				+ '<tr id=\"row_' + id +'\" class=\"rowHeight\">'
					+ '<td class=\"logo\">'
						+ '<img src=\"' + this.providerLogoPath + this.carProviderIds[id] + this.providerLogoEnding + '\" alt=\"logo\" />'
					+ '</td>'
					+ '<td class=\"installments\">'
						+ '&nbsp;'
					+ '</td>'
					+ '<td class=\"ranking\">'
						+ '<div id=\"rater_' + this.carProviderIds[id] + '_' + id + '\" class=\"rater\"></div>'
						+ '<div id=\"rater_' + this.carProviderIds[id] + '_' + id + '_status\" class=\"raterStatus\">' + this.resultTxtProperties[4] + ':&nbsp;' + count + '&nbsp;' + this.resultTxtProperties[5] + '</div>'
//						+ '<script type=\"text/javascript\">'
//						+ 'new Rater($(\'rater_' + this.carProviderIds[id] + '_' + id + '\'), raterLayout.stars,{width:110,height:22,ratingto: function(obj, score){ extendedRater.updateRating4Provider(' + this.carProviderIds[id] + ',score); },fg:\"' + this.contextPath + '/images/star_over.gif\", bg:\"' + this.contextPath + '/images/star_empty.gif\", fg_rated:\"' + this.contextPath + '/images/star_over.gif\", reratable: false },' + ranking/10 + ');'
//						+ '</script>'
					+ '</td>'
					+ '<td class=\"type\">'
					+ insType
					+ '</td>'
					+ '<td class=\"price\" colspan=\"3\">'
						+ '<table cellpadding=\"0\" cellspacing=\"0\">'
							+ '<tr>'
								+ '<td class=\"price\">'
									+ '<div id=\"field2_' + id + '\" class=\"info\" align=\"center\">'
									+ this.formatNumber2Price(price)
									+ '&nbsp;'
									+ this.resultTxtProperties[6]
									+ '&nbsp;'
									+ '</div>'
								+ '</td>'
								+ '<td class=\"commingSoon\" rowspan=\"2\">'
								+ '<img src=\"images/comming_soon.jpg\" width=\"77px\" height=\"58px\" alt=\"Comming Soon\" />'+ '</td>'
							+ '</tr>'
							+ '<tr>'
							+ '<td class=\"details\">'
							+ '<div class=\"displayInl paddingTop2\" id=\"info_' + this.carProviderIds[id] + '\" onclick=\"offerDetails(\'details_' + this.carProviderIds[id] + '\')\" style=\"padding-top: 1px; text-align: center; display: none; cursor:help;\">'+ this.resultTxtProperties[11]+'</div>'
							+ '</td>'
							+ '</tr>'
						+ '</table>'
					+ '</td>'
				+ '</tr>'
			+ '</table>'				
		+ '</div>';
		
			$('resultListTable').insert(newRow, content);	
		
		initializeRater(id, this.carProviderIds[id], ranking);
				
	},
	staticResultList : function(price, ranking, count, id, url, providerPdf, providerLogoStatic, insType){
		//alert(this.carProviderIds[id] + ", " + ranking/10);
		//$('resultListTable').innerHTML = $('resultListTable').innerHTML
		var newRow =  '<div id=\"provider_' + id +'\" >'
		+ '<input type=\"hidden\" id=\"providerPrice_' + id +'\" value=\"\" />'
		+'<hr/>'
		+ '<table cellpadding=\"0\" cellspacing=\"0\">'
				+ '<tr id=\"row_' + id +'\" class=\"rowHeight\">'
				+ '<td class=\"logo\">'
					+ '<img src=\"' + providerLogoStatic + '\" alt=\"logo\" />'
				+ '</td>'
					+ '<td class=\"installments\">'
						+ '&nbsp;'
					+ '</td>'
					+ '<td class=\"ranking\">'
						+ '<div id=\"rater_' + this.carProviderIds[id] + '_' + id + '\" class=\"rater\"></div>'
						+ '<div id=\"rater_' + this.carProviderIds[id] + '_' + id + '_status\" class=\"raterStatus\">' + this.resultTxtProperties[4] + ':&nbsp;' + count + '&nbsp;' + this.resultTxtProperties[5] + '</div>'
//						+ '<script type=\"text/javascript\">'
//						+ 'new Rater($(\'rater_' + this.carProviderIds[id] + '_' + id + '\'), raterLayout.stars,{width:110,height:22,ratingto: function(obj, score){ extendedRater.updateRating4Provider(' + this.carProviderIds[id] + ',score); },fg:\"' + this.contextPath + '/images/star_over.gif\", bg:\"' + this.contextPath + '/images/star_empty.gif\", fg_rated:\"' + this.contextPath + '/images/star_over.gif\", reratable: false },' + ranking/10 + ');'
//						+ '</script>'
					+ '</td>'
					+ '<td class=\"type\">'
					+ insType
					+ '</td>'
					+ '<td class=\"price\" colspan=\"3\">'
						+ '<table cellpadding=\"0\" cellspacing=\"0\">'
							+ '<tr>'
								+ '<td class=\"price\" rowspan=\"2\">'
									+ '<div id=\"field2_' + id + '\" class=\"info\" align=\"center\">'
										+ this.resultTxtProperties[0]
									+ '</div>'
								+ '</td>'
								+ '<td class=\"button\">'
									+ '<input type=\"submit\" id=\"forwardSubmit' + this.carProviderIds[id] + '\" name=\"forward\" style=\"display:none;\" />'
									+ '<a href=\"javascript:void(0)\" target=\"_blank\" class=\"btnResultPage\" onclick=\"click2Submit(\'formCarPage4\', \'' + this.contextPath + '\', \'' + this.resultTxtProperties[1] + '\', \''+ url + '\', \'' + this.carProviderIds[id] + '\', true, null, null, null); return false;\"></a>'
								+ '</td>'
							+ '</tr>'
							+ '<tr>'
								+ '<td class=\"gt\">'
									+ '<a href=\"' + providerPdf + '" target=\"_blank\">'
									+ this.resultTxtProperties[3]+ '&nbsp;'
									+ this.resultTxtProperties[7]
									+ '</a>'
								+ '</td>'
							+ '</tr>'
						+ '</table>'
					+ '</td>'
				+ '</tr>'
			+ '</table>'				
		+ '</div>';
		
			$('resultListTable').insert(newRow, content);	
		
		initializeRater(id, this.carProviderIds[id], ranking);
				
	},
	buildInputField : function(id){
		$('resultListTable').innerHTML = $('resultListTable').innerHTML 
				+ '<div id=\"provider_' + id +'\" >'
				+ '<input type=\"hidden\" id=\"providerPrice_' + id +'\" value=\"1000000000\" />'
				+'<hr/>'
				+ '<table cellpadding=\"0\" cellspacing=\"0\">'
					+ '<tr id=\"row_' + id +'\" class=\"rowHeight\">'
						+ '<td class=\"logo\">'
							+ '<img src=\"' + this.providerLogoPath + this.carProviderIds[id] + this.providerLogoEnding + '\" alt=\"logo\" />'
						+ '</td>'
						+ '<td id=\"loader\" class=\"installments\">'
							+ '&nbsp;'
						+ '</td>'
						+ '<td colspan=\"4\">'
						+ '<table cellpadding=\"0\" cellspacing=\"0\">'
							+ '<tr >'
								+ '<td colspan=\"3\" style=\"border-top-width: 0px;\">'
									+ '<div style=\"padding-bottom:5px;\">' + this.resultTxtProperties[8] + '</div>'
								+ '</td>'
							+ '</tr>'
							+ '<tr>'
								+ '<td style=\"border-top-width: 0px;\">'
										+ '<div style=\"width:100px;\"><input id=\"personalNumber\" type=\"text\" size="11" maxlength="11" value=""></div>'
								+ '</td>'
								+ '<td style=\"border-top-width: 0px;\">'
									+ '<div id=\"personalIdError\" class=\"validation-advice\">&nbsp;</div>'
								+ '</td>'
								+ '<td style=\"border-top-width: 0px;\">'
									+ '<div style=\"width:30px;\"><a href=\"javascript:void(0)\" class=\"btnResultPageSend\" onclick=\"resultPage.sendPersonalId();\"></a></div>'
								+ '</td>'
							+ '</tr>'
						+ '</table>'								
							+ '</td>'
					+ '</tr>'
				+ '</table>'	
				+ '</div>';
		this.returnedResponses += 1;
		
	},
	rebuildResultRow : function(price, ranking, count, id, url, providerPdf, insType){
		var newInnerHtml =  
			'<input type=\"hidden\" id=\"providerPrice_' + id +'\" value=\"\" />'
			+'<hr/>'
			+ '<table cellpadding=\"0\" cellspacing=\"0\">'
				+ '<tr id=\"row_' + id +'\" class=\"rowHeight\">'
					+ '<td class=\"logo\">'
						+ '<img src=\"' + this.providerLogoPath + this.carProviderIds[id] + this.providerLogoEnding + '\" alt=\"logo\" />'
					+ '</td>'
					+ '<td class=\"installments\">'
						+ '&nbsp;'
					+ '</td>'
					+ '<td class=\"ranking\">'
						+ '<div id=\"rater_' + this.carProviderIds[id] + '_' + id + '\" class=\"rater\"></div>'
						+ '<div id=\"rater_' + this.carProviderIds[id] + '_' + id + '_status\" class=\"raterStatus\">' + this.resultTxtProperties[4] + ':&nbsp;' + count + '&nbsp;' + this.resultTxtProperties[5] + '</div>'
						+ '<script type=\"text/javascript\">'
						+ 'new Rater($(\'rater_' + this.carProviderIds[id] + '_' + id + '\'), raterLayout.stars,{width:110,height:22,ratingto: function(obj, score){ extendedRater.updateRating4Provider(' + this.carProviderIds[id] + ',score); },fg:\"' + this.contextPath + '/images/star_over.gif\", bg:\"' + this.contextPath + '/images/star_empty.gif\", fg_rated:\"' + this.contextPath + '/images/star_over.gif\", reratable: false },' + ranking/10 + ');'
						+ '</script>'
					+ '</td>'
					+ '<td class=\"type\">'
					+ insType
					+ '</td>'
					+ '<td class=\"price\" colspan=\"3\">'
					+ '<table cellpadding=\"0\" cellspacing=\"0\">'
						+ '<tr>'
							+ '<td class=\"price\">'
								+ '<div id=\"field2_' + id + '\" class=\"info\" align=\"center\">'
								+ this.formatNumber2Price(price)
								+ '&nbsp;'
								+ this.resultTxtProperties[6]
								+ '&nbsp;'
								+ '</div>'
							+ '</td>'
							+ '<td class=\"button\">'
								+ '<input type=\"submit\" id=\"forwardSubmit' + this.carProviderIds[id] + '\" name=\"forward\" style=\"display:none;\" />'
								+ '<a href=\"javascript:void(0)\" target=\"_blank\" class=\"btnResultPage\" onclick=\"click2Submit(\'formCarPage4\', \'' + this.contextPath + '\', \'' + this.resultTxtProperties[1] + '\', \''+ url + '\', \'' + this.carProviderIds[id] + '\', true, null, null, null); return false;\"></a>'
							+ '</td>'
						+ '</tr>'
						+ '<tr>'
						+ '<td class=\"details\">'
						+ '<div class=\"displayInl paddingTop2\" id=\"info_' + this.carProviderIds[id] + '\" onclick=\"offerDetails(\'details_' + this.carProviderIds[id] + '\')\" style=\"padding-top: 1px; text-align: center; display: none; cursor:help;\">'+ this.resultTxtProperties[11]+'</div>'
						+ '</td>'
							+ '<td class=\"gt\">'
								+ '<a href=\"' + providerPdf + '" target=\"_blank\">'
								+ this.resultTxtProperties[3]+ '&nbsp;'
								+ this.resultTxtProperties[7]
								+ '</a>'
							+ '</td>'
						+ '</tr>'
					+ '</table>'
				+ '</td>'
				+ '</tr>'
			+ '</table>';
			
		$('provider_' + id).innerHTML = newInnerHtml;
		
		initializeRater(id, this.carProviderIds[id], ranking);

	},
	sendPersonalId : function() {
		if (!this.personalIdInserted && /^[0-9]{11}$/.test($('personalNumber').value)) {
			$('personalIdError').innerHTML='&nbsp;';
			$('loader').className = 'installmentsLoader';
			this.personalId = $('personalNumber').value;
			this.sendAjaxRequest(this.mbankProviderId, this.mbankRowId, this.personalId, this.instalments);
		} else {
			$('personalIdError').innerHTML=this.resultTxtProperties[9];
		} 
	},
	setTemplate4Details : function(response){
		$('details_' + response.providerId).innerHTML = '&nbsp;';
		
		// prepare the template DIVs
		if (response.searchProfile.owner.previousInsurerOc != 'brak') {
			$('ownerOcNotOnlyBrak').style.display='block';
		} else {
			$('ownerOcNotOnlyBrak').style.display='none';
		}
		
		if (response.searchProfile.fullKasko) {
			$('caseFullKasko').style.display='block';
			$('ownerAcExisting').style.display='block';
			$('uniqaAcOver').style.display='none';
			$('uniqaWarning').style.display='none'; 
			if (response.searchProfile.owner.previousInsurerAc != 'brak') {
				$('ownerAcNotOnlyBrak').style.display='block';
			}
			if (response.providerId == 3)
			{
				if(!response.searchProfile.car.newCar)
				{
					$('uniqaWarning').style.display='block'; 
					$('uniqaAcOver').style.display='none';
					$('mBankSource').style.display='none';
					$('mBankPurpose').style.display='none';
					$('mBankAge').style.display='none';
					$('mBankValueTooHigh').style.display='none';
				}
			}
				
		} 
		else {
			if (response.providerId == 6){
				$('uniqaAcOver').style.display='none';
				$('uniqaWarning').style.display='none';
				if(response.searchProfile.insuranceSumAc > parseFloat(150000)) 
				{ 
					$('mBankValueTooHigh').style.display='block'; 
					}
				else if(response.searchProfile.carAge > parseInt('10')) 
				{ 	
					$('mBankAge').style.display='block'; 
				}
				else if(response.searchProfile.car.carPurposeId != parseInt('1')) 
				{ 	
					$('mBankPurpose').style.display='block'; 
					}
				else if(response.searchProfile.car.vehicleSourceId == parseInt('3') || response.searchProfile.car.vehicleSourceId == parseInt('4')) 
				{ 
					$('mBankSource').style.display='block'; 
					}
			} 
			else 
			{
			if (response.providerId == 3)
				{
					$('uniqaAcOver').style.display='none'; 
					//alert(response.searchProfile.isuranceAcOver);
							if(response.searchProfile.isuranceAcOver) 
								{ 
									$('uniqaAcOver').style.display='block'; 
									$('mBankSource').style.display='none';
									$('mBankPurpose').style.display='none';
									$('mBankAge').style.display='none';
									$('mBankValueTooHigh').style.display='none'; 
								}
					}
			}
			
			$('caseFullKasko').style.display='none';
			$('ownerAcExisting').style.display='none';
			$('ownerAcNotOnlyBrak').style.display='none';
		}
		if (response.providerId == 6) {
			$('caseProviderId6').style.display='block';
			$('caseProviderIdOtherwise').style.display='none';
		} else {
			$('caseProviderIdOtherwise').style.display='block';
			$('caseProviderId6').style.display='none';
		}
		if (response.searchProfile.deductible) {
			$('deductible').style.display='block';
		} else {
			$('deductible').style.display='none';
		}
		if (response.searchProfile.coveredForDepreciation) {
			$('coveredForDepreciation').style.display='block';
		} else {
			$('coveredForDepreciation').style.display='none';
		}
		if (response.searchProfile.liability) {
			$('liability').style.display='block';
			$('ownerNnwExisting').style.display='block';
		} else {
			$('liability').style.display='none';
			$('ownerNnwExisting').style.display='none';
		}
		if (response.searchProfile.assistance) {
			$('assistance').style.display='block';
		} else {
			$('assistance').style.display='none';
		}
		if (response.searchProfile.pop) {
			$('pop').style.display='block';
			$('ownerPopNotOnlyBrak').style.display='block';
		} else {
			$('pop').style.display='none';
			$('ownerPopNotOnlyBrak').style.display='none';
		}
		if (response.searchProfile.kglass) {
			$('kglass').style.display='block';
		} else {
			$('kglass').style.display='none';
		}
		if (response.searchProfile.coOwnerExisting) {
			$('coOwnerExisting').style.display='block';
			$('coOwnerExisting2').style.display='block';
			if (response.searchProfile.coOwner.previousInsurerOc != 'brak') {
				$('coOwnerOcNotOnlyBrak').style.display='block';
			} 
			if (response.searchProfile.fullKasko) {
				$('coOwnerAcExisting').style.display='block';
				if (response.searchProfile.coOwner.previousInsurerAc != 'brak') {
					$('coOwnerAcNotOnlyBrak').style.display='block';
				}
			}
		} else {
			$('coOwnerExisting').style.display='none';
			$('coOwnerExisting2').style.display='none';
			$('coOwnerOcNotOnlyBrak').style.display='none';
			$('coOwnerAcExisting').style.display='none';
			$('coOwnerAcNotOnlyBrak').style.display='none';
		}
		
		if (response.searchProfile.youngestOtherDriverExisting) {
			//$('youngestOtherDriverExisting').style.display='block';
		} else {
			//$('youngestOtherDriverExisting').style.display='none';
		}
		
		// copy template and fill the content
		var container = $('detailsTemplate').innerHTML;
		container = container.replace('#car_provider_id#', response.providerId);
		container = container.replace('#response.price#',this.formatNumber2Price(response.price));
		container = container.replace('#response.searchProfile.startOfInsuranceFormat#',response.searchProfile.startOfInsuranceFormat);
		container = container.replace('#response.searchProfile.instalments#',response.searchProfile.instalments);
		container = container.replace('#response.searchProfile.endOfInsuranceFormat#',response.searchProfile.endOfInsuranceFormat);
		if (response.searchProfile.partlyKasko) {
			container = container.replace('#response.searchProfile.partlyKasko#', '<img src="images/blocks/small/checked.jpg" alt="tak" />');
		} else {
			container = container.replace('#response.searchProfile.partlyKasko#', '<img src="images/blocks/small/not_checked.jpg" alt="nie" />');
		}
		if (response.searchProfile.fullKasko) {
			container = container.replace('#response.searchProfile.fullKasko#', '<img src="images/blocks/small/checked.jpg" alt="tak" />');
			container = container.replace('#response.searchProfile.getStartOfInsurance#',response.searchProfile.startOfInsuranceFormat);
			
			//container = container.replace('<div id="caseFullKasko" style="display: none;">', '<div id="caseFullKasko" style="display: block;">');
			container = container.replace('#response.searchProfile.insuranceSumAdditionalEquip#',response.searchProfile.insuranceSumAdditionalEquip);
			container = container.replace('#response.searchProfile.owner.typeAc#',response.searchProfile.owner.typeAc);
			
			if (response.providerId == 6) {
				//container = container.replace('<div id="caseProviderId6" style="display: none;">', '<div id="caseProviderId6" style="display: block;">');
				container = container.replace('#response.searchProfile.insuranceSumAc#', response.searchProfile.insuranceSumAc);
			} else {
				//container = container.replace('<div id="caseProviderIdOtherwise" style="display: none;">', '<div id="caseProviderIdOtherwise" style="display: block;">');
				container = container.replace('#response.searchProfile.insuranceSumAc2#', response.searchProfile.insuranceSumAc);
			}
			if (response.searchProfile.deductible) {
				container = container.replace('#response.searchProfile.deductible#', '<img src="images/blocks/small/ico_confirm.png" alt="tak" />');
				//container = container.replace('<div id="deductible" style="display: none;">','<div id="deductible" style="display: block;">');
				container = container.replace('#response.searchProfile.owner.ownParticipation#',response.searchProfile.owner.ownParticipation);
			} else {
				container = container.replace('#response.searchProfile.deductible#', '<img src="images/blocks/small/ico_error.png" alt="nie" />');
			}
			if (response.searchProfile.coveredForDepreciation) {
				container = container.replace('#response.searchProfile.coveredForDepreciation#', '<img src="images/blocks/small/ico_confirm.png" alt="tak" />');
				//container = container.replace('<div id="coveredForDepreciation" style="display: none;">','<div id="coveredForDepreciation" style="display: block;">');
				container = container.replace('#response.searchProfile.owner.yearsOfDepreciation#',response.searchProfile.owner.yearsOfDepreciation);
			} else {
				container = container.replace('#response.searchProfile.coveredForDepreciation#', '<img src="images/blocks/small/ico_error.png" alt="nie" />');
			}
			if (response.searchProfile.decreaseInsuranceSum) {
				container = container.replace('#response.searchProfile.owner.decreaseInsuranceSum#', '<img src="images/blocks/small/ico_confirm.png" alt="tak" />');
			} else {
				container = container.replace('#response.searchProfile.owner.decreaseInsuranceSum#', '<img src="images/blocks/small/ico_error.png" alt="nie" />');
			}
			
		} else {
			container = container.replace('#response.searchProfile.fullKasko#', '<img src="images/blocks/small/not_checked.jpg" alt="nie" />');
		}
		
		if (response.searchProfile.liability) {
			container = container.replace('#response.searchProfile.liability#', '<img src="images/blocks/small/checked.jpg" alt="tak" />');
			//container = container.replace('<div id="liability" style="display: none;">','<div id="liability" style="display: block;">');
			container = container.replace('#response.searchProfile.costOfInsuranceNnw#',response.searchProfile.costOfInsuranceNnw);
		} else {
			container = container.replace('#response.searchProfile.liability#', '<img src="images/blocks/small/not_checked.jpg" alt="nie" />');
		}
		
		if (response.searchProfile.assistance) 
		{
			container = container.replace('#response.searchProfile.assistance#', '<img src="images/blocks/small/checked.jpg" alt="tak" />');

			if (response.providerId == 3 || response.providerId == 9) 
			{
				container = container.replace('#response.searchProfile.owner.assistanceInsuranceType#',response.searchProfile.customAssistanceType);
			}
			else
			{
				//container = container.replace('<div id="assistance" style="display: none;">','<div id="assistance" style="display: block;">');
				container = container.replace('#response.searchProfile.owner.assistanceInsuranceType#',response.searchProfile.owner.assistanceInsuranceType);
			}
		} 
		else 
		{
			container = container.replace('#response.searchProfile.assistance#', '<img src="images/blocks/small/not_checked.jpg" alt="nie" />');
		}
	
		if (response.searchProfile.miniAssistance) {
			container = container.replace('#response.searchProfile.miniAssistance#', '<img src="images/blocks/small/checked.jpg" alt="tak" />');
		} else {
			container = container.replace('#response.searchProfile.miniAssistance#', '<img src="images/blocks/small/not_checked.jpg" alt="nie" />');
		}

		if (response.searchProfile.pop) {
			container = container.replace('#response.searchProfile.pop#', '<img src="images/blocks/small/checked.jpg" alt="tak" />');
			//container = container.replace('<div id="pop" style="display: none;">','<div id="pop" style="display: block;">');
			container = container.replace('#response.searchProfile.insuranceSumPop#',response.searchProfile.insuranceSumPop);
			container = container.replace('#response.searchProfile.owner.legalProtection#',response.searchProfile.owner.legalProtection);
			
			if (response.searchProfile.owner.ownShareInDamages) {
				container = container.replace('#response.searchProfile.owner.ownShareInDamages#', '<img src="images/blocks/small/ico_confirm.png" alt="tak" />');
			} else {
				container = container.replace('#response.searchProfile.owner.ownShareInDamages#', '<img src="images/blocks/small/ico_error.png" alt="nie" />');
			}

			container = container.replace('#response.searchProfile.owner.previousInsurerPOP#',response.searchProfile.owner.previousInsurerPOP);			
			container = container.replace('#response.searchProfile.owner.numbersOfPoliciesWithoutDamagesPop#',response.searchProfile.owner.numbersOfPoliciesWithoutDamagesPop);
			container = container.replace('#response.searchProfile.owner.numbersOfDamagesCoveredPop#',response.searchProfile.owner.numbersOfDamagesCoveredPop);
		} else {
			container = container.replace('#response.searchProfile.pop#', '<img src="images/blocks/small/not_checked.jpg" alt="nie" />');
		}
		
		if (response.searchProfile.kglass) {
			container = container.replace('#response.searchProfile.kglass#', '<img src="images/blocks/small/checked.jpg" alt="tak" />');
			//container = container.replace('<div id="kglass" style="display: none;">','<div id="kglass" style="display: block;">');
			container = container.replace('#response.searchProfile.insuranceSumKglass#',response.searchProfile.insuranceSumKglass);
		} else {
			container = container.replace('#response.searchProfile.kglass#', '<img src="images/blocks/small/not_checked.jpg" alt="nie" />');
		}
		
		container = container.replace('#response.searchProfile.car.vehicleVendorName#',response.searchProfile.car.vehicleVendorName);
		container = container.replace('#response.searchProfile.car.vehicleModelName#',response.searchProfile.car.vehicleModelName);
		container = container.replace('#response.searchProfile.car.vehicleSizeOfEngine#',response.searchProfile.car.vehicleSizeOfEngine);
		container = container.replace('#response.searchProfile.car.customNumberOfSeats#',response.searchProfile.car.customNumberOfSeats);
		container = container.replace('#response.searchProfile.car.vehicleHorsepower#',response.searchProfile.car.vehicleHorsepower);
		container = container.replace('#response.searchProfile.car.vehicleNumberOfDoors#',response.searchProfile.car.vehicleNumberOfDoors);
		container = container.replace('#response.searchProfile.car.carType#',response.searchProfile.car.carType);
		container = container.replace('#response.searchProfile.car.carPurpose#',response.searchProfile.car.carPurpose);
		container = container.replace('#response.searchProfile.car.vehicleSource#',response.searchProfile.car.vehicleSource);
		container = container.replace('#response.searchProfile.car.mileage#',response.searchProfile.car.mileage);
		container = container.replace('#response.searchProfile.car.forecastMileage#',response.searchProfile.car.forecastMileage);
		container = container.replace('#response.searchProfile.car.productionYear#',response.searchProfile.car.productionYear);
		container = container.replace('#response.searchProfile.car.saleYear#',response.searchProfile.car.saleYear);
		container = container.replace('#response.searchProfile.car.firstRegistrationFormat#',response.searchProfile.car.firstRegistrationFormat);
		if (response.searchProfile.car.newCar) {
			container = container.replace('#response.searchProfile.car.newCar#', '<img src="images/blocks/small/ico_confirm.png" alt="tak"/>');
		} else {
			container = container.replace('#response.searchProfile.car.newCar#', '<img src="images/blocks/small/ico_error.png" alt="nie" />');
		}
		if (response.searchProfile.car.techRevision) {
			container = container.replace('#response.searchProfile.car.techRevision#', '<img src="images/blocks/small/ico_confirm.png" alt="tak" style="padding-top:3px;" />');
		} else {
			container = container.replace('#response.searchProfile.car.techRevision#', '<img src="images/blocks/small/ico_error.png" alt="nie" style="padding-top:3px;" />');
		}
		container = container.replace('#response.searchProfile.owner.zip#',response.searchProfile.owner.zip);
		container = container.replace('#response.searchProfile.owner.district#',response.searchProfile.owner.district);
		container = container.replace('#response.searchProfile.owner.borough#',response.searchProfile.owner.borough);
		container = container.replace('#response.searchProfile.owner.federalState#',response.searchProfile.owner.federalState);
		container = container.replace('#response.searchProfile.owner.birthdayFormat#',response.searchProfile.owner.birthdayFormat);
		container = container.replace('#response.searchProfile.owner.gender#',response.searchProfile.owner.gender);
		container = container.replace('#response.searchProfile.owner.maritalStatus#',response.searchProfile.owner.maritalStatus);
		container = container.replace('#response.searchProfile.owner.driverLicenseFormat#',response.searchProfile.owner.driverLicenseFormat);
		
		if (response.searchProfile.coOwnerExisting) {
			container = container.replace('#response.searchProfile.coOwnerExisting#', '<img src="images/blocks/small/ico_confirm.png" alt="tak" style="padding-top:3px;" />');
			//container = container.replace('<div id="coOwnerExisting" style="display: none;">','<div id="coOwnerExisting" style="display: block;">');
			container = container.replace('#response.searchProfile.coOwner.birthdayFormat#',response.searchProfile.coOwner.birthdayFormat);
			container = container.replace('#response.searchProfile.coOwner.gender#',response.searchProfile.coOwner.gender);
			container = container.replace('#response.searchProfile.coOwner.zip#',response.searchProfile.coOwner.zip);
			container = container.replace('#response.searchProfile.coOwner.borough#',response.searchProfile.coOwner.borough);
			container = container.replace('#response.searchProfile.coOwner.district#',response.searchProfile.coOwner.district);
			container = container.replace('#response.searchProfile.coOwner.federalState#',response.searchProfile.coOwner.federalState);
			container = container.replace('#response.searchProfile.coOwner.driverLicenseFormat#',response.searchProfile.coOwner.driverLicenseFormat);
		} else {
			container = container.replace('#response.searchProfile.coOwnerExisting#', '<img src="images/blocks/small/ico_error.png" alt="nie" style="padding-top:3px;" />');
		}

		if (response.searchProfile.youngestOtherDriverExisting) {
			container = container.replace('#response.searchProfile.youngestOtherDriverExisting#', '<img src="images/blocks/small/ico_confirm.png" alt="tak" style="padding-top:3px;" />');
			
//			if (response.searchProfile.youngestOtherDriverUnder26) {
//				container = container.replace('#response.searchProfile.youngestOtherDriverUnder26#', '<img src="images/blocks/small/ico_confirm.png" alt="tak" style="padding-top:3px;" />');
//			} else {
//				container = container.replace('#response.searchProfile.youngestOtherDriverUnder26#', '<img src="images/blocks/small/ico_error.png" alt="nie" style="padding-top:3px;" />');
//			}
		} else {
			container = container.replace('#response.searchProfile.youngestOtherDriverExisting#', '<img src="images/blocks/small/ico_error.png" alt="nie" style="padding-top:3px;" />');
		}

		container = container.replace('#response.searchProfile.owner.previousInsurerOc#',response.searchProfile.owner.previousInsurerOc);
		container = container.replace('#response.searchProfile.owner.yearsWithoutAccidentsOc#',response.searchProfile.owner.yearsWithoutAccidentsOc);
		container = container.replace('#response.searchProfile.owner.discountOrRiseOcStringValue#',response.searchProfile.owner.discountOrRiseOcStringValue);
		container = container.replace('#response.searchProfile.owner.numbersOfPoliciesWithoutDamagesOc#',response.searchProfile.owner.numbersOfPoliciesWithoutDamagesOc);
		container = container.replace('#response.searchProfile.owner.accidentsLastYearOc#',response.searchProfile.owner.accidentsLastYearOc);
		container = container.replace('#response.searchProfile.owner.previousInsurerAc#',response.searchProfile.owner.previousInsurerAc);
		container = container.replace('#response.searchProfile.owner.yearsWithoutAccidentsAc#',response.searchProfile.owner.yearsWithoutAccidentsAc);
		container = container.replace('#response.searchProfile.owner.discountOrRiseAcStringValue#',response.searchProfile.owner.discountOrRiseAcStringValue);
		container = container.replace('#response.searchProfile.owner.numbersOfPoliciesWithoutDamagesAc#',response.searchProfile.owner.numbersOfPoliciesWithoutDamagesAc);
		container = container.replace('#response.searchProfile.owner.accidentsLastYearAc#',response.searchProfile.owner.accidentsLastYearAc);
		container = container.replace('#response.searchProfile.owner.accidentsLastYearNnw#',response.searchProfile.owner.accidentsLastYearNnw);
		
		if (response.searchProfile.coOwnerExisting) {
			//container = container.replace('<div id="coOwnerExisting2" style="display: none;">','<div id="coOwnerExisting2" style="display: block;">');
			container = container.replace('#response.searchProfile.coOwner.previousInsurerOc#',response.searchProfile.coOwner.previousInsurerOc);
			container = container.replace('#response.searchProfile.coOwner.yearsWithoutAccidentsOc#',response.searchProfile.coOwner.yearsWithoutAccidentsOc);
			container = container.replace('#response.searchProfile.coOwner.discountOrRiseOcStringValue#',response.searchProfile.coOwner.discountOrRiseOcStringValue);
			container = container.replace('#response.searchProfile.coOwner.accidentsLastYearOc#',response.searchProfile.coOwner.accidentsLastYearOc);
			container = container.replace('#response.searchProfile.coOwner.previousInsurerAc#',response.searchProfile.coOwner.previousInsurerAc);
			container = container.replace('#response.searchProfile.coOwner.yearsWithoutAccidentsAc#',response.searchProfile.coOwner.yearsWithoutAccidentsAc);
			container = container.replace('#response.searchProfile.coOwner.discountOrRiseAcStringValue#',response.searchProfile.coOwner.discountOrRiseAcStringValue);
			container = container.replace('#response.searchProfile.coOwner.accidentsLastYearAc#',response.searchProfile.coOwner.accidentsLastYearAc);
		}
		
		$('details_' + response.providerId).innerHTML = container;
		
		
	},
	getProviderPdf : function(carProviderId) {
		if (carProviderId == 1) {
			return this.contextPath + "/downloads/benefia24.pdf";
		}
		if (carProviderId == 2) {
			return this.contextPath + "/downloads/generali.pdf";
		}
		if (carProviderId == 3) {
			return this.contextPath + "/downloads/uniqa.pdf";
		}
		if (carProviderId == 4) {
			return this.contextPath + "/downloads/aviva.pdf";
		}
		if (carProviderId == 6) {
			return this.contextPath + "/downloads/mbank.pdf";
		}
		if (carProviderId == 7) {
			return this.contextPath + "/downloads/PZU.pdf";
		}
		if (carProviderId == 8) {
			return this.contextPath + "/downloads/LD.pdf";
		}
		if (carProviderId == 9) {
			return this.contextPath + "/downloads/HDI.pdf";
		}
		if (carProviderId == 10) {
			return this.contextPath + "/downloads/AD.pdf";
		}
		if (carProviderId == 11) {
			return this.contextPath + "/downloads/PZU.pdf";
		}
		if (carProviderId == 12) {
			return this.contextPath + "/downloads/axa.pdf";
		}
		if (carProviderId == 13) {
			return this.contextPath + "/downloads/link4.pdf";
		}
		return "";
	},
	formatNumber2Price : function(number){ 
		var price = number.toFixed(2);
		var price = price.toString();
		var price = price.replace('.', ',');
		return price;		
	},
	swap : function(element1, element2) {
		
		if(element1 && element2) { //nodes found
			var parent = element1.parentNode;

			if (parent.lastChild == element2) {
				var nextOfElement1 = element1.nextSibling;
				parent.appendChild(element1);
				parent.insertBefore(element2, nextOfElement1);
			} else {
				var nextOfElement1 = element1.nextSibling;
				var nextOfElement2 = element2.nextSibling;
				parent.insertBefore(element1, nextOfElement2);
				parent.insertBefore(element2, nextOfElement1);
			}
		}
			
	},
	sortResults : function(){
		var parent = $('resultListTable');
		
		for (var i = 0; i < parent.childElements().length; i++) {
			for (var j = i; j < parent.childElements().length; j++) {
				if(parent.childElements()[i].childElements()[0].value != "" && parent.childElements()[j].childElements()[0].value != "" && 
				   parseFloat(parent.childElements()[i].childElements()[0].value) > parseFloat(parent.childElements()[j].childElements()[0].value)){
					this.swap(parent.childElements()[i], parent.childElements()[j]);
				}	
			}
		}
		
	}
});

