
 var pnlSearchParams = null;
 var btnSearch = null;
 var pnlResults = null;
 var lblMessage = null;
 var spanToggleLink = null;
 var hasSearched = 0;
 var resultCount = 0;
 var isPinned = 0;
 var showResults = 0;
 var searchParamsPanel = 1;
 var resultsPanel = 0;
   
/* 
 Basic logic rules
 
 If a result has been performed and there are results: Show results and lblMessage
 If a result has been performed with no results: Don't show results, but do show lblMessage
 If a result hasn't been performed: Hide results; hide lblMessage
 
 If a result hasn't been performed: Always show params
 If a result has been performed but no results: Show params
 If a result has been performed with results: Hide params _unless_ the user has pinned
 
 On load - set the display parameters of each item
 
 Add a toggle function for parameters
 
 */
 
function toggleSearchParamsPanel() {
    setSearchParamsPanelDisplay(searchParamsPanel ? 0:1);
}
    
function setSearchParamsPanelDisplay(newval) {
    
    searchParamsPanel = newval;
    pnlSearchParams.style.display = (searchParamsPanel ? "block" : "none");
    btnSearch.style.display = (searchParamsPanel ? "block" : "none");
    var imgHtml = "";
    if (searchParamsPanel) {
        spanToggleLink.innerHTML = imgHtml + "Hide Search Options";
        //spanToggleLink.className = 'Toggle';
        spanPinLink.style.display = "";
    } else {
        spanToggleLink.innerHTML = imgHtml + "Show Search Options";
        //spanToggleLink.className = 'Toggle';
        setPinned(0);
        spanPinLink.style.display = "none";
    }
}

function toggleResultsPanel() {
    setResultsPanelDisplay(resultsPanel ? 0:1);
}

function setResultsPanelDisplay(newval) {
    resultsPanel = newval;
    if (pnlResults != null)
    {
        pnlResults.style.display = ((resultCount && resultsPanel) ? "block" : "none");
    }
    
}
    
// Set the initial display values for the various panels
function setDefaultPanelDisplay() {

    if (!pnlSearchParams) { initialisePanelDisplay(); }
    var isPinned = getPinnedStatus();
    // set the various local vals
    if (hasSearched) {
        spanToggleLink.style.display = "";
        setResultsPanelDisplay(1);
      
        setSearchParamsPanelDisplay(!resultCount || isPinned ? 1 : 0);
        //setSearchParamsPanelDisplay(isPinned ? 1 : 0);
    } else {
        spanToggleLink.style.display = "none";
        setResultsPanelDisplay(0);
        setSearchParamsPanelDisplay(1);
    }
    
    if (isPinned) {
        spanPinLink.innerHTML = "<img src='../Graphics/buttons/toggle-on.png' alt='Clicking this will prevent the search box from staying open' title='Clicking this will prevent the search box from staying open' border='0'>";
    } else {
        spanPinLink.innerHTML = "<img src='../Graphics/buttons/toggle.png' title='Clicking this will force the search box to stay open' alt='Clicking this will force the search box to stay open' border='0'>";
    }
    /*
    if (hasSearched) {
        if (resultCount) {
            lblMessage.innerHTML = "" + resultCount + " result(s) found";
        } else {
            lblMessage.innerHTML = "<strong>No results found</strong>";
        }
    }
    */
}

function togglePanelDisplay() {
    // legacy 
    toggleSearchParamsPanel();   
}
    
/* Pinning */
function getPinnedStatus() {
var dc = document.cookie;
if (dc.indexOf("; isParamsPinned=1") > -1) {
 return true;
} else if (dc.indexOf("isParamsPinned=1") == 0) {
 return true;
}
return false;
}
   
function setPinned(pinval) {
document.cookie = "isParamsPinned="+pinval;
isPinned = pinval;
    if (isPinned) {
        spanPinLink.innerHTML = "<img src='../Graphics/buttons/toggle-on.png' alt='Clicking this will prevent the search box from staying open' title='Clicking this will prevent the search box from staying open' border='0'>";
    } else {
        spanPinLink.innerHTML = "<img src='../Graphics/buttons/toggle.png' alt='Clicking this will force the search box to stay open' title='Clicking this will force the search box to stay open' border='0'>";
    }
}

function togglePinOption() {
  setPinned((isPinned?0:1));
}
/* END Pinning */
       
setDefaultPanelDisplay();