﻿var g_tmp_ddl_ACHDrafts;
var g_leftovers = 0;

function CopyOneTimeValues(){
	document.all('OneTimeDebit_dub_StartDate').value=document.all('OneTimeDebit_txt__startdate').value;
	document.all('OneTimeDebit_dub_MonthyPayment').value=document.all('OneTimeDebit_req_txt__MonthlyPayment').value;
}

function CopyRecurringValues(){
	document.all('RecurringDebit_dub_StartDate').value=document.all('RecurringDebit_txt__startdate').value;
	document.all('RecurringDebit_dub_MonthyPayment').value=document.all('RecurringDebit_req_txt__MonthlyPayment').value;
}

function SetStartDate(GroupID,section){

	var d = new Date();
	var num = new Number(GroupID);
	var s = "";
	var docColl = document.all;
	var ddl_ACHDrafts;
	
	if (num == -1){return}
	
	if (num != 0 ){	
		if (num >= d.getDate()){
			s += (d.getMonth() + 1) + "/";
			s += num + "/";
			s += d.getYear();		
			
			d = new Date(s);
			
			s = (d.getMonth() + 1) + "/";            //Get month
			s += d.getDate() + "/";                   //Get day
			s += d.getYear();						//Get year
		}else{
			s += (d.getMonth() + 2) + "/";
			s += num + "/";
			s += d.getYear();
			d = new Date(s);

			s = (d.getMonth() + 1) + "/";            //Get month
			s += d.getDate() + "/";                   //Get day
			s += d.getYear();						//Get year


		}

		var docColl = document.all;	
		var docControl;
		if (docColl != null){
			for(i=0;i<docColl.length;i++){
				//For the GroupID visible text field
				if(docColl.item(i).tagName == 'INPUT' && docColl.item(i).id.indexOf('txt__startdate') != -1 ){
					docControl = docColl.item(i);
					
					if (section=='O' && (docControl.id.indexOf('One')!=-1)){
						
						docControl.value = s;
					}
					if (section=='R' && (docControl.id.indexOf('Rec')!=-1)){

						document.all("RecurringDebit_DayOfMonth").value = d.getDate()			
						docControl.value = s;
					}
					if (section==''){

						docControl.value = s;
					}					
				}
				
				//For the GroupID hidden text field
				if(docColl.item(i).tagName == 'INPUT' && docColl.item(i).id.indexOf('txt_ACHGroupID') != -1 ){
					docControl = docColl.item(i);
					
					if (section=='O' && (docControl.id.indexOf('One')!=-1)){
						
						docControl.value = GroupID;
					}
					if (section=='R' && (docControl.id.indexOf('Rec')!=-1)){
						
						docControl.value = GroupID;
					}
					if (section==''){

						docControl.value = GroupID;
					}
				}
			}
		}

	}
		
	if (docColl != null){
		for(i=0;i<docColl.length;i++){
		
			if(docColl.item(i).tagName == 'SELECT' && docColl.item(i).id.indexOf('ACHGroups') != -1 ){
				ddl_ACHDrafts = docColl.item(i);
				break;
			}
		}
	}	
	
	try{
		document.all("txt_ACHGroupID").value = ddl_ACHDrafts(ddl_ACHDrafts.selectedIndex).text
	}catch(e){
		document.all("RecurringDebit_txt_ACHGroupID").value = ddl_ACHDrafts(ddl_ACHDrafts.selectedIndex).text
	}

}

function SetDateChooserFromACHGroup(GroupID,dtScheduledDateID,DayOfTheMonthID){
    var chooser = document.getElementById(dtScheduledDateID);
    //var chooser = igdrp_getComboById(dtScheduledDateID);
	var d = new Date();
	var num = new Number(GroupID);
	var newDate = new Date();
	var docColl = document.all;
	var ddl_ACHDrafts;
	
	if (num == -1){return}
	
	if (num != 0 ){	
		if (num >= d.getDate())
		    newDate.setMonth(d.getMonth());
		else
		    newDate.setMonth(d.getMonth() + 1);
	    newDate.setDate(num);
	    newDate.setFullYear(d.getFullYear());

	    chooser.value = newDate.format("MM/dd/yyyy");
        //chooser.setValue(newDate);
	}
	if (DayOfTheMonthID != null){
	    var DayOftheMonth = document.getElementById(DayOfTheMonthID);
	    if (DayOftheMonth != null)
	        DayOftheMonth.value = newDate.getDate();
	}
	        
}

