// JavaScript Document
var whitespace = " \t\n\r";
function isEmpty(strVal)
{
	return ((strVal == null) || (strVal.length == 0));
}
function isWhitespace(strVal)
{
	var nPos = 0;

	if (isEmpty(strVal))
		return false;

	for (nPos = 0; nPos < strVal.length; nPos++)
	
		if (whitespace.indexOf(strVal.charAt(nPos)) == -1){
			
			return false;
			}

	return true;
}

// rtrim: Right trim the string and return the trimmed value
function rtrim(strVal)
{
	var nPos = 0;
    var endPos
	if (isEmpty(strVal))
		return strVal;


	for (nPos = strVal.length-1; nPos >= 0; nPos--) {
		if (whitespace.indexOf(strVal.charAt(nPos)) == -1){
		 endPos = (nPos);
		 nPos = 0;  
		}  	     
	}
  
	return (endPos == strVal.length-1 ? strVal.substring(0) : strVal.substring(0, endPos+1));
}

// ltrim: Left trim the string and return the trimmed value
function ltrim(strVal)
{
	var nPos = 0;
    var endPos = 0;
	if (isEmpty(strVal))
		return strVal;

     for (nPos = 0; nPos < strVal.length; nPos++) {
	  if (whitespace.indexOf(strVal.charAt(nPos)) == -1){
			 endPos = (nPos);
		     nPos = strVal.length;  
		   }
     }
		
	return strVal.substring(endPos);
}

// alltrim: Trim the string on left and right, and return the trimmed value
function alltrim(strVal)
{
	return (isEmpty(strVal) ? strVal:ltrim(rtrim(strVal)));
}

/********************************************************
 replace: useful for JavaScript 1.0 and 1.1 where replace 
	  is not available. With JavaScript 1.2 (and above)
	  replace function is available.
	: replaces one occurrence of strVal with strWith in strSrc
********************************************************/
function replace(strSrc, strVal, strWith)
{
	var nPos = 0, strLeft="", strRight="";

	// check if empty (or) no string is found to replace
	if (isEmpty(strSrc) || (strSrc.indexOf(strVal) < 0))
		return strSrc;

	nPos = strSrc.indexOf(strVal);
	strLeft = strSrc.substring(0, nPos);
	nPos += strVal.length;
	strRight = strSrc.substring(nPos);

	return (strLeft + strWith + strRight);
}

// replaceall : replace all occurrences of strVal with strWith in strSrc
function replaceall(strSrc, strVal, strWith)
{
	var strBuffer=strSrc;

	while (strBuffer.indexOf(strVal) >= 0)
		strBuffer = replace(strBuffer, strVal, strWith);

	return (strBuffer);
}

// occurs: return no of occurrences of strVal within strSrc
function occurs(strVal, strSrc)
{
	var nCnt = 0, strBuffer=strSrc;

	while (strBuffer.indexOf(strVal) >= 0)
	{
		strBuffer = replace(strBuffer, strVal, "");
		nCnt++;
	}

	return (nCnt);
}

// replicate: returns string that contains strVal repeated nCnt times
function replicate(strVal, nCnt)
{
	var i = 0, strBuffer = "";

	for (i = 0; i < nCnt; i++)
		strBuffer += strVal;

	return (strBuffer);
}

/**************************************************************
 stuff: returns string after replacing nCnt characters (starting
	from nStartPos) with strReplacement in strSrc. 

 NOTE: starting position is 0
**************************************************************/
function stuff(strSrc, nStartPos, nCnt, strReplacement)
{
	var strLeft= "", strRight="";

	// check boundary values
	if (nCnt < 0 || nStartPos < 0 || (nStartPos > strSrc.length-1))
		return strSrc;

	strLeft = strSrc.substring(0, nStartPos);
	strRight = strSrc.substring(nStartPos+nCnt);

	return (strLeft + strReplacement + strRight);
}

<!--
/**********************************************************************
Depends on: isEmpty(), isWhitespace() functions string.js library 

NOTE: 
  -- always alltrim field value before calling any of these functions
  -- if field is empty, the function call will return true
**********************************************************************/

