var digits = "0123456789";
var lowercaseLetters = "abcdefghijklmnopqrstuvwxyz"
var uppercaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
var blanks = " \t\n\r";  // aka whitespace chars
// decimal point character differs by language and culture
var decimalPointDelimiter = "."
// non-digit characters allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters allowed in US phone numbers
var validUSPhoneChars = digits + phoneNumberDelimiters;
// U.S. phone numbers have 10 digits, formatted as ### ### #### or (###)###-####
var digitsInUSPhoneNumber = 10;
// non-digit characters which are allowed in ZIP Codes
var ZIPCodeDelimiters = "-";
// our preferred delimiter for reformatting ZIP Codes
var ZIPCodeDelimeter = "-"
// U.S. ZIP codes have 5 or 9 digits, formatted as ##### or #####-####
var digitsInZIPCode1 = 5
var digitsInZIPCode2 = 9
// Valid U.S. Postal Codes for states, territories, armed forces, etc.
// See http://www.usps.gov/ncsc/lookups/abbr_state.txt
var USStateCodeDelimiter = "|";
var USStateCodes = "AL|AK|AS|AZ|AR|CA|CO|CT|DE|DC|FM|FL|GA|GU|HI|ID|IL|IN|IA|KS|KY|LA|ME|MH|MD|MA|MI|MN|MS|MO|MT|NE|NV|NH|NJ|NM|NY|NC|ND|MP|OH|OK|OR|PW|PA|PR|RI|SC|SD|TN|TX|UT|VT|VI|VA|WA|WV|WI|WY|AE|AA|AE|AE|AP|al|ak|as|az|ar|ca|co|ct|de|dc|fm|fl|ga|gu|hi|id|il|in|ia|ks|ky|la|me|mh|md|ma|mi|mn|ms|mo|mt|ne|nv|nh|nj|nm|ny|nc|nd|mp|oh|ok|or|pw|pa|pr|ri|sc|sd|tn|tx|ut|vt|vi|va|wa|wv|wi|wy|ae|aa|ae|ae|ap"
var strErrorMessage = new String(); 
var FrameBody, FrameSearch, objErrorField;

function OnPageLoad(){
	if(null!=document.frames.ICFRSBody)
		FrameBody=document.frames.ICFRSBody.document;
	if(null !=document.frames.IQuickSearch)
		FrameSearch=document.frames.IQuickSearch.document;
	return;
}
function FormatPhone(objField){
	if(null!=objField && objField.value.length>0){
		objField.value=stripCharsNotInBag(objField.value,digits);
		var strPhone=new String(objField.value);
		if(strPhone.length==10){
			objField.value=reformat (strPhone, "(", 3, ") ", 3, "-", 4);
		}else{
			objField.value=""
			var strErrorMessage="<strong>Phone Number Formatter<HR></strong>";
			strErrorMessage+="Please supply 10 digits for phone number including area code.";
			PopWinClient(strErrorMessage, "Validation Error", "MenuTable", 10000);
		}
	}
	return;
}
function FormatZip(objField){
	if(null!=objField && objField.value.length>0){
		var strZipCode=new String(stripCharsNotInBag(objField.value, digits));
		if(strZipCode.length==9){strZipCode=reformat (strZipCode, "", 5, "-", 4);}
		else{strZipCode=strZipCode.substring(0,5);}
		if(strZipCode.length<5){	
			objField.value="";
			var strErrorMessage="<strong>Zip Code Formatter<HR></strong>";
			strErrorMessage+="Please supply at least 5 and no more than 9 digits for zip code.";
			PopWinClient(strErrorMessage, "Validation Error", "MenuTable", 10000);
		}else{
			objField.value=strZipCode;
		}
	}
	return;
}
function BlurLastField(){
	if(typeof(document.frames.ICFRSBody.document.getElementById("CFRSToolBar1_tbimgSave")) != "undefined" && 
				null != document.frames.ICFRSBody.document.getElementById("CFRSToolBar1_tbimgSave")){
		if(document.frames.ICFRSBody.document.getElementById("CFRSToolBar1_tbimgSave").disabled){
			if(document.frames.ICFRSBody.document.getElementById("CFRSToolBar1_tbimgEdit").disabled && 
					(null==document.frames.ICFRSBody.document.getElementById("tblLoans") || document.frames.ICFRSBody.document.getElementById("tblLoans")=="undefined"))
			{
				if(document.frames.ICFRSBody.document.getElementById("CFRSToolBar1_tbimgNew").disabled)
					document.frames.ICFRSBody.document.getElementById("tblCommands").focus();
				else
					document.frames.ICFRSBody.document.getElementById("CFRSToolBar1_tbimgNew").focus();
			}else{
				if(null!=document.frames.ICFRSBody.document.getElementById("tblLoans") && document.frames.ICFRSBody.document.getElementById("tblLoans")!="undefined")
					document.frames.ICFRSBody.document.getElementById("tblLoans").focus();
				else
					document.frames.ICFRSBody.document.getElementById("CFRSToolBar1_tbimgEdit").focus();}
		}else{
				document.frames.ICFRSBody.document.getElementById("CFRSToolBar1_tbimgSave").focus();
		}
	}
	return;
}
function reformat (strChange)
{
   var arg;
   var sPos = 0;
   var resultString = "";
   for (var i = 1; i < reformat.arguments.length; i++) {
     arg = reformat.arguments[i];
     if (i % 2 == 1) resultString += arg;
     else {
       resultString += strChange.substring(sPos, sPos + arg);
       sPos += arg;
     }
  }
  return resultString;
}

