
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}



function MM_jumpMenu(targ,selObj,restore){ //v3.0 
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+".html'"); 
if (restore) selObj.selectedIndex=0; 
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}



function checkRadios() {
 var el = document.forms[0].elements;
 for(var i = 0 ; i < el.length ; ++i) {
  if(el[i].type == "radio") {
   var radiogroup = el[el[i].name]; // get the whole set of radio buttons.
   var itemchecked = false;
   for(var j = 0 ; j < radiogroup.length ; ++j) {
    if(radiogroup[j].checked) {
	 itemchecked = true;
	 break;
	}
   }
   if(!itemchecked) { 
    alert("Please choose an answer for "+el[i].name+".");
    if(el[i].focus)
     el[i].focus();
	return false;
   }
  }
 }
 return true;
} 


function submitonce(theform){
	if (document.all||document.getElementById){
		for (i=0;i<theform.length;i++){
		var tempobj=theform.elements[i]
		if(tempobj.type.toLowerCase()=="submit"||tempobj.type.toLowerCase()=="reset")
		tempobj.disabled=true
		}
	}
}


function isPhoneNum(value) {

var pattern = new RegExp("^[0-9]+$");
	if (!pattern.test(value)){
			alert('The phone number should contain numbers only.');
			document.questionaire.phone.focus();	
		return false;
	}

	if (value.length < 10) {
	alert('Please enter a valid phone number including area code - you did not enter enough numbers');
	document.questionaire.phone.focus();
		return false;
	}

	var pattern = new RegExp("^[0-9\-()\.\+ ]+$");
	if (!pattern.test(value)) {
	alert('Please enter a valid phone number');
	document.questionaire.phone.focus();
			return false;
	}
	return true;
}
 
function validatetf() {


if (document.tellafriend.friendmail1.value.length==0) {
alert("please enter your friend's email address");
return false;
}

if (document.tellafriend.email.value.length==0) {
alert("please enter your email address");
return false;
}
if (document.tellafriend.name.value.length==0) {
alert("please enter your name");
return false;
}

document.tellafriend.submit()
return true;
}

