// JavaScript Document

// ------------ MAIN NAVIGATION ------------>

// variable to monitor last expanded submenu
var last_expanded = "";

// Create a function to show/hide sub menu groups
function showHide(id) {	
	// Get id of each submenu group
	var obj = document.getElementById(id);
	
	// Create variable to set show/hide status of each submenu group
	var status = obj.className;

	// Create if/else statement to see if submenu group is showing or hidden
	if (status == "hide") {
		
		// if the last expanded submenu is not hidden then hide that submenu
		if (last_expanded != "") {
			var last_obj = document.getElementById(last_expanded);
			last_obj.className = "hide";
		}
		
		// If submenu group is hidden, then set status to show
		obj.className = "show";
		last_expanded = id;		

	} else {
		
		// Else hide that submenu
		obj.className = "hide";
	}
}


// ------------ CONTACT FORM VALIDATION ------------>

// Global variable to hold all error messages.
var errMsg = "";

function init() {
	getName();
	getEmail();
	
	// Display the error messages
	if( displayErrorMessage() ) {
		return true;
		// Send to php script
		// mailer.php
	} else {
		return false;
	}
}


//Validate the user input from the form.
//User Name
function getName() {
	
	var userName = document.getElementById('name').value;
	if (userName != null && userName.length > 0) {
	// First Name exists.
	
	} else {
		errMsg += "\n Enter your name.";
		document.getElementsByTagName('input')[0].className = 'requiredfield'; //Change field to yellow
		document.getElementsByTagName('label')[0].className = 'requiredtext'; //Change text to red
	// First Name doesn't exist.
	}
}


//Email
function getEmail() {
	var validEmail = /^(\w+\.)*\w+@(\w+\.)+[A-Za-z]+$/; // Regular expression for pattern of an email

	var userEmail = document.getElementById('email').value;
	if (validEmail.test(userEmail)) {
	// E-mail address is valid.

 	} else {
	errMsg += "\n Enter a valid email address.";
	document.getElementsByTagName('input')[1].className = 'requiredfield'; //Change field to yellow
	document.getElementsByTagName('label')[1].className = 'requiredtext'; //Change text to red
	// E-mail address isn't valid.
 }
}


//Display the validation results accordingly (see Screen Captures).
function displayErrorMessage() {
	var isValidData = false;
	
	if (errMsg != null && errMsg.length > 0) {
		alert("Please fix the following issues:\n" + errMsg);
	}  else {
		isValidData = true;	
	}
	
	return isValidData;
}


//  ------------ HOMEPAGE SLIDESHOW ------------>

img2 = new Image()

seconds = "2.5";

function imgOne()
{
document.myimg.src = "images/home_SlideShow02.jpg" ; 
setTimeout("imgTwo()", seconds * 1000);
}
function imgTwo()
{
document.myimg.src ="images/home_SlideShow03.jpg";
setTimeout("imgThree()", seconds * 1000);
}
function imgThree()
{
document.myimg.src ="images/home_SlideShow06.jpg";
setTimeout("imgFour()", seconds * 1000);
}
function imgFour()
{
document.myimg.src ="images/home_SlideShow07.jpg";
setTimeout("imgFive()", seconds * 1000);
}
function imgFive()
{
document.myimg.src ="images/home_SlideShow08.jpg";
setTimeout("imgSix()", seconds * 1000);
}
function imgSix()
{
document.myimg.src = "images/home_SlideShow01.jpg" ; 
setTimeout("imgOne()", seconds * 1000);
}
/*function imgSeven()
{
document.myimg.src = "images/home_SlideShow01.jpg" ; 
setTimeout("imgOne()", seconds * 1000);
}
function imgEight()
{
document.myimg.src = "images/home_SlideShow01.jpg" ; 
setTimeout("imgOne()", seconds * 1000);
}
*/
//  ------------ INTERACTIVE NEW WINDOWS ------------>

function newWindow(pFile, pName, pSize) { 
  var myWindow = window.open(pFile, pName, pSize, menubar=0, location=0);
}

//  ------------ OPENING EXTERNAL WINDOWS ------------>
$("a.external").attr({ target: "_blank"});