/**************************************************************************
' Author:  Andrew Cotterell
' Date:    11.04.2003
' Purpose: To set the ACH Group based on the debt date.
' Inputs:  Day and the ACH Group drop down.
' 
'		   
'***************************************************************************/
function SelectDebitACHGroup(dte,SetGroupID){
   // For the given date day, find the matching GROUP.
   // Doing client side to avoid postback to server.
	
	if (isEmpty(dte.value)){return false;}
	
	var d = new Date(dte.value);
	if(isNaN(d)){alert ('You have entered an invalid date.');return false;}
	
	var iCount = 0;
	var docColl = document.all;
	var ddl_ACHDrafts;
	var colIdx = new Array();
	

	if (docColl != null){
		for(i=0;i<docColl.length;i++){
		
			if(docColl.item(i).tagName == 'SELECT' && docColl.item(i).id.indexOf('ACHGroups') != -1 ){
				ddl_ACHDrafts = docColl.item(i);
				
				
				if (g_tmp_ddl_ACHDrafts == null){
					g_tmp_ddl_ACHDrafts = new cloneObject(ddl_ACHDrafts);
				}


				if (ddl_ACHDrafts.selectedIndex != 0 ){
					return;
				}
			
				for (i = 0; i < ddl_ACHDrafts.options.length; i += 1){
					if ( ddl_ACHDrafts.options(i).value == d.getDate() || ddl_ACHDrafts.options(i).value == 0 ){
						iCount += 1;
					}else{
						colIdx[i] = ddl_ACHDrafts.options(i).text
					}
				}
			

				
				//If more the ACH Group was found enable the drop down and select the first item.
				if (iCount > 1){

					//DELETE ACHGroups that didn't not match the selected date
					for (i = 0 ; i < colIdx.length; i++ ){
						for (idx = 0; idx < ddl_ACHDrafts.length; idx++){
							try{
								if (colIdx[i].toString() == ddl_ACHDrafts.options(idx).text){
									ddl_ACHDrafts.options.remove(idx);
								}
							}catch(e){}
						}
					}
					
					ddl_ACHDrafts.disabled = false;
				}else{
					if (iCount==0){
					
						if (ddl_ACHDrafts.length < 5){g_leftovers = ddl_ACHDrafts.length}

							if(g_tmp_ddl_ACHDrafts.length != (ddl_ACHDrafts.length-g_leftovers) ){
					
								var oOption
									for (i = 0; i < g_tmp_ddl_ACHDrafts.length; i++ ){
										oOption = document.createElement("OPTION");
										ddl_ACHDrafts.options.add(oOption)
										oOption.innerText = g_tmp_ddl_ACHDrafts[i].text
										oOption.value = g_tmp_ddl_ACHDrafts[i].value
								
									}
							
								SelectDebitACHGroup(dte,SetGroupID)
							}else{
								//No ACH group was found.
								alert('No ACH Group was found for the given date.\nPlease select an ACH Group.')
								//delete the extras
								for (o=0;o<g_leftovers;o++){ddl_ACHDrafts.options.remove(o)}
								ddl_ACHDrafts.disabled = false;
								
							}		

					}else{
						//DELETE ACHGroups that didn't not match the selected date
						for (i = 0 ; i < colIdx.length; i++ ){
							for (idx = 0; idx < ddl_ACHDrafts.length; idx++){
								try{
									if (colIdx[i].toString() == ddl_ACHDrafts.options(idx).text){
										ddl_ACHDrafts.options.remove(idx);
									}
								}catch(e){}
							}
						}
						
						ddl_ACHDrafts.disabled = false;
					}
				}
				
				
				if (SetGroupID==true){
					ddl_ACHDrafts.options.item(0).selected=true;
					document.all("txt_ACHGroupID").value = ddl_ACHDrafts(ddl_ACHDrafts.selectedIndex).text
				}
				break;
			}
		
		}
	}
	
	
}


