jQuery(document).ready(function(){

jQuery('#featured-description').dialog({
	autoOpen: false,
	modal: true,
	title: 'Featured Listing',
	width: 400,
	height: 150,
	resizable: false
});

jQuery('.featured strong a').click(function() {
	jQuery('#featured-description').dialog('open');
	return false;
});

jQuery('#featured-preview').dialog({
	autoOpen: false,
	modal: true,
	title: 'Featured Listing',
	width: 490,
	height: 500,
	resizable: false
});

jQuery('.featured .preview').click(function() {
	jQuery('#featured-preview').dialog('open');
	return false;
});

jQuery('#spotlight-description').dialog({
	autoOpen: false,
	modal: true,
	title: 'Spotlight Listing',
	width: 400,
	height: 150,
	resizable: false
});

jQuery('.spotlight strong a').click(function() {
	jQuery('#spotlight-description').dialog('open');
	return false;
});

jQuery('#spotlight-preview').dialog({
	autoOpen: false,
	modal: true,
	title: 'Spotlight Listing',
	width: 490,
	height: 500,
	resizable: false
});

jQuery('.spotlight .preview').click(function() {
	jQuery('#spotlight-preview').dialog('open');
	return false;
});

jQuery('#info-form').dialog({
	autoOpen: false,
	modal: true,
	title: 'Request more information',
	width: 376,
	height: 300,
	resizable: false
});

jQuery('.dealers a, .print a:eq(0)').click(function() {
	jQuery('#info-form').dialog('open');
	return false;
});

if (location.href == 'http://www.2theadvocate.com/wheels' || location.href == 'http://www.2theadvocate.com/wheels/') {

var zipRequired = false;

var func = window.onload;
if (func != null) {
	window.onload = function() {
		func();
		initDropdowns();
	};
} else {
	window.onload = function() {
		initDropdowns();
	};
}

function initDropdowns() {
	fillMakes();
	//pre-populate based on default search criteria
	fillFormElement(document.getElementById('make0'), "", "select-one");
	fillFormElement(document.getElementById('model0'), "", "select-one");
	fillFormElement(document.getElementById('priceH'), "", "select-one");
	fillFormElement(document.getElementById('zip'), "Enter a Zip", "text");
}

function validateInventorySearch() {
	var errorText = 'Please correct the following errors in your submission:\n\n';
	var hasErrors = false;
	var zip = document.getElementById('zip');
	//If a zip was specified, make sure it is a valid zip
	if(zip.value == "Enter a Zip") {
		zip.value = "";
	} else if(zip.value != '') {
		if(!isValidZip(zip.value)) {
			errorText += "Please enter a valid zip code.\n";
			hasErrors = true;
		}
	}
	if(hasErrors) {
		alert(errorText);
		return false;
	}
	return true;
}

$('#tab-1 form').submit(function() {
	if ($('#zip').val() == 'Enter a Zip') {
		$('#zip').val('');
	}
});

}

});
