/********* GET RESULTS DIV ****************************************/

var resultsHtml = null;
var formHtml = null;
var blurbHtml = null;
var serverUrl = "/hillspet-web/mvc/search";
var liveServerSearchUrl = "/cps/rde/xchg/hillspet/xsl/hs.xsl/-/dynaments/search-your-neighborhood-forms.xml";
var liveServerBlurbUrl = "/cps/rde/xchg/hillspet/xsl/hs.xsl/-/dynaments/search-bottom-blurb.html";
var pageType = "V"; 
//var query = null;
//if (location.href.indexOf('find-a-vet') > -1) pageType = "V";

function getFormHtml(query) {
        //alert("form=" + query);
		//alert('getFormHtml function running');
	$.get(liveServerSearchUrl + query,
     		function(data) { 
        		formHtml = data;
				//alert('data');
				//alert('formHtml=' + formHtml);
        		//$("#wheretobuy_form_container").html(unescape(formHtml));
				//alert('at this point form should be populating');
				$('#marquee_wtbneighborhood').hide();
				$('#marquee_wtbfindvet').hide();
				$('#redtitle').hide();
      		}
  	);
}

function getResultsHtml(query) {
        //alert("search=" + query);
	$.get(serverUrl + query,
     		function(data) { 
        		resultsHtml = data;
       	               // if (pageType == 'V') $('#marquee_wtbneighborhood').hide();
						$('#marquee_wtbneighborhood').hide();
	               // if (pageType == 'V') $('#marquee_wtbfindvet').hide();
					    $('#marquee_wtbfindvet').hide();
                        $('#description_wtbneighborhood').hide();
                        $('#findavet_wrapper').hide();
                        $('#formTitle').html("Results");
        		$("#wheretobuy_results_container").html(unescape(resultsHtml));
      		}
  	);
}

function getBlurbHtml(query) {
        //alert("form=" + query);
	$.get(liveServerBlurbUrl + query,
     		function(data) { 
        		blurbHtml = data;
                        //alert(blurbHtml);
        		$("#findavet_wrapper").html(unescape(blurbHtml));
      		}
  	);
}

getFormHtml("?type=" + pageType);
getBlurbHtml("?type=" + pageType);

//getResultsHtml(location.search);

$(document).ready(
	function() { 
	var query = "?type=" + pageType;
	getFormHtml(query);
	//alert('just run getForm function');
	//alert(formHtml);
	
	$("#wheretobuy_form_container").load("/cps/rde/xchg/hillspet/xsl/hs.xsl/-/dynaments/search-your-neighborhood-forms.xml?type=V");
	//		if (formHtml == null) {getFormHtml(query);}
        	if (formHtml != null) {
	            $("#wheretobuy_form_container").html(unescape(formHtml));
        	}
        	if (resultsHtml != null) {
	            $("#wheretobuy_results_container").html(unescape(resultsHtml));
        	}
        	if (blurbHtml != null) {
	            $("#findavet_wrapper").html(unescape(blurbHtml));
        	}
     	}
);

    function doCityStateSearch() {

		$('#postalCode').val("");
	    
		var searchForm = $('#where_ToBuy_zipSearch');
	        var searchType = 'CITY_STATE';
		var type = $('#type').val();
		var country = $('#country').val();
		var miles = $('#miles').val();
		var city = $('#city').val();
		var state = $('#stateList').val();

		var query = "?searchType=" + searchType + "&type=" + type + "&country=" + country + "&miles=" + miles + "&city=" + city + "&state=" + state + "&display-marquee=false";

		getResultsHtml(query);
    }

    function doZipSearch() {
		$('#city').val("");
		$('#state').val("");

	        var searchType = 'ZIP';
		var type = $('#type').val();
		var country = $('#country').val();
		var miles = $('#miles').val();
		var postalCode = $('#postalCode').val();
		var query = "?searchType=" + searchType + "&type=" + type + "&country=" + country + "&miles=" + miles + "&postalCode=" + postalCode + "&display-marquee=false";

		getResultsHtml(query);
    }


