AjaxRequest.get({
			url: 
				headerUrl,
			onSuccess:
				function(req){document.getElementById("header").innerHTML = req.responseText;createAutoComplete();}	
	});

function createAutoComplete(){

    this.oACDS = new YAHOO.widget.DS_XHR("/review/autoCompleteSearch_ajax.jsp", ["Complexes","Complexes.complex.complex_name","complex"]);
    this.oACDS.queryMatchContains = true;
    this.oAutoComp = new YAHOO.widget.AutoComplete("ysearchinput","ysearchcontainer", this.oACDS);
    this.oAutoComp.useShadow = true;
    
    this.oAutoComp.formatResult = function(oResultItem, sQuery) {
    	var str = "<a href=\""+oResultItem[1].url+"\">"+ oResultItem[1].complex_name + "</a> "
    	
    	if(oResultItem[1].formerly){
	    	str+="<br /><i>("+oResultItem[1].formerly+"</i>";
    	}
    	
    	str+="<br />" + oResultItem[1].city + ", "+oResultItem[1].state+"";
        return str; 
    };
    
    this.oAutoComp.doBeforeExpandContainer = function(oTextbox, oContainer, sQuery, aResults) {
        var pos = YAHOO.util.Dom.getXY(oTextbox);
        pos[1] += YAHOO.util.Dom.get(oTextbox).offsetHeight + 2;
        YAHOO.util.Dom.setXY(oContainer,pos);
        return true;
    };

    // Stub for form validation
    this.validateForm = function() {
        return true;
    };
    
    //define your itemSelect handler function:
	var itemSelectHandler = function(sType, aArgs) {
		if("itemSelect" == sType){
			document.location= aArgs[2][1].url;
		}
	};

	//subscribe your handler to the event
	this.oAutoComp.itemSelectEvent.subscribe(itemSelectHandler);
};


if(document.getElementById("mapBox"))
AjaxRequest.get({
	url:
		mapUrl,
	onSuccess:
		function(req){
			
			document.getElementById("mapBox").innerHTML = req.responseText;
			
			document.forms.sort.sort.onchange = function(){
				AjaxRequest.get({
					url: 
						'/review/services/sort.jsp?sort='
						+document.forms.sort.sort.value
						+'&key='+key+'&type=complex',
					onSuccess:
						function(req){window.location = window.location.replace(/[1-9]*\.html/,'.html');window.location.reload();}	
					});
			}
			var gmap = false;
			document.getElementById("gMap").style.height = "424px";
			
			ddaccordion.init({
			headerclass: "mapTab", 
			headerclass2: "mapTab2", 
			contentclass: "map", 
			collapseprev: true, 
			defaultexpanded: [], 
			animatedefault: false, 
			persiststate: true, 
			toggleclass: ["mapClose", "mapOpen"], 
			togglehtml: ["prefix", "show", "hide"], 
			animatespeed: "fast",
			onExpand:function(){
					if(gmap == false){
						gmap = new loadMap("gMap"); 
						gmap.getComplexes();
					}
					return true;
				}
			});
			
		}
		
});