WDP.models = {};
WDP.init = {};

WDP.init.CraigslistRequestData = function(city, category, subcategory, query){
	this.domain = 'craigslist';
	this.city = city;
	this.category = category;
	this.subcategory = subcategory;
	this.query = query;
}

WDP.init.searchForm = function(){
	var searchForm = $("#search_form");
	searchForm.submit(function(e){
    	return false;
	});

	WDP.init.populateSearchFields();

	searchForm.find("input[type='submit']").on('click', function(event) {
		var currentCity = $("#search_city option:selected").val();
		var requestData = new WDP.init.CraigslistRequestData(currentCity, 
															$("#search_category option:selected").val(), 
															$("#search_subcategory option:selected").val(), 
															$("#search_query").val());
		WDP.models.currentCity = currentCity;
		WDP.getCLPage(requestData, function(searchResults){WDP.detailViz.init(searchResults)});
	});

	searchForm.find('#search_subcategory').on('change', function(event){
		WDP.init.subCategoryTypeName();
	});

	$('#search_category').on('change', function(event) {
		WDP.init.subcategoriesForCategory();
		WDP.init.subCategoryTypeName();
	});
	WDP.init.subCategoryTypeName();
}

WDP.init.subCategoryTypeName = function(subcategory_select_val){
	var currentCategory = $("#search_category option:selected").val();
	var currentSubcategory = $("#search_subcategory option:selected").val();
	WDP.models.subCategoryTypeName = WDP.models.cl.categories[currentCategory].subcategories[currentSubcategory].categoryType;
}

WDP.init.populateSearchFields = function(){
	$.getJSON(WDP.baseUrl + 'data/cl.json', function(searchModel) {
		var model = searchModel.craigslist;
		WDP.models.cl = model;
		WDP.init.select($('#search_city optgroup'), model.cities);
		WDP.init.select($('#search_category optgroup'), model.categories);
		WDP.init.subcategoriesForCategory();

	});	
}

WDP.init.select = function(parentSelect, model){
	for(var item in model){
		parentSelect.append("<option value='"+ item +"'>" + model[item].display + "</option>")
	}
}

WDP.init.subcategoriesForCategory = function(){
	document.getElementById('search_subcategory_optgroup').innerHTML = '';
	WDP.init.select($('#search_subcategory optgroup'), WDP.models.cl.categories[$("#search_category option:selected").val()].subcategories);	
}
if(WDP.page === 'home'){
	WDP.init.searchForm();	
}
else{
	WDP.cc.init();
}

@@ -308,16 +308,17 @@
 form%22);%0A
+%0A
 %09searchF
@@ -325,15 +325,21 @@
 orm.
+on('
 submit
-(
+', 
 func
@@ -348,16 +348,20 @@
 on(e
+vent
 )%7B%0A    %09
 retu
@@ -360,135 +360,36 @@
    %09
-return false;%0A%09%7D);%0A%0A%09WDP.init.populateSearchFields();%0A%0A%09searchForm.find(%22input%5Btype='submit'%5D%22).on('click', function(event) %7B%0A%09
+event.preventDefault();%0A    
 %09var
@@ -812,24 +812,59 @@
 s)%7D);%0A%09%7D);%0A%0A
+%09WDP.init.populateSearchFields();%0A%0A
 %09searchForm.

refactor to use on submit event to submit search request