
	$(document).ready(function() {
		// initialize tabs
		//$('#tab_vehicle').show();
		//$('#shop_for_tires_tabs').removeClass();
		//$('#shop_for_tires_tabs').addClass('tab_vehicle');
		//$('#shop_for_tires_tabs a[rel=tab_vehicle]').addClass('current_tab');
	});



	$('#shop_for_tires_tabs a').live('click', function() {
		var tab_id = $(this).attr('rel');
		// show needed tab
		$('.shop_for_tires_form_tab').hide();
		$('#'+tab_id).toggle();
		// HighLight needed tab
		$('#shop_for_tires_tabs').removeClass();
		$('#shop_for_tires_tabs').addClass(tab_id);
		// Chnage font settings
		$('#shop_for_tires_tabs a').removeClass();
		$(this).addClass('current_tab');
	});



	$('#vehiclemake').live('change', function() {
		$(this).removeClass('red');
		$.ajax({
			type: 'POST',
			url: 'index.php?route=common/shop_for_tires/getvehiclemodel',
			data: { 'vehiclemake': $('#vehiclemake').val() },
			dataType: 'json',
			beforeSend: function() {
				//$('.warning').remove();
				//$('#vehiclemake').after('<span class="wait">&nbsp;<img src="catalog/view/theme/default/image/loading.gif" alt="" /></span>');
			},
			complete: function() {
				//$('.wait').remove();
			},
			success: function(json) {
				if (json['error']) {
					alert (json['error']);
				} else {
					$('#vehicleyear').html(' '); $("<option>").attr("value", "").text(json['vehicleyear_default']).appendTo('#vehicleyear');
					$('#vehicleoption').html(' '); $("<option>").attr("value", "").text(json['vehicleoption_default']).appendTo('#vehicleoption');
					$('#vehiclemodel').html(' '); $("<option>").attr("value", "").text(json['vehiclemodel_default']).appendTo('#vehiclemodel');
					$.each(json['vehiclemodel_data'], function(val, text) {
						$("<option>").attr("value", val).text(text).appendTo('#vehiclemodel');
					});
				}
			}
		});
	});



	$('#vehiclemodel').live('change', function() {
		$(this).removeClass('red');
		$.ajax({
			type: 'POST',
			url: 'index.php?route=common/shop_for_tires/getvehicleyear',
			data: {	'vehiclemake': $('#vehiclemake').val(),
					'vehiclemodel': $('#vehiclemodel').val()
				},
			dataType: 'json',
			beforeSend: function() {
				//$('.warning').remove();
				//$('#vehiclemodel').after('<span class="wait">&nbsp;<img src="catalog/view/theme/default/image/loading.gif" alt="" /></span>');
			},
			complete: function() {
				//$('.wait').remove();
			},
			success: function(json) {
				if (json['error']) {
					alert (json['error']);
				} else {
					$('#vehicleoption').html(' '); $("<option>").attr("value", "").text(json['vehicleoption_default']).appendTo('#vehicleoption');
					$('#vehicleyear').html(' '); $("<option>").attr("value", "").text(json['vehicleyear_default']).appendTo('#vehicleyear');
					$.each(json['vehicleyear_data'], function(val, text) {
						$("<option>").attr("value", val).text(text).appendTo('#vehicleyear');
					});
				}
			}
		});
	});



	$('#vehicleyear').live('change', function() {
		$(this).removeClass('red');
		$.ajax({
			type: 'POST',
			url: 'index.php?route=common/shop_for_tires/getvehicleoption',
			data: {	'vehiclemake': $('#vehiclemake').val(),
					'vehiclemodel': $('#vehiclemodel').val(),
					'vehicleyear': $('#vehicleyear').val()
				},
			dataType: 'json',
			beforeSend: function() {
				//$('.warning').remove();
				//$('#vehicleyear').after('<span class="wait">&nbsp;<img src="catalog/view/theme/default/image/loading.gif" alt="" /></span>');
			},
			complete: function() {
				//$('.wait').remove();
			},
			success: function(json) {
				if (json['error']) {
					alert (json['error']);
				} else {
					$('#vehicleoption').html(' '); $("<option>").attr("value", "").text(json['vehicleoption_default']).appendTo('#vehicleoption');
					$.each(json['vehicleoption_data'], function(val, text) {
						$("<option>").attr("value", val).text(text).appendTo('#vehicleoption');
					});
				}
			}
		});
	});

	$('#vehicleoption').live('change', function() {
		$(this).removeClass('red');
	});


	$('#tirebrand').live('change', function() {
		$(this).removeClass('red');
		$.ajax({
			type: 'POST',
			url: 'index.php?route=common/shop_for_tires/gettirename',
			data: { 'tirebrand': $('#tirebrand').val() },
			dataType: 'json',
			beforeSend: function() {
				//$('.warning').remove();
				//$('#vehicleyear').after('<span class="wait">&nbsp;<img src="catalog/view/theme/default/image/loading.gif" alt="" /></span>');
			},
			complete: function() {
				//$('.wait').remove();
			},
			success: function(json) {
				if (json['error']) {
					alert (json['error']);
				} else {
					$('#tirename').html(' '); $("<option>").attr("value", "").text(json['tirename_default']).appendTo('#tirename');
					$.each(json['tirename_data'], function(val, text) {
						$("<option>").attr("value", val).text(text).appendTo('#tirename');
					});
				}
			}
		});
	});

	$('#tirename').live('change', function() {
		$(this).removeClass('red');
	});

	$('#tirewidth').live('change', function() {
		$(this).removeClass('red');
	});

	$('#tireratio').live('change', function() {
		$(this).removeClass('red');
	});

	$('#tirediameter').live('change', function() {
		$(this).removeClass('red');
	});

	$('#zipcode').live({
		click: function() {
			if ($(this).val() == "Enter Zip Code") $(this).val('');
			else if ($(this).val() == "") $(this).val('Enter Zip Code');
			$(this).removeClass('red');
		},
		keydown: function() {
			if ($(this).val() == "Enter Zip Code") $(this).val('');
			$(this).removeClass('red');
		},
		blur: function() {
			if ($(this).val() == "Enter Zip Code") $(this).val('');
			else if ($(this).val() == "") $(this).val('Enter Zip Code');
			$(this).removeClass('red');
		}
	});