// isDigit: check if val has digits (0-9)
function isDigit(val)
{
  var strBuffer = new String(val);
  var nPos = 0;

  if (isEmpty(strBuffer))
    return false;

  for (nPos = 0; nPos < strBuffer.length; nPos++)
    if (strBuffer.charAt(nPos) < '0' || strBuffer.charAt(nPos) > '9')
      return false;

  return true;
}

// isAlpha: check if val has alphabets only (a-z, A-Z)
function isAlpha(val)
{
  var strBuffer = new String(val);
  var nPos = 0;

  if (isEmpty(strBuffer))
    return false;

  for (nPos = 0; nPos < strBuffer.length; nPos++)
    if (!((strBuffer.charAt(nPos) >= 'a' && strBuffer.charAt(nPos) <= 'z') ||
      (strBuffer.charAt(nPos) >= 'A' && strBuffer.charAt(nPos) <= 'Z')))
      return false;

  return true;
}

// isInteger: check if nVal is integer type
function isInteger(nVal)
{
  var strBuffer = new String(nVal);
  var nPos = 0, nStart = 0;

  if (isEmpty(strBuffer))
    return true;
  if (isWhitespace(strBuffer))
    return false;

  // check if -ve or +ve sign occurs in the beginning
  if ((strBuffer.charAt(0) == '-') || (strBuffer.charAt(0) == '+'))
    nStart = 1;
  else
    nStart = 0;

  for (nPos = nStart; nPos < strBuffer.length; nPos++)
    if (strBuffer.charAt(nPos) < '0' || strBuffer.charAt(nPos) > '9')
      return false;

  return true;  
}

// isFloat: check if fVal is floating-point type
//  LIMITATION: no scientific notation (for eg: xxxx.xxE+xx)
function isFloat(fVal)
{
  var strBuffer = new String(fVal);
  var nPos = 0, nStart = 0;

  if (isEmpty(strBuffer))
    return true;
  if (isWhitespace(strBuffer))
    return false;

  // check if -ve or +ve sign occurs in the beginning
  if ((strBuffer.charAt(0) == '-') || (strBuffer.charAt(0) == '+'))
    nStart = 1;
  else
    nStart = 0;

  for (nPos = nStart; nPos < strBuffer.length; nPos++)
    if ((strBuffer.charAt(nPos) < '0' || strBuffer.charAt(nPos) > '9') && 
        (strBuffer.charAt(nPos) != '.'))
      return false;

  return true;
}

/************************************************************
isDate  : Check if dVal is valid date
  : valid date format - 
    MM (or) M / DD (or) D / Y (or) YY (or) YYYY
  : YY > 50 should be 19YY
  : YY <= 50 should be 20YY
*************************************************************/
function isDate(dVal)
{
  var strBuffer= new String(dVal);
  var cDelimiter='';
  var strMonth=0, strDay=0, strYear=0;
  var nPos=-1;

  if (isEmpty(strBuffer))
    return true;
  if (isWhitespace(strBuffer))
    return false;

  // Get the delimiter used
  if (occurs('/', strBuffer) == 2)
    cDelimiter = '/';
  else if (occurs('-', strBuffer) == 2)
    cDelimiter = '-';

  // If no '/' or '-' found return false
  if (cDelimiter == '')
    return false;

  // validate month, date, and year (Y, YY, YYYY are valid year formats)
  nPos = strBuffer.indexOf(cDelimiter);
  strMonth = strBuffer.substring(0, nPos);
  if (strMonth.length > 2 || !isDigit(strMonth))
    return false;
  strBuffer = strBuffer.substring(nPos+1);
  nPos = strBuffer.indexOf(cDelimiter);
  strDay = strBuffer.substring(0, nPos);
  if (strDay.length > 2 || !isDigit(strDay))
    return false;
  strBuffer = strBuffer.substring(nPos+1);
  strYear = strBuffer;
  if ((strYear.length > 4) || (strYear.length == 3) || !isDigit(strYear))
    return false;

  // if YY < 50 then YYYY=20YY, else if YY >= 50 then YYYY=19YY
  var iYear = parseInt(strYear);
  if (iYear < 50)
    strYear = "20" + (strYear < 10 ? '0' + strYear:strYear);
  else if (iYear >= 50 && iYear < 100)
    strYear = "19" + strYear;

  strBuffer = strMonth + cDelimiter + strDay + cDelimiter + strYear;

  // validate date
  var dBuffer = new Date(strBuffer);
  
  if(strDay.length == 2){
   firstDigit = strDay.substring(0,1);
   secondDigit = strDay.substring(1,2);
   if (firstDigit == '0')
    strDay = secondDigit;
  }
    


  if(strMonth.length == 2){
     firstDigit = strMonth.substring(0,1);
     secondDigit = strMonth.substring(1,2);
     if (firstDigit == '0')
      strMonth = secondDigit;
  }
  
  if (dBuffer.getDate() != parseInt(strDay) || 
        dBuffer.getMonth()+1 != parseInt(strMonth) || 
        dBuffer.getFullYear() != parseInt(strYear))        
    return false;
 

  return true;
}

