
window.onload = function() {
	if ((thisPage!="m_home") && (thisPage!="m_none")) {
		changeMenuClass(thisPage, "current");
	}
	setOnClick();
}

function changeMenuClass(id, newClass) {
	identity=document.getElementById(id);
	identity.className=newClass;
}

function openWindow(href) {
	var openWindow = this.open(href, "");//, windowFeatures);
}

var NEW_WIN_MSG = " (opens in new window)";

function setOnClick() {
  if(!document.getElementsByTagName) {
    return;
  }
  var anchors = document.getElementsByTagName("a");
  for (var i=anchors.length; i !=0; i--) {
    var a=anchors[i-1];
	if (a.rel.indexOf("external") != -1) {
		a.title += NEW_WIN_MSG;
		a.onclick = function(){openWindow(this.href);return false;}
	}
	if (a.rel.indexOf("picture") != -1) {
		a.title += NEW_WIN_MSG;
		a.onclick = function(){openPicture(this.href);return false;}
	}
  }
}

//Contact form validation
function validateContactForm() {
	var f_un = document.getElementById("Name");
	if (f_un.value.length<2) {
		alert('Please enter your name.');
		f_un.focus();
		f_un.select();
		return false
	}
	var f_ue = document.getElementById("Email");
	if (!validEmail(f_ue.value)) {
		alert("Please enter a valid email address.");
		f_ue.focus();
		f_ue.select();
		return false
	}
	var f_up = document.getElementById("password");
	if (f_up.value.length<5) {
		alert('Please enter the letters appearing in the image.');
		f_up.focus();
		f_up.select();
		return false
	}
	return true
}

//email validation
function validEmail(email) {
	invalidChars = " /:,;"
	if (email == "") {
		return false
	}
	for (i=0; i<invalidChars.length; i++) {
		badChar = invalidChars.charAt(i)
		if (email.indexOf(badChar,0) != -1) {
			return false
		}
	}
	atPos = email.indexOf("@",1)
	if (atPos == -1) {
		return false
	}
	if (email.indexOf("@",atPos+1) != -1) {
		return false
	}
	periodPos = email.indexOf(".",atPos)
	if (periodPos == -1) {
		return false
	}
	if (periodPos+3 > email.length)	{
		return false
	}
	return true
}

