// JavaScript Document
<!--
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


//used to check email field validation.
function is_email(email)
{
	if(!email.match(/^[A-Za-z0-9\._\-+]+@[A-Za-z0-9_\-+]+(\.[A-Za-z0-9_\-+]+)+$/))
		return false;
	return true;
}
function IsNumeric(strString)
   //  check for valid numeric strings 
   {
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;
   if (strString.length == 0) return false;
   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
return blnResult;
}

function IsAlpha(strString)
   //  check for valid numeric strings 
   {
   var strValidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ- ";
   var strChar;
   var blnResult = true;
   if (strString.length == 0) return false;
   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
return blnResult;
}

function ismobile(string) {
  if (string.length !=10)
      return false;
   return true;
}


function validateZIP(field) {
var valid = "0123456789-";
var hyphencount = 0;

if (field.length!=5 && field.length!=10) {
alert("Please enter your 5 digit zip code.");
return false;
}
for (var i=0; i < field.length; i++) {
temp = "" + field.substring(i, i+1);
if (temp == "-") hyphencount++;
if (valid.indexOf(temp) == "-1") {
alert("Invalid characters in your zip code.  Please try again.");
return false;
}
if ((hyphencount > 1) || ((field.length==10) && ""+field.charAt(5)!="-")) {

return false;
   }
}
return true;
}

function validate(){
	if(document.appl_frm.debt_amount.selectedIndex == 0){
	alert('Please select your mortgage balance.');
	document.appl_frm.debt_amount.focus();
	return false;
	}
	if(document.appl_frm.property_value.selectedIndex == 0){
	alert('Please select your property value.');
	document.appl_frm.property_value.focus();
	return false;
	}
	if(document.appl_frm.fname.value==''){
	alert('Please enter your first name.');
	document.appl_frm.fname.focus();
	return false;
	}
	if (IsAlpha(document.appl_frm.fname.value) == false) 
	{
	alert("Please enter a valid first name (letters only: no numbers, or special characters)");
	document.appl_frm.fname.value="";
	document.appl_frm.fname.focus();
	return false;
    }
	if(document.appl_frm.lname.value==''){
	alert('Please enter your last name.');
	document.appl_frm.lname.focus();
	return false;
	}
		if (IsAlpha(document.appl_frm.lname.value) == false) 
	{
	alert("Please enter a valid last name (letters only: no numbers, or special characters)");
	document.appl_frm.lname.value="";
	document.appl_frm.lname.focus();
	return false;
    }
	if(document.appl_frm.email.value==''){
	alert('Please enter your email address.');
	document.appl_frm.email.focus();
	return false;
	}
	else if(!is_email(document.appl_frm.email.value))
	{
	alert("Invalid email-id.");		
	document.appl_frm.email.focus();
	return false;
	}
	
	if(document.appl_frm.state.selectedIndex==0){
	alert('Please select your state.');
	document.appl_frm.state.focus();
	return false;
	}	
	
	if (validateZIP(document.appl_frm.Zip.value) == false) {
	//alert("The hyphen character should be used with a properly formatted 5 digit+four zip code, like '12345-6789'.   Please try again.");
	document.appl_frm.Zip.value="";
	document.appl_frm.Zip.focus();
	return false;
    }
	
	if(document.appl_frm.Zip.value==''){
	alert('Please enter your zip code.');
	document.appl_frm.Zip.focus();
	return false;
	}
	
	if(document.appl_frm.tel1.value==''){
	alert('Please enter your home phone area code.');
	document.appl_frm.tel1.focus();
	return false;
	}
	if (IsNumeric(document.appl_frm.tel1.value) == false) 
	{
	alert("Please enter valid home phone."+ '\n' +" (numbers only: no dashes, spaces, or brackets)");
	document.appl_frm.tel1.value="";
	document.appl_frm.tel1.focus();
	return false;
    }
	if(document.appl_frm.tel2.value==''){
	alert('Please enter your home phone code.');
	document.appl_frm.tel2.focus();
	return false;
	}
	if (IsNumeric(document.appl_frm.tel2.value) == false) 
	{
	alert("Please enter valid home phone."+ '\n' +" (numbers only: no dashes, spaces, or brackets)");
	document.appl_frm.tel2.value="";
	document.appl_frm.tel2.focus();
	return false;
    }
	if(document.appl_frm.tel3.value==''){
	alert('Please enter your home phone.');
	document.appl_frm.tel3.focus();
	return false;
	}
	if (IsNumeric(document.appl_frm.tel3.value) == false) 
	{
	alert("Please enter valid home phone."+ '\n' +" (numbers only: no dashes, spaces, or brackets)");
	document.appl_frm.tel3.value="";
	document.appl_frm.tel3.focus();
	return false;
    }
	
	
	if(document.appl_frm.cel1.value==''){
	alert('Please enter your cell phone area code.');
	document.appl_frm.cel1.focus();
	return false;
	}
	if (IsNumeric(document.appl_frm.cel1.value) == false) 
	{
	alert("Please enter valid cell phone."+ '\n' +" (numbers only: no dashes, spaces, or brackets)");
	document.appl_frm.cel1.value="";
	document.appl_frm.cel1.focus();
	return false;
    }

	if(document.appl_frm.cel2.value==''){
	alert('Please enter your cell phone area code.');
	document.appl_frm.cel2.focus();
	return false;
	}
	if (IsNumeric(document.appl_frm.cel2.value) == false) 
	{
	alert("Please enter valid cell phone."+ '\n' +" (numbers only: no dashes, spaces, or brackets)");
	document.appl_frm.cel2.value="";
	document.appl_frm.cel2.focus();
	return false;
    }
	
	if(document.appl_frm.cel3.value==''){
	alert('Please enter your cell phone.');
	document.appl_frm.cel3.focus();
	return false;
	}
	if (IsNumeric(document.appl_frm.cel3.value) == false) 
	{
	alert("Please enter valid cell phone."+ '\n' +" (numbers only: no dashes, spaces, or brackets)");
	document.appl_frm.cel3.value="";
	document.appl_frm.cel3.focus();
	return false;
    }

	if(document.appl_frm.security_code.value==''){
	alert('Please enter your security code.');
	document.appl_frm.security_code.focus();
	return false;
	}

	//document.dieform.action="proc_contact.php";
	//document.dieform.submit();
}


//Code for Google Adwords
var google_conversion_id = 1063423424;
var google_conversion_language = "en_US";
var google_conversion_format = "1";
var google_conversion_color = "ffffff";
var google_conversion_label = "X409CKSphQEQwJuK-wM";

var isNN = (navigator.appName.indexOf("Netscape")!=-1);

function autoTab(input,len, e) {
  var keyCode = (isNN) ? e.which : e.keyCode; 
  var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
  if(input.value.length >= len && !containsElement(filter,keyCode)) {
    input.value = input.value.slice(0, len);
    input.form[(getIndex(input)+1) % input.form.length].focus();
  }

  function containsElement(arr, ele) {
    var found = false, index = 0;
    while(!found && index < arr.length)
    if(arr[index] == ele)
    found = true;
    else
    index++;
    return found;
  }

  function getIndex(input) {
    var index = -1, i = 0, found = false;
    while (i < input.form.length && index == -1)
    if (input.form[i] == input)index = i;
    else i++;
    return index;
  }
  return true;
}
