// JavaScript Document
	function PadFront(s,n){
	// Pad the front of s with zeros until the length equals n
	// s is a string of characters.
	// n is the minimum length for the string.
	// If s is already of length n or longer, nothing is changed.
	while((s.value).length < n) { s.value = '0' + s.value; }
	return s;
	}
	function isEmailAddr(email)
	{
	  var result = false;
	  var theStr = new String(email);
	  var index = theStr.indexOf("@");
	  if (index > 0)
	  {
		 var pindex = theStr.indexOf(".",index);
		 if ((pindex > index+1) && (theStr.length > pindex+1))
		result = true;
	  }
	  return result;
	}
	function validRequired(formField,fieldLabel,type)
	{
		var result = true;

		if ( (type == "1" && formField.value == "") || (type == "0" && formField.value == "0") )
		{
			alert('Please enter a value for the "' + fieldLabel +'" field.');
			formField.focus();
			result = false;
		}

		return result;
	}
	function allDigits(str)
	{
		return inValidCharSet(str,"0123456789");
	}
	function inValidCharSet(str,charset)
	{
		var result = true;

		// Note: doesn't use regular expressions to avoid early Mac browser bugs
		for (var i=0;i<str.length;i++)
			if (charset.indexOf(str.substr(i,1))<0)
			{
				result = false;
				break;
			}

		return result;
	}
	function validEmail(formField,fieldLabel,required)
	{
		var result = true;

		if (required && !validRequired(formField,fieldLabel,'1'))
			result = false;

		if (result && ((formField.value.length < 3) || !isEmailAddr(formField.value)) )
		{
			alert("Please enter a complete email address in the form: yourname@yourdomain.com");
			formField.focus();
			result = false;
		}

	  return result;

	}
	function validDate(formField,fieldLabel,required)
	{
		var result = true;

		if (required && !validRequired(formField,fieldLabel,'1'))
			result = false;

		if (result)
		{
			var elems = formField.value.split("/");

			result = (elems.length == 3); // should be three components

			if (result)
			{
				var month = parseInt(elems[0],10);
				var day = parseInt(elems[1],10);
				var year = parseInt(elems[2],10);
				result = allDigits(elems[0]) && (month > 0) && (month < 13) &&
						 allDigits(elems[1]) && (day > 0) && (day < 32) &&
						 allDigits(elems[2]) && ((elems[2].length == 2) || (elems[2].length == 4));
			}

			if (!result)
			{
				alert('Please enter a date in the format MM/DD/YYYY for the "' + fieldLabel +'" field.');
				formField.focus();
			}
		}

		return result;
	}
	function validNum(formField,fieldLabel,required)
	{
		var result = true;

		if (required && !validRequired(formField,fieldLabel,"1"))
			result = false;

		if (result)
		{
			if (!allDigits(formField.value))
			{
				alert('Please enter a number for the "' + fieldLabel +'" field.');
				formField.focus();
				result = false;
			}
		}

		return result;
	}
	function validateForm(theForm)
	{
		if (!validNum(theForm.appamount,"Amount of Loan",true)) return false;
		if ( parseFloat(theForm.appamount.value) < 500 || parseFloat(theForm.appamount.value) > 100000 )
		{
			alert("The Loan Amount must be GREATER than $500 and LESS than $100,000!");
			return false;
		}
		if (!validRequired(theForm.appdocstate,"State Services Performed","1")) return false;
		if ( (theForm.appdocfk.value == "0") && (theForm.docrequired.value == "1") )
		{
			if (!validRequired(theForm.appdocpractice,"Doctor Name","1")) return false;
		}
		if (!validRequired(theForm.appfname,"First Name","1")) return false;
		if (!validRequired(theForm.applname,"Last Name","1")) return false;
		if (!validRequired(theForm.appmaiden,"Mothers Maiden Name","1")) return false;
		if (!validNum(theForm.appssn1,"SSN",true)) return false;
		if (!validNum(theForm.appssn2,"SSN",true)) return false;
		if (!validNum(theForm.appssn3,"SSN",true)) return false;
		//if ( (parseInt(theForm.appssn1.value) < 100) || (parseInt(theForm.appssn2.value) < 10) || (parseInt(theForm.appssn3.value) < 1000) )
		if ( ((theForm.appssn1.value).length < 3) || ((theForm.appssn2.value).length < 2) || ((theForm.appssn3.value).length < 4) )
		{
			alert("Invalid SSN Number!  Must be in the format of ###-##-####");
			return false;
		}
		if (!validNum(theForm.appdob1,"Date of Birth",true)) return false;
		if (!validNum(theForm.appdob2,"Date of Birth",true)) return false;
		if (!validNum(theForm.appdob3,"Date of Birth",true)) return false;
		if ( (parseFloat(theForm.appdob1.value) < 1) || (parseFloat(theForm.appdob1.value) > 12) ||
			  (parseFloat(theForm.appdob2.value) < 1) || (parseFloat(theForm.appdob2.value) > 31) ||
			  (parseFloat(theForm.appdob3.value) < 1900) || (parseFloat(theForm.appdob3.value) > 2004) )
		{
			alert("Invalid Date of Birth!");
			return false;
		}
		if ( checkAge(parseFloat(theForm.appdob3.value), parseFloat(theForm.appdob1.value), parseFloat(theForm.appdob2.value) ) < 18 )
		{
			alert("You must be 18 years old!");
			return false;
		}
		if (!validEmail(theForm.appemail,"Email Address",true)) return false;
		if (!validRequired(theForm.appaddress1,"Address","1")) return false;
		if ( ((theForm.appaddress1.value).toUpperCase().indexOf("PO BOX") >= 0) ||
			  ((theForm.appaddress1.value).toUpperCase().indexOf("P.O. BOX") >= 0) ||
			  ((theForm.appaddress1.value).toUpperCase().indexOf("POBOX") >= 0) ||
			  ((theForm.appaddress1.value).toUpperCase().indexOf("P.O.BOX") >= 0) )
		{
			alert("Address cannot contain a PO Box!");
			return false;
		}
		if (!validRequired(theForm.appcity,"City","1")) return false;
		if (!validRequired(theForm.appstate,"State","1")) return false;
		if (!validNum(theForm.appzip,"Zip","1")) return false;
		if (!validNum(theForm.apptimeyears,"Time at Current Address - Years","1")) return false;
		if (!validNum(theForm.apptimemonths,"Time at Current Address - Months","1")) return false;
		if ( (parseFloat(theForm.apptimeyears.value) < 2) || (((parseFloat(theForm.apptimeyears.value) * 12) + parseFloat(theForm.apptimemonths.value)) < 24) )
		{
			if (!validRequired(theForm.appprevaddress,"Previous Address","1")) return false;
			if ( ((theForm.appprevaddress.value).toUpperCase().indexOf("PO BOX") >= 0) ||
				  ((theForm.appprevaddress.value).toUpperCase().indexOf("P.O. BOX") >= 0) ||
				  ((theForm.appprevaddress.value).toUpperCase().indexOf("POBOX") >= 0) ||
				  ((theForm.appprevaddress.value).toUpperCase().indexOf("P.O.BOX") >= 0) )
			{
				alert("Previous Address cannot contain a PO Box!");
				return false;
			}
			if (!validRequired(theForm.appprevcity,"Previous City","1")) return false;
			if (!validRequired(theForm.appprevstate,"Previous State","1")) return false;
			if (!validNum(theForm.appprevzip,"Previous Zip","1")) return false;
			if (!validNum(theForm.appprevtimeyears,"Time at Previous Address - Years","1")) return false;
			if (!validNum(theForm.appprevtimemonths,"Time at Previous Address - Months","1")) return false;
		}
		if (!validNum(theForm.apphousingcost,"Monthly Rent/Mortgage","1")) return false;
		if (!validNum(theForm.apphomephone1,"Home Phone",true)) return false;
		if (!validNum(theForm.apphomephone2,"Home Phone",true)) return false;
		if (!validNum(theForm.apphomephone3,"Home Phone",true)) return false;
		//if ( (parseInt(theForm.apphomephone1.value) < 100) || (parseInt(theForm.apphomephone2.value) < 100) || (parseInt(theForm.apphomephone3.value) < 1000) )
		if ( ((theForm.apphomephone1.value).length < 3) || ((theForm.apphomephone2.value).length < 3) || ((theForm.apphomephone3.value).length < 4) )
		{
			alert("Invalid Home Phone Number!  Must be in the format of ###-###-####");
			return false;
		}
		if ( ((theForm.appaltphone1.value).length > 0) || ((theForm.appaltphone2.value).length > 0) || ((theForm.appaltphone3.value).length > 0) )
		{
			if (!validNum(theForm.appaltphone1,"Alternate/Cell Phone",true)) return false;
			if (!validNum(theForm.appaltphone2,"Alternate/Cell Phone",true)) return false;
			if (!validNum(theForm.appaltphone3,"Alternate/Cell Phone",true)) return false;
			if ( ((theForm.appaltphone1.value).length < 3) || ((theForm.appaltphone2.value).length < 3) || ((theForm.appaltphone3.value).length < 4) )
			{
				alert("Invalid Alternate/Cell Number!  Must be in the format of ###-###-####");
				return false;
			}
		}
		if (!validRequired(theForm.appempname,"Employer Name","1")) return false;
		if (!validRequired(theForm.appposition,"Position","0")) return false;
		if (!validNum(theForm.appincome,"Income","1")) return false;
		if (!validRequired(theForm.appbusaddress,"Employer Address","1")) return false;
		if ( ((theForm.appbusaddress.value).toUpperCase().indexOf("PO BOX") >= 0) ||
			  ((theForm.appbusaddress.value).toUpperCase().indexOf("P.O. BOX") >= 0) ||
			  ((theForm.appbusaddress.value).toUpperCase().indexOf("POBOX") >= 0) ||
			  ((theForm.appbusaddress.value).toUpperCase().indexOf("P.O.BOX") >= 0) )
		{
			alert("Employer Address cannot contain a PO Box!");
			return false;
		}
		if (!validRequired(theForm.appbuscity,"Employer City","1")) return false;
		if (!validRequired(theForm.appbusstate,"Employer State","1")) return false;
		if (!validNum(theForm.appbuszip,"Employer Zip","1")) return false;
		if (!validNum(theForm.appbusphone1,"Business Phone",true)) return false;
		if (!validNum(theForm.appbusphone2,"Business Phone",true)) return false;
		if (!validNum(theForm.appbusphone3,"Business Phone",true)) return false;
		//if ( (parseInt(theForm.appbusphone1.value) < 100) || (parseInt(theForm.appbusphone2.value) < 100) || (parseInt(theForm.appbusphone3.value) < 1000) )
		if ( ((theForm.appbusphone1.value).length < 3) || ((theForm.appbusphone2.value).length < 3) || ((theForm.appbusphone3.value).length < 4) )
		{
			alert("Invalid Business Phone Number!  Must be in the format of ###-###-####");
			return false;
		}
		if (!validNum(theForm.appemptimeyears,"Time at Current Employer - Years","1")) return false;
		if (!validNum(theForm.appemptimemonths,"Time at Current Employer - Months","1")) return false;
		if ( (parseFloat(theForm.appemptimeyears.value) < 2) || (((parseFloat(theForm.appemptimeyears.value) * 12) + parseFloat(theForm.appemptimemonths.value)) < 24) )
		{
			if (!validRequired(theForm.appprevemployer,"Previous Employer","1")) return false;
			if (!validRequired(theForm.appprevposition,"Previous Position","0")) return false;
			if (!validRequired(theForm.appprevempaddress,"Employer Address","1")) return false;
			if ( ((theForm.appprevempaddress.value).toUpperCase().indexOf("PO BOX") >= 0) ||
				  ((theForm.appprevempaddress.value).toUpperCase().indexOf("P.O. BOX") >= 0) ||
				  ((theForm.appprevempaddress.value).toUpperCase().indexOf("POBOX") >= 0) ||
				  ((theForm.appprevempaddress.value).toUpperCase().indexOf("P.O.BOX") >= 0) )
			{
				alert("Previous Employer Address cannot contain a PO Box!");
				return false;
			}
			if (!validRequired(theForm.appprevempcity,"Previous Employer City","1")) return false;
			if (!validRequired(theForm.appprevempstate,"Previous Employer State","1")) return false;
			if (!validNum(theForm.appprevempzip,"Previous Employer Zip","1")) return false;
			if (!validNum(theForm.appprevemptimeyears,"Time at Previous Employer - Years","1")) return false;
			if (!validNum(theForm.appprevemptimemonths,"Time at Previous Employer - Months","1")) return false;
		}
		if ( theForm.appbankruptcy.value == "1" )
		{
			if (!validNum(theForm.appbankruptcymonth,"Bankruptcy Month",true)) return false;
			if (!validNum(theForm.appbankruptcyyear,"Bankruptcy Year",true)) return false;
			if ( parseInt(theForm.appbankruptcymonth.value) > 12 || parseInt(theForm.appbankruptcymonth.value) < 1 )
			{
				alert("The Bankruptcy month must be between 1 and 12!");
				return false;
			}
			if ( parseInt(theForm.appbankruptcyyear.value) > 2004 || parseInt(theForm.appbankruptcyyear.value) < 1900 )
			{
				alert("The Bankruptcy year is invalid!");
				return false;
			}
			if (!validRequired(theForm.appbankruptcystatus,"Bankruptcy Status","0")) return false;
			if ( theForm.appbankruptcystatus.value == "1" )
			{
				alert("Bankruptcy Status cannot be UNRESOLVED!");
				return false;
			}
		}
		if ( theForm.appcollateral.value == "1" )
		{
			if (!validNum(theForm.apppropertyvalue,"Estimated Property Value",true)) return false;
			if (!validNum(theForm.appmortgagebalance,"Current Mortgage Balance",true)) return false;
		}
	}
   function setEmail()
   {
      if ( document.appform.noemail.value = 'True' )
      	{
      		document.appform.appemail.value = 'unknown@unknown.com';
      	}
      	else
      	{
      		document.appform.appemail.value = '';
      	}

   }
   var field_length = '';
	function nextField(obj, event, len, next_field)
	{
		if (event == "down")
		{
			 field_length=obj.value.length;
		}
		else if (event == "up")
		{
			 if (obj.value.length != field_length)
			 {
				  field_length=obj.value.length;

				  if (field_length == len)
						next_field.focus();
			 }
		}
	}
	var prefix="$"
	var wd
	function makeCurrency(thisone)
	{
		//if (thisone.charAt(0)=="$")
		//{
		//	return;
		//}
		//alert(thisone);
		wd="w";
		var tempnum=thisone.toString();
		for (i=0;i<tempnum.length;i++)
		{
			if (tempnum.charAt(i)==".")
			{
				wd="d";
				break;
			}
		}
		if (wd=="w")
		{
			//thisone=prefix+tempnum+".00";
			return (prefix+tempnum+".00");
		}
		else
		{
			if (tempnum.charAt(tempnum.length-2)==".")
			{
				//thisone=prefix+tempnum+"0";
				return (prefix+tempnum+"0");
			}
			else
			{
				tempnum=Math.round(tempnum*100)/100;
				//thisone=prefix+tempnum;
				return (prefix+tempnum);
			}
		}
	}
	function checkAge(yr, mon, day)
	{
		dd = day;
		mm = mon;
		yy = yr;

		days = new Date();
		gdate = days.getDate();
		gmonth = days.getMonth();
		gyear = days.getYear();
		if (gyear < 2000) gyear += 1900;
		age = gyear - yy;
		if ((mm == (gmonth + 1)) && (dd <= parseInt(gdate))) {
		age = age;
		} else {
		if (mm <= (gmonth)) {
		age = age;
		} else {
		age = age - 1;
			}
		}
		if (age == 0)
		age = age;
		//alert("You are " + age+ " years old . . .\n\n");
		return age;
	}