function SelectACHGroupFromDate(datevalue,ddl_ACHGroupID){
   // For the given date day, find the matching GROUP.
   // Doing client side to avoid postback to server.
	
	if (isEmpty(datevalue)){return false;}
	
	var d = new Date(datevalue);
	
	if(isNaN(d)){alert ('You have entered an invalid date.');return false;}
	
	var iCount = 0;
	var colIdx = new Array();
	var ddl_ACHDrafts = document.all(ddl_ACHGroupID).options;
	
	
	if (g_tmp_ddl_ACHDrafts == null){
		g_tmp_ddl_ACHDrafts = new cloneObject(ddl_ACHDrafts);
	}
	

	//If the ACH Group ID is not the first item in the list.
	if (ddl_ACHDrafts.selectedIndex != 0 ){
		return;
	}
	
	var colIdx = new Array();
	
	for (i = 0; i < ddl_ACHDrafts.length; i++){
		// ddl_ACHDrafts.options(i).value == 0 indicates null ach groups.
		if ( ddl_ACHDrafts(i).value == d.getDate() || ddl_ACHDrafts.options(i).value == 0 ){
			iCount += 1;

		}else{
			colIdx[i] = ddl_ACHDrafts.options(i).text
		}
	}
	
	//If more the ACH Group was found enable the drop down and select the first item.
	if (iCount > 1){
		//DELETE ACHGroups that didn't not match the selected date
		for (i = 0 ; i < colIdx.length; i++ ){
			for (idx = 0; idx < ddl_ACHDrafts.length; idx++){
				try{
					if (colIdx[i].toString() == ddl_ACHDrafts.options(idx).text){
						ddl_ACHDrafts.options.remove(idx);
					}
				}catch(e){}
			}
		}
	
		ddl_ACHDrafts.disabled = false;
	}else{
		if (iCount==0){
		
			if (ddl_ACHDrafts.length < 5){g_leftovers = ddl_ACHDrafts.length}
			
			if(g_tmp_ddl_ACHDrafts.length != (ddl_ACHDrafts.length-g_leftovers) ){
	
				var oOption
					for (i = 0; i < g_tmp_ddl_ACHDrafts.length; i++ ){
						oOption = document.createElement("OPTION");
						ddl_ACHDrafts.options.add(oOption)
						oOption.innerText = g_tmp_ddl_ACHDrafts[i].text
						oOption.value = g_tmp_ddl_ACHDrafts[i].value
				
					}
			
				SelectACHGroupFromDate(datevalue,ddl_ACHGroupID);
			}else{
				//No ACH group was found.
				alert('No ACH Group was found for the given date.\nPlease select an ACH Group.')
				//delete the extras
				for (o=0;o<g_leftovers;o++){ddl_ACHDrafts.options.remove(o)}
				ddl_ACHDrafts.disabled = false;
				
			}		
		}else{
		
			//DELETE ACHGroups that didn't not match the selected date
			for (i = 0 ; i < colIdx.length; i++ ){
				for (idx = 0; idx < ddl_ACHDrafts.length; idx++){
					try{
						if (colIdx[i].toString() == ddl_ACHDrafts.options(idx).text){
							ddl_ACHDrafts.options.remove(idx);
						}
					}catch(e){}
				}
			}

				
				ddl_ACHDrafts.disabled = false;
			
		}		

	}

	ddl_ACHDrafts.value = d.getDate()
	ddl_ACHDrafts.options.item(0).selected=true;
}

/**************************************************************************
' Author:  Andrew Cotterell
' Date:    11.04.2003
' Purpose: To set the ACH Group based on the debt date.
' Inputs:  Day and the ACH Group drop down.
'		   
'***************************************************************************/
function SelectOneTimeDebitACHGroup(dte){
   // For the given date day, find the matching GROUP.
   // Doing client side to avoid postback to server.
	
	if (isEmpty(dte.value)){return false;}
	
	var d = new Date(dte.value);
	
	if(isNaN(d)){alert ('You have entered an invalid date.');return false;}
	
	var iCount = 0;
	var colIdx = new Array();
	var ddl_ACHDrafts = document.all("OneTimeDebit_ddl__ACHGroups").options;
	
	
	if (g_tmp_ddl_ACHDrafts == null){
		g_tmp_ddl_ACHDrafts = new cloneObject(ddl_ACHDrafts);
	}
	

	//If the ACH Group ID is not the first item in the list.
	if (ddl_ACHDrafts.selectedIndex != 0 ){
		return;
	}
	
	var colIdx = new Array();
	
	for (i = 0; i < ddl_ACHDrafts.length; i++){
		// ddl_ACHDrafts.options(i).value == 0 indicates null ach groups.
		if ( ddl_ACHDrafts(i).value == d.getDate() || ddl_ACHDrafts.options(i).value == 0 ){
			iCount += 1;

		}else{
			colIdx[i] = ddl_ACHDrafts.options(i).text
		}
	}
	
	//If more the ACH Group was found enable the drop down and select the first item.
	if (iCount > 1){
		//DELETE ACHGroups that didn't not match the selected date
		for (i = 0 ; i < colIdx.length; i++ ){
			for (idx = 0; idx < ddl_ACHDrafts.length; idx++){
				try{
					if (colIdx[i].toString() == ddl_ACHDrafts.options(idx).text){
						ddl_ACHDrafts.options.remove(idx);
					}
				}catch(e){}
			}
		}
	
		ddl_ACHDrafts.disabled = false;
	}else{
		if (iCount==0){
		
			if (ddl_ACHDrafts.length < 5){g_leftovers = ddl_ACHDrafts.length}
			
			if(g_tmp_ddl_ACHDrafts.length != (ddl_ACHDrafts.length-g_leftovers) ){
	
				var oOption
					for (i = 0; i < g_tmp_ddl_ACHDrafts.length; i++ ){
						oOption = document.createElement("OPTION");
						ddl_ACHDrafts.options.add(oOption)
						oOption.innerText = g_tmp_ddl_ACHDrafts[i].text
						oOption.value = g_tmp_ddl_ACHDrafts[i].value
				
					}
			
				SelectOneTimeDebitACHGroup(dte)
			}else{
				//No ACH group was found.
				alert('No ACH Group was found for the given date.\nPlease select an ACH Group.')
				//delete the extras
				for (o=0;o<g_leftovers;o++){ddl_ACHDrafts.options.remove(o)}
				ddl_ACHDrafts.disabled = false;
				
			}		
		}else{
		
			//DELETE ACHGroups that didn't not match the selected date
			for (i = 0 ; i < colIdx.length; i++ ){
				for (idx = 0; idx < ddl_ACHDrafts.length; idx++){
					try{
						if (colIdx[i].toString() == ddl_ACHDrafts.options(idx).text){
							ddl_ACHDrafts.options.remove(idx);
						}
					}catch(e){}
				}
			}

				
				ddl_ACHDrafts.disabled = false;
			
		}		

	}

	ddl_ACHDrafts.value = d.getDate()
	ddl_ACHDrafts.options.item(0).selected=true;
	document.all("OneTimeDebit_txt_ACHGroupID").value = ddl_ACHDrafts(ddl_ACHDrafts.selectedIndex).text
}