// isZipcode: check if valid US zip code (##### or #####-####)
function isZipcode(strZip)
{
  var strLeft="", strRight="", strVal = new String(strZip);

  if (isEmpty(strVal))
    return true;
  if (isWhitespace(strVal))
    return false;

  if (strVal.length != 5 && strVal.length != 10)
    return false;

  if ((strVal.length == 5) && isDigit(strVal))
    return true;

  if ((strVal.length == 10) && isDigit(strVal.substring(0, 5)) && 
            isDigit(strVal.substring(6)))
    return true;

  return false;
}

// isDatePart: check if nVal is valid day: 1-31, month:1-12, year:YYYY
function isDatePart(nVal, strType)
{
  var strBuffer = new String(nVal);

  if (isEmpty(strBuffer) || isWhitespace(strBuffer))
    return false;
  
  nVal = parseInt(strBuffer);
  if (!isDigit(nVal))
    return false;

  if ((strType == "Year") && (nVal < 0 || (nVal > 99 && nVal < 1000) || nVal > 9999))
    return false;
  else if ((strType == "Month") && (nVal < 1 || nVal > 12))
    return false;
  else if ((strType == "Day") && (nVal < 1 || nVal > 31))
    return false;

  return true;
}

function ConvToAlphaNumeric(objFld) {
    objFld.value = alltrim(objFld.value);
    objFld.value = objFld.value.replace(/[^\d\w]*/gi,''); 
}

/**********************************************************************
Depends on: 	alltrim(), isEmpty(), replaceall() functions of string.js library
		isFloat(), isDigit(), isZipcode() functions of ctype.js library 
		
NOTE: 
  -- always alltrim field value before calling any of these functions
  -- if field is empty, the function call will return true
**********************************************************************/

function checkField(objFld, strType)
{
	objFld.value = alltrim(objFld.value);
	if (isEmpty(objFld.value))
		return true;

	// Remove commas from Integer and Float fields
	if ((strType == "Integer") || (strType == "Float"))
		objFld.value = replaceall(objFld.value, ",", "");

	if ((strType == "Digit") && !isDigit(objFld.value))
	{
		alert("Please enter a response in numerical format (please " + 
			"exclude dollar signs, commas, parenthesis or any other " + 
			"non-numeric symbols).");
		objFld.value = "";
		objFld.focus();
		return false;
	}

	if (strType == "Integer") 
		if (!isInteger(parseInt(objFld.value)))
		{
			alert("Please enter a response in numerical format (please " + 
				"exclude dollar signs, commas, parenthesis or any other " + 
				"non-numeric symbols).");
			objFld.value = "";
			objFld.focus();
			return false;
		}
		else
			objFld.value = parseInt(objFld.value);

	if (strType == "Float") 
		if (!isFloat(parseFloat(objFld.value)))
		{
			alert("Please enter a response in numerical format (please " + 
				"exclude dollar signs, commas, parenthesis or any other " + 
				"non-numeric symbols).");
			objFld.value = "";
			objFld.focus();
			return false;
		}
		else
			objFld.value = parseFloat(objFld.value);

	if (strType == "ZIP") 
		if (!isZipcode(objFld.value))
		{
			alert("Please enter valid zip code value");
			objFld.value = "";
			objFld.focus();
			return false;
		}

	if (strType == "Date") 
		if (!isDate(objFld.value))
		{
			alert("Please enter valid date value (MM/DD/YYYY)");
			objFld.value = "";
			objFld.focus();
			return false;
		}

	if (strType == "DatePartYear" && checkField(objFld, "Digit"))
	{
		if (!isDatePart(objFld.value, "Year"))
		{
			alert("Please enter valid year value");
			objFld.value = "";
			objFld.focus();
			return false;
		}
		else if (objFld.value < 100)
			objFld.value = (objFld.value < 50 ? 2000:1900) + parseInt(objFld.value);
	}


	return true;
}

