/**
 * Javascript for Norfolk Punch Theme
 */

//--[ CURRENT DATE ]

var dow = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
var moy = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
var dSuff = ["st", "nd", "rd", "th", "th", "th", "th", "th", "th", "th", "th", "th", "th", "th", "th", "th", "th", "th", "th", "th", "st", "nd", "rd", "th", "th", "th", "th", "th", "th", "th", "st"];

function writeDate()
{
	// Define elements of date
    var today = new Date();
	var day = dow[today.getDay()];
	var dayOfMonth = today.getDate() + dSuff[today.getDate()-1];
	var month = moy[today.getMonth()];
	var year = today.getYear();

	// Correct year [Mozilla, etc.]
	year += ((year < 1900) ? 1900 : 0)

	// Write date to document
	document.write(day + ",&nbsp;" + dayOfMonth + "&nbsp;" + month + ",&nbsp;" + year);
}

//--[ E-MAIL ADDRESS ENCRYPTER ]

function writeEmail(usr, linkTitle, organisation) {

	var action = 'mailto:', add2 = '@kerbology', add3 = '.com';
	var eAdd = usr + add2 + add3;
	linkTitle = (linkTitle == " ") ? eAdd : linkTitle;
	doc.write('<a href="' + action + eAdd + '" title="Click to contact ' + organisation + ' by e-mail">' + linkTitle + '</a>');
}

//--[ E-mail Address Encrypter (v1.0) ]

function email(emailUser,emailDomain)  {

	window.location = 'mailto:' + emailUser + "@" + emailDomain;
}


//--[ Confirm Record Deletion ]

function confirmDelete(type) {

    return confirm('Are you sure you want to delete this ' + type + '?');
}


function bookmarkPage() {

    if (document.all) {
        window.external.AddFavorite(location.href, document.title);
    } else if (window.sidebar) {
        window.sidebar.addPanel(document.title, location.href, "");
    } else {
        alert("Please click Command-D to add this page to your bookmarks/favourites");
    }
}


//--[ EVENT HANDLER ]

/* Thanks to Scott Andrew */
function addEvent(obj, evType, fn) {

    if (obj.addEventListener){ 
        obj.addEventListener(evType, fn, true); 
        return true; 
    } else if (obj.attachEvent){ 
        var r = obj.attachEvent("on"+evType, fn); 
        return r; 
    } else { 
        return false; 
    } 
}


//--[ IMAGE SWAPPER ]

function swapImage(target, filename) {

	document[target].src = filename;
}
