/*  filename:   MC_elibrary.js
    version:    1.03
    author:     michael cosentino
    date:       03/03/04
    
    This Javascript is used for the eLibrary module for article pages.
    It extracts the NYT keywords from %%KEYWORDS%% and dynamically writes a 
    bulleted list of search terms for HighBeam
    
    02/04/04: original file created
    02/05/04: added ability to omit "bad" keywords"
    02/19/04: apply redesigned template
    03/03/04: per client's request, start from 2nd keyword. Make appropriations
              for when there are no eligible results.
*/

var aKeywords = strKeywords.split(";");     // create array, semicolon delimited
var aBadKeywords = new Array("suggested");  // list of "bad" keywords   
var aLinkDesc = new Array();                // array of link descriptions
aKeywords.length -= 1;                      // remove last element due to trailing
                                            // semicolon in query string

// filter out "bad" keywords
for (j = 0; j < aBadKeywords.length; j++) {
    for (i = 0; i < aKeywords.length; i++) {
        if (aKeywords[i].indexOf(aBadKeywords[j]) != -1) {
            aKeywords.splice(i, 1);
            i--;
        }
    }
}    

// don't let user request more keywords than available
if (numKeywords > aKeywords.length) numKeywords = aKeywords.length;

// create display-ready list of keywords
for (i = 0; i < aKeywords.length; i++) {
    aLinkDesc[i] = unescape(aKeywords[i]);
    aLinkDesc[i] = aLinkDesc[i].replace(/\+|_/g, " ");
}

// write table
document.write('    <table width="100%" cellpadding="0" cellspacing="0" border="0">\n');
document.write('        <tr> \n');
document.write('        <td background="http://www.nytimes.com/ads/elibrary/dottedline.gif"><img src="http://graphics7.nytimes.com/images/misc/spacer.gif" width="138" height="1"></td>\n');
document.write('        </tr>\n');
document.write('		</table>\n');
document.write('    <img src="http://graphics7.nytimes.com/images/misc/spacer.gif" width="10" height="5"><br>\n');
document.write('    <!-- END OF NO-EDIT AREA -->\n');
document.write('    <!-- EDIT 120X90 GIF -->\n');
document.write('    <img src="http://www.nytimes.com/ads/elibrary/highbeam.gif" width="120" height="90" alt="Highbeam Research" border="0"><br>\n');
document.write('    <!-- END 120X90 GIF -->\n');
document.write('    <img src="http://graphics7.nytimes.com/images/misc/spacer.gif" width="10" height="5"><br />\n');
document.write('    <!-- BEGIN AD COPY --><div style="font-family: arial, helvetica, sans-serif; font-size:11px; color:#666666;"><strong>\n');

// write bulleted list
if (aKeywords.length > 1) {
    document.write('    Research our extensive archive of more than 28 million documents from 2,600 sources for\n');
    document.write('    </strong></div>\n');
    document.write('    <!-- END AD COPY -->\n');
    document.write('    <!-- EDIT LINK -->\n');
    
    for (i = 1; i <= numKeywords; i++) {
        if (aKeywords[i]) {
            document.write('        &#8226; <a style="font-family: arial, helvetica, sans-serif; font-size:11px; color:#ff6600;" href="http://www.highbeam.com/library/search.asp?q=' + aKeywords[i] + '&refid=' + refid + '" target="_blank">' + aLinkDesc[i] + '</a><br />\n');
        }
    }
} else {
    document.write('    <a style="font-family: arial, helvetica, sans-serif; font-size:11px; color:#ff6600;" href="http://www.highbeam.com/library/index.asp?refid=' + refid + '" target="_blank">Research</a> our extensive archive of more than 28 million documents from 2,600 sources.\n');
    document.write('    </strong></div>\n');
}

document.write('    <!-- END LINKS -->\n');
document.write('    </font>\n');