/*******************************************************************************
 checkRange: 	Check the range of field value.
 Parameters:	objFld - Field reference
		strType - "Inclusive" = include boundary values
			- "Exclusive" = exclude boundary values
			- "LeftInclusive" = include only left boundary value
			- "RightInclusive" = include only right boundary value
*********************************************************************************/
function checkRange(objFld, fLower, fUpper, strType)
{
	var fVal = 0.0;

	if (isEmpty(objFld.value))
		return true;
	if (!isFloat(objFld.value))
		return false;

	fVal = parseFloat(objFld.value);

	if ((strType == "Inclusive") && (fVal >= fLower) && (fVal <= fUpper))
		return true;
	else if ((strType == "Exclusive") && (fVal > fLower) && (fVal < fUpper))
		return true;
	else if ((strType == "LeftInclusive") && (fVal >= fLower) && (fVal < fUpper))
		return true;
	else if ((strType == "RightInclusive") && (fVal > fLower) && (fVal <= fUpper))
		return true;

	alert("Value should be between " + fLower + " and " + fUpper);
	objFld.value = "";
	objFld.focus();

	return false;
}

/************************************************************
 checkLength: 	Check the length of the field value.
		Useful for fields like TEXTAREA 
		where MAXLENGTH attribute is not available
 Parameters:	objFld - Field reference 
************************************************************/
function checkLength(objFld, nLen)
{
	var strVal = new String(objFld.value);

	if (strVal.length > nLen) {
		alert("Maximum length allowed is " + nLen + " characters. " + 
			"Value has been truncated to the size of " + nLen + ".");
		objFld.value = strVal.substring(0, nLen);
		objFld.focus();
		return false;
	}

	return true;
}

<!--
// Validate E-mail Address (JavaScript 1.0 version)
// by Kevin Lynn Brown 
// kbrown@myersinternet.com
// ?999 All rights reserved

/**************************************************************
 Description: Email address must be of form a@b.c i.e., 
	there must be at least one character before the @
	there must be at least one character before and after the .
	the characters @ and . are both required
 Dependencies: alltrim, isEmpty, occurs of string.js
**************************************************************/

function validEmail(objFld) {
	var strInvalid = "*?#&^~`'\\[]<>;/:\" ", bAliasedEmail = false, strAliasedEmail="";
	var i = 0, bValid = true;

	objFld.value = alltrim(objFld.value);
	if (isEmpty(objFld.value))
		return true;

	var strEmail = new String(objFld.value);

	// Assumption: if strEmail contains < and >, Email is between < and >
	if (strEmail.indexOf('<') < strEmail.indexOf('>') && strEmail.indexOf('<') >= 0)
	{
		bAliasedEmail = true;
		strAliasedEmail = strEmail;
		strEmail = strEmail.substring(strEmail.indexOf('<')+1, 
				strEmail.indexOf('>'));
	}

	if (strEmail.length < 5)	// check the length
		bValid = false;
	else if (strEmail.lastIndexOf("@") <= 0 || (strEmail.lastIndexOf(".") - 
				strEmail.lastIndexOf("@") <= 1)) // check positions of @ and .
		bValid = false;
	else if (occurs('@', strEmail) > 1)	// check if @ occurs more than once
		bValid = false
	else	// check if any invalid characters present
	{
		for (i = 0; i < strEmail.length; i++)
			if (strInvalid.indexOf(strEmail.charAt(i)) >= 0)
			{
				bValid = false;
				break;
			}
	}
	

	if (!bValid) {
		alert("Please enter a valid email address");
		objFld.value = "";
		objFld.focus();
		return bValid;
	}	
	

	
	if (bAliasedEmail)
	 this.value = strAliasedEmail;
	else
	 this.value = strEmail;
	
	return bValid;
}

