function checkTerms() {
	if ($('#terms').is(':checked')) {
		return true;
	} else {
		alert("You must accept the terms and conditions.");
		return false;
	}
}
function findShop(type){
	var urlFriendly = (type == 'body') ? $('#bodyShops').val() : $('#repairShops').val();
	window.location.href = "/shop/"+ urlFriendly;
}
function confirmShopType() {
	if ($("input:radio[@name=ty]:checked").val() || $("input#gfFieldShop").val() !="SHOP NAME") {
		//setZip();
		return true;
	} else {
		alert("Please be sure to indicate a shop type.");
		return false;
	}
}
function handleSearch() {
	var sn = $("#gfFieldShop").val();
	var zc = $("#gfFieldZip").val();
	var currentAction = routeSearch();//$('form#shopSearch').attr('action');
	if( zc != 'WORK OR HOME ZIP' && zc != '') {
		//it's a zip code search
		if (!confirmShopType()) {
			//only for zip searches, shop type must be indicated
			return;
		}
		currentAction = (currentAction == '') ? '/search/autobody/' : currentAction;
		window.location.href = currentAction + "zipcode/"+zc+"/";
//		$('form#shopSearch').attr('action', currentAction + "zipcode/"+zc+'/');
//		$('form#shopSearch').submit();
	} else if ( sn !="SHOP NAME" && sn !='') {
		//it's a shop name search
		//figure out if they've checked a radio
		if(!$("input:radio[@name=ty]:checked").val()){
			//reset to search both shop types
			//$('form#shopSearch').attr('action', "/search/shop/name/"+sn+'/map/1/');
			window.location.href = "/search/shop/name/"+sn+'/map/1/';
		} else {
			//the correct action has already been triggered, so just append
			//$('form#shopSearch').attr('action', currentAction + "name/"+sn+'/');
			window.location.href = currentAction + "name/"+sn+'/';
		}
		//$('form#shopSearch').submit();
	}
	//do nothing if they've left the defaults
	return;
}
function handleReviewSearch() {
	var sn = $("#gfReviewShop").val();
	if (sn == "SHOP NAME"){
		alert('Please indicate the shop\'s name');
		return false;
	}
	window.location.href = "/search/shop/name/"+sn+"/";
	//$('form#writeReview').attr('action', "/search/shop/name/"+sn+'/');
	//$('form#writeReview').submit();
}
function findShopsByZip(type) {
	if (type == 'body'){
		window.location.href = "/search/autobody/zipcode/"+ $('#bodyShopsByZip').val();
	} else {
		window.location.href = "/search/automechanic/zipcode/"+ $('#repairShopsByZip').val();
	}	
}
function routeSearch() {
	//note: not using this function on the homepage
	if ($("input:radio[@name=ty]:checked").val() == 1) {
		//$('form#shopSearch').attr('action', "/search/automechanic/")
		return "/search/automechanic/";
	} else {
		//$('form#shopSearch').attr('action', "/search/autobody/")
		return "/search/autobody/";
	}
}
function populateCars() {
	var select = $('#ddlMake');
	var l = mmMkCars.length;
	for (var i = 1; i <= l; i++) {
		if (mmMkCars[i]) {
			select.append('<option value="'+mmMkCars[i]+'">'+mmMkCars[i]+'</option>');
		}
	}	
}
function newMmChangeMakeCars(selected) {
	var select = $('#ddlModel');
	//make sure the select is enabled
	select.attr('disabled', false);
	//clear any that are already there
	select.children().remove().end();
	
	if (!mmMdCars.hasOwnProperty(selected)) { //model array doesn't exist for some makes
	    select.append('<option value="other">other</option>');
	} else {
	    select.append('<option value="0">-choose-</option>');
	    var carModels = mmMdCars[selected].split(',');
        var l = carModels.length;
        if (l) {
        	for (var i = 0; i < l; i++) {
        		if (carModels[i]) {
        			select.append('<option value="'+carModels[i]+'">'+carModels[i]+'</option>');
        		}
        	}	
        }
	}
}
function confirmShopSearch() {
	if ($("input#gfReviewShop").val() == "SHOP NAME" || $("input#gfReviewShop").val() == "") {
		alert("Shop name is required.");
		return false;
	} else {
		return true;
	}
}
function revealReview(which) {
	$('p#excerpt'+which).addClass('hidden');
	$('div#full'+which).removeClass('hidden');
}
$(document).ready(function() {
	$("#news").accordion({
		event: "mouseover"
	});
	$("#basic-accordian").accordion({
		autoHeight: false,
		collapsible: true,
		active: false
	});
	$("#a-z-accordion").accordion({
		autoHeight: false,
		collapsible: true,
		active: false
	});
	$("#what_to_expect").accordion({
		header: '.accordion_headings',
		autoHeight: false,
		collapsible: true,
		active: false
	});
	$("#your_rights").accordion({
		header: '.accordion_headings',
		autoHeight: false,
		collapsible: true,
		active: false
	});
	$("#nav-login a").click(function() {
		//$("#gfLoginBox").slideToggle("slow");
	});
	$("#gfNewsScamTabs").tabs();
	$("#safety").tabs();
	$('.tt').hover(
      function (e) {
        $('#balloon1').css({"visibility":"visible", "top": e.pageY - 50, "left":700});
      },
      function () {
          $('#balloon1').css({"visibility":"hidden"});
      }
    );
	populateCars();
});

