// JavaScript Document
var decimalPointDelimiter = "."
var defaultEmptyOK = false
var whitespace = " \t\n\r";
var digitsInZIPCode1 = 5
var digitsInZIPCode2 = 9

function isEmpty(s)
{   return ((s == null) || (s.length == 0))

}

function isWhitespace (s)

{   var i;

    // Is s empty?
    if (isEmpty(s)) return true;

    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);

        if (whitespace.indexOf(c) == -1) return false;
    }

    // All characters are whitespace.
    return true;
}

function isEmail (s)
{   if (isEmpty(s)) 
       if (isEmail.arguments.length == 1) return defaultEmptyOK;
       else return (isEmail.arguments[1] == true);
   
    // is s whitespace?
    if (isWhitespace(s)) return false;
    
    // there must be >= 1 character before @, so we
    // start looking at character position 1 
    // (i.e. second character)
    var i = 1;
    var sLength = s.length;

    // look for @
    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    // look for .
    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }
     // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
      else return true;
}

function isFloat (s)

{   var i;
    var seenDecimalPoint = false;

    if (isEmpty(s)) 
       if (isFloat.arguments.length == 1) return defaultEmptyOK;
       else return (isFloat.arguments[1] == true);

    if (s == decimalPointDelimiter) return false;

    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);

        if ((c == decimalPointDelimiter) && !seenDecimalPoint) seenDecimalPoint = true;
        else if (!isDigit(c)) return false;
    }

    // All characters are numbers.
    return true;
}

function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}

function isZIPCode (s)
{  if (isEmpty(s)) 
       if (isZIPCode.arguments.length == 1) return defaultEmptyOK;
       else return (isZIPCode.arguments[1] == true);
   return (isInteger(s) && 
            ((s.length == digitsInZIPCode1) ||
             (s.length == digitsInZIPCode2)))
}


function isInteger (s)

{   var i;

    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isInteger.arguments[1] == true);

    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);

        if (!isDigit(c)) return false;
    }

    // All characters are numbers.
    return true;
}

//Calculates Total of Assets 
function calAssetsTotal()
{	
	var txtAsset, total_asset=0, total_liab=0;
	for(var i=1;i<=8;i++)
	{
		textid = "asset" + i;
		txtAsset = document.getElementById(textid).value
		if(isInteger (txtAsset))
			total_asset = total_asset + parseInt(txtAsset);
		else
		{
			if(!isEmpty(txtAsset))
			{
				alert("Asset must be Numeric")
				document.getElementById(textid).value = 0
				theForm.textid.focus()
			}
		}
	}
	document.getElementById('tot_asset').value = total_asset;
	total_liab=document.getElementById('tot_liab').value
	document.getElementById('net_worth').value = total_asset - total_liab;
}

//Calculates Total of Liabilties
function calLiabilitiesTotal()
{	
	var txtLiab, total_liab=0, total_asset=0;
	for(var i=1;i<=7;i++)
	{
		textid="liab" + i;
		txtLiab = document.getElementById(textid).value
		if(isInteger (txtLiab))
			total_liab = total_liab + parseInt(txtLiab);
		else
		{
			if(!isEmpty(txtLiab))
			{
				alert("Liability must be Numeric")
				document.getElementById(textid).value = 0
				theForm.textid.focus()
			}
		}
	}
	document.getElementById('tot_liab').value = total_liab;
	total_asset=document.getElementById('tot_asset').value
	document.getElementById('net_worth').value = total_asset - total_liab;
}

function checkValues(radioName)
{
var radioBtns = document.getElementsByTagName('input');
var checked = false;
for(ctr = 0; ctr < radioBtns.length; ctr++)
	{
	if(radioBtns[ctr].name == radioName)
		{
		if(radioBtns[ctr].checked == true)
			{
			return true;
			}
		}
	}
return false;
}

