// JavaScript fuctions for klp.com.au

// script to validate user input for contact form on klp.com.au

function testInput() {
	var name = document.getElementById('name');
	var email = document.getElementById('email');
	var spoofmail = email.value.split('@');
	var spoofaddress = spoofmail[1];
	var spoofname = name.value.split('@');
	var spoofName = spoofname[1];
	if (name.value == "" || email.value == "") {
		alert("Please enter your name and \r a valid email address.");
		name.focus();
		name.style.borderColor = '#F00';
		return false;
	} else if (email.value.indexOf('@') < -1 || email.value.indexOf('.') == -1) {
		alert("Please enter a valid email address.");
		email.focus();
		email.style.borderColor = '#F00';
		return false;
	} else if (spoofaddress == 'klp.com.au' || spoofName == 'klp.com.au') {
		return false;
	}
}

/* 
JavaScript Clock Version 1.3
Written by Kevin Futter Feb 2004
Modified April 2004 to properly handle midday time transition
Lite version to display date only
*/

function calcDate() {
	// initialise Date object variables
	var myTime = new Date();
	var myYear = myTime.getFullYear();
	var myMonth = myTime.getMonth();
	var myDate = myTime.getDate();
	var myDay = myTime.getDay();
	// convert returned day numbers to strings
	if (myDay == 0) {
		myDay = "Sunday";
	} else if (myDay == 1) {
		myDay = "Monday";
	} else if (myDay == 2) {
		myDay = "Tuesday";
	} else if (myDay == 3) {
		myDay = "Wednesday";
	} else if (myDay == 4) {
		myDay = "Thursday";
	} else if (myDay == 5) {
		myDay = "Friday";
	} else if (myDay == 6) {
		myDay = "Saturday";
	}
	// convert returned month numbers to strings
	if (myMonth == 0) {
		myMonth = "January";
	} else if (myMonth == 1) {
		myMonth = "February";
	} else if (myMonth == 2) {
		myMonth = "March";
	} else if (myMonth == 3) {
		myMonth = "April";
	} else if (myMonth == 4) {
		myMonth = "May";
	} else if (myMonth == 5) {
		myMonth = "June";
	} else if (myMonth == 6) {
		myMonth = "July";
	} else if (myMonth == 7) {
		myMonth = "August";
	} else if (myMonth == 8) {
		myMonth = "September";
	} else if (myMonth == 9) {
		myMonth = "October";
	} else if (myMonth == 10) {
		myMonth = "November";
	} else if (myMonth == 11) {
		myMonth = "December";
	}
	// initialise display variables and format
	var displayDate = (myDay + " " + myDate + " " + myMonth + ", " + myYear);
	var date_time = displayDate;
	// write date to document
	document.getElementById('date').innerHTML = date_time;
}

// function to position footer at bottom of viewport if page shorter

function moveFooter() {
	var footer = document.getElementById('footer');
	var footerPos = footer.offsetTop;
	var	viewportHeight = document.body.parentNode.clientHeight;
	var docHeight = document.height;
	//alert('Footer: ' + footerPos + ', Viewport: ' + viewportHeight + ', Page: ' + docHeight);
	if (footerPos < viewportHeight) {
		footer.style.position = 'absolute';
		footer.style.bottom = '0';
	}
}

window.onload = moveFooter;