/**************************************************************************
' Author:  Andrew Cotterell
' Date:    11.04.2003
' Purpose: To set the ACH Group based on the debt date.
' Inputs:  Day and the ACH Group drop down.
'		   
'***************************************************************************/
function SelectRecurringACHGroup(dte){
   // For the given date day, find the matching GROUP.
   // Doing client side to avoid postback to server.
   
    if (isEmpty(dte.value)){return false;}
   
	var d = new Date(dte.value);	
	if(isNaN(d)){alert ('You have entered an invalid date.');return false;}
	
	var iCount = 0;
	
	
	var ddl_ACHDrafts = document.all("RecurringDebit_ddl__ACHGroups").options;
	
	
	if (g_tmp_ddl_ACHDrafts == null){
		g_tmp_ddl_ACHDrafts = new cloneObject(ddl_ACHDrafts);
	}
	

	//If the ACH Group ID is not the first item in the list.
	if (ddl_ACHDrafts.selectedIndex != 0 ){
		return;
	}
	
	var colIdx = new Array();
	
	
		
	for (i = 0; i < ddl_ACHDrafts.length; i++){
		// ddl_ACHDrafts.options(i).value == 0 indicates null ach groups.
		if ( ddl_ACHDrafts(i).value == d.getDate() || ddl_ACHDrafts.options(i).value == 0 ){
			iCount += 1;

		}else{
			colIdx[i] = ddl_ACHDrafts.options(i).text
		}
	}
	
	//If more the ACH Group was found enable the drop down and select the first item.
	if (iCount > 1){
		
		//DELETE ACHGroups that didn't not match the selected date
		for (i = 0 ; i < colIdx.length; i++ ){
			for (idx = 0; idx < ddl_ACHDrafts.length; idx++){
				try{
					if (colIdx[i].toString() == ddl_ACHDrafts.options(idx).text){
						ddl_ACHDrafts.options.remove(idx);
					}
				}catch(e){}
			}
		}
	
		ddl_ACHDrafts.disabled = false;
	}else{
		if (iCount==0){
		
			if (ddl_ACHDrafts.length < 5){g_leftovers = ddl_ACHDrafts.length}
			
			if(g_tmp_ddl_ACHDrafts.length != (ddl_ACHDrafts.length-g_leftovers) ){
	
				var oOption
					for (i = 0; i < g_tmp_ddl_ACHDrafts.length; i++ ){
						oOption = document.createElement("OPTION");
						ddl_ACHDrafts.options.add(oOption)
						oOption.innerText = g_tmp_ddl_ACHDrafts[i].text
						oOption.value = g_tmp_ddl_ACHDrafts[i].value
				
					}
			
				SelectRecurringACHGroup(dte)
			}else{
				//No ACH group was found.
				alert('No ACH Group was found for the given date.\nPlease select an ACH Group.')
				//delete the extras
				for (o=0;o<g_leftovers;o++){ddl_ACHDrafts.options.remove(o)}
				ddl_ACHDrafts.disabled = false;
				
			}		
		}else{
		
			//DELETE ACHGroups that didn't not match the selected date
			for (i = 0 ; i < colIdx.length; i++ ){
				for (idx = 0; idx < ddl_ACHDrafts.length; idx++){
					try{
						if (colIdx[i].toString() == ddl_ACHDrafts.options(idx).text){
							ddl_ACHDrafts.options.remove(idx);
						}
					}catch(e){}
				}
			}

			ddl_ACHDrafts.disabled = false;
			
		}		

	}
	

	if( isNaN(d.getDate()) ){
		document.all("RecurringDebit_DayOfMonth").value = '';
	}else{
		document.all("RecurringDebit_DayOfMonth").value = d.getDate();
	}

	ddl_ACHDrafts.value = d.getDate();
	ddl_ACHDrafts.options.item(0).selected=true;

	document.all("RecurringDebit_txt_ACHGroupID").value = ddl_ACHDrafts(ddl_ACHDrafts.selectedIndex).text;
}

