function setNeighborhood(neighborhood)
{
	n = document.getElementById(neighborhood);
	a = n.getElementsByTagName('a')[0].id;
	//console.log("before value: %s", n.getElementsByTagName('a')[0].id);
	if (a.indexOf('_') == -1)
	{
		n.getElementsByTagName('a')[0].id = neighborhood + '_on';
		n.getElementsByTagName('span')[0].style.color = '#000';
		document.getElementById(neighborhood + '_checkbox').checked = true;
	}
	else if (a.indexOf('_') > 0)
	{
		n.getElementsByTagName('a')[0].id = '';
		n.getElementsByTagName('a')[0].style.background = '';
		n.getElementsByTagName('span')[0].style.color = '';
		document.getElementById(neighborhood + '_checkbox').checked = false;
	}
	//console.log("after value: %s", n.getElementsByTagName('a')[0].id);
}

function setNeighborhoodSearch(neighborhood,updateMap)
{
	var stateChange = 0;
	
	if (neighborhood == 'bronx') stateChange = 32768;
	if (neighborhood == 'queens') stateChange = 16384;
	if (neighborhood == 'brooklyn') stateChange = 8192;
	if (neighborhood == 'financial') stateChange = 4096;
    if (neighborhood == 'les') stateChange = 2048;
    if (neighborhood == 'tribeca') stateChange = 1024;
    if (neighborhood == 'east_village') stateChange = 512;
    if (neighborhood == 'west_village') stateChange = 256;
    if (neighborhood == 'gramercy') stateChange = 128;
    if (neighborhood == 'chelsea') stateChange = 64;
    if (neighborhood == 'theater') stateChange = 32;
    if (neighborhood == 'midtown_east') stateChange = 16;
    if (neighborhood == 'midtown_west') stateChange = 8;
    if (neighborhood == 'ues') stateChange = 4;
    if (neighborhood == 'uws') stateChange = 2;
    if (neighborhood == 'uptown') stateChange = 1;
	
	n = document.getElementById(neighborhood);
	a = n.getElementsByTagName('a')[0].id;

	if (a.indexOf('_') == -1)
	{
		if (updateMap) document.getElementById("SearchState").value = stateChange + parseInt(document.getElementById("SearchState").value);
		if (document.getElementById("SearchState").value != 8192 || document.getElementById("SearchState").value != 16384 || document.getElementById("SearchState").value != 32768)
		{
		    n.getElementsByTagName('a')[0].id = neighborhood + '_on';
		    n.getElementsByTagName('span')[0].style.color = '#000';
	    }
	}
	else if (a.indexOf('_') > 0)
	{
		if (updateMap) document.getElementById("SearchState").value -= stateChange;
		n.getElementsByTagName('a')[0].id = '';
		n.getElementsByTagName('a')[0].style.background = '';
		n.getElementsByTagName('span')[0].style.color = '';

	}
	
    if (updateMap) buildResults();   
}

function resetNeighborhood(neighborhood)
{
	n = document.getElementById(neighborhood);
	a = n.getElementsByTagName('a')[0].id;
	n.getElementsByTagName('a')[0].id = null;
	n.getElementsByTagName('a')[0].style.background = null;
	n.getElementsByTagName('span')[0].style.color = null;
}

function hoverNeighborhood(neighborhood)
{
	n = document.getElementById(neighborhood);
	a = n.getElementsByTagName('a')[0].id;
	if (a.indexOf('_') == -1)
	{
		n.getElementsByTagName('a')[0].id = neighborhood + '_on';
		n.getElementsByTagName('span')[0].style.color = '#000';
	}
}

function toggleParties()
{
    if (document.getElementById("parties").className == "arrow_right")
    {
        document.getElementById("parties").className = "arrow_down";
        document.getElementById("party_links").className = "dropdown_links";
    }
    else
    {
        document.getElementById("parties").className = "arrow_right";
        document.getElementById("party_links").className = "dropdown_links hidden";
    }
}

function showMap()
{
    document.getElementById("results").className = "results_full short";
    document.getElementById("map").className = "";
    document.getElementById("search_results").className = "hidden";
    document.getElementById("search_map").className = "";
}

function hideMap()
{
    document.getElementById("results").className = "results_full";
    document.getElementById("map").className = "hidden";
    document.getElementById("search_results").className = "";
    document.getElementById("search_map").className = "hidden";
}

function buildResults()
{   
    document.getElementById("results_pane_full").innerHTML = "";
    var searchState = document.getElementById("SearchState").value;
    if (searchState == 0) searchState = 8191; //if nothing is selected, show all regions
        
    //Parse out searchState to figure out which events to display. I use 13 binary values, converted to 1 decimal number to store the state 0-8191 (2^13 - 1)
    for (var i = 15; i >= 0; i--)
    {        
        if (searchState >= (Math.pow(2,i)))
        {
            
            searchState -= Math.pow(2,i);
            if (i == 15) displayLocation("The Bronx");
            if (i == 14) displayLocation("Queens");
            if (i == 13) displayLocation("Brooklyn");
            if (i == 12) displayLocation("Financial District");
            if (i == 11) displayLocation("Lower East Side");   
            if (i == 10) displayLocation("SoHo/TriBeCa");   
            if (i == 9) displayLocation("East Village/ABC City");   
            if (i == 8) displayLocation("West Village/Greenwich Village");   
            if (i == 7) displayLocation("Murray Hill/Gramercy/Stuy Town");   
            if (i == 6) displayLocation("Midtown South/Chelsea");   
            if (i == 5) displayLocation("Times Square/Theater District");   
            if (i == 4) displayLocation("Midtown East");   
            if (i == 3) displayLocation("Midtown West");   
            if (i == 2) displayLocation("Upper East Side");   
            if (i == 1) displayLocation("Upper West Side");   
            if (i == 0) displayLocation("Uptown");   
        
        }
    }   
}

