// JavaScript Document

window.onload = initAll;

function initAll()
		{
			newWinLinks();
			initForms();
		}


/****** This section of code is not needed since you discovered how to refresh an iFrame. ********
****************************************************************
Here is the original code that you modified:
function reloadIt()
{
frm=document.getElementsByName("pagers")[0];//we get the iframe object
frm.src=frm.src;//or you can set the src to a new src.
setTimeout("reloadIt()",60000);//the function will run every 60000 miliseconds, or 60 seconds
}

The previous code came from http://www.webdeveloper.com/forum/showthread.php?t=87861
*****************************************************************

	function initMaps()
			{
				var allMaps = new Array("JohnEGreenSaginaw");
				for (var i=0; i<allMaps.length; i++)
					{
							if(document.getElementById)
								{
									document.getElementById(allMaps[i]).className = "mapHidden";
								}
							else
								{
									alert("Sorry, your browser doesn't seem to have JavaScript enabled.");
								} // End of If Else Statement

					} //End of For Loop
	
	
			} //End of initMaps
*******************************************************************************************/

/*  The following funtion was replaced by the one below it, so that individual Google maps would only
load when the user clicked on the "Show Google Map" button.

function showMap(IdName,FrmName)
			{
				if(document.getElementById)
					{
						document.getElementById(IdName).className = "mapVisible";
						frm=document.getElementsByName(FrmName)[0];//we get the iframe object
						frm.src=frm.src;//or you can set the src to a new src.
					}
				else
					{
						alert("Sorry, your browser doesn't seem to have JavaScript enabled.");
					}
			}
*/
function showMap(IdName,FrmName,gglMapString)
			{
				if(document.getElementById)
					{
						document.getElementById(IdName).className = "mapVisible";
						frm = document.getElementsByName(FrmName)[0];//we get the iframe object
						frm.src = gglMapString;//or you can set the src to a new src.
					}
				else
					{
						alert("Sorry, your browser doesn't seem to have JavaScript enabled.");
					}
			}
// http://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=601+Porter+St,+Petoskey,+MI+49770-2848++&amp;sll=38.134557,-95.712891&amp;sspn=28.091652,56.601563&amp;ie=UTF8&amp;s=AARTsJp5bN8SPOYjBCr_rLIQhvpwKRmaxg&amp;ll=45.376388,-84.964657&amp;spn=0.021102,0.036478&amp;z=14&amp;iwloc=addr&amp;output=embed


function hideMap(IdName)
			{
				if(document.getElementById)
					{
						document.getElementById(IdName).className = "mapHidden";
					}
				else
					{
						alert("Sorry, your browser doesn't seem to have JavaScript enabled.");
					}
			}



function initRedirect()
			{
				alert("You are about to go to Google's website within a new browser tab or window. We are not responsible for the content of pages outside our website.");
				window.location = this;
				return false;
			}

function newWinLinks()
			{
				for (var i=0; i<document.links.length; i++)
					{
						if(document.links[i].className == "newWin")
							{
								document.links[i].onclick = newWindow;
							}
					}
			}
			
			
function newWindow()
			{
				alert("You are about to leave our website within a new browser tab or window. Please recognize that we are not responsible for the content of pages outside our website.");
				var mapWindow = window.open(this.href, this.name, "resizable=yes,scrollbars=yes,toolbar=yes,location=yes,status=yes,menubar=yes");//
				return false;
			}
//Code from book			
/*			
function newWinLinks() {
	for (var i=0; i<document.links.length; i++) {
		if (document.links[i].className == "newWin") {
			document.links[i].onclick = newWindow;
		}
	}
}

function newWindow() {
	var mapWindow = window.open(this.href, this.name, "resizable=yes,status=yes");
	return false;
}
*/










/**************************************************************************************
Purpose:		To support the required field form validation for the BAAMP contact page.
Created On:	1/12/09
Code Source:	Visual Quickstart Guide: JavaScript & Ajax Seventh Edition by Tom Negrino and Dori Smith
Modified By:	Phil Allen
Modifications:		If the user forgets to fill in a required field that happens to be a
			text box, the code will put the word "Required" into the textbox field to
			help prompt the user to fill it in.
				The MM_preloadImages function was disabled because it prevented the form
			validation from working at all in Internet Explorer 7. The original purpose of
			the function was to load the navigation mouseOver images as soon as the page
			loaded to prevent any delay for users on a slow internet connection when they
			moused over one of the changing navigation images. 
****************************************************************************************/

/****************************************************************************************************
window.onload = MM_preloadImages('img/contact_on.jpg','img/about_on.jpg','img/serv_prod_on.jpg');
*****************************************************************************************************/
/* The previous line was added so that there would not be a conflict between the onLoad event
in the body tag of the contact.asp file and the "window.onload = initForms;" statement at the 
beginning of this file. The onLoad event was moved from the body tag of the contact.asp file
to the previous statement so that the form validation for required fields would work. */

function initForms() {
	for (var i=0; i<document.forms.length; i++) {
		document.forms[i].onsubmit = function() {return validForm();}
	}
}

function validForm() {
	var allGood = true;
	var allTags = document.getElementsByTagName("*");

	for (var i=0; i<allTags.length; i++) {
		if (!validTag(allTags[i])) {
			allGood = false;
		}
	}
	return allGood;

	function validTag(thisTag) {
		var outClass = "";
		var allClasses = thisTag.className.split(" ");
	
		for (var j=0; j<allClasses.length; j++) {
			outClass += validBasedOnClass(allClasses[j]) + " ";
		}
	
		thisTag.className = outClass;
	
		if (outClass.indexOf("invalid") > -1) {
			thisTag.focus();
			if (thisTag.nodeName == "INPUT")
			{
				thisTag.value = "Required"; //This line was added to make the word, "Required" appear in the field when the field is selected.
				thisTag.select();
			}
								/***** Beginning of section not included with original code.  ******/
								/***** This section was added to make the validation work for
									  the drop-down field for 'State', but it doesn't work
									  right now (1/7/2009).                                  ******/
/*			else if (thisTag.nodeName == "SELECT") //  && thisTag.selectedIndex.value == "default"
			{
//				 thisTag.options[thisTag.selectedIndex].text = "Required";
				 thisTag.select();
			}
								/****** Ending of section not included with original code.  *******/
//			else 
				return false;
		}
		return true;
		
		function validBasedOnClass(thisClass) {
			var classBack = "";
		
			switch(thisClass) {
				case "":
				case "invalid":
					break;
				case "reqd":
					if (allGood && thisTag.value == "") {classBack = "invalid ";}
					else if (allGood && thisTag.value == "default") {classBack = "invalid ";}
					else if (allGood && thisTag.value == "Required") {classBack = "invalid ";}
//					else if (allGood && thistag.value == "(###)+###-####") {classBack = "invalid ";}
//					else if (allGood && thistag.value == "(###) ###-####") {classBack = "invalid ";}
					classBack += thisClass;
					break;
					default:
					classBack += thisClass;
			}
			return classBack;
		}
	}
}

