﻿// JScript File

// displayInfo object
function displayInfo(expandimgsrc, expandtext, collapseimgsrc, collapsetext)
{
    this.expandimg = new Image();
    this.expandimg.src = expandimgsrc;  // Preload img
    this.expandimg.alt = expandtext;
    this.expandimg.title = expandtext;

    this.collapseimg = new Image();
    this.collapseimg.src = collapseimgsrc;  // Preload img
    this.collapseimg.alt = collapsetext;
    this.collapseimg.title = collapsetext;
}

// Create objects
// 0 - Group
// 1- Items
var arrDisplayInfo = new Array();
arrDisplayInfo[0] = new displayInfo("Controls/SearchResults/Images/expandgrp.gif", "Expand", "Controls/SearchResults/Images/collapsegrp.gif", "Collapse");
arrDisplayInfo[1] = new displayInfo("Controls/SearchResults/Images/plus.gif", "Expand", "Controls/SearchResults/Images/minus.gif", "Collapse");

function expand(id, type)
{
    var elem = document.getElementById(id);
    if (elem)
    { 
        elem.style.display = 'block';
        elem.style.visibility = 'visible';
        var imgname = 'img' + elem.id;
        document[imgname].src = arrDisplayInfo[type].collapseimg.src;
        document[imgname].title = arrDisplayInfo[type].collapseimg.title;
        document[imgname].alt = arrDisplayInfo[type].collapseimg.alt;
    }
}

function collapse(id, type)
{
    var elem = document.getElementById(id);
    if (elem)
    { 
        elem.style.display = 'none';
        elem.style.visibility = 'hidden';
        var imgname = 'img' + elem.id;
        document[imgname].src = arrDisplayInfo[type].expandimg.src;
        document[imgname].title = arrDisplayInfo[type].expandimg.title;
        document[imgname].alt = arrDisplayInfo[type].expandimg.alt;
    }
}

function expandAll(id, type)
{
    var divs = document.getElementsByTagName("div");
    for (var i=0; i<divs.length; i++)
    {
        if (divs[i].id.indexOf(id) != -1)
            expand(divs[i].id, type);
    }
}

function collapseAll(id, type)
{
    var divs = document.getElementsByTagName("div");
    for (var i=0; i<divs.length; i++)
    {
        if (divs[i].id.indexOf(id) != -1)
            collapse(divs[i].id, type);
    }
}

function toggleDisplay(id, type)
{
    var elem = document.getElementById(id);
    if (elem) 
    {
        if (elem.style.display == 'block') 
        {
            collapse(id, type);
        } 
        else
        {
            expand(id, type);
        }
    }
}

function hideControl(id)
{
    var elem = document.getElementById(id);
    if (elem) 
    {
        elem.style.display = 'none';
        elem.style.visibility = 'hidden';
    }
}