/*** new js for the new-look NGRF, especially some clientside post-processing of FT content  ***/

var g_special_FT_handling = 'none', g_thisHref = this_url, g_thisInfoBranch = '', g_thisFTSector = '', g_thisEGBranch, g_thisContentTitle

var g_dynamicStyleSheet, d_jsWritingStepsPending = '--make dropdown links--'


var g_addFTsubmenusToMainNav = g_thisHref.indexOf(portal_url + '/future-trends') > -1

function detectSpecialHandlingNeeds(){

    var path = g_thisHref.split(portal_url + '/future-trends/')
    
    
    if (g_thisHref.indexOf('ft-2008') > -1){
        path = g_thisHref.split(portal_url + '/workgroups/editorialWG/ft-2008/')
    }
    
   
  
    if (path.length < 2){
        detectSpecial_EG_HandlingNeeds()
        return
    }
    path = path[1].split('/')
    
    g_thisFTSector = path[0]
    
    if (g_thisFTSector == 'regions'){
        if (path[2] && (path[2].indexOf('sector') > -1)){
            g_thisRegion = path[1]
            g_special_FT_handling = 'regions_to_sectors'
        }
        return
    }
    if (g_thisFTSector == 'lmiresources') return
    if (g_thisFTSector == 'what-is'){
        if (path[1] && (path[1] == 'sector')){
            g_special_FT_handling = 'sectors_AtoZ_listing'
        }
        
        return
    }
    if (g_thisFTSector == 'lmift-bookmarks') return
    
    
    if (path.length < 2){
         g_special_FT_handling = 'sector_top'
         g_thisFTSector = path[0]
        return
    }

    if (path.length == 2){
         g_special_FT_handling = 'sector_branch'
         g_thisInfoBranch = path[1]
         
 ////        if (g_thisInfoBranch == 'data-charts') g_special_FT_handling = 'datacharts'
        return
    }
    if (path.length > 2){
         g_special_FT_handling = 'sector_deep'
         g_thisInfoBranch = path[1]
        return
    }

}

function detectSpecial_EG_HandlingNeeds(){

    var path = g_thisHref.split(portal_url + '/EG/')
    
    if (path.length < 2){
        return
    }
    path = path[1].split('/')
    
    g_thisEGBranch = path[0]

    if (path.length < 2){
        g_special_FT_handling = 'EGBranch_top'
        return
    }

    g_special_FT_handling = 'EG_deep'
    
 
}

detectSpecialHandlingNeeds()


function addDynamicStylesheet(){        // not using this yet

    g_dynamicStyleSheet = document.createElement('style');
    g_dynamicStyleSheet.type = 'text/css';
    g_dynamicStyleSheet.rel = 'stylesheet';
    g_dynamicStyleSheet.media = 'screen';
    g_dynamicStyleSheet.title = 'dynamicSheet';
    document.getElementsByTagName("head")[0].appendChild(g_dynamicStyleSheet);

}

function process_SectorTops(){


    var bcel = document.getElementById('bodyContent')

    var imgs = bcel.getElementsByTagName('IMG')
    var paras = bcel.getElementsByTagName('P')

    cloneSectorImages(imgs)
    processParas_FT_tops(paras)
    insertSubsectionLinks()
    
    changePagePrintHeader('NGRF - LMI Future Trends', 'Sector: ' + gk_sectorTitles[g_thisFTSector])
///    insertFTportlet()

}


