	var mnuLastItem = '';	
	var divLastSubCat = '';


	function toggleChildModels(strID)
	{			
		if ($('#' + strID).is(":hidden"))
		{
			$('#' + strID).slideDown("slow");
			//$('#' + strID).show("slide", { direction: "down" }, 1000);
			if (mnuLastItem != '' && mnuLastItem != strID)
			{
				//$('#' + mnuLastItem).hide("slide", { direction: "up" }, 1000);
				$('#' + mnuLastItem).slideUp("slow");
			}				
			mnuLastItem = strID;
		}
		else 
		{
			//$('#' + strID).hide("slide", { direction: "up" }, 1000);
			$('#' + strID).slideUp("slow");
			mnuLastItem = strID;
		}

		return false;
	}


	function toggleSubCats(strID)
	{
		if ($('#' + strID).is(":hidden"))
		{
			$('#' + strID).slideDown("slow");
			//$('#' + strID).show("slide", { direction: "down" }, 1000);
			if (divLastSubCat != '' && divLastSubCat != strID)
			{
				//$('#' + mnuLastItem).hide("slide", { direction: "up" }, 1000);
				$('#' + divLastSubCat).slideUp("slow");
			}				
			divLastSubCat = strID;
			//window.location.href = '#' + strID;
			var elementClicked = $('#' + strID).attr("href");
			var destination = $('#' + strID).offset().top;
			$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination-20}, 500 );
		}
		else 
		{
			//$('#' + strID).hide("slide", { direction: "up" }, 1000);
			$('#' + strID).slideUp("slow");
			divLastSubCat = strID;
			var elementClicked = $('#header').attr("href");
			var destination = $('#header').offset().top;
			$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination-20}, 500 );
		}		
		return false;		
	}

	function checkEmail(strEmail) 
	{
		var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if (strEmail == '')	{
			return false;
		}
		if (!filter.test(strEmail)) {
			return false;
		}
		return true;
	}

	function validateMailingListForm()
	{
		if (!checkEmail($('#frmEmail').val())) {
			$('#frmEmail').focus();
			alert('Please fill in your Email address');
			return false;
		}
		if ($('#frmMake').val() == '')
		{
			$('#frmMake').focus();
			alert('Please select your make');
			return false;
		}
		if ($('#frmModel').val() == '' || $('#frmModel').val() == 'Please select your model')
		{
			$('#frmModel').focus();
			alert('Please select your model');
			return false;
		}
		if ($('#frmYear').val() == '' || $('#frmYear').val() == 'Please select the year')
		{
			$('#frmYear').focus();
			alert('Please select the year');
			return false;
		}
		$('#frmMailingList').submit();
	}

	function getModels() 
	{
		$.ajax({
				type: "GET",
				url: "/includes/_ajaxHandler.php?src=model&make=" + $('#frmMake').val(),
				dataType: "xml",
				success: function(xml) {
					$('#frmYear').empty();
					$('#frmModel').empty();
					var select = $('#frmModel');
					select.append("<option />");
					$(xml).find('model').each(function(){
						var title = $(this).text();
						select.append("<option value=\"" + title + "\">" + title + "</option>");
					});
					select.children(":first").text("Please select your model").attr("selected",true);
				}
		});
	}

	function getYears() 
	{
		$.ajax({
				type: "GET",
				url: "/includes/_ajaxHandler.php?src=year&make=" + $('#frmMake').val() + "&model=" + $('#frmModel').val(),
				dataType: "xml",
				success: function(xml) {
					$('#frmYear').empty();
					var select = $('#frmYear');
					select.append("<option />");
					$(xml).find('year').each(function(){
						var title = $(this).text();
						select.append("<option value=\"" + title + "\">" + title + "</option>");
					});
					select.children(":first").text("Please select the year").attr("selected",true);
				}
		});
	}
	
	
