function loadParentFrame(url) {parent.location.href = url;}

function go(url) {opener.location.href = url;}

function close_window() {window.close();}

function changeDays(numb,pMonth,pDay,pYear) {
	mth = pMonth.selectedIndex;
	sel = pYear.selectedIndex;
	yr  = pYear.options[sel].text;
	if (numb != 1) {
		numDays = numDaysIn(mth,yr);
		pDay.options.length = numDays;
		for (i=27;i<numDays;i++) {
			pDay.options[i].text = i+1;
		}
	}
	pDay = pDay.selectedIndex+1;
}
function numDaysIn(mth,yr) {
	if (mth==3 || mth==5 || mth==8 || mth==10) return 30;
	else if ((mth==1) && leapYear(yr)) return 29;
	else if (mth==1) return 28;
	else return 31;
}
function leapYear(yr) {
	if (((yr % 4 == 0) && yr % 100 != 0) || yr % 400 == 0)
		return true;
	else
		return false;
}

function goMenu(pMenu) {
	var sMenu = pMenu.options[pMenu.selectedIndex].value;
	if (sMenu.indexOf('openWin') == -1) {
		parent.location.href=sMenu;
	} else {
		eval(sMenu);
	}
}

//--Used for checking radio buttons and checkboxes when user clicks elsewhere
function checkIt(pField) {
	if ( pField.checked == false ) {
		pField.checked = true
	} else if ( pField.type == 'checkbox' ) {
		pField.checked = false; }
}

/*Used for putting focus on next input box when user completes current input box
--Adapted from http://developer.irt.org/script/335.htm
*/
function KeyPress(what,e,max,pField) {
    if (document.layers) {
        if (e.target.value.length >= max)
            eval(pField+'.focus(); '+pField+'.select();');
    }
    else if (document.all) {
        if (what.value.length > (max-1))
            eval(pField+'.focus(); '+pField+'.select();');
    }
}

function openWin(theURL,winName,features) {
aWindow = window.open(theURL,winName,features);
}

function openRemote(theURL,winName,features) {
remote = window.open(theURL,winName,features);
if (remote.opener == null) remote.opener = window;
}

function goToInsureDiscl(insDiscURL, toURL){
	// Define the insurance disclosure popup window 
	remote = window.open("","ins_discl","toolbar=no,scrollbars=no,dependent=yes,alwaysRaised=yes,resizable=yes,width=300,height=475");
	// URL for insurance disclosure popup page.
	//var urlStr = insDiscURL + '&fpURL=' + fromURL + '&tpURL=' + toURL + (pCategory == "" ?"" : '&category=' + pCategory);
	var urlStr = insDiscURL + '&tpURL=' + toURL;
	remote.location.href = urlStr;
	if (remote.opener == null) remote.opener = window; 
		remote.opener.name = "opener";
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function addCommas(pNum) {
	if (null==pNum || pNum=="") return "";
	if (pNum==0 || pNum=='0') return "0";
	var sNum = "" + pNum;
	var commaChar = /\,/g;
	sNum = sNum.replace(commaChar, "");		//wipe out any comma
	var minusSign = '';
	var newNum = '';
	
	if (sNum.substring(0,1)=='-') {
		minusSign = '-';
		sNum = sNum.substring(1);
	}
	var length = sNum.length;
	var decimalPoint = sNum.indexOf('.');
	if (decimalPoint > 0) {
		newNum += sNum.substring(decimalPoint,length);
		length = decimalPoint;
	}
	
	while(true)
	{
		if (length-3 > 0) {
			newNum = ',' + sNum.substring(length-3,length) + newNum;
			length = length-3;
		} 
		else {
			newNum = sNum.substring(0,length) + newNum;
			break;
		}
	}
	return (minusSign + newNum);
}


//Adds a dollar sign after the negative for withdrawals, or immediately before deposits.
function dollarSign(pAmount) {
	if (pAmount.substring(0,1)=='-') {
		pAmount = '-$' + pAmount.substr(1);
	} else {
		pAmount = '$' + pAmount;
	}
	return (pAmount);
}


/*Functions below (setCookie, getCookie, deleteCookie, fixDate) taken from 	
	http://www.webreference.com/js/column8/functions.html 
Documentation at: 
	http://www.webreference.com/js/column8/http.html
*/
// name - name of the cookie
// value - value of the cookie
// [expires] - expiration date of the cookie (defaults to end of current session)
// [path] - path for which the cookie is valid (defaults to path of calling document)
// [domain] - domain for which the cookie is valid (defaults to domain of calling document)
// [secure] - Boolean value indicating if the cookie transmission requires a secure transmission
// * an argument defaults when it is assigned null as a placeholder
// * a null placeholder is not required for trailing omitted arguments
function setCookie(name, value, path, expires, domain, secure) {
  deleteCookie(name,path);
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

// name - name of the desired cookie
// * return string containing value of specified cookie or null if cookie does not exist
function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

// name - name of the cookie
// [path] - path of the cookie (must be same as path used to create cookie)
// [domain] - domain of the cookie (must be same as domain used to create cookie)
// * path and domain default if assigned null or omitted if no explicit argument proceeds
function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" + 
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

// date - any instance of the Date object
// * hand all instances of the Date object to this function for "repairs"
function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}

function sameWin(theURL) {
	parent.location.href = theURL;
}

function twoDecimalPlaces(pNum) {
	var s = "" + pNum;
	var dot = s.indexOf(".");
	if (dot==-1) s += ".00";
	else {
		var ln = s.length;
		if (dot+1 == ln) s+= "00";
		else if (dot+2 == ln) s+= "0";
	}
	dot = s.indexOf(".");
	s = s.substring(0,dot+3);
	return s;
}

/*Source: http://www.sitepoint.com/article/structural-markup-javascript
Description: If you want multiple scripts to execute when a page loads 
the last script to register itself with window.onload will be the only script to execute.
This function attaches our function (fn) to the onload handler of the window 
object without overwriting what's already there.*/
function addEvent(obj, evType, fn){ 
 if (obj.addEventListener){ 
   obj.addEventListener(evType, fn, true); 
   return true; 
 } else if (obj.attachEvent){ 
   var r = obj.attachEvent("on"+evType, fn); 
   return r; 
 } else { 
   return false; 
 } 
}

/*
The following functions (MM_findObj(n, d), MM_preloadImages(), 
MM_swapImgRestore()and MM_swapImage()) are being copied from master.js.
If these functions get changed in one of the file, other one also needs to
be synched up
*/

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_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_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_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];}
}

