
//Opens a link in a new window
function open_win(URL, name) 
	{
    window.open(URL, name)
    }
		
		
		
// Displays and email address link dynamically to prevent spammers trawling
	
	// Input
	// name: text - email user name
	// domain: text - domain name
	// tld: text - top level domain (com, org, biz ...)
	// region: text - (none for US) au, uk and so on.
	// label: text - text of link displayed

	// Returns - nothing
	
	function secureEmail (name, domain, tld, region, label)
	{
		var theString = "<a href=\"mailto:";
		
		theString += name;
		theString += "@";
		theString += domain;
		theString += ".";
		theString += tld;
		theString += ".";
		theString += region;
		theString += "\">";
		theString += label;
		theString += "</a>";
		
	// alert(theString);
	
		document.write(theString);
	}	
	
// Inserts date the file was last modified on the page	
function date_modified()
	/* var days = new Array(8);
	days[1] = "Sunday";
	days[2] = "Monday";
	days[3] = "Tuesday";
	days[4] = "Wednesday";
	days[5] = "Thursday";
	days[6] = "Friday";
	days[7] = "Saturday";*/
	
	{
		var months = new Array(13);
		months[1] = "January";
		months[2] = "February";
		months[3] = "March";
		months[4] = "April";
		months[5] = "May";
		months[6] = "June";
		months[7] = "July";
		months[8] = "August";
		months[9] = "September";
		months[10] = "October";
		months[11] = "November";
		months[12] = "December";
		
	var dateObj = new Date(document.lastModified)
	//var wday = days[dateObj.getDay() + 1]
	var date = dateObj.getDate()
	var lmonth = months[dateObj.getMonth() + 1]
	var fyear = dateObj.getYear()
	
	if (fyear < 2000)
		fyear = fyear + 1900
	//document.write(wday + ", " + lmonth + " " + date + ", " + fyear)
	
	document.write("Last updated: " + date + " " + lmonth + " " + fyear);
	}	
	

//All associated with validating contact form	
function Trim(STRING){
STRING = LTrim(STRING);
return RTrim(STRING);
}

function RTrim(STRING){
while(STRING.charAt((STRING.length -1))==" "){
STRING = STRING.substring(0,STRING.length-1);
}
return STRING;
}


function LTrim(STRING){
while(STRING.charAt(0)==" "){
STRING = STRING.replace(STRING.charAt(0),"");
}
return STRING;
}

function isAlpha(str) 
{
	//regex stands for regular expressions
  var regex = /^[A-Z|a-z\s]./;
//	var result = regex.test(str);
  return regex.test(str);
}

function isEmailValid(str) 
{
	//regex stands for regular expressions
  var regex = /^[\w_\.]*[\w_\.]@([\w]+\.)+[\w]*[\w]$/;
  return regex.test(str);
}


function validateForm()
{
	//check that "your_name" is not empty and only contains alpha characters
	// || means "or" && means "and"
  if ((Trim(document.getElementById("your_name").value).length == 0) 
			|| (isAlpha(document.getElementById("your_name").value) == false))
  		{
  		alert("Please enter your name");
		document.getElementById("your_name").focus();
		return false;
  		}
  
  //check that "email" is not empty and contains a valid email address
	if (Trim(document.getElementById("email").value).length == 0)
		{
		alert("Please enter your email address");
		document.getElementById("email").focus();
		return false;
		}
		
	else {
		if(isEmailValid(document.getElementById("email").value) == false)
			{
  			alert("Please check that your email address is correct");
  			document.getElementById("email").focus();
  			return false;
			}
		}
	document.contact_me.submit();
}