function popSSL(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=400,height=300,left = 20,top = 20');"); }


isIE=document.all;
isNN=!document.all&&document.getElementById;
isN4=document.layers;
isHot=false;

function ddInit(e){
  topItem=isIE ? "BODY" : "HTML";
  whichItem=isIE ? document.all.theLayer : document.getElementById("theLayer");  
  hotItem=isIE ? event.srcElement : e.target;  
  while (hotItem.id!="titleBar"&&hotItem.tagName!=topItem){
    hotItem=isIE ? hotItem.parentElement : hotItem.parentNode;
  }  
  if (hotItem.id=="titleBar"){
    offsetx=isIE ? event.clientX : e.clientX;
    offsety=isIE ? event.clientY : e.clientY;
    nowX=parseInt(whichItem.style.left);
    nowY=parseInt(whichItem.style.top);
    ddEnabled=true;
    document.onmousemove=dd;
  }
}

function dd(e){
  if (!ddEnabled) return;
  whichItem.style.left=isIE ? nowX+event.clientX-offsetx : nowX+e.clientX-offsetx; 
  whichItem.style.top=isIE ? nowY+event.clientY-offsety : nowY+e.clientY-offsety;
  return false;  
}

function ddN4(whatItem){
  if (!isN4) return;
  N4=eval(whatItem);
  N4.captureEvents(Event.MOUSEDOWN|Event.MOUSEUP);
  N4.onmousedown=function(e){
    N4.captureEvents(Event.MOUSEMOVE);
    N4x=e.x;
    N4y=e.y;
  }
  N4.onmousemove=function(e){
    if (isHot){
      N4.moveBy(e.x-N4x,e.y-N4y);
      return false;
    }
  }
  N4.onmouseup=function(){
    N4.releaseEvents(Event.MOUSEMOVE);
  }
}

function showMe(id) { 
	active = id; 
	if (document.all) { 
	document.all[active].style.visibility = "visible";
	} 
	if(document.layers) { 
	document.layers[active].visibility = "show" ;
	} 
	if(document.getElementById) {
	document.getElementById(active).style.visibility='visible';
	} 
}

function hideMe(id){
	active = id; 
	if (document.all) { 
	document.all[active].style.visibility = "hidden"; 
	} 
	if(document.layers){ 
	document.layers[active].visibility = "hide";
	} 
	if(document.getElementById) {
	document.getElementById(active).style.visibility='hidden';
	} 
}


document.onmousedown=ddInit;
document.onmouseup=Function("ddEnabled=false");

var popUpWin=0;
function popUpWindow(URLStr, left, top, width, height)
{
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menub ar=no,scrollbar=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}


var relatedTag = 'TR';

var compatible = (
	document.getElementById && document.getElementsByTagName && document.createElement
	&&
	!(navigator.userAgent.indexOf('MSIE 5') != -1 && navigator.userAgent.indexOf('Mac') != -1)
	);

if (compatible)
	document.write('<style>.accessibility{display: none}</style>');


function prepareForm()
{

	if (!compatible) return;
	var marker = document.createElement(relatedTag);
	marker.style.display = 'none';

	var x = document.getElementsByTagName(relatedTag);
	var toBeRemoved = new Array;
	for (var i=0;i<x.length;i++)
	{
		if (x[i].getAttribute('relation'))
		{
			var y = getAllFormFields(x[i]);
			x[i].nestedRels = new Array;
			for (var j=0;j<y.length;j++)
			{
				var rel = y[j].getAttribute('show');
				if (!rel || rel == 'none') continue;
				x[i].nestedRels.push(rel);
			}
			if (!x[i].nestedRels.length) x[i].nestedRels = null;
			toBeRemoved.push(x[i]);
		}
	}

	while (toBeRemoved.length)
	{
		var rel = toBeRemoved[0].getAttribute('relation');
		if (!document.getElementById(rel))
		{
			var newMarker = marker.cloneNode(true);
			newMarker.id = rel;
			toBeRemoved[0].parentNode.replaceChild(newMarker,toBeRemoved[0]);
		}
		document.getElementById('waitingRoom').appendChild(toBeRemoved.shift());
	}
	document.onclick = arrangeFormFields;

	var y = document.getElementsByTagName('input');
	for (var i=0;i<y.length;i++)
	{
		if (y[i].checked && y[i].getAttribute('show'))
			intoMainForm(y[i].getAttribute('show'))
	}

	var z = document.getElementsByTagName('select');
	
	// Opera weird with hidden selects in quirks mode: selectedIndex = -1
	
	for (var i=0;i<z.length;i++)
	{
		if (z[i].options[z[i].selectedIndex].getAttribute('show'))
		{
			z[i].onchange = arrangeFormFields;
			intoMainForm(z[i].options[z[i].selectedIndex].getAttribute('show'))
		}			
	}
}

function arrangeFormFields(e)
{
	if (!e) var e = window.event;
	var tg = (e.target) ? e.target : e.srcElement;
	if (
		!(tg.nodeName == 'SELECT' && e.type == 'change')
		&&
		!(tg.nodeName == 'INPUT' && tg.getAttribute('show'))
	   ) return;
	var toBeInserted = tg.getAttribute('show');

	/* Why no switch statement? Because Netscape 3 gives an error message on encountering it,
		and this script must degrade perfectly. */

	if (tg.type == 'checkbox')
	{
		if (tg.checked)
			intoMainForm(toBeInserted);
		else
			intoWaitingRoom(toBeInserted);
	}
	else if (tg.type == 'radio')
	{
		removeOthers(tg.form[tg.name],toBeInserted)
		intoMainForm(toBeInserted);
	}
	else if (tg.type == 'select-one')
	{
		toBeInserted = tg.options[tg.selectedIndex].getAttribute('show');
		removeOthers(tg.options,toBeInserted);
		intoMainForm(toBeInserted);
	}
}

function removeOthers(others,toBeInserted)
{
	var toBeRemoved = new Array;
	for (var i=0;i<others.length;i++)
	{
		var show = others[i].getAttribute('show');
		if (show != toBeInserted)
			toBeRemoved.push(show);
	}
	while (toBeRemoved.length)
		intoWaitingRoom(toBeRemoved.shift());
}

function gatherElements(name)
{
	var Elements = new Array;
	var x = document.getElementsByTagName(relatedTag);
	for (var i=0;i<x.length;i++)
		if (x[i].getAttribute('relation') == name)
			Elements.push(x[i]);
	return Elements;
}

function intoWaitingRoom(name)
{
	if (name == 'none') return;
	var Elements = gatherElements(name);
	if (isInWaitingRoom(Elements[0])) return;
	while (Elements.length)
	{
		if (Elements[0].nestedRels)
			for (var i=0;i<Elements[0].nestedRels.length;i++)
				intoWaitingRoom(Elements[0].nestedRels[i]);
		document.getElementById('waitingRoom').appendChild(Elements.shift())
	}
}

function intoMainForm(name)
{
	if (name == 'none') return;
	var Elements = gatherElements(name);
	if (!isInWaitingRoom(Elements[0])) return;
	var insertPoint = document.getElementById(name);
	while (Elements.length)
		insertPoint.parentNode.insertBefore(Elements.shift(),insertPoint)
}

function isInWaitingRoom(obj)
{
	while(obj.nodeName != 'BODY')
	{
		obj=obj.parentNode;
		if (obj.id == 'waitingRoom')
			return true;
	}
	return false;
}


function getAllFormFields(node)
{
	var allFormFields = new Array;
	var x = node.getElementsByTagName('input');
	for (var i=0;i<x.length;i++)
		allFormFields.push(x[i]);
	var y = node.getElementsByTagName('option');
	for (var i=0;i<y.length;i++)
		allFormFields.push(y[i]);
	return allFormFields;
}

// push and shift for IE5

function Array_push() {
	var A_p = 0
	for (A_p = 0; A_p < arguments.length; A_p++) {
		this[this.length] = arguments[A_p]
	}
	return this.length
}

if (typeof Array.prototype.push == "undefined") {
	Array.prototype.push = Array_push
}

function Array_shift() {
	var A_s = 0
	var response = this[0]
	for (A_s = 0; A_s < this.length-1; A_s++) {
		this[A_s] = this[A_s + 1]
	}
	this.length--
	return response
}

if (typeof Array.prototype.shift == "undefined") {
	Array.prototype.shift = Array_shift
}

function VoteChecker(frm){
	var radio_choice,counter;
	if(frm.name=='frmRightVote'){
			for (counter = 0; counter < document.getElementById("frmRightVote").radio1.length; counter++){
				if (document.getElementById("frmRightVote").radio1[counter].checked)
				radio_choice = true; 
			}
			if (!radio_choice){
				alert("Please select the answer to poll.");
				return false;
			}else{
				document.getElementById("frmRightVote").submit();
				return true;
			}
	}else{
			for (counter = 0; counter < document.getElementById("frmVote").radio1.length; counter++){
				if (document.getElementById("frmVote").radio1[counter].checked)
				radio_choice = true; 
			}
			if (!radio_choice){
				alert("Please select the answer to poll.");
				return false;
			}else{
				document.getElementById("frmVote").submit();
				return true;
			}
	}
}



	var ship_name = "";
	var ship_street = "";
	var ship_street_2 = "";
	var ship_city = "";
	var ship_state = "";
	var ship_postcode = "";

function InitSaveVariables(form) {
	ship_name = form.ship_name.value;
	ship_street =  form.ship_street.value;
	ship_street_2 =  form.ship_street_2.value;
	ship_city =  form.ship_city.value;
	ship_state =  form.ship_state.value;
	ship_postcode =  form.ship_postcode.value;
}

function ShipToBillPerson(form) {
	if (form.copy.checked) {
	InitSaveVariables(form);
	form.ship_name.value = form.first_name.value + ' ' + form.last_name.value;
	form.ship_street.value = form.street.value;
	form.ship_street_2.value = form.address_line2.value;
	form.ship_city.value = form.city.value;
	form.ship_state.value = form.state.value;
	form.ship_postcode.value = form.postcode.value;
	} else {
	form.ship_name.value = ship_name;
	form.ship_street.value = ship_street;
	form.ship_street_2.value = ship_street_2;
	form.ship_city.value = ship_city ;
	form.ship_state.value = ship_state;
	form.ship_postcode.value = ship_postcode;
	}
}

<!--Branch switcher module on home page-->
function changeBranch(id,shtml) {
   if (document.getElementById || document.all) {
      var el = document.getElementById? document.getElementById(id): document.all[id];
      if (el && typeof el.innerHTML != "undefined") el.innerHTML = shtml;
   }
}
var branch_whitefish = '<img src="images/switcher_whitefish_photo.jpg" alt="Mountain West Bank, N.A., Whitefish MT" />\n<h1>Mountain West Bank, N.A.</h1>\n<div>601 Spokane Avenue<br />Whitefish, MT 59937-1510</div>\n<div>Phone: (406) 863-2265</div>';
var branch_kalispell = '<img src="images/switcher_kalispell_photo.jpg" alt="Mountain West Bank of Kalispell, N.A." />\n<h1>Mountain West Bank of<br />Kalispell, N.A.</h1>\n<div>444 West Idaho Street<br />Kalispell, MT 59904</div>\n<div>Phone: (406) 752-2265</div>';
var branch_greatfalls = '<img src="images/switcher_greatfalls_photo.jpg" alt="Mountain West Bank, N.A., Great Falls MT" />\n<h1>Mountain West Bank, N.A.</h1>\n<div>12 3rd Street N.W.<br />Great Falls, MT 59403-3607</div>\n<div>Phone: (406) 727-2265</div>';
var branch_missoula = '<img src="images/switcher_missoula_photo.jpg" alt="Mountain West Bank, N.A., Missoula MT" />\n<h1>Mountain West Bank, N.A.</h1>\n<div>1821 South Avenue West<br />Missoula, MT 59806-5990</div>\n<div>Phone: (406) 542-6222</div>';
var branch_helena = '<img src="images/switcher_helena_photo.jpg" alt="Mountain West Bank, N.A., Helena MT" />\n<h1>Mountain West Bank, N.A.</h1>\n<div>1225 Cedar St.<br />Helena, MT 59604-6013</div>\n<div>Phone: (406) 449-2265</div>';
var branch_bozeman = '<img src="images/switcher_bozeman_photo.jpg" alt="Mountain West Bank, N.A., Bozeman MT" />\n<h1>Mountain West Bank, N.A.</h1>\n<div>1960 North 19th Ave.<br />Bozeman, MT 59718-0850</div>\n<div>Phone: (406) 587-5600</div>';
<!--EOF Branch switcher module-->

