// Main JavaScripts
//
function clientLogin(sLogin)
	{
		if (sLogin.value != "")
			{
				if (sLogin.value.length < 4)
					{
						alert("Your Login Name must be at least 4 characters long.");
						document.frmNewClient.strClientLogin.value = ""
						document.frmNewClient.strClientLogin.focus();
					}
			}			
	}
//
function checkSSN(SSN)
	{
		if (SSN.value != "")
			{
				if (SSN.value.length < 9)
					{
						alert("Social Security Numbers must be nine digits.");
						document.frmClientInfo.strSSN.value = ""
						document.frmClientInfo.strSSN.focus();
					}
			}			
	}	
//
function checkCoSSN(SSN)
	{
		if (SSN.value != "")
			{
				if (SSN.value.length < 9)
					{
						alert("Social Security Numbers must be nine digits.");
						document.frmClientInfo.strCoSSN.value = ""
						document.frmClientInfo.strCoSSN.focus();
					}
			}			
	}	
//
//
function counsSSN(SSN)
	{
		if (SSN.value != "")
			{
				if (SSN.value.length < 9)
					{
						alert("Social Security Numbers must be nine digits.");
						document.frmCounsClient.strSSN.value = ""
						document.frmCounsClient.strSSN.focus();
					}
			}			
	}	
//
//
function ResetNC()
	{
			document.frmNewClient.strLogin.value = ""
			document.frmNewClient.strPassword.value = ""
			document.frmNewClient.strPassword2.value = ""
	}
//
//
function AttyLoginReset()
	{
		document.frmAttyLogin.strLogin.value = ""
		document.frmAttyLogin.strPassword.value = ""

	}
//
//
function ResetAtty()
	{
		document.frmAttyList.strAttyFName.value = ""
		document.frmAttyList.strAttyLName.value = ""
		document.frmAttyList.strAttyAdd1.value = ""
		document.frmAttyList.strAttyAdd2.value = ""
		document.frmAttyList.strAttyCity.value = ""
		document.frmAttyList.strGetState.value = ""
		document.frmAttyList.strAttyZip.value = ""
		document.frmAttyList.strAttyPhone.value = ""
		document.frmAttyList.strAttyPhone2.value = ""
		document.frmAttyList.strAttyEmail.value = ""

	}	
//
//
function Help()
	{
		alert("All fields are required.\n\nYour LoginID must be at least 5 characters long.\nYour password must be at least 6 characters long. Use numbers and/or letters.\nIt should be easy for you to remember but hard for others to figure out.\n\nIf you should forget either one click on 'Forgot your Password or LoginID?' link on the Login page and they will be emailed to you again.\n\nFor clients with a co-applicant use the primary's name for login purposes.")
	}
//
//
function WhyState()
	{
		alert("Your State is used to determine what Federal Bankruptcy District you reside.\nThis will enable us to show you bankruptcy attorneys that practice in your state.\n\nUse your legal state residence.")
	}	
//
//
function checkPassword(field)
	{
		if (field.value!="")
			{
				if (field.value.length<6)
					{
						alert("Your password must be at lease 6 characters in length");
						field.value="";
						field.focus();
					}
			}
	}
//
function checkPass2(field)
	{
		if (field.value != "")
			{
				if (field.value != document.frmNewClient.strClientPassword.value)
					{
						alert("Your passwords didn't match. Please try again.");
						field.value="";
						field.focus();
					}
			}
	}
//
function checkPass3(field)
	{
		if (field.value != "")
			{
				if (field.value != document.frmClientInfo.strClientPassword.value)
					{
						alert("Your passwords didn't match. Please try again.");
						field.value="";
						field.focus();
					}
			}
	}	
//
function checkEmail(field)
	{
		if (field.value!="")
			{
				if (!ValidEmail(field.value))
					{
						alert("Please use a valid email address");
						field.value="";
						field.focus();
					}
			}
	}