function displayLocation(location)
{
    var results_panel = document.getElementById("results_pane_full");
    var data = document.getElementById("BarData").value.split('|');
    
    var bars = data.length / 15;
    
    var htmlString = "";
    
    htmlString += "<div class='area_label'>" + location + "</div>";
    
    for (var i = 0; i < bars; i++)
    {
        if (data[(i * 15) + 3] == location)
        {
            htmlString += "<a href='Search_Detail.aspx?area=" + document.getElementById("SearchState").value + "&id=" + data[(i * 15) + 0] + "' class='bar_detail_link'>";
                    htmlString += "<div class='result_left'>";
                        htmlString += "<span style='font-weight: bold;'>" + data[(i * 15) + 1] + " - " + location + "</span><br />";
                        htmlString += data[(i * 15) + 2] + "<br />";
                        htmlString += "<span style='font-weight: bold;'>" + data[(i * 15) + 5] + "</span><br />";
                        htmlString += "<span class='hours_info'>" + data[(i * 15) + 6] + "</span>";
                        if (data[(i * 15) + 7] != "") htmlString += data[(i * 15) + 7] + ": <span style='color: Red;'>$" + data[(i * 15) + 8] + "</span><br />";
                        if (data[(i * 15) + 9] != "") htmlString += data[(i * 15) + 9] + ": <span style='color: Red;'>$" + data[(i * 15) + 10] + "</span><br />";
                        if (data[(i * 15) + 11] != "") htmlString += data[(i * 15) + 11] + ": <span style='color: Red;'>$" + data[(i * 15) + 12] + "</span><br />";
                        if (data[(i * 15) + 13] != "") htmlString += data[(i * 15) + 13] + ": <span style='color: Red;'>$" + data[(i * 15) + 14] + "</span><br />";
                    htmlString += "</div>";
                    htmlString += "<div class='result_right'>";
                        htmlString += "<span class='bar_result_image'><img src='" + data[(i * 15) + 4] + "' height='109' width='111' onclick=\"window.location = 'Search_Detail.aspx?area=" + document.getElementById("SearchState").value + "&id=" + data[(i * 15) + 0] + "'\" /></span>"; 
                    htmlString += "</div>";
            htmlString += "</a>";
        }
    }
    
    results_panel.innerHTML += htmlString;
}

function initMap()
{
    var searchState = parseInt(document.getElementById("SearchState").value);
                
    //Parse out searchState to figure out which events to display. I use 13 binary values, converted to 1 decimal number to store the state 0-8191 (2^13 - 1)
    for (var i = 15; i >= 0; i--)
    {        
        if (searchState >= (Math.pow(2,i)))
        {
            
            searchState -= Math.pow(2,i);
            if (i == 15) setNeighborhoodSearch("bronx",false);
            if (i == 14) setNeighborhoodSearch("queens",false);
            if (i == 13) setNeighborhoodSearch("brooklyn",false);
            if (i == 12) setNeighborhoodSearch("financial",false);
            if (i == 11) setNeighborhoodSearch("les",false);
            if (i == 10) setNeighborhoodSearch("tribeca",false);
            if (i == 9) setNeighborhoodSearch("east_village",false);   
            if (i == 8) setNeighborhoodSearch("west_village",false);   
            if (i == 7) setNeighborhoodSearch("gramercy",false);   
            if (i == 6) setNeighborhoodSearch("chelsea",false);   
            if (i == 5) setNeighborhoodSearch("theater",false);   
            if (i == 4) setNeighborhoodSearch("midtown_east",false);   
            if (i == 3) setNeighborhoodSearch("midtown_west",false);   
            if (i == 2) setNeighborhoodSearch("ues",false);   
            if (i == 1) setNeighborhoodSearch("uws",false);   
            if (i == 0) setNeighborhoodSearch("uptown",false);   
        
        }
    }   
}

function clearAll()
{
    resetNeighborhood("financial",false);
    resetNeighborhood("les",false);
    resetNeighborhood("tribeca",false);
    resetNeighborhood("east_village",false);   
    resetNeighborhood("west_village",false);   
    resetNeighborhood("gramercy",false);   
    resetNeighborhood("chelsea",false);   
    resetNeighborhood("theater",false);   
    resetNeighborhood("midtown_east",false);   
    resetNeighborhood("midtown_west",false);   
    resetNeighborhood("ues",false);   
    resetNeighborhood("uws",false);   
    resetNeighborhood("uptown",false);   
    
    document.getElementById("SearchState").value = 0;
}

function returnToSearch()
{
   window.location = "Default.aspx?area=" + document.getElementById("SearchState").value;
}

function displayImage(url)
{
    document.getElementById("LargePicture").innerHTML = "<img src='" + url + "'/>";
}