/**
 * Building querystring
 */
this.location.querystring = (function() {

    var queryStringDictionary = {};
    var querystring = decodeURI(location.search);

    if (!querystring) {
        return {};
    }

    querystring = querystring.substring(1);
    
    var pairs = querystring.split("&");

    for (var i = 0; i < pairs.length; i++) {
        var keyValuePair = pairs[i].split("=");
        queryStringDictionary[keyValuePair[0]]
                = keyValuePair[1];
    }

    queryStringDictionary.toString = function() {

        if (queryStringDictionary.length == 0) {
            return "";
        }

       var toString = ["?"];
        for (var key in queryStringDictionary) {
        toString.push(key + "=" +
        queryStringDictionary[key]);
        }
        toString = toString.join("");

        return toString;
    };

    // Return the key/value dictionary

    return queryStringDictionary;
})();

/**
 * Global variables
 */
var interrupt;
var interruptResults;
var mode = location.querystring["Mode"].toUpperCase();
mode = mode.trim();
var language = location.querystring["Lang"].toUpperCase();
language = language.trim();
var brand = location.querystring["Brand"].toUpperCase();
brand = brand.trim();

/**
 * Enables the loading animation 
 */
function EnableImgLoading()
{
    objImgLoading = document.getElementById("imgLoading");    
    if (objImgLoading != undefined)
        objImgLoading.style.display = "block";
}

/**
 * Disables the loading animation 
 */
function DisableImgLoading()
{
    objImgLoading = document.getElementById("imgLoading");    
    if (objImgLoading != undefined)
        objImgLoading.style.display = "none";
}

/**
 * This toggle between the divs that are contained in the left side panel of the map
 */
function togglePanels()
{
    searchPanel = document.getElementById("divCity-container");
    directionPanel = document.getElementById("directions");
    locationNamePanel = document.getElementById("location-names-container");
    noResultsPanel = document.getElementById("divNoResults");
    noDirectionResultsPanel = document.getElementById("divNoDirectionResults");
     
    
    if (searchPanel != undefined)
        searchPanel.style.display = "none";
        
    if (directionPanel != undefined)
        directionPanel.style.display = "none";
        
    if (locationNamePanel != undefined)
        locationNamePanel.style.display = "none";        
        
    if (noResultsPanel != undefined)
        noResultsPanel.style.diplay = "none";
        
    if (noDirectionResultsPanel != undefined)
    noDirectionResultsPanel.style.diplay = "none";
}

/**
 * Expands or slides out the div for the search results
 */
function expand(){  	        
    var div = document.getElementById("divList");
    div.style.width = "99%";

    clearTimeout(interrupt);
    clearTimeout(interruptResults);
        
    $("#divList").click(function() {
	    $(this).stop().animate({left:"0px"}, 1000);
    });
    
    interruptResults = setTimeout("switchResults('Expand')",100);
    interrupt = setTimeout("toggleBtn('0')",1000);
 }
 
 /**
 * Collapse or slides in the div for the search results
 */
 function collapse(){
    clearTimeout(interrupt);
    $("#divList").click(function() {
	    $(this).stop().animate({left:"71%"}, 1000);
    });
    interruptResults = setTimeout("switchResults('Collapse')",1000);
    interrupt = setTimeout("toggleBtn('1')",1000);	    	
} 

/**
 * Toggle the Expand and Collapse button when clicked
 */ 
function toggleBtn(value)
 {
    var expBtn = document.getElementById("listingExp");
    var colBtn = document.getElementById("listingColl");
    var div = document.getElementById("divList");
    
    if (value == "0")
    {
        expBtn.style.display = "none";
        colBtn.style.display = "block";
        
        if (language == "EN")
            colBtn.value = "Hide Details >>";
        else if (language == "ES")
            colBtn.value = "Ocultar Detalles >>";
        else            
            colBtn.value = "Masquer Details >>";
    }
    else
    {
        expBtn.style.display = "block";
        colBtn.style.display = "none";
        div.style.width = "28%";
        
        if (language == "EN")
            expBtn.value = "<< Show Details";
        else if (language == "ES")
            expBtn.value = "<< Mostrar Detalles";
        else            
            expBtn.value = "<< Montrer Details";
    }
 }
 
 /**
  * Hides or Show the results divs when expand and collasping.
  */
 function switchResults(value)
 {
    if (value == "Expand")
    {
        document.getElementById("results-layout").style.display = "none";
        document.getElementById("results-slider").style.display = "block";
    }  
    else
    {
        document.getElementById("results-layout").style.display = "block";
        document.getElementById("results-slider").style.display = "none";
    }
 }