//
function ValidEmail(strEmail)
	{
		var bIsValid;
		bIsValid = true;
		//Email address should not be less than 5 characters	
		if (strEmail.length < 5)
			{
				bIsValid = false;
			}
		else
			{
			//no spaces
				if (strEmail.indexOf(" ",1) != -1)
					{
						bIsValid = false;
					}
				else
					{
				//		'Must have @ sign
				if (strEmail.indexOf( "@", 1) < 1 )
					{
						bIsValid = false;
					}
				else
					{
						//			'Must have period after @
				if (strEmail.indexOf( ".",strEmail.indexOf( "@", 1) ) < (strEmail.indexOf( "@", 0) + 2) )
					{
						bIsValid = false;
					}
			}	
		}
	}
	return bIsValid;
	} 
//
//ADDED EMPTY SSN CHECK - jbt - 1/3/06
function clientSubmit(Flag)
	{
		if (document.frmClientInfo.strSSN.value == "")
			{
				alert("You must enter your social security number before you can submit or save data.")
				document.frmClientInfo.strSSN.focus()
			}
		else if (document.frmClientInfo.strClientLName.value == "")
			{
				alert("You must enter your last name before you can submit or save data.")
				document.frmClientInfo.strClientLName.focus()
			}
		else if (document.frmClientInfo.strMaiden.value == "")
			{
				alert("You must enter your Mother's maiden name before you can submit or save data.")
				document.frmClientInfo.strMaiden.focus()
			}
		else if (document.frmClientInfo.strBirthCity.value == "")
			{
				alert("You must enter your city of birth before you can submit or save data.")
				document.frmClientInfo.strBirthCity.focus()
			}
		else
			{	
				if (Flag == "Submit")
					{
						window.document.frmClientInfo.strFlag.value = "Submit"
						window.document.frmClientInfo.submit();
					}
				else if (Flag == "Later")
					{
						window.document.frmClientInfo.strFlag.value = "Later"
						window.document.frmClientInfo.submit();
					}
			}
	}
//
//
function counsSubmit(Flag)
	{
		if (Flag == "Submit")
			{
				window.document.frmCounsClient.strFlag.value = "Submit"
				window.document.frmCounsClient.submit();
			}
		else if (Flag == "Later")
			{
				window.document.frmCounsClient.strFlag.value = "Later"
				window.document.frmCounsClient.submit();
			}
	}	
//
//BUDGET SUBMIT
//
function budgetSubmit(Flag)
	{
		
		if (document.frmBudget.strTotUnSecPay.value < 1 || document.frmBudget.strTotUnSecDebt.value < 1)
			{
				alert("You must enter a balance and payment in unsecured debt to continue.\n\nIf you have NO Credit Card or Unsecured debt, enter $1 in both fields.")
				if(document.frmBudget.strTotUnSecDebt.value < 1)
					{
						document.frmBudget.strTotUnSecDebt.focus()
					}
				else if(document.frmBudget.strTotUnSecPay.value < 1)
					{
						document.frmBudget.strTotUnSecPay.focus()
					}
			}
		else
			{
				if (Flag == "Submit")
					{
						window.document.frmBudget.strFlag.value = "Submit"
						window.document.frmBudget.submit();
					}
				else if (Flag == "Later")
					{
						window.document.frmBudget.strFlag.value = "Later"
						window.document.frmBudget.submit();
					}
			}
	}
//
//CREDITOR LISTING SUBMIT
//
function creditorListingSubmit(Flag)
	{
		
		if (Flag == "Submit")
		{
			window.document.frmCreditorListing.strFlag.value = "Submit"
			window.document.frmCreditorListing.submit();
		}
		else if (Flag == "Later")
		{
			window.document.frmCreditorListing.strFlag.value = "Later"
			window.document.frmCreditorListing.submit();
		}
	}
