﻿// JScript File


var locationString = "All Areas";
var county = "All Counties";
var category = "All Categories";
var letter;



function evenstinCounty(e)
{
    county = trim(e.innerHTML);
    showLoading("lists");
    ajax(xmlDoc1, "ajax/events.aspx?county=" + county, ajaxListingDone, true);
 
    return false;
}

function weatherInCounty(e)
{
    county = trim(e.innerHTML);
    showLoading("lists");
    ajax(xmlDoc1, "ajax/weather.aspx?county=" + county, ajaxListingDone, true);
 
    return false;
}


function gotoCounty(e)
{
        //e.className = "selected";
        county = trim(e.innerHTML);
        showLoading("locations");
        locationString = "All Areas";
        
        if(county == "All Counties")
        {   
            //map.panTo(new GLatLng(53.42262, -7.8222));

            ajax(xmlDoc1, "ajax/counties.aspx?county=All", ajaxCountyDone, true);
            try
            {           
                        map.setCenter(new GLatLng(latitude, longitude), 4);
                        }
                        catch(e)
                        {}
            
        }
        else
        {
            //map.setCenter(new GLatLng(counties[county].glat, counties[county].glong),counties[county].zoom);
            ajax(xmlDoc2, "ajax/businessByCounty.aspx?county=" + county, ajaxCountyBusinessDone, true);
            
            ajax(xmlDoc1, "ajax/county.aspx?county=" + county, ajaxCountyDone, true);
            try
            {
             map.panTo(new GLatLng(counties[county].glat, counties[county].glong));
                  }
                        catch(e)
                        {}
         
}
 try
            {
map.clearOverlays();
   }
                        catch(e)
                        {}
        return false;

}
function gotoCategory(e)
{
        //e.className = "selected";
        category = e.innerHTML.replace('&amp;','&');
  
        showLoading("lists");
       if(county == "All Counties")
       {
        ajax(xmlDoc1, "ajax/category.aspx?category=" + urlencode(category), ajaxListingDone, true);
        }
        else
        {
            if(locationString == "All Areas")
            {
                ajax(xmlDoc1, "ajax/categoriesByArea.aspx?category=" + urlencode(category) + "&area=" + urlencode("%"+county), ajaxListingDone, true);
            
            }
            else
            {
                ajax(xmlDoc1, "ajax/categoriesByArea.aspx?category=" + urlencode(category) + "&area=" + urlencode(locationString+"_"+county), ajaxListingDone, true);
            
            }
        }
        
        try{
        
        map.clearOverlays();
             }
                        catch(e)
                        {}
        //setmap to county
        //
        return false;

}
function gotoLetter(e)
{
        letter = trim(e.innerHTML);
        
        showLoading("cats");
        
        if(letter == "All Categories")
        {
            category = letter;
            ajax(xmlDoc1, "ajax/letters.aspx?letter=All", ajaxLetterDone, true);
        }
        else
        {
            category = "businesses beginning with " + letter;
            ajax(xmlDoc1, "ajax/categories.aspx?category=" + letter, ajaxLetterDone, true);
        }
            
        return false;
}

function gotoArea(e)
{
        locationString = trim(e.innerHTML);
        //e.className = "selected";
        showLoading("lists");
        if(category == "All Categories")
        {
        
            ajax(xmlDoc1, "ajax/businessByArea.aspx?area=" + locationString, ajaxListingDone, true);
        }
        else
        {
            //category = "businesses beginning with " + letter;
            ajax(xmlDoc1, "ajax/categoriesByArea.aspx?area=" + locationString + "_" + county + "&category=" + category, ajaxListingDone, true);
        }
        
        return false;
}



function showLoading(loadingElement)
{
    document.getElementById(loadingElement).innerHTML = "<div style='text-align:center;height:100%;vertical-align:bottom;'><img style='margin:25px'  src='images/loading.gif' /><br />Loading...</div>";
}

function urlencode(str)
{
    str = escape(str);
    str = str.replace(/\+/g, "%2B");
    str = str.replace('%20', '+');
    str = str.replace('*', '%2A');
    str = str.replace(/\'/g, '%2F');
    str = str.replace('@', '%40');
    return str;
}

function ExecuteCode()
{
    var codeToExec = document.getElementById("code");
    if(codeToExec)
        eval(codeToExec.innerHTML);

}

function ajaxAreaDone()
{
	if(xmlDoc1.readyState!=4) 
		return false;  
	else
	{
		//var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		//xmlDoc.loadXML(xmlDoc1.responseText);
		document.getElementById("lists").innerHTML = xmlDoc1.responseText;
		ExecuteCode();
	}	
}

function ajaxLetterDone()
{
	if(xmlDoc1.readyState!=4) 
		return false;  
	else
	{
		//var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		//xmlDoc.loadXML(xmlDoc1.responseText);
		document.getElementById("cats").innerHTML = xmlDoc1.responseText;
		//document.getElementById("lists").innerHTML = getSearchString();
		ExecuteCode();
	}	
}

function ajaxCountyBusinessDone()
{
	if(xmlDoc2.readyState!=4) 
		return false;  
	else
	{
		//var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		//xmlDoc.loadXML(xmlDoc1.responseText);
		document.getElementById("lists").innerHTML = xmlDoc2.responseText;
		ExecuteCode();
	}	
}

function ajaxCountyDone()
{
	if(xmlDoc1.readyState!=4) 
		return false;  
	else
	{
		//var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		//xmlDoc.loadXML(xmlDoc1.responseText);
		document.getElementById("locations").innerHTML = xmlDoc1.responseText;
		//document.getElementById("lists").innerHTML = getSearchString();
		ExecuteCode();
	}	
}

function ajaxListingDone()
{
	if(xmlDoc1.readyState!=4) 
		return false;  
	else
	{
		//var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		//xmlDoc.loadXML(xmlDoc1.responseText);
		document.getElementById("lists").innerHTML = xmlDoc1.responseText;
		ExecuteCode();
	}	
}

function getSearchString()
{
    return "Searching for " + category + " in " + locationString + " in " + county;
}