/**************************************************************************
' Author:  Andrew Cotterell
' Date:    11.04.2003
' Purpose: To set the ACH Group based on the debt date.
' Inputs:  Disable flag: True/False.
'		   
'***************************************************************************/
function DisableDebitControls(ControlName, chkagreeid,FormTableID,req_txt__ABA,lbl__BankName,req_txt__OptionalBankName,req_txt__BankAccountNumber,ddl__ACHGroups){
	try{
	    var chkagree = document.getElementById(chkagreeid);
		bFlag = chkagree.checked;
		
		if (bFlag){
			if (!BankAccountFormCheck(ControlName,req_txt__ABA,lbl__BankName,req_txt__OptionalBankName,req_txt__BankAccountNumber)){
				chkagree.checked = false;
				return false;
			}
		}
		
//		CopyOneTimeValues()	
//	
		
//		document.all("OneTimeDebit_SaveCheck").value = bFlag			
//		
		var objTableRows = document.all(FormTableID).rows;
		var objTable = document.all(FormTableID).all;


//		for (i = 0; i < objTable.length; i += 1){
//			if (( objTable(i).id.indexOf('__') != -1 ) && (objTable(i).id != chkagreeid) ){
//				objTable(i).disabled = !bFlag;
//			}
//		}	
		
		for (i = 0; i < objTableRows.length; i += 1){
		
			
			if (objTableRows(i).tagName == 'IMG' && !bFlag){
				objTableRows(i).runtimeStyle.display='none';
			}else{
				objTableRows(i).runtimeStyle.display='inline';
			}
			
			if (i > 0){
				objTableRows(i).disabled = !bFlag;
			}
		}
			
		for (i = 0; i < objTable.length; i += 1){
		
			if (!bFlag){
				objTable(i).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.BasicImage(grayscale=1)"
			}else{
				objTable(i).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.BasicImage(grayscale=0)"
			}
		}
		
		document.all(ddl__ACHGroups).disabled = !bFlag;
	}catch(e){}	
	
	
}


/**************************************************************************
' Author:  Andrew Cotterell
' Date:    11.04.2003
' Purpose: To disable the bank account if account type equals processing
' Issue: 9062
'***************************************************************************/
function DisableBankAccount(){
	try{
		
		if (document.all("BankAccount_hdn__AccType").value == 'Processing'){

			var bFlag = true;
		
			
			var objTableRows = document.all("BankAccount_FormTable").rows;
			var objTable = document.all("BankAccount_FormTable").all;

			for (i = 0; i < objTable.length; i += 1){
				if(objTable(i).tagName == 'SELECT'){
					objTable(i).runtimeStyle.display='none';
					document.all("ltr_AccountType").innerText = 'Processing'
				}
				
				if(objTable(i).tagName == 'INPUT'){
					if(objTable(i).type == 'checkbox'){
						objTable(i).disabled=true;
					}
				}
			}

			for (i = 0; i < objTable.length; i += 1){
				if ( objTable(i).id.indexOf('__') != -1 ){
					if(objTable(i).tagName == 'INPUT'){
						if(objTable(i).type == 'checkbox'){
							objTable(i).disabled=true;
						}else{
							objTable(i).className = 'READONLY_TEXT';
						}
					}else{
						objTable(i).className = 'READONLY_TEXT';
					}
				}	
			}	
			

			//IF we want to make the table grey uncomment this	
			/*
			for (i = 0; i < objTable.length; i += 1){
			
				if (!bFlag){
					objTable(i).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.BasicImage(grayscale=1)"
				}else{
					objTable(i).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.BasicImage(grayscale=0)"
				}
			}
			*/
			document.all("BankAccount_ddl__AccType").disabled = bFlag;
			document.all("BankAccount_btn_UpdateBankInfo").runtimeStyle.display='none';
			document.all("BankAccount_btn_ValidateBankRoutingNumber").runtimeStyle.display='none';
		}
		
	}catch(e){}	

}