//
//QUESTIONNAIRE SUBMIT
//
function questionnaireSubmit(Flag)
	{
		var validated = true;
		if (Flag == "Submit")
		{
			// Questions 2 and 3 are required.
			if(window.document.frmQuestionnaire.HardshipCircumstances.value=='')
			{
				validated = false;
				alert('Please fill out the \'Hardship circumstances\' section (question 2) before continuing.')
				window.document.frmQuestionnaire.HardshipCircumstances.focus();
			}
			if(window.document.frmQuestionnaire.BudgetPlan.value=='')
			{
				validated = false;
				alert('Please fill out the \'Budget plan\' section (question 3) before continuing.')
				window.document.frmQuestionnaire.BudgetPlan.focus();
			}
			if (validated)
			{
				window.document.frmQuestionnaire.strFlag.value = "Submit"
				window.document.frmQuestionnaire.submit();
			}
		}
		else if (Flag == "Later")
		{
			window.document.frmQuestionnaire.strFlag.value = "Later"
			window.document.frmQuestionnaire.submit();
		}
	}
//
//EditACH SUBMIT
//
function editACHSubmit(Flag)
	{
		var validated = true;
		if (Flag == "Submit")
		{
			// ACH, Account Number, and Amount are required.
			if(window.document.frmEditACH.txtABA.value=='')
			{
				validated = false;
				alert('The ABA (Routing #) value is required. Please type in a value before continuing.')
				window.document.frmEditACH.txtABA.focus();
			}
			if(window.document.frmEditACH.txtAccountNo.value=='')
			{
				validated = false;
				alert('The Account Number value is required. Please type in a value before continuing.')
				window.document.frmEditACH.txtAccountNo.focus();
			}
			if(window.document.frmEditACH.txtFee.value=='')
			{
				validated = false;
				alert('The Payment amount is required. Please type in a value before continuing.')
				window.document.frmEditACH.txtFee.focus();
			}
			if (validated)
			{
				//window.document.frmEditACH.strFlag.value = "Submit"
				window.document.frmEditACH.submit();
			}
		}
	}
//
//ATTY INFO/EDIT SUBMIT
//
function attySubmit(Flag)
	{
		if (Flag == "Submit")
			{
				window.document.frmAttyList.strFlag.value = "Submit"
				window.document.frmAttyList.submit();
			}
	}
//
//ATTY INFO/EDIT SUBMIT
//
function attyESubmit(Flag)
	{
		if (Flag == "Submit")
			{
				window.document.frmAttyEdit.strFlag.value = "Submit"
				window.document.frmAttyEdit.submit();
			}
	}	
//
//CheckNum
//Forces a number to be entered
//Prevent type mismatch
//
function CheckNum(field)
	{
		if (isNaN(field.value) || field.value == "")
			{
				alert("You must enter a number");
				field.value = 0
				field.focus();
				field.select();
			}
	}
//
//CheckNum_NotReq
//Forces a number to be entered
//Prevent type mismatch
//
function CheckNum_NotReq(field)
	{
		if(field.value!="")
			{
				if (isNaN(field.value))
					{
						alert("You must enter a number");
						field.value = 0
						field.focus();
						field.select();
					}
			}
	}
//
//CheckCurr_NotReq
//If there is a value, make sure it's a number and formatted as currency
//
function CheckCurr_NotReq(field)
	{
		field.value=scrubComma(field.value);
		if(field.value!="")
			{		
				if (isNaN(field.value))
					{
						alert("Please enter a number.");
						field.value="0.00";
						field.focus();
						field.select();
					}
				else
					{
						field.value = formatCur(field.value);
					}
			}
	}
