		function pop_menu(page_req)
		{
			switch (page_req)
			{
				// these change location:
				case "":
				case "?page=prequal":
					//document.location.href = "index-old.php"+page_req;
					document.location.href = "index-old.php";
					break;
				// this spawns the popup:
				default:
					page_url = page_req;					
					window.open(page_url,"popwin","width=500,height=550,resizable=no,scrollbars=yes,toolbar=no,menubar=no");
					break;
			}
		}



function e(s) {
	rex=true;
	if (window.RegExp) 
	{
		st="a";ex=new RegExp(st);
		if (st.match(ex)) {
		r1=new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
		r2=new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)\$");
		b=(!r1.test(s)&&r2.test(s));
		}
		else 
		{
			rex=false;
		}
	} 
	else
	{
		rex=false;
	}

	if(!rex) b=(s.indexOf("@")>0 && s.indexOf(".")>0 && s!="" && s!="enter e-mail");
	return (b);
}

function f(h) 
{
	h.focus();
	h.select();
}
function val(fld) 
{
	s=fld.value;
	if(e(s)) 
	{
		if (checkform()) 
		{
		document.Entry.datatype.value = "Todd";
		}
		else 
		{
		//f(fld);
			return false;
		}

		if (clearform()); 
	} 
	else 
	{
		alert("Please include a proper e-mail address, of the form id\@domain.zzz or id\@domain.xx.zzz.");
		document.Entry.Email.focus();
		//f(fld);
		return false;
	}
}




function ltrim(str) { 
	for(var k = 0; k < str.length && isWhitespace(str.charAt(k)); k++);
	return str.substring(k, str.length);
}
function rtrim(str) {
	for(var j=str.length-1; j>=0 && isWhitespace(str.charAt(j)) ; j--) ;
	return str.substring(0,j+1);
}
function trim(str) {
	return ltrim(rtrim(str));
}
function isWhitespace(charToCheck) {
	var whitespaceChars = " \t\n\r\f";
	return (whitespaceChars.indexOf(charToCheck) != -1);
}




function gotFocusHomePhone()
{

	if(trim(document.Entry.HomePhone.value)=="" || trim(document.Entry.HomePhone.value)=="XXXXXXXXXX")	
	{
		document.Entry.HomePhone.value="";
		document.Entry.HomePhone.focus();
	}
}

function lostFocusHomePhone()
{
	if(trim(document.Entry.HomePhone.value)=="")
		document.Entry.HomePhone.value="XXXXXXXXXX";
}


function gotFocusWorkPhone()
{

	if(trim(document.Entry.WorkPhone.value)=="" || trim(document.Entry.WorkPhone.value)=="XXXXXXXXXX")	
	{
		document.Entry.WorkPhone.value="";
		document.Entry.WorkPhone.focus();
	}
}

function lostFocusWorkPhone()
{
	if(trim(document.Entry.WorkPhone.value)=="")
		document.Entry.WorkPhone.value="XXXXXXXXXX";
}


function gotFocusRefTwoPhone()
{

	if(trim(document.Entry.RefTwoPhone.value)=="" || trim(document.Entry.RefTwoPhone.value)=="XXXXXXXXXX")	
	{
		document.Entry.RefTwoPhone.value="";
		document.Entry.RefTwoPhone.focus();
	}
}

function lostFocusRefTwoPhone()
{
	if(trim(document.Entry.RefTwoPhone.value)=="")
		document.Entry.RefTwoPhone.value="XXXXXXXXXX";
}



function gotFocusRefOnePhone()
{

	if(trim(document.Entry.RefOnePhone.value)=="" || trim(document.Entry.RefOnePhone.value)=="XXXXXXXXXX")	
	{
		document.Entry.RefOnePhone.value="";
		document.Entry.RefOnePhone.focus();
	}
}

function lostFocusRefOnePhone()
{
	if(trim(document.Entry.RefOnePhone.value)=="")
		document.Entry.RefOnePhone.value="XXXXXXXXXX";
}



function gotFocusSSNOne()
{

	if(trim(document.Entry.ssn1.value)=="" || trim(document.Entry.ssn1.value)=="XXX")	
	{
		document.Entry.ssn1.value="";
		document.Entry.ssn1.focus();
	}
}