function validator(theForm)
{	
	if(theForm.fname.value =="")
	{
		alert("Please enter your First Name.");
		theForm.fname.focus();
		return(false);
	}
	if(theForm.lname.value =="")
	{
		alert("Please enter your Last Name.");
		theForm.lname.focus();
		return(false);
	}
	if(theForm.resAddr.value =="")
	{
		alert("Please enter your Residential Address.");
		theForm.resAddr.focus();
		return(false);
	}
	if(theForm.citizen.selectedIndex==0)
	{
		alert("Please enter your Citizenship.");
		theForm.citizen.focus();
		return(false);
	}
	if(theForm.country.selectedIndex==0)
	{
		alert("Please enter your Country");
		theForm.country.focus();
		return(false);
	}
	if(theForm.state.value =="")
	{
		alert("Please enter your state");
		theForm.state.focus();
		return(false);
	}
	if(theForm.city.value =="")
	{
		alert("Please enter your City");
		theForm.city.focus();
		return(false);
	}
	
	if(theForm.zip.value =="")
	{
		alert("Please enter your Zip code / Postal code.");
		theForm.zip.focus();
		return(false);
	}
	if(theForm.month.selectedIndex ==0)
	{
		alert("Please enter your Month of Birth.");
		theForm.month.focus();
		return(false);
	}
	if(theForm.day.selectedIndex ==0)
	{
		alert("Please enter your Day of Birth.");
		theForm.day.focus();
		return(false);
	}
	if(theForm.year.selectedIndex ==0)
	{
		alert("Please enter your Year of Birth.");
		theForm.year.focus();
		return(false);
	}
	//E-mail id validation	
	if (theForm.email.value == "")
	{
	   alert("Please enter your Email-id.");
	   theForm.email.focus();
	   return (false);
	}
    if (!isEmail(theForm.email.value))
    {
		 alert("Your Email ID is not valid.");
		 theForm.email.focus();
		 return false;
  	}
    if (theForm.email.value.length > 50)
    {
       alert("Please enter at most 50 characters in the \"Email-id\" field.");
       theForm.email.focus();
       return (false);
    }
	//
	
	if(theForm.ssn2.value =="")
	{
		alert("Please enter your Home Phone No.");
		theForm.ssn2.focus();
		return(false);
	}
	if(theForm.ssn.value =="")
	{
		alert("Please enter your Social Security No.");
		theForm.ssn.focus();
		return(false);
	}
	
	if(theForm.long.value =="")
	{
		alert("Please enter How long at the current address.");
		theForm.long.focus();
		return(false);
	}
	if(theForm.edulist.selectedIndex==0)
	{
		alert("Please enter your Highest Level of Education.");
		theForm.edulist.focus();
		return(false);
	}
	if(theForm.school1.value =="")
	{
		alert("Please enter your School Name.");
		theForm.school1.focus();
		return(false);
	}
	if(theForm.yr1.value =="")
	{
		alert("Please enter No. of School Years.");
		theForm.yr1.focus();
		return(false);
	}
	if(theForm.gd1.value =="")
	{
		alert("Please enter your Grade/Degree.");
		theForm.gd1.focus();
		return(false);
	}
	if(theForm.yrCompleted1.value =="")
	{
		alert("Please enter Year of Completion.");
		theForm.yrCompleted1.focus();
		return(false);
	}
	if(theForm.dt_avail.value =="")
	{
		alert("Please enter Date available to open Business.");
		theForm.dt_avail.focus();
		return(false);
	}
	if(!checkValues('work'))
	{
		alert("Please select Will you work in the business.");
		document.getElementById('work').focus();
		return false;
	}
	if(theForm.area1.value =="")
	{
		alert("Please enter your Geographical preference.");
		theForm.area1.focus();
		return(false);
	}
	if(!checkValues('store'))
	{
		alert("Please select No. of stores");
		document.getElementById('store').focus();
		return false;
	}
	
	if(!checkValues('law'))
	{
		alert("Please select Are you currently involved in a Law suit.");
		document.getElementById('law').focus();
		return false;
	}
	if(theForm.business.value =="")
	{
		alert("Please enter Have you failed in Business.");
		theForm.business.focus();
		return(false);
	}
	if(!checkValues('owned_frnchise'))
	{
		alert("Please select Have you ever owned a franchised business.");
		document.getElementById('owned_frnchise').focus();
		return false;
	}
	if(theForm.bus_exp.selectedIndex==0)
	{
		alert("Please enter your Business Experience level");
		theForm.bus_exp.focus();
		return(false);
	}
	if(!checkValues('worked_in_store'))
	{
		alert("Please select Have you ever worked in a Faces store.");
		document.getElementById('worked_in_store').focus();
		return false;
	}
	if(!checkValues('emp'))
	{
		alert("Please select your Employment status.");
		document.getElementById('emp').focus();
		return false;
	}
	if(theForm.employer.value =="")
	{
		alert("Please enter your Employer.");
		theForm.employer.focus();
		return(false);
	}
	if(theForm.noyears.value =="")
	{
		alert("Please enter No. of Years of Employment.");
		theForm.noyears.focus();
		return(false);
	}
	if(theForm.busname.value =="")
	{
		alert("Please enter Business Name.");
		theForm.busname.focus();
		return(false);
	}
	if(theForm.busadd.value =="")
	{
		alert("Please enter your business address.");
		theForm.busadd.focus();
		return(false);
	}
	if(theForm.coun2.selectedIndex ==0)
	{
		alert("Please enter Business country.");
		theForm.coun2.focus();
		return(false);
	}
	if(theForm.city2.value =="")
	{
		alert("Please enter Business city.");
		theForm.city2.focus();
		return(false);
	}
	if(theForm.state2.value =="")
	{
		alert("Please enter Business state.");
		theForm.state2.focus();
		return(false);
	}
	if(theForm.zip2.value =="")
	{
		alert("Please enter your Zip / Postal code of Business location.");
		theForm.zip2.focus();
		return(false);
	}
	if(theForm.tel.value =="")
	{
		alert("Please enter your Business Telephone No.");
		theForm.tel.focus();
		return(false);
	}
	if(theForm.income.selectedIndex ==0)
	{
		alert("Please enter your Annual income.");
		theForm.income.focus();
		return(false);
	}
	if(theForm.inst1.value =="")
	{
		alert("Please enter Reference Institute.");
		theForm.inst1.focus();
		return(false);
	}
	if(theForm.add1.value =="")
	{
		alert("Please enter Reference Institute Address.");
		theForm.add1.focus();
		return(false);
	}
	if(theForm.coun11.selectedIndex ==0)
	{
		alert("Please enter your Reference Institute country.");
		theForm.coun11.focus();
		return(false);
	}
	if(theForm.city11.value =="")
	{
		alert("Please enter Reference Institute city.");
		theForm.city11.focus();
		return(false);
	}
	if(theForm.state11.value =="")
	{
		alert("Please enter Reference Institute State.");
		theForm.state11.focus();
		return(false);
	}
	if(theForm.conname1.value =="")
	{
		alert("Please enter Contact name for Reference Institute.");
		theForm.conname1.focus();
		return(false);
	}
	if(theForm.tel1.value =="")
	{
		alert("Please enter Reference Institute Telephone No.");
		theForm.tel1.focus();
		return(false);
	}
	if(theForm.asset1.value == "")
	{
		alert("Please enter your CASH ON HAND & BANK.");
		theForm.asset1.focus();
		return(false);
	}
	if(theForm.asset2.value == "")
	{
		alert("Please enter NOTE DUE TO ME (RECEIVABLES).");
		theForm.asset2.focus();
		return(false);
	}
	if(theForm.asset3.value == "")
	{
		alert("Please enter your CASH VALUE ON INSURANCE(S)");
		theForm.asset3.focus();
		return(false);
	}
	if(theForm.asset4.value == "")
	{
		alert("Please enter your REAL ESTATE");
		theForm.asset4.focus();
		return(false);
	}
	if(theForm.asset5.value == "")
	{
		alert("Please enter your Stocks & Bonds");
		theForm.asset5.focus();
		return(false);
	}
	if(theForm.asset6.value == "")
	{
		alert("Please enter your CASH VALUE OF CAR(S)");
		theForm.asset6.focus();
		return(false);
	}
	if(theForm.asset7.value == "")
	{
		alert("Please enter your 401K, PENSION PLAN");
		theForm.asset7.focus();
		return(false);
	}
	
	if(theForm.liab1.value == "")
	{
		alert("Please enter NOTES PAYABLE TO BANK");
		theForm.liab1.focus();
		return(false);
	}
	if(theForm.liab2.value == "")
	{
		alert("Please enter NOTE & ACCOUNTS PAYABLE");
		theForm.liab2.focus();
		return(false);
	}
	if(theForm.liab3.value == "")
	{
		alert("Please enter LOANS ON LIFE INSURANCE");
		theForm.liab3.focus();
		return(false);
	}
	if(theForm.liab4.value == "")
	{
		alert("Please enter REAL ESTATE MORTGAGE");
		theForm.liab4.focus();
		return(false);
	}
	if(theForm.liab5.value == "")
	{
		alert("Please enter UNPAID TAXES");
		theForm.liab5.focus();
		return(false);
	}
	if(theForm.liab6.value == "")
	{
		alert("Please enter OTHER LOANS");
		theForm.liab6.focus();
		return(false);
	}
	if(theForm.anual_income.value =="")
	{
		alert("Please enter CURRENT ANNUAL INCOME(ALL SOURCES).");
		theForm.anual_income.focus();
		return(false);
	}
	if(theForm.liquid_capital.value =="")
	{
		alert("Please enter Liquid capital available to invest.");
		theForm.liquid_capital.focus();
		return(false);
	}
	if(theForm.date.value =="")
	{
		alert("Please enter Financial Position Above as of (Date) .");
		theForm.date.focus();
		return(false);
	}
	if(!checkValues('partners'))
	{
		alert("Please select Will you have Partners.");
		document.getElementById('partners').focus();
		return false;
	}
	if(theForm.disc.checked == false)
	{
		alert("Please Read the Disclaimer & check the corresponding box.");
		theForm.disc.focus();
		return(false);
	}
	if(theForm.applicant_name.value =="")
	{
		alert("Please enter Applicant Typed Name .");
		theForm.applicant_name.focus();
		return(false);
	}
return(true);
}