//
//TOTAL INCOME
//
function totIncome(field)
	{
	field.value=scrubComma(field.value);
		if(field.value=="")
			{
				field.value="0.00";
			}
	
		if (field.value > 9999)
			{
				alert("The amount you entered is a significant amount.\nMake sure you are entering your MONTHLY income.");//JBT ADDED 06/15/04 TO PREVENT CLIENT 
			}                                                        //FROM ENTERING ANNUAL AMOUNTS ********
	
		if (isNaN(field.value)||field.value<0)
			{
				alert("Please enter a number.");
				field.value="0.00";
				field.focus();
			}
		else
			{
				field.value = formatCur(field.value);
				var Income = eval(document.frmBudget.strIncome.value);
				var CoIncome = eval(document.frmBudget.strCoIncome.value);
				var Retire = eval(document.frmBudget.strRetire.value);  
				var SocSec = eval(document.frmBudget.strSocSec.value);
				var ChildSupIn = eval(document.frmBudget.strChildSupIn.value);
				var AFDC = eval(document.frmBudget.strAFDC.value);
				var Stamps = eval(document.frmBudget.strStamps.value);
				var Misc = eval(document.frmBudget.strMiscIn.value);
				document.frmBudget.strTotIncome.value = formatCur(fRound(Income + CoIncome + Retire + SocSec + ChildSupIn + AFDC + Stamps + Misc));
				document.frmBudget.strTotIncomeVar.value = formatCur(fRound(Income + CoIncome + Retire + SocSec + ChildSupIn + AFDC + Stamps + Misc));
			}
	}
//
//TOTAL EXPENES
//
function totExp(field)
	{	
		field.value=scrubComma(field.value);
		if(field.value=="")
			{
				field.value="0.00";
			}
		
		if (isNaN(field.value)||field.value<0)
			{			
				alert("Please enter a number.");
				field.value="0.00";
				field.focus();
			}
		else
			{
				field.value = formatCur(field.value);
				var strRent = eval(document.frmBudget.strRent.value);
				var strMortgage = eval(document.frmBudget.strMortgage.value);
				var strCar = eval(document.frmBudget.strCarPay.value);
				var strCarMaintenance = eval(document.frmBudget.strCarMaint.value);
				var strHousehold = eval(document.frmBudget.strFood.value);
				var strMedicalExpense = eval(document.frmBudget.strMedEx.value);
				var strChildCare = eval(document.frmBudget.strDayCare.value);
				var strChildSupport = eval(document.frmBudget.strChildSupEx.value);
				var strGas = eval(document.frmBudget.strGas.value);
				var strElectric = eval(document.frmBudget.strElectric.value);
				var strWater = eval(document.frmBudget.strWater.value);
				var strPhoneExp = eval(document.frmBudget.strPhone.value);
				var strCell = eval(document.frmBudget.strCell.value);
				var strLifeIns = eval(document.frmBudget.strLifeIns.value);
				var strHomeIns = eval(document.frmBudget.strHomeIns.value);
				var strAutoIns = eval(document.frmBudget.strAutoIns.value);
				var strMedicalIns = eval(document.frmBudget.strMedIns.value);
				var strClothes = eval(document.frmBudget.strClothes.value);
				var strFurnish = eval(document.frmBudget.strFurnish.value);
				var strHouseMaint = eval(document.frmBudget.strHouseMaint.value);
				var strCarTax = eval(document.frmBudget.strCarTax.value);
				var strPet = eval(document.frmBudget.strPet.value);
				var strTuition = eval(document.frmBudget.strTuition.value);
				var strDonations = eval(document.frmBudget.strDonations.value);
				var strDisbIns = eval(document.frmBudget.strDisbIns.value);
				var strOtherIns = eval(document.frmBudget.strOtherIns.value);
				var strMiscExp = eval(document.frmBudget.strMiscEx.value);
				
				// Added by JDH - May, 2007
				var strCable = eval(document.frmBudget.strCable.value);
				var strEntertainment = eval(document.frmBudget.strEntertainment.value);
				var strGifts = eval(document.frmBudget.strGifts.value);
				
				var strTotSecuredPayment = eval(document.frmBudget.strTotSec.value);
				document.frmBudget.strTotExpenses.value = formatCur(fRound(strRent + strMedicalExpense + strLifeIns + strMortgage + strAutoIns + strCar + strHomeIns + strCarMaintenance + strMedicalIns + strHousehold + strGas + strChildSupport + strElectric + strChildCare + strWater + strMiscExp + strCell + strPhoneExp + strHouseMaint + strCarTax + strTuition + strPet + strDonations + strOtherIns + strDisbIns + strClothes + strFurnish + strCable + strEntertainment + strGifts));
				document.frmBudget.strTotSec.value = formatCur(fRound(strMortgage + strCar));
			}
	}