/**************************************************************************
' Author:  Andrew Cotterell
' Date:    11.04.2003
' Purpose: To set the ACH Group based on the debt date.
' Inputs:  Disable flag: True/False.
'		   
'***************************************************************************/
function DisableRecurringDebitControls(){
	
	try{
		bFlag = document.all("RecurringDebit_chk_Iagree").checked
		
		if (bFlag){
			if (!BankAccountFormCheck(document.all('Form1'),'Recurring Debit')){
				document.all("RecurringDebit_chk_Iagree").checked = false;
				return false;
			}
		}
		
		CopyRecurringValues()
		var objTableRows = document.all("RecurringDebit_FormTable").rows;
		var objTable = document.all("RecurringDebit_FormTable").all;


		for (i = 0; i < objTable.length; i += 1){
			if ( objTable(i).id.indexOf('__') != -1 ){
				objTable(i).disabled = !bFlag;
			}
		}	
		
		for (i = 0; i < objTableRows.length; i += 1){
		
			
			if (objTableRows(i).tagName == 'IMG' && !bFlag){
				objTableRows(i).runtimeStyle.display='none';
			}else{
				objTableRows(i).runtimeStyle.display='inline';
			}
			
			if (i > 0){
				objTableRows(i).disabled = !bFlag;
			}

		}
			
		for (i = 0; i < objTable.length; i += 1){
		
			if (!bFlag){
				objTable(i).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.BasicImage(grayscale=1)"
			}else{
				objTable(i).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.BasicImage(grayscale=0)"
			}
		}


		document.all("RecurringDebit_ddl__ACHGroups").disabled = !bFlag;
	}catch(e){}	
}



/**************************************************************************
' Author:  Andrew Cotterell
' Date:    11.04.2003
' Purpose: 
' Inputs:  
'		   
'***************************************************************************/
function ValideBankRoutingNumber(obj,reqid,lblid){
   // Run through each digit and calculate the total.
	if (obj.value.length > 0){
		n = 0;
		for (i = 0; i < obj.value.length; i += 3) {
			n += parseInt(obj.value.charAt(i),     10) * 3
			+  parseInt(obj.value.charAt(i + 1), 10) * 7
			+  parseInt(obj.value.charAt(i + 2), 10);
		}

		// If the resulting sum is an even multiple of ten (but not zero),
		// the aba routing number is good.
		// We allow the 000000000 for Global to be able to process Money Orders

		if ((n != 0 && n % 10 == 0) || (obj.value == '000000000')){
			document.getElementById(reqid).runtimeStyle.display='none';
		}
		else
		{
			try{
				document.getElementById(lblid).runtimeStyle.display='none';
			}catch(e){
			}
			
			document.getElementById(reqid).runtimeStyle.display='inline';
			document.getElementById(reqid).innerHTML = 'Invalid ABA Route Number.';
			obj.focus();
			obj.select();			
		}
	}else{
		document.getElementById(reqid).runtimeStyle.display='none';
	}
}


/**************************************************************************
' Author:  Andrew Cotterell
' Date:    11.04.2003
' Purpose:	Determine whether or not the optional bank name is required
'			based on the bank name being empty or not.
' Inputs:  
'		   
'***************************************************************************/
function CheckBankName(){
	var pageForm = document.all('Form1')

	if (isWhitespace(BankAccount_lbl__BankName.innerText)){
		pageForm.BankAccount_req_txt__OptionalBankName.runtimeStyle.className = 'REQUIRED_TEXT';
		document.all('BankAccount_optionalInformation').innerHTML = '<br>This field is required if the rounting number was not validated.';

	}else{
		document.all('BankAccount_optionalInformation').innerHTML = '';
		pageForm.BankAccount_req_txt__OptionalBankName.className = 'INPUT_TEXT';

	}
}


function moveBack()
{
	window.history.back();
}

function clearBox(accountnum,val)
{
	if (accountnum.value.indexOf('t Number') > 0)
		{
			accountnum.value = '';
			accountnum.selected ;
		}
    
}

function go_to(dest)
{
	location.href = dest;
}


//Description	:	This function will warn the user that his or her
//					sessioin is about to expire.
//					if the user choose to continue. It will simple 
//					reload the page and maitain session.
//Date			:	9/04/02	
function WarnUserTimeout(){
    if (window.confirm('Your session will expire in 5 minutes. Do you want to continue?'))
    {
    	window.history.go(0)
    }
}


