// ========================================================================
// Copyright 2003-2005, Lexitech Ltd (http://www.lexitech.co.uk)
// All rights reserved.
// ========================================================================
// $Id: util.js 16 2005-05-23 00:12:32Z tprice $
// ========================================================================

// stop bad bots from trawling for email addresses
// (adapted from a tip by Joseph McLean)

function mailAnchor(who, where, preamble, text, subject, title, extraAttribs) {

    str = "";
    if (who == null || who.length == 0 || where == null || where.length == 0) return str;
    if (text == null || text.length == 0) {
        text = who + "@" + where;
    }
    if (preamble != null && preamble.length > 0) {
        str += preamble;
    }
    str += "<a"
    if (extraAttribs != null && extraAttribs.length > 0) {
        str += " " + extraAttribs;
    }
    str += " href=\"mail" + "to:" + who + "@" + where;
    if (subject == null || subject.length== 0) {
        str += "\"";
    } else {
        str += "?subject=" + subject + "\"";
    }
    if (title != null && subject.length > 0) {
        str += " title=\"" + title + "\"";
    }
    str += ">" + text + "</a>";
    // alert("Mail str: '" + str + "'");
    return str;
}

function writeMail(who, where, preamble, text, subject, title, extraAttribs) {
    document.write(mailAnchor(who, where, preamble, text, subject, title, extraAttribs));
}

function longDayFromShort(dayStr) {
    d = dayStr.toLowerCase();
    if (d == "sun") return "Sunday";
    else if (d == "mon") return "Monday";
    else if (d == "tue") return "Tuesday";
    else if (d == "wed") return "Wednesday";
    else if (d == "thu") return "Thursday";
    else if (d == "fri") return "Friday";
    else if (d == "sat") return "Saturday";
    else return dayStr;
}

function longMonthFromShort(monthStr) {
    m = monthStr.toLowerCase();
    if (m == "jan") return "January";
    else if (m == "feb") return "February";
    else if (m == "mar") return "March";
    else if (m == "apr") return "April";
    else if (m == "may") return "May";
    else if (m == "jun") return "June";
    else if (m == "jul") return "July";
    else if (m == "aug") return "August";
    else if (m == "sep") return "September";
    else if (m == "oct") return "October";
    else if (m == "nov") return "November";
    else if (m == "dec") return "December";
    else return monthStr;
}

function currDate() {
    dateStr = "";
    currDate = new Date();
    if (currDate && currDate.toDateString) {
        dateStr = currDate.toDateString();
    } else {
        dateStr = currDate.toString();
    }
    if (dateStr && dateStr.split) {
        split = dateStr.split(' ');
        munged = longDayFromShort(split[0]) + ", ";
        munged += " " + longMonthFromShort(split[1]);
        munged += " " + split[2];
        munged += " " + currDate.getFullYear()
        dateStr = munged;
    }
    // alert("Current date is '" + dateStr + "'");
    return dateStr;
}

function writeCurrDate() {
    document.write(currDate());
}