function HideShowCalendar(){
	var objCal=document.getElementById("Calendar1");
	var objImg=document.getElementById("imgShowHide");
	if(objCal.style.visibility=="hidden"){
		objCal.style.visibility="visible";
		objImg.style.borderColor="Lime";
		objImg.style.borderStyle="dotted";
	}else{
		objCal.style.visibility="hidden";
		objImg.style.borderColor="beige";
		objImg.style.borderStyle="ridge";
	}
}

/*function InitHideMessage(){
	//document.getElementById("txtImport").style.visibility="hidden";
	strMsg=new String(document.getElementById("lblMessage").innerText);
	if(strMsg.length<=0){document.getElementById("MessageDetails").style.visibility="hidden";}
	else{document.getElementById("MessageDetails").style.visibility="visible";}
	return false;
}
function HideMessage(){
	document.getElementById("MessageDetails").style.visibility="hidden";
	return false;
}
function HideSearchResults(){
	document.getElementById("SearchResults").style.visibility="hidden";
	return false;
}
function ShowSearch(){
	if(document.getElementById("Search").style.visibility=="visible"){
		document.getElementById("Search").style.visibility="hidden";
	}else{
		document.getElementById("Search").style.visibility="visible";
		var objSearchName=document.getElementById("inpFindFirstName");
		if(objSearchName!=undefined){
			objSearchName.focus();
		}
	}
	if(document.getElementById("SearchResults")!=null){
		document.getElementById("SearchResults").style.visibility="hidden";
	}
	return false;
}*/
/*Sets object read only display access state, background and text color, and clears the text.*/
function InitAdd(objField, boolCorrectAdd){
	if(null!=objField){
		if(!boolCorrectAdd){objField.value="";}
		InitEdit(objField);
	}
	return;
}
//Initializes integer field to 0
function InitAddInt(objField, boolCorrectAdd){
	if(null!=objField){
		if(!boolCorrectAdd){objField.value=0;}
		InitEdit(objField);
		objField.disabled=false;
	}
	return;
}

function InitAddSelect(objField, boolCorrectAdd){
	if(null!=objField){
		if(!boolCorrectAdd){objField.selectedIndex=0;}
		InitEditSelect(objField);
	}
	return;
}
function InitEditSelect(objField){
	if(null!=objField){
		objField.disabled=false;
		InitEdit(objField);
	}
	return;
}
/*Sets object read only display access state, background and text color*/
function InitEdit(objField){
	if(null!=objField){
		objField.readOnly=false;
		FldBackGround(objField,'white');
		FldText(objField,'maroon');
	}
	return;
}
function SetFocusOn(objField){
	objField.className='fldHvr';
	objField.select();
	return;
}
function SetFocusOff(){
	className='inpFld';
	return;
}
/*Sets object read only display access state, background and text color*/
function InitShowSelect(objField){
	if(null!=objField){
		objField.disabled=true;
	}
return;
}
function InitShow(objField){
	if(null!=objField){
		objField.readOnly=true;
		FldBackGround(objField,'ghostwhite');
		FldText(objField,'midnightblue');
	}
	return;
}
/*Sets object background color*/
function FldBackGround(objField, Color){
	objField.style.background=Color;
	return;
}
/*Sets object text color*/
function FldText(objField, Color){
	objField.style.color=Color;
	return;
}
/* ReadyCheckList accepts the name of a collection + the asp.net appended '_', 
 * the zero based size of the collection, and a boolean true/false indicating control state.
 * The collection is enumerated and either enabled or disabled. ASP.NET
*/
function ReadyCheckList(strFldName, intSizeCollection, boolDisabled){
	for(ln=0;ln<=intSizeCollection;++ln){
		{	
			strItem=strFldName+ln
			if(null!=document.frames.ICFRSBody.document.getElementById(strItem)){
				document.frames.ICFRSBody.document.getElementById(strItem).disabled=boolDisabled;
			}
		}
  }
	return;
}
//Returns bool. Function will search a combo list object for a matching row value and key.  ASP.NET/DHTML
function  FindRowSelect(objSelect, strValue, strKey){
	var boolRowFound=false;
	for(n=0;n<objSelect.length;n++){
		//alert(objCommAcnts(n).text);
		if(objSelect(n).value==strKey&&objSelect(n).text==strValue)
		{
			boolRowFound=true;
		}
	}
	return boolRowFound;
}
function  SetRowSelect(objSelect, strKey){
	var boolRowFound=0;
	for(n=0;n<objSelect.length;n++){
		//alert(objCommAcnts(n).text);
		if(objSelect(n).value==strKey)
		{
			boolRowFound=n;
			objSelect.selectedIndex=n;
		}
	}
	return boolRowFound;
}
//Returns void. Function add the value and key row option to combo list object. ASP.NET/DHTML
function AddSelectRow(objSelect, strValue, strKey){
	var strOption ="('"+strValue+"','"+strKey+"')";	//"('I - Intersession','I')"
	var intAddAt=objSelect.length;
  eval("objSelect.options[intAddAt]=" + "new Option" + strOption);
	return;
}