function BankAccountFormCheck(section,req_txt__ABA,lbl__BankName,req_txt__OptionalBankName,req_txt__BankAccountNumber){

	var why = "";
	var prefix = "The following fields are required before the "+section+" section can be activated:\n"
	
	if (isWhitespace(document.getElementById(req_txt__ABA).value)) {
		why += '\t - Rounting Number';
		why += "\n";
    }

    if (isWhitespace(document.getElementById(lbl__BankName).innerText) && isWhitespace(document.getElementById(req_txt__OptionalBankName).value)){
    	why += '\t - Bank Name';
		why += "\n";
    }
    
    if (isWhitespace(document.getElementById(req_txt__BankAccountNumber).value)) {
		why += '\t - Account Number';
		why += "\n";
    }

	if (why != ""){
		alert (prefix + why);
		return false
	}	
	
	return true;
}


function cloneObject(what) {
    for (i in what) {
        this[i] = what[i];
    }
}

function retrieveObject(what) {
    var output = '';
    for (i in what) {
        if (typeof what[i] == 'object') {
            output += retrieveObject(what[i]);
        }
        else
            output += i + ' = ' + what[i] + '\n';
    }
    return output;
}



function RefreshScheduleTransactions(){
try{
	var frm = parent.document.frames;
	frm(0).document.all("__VIEWSTATE").name = "NOTVIEWSTATE"
	frm(0).document.forms("Form1").submit();
}catch(e){};
	//frm(0).document.__doPostBack('','')
}


function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}


//***************************************************************************
//Author: Andrew Cotterell
//Date: 5.15.2003
//Purpose:	Opens the Advance Search Option modal
//			the name Url.
//***************************************************************************
function OpenDocumentPrintWindow(standAlone,SQLReportName,sign){

	if(sign)
		{
		doOpenModal(APPLICATION_PATH + '/Signature/ViewDoc.aspx?View=2&SQLReportName='+SQLReportName+ '&URL=' + APPLICATION_PATH + '/Signature/Documents.aspx', 640, 800)	
		}
	else
		{
		if (SQLReportName != ''){
			if (standAlone){
				doOpenModal(APPLICATION_PATH + '/SQLReports/DocumentView.aspx?SQLReportName='+SQLReportName, 800, 800)		
			}else{
				doOpenModal(APPLICATION_PATH + '/SQLReports/DocumentView.aspx?crossOverApp=LM&SQLReportName='+SQLReportName, 800, 800)		
			}
		}else{
			alert('This report does not have a valid id.')	;
		}
		}
}

//LUIS MONTALVO - This function is no longer used
//***************************************************************************
//Author: Andrew Cotterell
//Date: 5.15.2003
//Purpose:	Opens the Advance Search Option modal
//			the name Url.
//***************************************************************************
//function OpenDocumentPrintWindow2(standAlone,buttonid, documentid,sign){

//	if(sign)
//		{
//		doOpen(APPLICATION_PATH + '/Signature/ViewDoc.aspx?View=2&documentid='+documentid+'&buttonid='+buttonid + '&URL=' + APPLICATION_PATH + '/Signature/Documents.aspx', 640, 800)	
//		}
//	else
//		{
//		if (buttonid != '' && documentid != ''){
//			if (standAlone){
//				doOpen(APPLICATION_PATH + '/SQLReports/DocumentView2.aspx?documentid='+documentid+'&buttonid='+buttonid, 760, 800)		
//			}else{
//				doOpen(APPLICATION_PATH + '/SQLReports/DocumentView2.aspx?crossOverApp=LM&documentid='+documentid+'&buttonid='+buttonid, 640, 800)		
//			}
//		}else{
//			alert('This report does not have a valid id.')	;
//		}
//		}
//}

  function DownloadIssueAttachment(IssueID, AttachmentName)
  {
      // Create an IFRAME.
      var iframe = document.createElement("iframe");
 
      // Get the desired region from the dropdown.
      //var region = $get("Region").value;
 
      // Point the IFRAME to GenerateFile, with the
      //   desired region as a querystring argument.
      iframe.src = APPLICATION_PATH + "/SQLReports/DocumentView2.aspx?RequestType=IssueAttachment&AttachmentName=" + AttachmentName + "&IssueID=" + IssueID
 
      // This makes the IFRAME invisible to the user.
      iframe.style.display = "none";
      // Add the IFRAME to the page.  This will trigger
      //   a request to GenerateFile now.
      document.body.appendChild(iframe); 
  }


//***************************************************************************
//Author: Andrew Cotterell
//Date: 5.13.2003
//Purpose:	To open a Modal pop-up window centered to the parent with 
//			the name Url.
//***************************************************************************
function doOpenModal(pageName, iWindowWidth, iWindowHeight){
	var sWindowConfig = "resizable:no;help:no;scroll:yes;center:yes;status:no;dialogWidth:" + iWindowWidth + "px;dialogHeight:" + iWindowHeight + "px";
	var returnValue = window.showModalDialog(pageName,null, sWindowConfig);
}

