	var CWKRef = {
		   _states: ['Alabama','Florida','Georgia','Iowa','Minnesota','South Carolina','South Dakota','Tennessee'],
		_divisions: [{State:'Alabama',City:'Ashford'},{State:'Alabama',City:'Dothan'},{State:'Alabama',City:'Huntsville'},{State:'Alabama',City:'Lanett'},
				{State:'Alabama',City:'Madison'},{State:'Alabama',City:'Montgomery'},{State:'Alabama',City:'Prattville'},{State:'Alabama',City:'Valley'},
				{State:'Florida',City:'Panama City'},{State:'Florida',City:'Pinellas'},{State:'Georgia',City:'Augusta'},{State:'Georgia',City:'Columbus'},
				{State:'Georgia',City:'West Point'},{State:'Iowa',City:'Lakeside'},{State:'Iowa',City:'Sioux City'},{State:'Iowa',City:'Storm Lake'},
				{State:'Minnesota',City:'Adrian'},{State:'Minnesota',City:'Currie'},{State:'Minnesota',City:'Edgerton'},{State:'Minnesota',City:'Ellsworth'},
				{State:'Minnesota',City:'Jasper'},{State:'Minnesota',City:'Lake Wilson'},{State:'Minnesota',City:'Luverne'},{State:'Minnesota',City:'Marshall'},
				{State:'Minnesota',City:'Pipestone'},{State:'Minnesota',City:'Slayton'},{State:'Minnesota',City:'Tracy'},{State:'Minnesota',City:'Worthington'},
				{State:'South Carolina',City:'Charleston'},{State:'South Carolina',City:'Summerville'},{State:'South Dakota',City:'Belle Fourche'},
				{State:'South Dakota',City:'Black Hawk'},{State:'South Dakota',City:'Canton'},{State:'South Dakota',City:'Centerville'},
				{State:'South Dakota',City:'Colman'},{State:'South Dakota',City:'Deadwood'},{State:'South Dakota',City:'Elk Point'},
				{State:'South Dakota',City:'Flandreau'},{State:'South Dakota',City:'Harrisburg'},{State:'South Dakota',City:'Lead'},
				{State:'South Dakota',City:'Lennox'},{State:'South Dakota',City:'Madison'},{State:'South Dakota',City:'North Sioux City'},
				{State:'South Dakota',City:'Parker'},{State:'South Dakota',City:'Piedmont'},{State:'South Dakota',City:'Rapid City'},
				{State:'South Dakota',City:'Sioux Falls'},{State:'South Dakota',City:'Sommerset'},{State:'South Dakota',City:'Spearfish'},
				{State:'South Dakota',City:'St. Onge'},{State:'South Dakota',City:'Sturgis'},{State:'South Dakota',City:'Tea'},
				{State:'South Dakota',City:'Viborg'},{State:'South Dakota',City:'Watertown'},{State:'South Dakota',City:'Whitewood'},
				{State:'South Dakota',City:'Yankton'},{State:'Tennessee',City:'Knoxville'}],
		
		_dom_ctrl: { 
			state: function() { return document.getElementById('cwk-state'); },
			city:  function() { return document.getElementById('cwk-city');  }
		},
		
		_controls: function(o) {
			return o.parentNode.getElementsByTagName('select');
		},
		
		_dom_ctrl_init: function(cityonly) {
			if (! cityonly)
			{
				var o = CWKRef._dom_ctrl.state();
				if (o && this._states.length > 0)
				{
					for (var i = 0; i < this._states.length; i++)
					{
						if ( (this._site() == this.Site.PrairieWave && this._states[i].match(/(Minnesota|Iowa|South Dakota)/i)) ||
							  this._site() == this.Site.Graceba || this._site() == this.Site.Knology)
						o.options[o.options.length] = new Option(this._states[i], this._states[i]);
					}
				}
			}
			var o = CWKRef._dom_ctrl.city();
			if (o && this._divisions.length > 0)
			{
				for (var i = 0; i < this._divisions.length; i++)
					o.options[o.options.length] = new Option(this._divisions[i].City, this._divisions[i].State+':'+this._divisions[i].City);
				o.disabled = false;
			}
		},
		
		_reset: function() {
			for (var i = this._dom_ctrl.city().options.length - 1 ; i > 0 ; i--)
				this._dom_ctrl.city().options[i] = null;
			var o = this._dom_ctrl_init(true);
		},
		
		_site: function() {
			if (window.location.href.match(/prairiewave/gi))
				return 1;
			else if (window.location.href.match(/graceba/gi))
				return 2;
			else
				return 3;
		},
		
		Site: { PrairieWave:1, Graceba:2, Knology:3 },
		
		Init: function(opts) {			
			this._dom_ctrl.state().options[0] = new Option('---', ''); this._dom_ctrl.city().options[0] = new Option('---', '');
			this._dom_ctrl_init(); this._dom_ctrl.city().disabled = true;
		},
		
		Filter: function(o) {
			this._reset();
			var val = o.options[o.selectedIndex].value;
			for (var i = this._dom_ctrl.city().options.length - 1 ; i > 0 ; i--)
			{
				var state = this._dom_ctrl.city().options[i].value.split(':')[0];
				if (state != val)
					this._dom_ctrl.city().options[i] = null;
			}
			if (this._dom_ctrl.city().options.length == 1)
				this._dom_ctrl.city().disabled = true;
		},
		
		Refer: function(o) {
			var params = '', arDdl = this._controls(o);
			if (arDdl.length && arDdl.length == 1)
			{
				if (arDdl[0].options[arDdl[0].selectedIndex].value.length == 0) return;
				params = '?City='+arDdl[0].options[arDdl[0].selectedIndex].value;
			}
			else if (arDdl.length && arDdl.length == 2)
			{
				if (arDdl[0].options[arDdl[0].selectedIndex].value.length == 0 || arDdl[1].options[arDdl[1].selectedIndex].value.length == 0) return;
				params = '?State='+arDdl[0].options[arDdl[0].selectedIndex].value+'&City='+arDdl[1].options[arDdl[1].selectedIndex].text;
			}
			if (params.length > 0)
				window.location='http://www.connectwithknology.com/'+params;
		}
	}