/*  filename:   MC_elibrary_1.03b.js
    version:    1.03b
    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, " ");
}

if (!clickGoto) {
    clickGoto = "";
} else {
    clickGoto += "=";
}

// write table
document.write('<table width="160" border="0" cellspacing="0" cellpadding="1" align="center">\n');
document.write('<tr>\n');
document.write('<td bgcolor="#000000">\n');
document.write('    <table width="158" border="0" cellspacing="0" cellpadding="0">\n');
document.write('    <tr>\n');
document.write('    <td bgcolor="#FFFFFF" valign="top">\n');
document.write('    <div style="text-align:left;padding-left:10px;margin-top:7px;">\n');
document.write('        <table border="0" cellspacing="0" cellpadding="0">\n');
document.write('        <tr>\n');
document.write('        <td>\n');
document.write('        <div style="font-size:12px;font-family:arial,sans-serif;color:#666;font-weight:bold;">Find out more about:</div>\n');
document.write('        <form action="http://www.highbeam.com/library/search.asp" target="_blank" style="margin:0;padding:0;"></td>\n');
document.write('        </tr>\n');
document.write('        <tr>\n');
document.write('        <td>\n');
document.write('        <input type="text" name="q" value="');

// fill text box with element 2
if (aKeywords[1]) document.write(aLinkDesc[1]);

document.write('" size="12" style="width:130px;" style="font-size:12px;font-family:arial,sans-serif;color:#000;font-weight:bold;" /></td>\n');
document.write('        </tr>\n');
document.write('        <tr>\n');
document.write('        <td>\n');
document.write('        <input type="image" name="" value="" src="http://www.highbeam.com/creative/misc/nyt/research-now.gif" border="0" width="92" height="22" style="margin: 0px 10px 10px 0px;" />\n');

// write bulleted list: only elements 3 and 4
if (aKeywords[2]) {
    document.write('        <div style="font-size:12px;font-family:arial,sans-serif;color:#666;font-weight:bold;text-align:left;">Related Research:</div>\n');
    document.write('        <div style="font-size:12px;font-family:arial,sans-serif;color:#666;font-weight:bold;text-align:left;">\n');
    document.write('        <div style="padding-bottom:4px;">&#149;<a href="http://www.highbeam.com/library/search.asp?q=' + aKeywords[2] + '&refid=' + refid + '" style="color:#c00;" target="_blank">' + aLinkDesc[2] + '</a></div>\n');
    
    if (aKeywords[3]) {
        document.write('        <div style="padding-bottom:10px;">&#149;<a href="http://www.highbeam.com/library/search.asp?q=' + aKeywords[3] + '&refid=' + refid + '" style="color:#c00;" target="_blank">' + aLinkDesc[3] + '</a></div>\n');
    }
    document.write('        </div>\n');
}

document.write('        </td>\n');
document.write('        </tr>\n');
document.write('        <tr>\n');
document.write('        <td>\n');
document.write('        <input type="hidden" name="refid" value="' + refid + '" /></form>\n');
document.write('       <div style="margin-top:8px;font-size:12px;font-family:arial,sans-serif;color:#666;font-weight:bold;">HighBeam Research has an extensive archive of more than 32 million documents from 2,800 sources.</div></td>\n');
document.write('        </tr>\n');
document.write('        </table>\n');
document.write('    </div>\n');
document.write('    </td>\n');
document.write('    </tr>\n');
document.write('    </table>\n');
document.write('<div><a href="' + clickGoto + 'http://www.highbeam.com" target="_blank"><img src="http://www.highbeam.com/creative/misc/nyt/hbrLogo_fadeUp.gif" alt="" width="158" height="52" border="0"></a></div>\n');
document.write('</td>\n');
document.write('</tr>\n');
document.write('</table>\n');

