
function initCommon()
{
    // Hook into startup for every page - enable global control at startup
}


function setClass( poElement, psClassName)
{
    document.getElementById( poElement ).className = psClassName;
}

function stateJumpMenu(poSelect,psDiseaseId,psRegionId)
{
    psRegion = poSelect.options[ poSelect.selectedIndex ].value;
    if( psRegion == 0 ) { return 0 }
    window.location = psDiseaseId + '_' + psRegion + '_' + psRegionId + '.html';
}

function urlJumpMenu(poSelect)
{
    psUrl = poSelect.options[ poSelect.selectedIndex ].value;
    if( psUrl == 0 ) { return 0 }
    window.location = psUrl;
}

function handleCursor(psDOMid,psType)
{
    document.getElementById(psDOMid).style.cursor = psType;
}



function displayIcon()
/*
    USES:
        oIconImageHash
        document.getElementById('titleIconImg')
*/
{
    // CHECK IF PARAMETER PASSED
    var sUrl = window.location.href;
    if( 
        sUrl.indexOf('?') != -1                                 // IF PARAMETER DETECTED 
        &&   sUrl.split('?')[1].indexOf('adjacent=') == -1      // AND PARAMETER DOES NOT CONTAIN 'adjacent='
    )
    {
        var aUrl = sUrl.split('?');
        if( aUrl[1].indexOf('http%3A%2F%2F') != -1 )    // IF PARAMETER IS URL - encoded using encodeURIComponent() - expecting "http://"
        {
            document.getElementById('titleIconImg').src = decodeURIComponent( aUrl[1] );
        }
        else    // SET IMAGE FILE USING PARAMETER
        {
            document.getElementById('titleIconImg').src = sIconImgPath + '/' + sIconImgPrefix + aUrl[1] + '.' + sIconImgExt;
        }
        return;
    }

    //READ HASH RULE TO DETERMINE WHICH IMAGE(S) TO DISPLAY
    aImages = processRule(oIconImageHash);

    if( !aImages.length ) { return 0 }  // QUIT IF NO IMAGE FOUND

    //IF MULTIPLE IMAGES TO DISPLAY, THEN RANDOMLY DISPLAY
    ImgCount = aImages.length;
    var ranval = Math.random();
    nSelectedImg = Math.floor(ranval * ImgCount);

    // SET IMAGE DISPLAY
    document.getElementById('titleIconImg').src = sIconImgPath + '/' + sIconImgPrefix + aImages[nSelectedImg] + '.' + sIconImgExt;
}


function processRule(poHash)
/*
    USES:
        diseaseId
        categoryName
        regionId
*/
{
    // DETERMINE WHICH DISEASE, CATEGORY, REGION
    //
    if ( poHash[diseaseId] )                                        //   TEST DISEASE
    {
        if ( poHash[diseaseId][categoryName] )                      //   TEST CATEGORY
        {
            if ( poHash[diseaseId][categoryName][regionId] )        //   TEST REGION
            {
                return poHash[diseaseId][categoryName][regionId];   //   SET IMAGE
            }
            else if ( poHash[diseaseId][categoryName]['all'] )      //   TEST REGION is 'all'
            {
                return poHash[diseaseId][categoryName]['all'];      //   SET IMAGE
            }
            else  // otherwise quit and use image defined in HTML
            {
                return 0;                                           //   else use existing 
            }
        }
        else if ( poHash[diseaseId]['all'] )                        //   TEST CATEGORY is 'all'
        {
            if ( poHash[diseaseId]['all'][regionId] )
            {
                return poHash[diseaseId]['all'][regionId];          //   SET IMAGE
            }
            else if ( poHash[diseaseId]['all']['all'] )
            {
                return poHash[diseaseId]['all']['all'];             //   SET IMAGE
            }
            else
            {
                return 0;                                           //   else use existing 
            }
        }
        else  // otherwise quit and use image defined in HTML
        {
            return 0;                                               //   else use existing 
        }
    }
    else if ( poHash['all'] )  // Test if 'all' rule exists         //   TEST DISEASE is 'all'
    {
        if ( poHash['all'][categoryName] )
        {
            if ( poHash['all'][categoryName][regionId] )
            {
                return poHash['all'][categoryName][regionId];       //   SET IMAGE
            }
            else if ( poHash['all'][categoryName]['all'] )
            {
                return poHash['all'][categoryName]['all'];          //   SET IMAGE
            }
            else
            {
                return 0;                                           //   else use existing 
            }
        }
        else if ( poHash['all']['all'] )
        {
            if ( poHash['all']['all'][regionId] )
            {
                return poHash['all']['all'][regionId];              //   SET IMAGE
            }
            else if ( poHash['all']['all']['all'] )
            {
                return poHash['all']['all']['all'];                 //   SET IMAGE
            }
            else
            {
                return 0;                                           //   else use existing 
            }
        }
        else
        {
            return 0;                                               //   else use existing 
        }
    }
    else  // otherwise quit and use image defined in HTML
    {
        return 0;                                                   //   else use existing 
    }
}

