// JavaScript Document
var pcuCore = {};

addEvent(window, "load", intializePage, false);

function addEvent(elm, eventType, fn, useCapture)
{
	if (elm.addEventListener) // If Firefox then use addEventListener method
	{
		elm.addEventListener(eventType, fn, useCapture);
		return true;
	}
	else if (elm.attachEvent) // If IE use attachEvent method add ON to the event type
	{
		var r = elm.attachEvent("on" + eventType, fn);
		return r;
	}
	else
	{
		elm["on" + eventType] = fn;
	}
}

function intializePage()
{
	var rightCol = document.getElementById("rightCol");
	intNavLinks();
	rightCol.innerHTML = "<iframe name='mainframe' src='mainFrame.htm' frameborder='0' width='600' height='680'></iframe>";
}

function intNavLinks()
{
	var linkExp = /#/g;
	var menuDiv = pcuCore.getElementsByClass("menu");
	var menuLinks = menuDiv[0].getElementsByTagName("a");
	for (i =0; i<menuLinks.length; i++)
	{
		if (!linkExp.test(menuLinks[i].href))
		{
			addEvent(menuLinks[i], "click", changeContent, false)
		}
	}
}


function changeContent(e)
{
	var content = document.getElementsByTagName("iframe");
	if (window.event)
	{
		var elm = window.event.srcElement;
		e.returnValue = false;
	}
	else
	{
		var elm = e.target;
		e.preventDefault();
	}
	
	var linkName = elm.href;
	content[0].setAttribute('src', linkName);
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Java Script Function to get all Elements By Class
// To call function - var elementArray = pcuCore.getElementsByClass("enterClassName");

pcuCore.getElementsByClass = function(theClass)
{
	var elementArray = []; //Array for all elements in document
	
	// Test if an object exist and then
	// Gets all elements in the document
	if (typeof document.all != "undefined") // If doument.all returns anything but undefined
	{
		elementArray = document.all; // For IE 5x does not understand * value
	}
	else
	{
		elementArray = document.getElementsByTagName("*"); // For all other browsers.
	}
	
	var matchedArray = []; //Array for all elements that match the class
	var pattern = new RegExp("(^| )" + theClass + "( |$)"); // Stores the expression for the class to find
	
	// Loops through all elements and find matches to class then stores them in matchedArray var.
	for (var i = 0; i < elementArray.length; i++)
	{
		if (pattern.test(elementArray[i].className)) // If class matches the pattern varible
		{
			matchedArray[matchedArray.length] = elementArray[i]; // Then stores matching element
		}
	}

	return matchedArray; // Returns matching elements to calling function
};

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
//  Javascript from CO-OP to validate form
//
function checkval()
{
	errorstr="";
	errorcount=0;

	match_criteria();
	checkstr();

	if (errorcount==0)
	{ return true }
	else
 	{
 		alert(errorstr)
		return false
 	}
}

function match_criteria()
{
	// require city+state or zip for Canada and U.S.
	if (document.locator_criteria.country.value == 'UNITED STATES' && document.locator_criteria.city.value.replace(/ /g,'') == '' && document.locator_criteria.state.selectedIndex != 0)

// if (document.locator_criteria.city.value.replace(/ /g,'') == '' && document.locator_criteria.state.selectedIndex != 0)
	{
 		errorstr='Please enter either a zip code or a city AND state, but not a state without a city.';
		errorcount++;
	}
 	else if (document.locator_criteria.city.value.replace(/ /g,'') != '' && document.locator_criteria.state.selectedIndex == 0)
	{
		errorstr='Please enter either a zip code or a city AND state, but not a city without a state.';
 		errorcount++;
 	}
	else if (document.locator_criteria.city.value.replace(/ /g,'') != '' && document.locator_criteria.state.selectedIndex != 0)
	{ return true; }
	else if (document.locator_criteria.country.value == 'CANADA' && document.locator_criteria.state.selectedIndex != 0)
	{ return true; }
	else if (document.locator_criteria.zip.value.replace(/ /g,'') == '')
	{
	errorstr='Please enter either a Zip Code or a City AND State.';
	errorcount++;
	}
	else
	{ return true; }
}

function checkstr()
 {
 if (document.locator_criteria.cuname.value.indexOf("'")!=-1 || document.locator_criteria.cuname.value.indexOf("-")!=-1)
 {

 if (errorstr!="")
 { errorstr = errorstr + '\n \n ' }

 errorstr=errorstr + "If your credit union's name contains a dash or apostrophe, please enter the name up to that point. For instance, \"First\" instead of \"First's National\" or \"Central\" instead of \"Central-Union\"."
 errorcount++
 }
 else
 { return true }
} 

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function clearForm() {
//	document.form1.ACCOUNTNUMBER.value="";
//  document.form1.PASSWORD.value="";
	document.form1.reset();
}

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function makeSecure(whereToGo) {
  if (document.location.protocol != "https:") {
    document.location.href=whereToGo;
  }
}

