function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		};
	};
}

function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") &&
				anchor.getAttribute("rel") == "external")
			anchor.target = "_blank";
		}
}

// function clearText(thefield){
// if (thefield.defaultValue==thefield.value)
// 	thefield.value = "";
// }

function autoClear(){
	var inp = document.getElementsByTagName('input');
	for(var i = 0; i < inp.length; i++) {
		if(inp[i].type == 'text') {
			inp[i].setAttribute('rel',inp[i].defaultValue);
			inp[i].onfocus = function() {
				if(this.value == this.getAttribute('rel')) {
					this.value = '';
				} else {
					return false;
				};
			};
			inp[i].onblur = function() {
				if(this.value == '') {
					this.value = this.getAttribute('rel');
				} else {
					return false;
				}
			};
		}
	}
}

function CheckEmail(form) {
	// email = form.email.value;
	email = document.getElementById('signupemail').value;
	AtPos = email.indexOf("@");
	StopPos = email.lastIndexOf(".");
	Message = "";

	if (email == "") {
	Message = "Not a valid Email address" + "\n";
	}

	if (AtPos == -1 || StopPos == -1) {
	Message = "Not a valid email address";
	}

	if (StopPos < AtPos) {
	Message = "Not a valid email address";
	}

	if (StopPos - AtPos == 1) {
	Message = "Not a valid email address";
	}

	// alert(Message);
	
	if (Message == "") {
		return true;
	}
	else {
		alert(Message);
		return false;
	}
	
}

sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		};
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		};
	}
};
if (window.attachEvent) window.attachEvent("onload", sfHover);



addLoadEvent(externalLinks);
addLoadEvent(autoClear);