//Returns void. Function deletes the selected row option of a combo list object. ASP.NET/DHTML
function DelSelectRow(objSelect){
	if(objSelect.length>0){objSelect.options[(objSelect.selectedIndex)] = null;}
	return;
}

function ShowUserInfo(strServerPath){
	showModalDialog(strServerPath+'/cf_utility/HostMyAccount.aspx','','dialogWidth:550px;dialogHeight:485px;help:no;edge:raised;status:yes;unadorned:yes');
	return;
}
function AboutCFRS(strServerPath){
	popWinCN_ShowDialog(strServerPath+"/cf_utility/AboutCFRS.aspx", "420", "250");
	return;
}
function ShowSwitch(strServerPath){
	showModalDialog(strServerPath+'/cf_utility/HostSwitchCommittee.aspx','','dialogWidth:655px;dialogHeight:450px;center:1;help:no;edge:raised;status:yes;unadorned:yes');
	location.replace(strServerPath+"/default.aspx");
	return;
}
function PopWinClient(strMessage, strTitle, strShowBy, intHideAfter, intWinHeight, intWinWidth, intMsgWinHeight){	//Use this function for init of client side pop up messages.
	boolPopChange=true;	//Force content/title change. 
	popWinCN_Close();
	if(intWinHeight==undefined||intWinWidth==undefined||intMsgWinHeight==undefined){
		document.getElementById('popWin').style.height="100px";
		document.getElementById('popWin').style.width="250px";
		document.getElementById('popWin_content').style.height="76px";
	}else{
		document.getElementById('popWin').style.height=intWinHeight+"px";
		document.getElementById('popWin').style.width=intWinWidth+"px";
		document.getElementById('popWin_content').style.height=intMsgWinHeight+"px";
	}
	if(strShowBy==undefined){
		strShowBy="MenuTable";
	}
	if(strTitle==undefined){
		strTitle="CFRS Message";
	}else{txtPopTitle=strTitle;}

	if(strMessage==undefined){
		strMessage="No message supplied.";
	}else{txtPopMessage=strMessage;}

	if(intHideAfter==undefined){
		intHideAfter=2000;
	}else{popWinhideAfter=intHideAfter;}
	popWinCN_winLoad();popWinCN_ShowPopup(document.getElementById(strShowBy));
	return;
}
function replInStr(stringValue,stringReplace,stringWith){
  var i;
  var returnString = "";
  // Search through string's characters one by one;
  // if character is not in bag, append to returnString
  for (i = 0; i < stringValue.length; i++){   
    var c = stringValue.charAt(i);
    if (stringReplace.indexOf(c) == -1){returnString += c}
    else{returnString+=stringWith}
  }
  return returnString;
  }
// Removes all characters which appear in string bag from string
function stripCharsInBag (stringValue, bag){
  var i;
  var returnString = "";
  // Search through string's characters one by one;
  // if character is not in bag, append to returnString
  for (i = 0; i < stringValue.length; i++){   
    // Check that current character isn't blank
    var c = stringValue.charAt(i);
    if (bag.indexOf(c) == -1) 
      returnString += c;
    }
  return returnString;
 }
// Removes all characters which do NOT appear in string bag from string
function stripCharsNotInBag (stringValue, bag)
{
  var i;
  var returnString = "";

  // Search through string'stringValue characters one by one;
  // if character is in bag, append to returnString
  for (i = 0; i < stringValue.length; i++)
    {   
    // Check that current character isn't blank
    var c = stringValue.charAt(i);
    if (bag.indexOf(c) != -1) 
      returnString += c;
    }
  return returnString;
}
// Removes all blank chars (as defined by blanks) from s
function stripBlanks(stringValue){
  return stripCharsInBag(stringValue, blanks)
}
// Removes leading blank chars (as defined by blanks) from s
function stripLeadingBlanks(stringValue)
{ 
  var i = 0;
  while ((i < stringValue.length) && (blanks.indexOf(stringValue.charAt(i)) != -1))
     i++;
  return stringValue.substring(i, stringValue.length);
}
// Removes trailing blank chars (as defined by blanks) from s
function stripTrailingBlanks(stringValue)
{ 
  var i = stringValue.length - 1;
  while ((i >= 0) && (blanks.indexOf(stringValue.charAt(i)) != -1))
     i--;
  return stringValue.substring(0, i+1);
}
// Removes leading+trailing blank chars (as defined by blanks) from s
function stripLeadingTrailingBlanks(stringValue)
{ 
  stringValue = stripLeadingBlanks(stringValue);
  stringValue = stripTrailingBlanks(stringValue);
  return stringValue;
}