/**********************************************************************
 chkMandatory: check mandatory fields on the form objForm
 parameters: objForm - form reference


 pre-requisites: aMandatory - array of fields for which mandatory evaluation 
				should be done
		aMandatory should be defined on each HTML page 
 format of aMandatory:
    aMandatory[<field-name-string>] = new Array(<message-string>, <input-type-string>, <focus-on-string>);

 <message-string>: message to be displayed on mandatory check failure 
		(NOTE: system dispalyes "<message-string> is mandatory")
 <input-type-string>: "TEXT", "RADIO"
 <focus-on-string>: name of the field where focus should be placed on mandatory check failure.
		    if this is "" then focus is place on <field-name-string>
**********************************************************************/
var aMandatory = new Array();
function chkMandatory(objForm)
{
	for (var iLoop in aMandatory)
	{
		var strVal;
		strVal = "";
		if (aMandatory[iLoop][1] == "Text")
			strVal = eval("objForm." + iLoop + ".value");
		else if (aMandatory[iLoop][1] == "Radio")
		{
			var oEle = eval("objForm." + iLoop);
			var iLen = oEle.length;
			for (var iEle = 0; iEle < iLen; iEle++)
				if (oEle[iEle].checked)
				{
					strVal = oEle[iEle].value;						
					break;					
				}
		}
		else if (aMandatory[iLoop][1] == "Select")
		{
			var iIdx = eval("objForm." + iLoop + ".selectedIndex");
			if (iIdx > -1)
				strVal = eval("objForm." + iLoop + "[" + iIdx + "].value");
			else
				strVal = "";
		}
		if (strVal == "")
		{
			if (aMandatory[iLoop][1] == "Text")
				alert("Please enter value for " + aMandatory[iLoop][0] + ".");

			if (aMandatory[iLoop][1] == "Radio" || aMandatory[iLoop][1] == "Select")
				alert("Please select " + aMandatory[iLoop][0] + ".");

			if (aMandatory[iLoop][2] != "")
				eval("objForm." + aMandatory[iLoop][2] + ".focus()");
			else
			{
				if (aMandatory[iLoop][1] == "Radio")
					eval("objForm." + iLoop + "[0].focus()");
				else
					eval("objForm." + iLoop + ".focus()");
			}
			return false;
		}
	}
	return true;
}

/**********************************************************************
This function is same as chkMandatory(objForm), but applied on 
**********************************************************************/
function chkMandatoryRecursively(objForm, iRecursiveCnt)
{
	for (var iRecCnt = 1; iRecCnt <= iRecursiveCnt; iRecCnt++)
	{
		for (var iLoop in aMandatory)
		{
			var strVal;
			strVal = "";
			if (aMandatory[iLoop][1] == "Text")
				strVal = eval("objForm." + iLoop + iRecCnt + ".value");
			else if (aMandatory[iLoop][1] == "Radio")
			{
				var oEle = eval("objForm." + iLoop + iRecCnt);
				var iLen = oEle.length;
				for (var iEle = 0; iEle < iLen; iEle++)
					if (oEle[iEle].checked)
					{
						strVal = oEle[iEle].value;						
						break;					
					}
			}
			else if (aMandatory[iLoop][1] == "Select")
			{
				var iIdx = eval("objForm." + iLoop + iRecCnt + ".selectedIndex");
				if (iIdx > -1)
					strVal = eval("objForm." + iLoop + iRecCnt + "[" + iIdx + "].value");
				else
					strVal = "";
			}
			if (strVal == "")
			{
				if (aMandatory[iLoop][1] == "Text")
					alert("Please enter value for " + aMandatory[iLoop][0] + ".");

				if (aMandatory[iLoop][1] == "Radio" || aMandatory[iLoop][1] == "Select")
					alert("Please select " + aMandatory[iLoop][0] + ".");

				if (aMandatory[iLoop][2] != "")
					eval("objForm." + aMandatory[iLoop][2] + iRecCnt + ".focus()");
				else
				{
					if (aMandatory[iLoop][1] == "Radio")
						eval("objForm." + iLoop + iRecCnt + "[0].focus()");
					else
						eval("objForm." + iLoop + iRecCnt + ".focus()");
				}
			return false;
			}
		}
	}

	return true;
}