function lostFocusSSNOne()
{
	if(trim(document.Entry.ssn1.value)=="")
		document.Entry.ssn1.value="XXX";
}



function gotFocusSSNTwo()
{

	if(trim(document.Entry.ssn2.value)=="" || trim(document.Entry.ssn2.value)=="XX")	
	{
		document.Entry.ssn2.value="";
		document.Entry.ssn2.focus();
	}
}

function lostFocusSSNTwo()
{
	if(trim(document.Entry.ssn2.value)=="")
		document.Entry.ssn2.value="XX";
}



function gotFocusSSNThree()
{

	if(trim(document.Entry.ssn3.value)=="" || trim(document.Entry.ssn3.value)=="XXXX")	
	{
		document.Entry.ssn3.value="";
		document.Entry.ssn3.focus();
	}
}

function lostFocusSSNThree()
{
	if(trim(document.Entry.ssn3.value)=="")
		document.Entry.ssn3.value="XXXX";
}



function isDigit(c)
{   return ((c >= "0") && (c <= "9"))
}

function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}

function isInteger (s)
{   
	var i,vval;
	vval="";

    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)) 
		{
			vval="True";
			break;
		}
		else
			vval="False";
			
    }

    // All characters are numbers.

	if(vval=="True")
		return true;
	else
		return false;
}



function isChars (s)
{   
	var i,vval;
	vval="";

    if (isEmpty(s)) 
       if (isChars.arguments.length == 1) return defaultEmptyOK;
       else return (isChars.arguments[1] == true);

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);


        if (!isDigit(c)) 
		{
			vval="True";
			break;
		}
		else
			vval="False";
			
    }

    // All characters are numbers.

	if(vval=="True")
		return true;
	else
		return false;
}



function LTrim(str)
{
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(0)) != -1) {

      var j=0, i = s.length;


      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;

      s = s.substring(j, i);
   }
   return s;
}


function RTrim(str)
{
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {

      var i = s.length - 1;      

      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;

      s = s.substring(0, i+1);
   }

   return s;
}

function trim(str)
{   
   return RTrim(LTrim(str));
}



function gotFocusDOBDD()
{

	if(trim(document.Entry.dobdd.value)=="" || trim(document.Entry.dobdd.value)=="DD")	
	{
		document.Entry.dobdd.value="";
		document.Entry.dobdd.focus();
	}
}

function lostFocusDOBDD()
{
	if(trim(document.Entry.dobdd.value)=="")
		document.Entry.dobdd.value="DD";
}



function gotFocusDOBMM()
{

	if(trim(document.Entry.dobmm.value)=="" || trim(document.Entry.dobmm.value)=="MM")	
	{
		document.Entry.dobmm.value="";
		document.Entry.dobmm.focus();
	}
}

function lostFocusDOBMM()
{
	if(trim(document.Entry.dobmm.value)=="")
		document.Entry.dobmm.value="MM";
}



function gotFocusDOBYY()
{

	if(trim(document.Entry.dobyy.value)=="" || trim(document.Entry.dobyy.value)=="YYYY")	
	{
		document.Entry.dobyy.value="";
		document.Entry.dobyy.focus();
	}
}

function lostFocusDOBYY()
{
	if(trim(document.Entry.dobyy.value)=="")
		document.Entry.dobyy.value="YYYY";
}





function gotFocusHireDD()
{

	if(trim(document.Entry.hiredd.value)=="" || trim(document.Entry.hiredd.value)=="DD")	
	{
		document.Entry.hiredd.value="";
		document.Entry.hiredd.focus();
	}
}

function lostFocusHireDD()
{
	if(trim(document.Entry.hiredd.value)=="")
		document.Entry.hiredd.value="DD";
}



function gotFocusHireMM()
{

	if(trim(document.Entry.hiremm.value)=="" || trim(document.Entry.hiremm.value)=="MM")	
	{
		document.Entry.hiremm.value="";
		document.Entry.hiremm.focus();
	}
}

function lostFocusHireMM()
{
	if(trim(document.Entry.hiremm.value)=="")
		document.Entry.hiremm.value="MM";
}



