/*Summit Ridge Credit Union*/

//INITIALIZE PAGE

function init()
{
	matchHeight('content','right','right','y',20);
	imgRot();
}

//NAVIGATION
function swapimg(el)
{
	var isHover = false;
	var tmpImg = el.childNodes[0].src;
	var hoverCheck = tmpImg.substr(tmpImg.lastIndexOf(".") - 2, 2);
	if(hoverCheck == "_h")
	{
		isHover = true;
	}
	var filext = tmpImg.substring(tmpImg.lastIndexOf("."));
	var curImg = tmpImg.substr(0,tmpImg.lastIndexOf("."));
	var newImg;
	if(isHover)
	{
		newImg = curImg.substr(0, curImg.lastIndexOf("_h")) + filext;
	} else {
		newImg = curImg + "_h" + filext;
	}
	el.childNodes[0].src = newImg;
}

//global toggleShow
var ts_id, dto;
if(navigator.appName == "Microsoft Internet Explorer")
{
	var bie7 = navigator.appVersion.substring(22,23);
}
if(bie7 == 7)
{
	var ie7 = true;
}

function toggleShow(el)
{
	if (dto) {
		stopTimer();
		hideAll();
	}
	var d = document.getElementById(el);
	if(d.style.display != "block")
	{
		if(ie7)
		{ 
			d.style.display = "none";
		} else {
			d.style.display = "block";
		}
		ts_id = d;
		startTimer();
	} else {
		startTimer();
	}
}

function startTimer()
{
	dto = setTimeout(toggleHide, 2000);
}

function stopTimer()
{
	clearTimeout(dto);
}

function toggleHide()
{
	ts_id.style.display = "none";
}

function hideAll()
{
	var menus = new Array('prodserv','loans','about');
	for(var i=0; i < menus.length; i++)
	{
		var mn = document.getElementById(menus[i]);
		mn.style.display = "none";
	}
}


//VALIDATIONS
function valLogin() 
{
 var pass=true;
 var msg='';
 for (var h = 0; h < document.forms[0].length; h++)
 {
  if ((document.forms[0].elements[h].name == 'ACCT' ) || (document.forms[0].elements[h].name == 'PSWD' )) 
  {
   if (document.forms[0].elements[h].value == '' ) 
   {
    pass=false;
   }
  }
 }
 if (!pass) 
 {
  alert("Both Account# and Password are required fields.\n" +
  "Fill in both fields before attempting to login." );
 }
 return pass;
}

//GET WINDOW SIZE
function winSize()
{
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' )
	{
	//Non-IE
	myWidth = window.innerWidth;
	myHeight = window.innerHeight;
	} else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
	{
	//IE 6+ in 'standards compliant mode'
	myWidth = document.documentElement.clientWidth;
	myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	//IE 4 compatible
	myWidth = document.body.clientWidth;
	myHeight = document.body.clientHeight;
	}
	var sizeArray = new Array(myWidth,myHeight);
	return(sizeArray);
}

//USE ONLOAD IN BODY TO MATCH HEIGHT TO TWO OR THREE DIVS
function matchHeight(div1, div2, div3, toScreen, sub){
	var sizeArray = new Array();
	sizeArray = winSize();

	var d1 = document.getElementById(div1);
	var d2 = document.getElementById(div2);
	var d3 = document.getElementById(div3);
	
	//check scrollHeight to see if extends beyond initial window
	var d1SH = d1.scrollHeight;
	var d2SH = d2.scrollHeight;
	var d3SH = d3.scrollHeight;
	var maxSH = sizeArray[1];
	if(maxSH < d1SH)
	{
		maxSH = d1SH;
	}
	if(maxSH < d2SH)
	{
		maxSH = d2SH;
	}
	if(maxSH < d3SH)
	{
		maxSH = d3SH;
	}

	if (toScreen == "y") {
		d1.style.height = (maxSH - sub) + "px";
		d2.style.height = (maxSH - sub) + "px";
		if (d2.offsetHeight > d1.offsetHeight) {
			d2.style.height = (maxSH -sub) + "px";
			d1.style.height = d2.offsetHeight + "px";
			d3.style.height = d2.offsetHeight + "px";
		}
		else {
			d1.style.height = (maxSH - sub) + "px";
			d2.style.height = d1.offsetHeight + "px";
			d3.style.height = d1.offsetHeight + "px";
		}
	} else {
			if (d2.offsetHeight > d1.offsetHeight) {
			d1.style.height = d2.offsetHeight + "px";
			d3.style.height = d2.offsetHeight + "px";
		}
		else {
			d2.style.height = d1.offsetHeight + "px";
			d3.style.height = d1.offsetHeight + "px";
		}
	}
}

