var plocation = "";
var month = "";
var ptype = "";

new Event.observe(window,"load", function(ev) {

	plocation = $("programlocation").value;
	$("programlocation").observe("dropdown:change",function(ev) {
		ev.stop();
		if (this.value != plocation) {
			// It's been changed, let's reload the ntypes!
			plocation = this.value;
			new Ajax.Updater("programs","http://www.familytreemd.org/modules/programs/_ajax/reload-programs.php?location=" + plocation + "&type=" + ptype + "&month=" + month, { evalScripts: true });
		}
	});
	
	ptype = $("programtype").value;
	$("programtype").observe("dropdown:change",function(ev) {
		ev.stop();
		if (this.value != ptype) {
			// It's been changed, let's reload the ntypes!
			ptype = this.value;
			new Ajax.Updater("programs","http://www.familytreemd.org/modules/programs/_ajax/reload-programs.php?location=" + plocation + "&type=" + ptype + "&month=" + month, { evalScripts: true });
		}
	});
	
	$$(".start_over")[0].observe("click",function(ev) {
		ev.stop();
		plocation = "";
		ptype = "";
		$("programlocation").value = "";
		$("programtype").value = "";
		
		newLink = new Element("a", { href: "#" });
	    newLink.observe("click", ProtoDrop.Drop);
	    newLink.innerHTML = "All Locations";
		$("programlocation").next("a").replace(newLink);

		newLink = new Element("a", { href: "#" });
	    newLink.observe("click", ProtoDrop.Drop);
	    newLink.innerHTML = "All Programs";
		$("programtype").next("a").replace(newLink);
		new Ajax.Updater("programs","http://www.familytreemd.org/modules/programs/_ajax/reload-programs.php?location=" + plocation + "&type=" + ptype + "&month=" + month, { evalScripts: true });
	});
	
	reloadProgramHooks();
});

function reloadProgramHooks() {
	$$(".register").invoke("observe","click",function(ev) {
		ev.stop();
		
		dims = document.viewport.getDimensions();
		sscroll = document.viewport.getScrollOffsets();
		
		ttop = ((dims.height - 300) / 2) + sscroll.top;
		lleft = (dims.width / 2) + sscroll.left - 250;
		
		$("program_register").setStyle({ left: lleft + "px", top: ttop + "px" });
		new Ajax.Updater("program_register","http://www.familytreemd.org/modules/programs/_ajax/register.php?event=" + this.readAttribute("name"), {
			onComplete: function() {
				new Effect.Appear("program_register");
			},
			evalScripts: true
		});
	});
	
}