/**************************************************************************************************************/
/**** JQuery Form Validate  ***********************************************************************************/
/**************************************************************************************************************/

	TireSearchFormSubmitting=function() {
		alert("Additional Submitting handler (e.g. Ajax) !!!");
	}

	jQuery.validator.addMethod("MakeValidate", function(value, element) { if (element.value == "") { return false; } else { return true; } });
	jQuery.validator.addMethod("ModelValidate", function(value, element) { if (element.value == "") { return false; } else { return true; } });
	jQuery.validator.addMethod("YearValidate", function(value, element) { if (element.value == "") { return false; } else { return true; } });
	jQuery.validator.addMethod("OptionValidate", function(value, element) { if (element.value == "") { return false; } else { return true; } });

	jQuery.validator.addMethod("BrandValidate", function(value, element) { if (element.value == "") { return false; } else { return true; } });
	jQuery.validator.addMethod("NameValidate", function(value, element) { if (element.value == "") { return false; } else { return true; } });

	jQuery.validator.addMethod("WidthValidate", function(value, element) { if (element.value == "") { return false; } else { return true; } });
	jQuery.validator.addMethod("RatioValidate", function(value, element) { if (element.value == "") { return false; } else { return true; } });
	jQuery.validator.addMethod("DiameterValidate", function(value, element) { if (element.value == "") { return false; } else { return true; } });

	jQuery.validator.addMethod("ZIPvalidate", function(value, element) { if (element.value == "Enter Zip Code") { return false; } else { return true; } });

	$(document).ready(function() {

		$("#TireSearchForm").validate({
			/*submitHandler:function(form) { TireSearchFormSubmitting(); }, */
			rules: {
				zipcode: { required: true, ZIPvalidate : true }
			},
			errorPlacement: function(error, element) {
				//console.log(error);
				element.addClass('red');
				if (element.attr('name') == 'zipcode') { element.val('Enter Zip Code');  }
			}
		});


		$("#TireSearchVehicleForm").validate({
			/*submitHandler:function(form) { TireSearchFormSubmitting(); }, */
			rules: {
				vehiclemake: { 	MakeValidate: true },
				vehiclemodel: { ModelValidate: true },
				vehicleyear: {	YearValidate: true },
				vehicleoption: { OptionValidate: true },
				zipcode: {	required: true, ZIPvalidate : true }
			},
			messages: {
				zipcode: "Enter Zip Code"
			},
			errorPlacement: function(error, element) {
				//console.log(error);
				element.addClass('red');
				if (element.attr('name') == 'zipcode') { element.val('Enter Zip Code');  }
			}
		});


		$("#TireSearchBrandForm").validate({
			/*submitHandler:function(form) { TireSearchFormSubmitting(); }, */
			rules: {
				tirebrand: { 	BrandValidate: true },
				tirename: { 	NameValidate: true },
				zipcode: {		required: true, ZIPvalidate : true }
			},
			messages: { zipcode: "Enter Zip Code" },
			errorPlacement: function(error, element) {
				//console.log(error);
				element.addClass('red');
				if (element.attr('name') == 'zipcode') { element.val('Enter Zip Code');  }
			}
		});


		$("#TireSearchTiresizeForm").validate({
			/*submitHandler:function(form) { TireSearchFormSubmitting(); }, */
			rules: {
				tirewidth: { WidthValidate: true },
				tireratio: { RatioValidate: true },
				tirediameter: { DiameterValidate: true },
				zipcode: { required: true, ZIPvalidate : true }
			},
			messages: { zipcode: "Enter Zip Code" },
			errorPlacement: function(error, element) {
				//console.log(error);
				element.addClass('red');
				if (element.attr('name') == 'zipcode') { element.val('Enter Zip Code');  }
			}
		});


	});



/**************************************************************************************************************/

