function get_dealers(region) {
	// clear the table
	$('dealer-table').down('tbody').update('');
	// post the dealer req
	ajax_req($H({"region": region}), load_dealers);
}

function load_dealers() {
	var odd = false;
	for(var i = 0, j = this.length; i < j; ++i) {
		odd = ((i % 2) > 0);
		var tr = new Element('tr');
		var td;
		if (odd) {
			tr.addClassName('odd');
		}
		
		// dealer
		td = new Element('td');
		td.update(this[i].dealer);
		tr.insert({bottom: td});
		
		// address
		td = new Element('td');
		td.update(this[i].address);
		tr.insert({bottom: td});
		
		// city
		td = new Element('td');
		td.update(this[i].city);
		tr.insert({bottom: td});
		
		// state
		td = new Element('td');
		td.update(this[i].state);
		tr.insert({bottom: td});
		
		// zip
		td = new Element('td');
		td.update(this[i].zip);
		tr.insert({bottom: td});
		
		// phone
		td = new Element('td');
		td.update(this[i].phone);
		tr.insert({bottom: td});
		
		// website
		td = new Element('td');
		td.update(this[i].web);
		tr.insert({bottom: td});
		
		$('dealer-table').down('tbody').insert({bottom: tr});
	}
}

function ajax_validResponse(json) {
	if (json.length > 0) {
		eval('response = '+json);
		if (response) {
			return true;
		}
	}
	return false;
}

function ajax_req(hash, successFunction) {
	new Ajax.Request('/index.php?id=122', {
		method: 'post',
		parameters: hash,
		onSuccess: function(transport) { 
			if (ajax_validResponse(transport.responseText)) {
				eval('response = '+transport.responseText);
				successFunction.call(response);
			}
		},
		onFailure: function(transport) { 
			//generalError('Error connecting to server.'); 
		}
	});
}