// JavaScript Document
	// Preload Images
	var myimages = new Array();
	var imagedir = "images/";
	function preloadimgs(){
		if (document.images)
		{
			var arrlen = myimages.length;
			for (var x=0; x<arguments.length; x++){
				myimages[x + arrlen] = new Image();
				myimages[x + arrlen].src = imagedir + arguments[x];
			}
		}
	}
	//preloadimgs("main-buttonover-tile.gif","main-button-tile.gif");
	
	function menuclass() {
		for (var x=0; x<arguments.length; x++){
			ele = document.getElementById(arguments[x]);
			ele.className += (ele.className ? " " : "") + "currentmenu";
			for (var i=0; i<ele.childNodes.length; i++) {
				aele = ele.childNodes[i];
				if (aele.nodeName == "A") 
					aele.className += (aele.className ? " " : "") + "currentmenu";
			}
		}
	}
	
	function evtObserve(element, name, observer, useCapture) {
		if (typeof element == 'string')
			element = document.getElementById(element);
		if (element.addEventListener) {
			element.addEventListener(name, observer, useCapture);
		} else if (element.attachEvent) {
			element.attachEvent('on' + name, observer);
		}
	}

function btnExpand(hiddenDiv, inputDiv) {
	if (document.getElementById(hiddenDiv).style.display!='block') {
		document.getElementById(inputDiv).value = "";
		document.getElementById(hiddenDiv).style.display='block';
		document.getElementById(inputDiv).focus();
	} else {
		document.getElementById(hiddenDiv).style.display='none';
	}
}

function mnuExpand(folderDiv) {
	for (var i=0; i<folderDiv.childNodes.length; i++) {
		var ele = folderDiv.childNodes[i];
		if (ele.nodeName == "UL") 
			if (ele.style.display!='block') {
				ele.style.display='block'
			} else {
				ele.style.display='none'
			}
	}
}

//Call from on submit to avoid popup blocker errors and allow submit by return.
function newatmsubmit(theinpt) {
	document.getElementById("atmcity").value = "";
	document.getElementById("atmstate").value = "";
	document.getElementById("atmzip").value = "";
	errmsg = "";
	txt = document.getElementById(theinpt).value;
	zip = parseInt(txt);
	if (zip > 0 && txt.length < 5) {
		errmsg = 'You did not enter a valid zipcode.  Would you like to go to the ATM Locator website?';
	} else if (zip > 0) {
		document.getElementById("atmzip").value = zip;
	} else {
		com = txt.indexOf(',');
		if (com < 1) {
			errmsg = 'You must enter both a city and state.  Would you like to go to the ATM Locator website?';
		} else {
			/*String.prototype.trim = function() {
				return this.replace(/^\s+|\s+$/g,"");
			}
			String.prototype.ltrim = function() {
				return this.replace(/^\s+/,"");
			}
			String.prototype.rtrim = function() {
				return this.replace(/\s+$/,"");
			}*/
			document.getElementById("atmcity").value = (txt.substr(0, com)).replace(/^\s+|\s+$/g,"");
			document.getElementById("atmstate").value = (txt.substr(com+1)).replace(/^\s+|\s+$/g,"");
		}
	}

	if (errmsg.length > 0) {
		ask = confirm(errmsg);
		if (ask == false) return false;
		launchwin("http://www.co-opfs.org/public/locators/atmlocator/", true, 780, 600);
		return false;
	}
	var ask = confirm('You are now leaving WyHy Federal Credit Union\'s website and connecting to a web-site that is not operated by the Credit Union.  WyHy is not responsible for the content or availability of linked sites.  The privacy and security policies of the linked site may differ from the WyHy site.');
	if (ask == false) return false;
	else {
		var win = window.open("",'wyhypop','scrollbars=yes,resizable=yes,width=780,height=600');
		var a = window.setTimeout("document.form['atmlaunch'].submit();",500);
		if (window.focus) {win.focus()}
		return true;
	}
}

function sharedsubmit(theinpt) {
	state = document.getElementById(theinpt).value;
	if (state == 0) {
		shared = "http://www.cuservicecenter.com";
		ask = confirm('You did not select a state.  Would you like to go to the Shared Banking website?');
		if (ask == false) return false;
	}
	else {
		//shared = "http://www.cuservicecenter.com/searchResults.aspx?address=&city=&zip=&international=US&radius=10&recordStart=0&state=" + state;
		shared = "http://www.cuservicecenter.com/ServiceCenters.aspx?&country=US&state=" + state;
	}
	return launchwin(shared, true, 1024, 800);
}

