//Global variable
queryString = unescape(document.location.search.substring(1));

//Array for 'ShowStatus' Messages
arrMsg = new Array();

//Messages for toolbar and footer
arrMsg.home = "East Hill Friends home page";
arrMsg.about = "Learn more about our beliefs and about Quakers";
arrMsg.contact = "Send us a message";
arrMsg.directions = "See local map and get driving directions to the church";
arrMsg.links = "Links to some useful sites";
arrMsg.top = "Top of Page";

//Messages for all other
arrMsg.alpha = "An opportunity to explore the meaning of life";
arrMsg.bsf = "An interdenominational lay Christian organization with bible study classes in the US and around the world";
arrMsg.email = "Email address - Please double check for accuracy!";
arrMsg.favorites = "Add East Hill Friends Church to your favorites!";
arrMsg.fruit = "Fruit of the Vine, a weekly devotional published by Barlay Press";
arrMsg.evangelicalFriends = "Find out about more about Evangelical Friends history and beliefs";
arrMsg.goToYahoo = "Get suggested driving directions from Yahoo! Maps";
arrMsg.message = "Enter a message - Let us know what you are interested in!";
arrMsg.mission = "Learn about the Evangelical Friends Mission";
arrMsg.name = "Please enter your name";
arrMsg.needHim = "That one special relationship with Jesus!";
arrMsg.nwym = "Visit the Northwest Yearly Meeting of Friends website";
arrMsg.quakerCove = "A Friends camp located on the Puget Sound with camping and retreat facilities available";
arrMsg.verse = "See this verse in the International Reader's Version of the bible";
arrMsg.telephone = "Telephone number and area code - Best time to call?";
arrMsg.twinRocks = "Take a look at the Twin Rocks Camp and Conference Center on the beautiful Oregon coast";


function ShowStatus(key)
{
	var msg = (key) ? arrMsg[key] : "";	
	window.status = msg;	
}

function AddToFavorites()
{
	var urlAddress = "http://www.EastHillFriendsChurch.com";
	var pageName = "East Hill Friends Church";
	
	if (window.external)
		window.external.AddFavorite(urlAddress,pageName);
	else
		alert("Sorry! Your browser doesn't support this function.");	
}

function GetFirstName()
{
	var firstName = (queryString && queryString.indexOf("firstName=") == 0) ? queryString.split("firstName=")[1] : "";
	return firstName;
}

function Validate(form)
{   
    //Alert if name is empty
	if (form.Name.value == "")
	{
		alert("Please enter your name.");
		form.Name.focus();
		return false;
	}

	//Alert if telephone is incomplete
	if (form.Telephone.value.length < 10)
	{
		alert("Please enter your complete telephone number, including the area code.");
		form.Telephone.focus();
		return false;
	}
	  
    //Alert if email is incomplete
	if (form.Email.value == "")
	{           
	    alert("Please enter your email address.");
	    form.Email.focus();
	    return false;	
	}
	
	//Alert if message is missing
	if (form.Message.value == "")
	{
	    alert("Please enter a message to email.");
	    form.Message.focus();
	    return false;
	}

    //Validate email address
    var sendTo = form.Email.value;
    var arrTo = sendTo.split("; ");  
    var rxEmail=/^\w(\.?[\w-])*@\w(\.?[\w-])*\.[a-z]{2,6}(\.[a-z]{2})?$/i;

    for (var i=0; i<(arrTo.length); i++)
    {
        if (!rxEmail.test(arrTo[i]))
        {      
          alert("The e-mail address "+ arrTo[i] +" does not appear to be valid");
          return false;
        }
    }
    
    //Redirect after message is sent
    var name =  form.Name.value;
	var firstName = name.split(" ")[0];

	form.redirect.value = "index.htm?firstName=" + escape(firstName);
	return true;
}