//***************************************************************************
//Author: Andrew Cotterell
//Date: 5.13.2003
//Purpose:	To open a Modal pop-up window centered to the parent with 
//			the name Url.
//***************************************************************************
function doOpen(pageName, iWindowWidth, iWindowHeight){
    //var sWindowConfig = "resizable:no;toolbar:yes;menubar:yes;scroll:yes;center:yes;status:no;dialogWidth:" + iWindowWidth + "px;dialogHeight:" + iWindowHeight + "px";
	var returnValue = window.open(pageName,null);
}


//******************************************************************************************
//	Report Server Print Section
//	By: Acotterel
//******************************************************************************************

function OnSavePage(){
	var oWnd = GetContentWnd();	
	var oDoc = oWnd.document;	
	var strLoc = oWnd.location.href;
				
	strLoc = strLoc.substr(0, strLoc.lastIndexOf("/")+1)+strPrintPage+'&PrintType=PDF';

	if (window.navigator.userAgent.indexOf("MSIE ")!=-1 && navigator.appVersion.substr(0, 1) >= 4){
			
		if( oWnd.printHiddenFrame == null){

			oDoc.body.insertAdjacentHTML("beforeEnd", "<iframe name='printHiddenFrame' width='0' height='0'></iframe>");
			framedoc = oWnd.printHiddenFrame.document;
			framedoc.open();
			framedoc.write(
				"<frameset name=test onload='printMe.focus();printMe.print();' rows=\"100%\">" +
				"<frame name=printMe src=\""+strLoc+"\">" +							
				"</frameset>");
			framedoc.close();
		}			
	}
	
	return true;
}


function OnPrintPage(){
	var oWnd = GetContentWnd();	
	var oDoc = oWnd.document;	
	var strLoc = oWnd.location.href;
				
	strLoc = strLoc.substr(0, strLoc.lastIndexOf("/")+1)+strPrintPage+'&PrintType=HTML';

	if (window.navigator.userAgent.indexOf("MSIE ")!=-1 && navigator.appVersion.substr(0, 1) >= 4){
			
		if( oWnd.printHiddenFrame == null){

			oDoc.body.insertAdjacentHTML("beforeEnd", "<iframe name='printHiddenFrame' width='0' height='0'></iframe>");
			framedoc = oWnd.printHiddenFrame.document;
			framedoc.open();
			framedoc.write(
				"<frameset name=test onload='printMe.focus();printMe.print();' rows=\"100%\">" +
				"<frame name=printMe src=\""+strLoc+"\">" +							
				"</frameset>");
			framedoc.close();
		}

	}

	return true;
}



function GetContentWnd(){ return window; }	

//******************************************************************************************
//	Counselor/SalesForce Section
//	By: Acotterell
// issue: 8846
//******************************************************************************************

function ChangeMe(obj){
	//SalesForce
	try{
		if (document.all("LeadClientSearch_opt_DisplayCustomers_2").checked == true) {
			document.all("LeadClientSearch_tbr_TypeOfLead").style.display="none"
			document.all("LeadClientSearch_tbr_SearchFilter").style.display="none"
		}
    }catch (e){}
    
	//Clients
    if (document.all("LeadClientSearch_opt_DisplayCustomers_1").checked == true) {
        document.all("LeadClientSearch_tbr_TypeOfLead").style.display="none"
        document.all("LeadClientSearch_tbr_SearchFilter").style.display="none"
    }
    
    //Leads
    if (document.all("LeadClientSearch_opt_DisplayCustomers_0").checked == true) {
		//document.all("LeadClientSearch_tbr_TypeOfLead").style.display="inline"
		document.all("LeadClientSearch_tbr_SearchFilter").style.display="inline"
    }
}

function ChangeSearchViewCondition(obj){
	alert(obj.id);
}


function OpenNote(id){
	doOpenModal(APPLICATION_PATH + '/Signature/IssueNote.aspx?IssueNoteID='+id, 400, 500)
}


//This code fixes a bug that infragistics has with FireFox 3.6.2 - Firebox removed the document.getBoxObjectFor method.  That means 
//it needs to be created on the fly
if (!document.getBoxObjectFor) {
    document.getBoxObjectFor = function(el) {
        var pos = {};

        pos.x = el.offsetLeft;
        pos.y = el.offsetTop;
        parent = el.offsetParent;
        if (parent != el) {
            while (parent) {
                pos.x += parent.offsetLeft;
                pos.y += parent.offsetTop;
                parent = parent.offsetParent;
            }
        }

        parent = el.offsetParent;
        while (parent && parent != document.body) {
            pos.x -= parent.scrollLeft;
            if (parent.tagName != 'TR') {
                pos.y -= parent.scrollTop;
            }
            parent = parent.offsetParent;
        }

        return pos;
    };
}
