function openHelpPopup(text) {
    if (screen.width) {
        ls = screen.width / 2 - 350 / 2;
    } else {
        ls = 50;
    }
    if (screen.height) {
        ts = screen.height / 2 - 170 / 2;
    } else {
        ts = 50;
    }
    wh = window.open ('','sHelp','left='+ls+',top='+ts+',width=350,height=170,toolbar=no,menubar=no,status=no,directories=no,resizable=yes,scrollbars=no,modal=1');
    wh.document.writeln('<html><head><title>Help</title>');
    wh.document.writeln('<link rel="stylesheet" type="text/css" href="/css/popup.css">');
    wh.document.writeln('</head>');
    wh.document.writeln('<body onload="window.focus();">');
    wh.document.writeln('<div class="fieldset" style="overflow: auto; width:330px; height:115px; margin-bottom: 10px; padding: 5px;">' + text + '</div>');
    wh.document.writeln('<div style="text-align: center; position: absolute; bottom: 10px; right: 10px;"><button onclick="window.close();" class="window">Sluiten</button></div>');
    wh.document.writeln('</body></html>');
    return false;
}

function stripHelpText(text)
{
    text = text.replace(/<h2[^>]*>.*?<\/h2[^>]*>/gi, '');
    text = text.replace(/<br[^>]*>/gi, '\n');
    text = text.replace(/<[^>]+>/g, '');
    return text;
}

/**
 * Escape double quotes (") and/or single quotes (')
 *
 * This function escapes the quotes for use in the help function. It replaces double quotes with &quot; and single quotes with \'
 *
 * @param  string  text  The text to quote
 * @param  int     type  Which quotes to escape: 1 = only double quotes, default = both
 *
 * @return string  The escaped string
 */
function helpEscapeQuotes(text, type)
{
    // type == 1 : only "
    // default : " and '
    if (type != 1) {
        text = text.replace(new RegExp("'", 'g'), "\\'");
    }
    text = text.replace(new RegExp('"', 'g'), '&quot;');
    return text;
}

function getHelpIconHtml(text)
{
    if (text && text.length) {
        return '<img src="/images/icons/help_16x16.png" title="' + helpEscapeQuotes(stripHelpText(text).substr(0, 200), 1) + '" onclick="openHelpPopup(\'' + helpEscapeQuotes(text) + '\');" style="cursor: pointer;">';
    } else {
        return '';
    }
}