/*
 * This document holds the actions style manipulation
 * to add to the user expierence
*/


/**
 * searchInputText allows the word Search to appear
 * in the search input until the user gives it focus
 *
 * @param element object
 * @return void
*/
function searchInputText(element)
{
	if(element.value == "Search")
	{
	  element.value = "";
	  element.style.color = "#000000";
	  element.style.fontStyle = "normal";
	}
}

/**
 * checkContactForm checks the contact form to make sure
 * all compulsory fields have been entered correctly
 * 
 * @return void
 */
function checkContactForm()
{
	var valid = true;
	
	if(window.document.getElementById('fname').value == "")
	{
		valid = false;
		window.document.getElementById('fnameError').style.visibility = "visible";
		window.document.getElementById('fname').style.backgroundColor = "#fff0f0";
	} else {
		window.document.getElementById('fnameError').style.visibility = "hidden";
		window.document.getElementById('fname').style.backgroundColor = "#FFFFFF";
	}
	if(window.document.getElementById('lname').value == "")
	{
		valid = false;
		window.document.getElementById('lnameError').style.visibility = "visible";
		window.document.getElementById('lname').style.backgroundColor = "#fff0f0";
	} else {
		window.document.getElementById('lnameError').style.visibility = "hidden";
		window.document.getElementById('lname').style.backgroundColor = "#FFFFFF";
	}
	if(window.document.getElementById('email').value == "")
	{
		valid = false;
		window.document.getElementById('emailError').style.visibility = "visible";
		window.document.getElementById('email').style.backgroundColor = "#fff0f0";
	} else {
		window.document.getElementById('emailError').style.visibility = "hidden";
		window.document.getElementById('email').style.backgroundColor = "#FFFFFF";
	}
	if(window.document.getElementById('w78032df').value != 'dam4q2')
	{
		valid = false;
		window.document.getElementById('securityError').style.visibility = "visible";
		window.document.getElementById('w78032df').style.backgroundColor = "#fff0f0";
	} else {
		window.document.getElementById('securityError').style.visibility = "hidden";
		window.document.getElementById('w78032df').style.backgroundColor = "#FFFFFF";
	}
	if(window.document.getElementById('msg').value == "")
	{
		valid = false;
		window.document.getElementById('msg').style.backgroundColor = "#fff0f0";
		window.document.getElementById('msg').innerHTML = "Message Required";
	} else {
		window.document.getElementById('msg').style.backgroundColor = "#FFFFFF";
	}
	
	if(valid)
	{
		return true;
	} else {
		return false;
	}
	
}


/*
 * Below are the variables and functions for dropdown
 * menu
*/

//Global Variables that are needed by the menus
var timer;
var menuItem;
var timeOut = 1000;


/**
 * menuOpen stops the timer for closing the menu item
 * then checks to see if any others are open before
 * opening the required menu item
 *
 * @param elementID string
 * @return void
*/
function menuOpen(elementID)
{
	stopCloseTimer();
	//Check to see if there is a menu item already open
	//if so close previous menu item
	if(menuItem) menuItem.style.visibility = "hidden";
	
	menuItem = document.getElementById(elementID);
	menuItem.style.visibility = "visible";
}

/**
 * startCloseTimer starts the timer for how long
 * the menu item will stay open
 *
 * @return void
*/
function startCloseTimer()
{
	timer = window.setTimeout(closeMenuItem, timeOut);	
}

/**
 * closeMenuItem closes the currently open menu item
 *
 * @return void
*/
function closeMenuItem()
{
	if(menuItem) menuItem.style.visibility = "hidden";
}

/**
 * stopCloseTimer stops the menu close timer and sets
 * it to null
 *
 * @return void
*/
function stopCloseTimer()
{
	if(timer)
	{
		window.clearTimeout(timer);
		timer = null;
	}
}

//Assign closeMenuItem function refrence so when page clicked closes menu
document.onclick = closeMenuItem;