function gotFocusHireYY()
{

	if(trim(document.Entry.hireyy.value)=="" || trim(document.Entry.hireyy.value)=="YYYY")	
	{
		document.Entry.hireyy.value="";
		document.Entry.hireyy.focus();
	}
}

function lostFocusHireYY()
{
	if(trim(document.Entry.hireyy.value)=="")
		document.Entry.hireyy.value="YYYY";
}






function gotFocusPayOneDD()
{

	if(trim(document.Entry.payonedd.value)=="" || trim(document.Entry.payonedd.value)=="DD")	
	{
		document.Entry.payonedd.value="";
		document.Entry.payonedd.focus();
	}
}

function lostFocusPayOneDD()
{
	if(trim(document.Entry.payonedd.value)=="")
		document.Entry.payonedd.value="DD";
}



function gotFocusPayOneMM()
{

	if(trim(document.Entry.payonemm.value)=="" || trim(document.Entry.payonemm.value)=="MM")	
	{
		document.Entry.payonemm.value="";
		document.Entry.payonemm.focus();
	}
}

function lostFocusPayOneMM()
{
	if(trim(document.Entry.payonemm.value)=="")
		document.Entry.payonemm.value="MM";
}



function gotFocusPayOneYY()
{

	if(trim(document.Entry.payoneyy.value)=="" || trim(document.Entry.payoneyy.value)=="YYYY")	
	{
		document.Entry.payoneyy.value="";
		document.Entry.payoneyy.focus();
	}
}

function lostFocusPayOneYY()
{
	if(trim(document.Entry.payoneyy.value)=="")
		document.Entry.payoneyy.value="YYYY";
}




function gotFocusPayTwoDD()
{

	if(trim(document.Entry.paytwodd.value)=="" || trim(document.Entry.paytwodd.value)=="DD")	
	{
		document.Entry.paytwodd.value="";
		document.Entry.paytwodd.focus();
	}
}

function lostFocusPayTwoDD()
{
	if(trim(document.Entry.paytwodd.value)=="")
		document.Entry.paytwodd.value="DD";
}



function gotFocusPayTwoMM()
{

	if(trim(document.Entry.paytwomm.value)=="" || trim(document.Entry.paytwomm.value)=="MM")	
	{
		document.Entry.paytwomm.value="";
		document.Entry.paytwomm.focus();
	}
}

function lostFocusPayTwoMM()
{
	if(trim(document.Entry.paytwomm.value)=="")
		document.Entry.paytwomm.value="MM";
}



function gotFocusPayTwoYY()
{

	if(trim(document.Entry.paytwoyy.value)=="" || trim(document.Entry.paytwoyy.value)=="YYYY")	
	{
		document.Entry.paytwoyy.value="";
		document.Entry.paytwoyy.focus();
	}
}

function lostFocusPayTwoYY()
{
	if(trim(document.Entry.paytwoyy.value)=="")
		document.Entry.paytwoyy.value="YYYY";
}







function gotFocusHomePhone()
{

	if(trim(document.Entry.HomePhone.value)=="" || trim(document.Entry.HomePhone.value)=="##########")	
	{
		document.Entry.HomePhone.value="";
		document.Entry.HomePhone.focus();
	}
}

function lostFocusHomePhone()
{
	if(trim(document.Entry.HomePhone.value)=="")
		document.Entry.HomePhone.value="##########";
}


function gotFocusCellPhone()
{

	if(trim(document.Entry.CellPhone.value)=="" || trim(document.Entry.CellPhone.value)=="##########")	
	{
		document.Entry.CellPhone.value="";
		document.Entry.CellPhone.focus();
	}
}

function lostFocusCellPhone()
{
	if(trim(document.Entry.CellPhone.value)=="")
		document.Entry.CellPhone.value="##########";
}


function gotFocusWorkPhone()
{

	if(trim(document.Entry.WorkPhone.value)=="" || trim(document.Entry.WorkPhone.value)=="##########")	
	{
		document.Entry.WorkPhone.value="";
		document.Entry.WorkPhone.focus();
	}
}