/**********************************************************************
 chkMandatoryFiled: perform mandatory check on the field
**********************************************************************/

function chkMandatoryField(objForm, objField, strCaption, strFieldType, strFocusOn)
{
	var strVal;
	strVal = "";
	if (strFieldType == "Text")
		strVal = objField.value;
	else if (strFieldType == "Radio")

	{
		var iLen = objField.length;
		for (var iEle = 0; iEle < iLen; iEle++)
			if (objField[iEle].checked)
			{
				strVal = objField[iEle].value;						
				break;					
			}
	}
	else if (strFieldType == "Select")
	{
		var iIdx = objField.selectedIndex;
		if (iIdx > -1)
			strVal = objField[iIdx].value;
		else
			strVal = "";
	}
	if (strVal == "")
	{
		if (strFieldType == "Text")
			alert("Please enter value for " + strCaption + ".");

		if (strFieldType == "Radio" || strFieldType == "Select")
			alert("Please select " + strCaption + ".");

		if (strFocusOn != "")
			eval("objForm." + strFocusOn + ".focus()");
		else
		{
			if (strFieldType == "Radio")
				objField[0].focus();
			else
				objField.focus();
		}
		return false;
	}

	return true;	
}

<!--
  //Begin Mac checks
  var mc_detect = navigator.userAgent.toLowerCase();
  var mc_OS, mc_browser, mc_thestring;

  function checkIt(string) {
	var place = mc_detect.indexOf(string) + 1;
	mc_thestring = string;
	return place;
  }


  if (checkIt('msie')) {
	mc_browser = "IE";
  } else {
	mc_browser = "";
  }
  if (checkIt('mac')) {
	mc_OS = 'Mac';
  } else {
    mc_OS =  '';
  }

	var blnChkMandatoryFlds = false;
  
  aMandatory["b_first_name"] = new Array("First Name", "Text", "");
  aMandatory["b_last_name"] = new Array("Last Name", "Text", "");
  aMandatory["m_b_email"] = new Array("Email address", "Text", "");
  aMandatory["m_loantype"] = new Array("Purpose of loan", "Select", "");
  //aMandatory["property_value"] = new Array("Property value", "Text", "");
  //aMandatory["loan_amount"] = new Array("Loan amount", "Text", "");
  aMandatory["m_coborrower"] = new Array("Is there a co-borrower?", "Radio", "");
  aMandatory["subject_property_state"] = new Array("In what state are you looking for a loan?", "Select", "");
  aMandatory["m_reo"] = new Array("Do you currently own any real estate?", "Radio", "");
  
  aMandatory["credit_history"] = new Array("How is your credit?", "Radio", "");
  
  
  
  

  function evalPhoneNo(objForm, objPhone)
  {
    objPhone.value = eval("objForm." + objPhone.name + "1.value") +
            eval("objForm." + objPhone.name + "2.value") +
            eval("objForm." + objPhone.name + "3.value");
  }

  function chkPhoneNo(objPhone, objFocus)
  {
    var iLen = objPhone.value.length;
    var iAreaCode;
    if (iLen == 0)
      return true;
    if (iLen < 10)
    {
      alert("Please enter valid phone number.");
      objFocus.focus();
      return false;
    }

    return true;
  }

  function chkOthers(objForm)
  {
  if (mc_OS == 'Mac') {
    if ( ( (document.getElementById("b_home_phone_no1").value != "") && (document.getElementById("b_home_phone_no2").value != "") && (document.getElementById("b_home_phone_no3").value != "") ) || ( (document.getElementById("b_work_phone1").value != "") && (document.getElementById("b_work_phone2").value != "") && (document.getElementById("b_work_phone3").value != "") ) ) {
		var blnvar = 'Y';

		//return false;
	    objForm.b_home_phone_no.value = document.getElementById("b_home_phone_no1").value + '' + document.getElementById("b_home_phone_no2").value + '' + document.getElementById("b_home_phone_no3").value;
	    objForm.b_work_phone.value = document.getElementById("b_work_phone1").value + '' + document.getElementById("b_work_phone2").value + '' + document.getElementById("b_work_phone3").value;

	    //alert(document.getElementById("b_home_phone_no").value);
	    //alert(document.getElementById("b_work_phone").value);
	    //return false;
    } else {
        alert("Home Phone Number or Work Phone Number is mandatory.");
		document.getElementById("b_home_phone_no1").focus();
		return false;
    }
  }

  if (mc_OS != 'Mac') {
    if ( ( (document.getElementById("b_home_phone_no1").value == "") && (document.getElementById("b_home_phone_no2").value == "") && (document.getElementById("b_home_phone_no3").value == "") ) && ( (document.getElementById("b_work_phone1").value == "") && (document.getElementById("b_work_phone2").value == "") && (document.getElementById("b_work_phone3").value == "") ) ) {
      alert("Home Phone Number or Work Phone Number is mandatory.");
      document.getElementById("b_home_phone_no1").focus();
      return false;
    }
    var bRetVal = chkPhoneNo(document.getElementById("b_home_phone_no"), document.getElementById("b_home_phone_no1"));
    if (!bRetVal)
      return bRetVal;
    bRetVal = chkPhoneNo(document.getElementById("b_work_phone"), document.getElementById("b_work_phone1"));
    if (!bRetVal)
      return bRetVal;
    bRetVal = chkPhoneNo(document.getElementById("b_cell_phone"), document.getElementById("b_cell_phone1"));
    if (!bRetVal)
      return bRetVal;
  }

    var iNoProp = parseInt(objForm.m_no_properties.value);
    if (objForm.m_reo[1].checked && (isNaN(iNoProp) || iNoProp <= 0))
    {
      alert("Please enter no of properties owned");
      objForm.m_no_properties.value = "";
      objForm.m_no_properties.focus();
      return false;
    }

	if ( (blnChkMandatoryFlds == true) && (isNaN(parseFloat(objForm.property_value.value)) || (parseFloat(objForm.property_value.value) <= 0)) )
    {
      alert("Please enter a value for Property Value.");
      objForm.property_value.focus();
      return false;
    }

	if ( (blnChkMandatoryFlds == true) && (isNaN(parseFloat(objForm.loan_amount.value)) || (parseFloat(objForm.loan_amount.value) <= 0)) )
    {
      alert("Please enter a value for Loan Amount.");
      objForm.loan_amount.focus();
      return false;
    }

    if (parseFloat(objForm.loan_amount.value) < parseFloat(objForm.min_loan.value))
    {
      alert("Our minimum loan size is $" + objForm.min_loan.value +
          ". Please increase your loan amount.");
      objForm.loan_amount.focus();
      return false;
    }
    if (parseFloat(objForm.loan_amount.value) > 999999999999)
      {
      alert("You have entered a loan amount higher than the maximum amount.  Please decrease your loan amount.");
      objForm.loan_amount.focus();
      return false;
    }
    if (parseFloat(objForm.property_value.value) > 999999999999)
      {
      alert("You have entered a property value higher than the maximum amount.  Please decrease your property_value.");
      objForm.property_value.focus();
      return false;
    }
    return true;
  }

    function doSubmit(){
     if( chkForm(document.entry_page))
      document.entry_page.submit();
    }
	
	function doSubmitF(objForm){
     if(chkForm(objForm))
      objForm.submit();
    }

  function chkForm(objForm)
  {
    var bRetVal;
    bRetVal = chkMandatory(objForm);
    if (!bRetVal)
      return bRetVal;
    bRetVal = chkOthers(objForm);
    if (!bRetVal)
      return false;

    //objForm.submit();
    return true;
  }

  function showPopup()
  {
    var objWinNotif;
    objWinNotif = window.open("help_loantype.htm",
          "help_loantype", "height=300,width=450,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no");
    objWinNotif.opener = null;
  }

  function setOtherOption(strVal, objEle)
  {
    if (strVal.length > 0)
      for (var i = 0; i < objEle.options.length; i++)
        if (objEle.options[i].value == "Other")
        {
          objEle.selectedIndex = i;
          break;
        }
  }

  function getLoanAmt(objForm)
  {
    var fPropertyVal = objForm.property_value.value;
    var fPctDownPmt = objForm.percent_down.value;
    if (!isNaN(parseFloat(fPropertyVal)))
      objForm.loan_amount.value = fPropertyVal*(100.0 - fPctDownPmt)/100.0;
    else
    {
      objForm.percent_down.value = 0;
      return false;
    }
  }


  function chkRetForm(objForm)
  {

    if (objForm.m_login_email.value.length <= 0)
    {
      alert("Please enter a valid Login");
      objForm.m_login_email.focus();
      return false;
    }


    if (objForm.m_password.value.length < 4)
    {
      alert("Password must be minimum 4 characters");
      objForm.m_password.focus();
      return false;
    }


    return true;
  }
  
  function chkPwd(objForm)
  {
	 if(objForm.m_password.value.length < 4)
	 {
		 alert("Password must be minimum 4 characters");
		 objForm.m_password.focus();
		 return false;
	 }
	 
	 if(objForm.confirm_password.value.length < 4)
	 {
		 alert("Password must be minimum 4 characters");
		 objForm.confirm_password.focus();
		 return false;
	 }
	 
	 if(objForm.m_password.value != objForm.confirm_password.value)
	 {
		 alert("please confirm the password correctly.");
		 objForm.m_password.focus();
		 return false;
     }
	 
	 return true;
  }
  
  function changeLoc(objSel)
  {
    document.entry_page.access_id.value = objSel[objSel.selectedIndex].value;
    document.entry_page.access_who.value = "LO";
  }


  //these 2 functions were added for the mlp->iAPP auto-population
  function fnSelLoanPurpose(objForm,selVal) {
    var i;
    for (i=0;i<objForm.m_loantype.options.length;i++) {
      if ((objForm.m_loantype.options[i].value == "-2")  && (selVal == 'purchase')) {
        objForm.m_loantype.options[i].selected = true;
      }
      if ((objForm.m_loantype.options[i].value == "-1")  && (selVal == 'home_equity')) {
        objForm.m_loantype.options[i].selected = true;
      }
      if ((objForm.m_loantype.options[i].value == "05")  && (selVal == 'refinance')) {
        objForm.m_loantype.options[i].selected = true;
      }
    }
  }

  function fnSelPropertyState(objForm,selVal) {
    var i;
    for (i=0;i<objForm.subject_property_state.options.length;i++) {
      if (objForm.subject_property_state.options[i].value == selVal) {
          objForm.subject_property_state.options[i].selected = true;
      }
    }
  }

  function chkLoanPurposeSeln(objSel) {
	var strPurpose = objSel.options[objSel.options.selectedIndex].value;

	if (strPurpose == '16') {
		document.getElementById("prop_value_reqd").innerHTML = "";
		document.getElementById("loan_amount_reqd").innerHTML = "";
		blnChkMandatoryFlds = false;
	} else {
		document.getElementById("prop_value_reqd").innerHTML = "*";
		document.getElementById("loan_amount_reqd").innerHTML = "*";
		blnChkMandatoryFlds = true;
	}
  }
  
  aMandatory["m_password"] = new Array("Password", "Text", "");

  function chkOthers(objForm)
  {
    if (objForm.m_password.value.length < 4)
    {
      alert("Password must be minimum 4 characters");
      objForm.m_password.focus();
      return false;
    }
    else if (objForm.m_password.value != objForm.confirm_password.value)
    {
      alert("Please confirm the password correctly");
      objForm.confirm_password.value = "";
      objForm.confirm_password.focus();
      return false;
    }

    return true;
  }
