/* Tenants: Validate SSN */
function CheckSSN(formfield)
{
     var theCount = 0;
     var theString = formfield.value;
     var newString = "";
     var myString = theString;
     var theLen = myString.length;
     for ( var i = 0 ; i < theLen ; i++ )
     {
     // Character codes for ints 1 - 9 are 48 - 57
          if ( ((myString.charCodeAt(i) >= 48 ) && (myString.charCodeAt(i) <= 57)) || (myString.charCodeAt(i) == 88) )
          newString = newString + myString.charAt(i);   
     }
	// Now the validation to determine that the remaining string is 9 characters.
     if (newString.length == 9 )
     {
		  // Now the string has been stripped of other chars it can be reformatted to ###-##-#### 
          var newLen = newString.length;
          var newSSN = "";
          for ( var i = 0 ; i < newLen ; i++ )
          {
               if ( ( i == 2 ) || ( i == 4 ) )
               {
                    newSSN = newSSN + newString.charAt(i) + "-";
               }else{
                    newSSN = newSSN + newString.charAt(i);
               }
          }
          formfield.value = newSSN;
          return true;
     }else{

          alert("The social security number you entered '"+theString+"' does not contain the correct number of digits.\n\nPlease enter it in the following format: ###-##-####");
          formfield.focus();
          return false;
     }
}

/* Tenants: Validate Phone */
function CheckPhoneNumber(formfield)
{
     var theCount = 0;
     var theString = formfield.value;
     var newString = "";
     var myString = theString;
     var theLen = myString.length;
     for ( var i = 0 ; i < theLen ; i++ )
     {
     // Character codes for ints 1 - 9 are 48 - 57
          if ( (myString.charCodeAt(i) >= 48 ) && (myString.charCodeAt(i) <= 57) )
          newString = newString + myString.charAt(i);   
     }
	// Now the validation to determine that the remaining string is 9 characters.
     if (newString.length == 10 )
     {
		  // Now the string has been stripped of other chars it can be reformatted to ###-##-#### 
          var newLen = newString.length;
          var newPhone = "";
          for ( var i = 0 ; i < newLen ; i++ )
          {
               if ( ( i == 2 ) || ( i == 5 ) )
               {
                    newPhone = newPhone + newString.charAt(i) + "-";
               }else{
                    newPhone = newPhone + newString.charAt(i);
               }
          }
          formfield.value = newPhone;
          return true;
     }else{
          alert("The phone number you entered '"+theString+"' does not contain the correct number of digits.\n\nPlease enter it in the following format: ###-###-####");
          formfield.focus();
          return false;
     }
}

/* Tenants: Format Phone Number */
function loanappFormatPhoneNumber(isField,fieldLabel){

isPhone = isField.value;
if (isPhone.length == 10)
{isPhone = isPhone.replace(/\D/g,'').replace(/^(\d{3})(\d{3})/,'$1-$2-');isField.value = isPhone;}
else if (isPhone.length < 12 || isPhone.length > 12 || isNaN(isPhone))
{
	alert('Please enter your ' + fieldLabel + ' phone number in the following format: ###-###-####');
	isField.focus();
}
}

function formatNumberField(fieldData,fieldLabel)
{
	if (/^\.?$/.test(fieldData.value) || !/^-?\d*\.?\d*$/.test(fieldData.value)) {alert('The ' + fieldLabel + ' field requires a number with only decimals and no commas.\nExample: 100000 or 100000.00'); return false; }
}

/* Validate Form 1 */
function validateFormSubmission1(form)
{
	// Telephone Fields
	//if (form.field_4.value != "") { if (CheckPhoneNumber(form.field_4,"daytime")==false){ form.field_4.focus(); return false; } }
	//if (form.field_5.value != "") { if (CheckPhoneNumber(form.field_5,"evening")==false){ form.field_5.focus(); return false; } }

  return (true);
}

/* Validate Form 2 */
function validateFormSubmission2(form)
{
	// Telephone Fields
	//if (form.field_12.value != "") { if (CheckPhoneNumber(form.field_12,"daytime")==false){ form.field_12.focus(); return false; } }
	//if (form.field_13.value != "") { if (CheckPhoneNumber(form.field_13,"evening")==false){ form.field_13.focus(); return false; } }

  return (true);
}

/* Validate Form 3 */
function validateFormSubmission3(form)
{
	// Telephone Fields
	//if (form.field_18.value != "") { if (CheckPhoneNumber(form.field_18,"daytime")==false){ form.field_18.focus(); return false; } }
	//if (form.field_19.value != "") { if (CheckPhoneNumber(form.field_19,"evening")==false){ form.field_19.focus(); return false; } }

  return (true);
}

/* Validate Form 4 */
function validateFormSubmission4(form)
{
	// Telephone Fields
	//if (form.field_29.value != "") { if (CheckPhoneNumber(form.field_29,"daytime")==false){ form.field_29.focus(); return false; } }
	//if (form.field_30.value != "") { if (CheckPhoneNumber(form.field_30,"evening")==false){ form.field_30.focus(); return false; } }

  return (true);
}