function lostFocusWorkPhone()
{
	if(trim(document.Entry.WorkPhone.value)=="")
		document.Entry.WorkPhone.value="##########";
}






function checkform()
{

	if (document.Entry.FirstName.value == null || document.Entry.FirstName.value.length == 0) 
	{
		alert("\nPlease Enter your First Name.");
		document.Entry.FirstName.focus();
		return false;
	}

	if (isInteger(document.Entry.FirstName.value) == true)
	{
			alert("\nNo numbers allowed in your First Name.");
			document.Entry.FirstName.focus();
			return false;		
	}

	if (document.Entry.LastName.value == null || document.Entry.LastName.value.length == 0) 
	{
		alert("\nPlease Enter your Last Name.");
		document.Entry.LastName.focus();
		return false;
	}

	if (isInteger(document.Entry.LastName.value) == true)
	{
			alert("\nNo numbers allowed in your Last Name.");
			document.Entry.LastName.focus();
			return false;		
	}


	if (document.Entry.Gender.value == "") 
	{
		alert("\nPlease select Your Gender.");
		document.Entry.Gender.focus();
		return false;
	}


	if (document.Entry.date_dob_m.value == "") 
	{
		alert("\nPlease select Your Date of Birth (Month).");
		document.Entry.date_dob_m.focus();
		return false;
	}

	if (document.Entry.date_dob_d.value == "") 
	{
		alert("\nPlease select Your Date of Birth (Day).");
		document.Entry.date_dob_d.focus();
		return false;
	}

	if (document.Entry.date_dob_y.value == "") 
	{
		alert("\nPlease select Your Date of Birth (Year).");
		document.Entry.date_dob_y.focus();
		return false;
	}
	
	if (document.Entry.Email.value == null || document.Entry.Email.value.length == 0) 
	{
		alert("\nPlease Enter your Email.");
		document.Entry.Email.focus();
		return false;
	}

	if (!e(document.Entry.Email.value))
	{

		alert("Please include a proper e-mail address, of the form id\@domain.zzz or id\@domain.xx.zzz.");
		document.Entry.Email.focus();
		//f(fld);
		return false;
	}
	

	if (trim(document.Entry.HomePhone.value) == "##########") 
	{
		alert("\nPlease Enter your Home Phone Number.");
		document.Entry.HomePhone.focus();
		return false;
	}

	if (isChars(document.Entry.HomePhone.value) == true)
	{
			alert("\nNo Alphabets allowed in Home Phone number.");
			document.Entry.HomePhone.focus();
			return false;		
	}

	if (document.Entry.HomePhone.value.length < 10) 
	{
		alert("\nHome Phone number must contain minimum of 10 digits.");
		document.Entry.HomePhone.focus();
		return false;
	}

	if (trim(document.Entry.CellPhone.value) != "##########" && trim(document.Entry.CellPhone.value) != "")
	{
	  	
		if (isChars(document.Entry.CellPhone.value) == true)
		{
			alert("\nNo Alphabets allowed in Cell Phone number.");
			document.Entry.CellPhone.focus();
			return false;		
		}

		if (document.Entry.CellPhone.value.length < 11) 
		{
			alert("\nCell Phone Number must contain 11 digits starting with 0 (zero).");
			document.Entry.CellPhone.focus();
			return false;
		}

	}



	if (document.Entry.StreetNumber.value == null || document.Entry.StreetNumber.value.length == 0) 
	{
		alert("\nPlease Enter your House No. / Name.");
		document.Entry.StreetNumber.focus();
		return false;
	}

	if (document.Entry.StreetName.value == null || document.Entry.StreetName.value.length == 0) 
	{
		alert("\nPlease Enter your Street Name.");
		document.Entry.StreetName.focus();
		return false;
	}

	if (document.Entry.City.value == null || document.Entry.City.value.length == 0) 
	{
		alert("\nPlease Enter your City Name.");
		document.Entry.City.focus();
		return false;
	}

	if (isInteger(document.Entry.City.value) == true)
	{
			alert("\nNo numbers allowed in City Name.");
			document.Entry.City.focus();
			return false;		
	}
	
	if (document.Entry.State.value == "") 
	{
		alert("\nPlease select your State.");
		document.Entry.State.focus();
		return false;
	}

	if (document.Entry.ZipCode.value == null || document.Entry.ZipCode.value.length == 0) 
	{
		alert("\nPlease Enter your ZipCode.");
		document.Entry.ZipCode.focus();
		return false;
	}
	
	if (document.Entry.LoanPurpose.value == "") 
	{
		alert("\nPlease select purpose of the Loan.");
		document.Entry.LoanPurpose.focus();
		return false;
	}
	
	if (document.Entry.OccupancyPayment.value == null || document.Entry.OccupancyPayment.value.length == 0 || trim(document.Entry.OccupancyPayment.value) == "")
	{
		alert("\nPlease Enter your Monthly Rent or Mortgage Payment .");
		document.Entry.OccupancyPayment.focus();
		return false;
	}

	if (isChars(document.Entry.OccupancyPayment.value) == true)
	{
			alert("\nNo Alphabets allowed in Monthly Rent or Mortgage Payment.");
			document.Entry.OccupancyPayment.focus();
			return false;		
	}
	
		if (document.Entry.OtherMonthlyExpenses.value == null || document.Entry.OtherMonthlyExpenses.value.length == 0 || trim(document.Entry.OtherMonthlyExpenses.value) == "")
	{
		alert("\nPlease Enter your Other Monthly Expenses.");
		document.Entry.OtherMonthlyExpenses.focus();
		return false;
	}

	if (isChars(document.Entry.OtherMonthlyExpenses.value) == true)
	{
			alert("\nNo Alphabets allowed in Other Monthly Expenses.");
			document.Entry.OtherMonthlyExpenses.focus();
			return false;		
	}
 
 




	if (document.Entry.Employer.value == null || document.Entry.Employer.value.length == 0) 
	{
		alert("\nPlease Enter your Employer Name");
		document.Entry.Employer.focus();
		return false;
	}

	if (trim(document.Entry.WorkPhone.value) == "##########") 
	{
		alert("\nPlease Enter your Work Phone Number.");
		document.Entry.WorkPhone.focus();
		return false;
	}

	if (isChars(document.Entry.WorkPhone.value) == true)
	{
			alert("\nNo Alphabets allowed in Work Phone number.");
			document.Entry.WorkPhone.focus();
			return false;		
	}

	if (document.Entry.WorkPhone.value.length < 10) 
	{
		alert("\nWork Phone number must contain minimum of 10 digits.");
		document.Entry.WorkPhone.focus();
		return false;
	}


	if (document.Entry.NetIncome.value == null || document.Entry.NetIncome.value.length == 0)
	{
		alert("\nPlease Enter your Net Income.");
		document.Entry.NetIncome.focus();
		return false;
	}

	if (isChars(document.Entry.NetIncome.value) == true)
	{
			alert("\nNo Alphabets allowed in Net Income.");
			document.Entry.NetIncome.focus();
			return false;		
	}
 

	if (document.Entry.PayFrequency.value == "") 
	{
		alert("\nPlease select Your Pay Frequency.");
		document.Entry.PayFrequency.focus();
		return false;
	}

	if (document.Entry.IncomeSource.value == "") 
	{
		alert("\nPlease select Your Income Source.");
		document.Entry.IncomeSource.focus();
		return false;
	}

	if (document.Entry.bankName.value == null || document.Entry.bankName.value.length == 0) 
	{
		alert("\nPlease Enter your Bank Name.");
		document.Entry.bankName.focus();
		return false;
	}
	
	if (document.Entry.accountNumber.value == null || document.Entry.accountNumber.value.length == 0) 
	{
		alert("\nPlease Enter your Account Number.");
		document.Entry.accountNumber.focus();
		return false;
	}

	if (document.Entry.bsbNumber.value == null || document.Entry.bsbNumber.value.length == 0) 
	{
		alert("\nPlease Enter your BSB Number.");
		document.Entry.bsbNumber.focus();
		return false;
	}	
	
	if (document.Entry.accountType.value == "") 
	{
		alert("\nPlease select Your Bank Account Type.");
		document.Entry.accountType.focus();
		return false;
	}

}

