/**
 * Toggle.
 */          
function fT(a)
{    
    var v = (a.value != undefined) ? a.value : a;
                             
    rS(v);    
    
    var del = v.lastIndexOf('$');
    var grp = v.substring(0, del);    
    var val = v.substring(del);
        
    for(var i = $CSA.length - 1; i >= 0; --i)
    {        
    // Whip through each case study...
        
        var id = 'CS' + $CSA[i].CSID;
                                
        if ($ELC[id] != null)
        {               
            var hide = false;
                                                                
            for(var e in $REQ)
            {
            // For every selection we have stored, test against the attributes our case study is assigned:
            
                var attrs = $REQ[e].$ATTRS;
                var type  = $REQ[e].TYPE;                 
                var mFlag = false;
                                
                for (var j = 0; j < attrs.length; j++)
                {
                // SINGLE types are mandatory when 1+ value is available; MULTIPLE types are "at least 1", when 1+ values are available:
                
                    var selection = e + attrs[j];
                    
                    if (type == 'SINGLE')
                    {           
                        if ($CSA[i].$ATTRS[selection] == undefined)        
                        {                        
                            hide = true;                            
                            break;
                        }
                    }
                    else if (type == 'MULTIPLE')
                    {
                        if ($CSA[i].$ATTRS[selection] != undefined)        
                        {
                            mFlag = true;                            
                            break;
                        }                    
                    }
                }
                
                if ((type == 'MULTIPLE') && (!mFlag) && (attrs.length > 0))
                {
                    hide = true;
                }
                   
                if (hide) { break; };
            }
                   
            if (hide)
            {
                $ELC[id].style.display = 'none';
            }                    
            else
            {                            
                $ELC[id].style.display = 'block';
            }                   
        }        
    }
};
/**
 * Cache elements.
 */
function cE()
{    
    for(var i = $CSA.length - 1; i >= 0; --i)
    {     
        var id = 'CS' + $CSA[i].CSID;
           
        $ELC[id] = gE(id);     
    }
};    
/**
 * Register/store selection.
 */
function rS(v)
{
    var del = v.lastIndexOf('$');
    var grp = v.substring(0, del);    
    var val = v.substring(del);
    var typ = $REQ[grp].TYPE;
  
    RegisterSearchView();
    
    switch (typ)
    {
        case 'SINGLE' :        

            $REQ[grp].$ATTRS = (val.length > 1) ? [val] : []; 
            
            if (val.length > 1)
            {
                RegisterUsage(val.substring(1));
            }
                       
        break;       
         
        case 'MULTIPLE' :         
        
            var a = $REQ[grp].$ATTRS;
            var x = false;
                        
            for (var i = 0; i < a.length; i++)
            {                
                if (a[i] == val) { $REQ[grp].$ATTRS.splice(i, 1); x = true; };
            }
            
            if (!x) 
            { 
                $REQ[grp].$ATTRS.push(val); 
                
                RegisterUsage(val.substring(1));
            };            
        break;
        
        default : break;
    }
};
/**
 * xBrow element fetch.
 */
function gE(id)
{
    var d = document;
    
    return((d.getElementById) ? d.getElementById(id) : ((d.all) ? d.all[id] : ((d.layers) ? d.layers[id] : null)));
};  
/**
 * Register usage of attribute.
 */
function RegisterUsage(ATID, CSID)
{         
    try 
    {                  
        SendXmlHttpRequest(GetXmlHttpObject(CB), $RURI + 'RegisterUsage.aspx?ATID=' + ((!isNaN(ATID)) ? ATID : '') + '&CSID=' + ((!isNaN(CSID)) ? CSID : '0')); 
    }
    catch(e)
    {
    } 
}
/**
 * Register usage of attribute.
 */
function RegisterSearchView()
{         
    try 
    {                  
        SendXmlHttpRequest(GetXmlHttpObject(CB), $RURI + 'RegisterSearchView.aspx?VIEW=1'); 
    }
    catch(e)
    {
    } 
}
/**
 * AJAX
 */         
function GetXmlHttpObject(handler)
{ 
    var o = null;
    
    if (!window.XMLHttpRequest)
    {
    // Microsoft
    
        o = GetMSXmlHttp();
        
        if (o != null)
        {
            o.onreadystatechange = handler;
        }
    } 
    else
    {
    // Mozilla | Netscape | Safari
    
        o = new XMLHttpRequest();
        
        if (o != null)
        {
            o.onload   = handler;
            o.onerror  = handler;
        }
    } 
    
    return o; 
} 
function GetMSXmlHttp() 
{
    var xmlHttp     = null;
    var clsids      = ["Msxml2.XMLHTTP.6.0","Msxml2.XMLHTTP.4.0","Msxml2.XMLHTTP.3.0"];
                    
    for(var i = 0; i < clsids.length && xmlHttp == null; i++) 
    {
        xmlHttp = CreateXmlHttp(clsids[i]);
    }
    
    return xmlHttp;
}
function CreateXmlHttp(clsid) 
{
    var xmlHttp     = null;
    
    try 
    {
        xmlHttp     = new ActiveXObject(clsid);
        lastclsid   = clsid;
        
        return xmlHttp;
    }
    catch(e) {}
}
function SendXmlHttpRequest(xmlHttp, url) 
{ 
    xmlHttp.open('GET', url, true);     
    xmlHttp.send(null); 
}
function CB()
{
}

