// --- slideshow --- //

function slideshow() {
	whichphoto = 1
	setTimeout('startslideshow()',5000);
}
function startslideshow() {
	if (whichphoto < howmanyphotos) {
		opacity = 100;
		s = setInterval('fadeout()',1);
	} else {
		opacity = 0;
		s = setInterval('fadein()',1);
	}
}
function fadeout() {
	if (opacity > 0) {
		opacity = opacity - 2;
		document.getElementById('homephoto'+whichphoto).style.opacity=opacity/100;
		document.getElementById('homephoto'+whichphoto).style.mozOpacity=opacity/100;
		document.getElementById('homephoto'+whichphoto).style.filter="alpha(opacity="+opacity+")";
	} else {
		clearInterval(s);
		whichphoto = whichphoto + 1;
		setTimeout('startslideshow()',5000);
	}
}
function fadein() {
	if (opacity < 100) {
		opacity = opacity + 2;
		document.getElementById('homephoto1').style.opacity=opacity/100;
		document.getElementById('homephoto1').style.mozOpacity=opacity/100;
		document.getElementById('homephoto1').style.filter="alpha(opacity="+opacity+")";
	} else {
		clearInterval(s);
		for (x=1; x<=howmanyphotos; x++) {
			document.getElementById('homephoto'+x).style.opacity=opacity/100;
			document.getElementById('homephoto'+x).style.mozOpacity=opacity/100;
			document.getElementById('homephoto'+x).style.filter="alpha(opacity="+opacity+")";
		}
		whichphoto = 1;
		setTimeout('startslideshow()',5000);
	}
}

// --- email validation --- //

function validate() {
	var emailaddress=document.contactform.email

	if (document.contactform.name.value=="") {
		alert("Please fill out the Name field.");
		document.contactform.name.focus();
		return false;
	}

	if (document.contactform.email.value=="") {
		alert("Please fill out the Email field.");
		document.contactform.email.focus();
		return false;
	}

	if (checkemail(emailaddress.value)==false){
		emailaddress.value="";
		emailaddress.focus();
		return false;
	}

	if (document.contactform.message.value=="") {
		alert("Please fill out the Message field.");
		document.contactform.message.focus();
		return false;
	}

	document.contactform.submit();

}

function checkemail(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)

	if (str.indexOf(at)==-1){
		alert("Please enter a valid Email Address.");
		return false;
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		alert("Please enter a valid Email Address.");
		return false;
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		alert("Please enter a valid Email Address.");
		return false;
	}

	if (str.indexOf(at,(lat+1))!=-1){
		alert("Please enter a valid Email Address.");
		return false;
	}

	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		alert("Please enter a valid Email Address.");
		return false;
	}

	if (str.indexOf(dot,(lat+2))==-1){
		alert("Please enter a valid Email Address.");
		return false;
	}
	
	if (str.indexOf(" ")!=-1){
		alert("Please enter a valid Email Address.");
		return false;
	}

	return true;
}