function writeEmail(sDomain, sAlias, sDisplayText) {

    if (!sDomain)
        sDomain = 'tekwerk.nl';

    sEmail = sAlias + '\u0040' + sDomain;

    if (!sDisplayText)
        sDisplayText = sEmail;

    document.write('<a title="' + sEmail + '" href="mailto:' + sAlias + '\u0040' + sDomain + '">' + sDisplayText + '</a>');

}


function setCookie(name, value, iDays) {

    var today = new Date();
    today.setTime(today.getTime());

    var expires = new Date(today.getTime() + (iDays * 1000 * 60 * 60 * 24));
    var path = '/';
    var domain;
    var secure;

    var sCookie = name + '=' + escape(value) +
        ((iDays) ? ';expires=' + expires.toGMTString() : '') +
        ((path) ? ';path=' + path : '') +
        ((domain) ? ';domain=' + domain : '') +
        ((secure) ? ';secure' : '');

    document.cookie = sCookie;

}


function getCookie(Name) {
    var search = Name + "=";
    if (document.cookie.length > 0) {
        // if there are any cookies 
        offset = document.cookie.indexOf(search);
        if (offset != -1) {
            // if cookie exists 
            offset += search.length;
            // set index of beginning of value
            end = document.cookie.indexOf(";", offset);
            // set index of end of cookie value
            if (end == -1) end = document.cookie.length;
            return unescape(document.cookie.substring(offset, end));
        } else {
            return '';
        }
    }
}


function createMethodReference(object, method) {

    if (!(method instanceof Function))
        method = object[method];

    return function () {
        method.apply(object, arguments);
    };

}


function Debug(sLine, bEscaped) {

    var debugPlaceholder = document.getElementById('debugPlaceholder');

    if (!debugPlaceholder) {

        var body = document.getElementsByTagName('body')[0];

        debugPlaceholder = document.createElement('div');
        debugPlaceholder.id = 'debugPlaceholder';
        debugPlaceholder.style.backgroundColor = 'White';
        debugPlaceholder.style.border = '1px dashed #bbb';
        debugPlaceholder.style.padding = '5px 5px 0px 5px';
        debugPlaceholder.style.color = '#bbb';
        debugPlaceholder.style.position = 'absolute';
        debugPlaceholder.style.top = '0px';
        debugPlaceholder.style.left = '0px';
        debugPlaceholder.style.zIndex = 100;

        body.appendChild(debugPlaceholder);

    }

    if (bEscaped)
        sLine = unescape(sLine);

    var debugLine = document.createElement('p');
    debugLine.appendChild(document.createTextNode(sLine));

    debugPlaceholder.appendChild(debugLine);

}


function formatCurrency(num) {

    num = num.toString().replace(/\$|\,/g, '');

    if (isNaN(num))
        num = "0";

    sign = (num == (num = Math.abs(num)));
    num = Math.floor(num * 100 + 0.50000000001);
    cents = num % 100;
    num = Math.floor(num / 100).toString();

    if (cents < 10)
        cents = "0" + cents;

    for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++)
        num = num.substring(0, num.length - (4 * i + 3)) + '.' +
	num.substring(num.length - (4 * i + 3));
    return (((sign) ? '' : '-') + '\u20AC ' + num + ',' + cents);

}


function findPos(obj) {

    var curleft = 0;
    var curtop = 0;

    if (obj.offsetParent) {
        do {
            curleft += obj.offsetLeft;
            curtop += obj.offsetTop;
        } while (obj = obj.offsetParent);
    }

    return [curleft, curtop];

}


function removeChildNodes(node) {

    if (node) {

        while (node.hasChildNodes()) {

            node.removeChild(node.firstChild);

        }

    }

}


function replaceText(node, sText) {

    removeChildNodes(node);

    node.appendChild(document.createTextNode(sText));

}
