﻿
function connectManufacturer() {
		//Submit Button ausblenden
		
		//$("input#subVehicleManufacturer").hide();

		//Reifenart setzen
		
		
		//Form Hersteller per Ajax senden
		$("#frmVehicleManufacturer").submit(function() {
			if ($("#drpVehicleManufacturer").val() != 'none') {
				$.post($(this).attr("action"),
				$(this).serialize(), 
				function(modelResponse) {
				if (controller.toUpperCase() != 'RIMAL' &&
					controller.toUpperCase() != 'COMPLETEWHEELAL' &&
					controller.toUpperCase() != 'COMPLETEWHEELST' && 
					controller.toUpperCase() != 'ACCOUNT') {
							$("#tyreByVehicleSearchBox").html(modelResponse);
							setNaviPointActive($("#searchVehicle"), true, true);
							connectNaviPoint($("#searchVehicle"));
						}
						else {
							$("#vehicleSearchContainer").html(modelResponse);
						}
						//connectVehicleModelForm();
					});
			}
			return false;
		});

		//Abschicken Hersteller bei Button change
		$("#drpVehicleManufacturer").change(function() {
			$("#frmVehicleManufacturer").submit();
		});
		
}

//Events fuer Reifengroesse
function connectVehicleTyreSize() {
	//Submit Button ausblenden
	//$("input#subVehicleTyreSize").hide();
	
	connectBackToManufacturer();
	connectBackToModel();
	connectBackToType();
	
	//Abschicken Hersteller bei Button change
	//Kein Ajax sondern Seite Komplett rendern
	$("#drpVehicleTyreSize").change(function() {
		$("#frmVehicleTyreSize").submit();
	});
}

//Events fuer Typauswahl
function connectVehicleTypeForm() {
	//Submit Button ausblenden
	//$("input.subVehicleType").hide();
	
	connectBackToManufacturer();
	connectBackToModel();
	
	//Form Type abschicken per Ajax
	// Fahrzeugsuche Reifen postet auf Auswahl der Reifengröße
	if (controller.toUpperCase() == 'TYREVEHICLE' || controller.toUpperCase() == 'TYRESIZE') {

			//alert(tyreTypeFromRoute);
			
			//gewaehlter Reifentyp in Ajax-Request verfuegbar machen
			//$("#TyreTypeAjax").val(tyreTypeFromRoute);
			$(".tyreTypeHiddenField").val(tyreTypeFromRoute);
			
			
			
			$(".frmVehicleType").submit(function() {
			$.post($(this).attr("action"), $(this).serialize(), function(modelResponse) {
			if (controller.toUpperCase() != 'RIMAL' &&
				controller.toUpperCase() != 'COMPLETEWHEELAL' &&
				controller.toUpperCase() != 'COMPLETEWHEELST' 
				 ) {
					$("#tyreByVehicleSearchBox").html(modelResponse);
					setNaviPointActive($("#searchVehicle"), true, true);
					connectNaviPoint($("#searchVehicle"));
				}
				else {
					$("#vehicleSearchContainer").html(modelResponse);
				}
				// Fuehrpark aktualisieren, falls vorhanden
				if ($('vehilceSlider').length != 0)
				{
					var url = '/' + language + '/Account/ListVehicleManufacturers';
				    $.ajax({
				        type: 'GET',
				        url: url,
				        dataType: 'html',
				        success: function(content) {
				            $('div.vehilceSlider').html(content);
				        },
				        error: function() {
				            alert('error');
				        }
				    });
				}
			});
			return false;
		});
	}

	//Abschicken Type bei Button change
	$("select.drpVehicleType").change(function() {
		$(this).parents('form:first').submit();
	});
}

//Inhalt des Fahrzeugsuchcontrolls setzen
function setVehicleContainerHtml(containerData) {
	if (controller.toUpperCase() != 'RIMAL' &&
    controller.toUpperCase() != 'COMPLETEWHEELAL' &&
    controller.toUpperCase() != 'COMPLETEWHEELST' && 
    controller.toUpperCase() != 'ACCOUNT') {
		$("#tyreByVehicleSearchBox").html(containerData);
	}
	else {
		$("#vehicleSearchContainer").html(containerData);
	}
}

//Zurueck Link auf Herstellerauswahl
function connectBackToManufacturer() {
	$("#lnkBackManufacturer").click(function() {
				$.get(
						$(this).attr("href"),
						function(response) {
							setVehicleContainerHtml(response);
						}
				);
				
				return false;
    });
}

//Zurueck Link auf Modellauswahl
function connectBackToModel() {
	$("#lnkBackModel").click(function() {
		$.get($(this).attr("href"),
				function(response) {
					setVehicleContainerHtml(response);
				});
		return false;
	});
}

//Zurueck Link auf Fahrzeugtyp
function connectBackToType() {
	$("#lnkBackType").click(function() {
		$.get($(this).attr("href"),
				function(response) {
						setVehicleContainerHtml(response);
				});
		return false;
	});
}

//Events fuer Modellauswahl
function connectVehicleModelForm() {
	connectBackToManufacturer();

	//Form Model abschicken per Ajax
	$("#frmVehicleModel").submit(function() {
	$.post($(this).attr("action"), $(this).serialize(), function(modelResponse) {

	if (controller.toUpperCase() != 'RIMAL' &&
	controller.toUpperCase() != 'COMPLETEWHEELAL' &&
	controller.toUpperCase() != 'COMPLETEWHEELST' && 
	controller.toUpperCase() != 'ACCOUNT') {
				$("#tyreByVehicleSearchBox").html(modelResponse);
				setNaviPointActive($("#searchVehicle"), true, true);
				connectNaviPoint($("#searchVehicle"));
			}
			else {
				$("#vehicleSearchContainer").html(modelResponse);
			}
			//connectVehicleTypeForm();
		});
		return false;
	});

	//Submit Button ausblenden
	//$("input#subVehicleModel").hide();

	//Abschicken Hersteller bei Button change
	$("#drpVehicleModel").change(function() {
		$("#frmVehicleModel").submit();
	});
}