// Returns true if string is an English letter (A .. Z, a..z)
function isLetter(letter)
{
  return (((letter >= "a") && (letter <= "z")) || ((letter >= "A") && (letter <= "Z")));
}
// Returns true if string is a digit (0 .. 9)
function isDigit(digit)
{
  return ((digit >= "0") && (digit <= "9"));
}

// Returns true if all chars in string are numbers;
// first character is allowed to be + or -; does not 
// accept floating point, exponential notation, etc.

function isInteger(intNumber)
{
  if (isBlank(intNumber))
    return false;

  // skip leading + or -
  if ((intNumber.charAt(0) == "-") || (intNumber.charAt(0) == "+"))
    var i = 1;
  else
    var i = 0;

  // Search through string'intNumber chars one by one until we find a 
  // non-numeric char, then return false; if we don't, return true
  for (i; i<intNumber.length; i++)
    {   
    // Check that current character is number
    var c = intNumber.charAt(i);
    if (!isDigit(c)) 
      return false;
    }
  // All characters are numbers
  return true;
}
// True if string is an unsigned floating point (real) number; 
// first character is allowed to be + or -; no exponential notation.

function isFloat(floatNumber)
{ 
	var seenDecimalPoint = false;

	if (isBlank(floatNumber)) 
		return false;
	if (floatNumber == decimalPointDelimiter) 
		return false;

	// skip leading + or -
	if ((floatNumber.charAt(0) == "-") || (floatNumber.charAt(0) == "+"))
		var i = 1;
	else
		var i = 0;

	// Search through string'floatNumber chars one by one until we find a 
	// non-numeric char, then return false; if we don't, return true

	for (i; i<floatNumber.length; i++)
		{   
		// Check that current character is number
		var c = floatNumber.charAt(i);

		if ((c == decimalPointDelimiter) && !seenDecimalPoint) 
			seenDecimalPoint = true;
		else if (!isDigit(c)) 
			return false;
		}
	// All characters are numbers
	return seenDecimalPoint;
}
// Returns true if s is valid 2-letter U.S. state abbreviation
function ValidateState(objState){
	if(!isStateCode(objState.value)||objState.value.length<2){objState.value="";}
	return isStateCode(objState.value);
}
function VerifyMoney(objField){
	//strips all characters besides digits and decimal.
	//Calls isFloat() to verify real number and only one decimal
	//returns 0 if failed
	var intReturn=0;
	objField.value=stripCharsNotInBag(objField.value,"."+digits);
	if(isFloat(objField.value)){
		intReturn=objField.value;
	}
	return intReturn;
}
function isStateCode(State)
{ 
  if (isBlank(State)) 
    return false;
  return ((USStateCodes.indexOf(State) != -1) &&
          (State.indexOf(USStateCodeDelimiter) == -1))
}
function isEmpty(stringValue){
  return ((stringValue == null) || (stringValue.length == 0));
}
// Returns true if string is empty or all blank chars
function isBlank(stringValue)
{
  var i;
  // Is stringValue empty?
  if (isEmpty(stringValue))
    return true;
  // Search through string'stringValue chars one by one until we find first
  // non-blank char, then return false; if we don't, return true
  for (i=0; i<stringValue.length; i++)
  {   
    // Check that current character isn't blank
    var c = stringValue.charAt(i);
    if (blanks.indexOf(c) == -1) 
      return false;
  }
  // All characters are blank
  return true;
}
/**
 * Date validation script.
 */

function checkdate(objName) {
	var objDateField = objName;
	if (chkdate(objName) == false) {
		objDateField.value="";
		//Error message, Error box title, window object to activate near, and error window timeout
		PopWinClient("<strong>Date Field Validation <HR></strong>" +strErrorMessage, "Validation Error", "MenuTable", 10000);
	}
	var strDate=new String(objDateField.value);
	if(strDate.length<1 && objName.id!="inpDateThru" && objName.id!="inpLetterSent"){
		objDateField.value=TodaysDate();
	}
		return false;
}
function chkdate(objName) {
	var objDateField = objName;
	var strDatestyle = "US"; //United States date style
	//var strDatestyle = "EU";  //European date style
	var strDate;
	var strDateArray;
	var strDay;
	var strMonth;
	var strYear="";
	var intday;
	var intMonth;
	var intYear;
	var booFound = false;
	var strSeparatorArray = new Array("-"," ","/",".");
	var intElementNr;
	strErrorMessage = "";
	var strMonthArray = new Array(12);
	
	strMonthArray[0] = "Jan";
	strMonthArray[1] = "Feb";
	strMonthArray[2] = "Mar";
	strMonthArray[3] = "Apr";
	strMonthArray[4] = "May";
	strMonthArray[5] = "Jun";
	strMonthArray[6] = "Jul";
	strMonthArray[7] = "Aug";
	strMonthArray[8] = "Sep";
	strMonthArray[9] = "Oct";
	strMonthArray[10] = "Nov";
	strMonthArray[11] = "Dec";
	strDate = objDateField.value;
	if (strDate.length < 1) {
		return true;
	}
	for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
		if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
			strDateArray = strDate.split(strSeparatorArray[intElementNr]);
			if (strDateArray.length != 3 && strDateArray.length != 2 ) {
				strErrorMessage = 1;
				strErrorMessage = "Not enough values supplied to determine date.";
			}
			else {
				strDay = strDateArray[0];
				strMonth = strDateArray[1];
				if(strDateArray.length!=3){
					var date = new Date();
					strYear = date.getFullYear();
				}else{
					strYear = strDateArray[2];
				}
			}
			booFound = true;
		}
	}
	if (booFound == false) {
		if (strDate.length>3) {
			strDay = strDate.substr(0, 2);
			strMonth = strDate.substr(2, 2);
			if(strDate.length<=4){	//No year
				var date = new Date();
				strYear = date.getFullYear();
			}
			else
				strYear=strDate.substr(4)
    }
	}
	if (strYear.length == 2) {
		var intYear=new Number(strYear)
		if(intYear<80)
			strYear = '20' + strYear;
		else
			strYear = '19' + strYear;
	}