/**
 * This function passed directions parameters and opens MapDirections
 */
function PassDirections(locationName, locationPhone, endAddress, startAddress)
{
    window.open("MapDirections.aspx?Location=" + locationName + "&Phone=" + locationPhone + "&EndAddress=" + endAddress + "&StartAddress=" + startAddress + "&Brand=" + brand + "&Language=" + language);
}
 
/**
 * Changes tables rows
 */ 
function changeRow(tableRow, highLight, changeColor)
{      
    if (highLight) 
        tableRow.bgColor = changeColor;
    else 
        tableRow.bgColor = changeColor;
}

/**
 * Shows the Locations results div in the left side panel of the map.
 */
function ShowLocationResults()
{
    ClearRoute();
    //add legend control
    AddLegendControl();
     
    // resizes the map
    var height = location.querystring["Height"];
    var layoutHeight = height * .80 - 62;
    document.getElementById("myMap").style.width = "70%";
    document.getElementById("myMap").style.height = "99%";
    
    document.getElementById("divPOI-header").style.display = "none";   
    document.getElementById("divCity-container").style.display = "none";
    document.getElementById("location-names-container").style.display = "none";
    document.getElementById("divNoResults").style.display = "none";
    document.getElementById("divNoDirectionResults").style.display = "none";
	document.getElementById("results-layout").style.display = "none";
	document.getElementById("directions").style.display = "none";
    document.getElementById("divList").style.display = "block";
    document.getElementById("results-layout").style.display = "block";
    document.getElementById("results-layout").style.overflow = "auto";
    document.getElementById("results-layout").style.height = layoutHeight + "px";
    document.getElementById("results-slider").style.height = layoutHeight + "px";
   //togglePanels();  
}

function ShowGroupPagesResults() {
    ClearRoute();
    //add legend control
    AddLegendControl();

    // resizes the map
    var height = location.querystring["Height"];
    var layoutHeight = height * .80 - 62;
    document.getElementById("myMap").style.width = "70%";
    document.getElementById("myMap").style.height = "99%";

    document.getElementById("divPOI-header").style.display = "none";
    document.getElementById("divMap-header").style.display = "none";
    document.getElementById("divCity-container").style.display = "none";
    document.getElementById("location-names-container").style.display = "none";
    document.getElementById("divNoResults").style.display = "none";
    document.getElementById("divNoDirectionResults").style.display = "none";
    document.getElementById("results-layout").style.display = "none";
    document.getElementById("directions").style.display = "none";
    document.getElementById("divList").style.display = "block";
    document.getElementById("results-layout").style.display = "block";
    document.getElementById("results-layout").style.overflow = "auto";
    document.getElementById("results-layout").style.height = layoutHeight + "px";
    document.getElementById("results-slider").style.height = layoutHeight + "px";
    //togglePanels();  
}

/**
 * Shows the City results div in the left side panel of the map.
 */
function ShowCityResults()
{
    ClearRoute();
    DeleteAllShape();
    //add legend control
    //AddLegendControl();
    TypeOfSearch("None");
    // resizes the map
    var height = location.querystring["Height"];
    var layoutHeight = height + .5 * .80 - 62;
    document.getElementById("myMap").style.width = "70%";
    document.getElementById("myMap").style.height = "99%";
       
    document.getElementById("divCity-container").style.display = "block";
    document.getElementById("location-names-container").style.display = "none";
    document.getElementById("divNoDirectionResults").style.display = "none";
    document.getElementById("divNoResults").style.display = "none";
    document.getElementById("divList").style.display = "none";
	//document.getElementById("results-layout").style.display = "none";
	document.getElementById("directions").style.display = "none";
    document.getElementById("divPOI-header").style.display = "none";
    
    DisableImgLoading();       
}

/**
 * Shows the Service Provider results div in the left side panel of the map.
 */