//
//TOT UNSEC DEBT
//
function totUnSec(field)
	{	
		field.value=scrubComma(field.value);
		if(field.value=="")
			{
				field.value="0.00";
			}
		if (isNaN(field.value)||field.value<0)
			{			
				alert("Please enter a number.");
				field.value="0.00";
				field.focus();
			}
		else
			{
				field.value=formatCur(field.value);
				var totUnSecDebt = eval(document.frmBudget.strTotUnSecDebt.value);
				var totUnSecPay = eval(document.frmBudget.strTotUnSecPay.value);
				var totSecPay = eval(document.frmBudget.strTotSec.value);
				var totExp = eval(document.frmBudget.strTotExpenses.value);
				var totIn = eval(document.frmBudget.strTotIncome.value);
				document.frmBudget.strTotUnSec.value = formatCur(fRound(totUnSecPay));
				document.frmBudget.strTotSec.value = formatCur(fRound(totSecPay));
				document.frmBudget.strTotExp.value = formatCur(fRound(totExp - totSecPay));
				document.frmBudget.strTotDebt.value = formatCur(fRound(totUnSecPay + totExp));
				document.frmBudget.strTotDebtVar.value = formatCur(fRound(totUnSecPay + totExp));
				document.frmBudget.strIncomeVar.value = formatCur(fRound(totIn) - (totUnSecPay + totExp));
			}
	}				
//
//FORMAT CURRENCY
//
function formatCur(value)
	{
		value=value.toString();
		var flag=0;
		///////////////removes leading zeros////////////////////
		while (flag==0)
			{
		//	if(value.substr(0,1)=="0" && value != "0.00"){
			if(value.substr(0,1)=="0" && value.substr(0,2)!="0.")
				{
					value=value.substring(1);
				}
			else
				{
					flag=1;
				}
			}
		////////////////adds decimal///////////////////////////
		if(value.indexOf(".")<0)
			{
			value=value+".00";
			}
		else
			{
				if(value.indexOf(".")==(value.length-1))
					{
						value=value+"00";
					}
				else
					{
						if(value.indexOf(".")==(value.length-2))
							{
								value=value+"0";
							}
						else
							{
								if(eval(value.indexOf("."))<eval(value.length-3))
									{	
										alert("Check your decimal.");
									}
							}
					}
			}
		if (eval(value) == 0)
			{
				value = "0.00";
			}
		return value;
	}
//
//ROUND
//
function fRound(num)
	{
		var temp;
		temp = eval(num)*100;
		temp=Math.round(eval(temp));
		return eval(temp)/100;
	}	
//
// SCRUB COMMA
//
function scrubComma(strData){
	var strTemp, i, intLength;
	strTemp = "";
	intLength = strData.length;
	if (intLength > 0) {
		for (i = 0; i< intLength;i++){
			if (strData.substr(i, 1) != ",") {
				strTemp = strTemp + strData.substr(i,1);
			}
		}
	}
	return strTemp;
}
//
function checkNum(num)
	{
		if (!isNaN(num))
			{
				if (num.length==9)
					{
						var count,rndTot;
						var total=0;
						var digit = new Array(9);
						for (count=0;count<9;count++)
							{	
								digit[count] = num.substr(count,1);
							}

						total=eval(digit[0])*3;
						eval(total+= digit[1]*7);
						eval(total+=digit[2]*1);
						eval(total+=digit[3]*3);
						eval(total+=digit[4]*7);
						eval(total+=digit[5]*1);
						eval(total+=digit[6]*3);
						eval(total+=digit[7]*7);
					
						if (eval(digit[8])==eval((Math.round((total+4)/10))*10-total))
							return true;
						else
							return false;
					}
			}
}
//
function getACH()
	{
		//window.location = "SaveACH_TXT.asp"
		//alert(" *** This area has been disabled. - Contact Jeff *** ");
		window.open("ftp://abcs@ftp.40debts.org/")
	}