// US style
	if (strDatestyle == "US") {
		strTemp = strDay;
		strDay = strMonth;
		strMonth = strTemp;
	}
	intday = parseInt(strDay, 10);
	if (isNaN(intday)) {
			strErrorMessage = "Plese supply a numerical value for day between 1 and 10.";
		return false;
	}
	intMonth = parseInt(strMonth, 10);
	if (isNaN(intMonth)) {
		for (i = 0;i<12;i++) {
			if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) {
				intMonth = i+1;
				strMonth = strMonthArray[i];
				i = 12;
			}
		}
		if (isNaN(intMonth)) {
			strErrorMessage = "Plese supply a numerical value for the month.";
			return false;
		}
	}
	intYear = parseInt(strYear, 10);
	if (isNaN(intYear)) {
			strErrorMessage = "Plese supply a numerical value for the year.";
		return false;
	}
	if (intMonth>12 || intMonth<1) {
			strErrorMessage = "Plese supply a value between 0 and 12 for the month.";
		return false;
	}
	if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) {
			strErrorMessage = "Plese supply a value between 0 and 31 for the specified month.";
		return false;
	}
	if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) {
			strErrorMessage = "Plese supply a value between 0 and 30 for the specified month.";
		return false;
	}
	if (intMonth == 2) {
		if (intday < 1) {
			strErrorMessage = "Plese supply a value greater than 0 for day of month.";
			return false;
		}
		if (LeapYear(intYear) == true) {
			if (intday > 29) {
				strErrorMessage = "This year February has 29 days.";
				return false;
			}
		}
		else {
			if (intday > 28) {
				strErrorMessage = "This year February has 28 days.";
				return false;
			}
		}
	}
	if (strDatestyle == "US") {
		//objDateField.value = strMonthArray[intMonth-1] + " " + intday+" " + strYear;
		objDateField.value = intMonth + "/" + intday+"/" + strYear;
		if(!DateLTEToday(objDateField.value)){
			objDateField.value="";
			return false;
		}
	}
	else {
		objDateField.value = intday + " " + strMonthArray[intMonth-1] + " " + strYear;
	}
	return true;
}
function LeapYear(intYear) {
	if (intYear % 100 == 0) {
		if (intYear % 400 == 0) { return true; }
	}
	else {
		if ((intYear % 4) == 0) { return true; }
	}
	strErrorMessage="Could not determine leap year from supplied year value.";
	return false;
}
function DateLTEToday(Test) {
	var strToday=TodaysDate();
	if (Date.parse(Test) <= Date.parse(strToday)) {
		return true;
	}
	else {
			strErrorMessage="Date supplied must be less than or equal to today's date.";
			return false;
	}
}
function TodaysDate(){
	var strTodaysDate="";
	var dtToday = new Date();												// Create Date object with today's date.
	strTodaysDate+=(dtToday.getMonth() + 1) + "/";  // Get month
	strTodaysDate+=dtToday.getDate() + "/";         // Get day
	strTodaysDate+=dtToday.getFullYear();           // Get year.
	return strTodaysDate;
}
//Common validation for Contribution type select boxes.
function CheckDupPurpCode(objChecking){
	var boolValid=true, intOnSelect=0;
	var objCheckAgainst=null, objSel1=null, objSel2=null, objSel3=null, objSel4=null;
	if(null!=document.frames["ICFRSBody"]){
		objSel1=document.frames.ICFRSBody.document.getElementById('selInKind1');
		objSel2=document.frames.ICFRSBody.document.getElementById('selInKind2');
		objSel3=document.frames.ICFRSBody.document.getElementById('selInKind3');
		objSel4=document.frames.ICFRSBody.document.getElementById('selInKind4');
	}else{
		objSel1=document.getElementById('selInKind1');
		objSel2=document.getElementById('selInKind2');
		objSel3=document.getElementById('selInKind3');
		objSel4=document.getElementById('selInKind4');
	}
	if(objChecking.selectedIndex>0){
		for(intSel=0;intSel<4;++intSel){
			if(null!=document.frames["ICFRSBody"])
				objCheckAgainst=eval("document.frames.ICFRSBody.document.getElementById('selInKind"+(intSel+1)+"')");
			else
				objCheckAgainst=eval("document.getElementById('selInKind"+(intSel+1)+"')");
			if(IsDuplicateSelect(objChecking, objCheckAgainst)){
				PopWinClient("<strong>Purpose Code Validation <HR></strong>Please select unique purpose codes.", "Validation Error", "MenuTable", 10000);
				boolValid=false;
				break;
			}
		}
		//If this is not the first available purpose code, pop this code into the first available and clear.
		if(boolValid && objChecking.id!="selInKind1"){	
			intOnSelect=new Number(objChecking.id.substr(objChecking.id.length-1, 1));
			if(objSel1.selectedIndex<1 && intOnSelect >1){
				objSel1.selectedIndex=objChecking.selectedIndex;
				objChecking.selectedIndex=0;
			}
			else if(objSel2.selectedIndex<1 && intOnSelect >2){
				objSel2.selectedIndex=objChecking.selectedIndex;
				objChecking.selectedIndex=0;
			}
			else if(objSel3.selectedIndex<1 && intOnSelect >3){
				objSel3.selectedIndex=objChecking.selectedIndex;
				objChecking.selectedIndex=0;
			}
		}
	}
	//If code was duplicated we have an empty element, or an element was set to empty by the client. Re-order list as needed.
	if(objChecking.selectedIndex<1){	
		intOnSelect=new Number(objChecking.id.substr(objChecking.id.length-1, 1));
		window.status=intOnSelect;
		if(intOnSelect==1){
			if(objSel2.selectedIndex>0){
				objChecking.selectedIndex=objSel2.selectedIndex;
				objSel2.selectedIndex=0;
			}
			if(objSel3.selectedIndex>0 && objSel2.selectedIndex<1){
				objSel12.selectedIndex=objSel3.selectedIndex;
				objSel13.selectedIndex=0;
			}
			if(objSel4.selectedIndex>0 && objSel3.selectedIndex<1){
				objSel3.selectedIndex=objSel4.selectedIndex;
				objSel4.selectedIndex=0;
			}
		}
		else if(intOnSelect==2){
			if(objSel3.selectedIndex>0 && objSel2.selectedIndex<1){
				objSel2.selectedIndex=objSel3.selectedIndex;
				objSel3.selectedIndex=0;
			}
			if(objSel4.selectedIndex>0 && objSel3.selectedIndex<1){
				objSel3.selectedIndex=objSel4.selectedIndex;
				objSel4.selectedIndex=0;
			}
		}
		else if(intOnSelect==3){
			if(objSel4.selectedIndex>0 && objSel3.selectedIndex<1){
				objSel3.selectedIndex=objSel4.selectedIndex;
				objSel4.selectedIndex=0;
			}
		}
	}
	return;
}
function IsDuplicateSelect(objChecking, objCheckAgainst){
	//Called by CheckDuplicate
	boolIsDuplicate=false;
	if(null!=objChecking && null!=objCheckAgainst){
		if(objChecking.id!=objCheckAgainst.id){
			if(objChecking.selectedIndex==objCheckAgainst.selectedIndex){
				boolIsDuplicate=true;
				objChecking.selectedIndex=0;
			}
		}
	}
	return boolIsDuplicate;
}
//Check for Purpose Code equal to one of a supplied value. Multiple values can be passed delimited with '|'.
function IsReqPurposeDesc(strTransTypes){
	var boolIsMatch=false,aryTransTypes= null, objCheckAgainst=null;
	if(null==strTransTypes || typeof(strTransTypes)=="undefined")
		strTransTypes="5|14";		//Travel and General Operational
	aryTransTypes= strTransTypes.split("|");
	for(intSel=0;intSel<4;++intSel){
		if(null!=document.frames["ICFRSBody"])
			objCheckAgainst=eval("document.frames.ICFRSBody.document.getElementById('selInKind"+(intSel+1)+"')");
		else
			objCheckAgainst=eval("document.getElementById('selInKind"+(intSel+1)+"')");
		if(null!=objCheckAgainst){
			for(intCheck=0; intCheck<aryTransTypes.length; ++intCheck){
				if(aryTransTypes[intCheck]==objCheckAgainst.value){
					boolIsMatch=true;
					break
				}
			}
			if(boolIsMatch==true)
				break;
		}
	}
	return boolIsMatch;
}
//Accept a single or multiple transaction types delimited by pipe. If selType.value is in list then true is returned.
function IsTransDescRequired(strTransTypes){
	var boolIsMatch=false;
	var aryTransTypes=strTransTypes.split("|");
	var objCheckAgainst=null;
	if(null!=document.frames["ICFRSBody"])
		objCheckAgainst=document.frames.ICFRSBody.document.getElementById('selType');
	else
		objCheckAgainst=document.getElementById('selType');

	if(null!=objCheckAgainst){
		for(intCheck=0; intCheck<aryTransTypes.length; ++intCheck){
			if(aryTransTypes[intCheck]==objCheckAgainst.value){
				boolIsMatch=true;
				break
			}
		}
	}
	return boolIsMatch;
}
//Returns true if objSelect (selected object) is a valid object with the value of strIsValue.
//Object must expose a value property. 
function IsValueThis(objSelect, strIsValue){
	var boolIsValue=false;
	if(null!=objSelect){
		if(objSelect.value==strIsValue){
			boolIsValue=true;
		}
	}
	return boolIsValue;
}
function IsLoanType(objSelect){
	var objCheckAgainst=null, objSel1=null, objSel2=null, objSel3=null, objSel4=null;
	var objDescription=null, objTDPurposeDescription=null, objTDPurposeCodes=null;
	if(null!=document.frames["ICFRSBody"]){
		objSel1=document.frames.ICFRSBody.document.getElementById('selInKind1');
		objSel2=document.frames.ICFRSBody.document.getElementById('selInKind2');
		objSel3=document.frames.ICFRSBody.document.getElementById('selInKind3');
		objSel4=document.frames.ICFRSBody.document.getElementById('selInKind4');
		objDescription=document.frames.ICFRSBody.document.getElementById('txtDescription');
		objTDPurposeDescription=document.frames.ICFRSBody.document.getElementById('tdPurposeDescription');
		objTDPurposeCodes=document.frames.ICFRSBody.document.getElementById('tdPurposeCodes');
	}else{
		objSel1=document.getElementById('selInKind1');
		objSel2=document.getElementById('selInKind2');
		objSel3=document.getElementById('selInKind3');
		objSel4=document.getElementById('selInKind4');
		objDescription=document.getElementById('txtDescription');
		objTDPurposeDescription=document.getElementById('tdPurposeDescription');
		objTDPurposeCodes=document.getElementById('tdPurposeCodes');
	}
	if(objSelect.value=="17"){
		objSel1.selectedIndex=0;
		objSel2.selectedIndex=0;
		objSel3.selectedIndex=0;
		objSel4.selectedIndex=0;
		objSel1.disabled=true;
		objSel2.disabled=true;
		objSel3.disabled=true;
		objSel4.disabled=true;
		objDescription.value="";
		objDescription.disabled=true;
		objTDPurposeDescription.style.display="none";
		objTDPurposeCodes.style.display="none";
	}else{
		InitEditSelect(objSel1);
		InitEditSelect(objSel2);
		InitEditSelect(objSel3);
		InitEditSelect(objSel4);
		InitEdit(objDescription);
		objTDPurposeDescription.style.display="inline";
		objTDPurposeCodes.style.display="inline";
	}
}
function VerifyPurposeCode(){
//returns true if a PurposeCodes or Description is present.
	boolReturn=false;
	var strDescription=new String(document.frames.ICFRSBody.document.getElementById("txtDescription").value);
	
	for(intSel=0;intSel<4;++intSel){
		objCheckAgainst=eval("document.frames.ICFRSBody.document.getElementById('selInKind"+(intSel+1)+"')");
		var objValue=new Number(objCheckAgainst.value);
		if(null!=objCheckAgainst&& stripBlanks(objCheckAgainst.value).length>0 &&objValue.valueOf()>0){
			boolReturn=true;
			break;
		}
	}
	if(!boolReturn){ //Check for a description
		if(null!=strDescription && strDescription.length>1){
			boolReturn=true;
		}
	}
	return boolReturn;
}
//Validate amount field
function valMoney(objCheck){
	objCheck.value=stripCharsNotInBag(objCheck.value, digits+".");
	if(isFloat(objCheck.value)||isInteger(objCheck.value)){
		return true;}
	else{
		PopWinClient("<strong>Amount Validation<HR></strong>Please supply only positive numbers for Amount.", "Validation Error", "MenuTable", 10000);
		objCheck.value="";}
	var strAmount=new String(objCheck.value);
	if(strAmount.length<1 || strAmount=="."){
		objCheck.value="0.00";
	} 
	return;
}
function CheckBalance(objAmount){
	objAmount.value=stripCharsNotInBag(objAmount.value, digits+".");
	var strAmount=new String(objAmount.value);
	if(strAmount.length<1 || strAmount=="."){
		objAmount.value="0.00";
	}else{
		var doubAmount = new Number(objAmount.value);
		objAmount.value = doubAmount.toFixed(2);
	}
	if(document.frames.ICFRSBody.document.getElementById("txtEditType").value=="ADD"){
		document.frames.ICFRSBody.document.getElementById("inpBalance").value=objAmount.value;
	}
	return;
}
//*************************
// Global Validators Enable/Disable. Will loop the entire collection for the current page.
// Calling page is responsible for disabling any validators that are not needed because
// of transaction type business rules.

