String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ""); }

function ID(id) { return typeof id == "string" ? document.getElementById(id) : id; }

__mo = {};
function mailme() {
	var xyz = ID("xyz");
	if(!xyz) { return; }
	var b = xyz.getElementsByTagName("strong");
	var u = __mo["u"] || (b[0].textContent||b[0].innerText);
	var d = __mo["d"] || "stil" + "leye" + ".com";
	var email = u + unescape("%40") + d;
	var a = document.createElement("a");
	a.setAttribute("href", "mai" + "lto:" + email);
	a.appendChild(document.createTextNode(email));
	xyz.innerHTML = "";
	xyz.appendChild(a);
	xyz.style.backgroundImage = "none";
	xyz.style.textIndent = "0";
}

function validateMailer(form) {
	var errorMsg = "";

	var emailRegExp = /^[a-z0-9]+([_\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\.[a-z]{2,}$/i;

	if( !form.from.value.trim().length ) {
		errorMsg += "- You must enter a name\n";
		form.from.focus();
	}

	if( !form.email.value.trim().match(emailRegExp) ) {
		if( !errorMsg.length ) form.email.focus();
		errorMsg += "- You must enter a valid email address\n";
	}

	if( !form.subject.value.trim() ) {
		if( !errorMsg.length ) form.subject.focus();
		errorMsg += "- You must enter a subject\n";
	}

	if( !form.message.value.trim() ) {
		if( !errorMsg.length ) form.message.focus();
		errorMsg += "- You must enter a message\n";
	}

	if( errorMsg.length ) {
		alert("The following problems were encountered:\n" + errorMsg);
		return false;
	}
	return true;
}

function thisYear() {
	var ty = ID("thisYear");
	if(ty) {
		ty.innerHTML = new Date().getFullYear();
	}
}

function showHide(node) {
	node = ID(node);
	node.style.display = node.style.display != "block" ? "block" : "none";
}

_didInit = false;
function init() {
	if(!_didInit) {
		_didInit = true;
		mailme();
		thisYear();
	}
}

onload = init;