function process_DataCharts(){

    var bcel = document.getElementById('bodyContent')
    var TOCel = document.getElementById('nav_test')
    if (bcel){

        bcel.innerHTML = bcel.innerHTML.replace(/<\/[aA]>\s*<\/([pP])>\s*<[pP][\w\s=":]*>/g, '</a>')           
        var imgs = bcel.getElementsByTagName('IMG')
        var paras = bcel.getElementsByTagName('P')
    
        bcel.innerHTML = processParas_FT_datacharts(paras)
        
        if(TOCel) TOCel.style.display = 'none'
    }

}

function process_SectorAtoZListing(){


    var summaryDivs = filterForClass('related summary_subs', document.getElementsByTagName('DL'))
    if (summaryDivs.length) {
        summaryDivs[0].style.display = 'none'   // only there for the from here menu to pick up
    }
    
    var nestedDivs = filterForClass('nested_bodyContent stx', document.getElementsByTagName('DIV')), s = ''
    var nestedHeads = filterForClass('indexFolderNestedHeading', document.getElementsByTagName('H2'))
    
    if (nestedDivs.length == 0) nestedDivs = filterForClass('nested_bodyContent', document.getElementsByTagName('DIV'))
    
    if (nestedDivs.length == 0) nestedDivs = [document.getElementById('bodyContent')] // subsection


    for (var i=0; i < nestedDivs.length; i++){
        var onediv = nestedDivs[i], paras = onediv.getElementsByTagName('p')
        var tableS = '<table width="100%" id="ft_data_charts_UI">', M = paras.length, extrasS = ''
        
//        tableS += '<tr><th colspan="2">' + nestedHeads[i].innerHTML + '</th></tr>'


        for (var j = 0; j < M; j++){
            tableS += processOneSectiorsAtoZpara(paras[j], j+1)
        }
        
        if (j % 2){ // the last cell was not matched by a second one in the row
            tableS = tableS.split('id="dccell_' +j + '"').join(' colspan="2" id="dccell_' +j + '"') + '</tr>'
        }
    
        tableS += '</table>'
        nestedDivs[i].innerHTML = tableS
        nestedDivs[i].className = ''
 //       s += tableS
    }
    
    
}



function processOneSectiorsAtoZpara(onePara, j, inSectorDepths){
    
    
    var s = ''
    
    var ncols = inSectorDepths ? 3 : 2
    
    var imgstr = gk_datachartsThumbnailStr  /////// .split('**sector**').join(g_thisFTSector)
    
    var img_url__hack__tmpl= '<img src="/webdav_uploads/NEWNGRF_FILES/FT_DC_thumbnails/'
    
    if (onePara.innerHTML.length < 10) return ''
    
    
    var thisphtml = ''

    var links_in_p = onePara.getElementsByTagName('A')
    var subheads_in_p = onePara.getElementsByTagName('STRONG')
    
    var oneCellstart = '<td id="dccell_' +j + '">', oneCellend = '</td>', oneIMGsub = imgstr

    var treatAsChartLink = links_in_p.length
        ? (links_in_p[0].href.indexOf('/data-charts') !=  links_in_p[0].href.length - 12)
        : 0;

    if (treatAsChartLink){ // try to insert a thumbnail for the linked-to id
        var srcspec = links_in_p[0].href, srcParts =  srcspec.split('/'), srcID = srcParts[srcParts.length-1], thisIMG = ''
        
        if (srcID.length < 2) srcID = srcParts[srcParts.length-2] // trailing slash
        if (srcID == 'view') srcID = srcParts[srcParts.length-2] // trailing template name

        if (inSectorDepths){
            var thispath = srcspec.split('/future-trends/')
            if (thispath.length > 1) srcID = thispath[1].split('/')[0]
        }
        if (gk_sectorECImg[srcID]){
            thisIMG = img_url__hack__tmpl + srcID + '/TNS/' + gk_sectorECImg[srcID] + '" />'   
            
            
            thisIMG = '<a href="' + portal_url + '/future-trends/' + srcID + '" title = "Click to view this sector">' + thisIMG + '</a>'
        }

        if ((j % ncols) == 1){

            oneCellstart = '<tr><td id="dccell_' +j + '">'
        }
        if ((j % ncols) == 0){

            oneCellend = '</td></tr>'
        }
        
        if(links_in_p.length >= 1){ // else put in a cell but do not expect a thumbnail etc
            var testHTMLstr = links_in_p[0].innerHTML + '</a>'
            links_in_p[0].title = 'Click to view this chart/data'
            links_in_p[0].className = 'mainDClink'
            var linkToCurSector = portal_url + '/future-trends/' + srcID 
            links_in_p[0].href = linkToCurSector
            
            for (var j=1; j < links_in_p.length; j++){
                var onelinkWithinSector = links_in_p[j].href.split(srcID)
                if(onelinkWithinSector.length > 1){
                    links_in_p[j].href = linkToCurSector + onelinkWithinSector[1]
                }
            }
            
            thisphtml = onePara.innerHTML
        
            
            if (thisphtml.indexOf(testHTMLstr) > -1){
                thisphtml = thisphtml.split(testHTMLstr).join(testHTMLstr + ' <p>' + thisIMG) + '</p>'
            }else if (thisphtml.indexOf('</A>') > -1){
                testHTMLstr = links_in_p[0].innerHTML + '</A>'
                thisphtml = thisphtml.split(testHTMLstr).join(testHTMLstr + ' <p>' + thisIMG) + '</p>'
            }
        }else if (onePara.className == 'treatAsTableCell'){
            thisphtml = '<p class="treatAsTableCell">' + onePara.innerHTML +'</p>'
        }
        s += oneCellstart + thisphtml + oneCellend
    }else{
    
        if (subheads_in_p.length){  // need this to strike a TH for the subhead, and finish the row behind if nec
            if ((j % ncols) > 0){ // the last cell was not matched by a second one in the row
                s = s.split('id="dccell_' + j + '"').join(' colspan="' + (ncols+1-j) + '" id="dccell_' +j + '"') + '</tr>'
                j++ // start again at an odd number higher than any seen so far
            }
            s += '<tr><th colspan="2">' + subheads_in_p[0].innerHTML + '</th></tr>'
        }else{
            extrasS += '<p>' + onePara.innerHTML + '</p>'
        }
    }
   
    return s
    
}

function sectorLinkStr(istop){

    var template = istop ? gk_ftsector_linkStrFromtop : gk_ftsector_linkStrFromDeep


    var s = template.split('**sector**').join(gk_sectorTitles[g_thisFTSector])
    s = s.split('**sectorURL**').join(portal_url + '/future-trends/' + g_thisFTSector)
    return s
}

function repositionNavwidgets(){ } // stub to be over-ridden by footer-loaded js

function changePagePrintHeader(mainhead, subhead){

    var headel = document.getElementById('portalHeader')
    if (headel) headel.innerHTML = mainhead + (subhead ? ' <i>' + subhead + '</i>' : '')

    document.title = mainhead + ' - ' + (g_thisContentTitle ? g_thisContentTitle + ' (' + subhead + ')' : subhead)

    repositionNavwidgets() // hack to put this here - now we have abs-pos inner nav, they have to be repositoned after adding content above

    window.setTimeout('repositionNavwidgets(),500')}

function process_SectorBranches(){
    
    var s = gk_level2HeadReplaceStr.split('**sectorLinkStr**').join(sectorLinkStr())
    
    var descrel = filterForClass('documentDescription', document.getElementsByTagName('DIV'), 1)
    var mainh1el = filterForClass('documentFirstHeading', document.getElementsByTagName('H1'), 1)
    

    s = s.split('**imgsrc**').join(gk_bgForInfoBranch[g_thisInfoBranch])
    s = s.split('**branch**').join(gk_sectorinfo_shortTitle[g_thisInfoBranch])

    s = s.split('**descr**').join((descrel ? descrel.innerHTML : ''))

    g_thisContentTitle = mainh1el.innerHTML
    mainh1el.innerHTML = s
    mainh1el.className = 'specialFTH1'
    if (descrel) descrel.style.display = 'none'
    
    changePagePrintHeader('NGRF - LMI Future Trends', 'Sector: ' + gk_sectorTitles[g_thisFTSector])

    insertFTportlet(g_thisInfoBranch)
    
    if (g_thisInfoBranch == 'data-charts') {
        process_DataCharts()
    }
    
}


function process_SectorDepths(){
    
    var crumbsEl = document.getElementById('portlet-breadcrumbs')
    var crumbs = crumbsEl.getElementsByTagName('A')
    var localCrumbs = '', startLocalCrumbs = 4, endLocalCrumbs = crumbs.length - 1
    for(var i= startLocalCrumbs; i < endLocalCrumbs; i++){
        localCrumbs += '<a href="' + crumbs[i].href + '" title="Navigate up to the '
            + crumbs[i].innerHTML + ' page">:: ' + crumbs[i].innerHTML + '</a>'
    }
    
    var descrel = filterForClass('documentDescription', document.getElementsByTagName('DIV'), 1)
    var mainh1el = filterForClass('documentFirstHeading', document.getElementsByTagName('H1'), 1)
    
    g_thisContentTitle = mainh1el.innerHTML
    
    var s = gk_levelDeepHeadReplaceStr.split('**sectorLinkStr**').join(sectorLinkStr())
    
    s = s.split('**localCrumbsstr**').join(localCrumbs)
    s = s.split('**curTitleStr**').join(mainh1el.innerHTML)
    
    s = s.split('**imgsrc**').join(gk_bgForInfoBranch[g_thisInfoBranch])
    s = s.split('**branchURL**').join(portal_url + '/future-trends/' + g_thisFTSector + '/' + g_thisInfoBranch)
    
    
    
    s = s.split('**branch**').join(gk_sectorinfo_shortTitle[g_thisInfoBranch])
    s = s.split('**descr**').join((descrel ? descrel.innerHTML : ''))

    mainh1el.innerHTML = s
    mainh1el.className = 'specialFTH1'
    if (descrel) descrel.style.display = 'none'
    
    insertFTportlet(g_thisInfoBranch)
    changePagePrintHeader('NGRF - LMI Future Trends', gk_sectorinfo_shortTitle[g_thisInfoBranch] + ' for sector: ' + gk_sectorTitles[g_thisFTSector])
    
        
    if (g_thisInfoBranch == 'data-charts') {
        if(gk_ftdc_subfolders_asdc[g_thisFTSector]){
            var splits = g_thisHref.split('/'), thisid = splits[splits.length-1]
            var specialSubs = gk_ftdc_subfolders_asdc[g_thisFTSector]
            for (var i=0; i < specialSubs.length; i++){
                if(specialSubs[i] == thisid){
                    process_DataCharts()
                }
            }

        }
    }

}


function process_regionsToSectors(){

    //// make the header special, wiuth region image
    
    var mainh1el = filterForClass('documentFirstHeading', document.getElementsByTagName('H1'), 1)
    var regionName = gk_regionTitles[g_thisRegion], headstr = gk_regiontosectorHeadReplaceStr.split('**regionid**').join(g_thisRegion)
    
    headstr = headstr.split('**regionName**').join(regionName)
    
    if (g_thisRegion == 'scotland') headstr = headstr.split('tiny.jpg').join('tiny.png') // wottahack!

    mainh1el.innerHTML = headstr
    mainh1el.className = 'specialFTH1'
    
    // make the paras special, with sector-rep images
    
    var bcel = document.getElementById('bodyContent')

    var linksBoxhtml = '<dl class="related"><dt>' + gk_regionTitles[g_thisRegion] + ' - information for sectors:</dt><dd>'
    
    var linksSrc = bcel.innerHTML.split('<p').join('<p class="sublink" ')
    linksSrc = linksSrc.split('<P').join('<P class="sublink" ')
    linksBoxhtml += linksSrc

    var eyecandystr = '<img style="float:right;" src="/webdav_uploads/NEWNGRF_FILES/ngrf_content/ft_sector_imgs/sectors_collage_large.jpg"'
    + 'width="248" height="212" border="0" />'

    bcel.innerHTML = linksBoxhtml + '</dd></dl>' ////+ eyecandystr
    
    
//    bcel.className = 'sectorsList'


    changePagePrintHeader('NGRF - LMI Future Trends', 'Regional information by sector for: ' + gk_regionTitles[g_thisRegion])
    
}

function insertFTportlet(infoBranch){


    var sectorBaseURL = portal_url + '/future-trends/' + g_thisFTSector + '/'
    var s = gk_ftinfosportlet_HTML
    
    if (infoBranch) s = s.split('href="' + infoBranch + '"').join('class="hilited" href="' + infoBranch + '"')
    
    s = s.split('href="').join('href="' + sectorBaseURL)
    
/////////////alert(s.indexOf('class="hilited"'))
    
    var crumbsEl = document.getElementById('portlet-breadcrumbs')
    
    crumbsEl.id = 'FTsector_detail_portlet'
    crumbsEl.className = ''
    
    crumbsEl.innerHTML = s
    

}

function hiliteCurrentInNavTree(){
    var navtree = document.getElementById('portlet-navigation-tree')
    if (navtree) {}
    else navtree = document.getElementById('EG_navigation_portlet')
    
    if (navtree){
        var links = navtree.getElementsByTagName('A'), N= links.length, compareCurURL = g_thisHref + '/'

        for(var i=0; i < N; i++){
            if (compareCurURL.indexOf(links[i].href) > -1){
                links[i].className = links[i].className + ' hilited'
            }else if (links[i].className.indexOf(' hilited') > -1){            
                links[i].className = links[i].className.split(' hilited').join('')
            }
        }
    }
}
function process_EGTops(){

    process_EG_Depths()

}


function process_EG_Depths(){

    var branch =  gk_EG_pseudoBranch[g_thisEGBranch]
    
    var s = gk_EG_DeepHeadReplaceStr

    var crumbsEl = document.getElementById('portlet-breadcrumbs')
    var crumbs = crumbsEl.getElementsByTagName('A')
    var localCrumbs = ''
    
    var descrel = filterForClass('documentDescription', document.getElementsByTagName('DIV'), 1)
    var mainh1el = filterForClass('documentFirstHeading', document.getElementsByTagName('H1'), 1)

    if (mainh1el) {

        if(g_special_FT_handling != 'EGBranch_top'){
            var startLocalCrumbs = 3, endLocalCrumbs = crumbs.length - 1
            localCrumbs = gk_EGtop_linkStrFromDeep.split('**branch**').join(g_thisEGBranch)
            localCrumbs = localCrumbs.split('**branchTitle**').join(gk_EG_topTtitles[g_thisEGBranch])
           
    
            for(var i= startLocalCrumbs; i < endLocalCrumbs; i++){
                localCrumbs += ' <a href="' + crumbs[i].href + '" title="Navigate up to the '
                    + crumbs[i].title.split('go to').join('') + ' page"><em>&gt;</em> ' + crumbs[i].innerHTML + '</a>'
            }
            
           g_thisContentTitle = mainh1el.innerHTML
        }
    
    
        var s = gk_EG_DeepHeadReplaceStr.split('**localcrumbs**').join(localCrumbs)
        
        s = s.split('**curTitleStr**').join(mainh1el.innerHTML)
    
        s = s.split('**descr**').join((descrel ? descrel.innerHTML : ''))
    
        mainh1el.innerHTML = s
        mainh1el.className = 'EGH1 ' + (g_special_FT_handling == 'EGBranch_top' ? 'EGBranch_top EGBranch_top_' + branch  : 'EGH1_' + branch)

        if (descrel) descrel.style.display = 'none'
        if (crumbsEl) crumbsEl.style.display = 'none'
    
    }


    

    
    changePagePrintHeader('NGRF - ' + gk_EG_branchTitles[branch], gk_EG_topTtitles[g_thisEGBranch]) //  + '; Making Guidance More Effective')
    

}


function cloneSectorImages(imgobjs){
    var s = ''
    for (var i = 0; i < imgobjs.length; i++){
        s += '<img src="' + imgobjs[i].src + '" class="visualNoprint" height="120">\r'
    }
    
    var mainh1el = filterForClass('documentFirstHeading', document.getElementsByTagName('H1'), 1)
    var descrel = filterForClass('documentDescription', document.getElementsByTagName('DIV'), 1)

    var contentEl = mainh1el.parentNode
    var imgsBanner = document.createElement('DIV')
    imgsBanner.className = 'sector_eyecandy visualNoprint'
    imgsBanner.innerHTML = s
    contentEl.insertBefore(imgsBanner, mainh1el)
    mainh1el.innerHTML = gk_crumbsFromFTSector + sectorLinkStr('top') // mainh1el.innerHTML
    mainh1el.className = 'specialFTH1'
    if (descrel){
        mainh1el.innerHTML = mainh1el.innerHTML + '<span class="descrinhead">' + descrel.innerHTML + '</span>'
        descrel.style.display = 'none'
    }
}


function processParas_FT_tops(paras){


    for (var i = 0; i < paras.length; i++){
        var thisphtml = paras[i].innerHTML
        var imgs_in_p = paras[i].getElementsByTagName('IMG')
        var links_in_p = paras[i].getElementsByTagName('A')
        
        
        
        if (i % 2) paras[i].className = "even"
        if (imgs_in_p.length) paras[i].className = "ftIMGpara"
        if (thisphtml.length < 9) paras[i].className = "ftIMGpara"
        if (links_in_p.length){ // add an icon to go with the link into subcontent
            var srcspec = links_in_p[0].href, srcParts
            
            if (srcspec.indexOf(g_thisHref) > -1) srcspec = srcspec.split(g_thisHref)[1]
            if (srcspec.indexOf(g_thisFTSector + '/') > -1){ // accidental editor's insertion of this page's id before the sub-branch
                srcspec = srcspec.split(g_thisFTSector + '/')[1]
                // now ought to correct the link
                links_in_p[0].href = g_thisHref + '/' + srcspec
            }
            if (srcspec.indexOf('/') == 0) srcspec = srcspec.split('/')[1]
            srcParts = srcspec.split('/')
            

            srcspec = srcParts[0]
            
            if(gk_iconsForSubsection[srcspec]){
  /*
                var iconIMG = document.createElement('IMG')
                iconIMG.src = gk_iconsForSubsectionBase + gk_iconsForSubsection[srcspec]
                iconIMG.className = 'subsect_small_icon'
                iconIMG.height = 24
                iconIMG.width = 24
                paras[i].insertBefore(iconIMG, paras[i].firstChild)
                
  */              
                var imgInsertStr = '<img class="subsect_small_icon" src="' + gk_iconsForSubsectionBase + gk_iconsForSubsection[srcspec]
                imgInsertStr += '" height="24" width="24" /> '
                
                paras[i].innerHTML = imgInsertStr + paras[i].innerHTML

            }
        }
    }
}




function processParas_FT_datacharts(paras){


    var imgstr = gk_datachartsThumbnailStr.split('**sector**').join(g_thisFTSector)
    
    var tableS = '<table id="ft_data_charts_UI">', N = paras.length, extrasS = ''
    

    for (var i = 0, j = 0; i < N; i++){
    
        if (paras[i].innerHTML.length < 10) continue
        var thisphtml = ''
    
        var links_in_p = paras[i].getElementsByTagName('A')
        var subheads_in_p = paras[i].getElementsByTagName('STRONG')
        
        var oneCellstart = '<td id="dccell_' +j + '">', oneCellend = '</td></tr>', oneIMGsub = imgstr
  
        var treatAsChartLink = links_in_p.length
            ? (links_in_p[0].href.indexOf('/data-charts') !=  links_in_p[0].href.length - 12)
            : 0;

        if (treatAsChartLink){ // try to insert a thumbnail for the linked-to id
            var srcspec = links_in_p[0].href, srcParts =  srcspec.split('/'), srcID = srcParts[srcParts.length-1]
            
            if (srcID.length < 2) srcID = srcParts[srcParts.length-2] // trailing slash
            if (srcID == 'view') srcID = srcParts[srcParts.length-2] // trailing template name
            var thisIMG = oneIMGsub.split('**id**').join(srcID)
            
            thisIMG = '<a href="' + srcspec + '" title = "Click to view this chart/data">' + thisIMG + '</a>'
            j++;
            if (j % 2){
                oneCellstart = '<tr><td id="dccell_' +j + '">'
                oneCellend = '</td>'
            }
            
            if(links_in_p.length == 1){ // else put in a cell but do not expect a thumbnail etc
                links_in_p[0].title = 'Click to view this chart/data'
                links_in_p[0].className = 'mainDClink'
                thisphtml = paras[i].innerHTML
            
                if (thisphtml.indexOf('</a>') > -1){
                    thisphtml = thisphtml.split('</a>').join('</a> <p>' + thisIMG) + '</p>'
                }else if (thisphtml.indexOf('</A>') > -1){
                    thisphtml = thisphtml.split('</A>').join('</A> <p>' + thisIMG) + '</p>'
                }
            }else if (paras[i].className == 'treatAsTableCell'){
                thisphtml = '<p class="treatAsTableCell">' + paras[i].innerHTML +'</p>'
            }
            tableS += oneCellstart + thisphtml + oneCellend
        }else{
            if (subheads_in_p.length){  // need this to strike a TH for the subhead, and finish the row behind if nec
                if (j % 2){ // the last cell was not matched by a second one in the row
                    tableS = tableS.split('id="dccell_' +j + '"').join(' colspan="2" id="dccell_' +j + '"') + '</tr>'
                    j++ // start again at an odd number higher than any seen so far
                }
                tableS += '<tr><th colspan="2">' + subheads_in_p[0].innerHTML + '</th></tr>'
            }else{
                extrasS += '<p>' + paras[i].innerHTML + '</p>'
            }
        }
        

        
    }
    if (j % 2){ // the last cell was not matched by a second one in the row
        tableS = tableS.split('id="dccell_' +j + '"').join(' colspan="2" id="dccell_' +j + '"') + '</tr>'
    }

    tableS += '</table>'
    
    return tableS + extrasS
}
function insertSubsectionLinks(){
    var s = gk_subsection_linksStr
    
    var clel = document.getElementById('contentsListing')
    
    var contentEl = clel.parentNode
    var linksDashboard = document.createElement('DIV')
    linksDashboard.id = 'sector_subs_nav'
    linksDashboard.innerHTML = s
    contentEl.insertBefore(linksDashboard, clel)
}



function makeSectionsMenuHTML(id, spec, urlpre, titlepost){
    var s = '<div class="subsectionsDropdown" id="ssdd_' + id + '" onMouseDown="donowt();return true;">'
    for (var i = 0; i < spec.length; i++){
        var linkid = spec[i][0], title = spec[i][1]
        if (linkid == ''){
            s += '<h6>' + title + '</h6>'
        }else{
            s += '<a href="' + (linkid.indexOf('http://') == 0 ? linkid + '" target="_blank"' : urlpre + linkid + '"')
                + ' title= "go to the *' + title + '*' + titlepost
            if (id == 'FT'){
                s += '" class="dropDownFTlink" onMouseOver="showSubNav(event, this);return true;" onMouseOut="mouseOutSubNav();return true;'
            }
            s += '">' + title + '</a>'
        }
    }
    s += '</div>'
    return s
}

function makeSectionsMenus(){

    makeDropdownMenuLinks()
    
    var s = gk_textsizerHTML // dynamically write the textsize changer since it depends on javascript anyway
    for (var i = 0; i < gk_subsectionMenuSpecs.length; i++){
        var branchID = gk_subsectionMenuSpecs[i][0]
            , branchURLid = gk_subsectionMenuSpecs[i][1]
            , spec = gk_subsectionMenuSpecs[i][2], titlepost = gk_subsectionMenuSpecs[i][3]
            , urlpre = portal_url + '/' + branchURLid + '/'
        s += makeSectionsMenuHTML(branchID, spec, urlpre, titlepost)
    }
    
    s += makeFromHereMenu()
    
    var newel = document.createElement('DIV')
    
    newel.className = 'visualNoPrint'
    newel.innerHTML = s
    
    
//    document.getElementById('portal-column-content').appendChild(newel)
 //   document.getElementById('portal-top').appendChild(newel)
    
        
    document.getElementById('portal-footer').appendChild(newel) // tuck it at bottom for the has-js no-css case

    addFTSectorInfoSubNav()
    
    hiliteCurrentInNavTree()
    
    if (document.images) {
        var imgpre = '/webdav_uploads/NEWNGRF_FILES/css_images/'
        var dummyPrecache = new Image(220,894), dummyPrecache2 = new Image(200,40)
        dummyPrecache.src = imgpre + navigator.appVersion.indexOf('MSIE 6') > -1 ? 'notrans_darkmenubg_60.jpg' : 'darkdropdownBG_200.png'
        dummyPrecache2.src = imgpre + 'navtab_showing.png'
    }
    
}

function insertDropdownMenuLink(branch, branchURLid){



    var s = gk_dropdownlinkStr.split('**key**').join(branch)
    s = s.split('**ID**').join(branchURLid)
    
    var li_el = document.getElementById('tab_' + branch)
    


    if (li_el){
        li_el.innerHTML = li_el.innerHTML.split('</A>').join('</A>' + s)
        li_el.innerHTML = li_el.innerHTML.split('</a>').join('</a>' + s)
    }


}


function makeDropdownMenuLinks(){


    if (d_jsWritingStepsPending.indexOf('--make dropdown links--') > -1){
        if(document.getElementById('tab_LMI')){
            d_jsWritingStepsPending =  d_jsWritingStepsPending.split('--make dropdown links--').join('- -')
            for (var i = 0; i < gk_subsectionMenuSpecs.length; i++){
                var branchID = gk_subsectionMenuSpecs[i][0] , branchURLid = gk_subsectionMenuSpecs[i][1]
                insertDropdownMenuLink(branchID, branchURLid)
            }
            insertDropdownMenuLink('fromhere', 'navigate_from_here')
        }else{
            window.setTimeout('makeDropdownMenuLinks()', 100)
        }
    }
}


function makeFromHereMenu(){

    var s = '<div class="subsectionsDropdown" id="ssdd_fromhere" onMouseDown="donowt();return true;">'


    var crumbsEl = document.getElementById('portlet-breadcrumbs')
    var siblingsPortlet = document.getElementById('in_this_section')
    
    if (crumbsEl){
        
        var crumbstxt = crumbsEl.innerHTML.split('</h5>')
        if (crumbstxt.length == 1) crumbstxt = crumbsEl.innerHTML.split('</H5>')
        crumbstxt = crumbstxt[1]
        
        
        crumbstxt = "<h6>'ancestors'  - &uarr; - upwards links:</h6>" + crumbstxt
        
        var newcrumbss = "<h6>'ancestors'  - &uarr; - upwards links</h6>"
            + '<a title="back to the top of the NGRF site" href="' + portal_url + '">NGRF Home</a>'
        var crumbsDivs = crumbsEl.getElementsByTagName('DIV'), N = crumbsDivs.length, M = N - 1
        
        for (var i=0; i < N; i++){       
            if (i==M){
                newcrumbss += "<h6>'here' - permalink to current page:</h6>"
                crumbsDivs[i].innerHTML = crumbsDivs[i].innerHTML.split('"go to ').join('"this is a shareable permanent link to the current page: ')
            }
            newcrumbss += '<div class="knsubnav" style="padding-left: ' + (i*4) + 'px;">'
            newcrumbss += crumbsDivs[i].innerHTML + '</div>'
        }
         
        crumbstxt = newcrumbss
        
        s += crumbstxt

/*      /// poss if level 3 within FT or EG ue the main nav instead of siblings

        var navtree = document.getElementById('portlet-navigation-tree')
        if (navtree) {}
        else navtree = document.getElementById('EG_navigation_portlet')
        
        if (navtree){
            var nts = navtree.innerHTML.replace(/<h5>[^<]+/, "<h5>'children': downwards links")           
            s += nts
        }
*/        
        if (siblingsPortlet){
            var siblingstxt = siblingsPortlet.innerHTML.split('</h5>')
            if (siblingstxt.length == 1) siblingstxt = siblingsPortlet.innerHTML.split('</H5>')
            if(siblingstxt.length > 1){
            siblingstxt = siblingstxt[1]
            var splitbeforeLinkToParent = siblingstxt.indexOf('<a class="link_to_parent"') > -1 
                ? siblingstxt.split('<a class="link_to_parent"')[0] 
                : siblingstxt.split('<A class="link_to_parent"')[0];
            siblingstxt = "<h6>'siblings'  <<- >> sideways links:</h6>" + siblingstxt.split('<a class="link_to_parent"')[0]
            }else{
                siblingstxt = "<h6>There are no sideways links</h6>"
            }
            s += siblingstxt
            var dls = document.getElementsByTagName('DL')
            var subsections = filterForClass('related subsection', dls), subsectionstxt = ''
            
            if (subsections.length){    // suck the links out of subsection dls; use them as child links in menu
                var N = subsections.length, oneDL, oneDT, oneLinkStr
                for (var i=0; i < subsections.length; i++){
                    oneDT = subsections[i].getElementsByTagName('DT')
                    oneLinkStr = oneDT[0].innerHTML
                    if (i % 2) oneLinkStr = oneLinkStr.split('<a ').join('<a class="odd"')
                    subsectionstxt += oneLinkStr
                }
            }else{    // see if there is a summary of contents; use its dd's html as child links in menu
                subsections = filterForClass('related summary_subs', dls)
                if(subsections.length){
                    var onedd = subsections[0].getElementsByTagName('DD')
                    if (onedd.length){
                        var links = onedd[0].getElementsByTagName('P'), M = links.length, oneLinkStr
                        for(var j=0; j < M; j++){
                            oneLinkStr = links[j].innerHTML.split('<img')[0] + '</a>'
                            if (j % 2) oneLinkStr = oneLinkStr.split('class="sub"').join('class="odd"')
                            subsectionstxt += oneLinkStr
                        }
                    }
                }
            }

            if (subsectionstxt != ''){
                s += "<h6>'children' - &darr; - downwards links:</h6>" + subsectionstxt
            }else{
                s += "<h6>There are no downwards links</h6>"
            }
         

        }
    }
    s += '</div>'
    return s        
}

var gk_hackedStylesStr = '<link rel="stylesheet" '
    + 'href="/webdav_uploads/NEWNGRF_FILES/ft_tops_expts.css?v=d0" '
    + 'type="text/css" media="screen" />'


var gk_subsection_linksStr = '<a id="sector_subs_nav_info" title="SECTOR INFORMATION: This contains '
    + 'an overview of the sector as a whole, details future trends '
    + ' in employment together with skill gaps and workforce development issues."  '
    + 'href="info"><img src="/is_single_pixel_gif.gif" '
    + ' border="0" height="110" width="115" /></a>'
    + '<a id="sector_subs_nav_data-charts" title="DATA &amp; CHARTS: Links to the charts contained within this sector are listed."  '
    + 'href="data-charts"><img src="/is_single_pixel_gif.gif"  '
    + 'border="0" height="99" width="85" /></a>'
    + '<a id="sector_subs_nav_regional" title="REGIONAL / NATIONAL DIMENSION: Information on regional trends and differences, together  '
    + 'with the trends in the home nations including Scotland and Wales" href="regional"><img src="/is_single_pixel_gif.gif" border="0"'
    + ' height="126" width="136" /></a>'
    + '<a id="sector_subs_nav_occupations" title="OCCUPATIONS: Information and trends on sectoral occupations"  '
    + 'href="occupations"><img src="/is_single_pixel_gif.gif" border="0" height="76" width="128" /></a>'
    + '<a id="sector_subs_nav_equalop" title="EQUAL OPPORTUNITIES: Key information on equal opportunity issues  '
    + 'specific to the sector" href="equal-op"><img src'
    + '="/is_single_pixel_gif.gif" border="0" height="118" width="86" /></a>'
    + '<a id="sector_subs_nav_ed-training" title="EDUCATION &amp; TRAINING: Education and training information  '
    + 'and issues including work-based learning, apprenticeships, vocational qualifications, and further '
    + ' and higher education courses" href="ed-training"><img src="/is_single_pixel_gif.gif" '
    + ' border="0" height="130" width="128" /></a>'
    + '<a id="sector_subs_nav_research" title="RESEARCH: A list of recent research publications which is intended to be a '
    + ' starting for those wishing for more detail on the sector." href="research"><img '
    + ' src="/is_single_pixel_gif.gif" border="0" height="120" width="119" /></a>'
    + '<a id="sector_subs_nav_links" title="LINKS &amp; SOURCES: This contains direct links to all the materials used to compile this sector. '
    + ' More in-depth and detailed information can be found in the source materials as only key points have been extracted. In addition, '
    + ' websites and further sources which may be of interest have been included." href="links"><img  '
    + 'src="/is_single_pixel_gif.gif" border="0" height="92" width="106" /></a>'
    + '<a id="sector_subs_nav_summary" title="SECTOR SUMMARY: This summary gives a brief overview of the key trends in the sector." '
    + ' href="summary"><img src="/is_single_pixel_gif.gif" '
    + ' border="0" height="119" width="123" /></a>'
    
var gk_ftinfosportlet_HTML =  '<img  src="/webdav_uploads/NEWNGRF_FILES/ngrf_content/ft_sector_imgs/FT_portlet_bg.jpg" width="176" height="197" border="0" />'
//    + '<a id="FT_portlet_backtosector" href="" title="Go back up to the main page for this sector"><img src="/is_single_pixel_gif.gif" '
//    + ' border="0" width="150" height="20" /></a>'
	+ '<div id="FTsector_detail_icons">'
    + '<a id="FT_portlet_backtosector" href="" title="Go back up to the main page for this sector"><img src="/is_single_pixel_gif.gif" '
    + ' border="0" width="150" height="20" /></a>'
	+ '<a id="FT_portlet_info" title="SECTOR INFORMATION: This contains '
    + 'an overview of the sector as a whole, details future trends '
    + ' in employment together with skill gaps and workforce development issues."  '
    + 'href="info"><img src="/is_single_pixel_gif.gif" '
    + ' border="0" width="54" height="58" /></a>'
    + '<a id="FT_portlet_charts" title="DATA &amp; CHARTS: Links to the charts contained within this sector are listed."  '
    + 'href="data-charts"><img src="/is_single_pixel_gif.gif"  '
    + 'border="0" width="48" height="53" /></a>'
    + '<a id="FT_portlet_regional" title="REGIONAL / NATIONAL DIMENSION: Information on regional trends and differences, together  '
    + 'with the trends in the home nations including Scotland and Wales" href="regional"><img src="/is_single_pixel_gif.gif" border="0"'
    + ' width="66" height="47" /></a>'
    + '<a id="FT_portlet_occupations" title="OCCUPATIONS: Information and trends on sectoral occupations"  '
    + 'href="occupations"><img src="/is_single_pixel_gif.gif" border="0" width="68" height="42" /></a>'
    + '<a id="FT_portlet_eo" title="EQUAL OPPORTUNITIES: Key information on equal opportunity issues  '
    + 'specific to the sector" href="equal-op"><img src'
    + '="/is_single_pixel_gif.gif" border="0" width="61" height="49" /></a>'
    + '<a id="FT_portlet_training" title="EDUCATION &amp; TRAINING: Education and training information  '
    + 'and issues including work-based learning, apprenticeships, vocational qualifications, and further '
    + ' and higher education courses" href="ed-training"><img src="/is_single_pixel_gif.gif" '
    + ' border="0" width="61" height="55" /></a>'
    + '<a id="FT_portlet_research" title="RESEARCH: A list of recent research publications which is intended to be a '
    + ' starting for those wishing for more detail on the sector." href="research"><img '
    + ' src="/is_single_pixel_gif.gif" border="0" width="64" height="43" /></a>'
    + '<a id="FT_portlet_links" title="LINKS &amp; SOURCES: This contains direct links to all the materials used to compile this sector. '
    + ' More in-depth and detailed information can be found in the source materials as only key points have been extracted. In addition, '
    + ' websites and further sources which may be of interest have been included." href="links"><img  '
    + 'src="/is_single_pixel_gif.gif" border="0" width="53" height="49" /></a>'
    + '<a id="FT_portlet_summary" title="SECTOR SUMMARY: This summary gives a brief overview of the key trends in the sector." '
    + ' href="summary"><img src="/is_single_pixel_gif.gif" '
    + ' border="0" width="59" height="53" /></a>'
	+ '</div>'
    
var gk_textsizerHTML = '<div id="changeTextSize_widget">'
    + '<a href="javascript:void(fontsizeDel(0))"'
    + ' title="Make Text Smaller"><img src="/is_single_pixel_gif.gif" border="0" height="18" width="13" /></a>'
    + '<a href="javascript:void(fontsizeMid())"'
    + ' title="Normal Text Size"><img src="/is_single_pixel_gif.gif" border="0" height="18" width="14" /></a>'
    + '<a href="javascript:void(fontsizeDel(1))"'
    + ' title="Make Text Larger"><img src="/is_single_pixel_gif.gif" border="0" height="18" width="15" /></a>'
    + '</div>'


var gk_dropdownlinkStr = '<a class="navtabdd" href="' + portal_url + '/**ID**" id="ddarrow_**key**"'
    + 'onClick="showSectionsMenu(\'**key**\');return false;"'
    + 'onMouseDown="donowt();return true;"'
    + 'title="Click for a menu of subsections"><img src="/is_single_pixel_gif.gif" width="26" height="22" border="0"></a>'
    

var gk_crumbsFromFTSector = '<span class="crumbsinhead"><a id="crumbToLevel0"'
+' title="navigate up to the NGRF home" href="'
    + portal_url + '">NGRF</a> <a id="crumbToLevel1" '
+' title="navigate up to the main NGRF LMI future-trends page" href="'
    + portal_url + '/future-trends">:: LMI Future-Trends</a> ::</span>'

var gk_crumbsFromFTRegion = '<span class="crumbsinhead"><a id="crumbToLevel0"'
+' title="navigate up to the NGRF home" href="'
    + portal_url + '">NGRF</a> <a id="crumbToLevel1" '
+' title="navigate up to the main NGRF LMI future-trends page" href="'
    + portal_url + '/future-trends">:: LMI Future-Trends</a> <a id="crumbToLevel2" '
+' title="navigate up to the regions/nations interface for NGRF LMI future-trends" href="'
    + portal_url + '/future-trends/regions">:: Regional / National Information</a> ::</span>'

var gk_crumbsFromEG = '<span class="crumbsinhead"><a id="crumbToLevel0"'
+' title="navigate up to the NGRF home" href="'
    + portal_url + '">NGRF</a> <a id="crumbToLevel1" '
+' title="navigate up to the main NGRF Making Guidance More Effective page" href="'
    + portal_url + '/EG"><em>&gt;</em> Making Guidance More Effective</a> **localcrumbs** ::</span>'
    + '<img style="float:right;margin:0;" class="EGBG_rightshiv" src="/is_single_pixel_gif.gif" '
    + ' border="0" width="100" height="20" />'

    
var gk_ftsector_linkStrFromtop = '<b class="ftsectortitle"><a class="sectorHeadLink" href="**sectorURL**"'
    + ' onMouseOver="showSubNav(event, this);return true;"'
    + ' onMouseOut="mouseOutSubNav();return true;"'
    + ' title="This is a link to the current page - the **sector** LMI future-trends sector page">**sector**</a> <em>::</em></b>'
    
var gk_ftsector_linkStrFromDeep = '<b class="ftsectortitle"><a class="sectorHeadLink" href="**sectorURL**"'
    + ' title="navigate up to the **sector** LMI future-trends sector page">**sector**</a></b>'

            
var gk_level2HeadReplaceStr = '<img class="visualNoPrint" src="/webdav_uploads/NEWNGRF_FILES/ngrf_content/ft_sector_imgs/**imgsrc** />'
    + gk_crumbsFromFTSector
    + '**sectorLinkStr** **branch**'
    + '<span class="descrinhead">**descr**</span>'

            
var gk_regiontosectorHeadReplaceStr = '<img class="visualNoPrint" '
    + 'src="/webdav_uploads/NEWNGRF_FILES/ngrf_content/ft_regions_imgs/**regionid**_tiny.jpg" />'
    + gk_crumbsFromFTRegion
    + '<b class="ftsectortitle"><a class="sectorHeadLink"' // **regionLinkStr**</span> <span class="demotedFTHeadElements"><em>::</em>'
    + ' href="' + portal_url + '/future-trends/regions/'
    + '**regionid**" title="navigate up to the **regionName** regional/national page"> **regionName**</a></b>'
    + ' <em>::</em> Regional information by sector'




            
var gk_levelDeepHeadReplaceStr = '<img class="visualNoPrint" src="/webdav_uploads/NEWNGRF_FILES/ngrf_content/ft_sector_imgs/**imgsrc** />'
    + gk_crumbsFromFTSector
    + '<span class="demotedSectorName">**sectorLinkStr**</span> <span class="demotedFTHeadElements"><em>::</em>'
    + '<a class="demotedFTbranch" href="**branchURL**" title="navigate up to the **branch** page for this sector"> **branch**</a>'
    + '**localCrumbsstr**'     
    + ' <em>::</em> </span>**curTitleStr**'
    + '<span class="descrinhead">**descr**</span>'

            
var gk_EG_DeepHeadReplaceStr = gk_crumbsFromEG
    + '<b class="curtitle">**curTitleStr**</b>'
    + '<span class="descrinhead">**descr**</span>'

var gk_EGtop_linkStrFromDeep = ' <b class="EGtop_title"><a class="EGtop_Link" href="'
    + portal_url + '/EG/**branch**"'
    + ' title="navigate up to the overview page for the **branchTitle** area of Making Guidance More Effective."><em>&gt;</em> **branchTitle**</a></b>'


var gk_datachartsThumbnailStr = '<img src="/webdav_uploads/NEWNGRF_FILES/FT_DC_thumbnails/**sector**/TNS/small_**id**.jpg" height="80" border="0" />'



var gk_iconsForSubsection = [], gk_bgForInfoBranch = [], gk_iconsForSubsectionBase = '/webdav_uploads/NEWNGRF_FILES/ngrf_content/ft_sector_imgs/teensy_xpts/'

gk_subsection_linksStr = gk_subsection_linksStr.split('<img src="').join('<img src="' + gk_iconsForSubsectionBase)


var gk_EG_pseudoBranch = [], gk_EG_topTtitles = [], gk_EG_branchTitles = []


gk_EG_pseudoBranch['impprac'] = 'practice'
gk_EG_pseudoBranch['ip'] = 'practice'
gk_EG_pseudoBranch['new-approach'] = 'practice'
gk_EG_pseudoBranch['benefits'] = 'effective'
gk_EG_pseudoBranch['impact'] = 'effective'
gk_EG_pseudoBranch['equal-opps'] = 'effective'
gk_EG_pseudoBranch['LLL'] = 'building'
gk_EG_pseudoBranch['RIP'] = 'building'
gk_EG_pseudoBranch['policy'] = 'building'


gk_EG_branchTitles['practice'] = 'Guidance Practice'
gk_EG_branchTitles['effective'] = 'Effective Guidance'
gk_EG_branchTitles['building'] = 'Building Capacity'

gk_EG_topTtitles['impprac'] = 'Improving practice'
gk_EG_topTtitles['ip'] = 'Learning from others'
gk_EG_topTtitles['new-approach'] = 'New approaches in guidance'
gk_EG_topTtitles['benefits'] = 'Benefits of guidance'
gk_EG_topTtitles['impact'] = 'Assessing guidance'
gk_EG_topTtitles['equal-opps'] = 'Understanding equal opportunities'
gk_EG_topTtitles['LLL'] = 'Guidance, learning &amp; development'
gk_EG_topTtitles['RIP'] = 'Using research in practice'
gk_EG_topTtitles['policy'] = 'Understanding policy'

var gk_sectorinfo_title = []
gk_sectorinfo_title['info'] = 'SECTOR INFORMATION: This contains an overview of the sector as a whole, details future trends in employment together with skill gaps and workforce development issues.';
gk_sectorinfo_title['charts'] = 'DATA &amp; CHARTS: Links to the charts contained within this sector are listed.';
gk_sectorinfo_title['regional'] = 'REGIONAL / NATIONAL DIMENSION: Information on regional trends and differences, together with the trends in the home nations including Scotland and Wales';
gk_sectorinfo_title['occupations'] = 'OCCUPATIONS: Information and trends on sectoral occupations';
gk_sectorinfo_title['eo'] = 'EQUAL OPPORTUNITIES: Key information on equal opportunity issues specific to the sector';
gk_sectorinfo_title['training'] = 'EDUCATION &amp; TRAINING: Education and training information and issues including work-based learning, apprenticeships, vocational qualifications, and further and higher education courses';
gk_sectorinfo_title['research'] = 'RESEARCH: A list of recent research publications which is intended to be a starting for those wishing for more detail on the sector.';
gk_sectorinfo_title['links'] = 'LINKS &amp; SOURCES: This contains direct links to all the materials used to compile this sector. More in-depth and detailed information can be found in the source materials as only key points have been extracted. In addition, websites and further sources which may be of interest have been included.';
gk_sectorinfo_title['summary'] = 'SECTOR SUMMARY: This summary gives a brief overview of the key trends in the sector.';

var gk_sectorinfo_shortTitle = []
gk_sectorinfo_shortTitle['info'] = 'Sector Information'
gk_sectorinfo_shortTitle['data-charts'] = 'Data &amp; Charts'
gk_sectorinfo_shortTitle['regional'] = 'Regional / National Dimension'
gk_sectorinfo_shortTitle['occupations'] = 'Occupations'
gk_sectorinfo_shortTitle['equal-op'] = 'Equal Opportunities'
gk_sectorinfo_shortTitle['ed-training'] = 'Education &amp; Training'
gk_sectorinfo_shortTitle['research'] = 'Research'
gk_sectorinfo_shortTitle['links'] = 'Links &amp; Sources'
gk_sectorinfo_shortTitle['summary'] = 'Sector Summary'

var gk_sectorECImg = [] // eye candy to represent the sector
gk_sectorECImg['agriculture'] = 'small_env-con.jpg'
gk_sectorECImg['arts'] = 'small_img2.jpg'
gk_sectorECImg['automotive'] = 'small_tyre2.jpg'
gk_sectorECImg['banking'] = 'small_euronote.jpg'
gk_sectorECImg['clothing'] = 'small_img2.jpg'
gk_sectorECImg['cogent'] = 'small_1.jpg'
gk_sectorECImg['communications'] = 'small_satdish.jpg'
gk_sectorECImg['construction'] = 'small_img2.jpg'
gk_sectorECImg['defence'] = 'small_plane.jpg'
gk_sectorECImg['earlyyears'] = 'small_img1.jpg'
gk_sectorECImg['education'] = 'small_img3.jpg'
gk_sectorECImg['energy'] = 'small_2.jpg'
gk_sectorECImg['engineering'] = 'small_img3.jpg'
gk_sectorECImg['food'] = 'small_bread.jpg'
gk_sectorECImg['hair'] = 'small_img1.jpg'
gk_sectorECImg['health'] = 'small_thermometer.jpg'
gk_sectorECImg['hospitality'] = 'small_img1.jpg'
gk_sectorECImg['it'] = 'small_keyboard.jpg'
gk_sectorECImg['justice'] = 'small_cordon.jpg'
gk_sectorECImg['languages'] = 'small_flag.jpg'
gk_sectorECImg['logistics'] = 'small_cargoship.jpg'
gk_sectorECImg['manufacturing'] = 'small_img1.jpg'
gk_sectorECImg['media'] = 'small_kp1.jpg'
gk_sectorECImg['plumbing'] = 'small_tap.jpg'
gk_sectorECImg['profconstruction'] = 'small_uniofglasgow.jpg'
gk_sectorECImg['publicadmin'] = 'small_houseoflords.jpg'
gk_sectorECImg['retail'] = 'small_img2.jpg'
gk_sectorECImg['socialcare'] = 'small_worker.jpg'
gk_sectorECImg['sport'] = 'small_climbers.jpg'
gk_sectorECImg['transport'] = 'small_img2.jpg'
gk_sectorECImg['voluntary'] = 'small_india.jpg'

var gk_regionTitles = [] // each region has a page linking to sector info; the ids of those are erratic so lookup here

gk_regionTitles['scotland'] = 'Scotland'
gk_regionTitles['ni'] = 'Northern Ireland'
gk_regionTitles['north-east'] = 'North East'
gk_regionTitles['north-west'] = 'North West'
gk_regionTitles['yorks-humber'] = 'Yorkshire and the Humber'
gk_regionTitles['wales'] = 'Wales'
gk_regionTitles['east-midlands'] = 'East Midlands'
gk_regionTitles['west-midlands'] = 'West Midlands'
gk_regionTitles['east'] = 'East of England'
gk_regionTitles['london'] = 'Greater London'
gk_regionTitles['south-east'] = 'South East'
gk_regionTitles['south-west'] = 'South West'


var gk_ftdc_subfolders_asdc = []

gk_ftdc_subfolders_asdc['sport'] = ['industry','regional','qualification','occupation']
gk_ftdc_subfolders_asdc['agriculture'] = ['industry','regionaldata']



gk_ftdc_subfolders_asdc['media'] = ['industrydata','regionaldata','occdata','eodata','qualdata']

gk_ftdc_subfolders_asdc['construction'] = ['regdata','eodata','occdata','eddata']

     

var g_curshowing_submenu = 0, g_semaphore_inmenu = 0, g_curshowingmenu_navtab

function showSectionsMenu(branch){
    var ulel = document.getElementById('ssdd_' + branch)
    var tabel = document.getElementById('ddarrow_' + branch), leftpos = 100;
    var liel = document.getElementById('tab_' + branch)

    var posY = 78

    if (tabel){
        leftpos = getPageOffsetLeft(tabel) - 181 // 160
        posY = getPageOffsetTop(tabel) + 16
        
        if (navigator.appVersion.indexOf("MSIE 6") > -1) leftpos += 3
    }
    if (ulel){
        if (g_curshowing_submenu == ulel){  // close on 2nd click
            hidesubmenus()
            return 0
        }
        
        if (g_curshowing_submenu){  // close previous menu - this is a new one
            hidesubmenus()
        }
        
        g_curshowing_submenu = ulel
        g_curshowing_submenu.style.left = leftpos + 'px'
        g_curshowing_submenu.style.top = posY + 'px'
        g_curshowing_submenu.style.display = 'block'
        g_semaphore_inmenu = 0
    }
    
    if (liel) {
        g_curshowingmenu_navtab = liel
        liel.className = 'menushowing';
    }
}

function hidesubmenus(e){
    if(g_semaphore_inmenu){
        g_semaphore_inmenu = 0;
        return 0;
    }
    
    if(g_curshowing_submenu){
        g_curshowingmenu_navtab.className = ''
        g_curshowing_submenu.style.display = 'none'
        g_curshowing_submenu = 0;
    }
}

function donowt(e){
    g_semaphore_inmenu = 1
}


gk_iconsForSubsection['info'] = 'info.jpg'
gk_iconsForSubsection['data-charts'] = 'charts.jpg'
gk_iconsForSubsection['regional'] = 'regions.jpg'
gk_iconsForSubsection['occupations'] = 'occupations.jpg'
gk_iconsForSubsection['equal-op'] = 'eo.jpg'
gk_iconsForSubsection['ed-training'] = 'training.jpg'
gk_iconsForSubsection['links'] = 'links.jpg'
gk_iconsForSubsection['research'] = 'research.jpg'
gk_iconsForSubsection['summary'] = 'summary.jpg'



gk_bgForInfoBranch['data-charts'] = 'ftcrumbs_charts.jpg" width="61" height="46"'
gk_bgForInfoBranch['ed-training'] = 'ftcrumbs_training.jpg" width="70" height="46"'
gk_bgForInfoBranch['equal-op'] = 'ftcrumbs_eo.jpg" width="57" height="56"'
gk_bgForInfoBranch['info'] = 'ftcrumbs_info.jpg" width="46" height="43"'
gk_bgForInfoBranch['links'] = 'ftcrumbs_links.jpg" width="55" height="43"'
gk_bgForInfoBranch['occupations'] = 'ftcrumbs_occupations.jpg" width="75" height="48"'
gk_bgForInfoBranch['regional'] = 'ftcrumbs_regional.jpg" width="61" height="54"'
gk_bgForInfoBranch['research'] = 'ftcrumbs_research.jpg" width="75" height="43"'
gk_bgForInfoBranch['summary'] = 'ftcrumbs_summary.jpg" width="63" height="51"'


var gk_sectorTitles = []

gk_sectorTitles['sport'] = "Active leisure and learning"
gk_sectorTitles['agriculture'] = "Agriculture: Land management and production; animal health and welfare; and the environmental industries"
gk_sectorTitles['arts'] = "Arts and entertainment"
gk_sectorTitles['media'] = "Audio-visual industries"
gk_sectorTitles['automotive'] = "Automotive Retail"
gk_sectorTitles['banking'] = "Banking and insurance"
gk_sectorTitles['cogent'] = "Chemical, nuclear, oil and gas, petroleum and polymer industries"
gk_sectorTitles['clothing'] = "Clothing, footwear, textiles and servicing"
gk_sectorTitles['communications'] = "Communications"
gk_sectorTitles['construction'] = "Construction"
gk_sectorTitles['profconstruction'] = "Professions allied to construction"
//  gk_sectorTitles['custodial'] = "Custodial care"
gk_sectorTitles['defence'] = "Defence"
gk_sectorTitles['earlyyears'] = "Early years education, childcare and playwork"
gk_sectorTitles['education'] = "Education"
gk_sectorTitles['energy'] = "Energy and utilities"
gk_sectorTitles['engineering'] = "Engineering"
gk_sectorTitles['food'] = "Food and drink manufacturing and processing"
gk_sectorTitles['hair'] = "Hair, beauty and body art"
gk_sectorTitles['health'] = "Health"
gk_sectorTitles['hospitality'] = "Hospitality"
gk_sectorTitles['it'] = "IT and Telecoms"
gk_sectorTitles['justice'] = "Justice: custodial care, community justice and police"
gk_sectorTitles['languages'] = "Languages across the sectors"
gk_sectorTitles['logistics'] = "Logistics"
gk_sectorTitles['manufacturing'] = "Manufacturing"
gk_sectorTitles['plumbing'] = "Plumbing and heating"
//  gk_sectorTitles['police'] = "Police and community justice"
gk_sectorTitles['publicadmin'] = "Public administration"
gk_sectorTitles['retail'] = "Retail"
gk_sectorTitles['socialcare'] = "Social care"
gk_sectorTitles['transport'] = "Passenger Transport"
gk_sectorTitles['voluntary'] = "Voluntary"


var gk_ft_menu_spec = [['', 'LMI Trends By Sectors:']
    , ['sport', 'Active leisure and learning']
	, ['agriculture', 'Agriculture: Land management...']
	, ['arts', 'Arts and entertainment']
	, ['media', 'Audio-visual industries']
	, ['automotive', 'Automotive retail']
	, ['banking', 'Banking and insurance']
	, ['cogent', 'Chemical, nuclear, oil and...']
	, ['clothing', 'Clothing, footwear, textiles...']
	, ['communications', 'Communications']
	, ['construction', 'Construction']
	, ['profconstruction', 'Professions allied to...']
//	, ['custodial', 'Custodial care']
	, ['defence', 'Defence']
	, ['earlyyears', 'Early years education,...']
	, ['education', 'Education']
	, ['energy', 'Energy and utilities']
	, ['engineering', 'Engineering']
	, ['food', 'Food and drink manufacturing...']
	, ['hair', 'Hair, beauty and body art']
	, ['health', 'Health']
	, ['hospitality', 'Hospitality']
	, ['it', 'IT and Telecoms']
	, ['justice', 'Justice: custodial care,...']
	, ['languages', 'Languages across the sectors']
	, ['logistics', 'Logistics']
	, ['manufacturing', 'Manufacturing']
	, ['transport', 'Passenger transport']
	, ['plumbing', 'Plumbing and heating']
//	, ['police', 'Police and community justice']
	, ['publicadmin', 'Public administration']
	, ['retail', 'Retail']
	, ['socialcare', 'Social care']
	, ['voluntary', 'Voluntary']
	, ['', 'Non-Sectoral Information:']
    , ['lmiresources', 'LMI resources']
	, ['regions', 'LMI : Regional / National...']
	, ['what-is', 'What is LMI Future Trends?']
	, ['lmift-bookmarks', 'LMI Social Bookmarks']]


var gk_eg_menu_spec =    [['', 'Guidance Practice:']
	, ['impprac', 'Improving practice']
	, ['ip', 'Learning from others']
	, ['new-approach', 'New approaches in guidance']
	, ['', 'Effective Guidance']
	, ['benefits', 'Benefits of guidance']
	, ['impact', 'Assessing guidance']
	, ['equal-opps', 'Understanding equal opp&hellip;']
	, ['', 'Building Capacity:']
	, ['LLL', 'Guidance, learning &amp; develop&hellip;']
	, ['RIP', 'Using research in practice']
	, ['policy', 'Understanding policy']]


var gk_modules_menu_spec =  [['', 'Start here:']
	, ['lmi_competence_check', 'LMI Competence Check']
	, ['', 'LMI Modules:']
	, ['nature', 'The Nature of LMI']
	, ['changing', 'The changing labour market']
	, ['locating', 'Locating sources']
	, ['choosing', 'Choosing between sources']
	, ['using', 'Frameworks for practice']
	, ['practice', 'Implementing good practice']
	, ['', 'Discussion & Background:']
	, ['blog', 'The LMI Learning Blog']
	, ['about', 'About the LMI Learning Modules']]

var gk_subsectionMenus = []

var gk_subsectionMenuSpecs = [['EG', 'EG', gk_eg_menu_spec, ' subsection of Making Guidance More Effective']
    , ['FT', 'future-trends', gk_ft_menu_spec, ' subsection of LMI Future-Trends / Labour Market Information']
    , ['LMI', 'lmi-learning', gk_modules_menu_spec, ' subsection of the LMI-Learning modules']]
    

/*** following iis from the former special ftsubnav.js file added in portlet in FT branch **/

function showSubNav(e, obj){

	if (!e) var e = window.event;  // MIM note to self: get rid of this if ends up we do not need it
    
    if (g_ft_curSubNavLink) g_ft_curSubNavLink.className = g_ft_curSubNavLink.hackatt_realclassname

    var url = obj.href, title = obj.innerHTML.replace(/^\W+/,'')
    title=title.replace(/\W+$/,'')    
    
    if (url.indexOf('future-trends/lmiresources') > -1) return 0
    if (url.indexOf('future-trends/what-is') > -1) return 0
    if (url.indexOf('future-trends/lmift-bookmarks') > -1) return 0
    
    
  
    var tmpl = (url.indexOf('future-trends/regions') > -1) ? g_ft_regionsTempl : subULTmpl
    
    if ((url.indexOf('future-trends/custodial') > -1) || (url.indexOf('future-trends/police') > -1) ){
        tmpl = replacedByJusticeTmpl /// Sally emailed sept 20 06 for this change
    }
    
    if(url.charAt(url.length-1) != '/') url += '/'

    var html = tmpl.split('**URLBASE**').join(url)
    html = html.split('**title**').join(title)
    g_ft_navDiv.innerHTML = html

    var posY = getPageOffsetTop(obj)
    var posX = 170; // **** CONSTANT ***** - just at right of portlet links
    
    if (obj.className == 'sectorHeadLink'){
        posY = e.clientY + 5
        posX = e.clientX + 10
    }
    
    if (obj.className == 'dropDownFTlink'){
        posX = e.clientX
        var tabel = document.getElementById('ddarrow_FT')
        if (tabel) posX = getPageOffsetLeft(tabel)
    }
    
    
    
    g_ft_navDiv.style.top = (posY) + 'px'
    g_ft_navDiv.style.left = (posX) + 'px'
    g_ft_navDiv.style.display = 'block'
    g_ft_navDiv_mouseoutSem = 1
    
    g_ft_curSubNavLink = obj
    g_ft_curSubNavLink.hackatt_realclassname = g_ft_curSubNavLink.className
    g_ft_curSubNavLink.className = 'as_hovered'
    

    
}

function disposeSubNav(){
    if(g_ft_navDiv_mouseoutSem){
    }else{
        g_ft_navDiv.style.display = 'none'
        g_ft_curSubNavLink.className = g_ft_curSubNavLink.hackatt_realclassname
    }
}

function mouseOutSubNav(){
    g_ft_navDiv_mouseoutSem = 0
    window.setTimeout('disposeSubNav()', 300)
}

function mouseInSubNavDIV(){
    g_ft_navDiv_mouseoutSem = 1
}

var g_ft_navDiv, g_ft_navDiv_mouseoutSem = 0, g_ft_curSubNavLink

function addRollovers(){
    var navtree = document.getElementById('portlet-navigation-tree')
    
    if (navtree){
        var links = navtree.getElementsByTagName('A'), N= links.length, oneLink, url = '', testUrl;
        var ftBase = portal_url + '/future-trends/'
        for (var i=0; i < N; i++){
            oneLink = links[i]
            oneLink.onmouseover=function(event) {
                showSubNav(event, this);
            }
            oneLink.onmouseout=mouseOutSubNav
        }
    }
}

function addFTSectorInfoSubNav(){

//    var navtree = document.getElementById('portlet-navigation-tree')
    var navtree = document.getElementById('credit-portlet')
    
    
    
    if (navtree){}
    else{
        navtree = document.getElementById('EG_navigation_portlet')
    }
    
    g_ft_navDiv = document.createElement('DIV')
    g_ft_navDiv.id = 'ft_subnav_div'
    g_ft_navDiv.onmouseover = mouseInSubNavDIV
    g_ft_navDiv.onmouseout = mouseOutSubNav
    g_ft_navDiv.style.zIndex = 1100;
    navtree.appendChild(g_ft_navDiv)
}

function filterForClass(aClass, aNodeList, firstEl){
	var aClass = new String(aClass);
	aClass=aClass.toLowerCase();
	var filteredNodeList = new Array();
	if(!(aNodeList.length > 0)){return filteredNodeList}
	for(var i=0; i<aNodeList.length; i++){
		var nodeString = new String(aNodeList[i].className);
		nodeString = nodeString.toLowerCase();
		if(nodeString == aClass){
			filteredNodeList[filteredNodeList.length] = aNodeList[i];
//			filteredNodeList.push(aNodeList[i]);
		}
	}
	if (firstEl){
		if(filteredNodeList.length > 0) return filteredNodeList[0]
		else return null;
	}
	return filteredNodeList;
}


function getPageOffsetTop(el) {
    
    var y;
    
    // Return the x coordinate of an element relative to the page.
    
    y = el.offsetTop;
    if (el.offsetParent != null){
        y += getPageOffsetTop(el.offsetParent);
    }
    return y;
}

var subULTmpl = '<ul>'
    + '<li><a href="**URLBASE**info" title="go to **title** :: Sector information">Sector information</a></li>'
	+ '<li><a href="**URLBASE**data-charts" title="go to **title** :: Data and charts">Data and charts</a></li>'
	+ '<li><a href="**URLBASE**regional" title="go to **title** :: Regional / national dimension">Regional/National</a></li>'
	+ '<li><a href="**URLBASE**occupations" title="go to **title** :: Occupations">Occupations</a></li>'
	+ '<li><a href="**URLBASE**equal-op" title="go to **title** :: Equal opportunities">Equal opportunities</a></li>'
	+ '<li><a href="**URLBASE**ed-training" title="go to **title** :: Education and training">Education and training</a></li>'
	+ '<li><a href="**URLBASE**research/" title="go to **title** :: Research">Research</a></li>'
//	+ '<li><a href="**URLBASE**discussion" title="go to **title** :: Discussion points">Discussion points</a></li>'
	+ '<li><a href="**URLBASE**summary" title="go to **title** :: Sector summary">Sector summary</a></li>'
	+ '<li><a href="**URLBASE**links" title="go to **title** :: Links and sources">Links and sources</a></li></ul>'


	
var g_ft_regionsTempl = '<ul>'
	+ '<li><a href="**URLBASE**scotland" title = "Click to get information for Scotland">Scotland</a></li>'
	+ '<li><a href="**URLBASE**ni" title = "Click to get information for Northern Ireland">Northern Ireland</a></li>'
	+ '<li><a href="**URLBASE**north-east" title = "Click to get information for North East">North East</a></li>'
	+ '<li><a href="**URLBASE**north-west" title = "Click to get information for North West">North West</a></li>'
	+ '<li><a href="**URLBASE**yorks-humber" title = "Click to get information for Yorkshire and the Humber">Yorkshire and the Humber</a></li>'
	+ '<li><a href="**URLBASE**wales" title = "Click to get information for Wales">Wales</a></li>'
	+ '<li><a href="**URLBASE**east-midlands" title = "Click to get information for East Midlands">East Midlands</a></li>'
	+ '<li><a href="**URLBASE**west-midlands" title = "Click to get information for West Midlands">West Midlands</a></li>'
	+ '<li><a href="**URLBASE**east" title = "Click to get information for East of England">East of England</a></li>'
	+ '<li><a href="**URLBASE**london" title = "Click to get information for Greater London">Greater London</a></li>'
	+ '<li><a href="**URLBASE**south-east" title = "Click to get information for South East">South East</a></li>'
	+ '<li><a href="**URLBASE**south-west" title = "Click to get information for South West">South West</a></li>'
	+ '</ul>'
	
	
var replacedByJusticeTmpl = '<p>This sector information has<br />  been replaced by the new  '
    + '<a href="http://www.guidance-research.org/future-trends/justice">Justice</a> sector.</p>'
    

/**  adapted from QCB for the little pseudo window for display annotated ref more **/
/** june 6 changing to use xmlrpc iso iframes - nasty bug in ie6 **/

var httpMoreViewObject = getHTTPObject()

var g_el_moreinfobox = null, g_el_moreviewarea = null, g_iframe_urlNowShowing = ''


function openInIFrame(title, url, el){



    alert(el.href)
    if (g_iframe_urlNowShowing == url){
        close_info_box()
        return false;
    }
    g_iframe_urlNowShowing = url
    
    if (g_el_moreinfobox) {}
    else    { g_el_moreinfobox = document.getElementById('moreinfobox') }
    if (g_el_iframeObj) {}
    else    { g_el_iframeObj = document.getElementById('iframeInfoArea') }
    
///////    g_el_iframeObj.src = url + '/annotref_quickview'

    g_el_moreinfobox.style.display = 'block' 

    var y = getAbsY(el), x = getAbsX(el)
    
    y += 25
    x = Math.max(10, x-250)

    if ( x > 450 ) x = (x - 250)
    
//    g_el_moreinfobox.style.display = 'block'
    g_el_moreinfobox.style.top = y + 'px'
    g_el_moreinfobox.style.left  = x + 'px'
    
 
    var sy = top.document.body.scrollTop, wh = top.document.body.clientHeight
    if((y - sy) > (wh - 375)){
        top.document.body.scrollTop = (y - (wh - 375))
    }
 /*  
    if (navigator.appVersion.indexOf("MSIE 6")>=0){ // hack -- why???? - no time to find out
        window.setTimeout("g_el_moreinfobox.style.display = 'block'", 800)
    }else{
        g_el_moreinfobox.style.display = 'block'
    }
*/    
    refreshIFrameObj(g_el_iframeObj, url + '/annotref_quickview')
    return false;
}


function openMoreInfo(el){

    var url = el.href + '/annotref_plaindata'
    
    if (g_iframe_urlNowShowing == url){
        close_info_box()
        return false;
    }
    
    g_iframe_urlNowShowing = url
    
    
    if (g_el_moreinfobox) {}
    else    { g_el_moreinfobox = document.getElementById('moreinfobox') }
    
    if (g_el_moreviewarea) {}
    else    { g_el_moreviewarea = document.getElementById('MoreInfoArea') }
    
    
    g_el_moreviewarea.innerHTML = '<h1 class="waitmsg">Please wait...</h1>'
    g_el_moreinfobox.style.display = 'block'
    
    var y = getAbsY(el), x = getAbsX(el)
    
    y += 25
    x = Math.max(10, x-250)

    if ( x > 450 ) x = (x - 250)
    
    
    
    x = 160
    
    
    g_el_moreinfobox.style.top = y + 'px'
    g_el_moreinfobox.style.left  = x + 'px'
    
 
    var sy = top.document.body.scrollTop, wh = top.document.body.clientHeight
    if((y - sy) > (wh - 375)){
        top.document.body.scrollTop = (y - (wh - 375))
    }
    
    httpMoreViewObject.open("GET", url, true);
    httpMoreViewObject.onreadystatechange = handleGotMoreToView;
    httpMoreViewObject.send(null);

}            

function handleGotMoreToView(){
  if (httpMoreViewObject.readyState == 4) {
    results = httpMoreViewObject.responseText;
    g_el_moreviewarea.innerHTML = results;

  }

}

function addMoreViewerToPage(){
    var newdiv = document.createElement('DIV')
    newdiv.innerHTML = gk_moreviewerHTML
    document.body.appendChild(newdiv)
}

if (window.addEventListener) window.addEventListener("load",addMoreViewerToPage,false);
else if (window.attachEvent) window.attachEvent("onload",addMoreViewerToPage);

var gk_moreviewerHTML = '<div id="moreinfobox" class="puwindow" style="left: 190px; top: 304px; z-index: 7; width: 583px; display: none;">'
	+ '<div  class="titleBar">'
	+ '<span id="moreinfobox_title"  class="titleBarText">Further information about this reference</span>'
	+ '<a href="javascript:void(close_info_box())"><b>[ close ]</b>'
	+ '<img style="border: medium none ; margin: 2px 3px 0pt;" src="knotes_ui_imgs/close_icon.gif"'
	+ 'tal:attributes="src string:$portal_url/knotes_ui_imgs/close_icon.gif" height="12" width="12"></a>'
	+ '</div>'
	+ '<div id="MoreInfoArea"></div>'
	+ '</div>'
	
function refreshIFrameObj(IFrameObj, URL){  /// will no be needed if use the ajaxian approach :o(

    var IFrameDoc;

    if (IFrameObj.contentDocument) {
        // For NS6
        IFrameDoc = IFrameObj.contentDocument; 
    } else if (IFrameObj.contentWindow) {
    // For IE5.5 and IE6
        IFrameDoc = IFrameObj.contentWindow.document;
    } else if (IFrameObj.document) {
    // For IE5
        IFrameDoc = IFrameObj.document;
    } else {
        IFrameObj.src = URL
        return true;
    }
    
  IFrameDoc.location.replace(URL);
  
}

function close_info_box(){
    g_iframe_urlNowShowing = ''
    g_el_moreinfobox.style.display = 'none'
}

// get the true offset of anything on NS4, IE4/5 & NS6, even if it's in a table!

function getAbsX(elt) { return (elt.x) ? elt.x : getAbsPos(elt,"Left"); }
function getAbsY(elt) { return (elt.y) ? elt.y : getAbsPos(elt,"Top"); }
function getAbsPos(elt,which) {
 iPos = 0;
 while (elt != null) {
  iPos += elt["offset" + which];
  elt = elt.offsetParent;
 }
 return iPos;
} 

/**** from the ratings macro - used to be inline from knotes blogblockmacros ****/

var rated = false;
function dimScreen(){
    bgdiv=document.createElement('div');
    bgdiv.setAttribute('id','dimdiv');
    bgdiv.style.filter="alpha(opacity=60)";  
    bgdiv.style.position='absolute';
    bgdiv.style.zindex='99999'
    bgdiv.style.left='0px';
    bgdiv.style.top='0px';
    bgdiv.style.width=document.documentElement.scrollWidth+"px";
    bgdiv.style.height=document.documentElement.scrollHeight+"px";
    bgdiv.style.background="url("+portal_url+"/knotes_ui_imgs/trans_bg.png)";
    document.body.appendChild(bgdiv);
    popUp(bgdiv)

}

function popUp(obj){
    popup=document.createElement('div');            
    popup.setAttribute('id','popup'); 
    popup.style.position='absolute';
    bgdiv.style.zindex='999999'
    popup.style.left=((document.documentElement.clientWidth /2)+document.documentElement.scrollLeft)-50+'px';
    popup.style.top=((document.documentElement.clientHeight/2)+document.documentElement.scrollTop)-25+'px';
    popup.style.padding="0.5em";
    popup.style.background="#FC4201";
    popup.style.color="white";
    popup.style.border="1px solid #667";
    popup.innerHTML="<span style='font-size:2em;'>Saving ...<"+""+"/span>"
    obj.appendChild(popup);
}
function endScreenDim(){
    obj=document.getElementById("dimdiv")
    if(obj)
        obj.parentNode.removeChild(obj)
}

function rateContent(stars){
    rated=true;
    for(i = 1;i<=stars;i++){
        obj = document.getElementById(i+"starimg");
        obj.src = portal_url+'/knotes_ui_imgs/full_small_star.gif';

    }
    for(i = stars+1;i<=5;i++){
        obj = document.getElementById(i+"starimg");
        obj.src = portal_url+'/knotes_ui_imgs/empty_small_star.gif';
    }
    document.getElementById("rating_score").value=stars;
    document.getElementById("your_rating").innerHTML="You are giving this document a "+stars+" star rating.<br /> Click submit to proceed or cancel if you have changed your mind"
    document.getElementById("submit_rating_form").style.display="inline";
}

function hoverStars(stars){
    if(rated) return false;
    for(i = 1;i<=Math.round(stars);i++){
        obj = document.getElementById(i+"starimg")
        if(stars-i<0)
            obj.src = portal_url+'/knotes_ui_imgs/half_small_star.gif'
        else
            obj.src = portal_url+'/knotes_ui_imgs/full_small_star.gif'

    }
    for(i = Math.round(stars)+1;i<=5;i++){
        obj = document.getElementById(i+"starimg")
        obj.src = portal_url+'/knotes_ui_imgs/empty_small_star.gif'
    }
}
function ajaxPost(){
    dimScreen();
    var url =this_url+"/rateContent?ajax=1&rating="+document.getElementById("rating_score").value
    document.getElementById("submit_rating_form").style.display="none";
    document.getElementById("waiting_post").style.display="block";
    httpRatingObject.open("GET", url, true);
    httpRatingObject.onreadystatechange = handleAjaxPost;
    httpRatingObject.send(null);
}


function handleAjaxPost() {
  if (httpRatingObject.readyState == 4) {
    results = httpRatingObject.responseText;
    ur = document.getElementById("user_rating")
    yr = document.getElementById("rating_score").value
    if(ur)
        ur.innerHTML=yr
    else
        document.getElementById("your_last_rating").innerHTML="Given "+yr+" stars by you"
    r = results.split(':')
    averageRating=r[0]/r[1]+0.0
    document.getElementById("avg_ratings").innerHTML="Rated "+r[1]+" time(s)"            
    hideSubmit();
    setTimeout("endScreenDim()",1000);

  }

}




function setStars(){
    hoverStars(averageRating);
}

function hideSubmit(){
    document.getElementById("submit_rating_form").style.display="none";
    document.getElementById("waiting_post").style.display="none";
    rated=false;
    hoverStars(averageRating);
}
function getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}

/*** these will only be for logged in users
var httpRatingObject = getHTTPObject()
if (window.addEventListener) window.addEventListener("load",setStars,false);
else if (window.attachEvent) window.attachEvent("onload",setStars);
***/


/** below we add some onload handlers depending on where we are ***/

if (window.addEventListener) window.addEventListener("load",makeSectionsMenus,false);   // includes addFTSectorInfoSubNav
else if (window.attachEvent) window.attachEvent("onload",makeSectionsMenus);


if (g_addFTsubmenusToMainNav){
    if (window.addEventListener) window.addEventListener("load",addRollovers,false);
    else if (window.attachEvent) window.attachEvent("onload",addRollovers);

}
	
switch(g_special_FT_handling) {
    case 'sector_top':

        document.write(gk_hackedStylesStr)
        
        if (window.addEventListener) window.addEventListener("load",process_SectorTops,false);
        else if (window.attachEvent) window.attachEvent("onload",process_SectorTops);
        
        break;


    case 'sector_branch':
    
        if (window.addEventListener) window.addEventListener("load",process_SectorBranches,false);
        else if (window.attachEvent) window.attachEvent("onload",process_SectorBranches);
        
        break;
        
    case 'sector_deep':
        
        if (window.addEventListener) window.addEventListener("load",process_SectorDepths,false);
        else if (window.attachEvent) window.attachEvent("onload",process_SectorDepths);
        
        break;
        
        
    case 'sectors_AtoZ_listing':
        
        if (window.addEventListener) window.addEventListener("load",process_SectorAtoZListing,false);
        else if (window.attachEvent) window.attachEvent("onload",process_SectorAtoZListing);
        
        break;
        
    case 'regions_to_sectors':
        
        if (window.addEventListener) window.addEventListener("load",process_regionsToSectors,false);
        else if (window.attachEvent) window.attachEvent("onload",process_regionsToSectors);
        
        break;
    
    case 'EGBranch_top':
        if (window.addEventListener) window.addEventListener("load",process_EGTops,false);
        else if (window.attachEvent) window.attachEvent("onload",process_EGTops);
        
        
        break;

    case 'EG_deep':
        
        if (window.addEventListener) window.addEventListener("load",process_EG_Depths,false);
        else if (window.attachEvent) window.attachEvent("onload",process_EG_Depths);

        
        break;
}
    




/*********  TEMPORARY SCRIPTS DURING DEMOING ANDDEVELOPMENT ***/


function swapNewsBoxStyle(classname){

    var newsbox = document.getElementById('newsBox')
// newsBox.Option2    
    if (newsbox){
        newsbox.className = classname
    }
    
    

}