function EnableValidation(){
    for (i = 0; i < document.frames.ICFRSBody.Page_Validators.length; i++) {
			document.frames.ICFRSBody.Page_Validators[i].enabled=true;
    }
	return;
}
function DisableValidation(){
    for (i = 0; i < document.frames.ICFRSBody.Page_Validators.length; i++) {
			document.frames.ICFRSBody.Page_Validators[i].enabled=false;
    }
	return;
}
function tbonMouseOver(txtButton){
	var objButton=ReturnObj(txtButton);
	objButton.className='tbBtnHover';
	return false;
}
function tbonMouseOut(txtButton){
	var objButton=ReturnObj(txtButton);
	objButton.className='tbBtnDefault';
	return false;
}
function tbonMouseUp(txtButton){
	var objButton=ReturnObj(txtButton);
	objButton.className='tbBtnDefault';
	return false;
}
function tbonMouseDown(txtButton){
	var objButton=ReturnObj(txtButton);
	objButton.className='tbBtnSelect';
	return false;
}
function ReturnObj(txtElement){
	var objElement;
	if(typeof(document.frames.ICFRSBody) != "undefined" && null != document.frames.ICFRSBody)
		objElement=document.frames.ICFRSBody.document.getElementById(txtElement);
	else
		objElement=document.getElementById(txtElement);
	return objElement;
}
var popUp; 
function OpenCalendar(idname, postBack)
{
	var strHoldMode="";
	if(null !=ICFRSBody.document.getElementById('txtEditType') ){
		strHoldMode=ICFRSBody.document.getElementById('txtEditType').value;
		ICFRSBody.document.getElementById('txtEditType').value="CALENDAR";
	}
	popUp = window.open('../cf_utility/Calendar.aspx?formname=' + document.forms[0].name + '&mode=' + strHoldMode + 
		'&id=' + idname + '&selected=' + document.frames.ICFRSBody.document.forms[0].elements[idname].value+ '&postBack=' + postBack, 
		'popupcal','width=165,height=245,left=200,top=250');
}