function launchwin(newurl, warning, winwidth, winheight) {
	if (warning == true) {
		var ask = confirm('You are now leaving WyHy Federal Credit Union\'s website and connecting to a web-site that is not operated by the Credit Union.  WyHy is not responsible for the content or availability of linked sites.  The privacy and security policies of the linked site may differ from the WyHy site.');
		if (ask == false) return false;
	}
	
	var opts = "";
	if (winwidth!=undefined) opts += ',width=' + winwidth;
	if (winheight!=undefined) opts += ',height=' + winheight;
	var win = window.open(newurl,'','scrollbars=yes,resizable=yes'+opts);
	if (window.focus) {win.focus();}
	return win;
}

// SlideShow Class used to rotate thru banners.
SlideShow = {
	currentimg:1,
	timer:null,
	imgcnt:2,
	idPrefix:"pict",
	isRndm:false,
	timeout:5000,
	menuItems:null,
	linkid:null,
	next: function() {
		this.stoptimer();
		next=this.currentimg + 1;
		if (next > this.imgcnt) next = 1;
		this.display(next, this.currentimg);
	},
	prev: function() {
		this.stoptimer();
		next=this.currentimg - 1;
		if (next < 1) next = this.imgcnt;
		this.display(next, this.currentimg);
	},
	showPic: function(picnum) {
		this.stoptimer();
		next=picnum;
		if (next < 1) next = this.imgcnt;
		if (next > this.imgcnt) next = 1;
		if (next == this.currentimg) return;
		this.display(next, this.currentimg);
	},
	stoptimer: function() {
		if (this.timer != null) {
			clearTimeout(this.timer);
			this.timer = null;
		}
	},
	start: function(prefix, timeout, rndm, linkid) {
		this.idPrefix = prefix;
		this.timeout = timeout;
		this.imgcnt = 0;
		this.timer="start";
		this.menuItems = new Array();
		if (linkid.length > 0) this.linkid = document.getElementById(linkid);
		while (document.getElementById(this.idPrefix + (this.imgcnt + 1))) {
			var picDiv = document.getElementById(this.idPrefix + (this.imgcnt + 1));
			for (var i=0; i<picDiv.childNodes.length; i++) {
				var aTag = picDiv.childNodes[i];
				if (aTag.nodeName == "A") {
					for (var j=0; j<aTag.childNodes.length; j++) {
						var ele = aTag.childNodes[j];
						if (ele.nodeName == "IMG") {
							for (var k=0; k<ele.attributes.length; k++) {
								var attr = ele.attributes[k];
								if (attr.nodeName == "alt") this.menuItems.push(attr.nodeValue);
							}
						}
					}
				}
			}
			this.imgcnt++;
		}
		if (rndm) {
			this.isRndm = true;
			disp = rndm(0);
			this.display(rndm(disp), disp);
		} else {
			this.isRndm = false;
			this.display(1, 2);
		}
	},
	rndm: function(ignore) {
		rnd = ignore;
		while (rnd == ignore) {
			rnd = Math.ceil(Math.random() * this.imgcnt);
		}
		return rnd;
	},
	showMenu: function() {
		if (this.linkid != null) {
			// First Clear the menu
			for (var i=this.linkid.childNodes.length-1; i>=0; i--) {
				this.linkid.removeChild(this.linkid.childNodes[i]);
			}
			// Now Add them
			for (i = 0; i < this.menuItems.length; i++) {
				li_ele = document.createElement("li");
				a_ele = document.createElement("a");
				a_ele.setAttribute("href", "javascript:SlideShow.showPic("+(i+1)+")");
				if (i == this.currentimg - 1) a_ele.className="current";
				a_ele.appendChild(document.createTextNode(this.menuItems[i]));
				li_ele.appendChild(a_ele);
				this.linkid.appendChild(li_ele);
			}
		}
	},
	display: function(on, off) {
		this.currentimg = on;
		this.showMenu();
		var pon = document.getElementById(this.idPrefix + on);
		pon.style.right = "0px"
		var poff = document.getElementById(this.idPrefix + off);
		poff.style.right = "6000px"
		if (this.isRndm) {
			next = rndm(on);
		} else {
			next = on + 1;
			if (next > this.imgcnt) next = 1;
		}
		if (this.timer != null)
			this.timer = setTimeout('SlideShow.display('+next+','+on+');', this.timeout);
	}
};