//
//USED TO SET VALUE TO Agreement CHECKBOX AND THEN SUBMIT
function checkSigned()
	{
		if (document.frmAgreement.Agree.checked)
			{
				document.frmAgreement.Agree.value = "T"
				document.frmAgreement.submit()
			}
		else
			{
				window.location = "Agreement.asp?ID=NotSigned"
			}
	}
//
//USED TO SET VALUE TO Agreement & CoAgreement CHECKBOX AND THEN SUBMIT
function checkCoSigned()
	{
		if (document.frmAgreement.Agree.checked && document.frmAgreement.CoAgree.checked)
			{
				document.frmAgreement.Agree.value = "T"
				document.frmAgreement.CoAgree.value = "T"
				document.frmAgreement.submit()
			}
		else
			{
				window.location = "Agreement.asp?ID=NotSigned"
			}
	}
//
//MAKES SURE ACHAuth CKECKED - 'Signed'
//SETS THE VALUE OF ACHAuth TO "T" AND Submits
function ACHAgree()
	{
		if (document.frmACH.strACHAuth.checked && document.frmACH.strABA.value != "" && document.frmACH.strAccountNum.value != "" && document.frmACH.strACHLName.value != "" && document.frmACH.strACHFName != "")
			{
				document.frmACH.strACHAuth.value = "T"
				document.frmACH.submit()
			}
		else
			{
				if (!(document.frmACH.strACHAuth.checked))
					{
						alert("You must check the 'I Agree' checkbox in order to continue!\nBy checking this checkbox you are authorizing ABCS to Debit your bank account.");
						document.frmACH.strACHAuth.focus();
					}
				else if (document.frmACH.strACHFName.value == "")
					{
						alert("You must include the first name of the bank account holder.");
						document.frmACH.strACHFName.focus();
					}
				else if (document.frmACH.strACHLName.value == "")
					{
						alert("You must include the last name of the bank account holder.");
						document.frmACH.strACHLName.focus();
					}
				else if (document.frmACH.strAccountNum.value == "")
					{
						alert("You must include your Account Number.");
						document.frmACH.strAccountNum.focus();
					}
				else if (document.frmACH.strABA.value == "")
					{
						alert("You must include a routing number.\nIf you need help finding your routing number click 'NeedHelp'.");
						document.frmACH.strABA.focus();
					}
			}
	}
//
//
function formatPhone(strNum)
	{
		if (strNum.value != "")
			{
			
				var i, strTemp
				strTemp = ""

				//REMOVE DASHES AND PARENTHS IF ANY
				for (i=0; i<strNum.value.length; i++)
					{
						if (strNum.value.substr(i, 1) != "-" && strNum.value.substr(i, 1) != "(" && strNum.value.substr(i, 1) != ")")
							{
								strTemp = strTemp + strNum.value.substr(i, 1)
							}
					}
				//REASSIGN VALUE TO strNum
				strNum.value = strTemp
				
//			
				//MAKE SURE 10 DIGIT PHONE NUMBER - (AREA CODE)
				if (strNum.value.length < 10)
					{
						alert("You must include area code when entering a phone number.");
						strNum.focus()
					}
			  else
					{
						strNum.value = (strNum.value.substr(0,3) + "-" + strNum.value.substr(3,3) + "-" + strNum.value.substr(6,4))
					}
					
			}//IF VALUE != ""
	}