function imgRot() {
	var images = new Array("images/rotating/img01.jpg","images/rotating/img02.jpg","images/rotating/img03.jpg","images/rotating/img04.jpg","images/rotating/img05.jpg","images/rotating/img06.jpg","images/rotating/img07.jpg","images/rotating/img08.jpg","images/rotating/img09.jpg","images/rotating/img10.jpg","images/rotating/img11.jpg");
	var imgid = document.getElementById("ib");
	var rand = Math.round(Math.random() * (images.length - 1));
	imgid.src = images[rand];
}

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 valCalc(frm) {
	var re = /^\d+\.?\d*$/     //matches digits with optional decimal
	var retval = true;
	
	//clear errors
	var errorArray = new Array();
	ere = /[err]/
	errorArray = document.getElementsByTagName('span');
	alert(errorArray.length);
	for(var a = 0; a < errorArray.length; a++)
	{
		if(errorArray[a].id)
		{
			alert(errorArray[a].id);
			if(ere.test(errorArray[a].id))
			{
				var tmpremove = document.getElementById(errorArray[a].id);
				alert(tmpremove);
				var tmpremparent = tmpremove.parentNode;
				alert(tmpremparent);
				tmpremparent.removeChild(tmpremove);
			}
		}
		errorArray2 = document.getElementsByTagName('span');
		alert(errorArray2.length);
	}
	
	for(var n = 0; n < frm.elements.length; n++)
	{
		if(typeof(frm.elements[n]) != "undefined")
		{
			if(frm.elements[n].tagName == "INPUT")
			{
				if(frm.elements[n].id != "") 
				{
					if(!re.test(frm.elements[n].value))
					{
						var tmpNode = document.createElement('span');
						tmpNode.setAttribute('class','red');
						var erratt = "error" + n;
						tmpNode.setAttribute('id',erratt);
						frm.elements[n].parentNode.appendChild(tmpNode);
						document.getElementById(erratt).innerHTML = "Input must be numeric. Decimal point is optional.";
						retval = false;
					}
				}
			}
		}
	}
	return retval;
}

//Generate <option>Lists</option>

function optionMonths()
{
	var optList = "<option value=\"1\">Jan</option>";
	optList += "<option value=\"2\">Feb</option>";
	optList += "<option value=\"3\">Mar</option>";
	optList += "<option value=\"4\">Apr</option>";
	optList += "<option value=\"5\">May</option>";
	optList += "<option value=\"6\">Jun</option>";
	optList += "<option value=\"7\">Jul</option>";
	optList += "<option value=\"8\">Aug</option>";
	optList += "<option value=\"9\">Sep</option>";
	optList += "<option value=\"10\">Oct</option>";
	optList += "<option value=\"11\">Nov</option>";
	optList += "<option value=\"12\">Dec</option>";
	document.write(optList);
}

function optionYears(num)
{
	var today = new Date();
	var curYear = today.getFullYear();
	var endYear = curYear + num;
	var optList;
	for (var i = curYear; i <= endYear; i ++)
	{
		optList += "<option value=\"" + i + "\">" + i + "</option>";
	}
	document.write(optList);
}