function ShowServiceProviderResults()
{
    ClearRoute();
    DeleteAllShape();
    //add legend control
    //AddLegendControl();
    TypeOfSearch("None");
     
    // resizes the map
    document.getElementById("myMap").style.width = "70%"; 
    document.getElementById("myMap").style.height = "99%";
//    document.getElementById("divMap").style.height = "562px";
//    document.getElementById("tableMap").style.height = "100px";
    
    document.getElementById("location-names-container").style.display = "block";
    document.getElementById("divNoDirectionResults").style.display = "none";
    document.getElementById("divNoResults").style.display = "none";
    document.getElementById("divCity-container").style.display = "none";
    document.getElementById("divList").style.display = "none";
	//document.getElementById("results-layout").style.display = "none";
	document.getElementById("directions").style.display = "none";
    document.getElementById("divPOI-header").style.display = "none";
     
    DisableImgLoading();       
}

/**
 * Shows the No results div in the left side panel of the map.
 */
function ShowNoResults()
{
    ClearRoute();
    DeleteAllShape();
    TypeOfSearch("None");
         
    // resizes the map
    document.getElementById("myMap").style.width = "70%"; 
    document.getElementById("myMap").style.height = "99%";
    
    document.getElementById("divNoResults").style.display = "block";
    document.getElementById("divNoDirectionResults").style.display = "none";
    document.getElementById("location-names-container").style.display = "none";
    document.getElementById("divCity-container").style.display = "none";
    document.getElementById("divList").style.display = "none";
	//document.getElementById("results-layout").style.display = "none";
	document.getElementById("directions").style.display = "none";
	document.getElementById("divPOI-header").style.display = "none";
    
     
    DisableImgLoading();       
}

function ShowNoJumpPages()
{
    //ClearRoute();
    //DeleteAllShape();
    //TypeOfSearch("None");
         
    // resizes the map
    document.getElementById("myMap").style.width = "70%"; 
    document.getElementById("myMap").style.height = "99%";
    
    document.getElementById("divNoResults").style.display = "block";
    document.getElementById("divNoDirectionResults").style.display = "none";
    document.getElementById("location-names-container").style.display = "none";
    document.getElementById("divCity-container").style.display = "none";
    document.getElementById("divList").style.display = "none";
	//document.getElementById("results-layout").style.display = "none";
	document.getElementById("directions").style.display = "none";
	document.getElementById("divPOI-header").style.display = "none";
    
     
    DisableImgLoading();       
}

/**
 * Shows the No direction results div in the left side panel of the map.
 */
function ShowNoDirectionResults(){
    // resizes the map
    document.getElementById("myMap").style.width = "70%"; 
    document.getElementById("myMap").style.height = "99%";

    document.getElementById("divNoDirectionResults").style.display = "block";
    //document.getElementById("divNoDirectionResults").style.display = "none";
    document.getElementById("divNoResults").style.display = "none";
    document.getElementById("location-names-container").style.display = "none";
    document.getElementById("divCity-container").style.display = "none";
    document.getElementById("divList").style.display = "none";
    //document.getElementById("results-layout").style.display = "none";
    document.getElementById("directions").style.display = "none";
    document.getElementById("divPOI-header").style.display = "none";
}

/**
 * Hides all divs and map when there is a page error
 */
function NoLocationIDFound()
{
    document.getElementById("divMap-container").style.display = "none";
}

/**
 * Custom watermark on a textbox when textbox has focus
 */
function DoWaterMarkOnFocus(ctrl, text)
{
    if (ctrl.value == text)
        ctrl.value = "";
    
    ctrl.className = "non-watermark-textbox";
}

/**
 * Custom watermark on a textbox when textbox has loses focus
 */
function DoWaterMarkOnBlur(ctrl, text)
{
    if (ctrl.value == "")
    {
        ctrl.value = text;
        ctrl.className = "watermark-textbox";        
    }
    else
    {
        ctrl.className = "non-watermark-textbox";        
    }   
}

function OnKeyUpPlots(e)
{

if (window.event.keyCode != undefined)
{
    if (window.event.keyCode == 13)
        document.getElementById('imgDirections').click();  
}
else
{
    var intKey = (window.Event) ? e.which : e.keyCode;
    if (intKey == 13) { //enter key
        document.getElementById('imgDirections').click();
        return false;
    }
    return true;
}

}