function SetDate(formName, id, newDate, postBack, mode)
{
	eval('var theform = document.' + formName + ';');
	popUp.close();
	if(null !=ICFRSBody.document.getElementById('txtEditType') )
		ICFRSBody.document.getElementById('txtEditType').value=mode;
	document.frames.ICFRSBody.document.forms[0].elements[id].value = newDate;
	if (postBack)
		__doPostBack(id,'');
}
function ReSetMode(mode){
//debugger
	popUp.close();
	if(null !=ICFRSBody.document.getElementById('txtEditType') )
		ICFRSBody.document.getElementById('txtEditType').value=mode;
}
//Post back the requested form name. Custom handler to provide post back to asp.net form code behind file without using .net controls. 
//Will co-exist when used in conjucntion with ASP.NET controls.
function PostBack(eventTarget, eventArgument, formName) {
	var theform;
	if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
		if(null!=document.frames["ICFRSBody"])
			theform = document.frames.ICFRSBody.forms[formName];
		else
			theform = document.forms[formName];
	}
	else {
		if(null!=frames["ICFRSBody"])
			theform = eval("frames.ICFRSBody.document."+formName);
		else
			theform = eval("document."+formName);
	}//frames.ICFRSBody.document.forms.item(0)
	theform._EVENTTARGET.value = eventTarget.split("$").join(":");
	theform._EVENTARGUMENT.value = eventArgument;
	theform.submit();
	return false;
}
function _doPostBack(eventTarget, eventArgument) {
	//Generic post back control. Utility.js
	PostBack(eventTarget, eventArgument, FrameBody.forms.item(0).id);
	return false;
}
function UnSelectOtherRows(SelectedRow, GridName){
	SelectedRow.className="hold";
	var objTable=null;
	if(null !=parent.frames['ICFRSTransactions'])
		objTable=parent.frames['ICFRSTransactions'].document.getElementById(GridName);
	
	if(null==objTable && null !=parent.frames['IQuickSearch'])
		objTable=parent.frames['IQuickSearch'].document.getElementById(GridName);
	
	if(null==objTable && null !=parent.frames['ICFRSBody'])
		objTable=parent.frames['ICFRSBody'].document.getElementById(GridName);
	
	if(null==objTable && null !=parent.document.getElementById(GridName))
		objTable=parent.document.getElementById(GridName);
	
	if(null==objTable && null !=document.getElementById(GridName))
		objTable=document.getElementById(GridName);
	
	if(null!=objTable && "undefined" != typeof(objTable)){
		//Start at 1 to skip header
		for(intRow=0; intRow< (objTable.rows.length);++intRow){
			if(typeof(objTable.rows[intRow].className)!="undefined"){
				if(objTable.rows[intRow].className=="grid-selected"){	
					objTable.rows[intRow].className=(objTable.rows[intRow].id=="Alternating") ?"grid-alternating" : "grid-item";
					objTable.rows[intRow].style.backgroundColor=(objTable.rows[intRow].id=="Alternating") ? "ghostwhite" : "white";
					break;
				}
			}
		}
	}
	SelectedRow.className="grid-selected";
	SelectedRow.style.backgroundColor="lightcyan";
	return;
}
//Assumes the key position is at column 0.
function SelectRow(DataGrid, RowKey){
	try{
		if(null != DataGrid && typeof(DataGrid) !="undefined"){
			for(intRow=0; intRow< (DataGrid.rows.length); ++intRow){
				if(DataGrid.rows[intRow].firstChild.firstChild.nodeValue==RowKey){
					DataGrid.rows[intRow].className="grid-selected";
					DataGrid.rows[intRow].style.backgroundColor="lightcyan";
					break;
				}
			}
		}
	}
	catch(e){
	}
	return;
}
