//-->
/////////////////////////////////////
// Create XML Object for city state//
/////////////////////////////////////
var xmlhttp=false;
try {
	xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
	xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
	xmlhttp = false;
	}
}
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	try {
		xmlhttp = new XMLHttpRequest();
	} catch (e) {
		xmlhttp=false;
	}
}
if (!xmlhttp && window.createRequest) {
	try {
		xmlhttp = window.createRequest();
	} catch (e) {
		xmlhttp=false;
	}
}
//-->
function getloc(){
	var browserName=navigator.appName; 
	if (browserName=="Netscape"){
		//begin netscape function		
			if (document.forms["form1"].zipcode.value.length <= 4){	
				document.forms["form1"].city.value="";
				document.forms["form1"].state.value="";			
//				document.forms["form1"].city.disabled = true;
//				document.forms["form1"].state.disabled = true;	
			}else if (document.forms["form1"].zipcode.value.length == 5){
//				document.forms["form1"].city.value="Loading...";
//				document.forms["form1"].state.value="Loading...";		
				url = "inc/getloc.loan?zipcode="+document.forms["form1"].zipcode.value;
				xmlhttp=null
				if (window.XMLHttpRequest){
				  xmlhttp=new XMLHttpRequest()
  				}
				xmlhttp.open("POST", url,true);
				xmlhttp.onreadystatechange=function() {
	  		if (xmlhttp.readyState==4) {				
				qs=xmlhttp.responseText;
				this.params = new Object()
				if (qs.length == 0) return
				qs = qs.replace(/\+/g, ' ')
				var args = qs.split('&')
				for (var i=0;i<args.length;i++) {
					var value;
					var pair = args[i].split('=')
					var name = unescape(pair[0])
				if (pair.length == 2)
					value = unescape(pair[1])
				else
					value = name
					this.params[name] = value					
				}
				var v1=this.params["city"]
				var v2=this.params["state"]	
				document.forms["form1"].city.value=v1;
				///////////////////////////////////////////
				selstate="";
				if(v2=="Alabama"){ selstate = "AL" }
				if(v2=="Alaska"){ selstate = "AK" }
				if(v2=="Arizona"){ selstate = "AZ" }
				if(v2=="Arkansas"){ selstate = "AR" }
				if(v2=="California"){ selstate = "CA" }
				if(v2=="Colorado"){ selstate = "CO" } 
				if(v2=="Connecticut"){ selstate = "CT" }
				if(v2=="Delaware"){ selstate = "DE" } 
				if(v2=="District of Columbia"){ selstate = "DC" } 
				if(v2=="Florida"){ selstate = "FL" }
				if(v2=="Georgia"){ selstate = "GA" }
				if(v2=="Hawaii"){ selstate = "HI" }
				if(v2=="Idaho"){ selstate = "ID" }
				if(v2=="Illinois"){ selstate = "IL" } 
				if(v2=="Indiana"){ selstate = "IN" }
				if(v2=="Iowa"){ selstate = "IA" } 
				if(v2=="Kansas"){ selstate = "KS" } 
				if(v2=="Kentucky"){ selstate = "KY" }
				if(v2=="Louisiana"){ selstate = "LA" }
				if(v2=="Maine"){ selstate = "ME" } 
				if(v2=="Maryland"){ selstate = "MD" }
				if(v2=="Massachusetts"){ selstate = "MA" }
				if(v2=="Michigan"){ selstate = "MI" } 
				if(v2=="Minnesota"){ selstate = "MN" }
				if(v2=="Mississippi"){ selstate = "MS" }
				if(v2=="Missouri"){ selstate = "MO" } 
				if(v2=="Montana"){ selstate = "MI" } 
				if(v2=="Nebraska"){ selstate = "NE" }
				if(v2=="Nevada"){ selstate = "NV" } 
				if(v2=="New Hampshire"){ selstate = "NH" }
				if(v2=="New Jersey"){ selstate = "NJ" } 
				if(v2=="New Mexico"){ selstate = "NM" }
				if(v2=="New York"){ selstate = "NY" } 
				if(v2=="North Carolina"){ selstate = "NC" } 
				if(v2=="North Dakota"){ selstate = "ND" }
				if(v2=="Ohio"){ selstate = "OH" } 
				if(v2=="Oklahoma"){ selstate = "OK" }
				if(v2=="Oregon"){ selstate = "OR" } 
				if(v2=="Pennsylvania"){ selstate = "PA" }
				if(v2=="Rhode Island"){ selstate = "RI" }
				if(v2=="South Carolina"){ selstate = "SC" }
				if(v2=="South Dakota"){ selstate = "SD" } 
				if(v2=="Tennessee"){ selstate = "TN" } 
				if(v2=="Texas"){ selstate = "TX" } 
				if(v2=="Utah"){ selstate = "UT" } 
				if(v2=="Vermont"){ selstate = "VT" }
				if(v2=="Virginia"){ selstate = "VA" }
				if(v2=="Washington"){ selstate = "WA" }
				if(v2=="West Virginia"){ selstate = "WV" }
				if(v2=="Wisconsin"){ selstate = "WI" } 
				if(v2=="Wyoming"){ selstate = "WY" } 
				//////////////////////
				for (i = 0; i < document.forms["form1"].state.options.length; i++) {  
					if (document.forms["form1"].state.options[i].value==selstate){ 
						document.forms["form1"].state.options[i].selected=true; 
					}
				}
				document.forms["form1"].city.disabled = false;
				document.forms["form1"].state.disabled = false;				
		 	 	}
	 		}
				xmlhttp.send(null)		
				return (false);
				document.forms["form1"].city.disabled = false;
				document.forms["form1"].state.disabled = false;								
			}
			//end Netscape Function
	}else{ 
		if (browserName=="Microsoft Internet Explorer"){
  			//begin ie function
			var zipcode = ""; 
			if (form1.zipcode.value.length <= 4){	
				form1.city.value="";
				form1.state.value="";			
//				document.form1.city.disabled = true;
//				document.form1.state.disabled = true;	
			}else if (form1.zipcode.value.length == 5){
//				form1.city.value="Loading...";
//				form1.state.value="Loading...";		
				var url = "inc/getloc.loan?zipcode="+form1.zipcode.value;
				xmlhttp.open("POST", url,true);
				xmlhttp.onreadystatechange=function() {
	  		if (xmlhttp.readyState==4) {
				qs=xmlhttp.responseText;
				this.params = new Object()
				if (qs.length == 0) return
				qs = qs.replace(/\+/g, ' ')
				var args = qs.split('&')
				for (var i=0;i<args.length;i++) {
					var value;
					var pair = args[i].split('=')
					var name = unescape(pair[0])
				if (pair.length == 2)
					value = unescape(pair[1])
				else
					value = name
					this.params[name] = value					
				}
				var v1=this.params["city"]
				var v2=this.params["state"]	
				if(v1==''){
					document.form1.city.disabled = false;
					document.form1.state.disabled = false;				
				}
				if(v2==''){
					document.form1.city.disabled = false;
					document.form1.state.disabled = false;				
				}				
				form1.city.value=v1;
				///////////////////////////////////////////
				var selstate="";
				if(v2=="Alabama"){ selstate = "AL" }
				if(v2=="Alaska"){ selstate = "AK" }
				if(v2=="Arizona"){ selstate = "AZ" }
				if(v2=="Arkansas"){ selstate = "AR" }
				if(v2=="California"){ selstate = "CA" }
				if(v2=="Colorado"){ selstate = "CO" } 
				if(v2=="Connecticut"){ selstate = "CT" }
				if(v2=="Delaware"){ selstate = "DE" } 
				if(v2=="District of Columbia"){ selstate = "DC" } 
				if(v2=="Florida"){ selstate = "FL" }
				if(v2=="Georgia"){ selstate = "GA" }
				if(v2=="Hawaii"){ selstate = "HI" }
				if(v2=="Idaho"){ selstate = "ID" }
				if(v2=="Illinois"){ selstate = "IL" } 
				if(v2=="Indiana"){ selstate = "IN" }
				if(v2=="Iowa"){ selstate = "IA" } 
				if(v2=="Kansas"){ selstate = "KS" } 
				if(v2=="Kentucky"){ selstate = "KY" }
				if(v2=="Louisiana"){ selstate = "LA" }
				if(v2=="Maine"){ selstate = "ME" } 
				if(v2=="Maryland"){ selstate = "MD" }
				if(v2=="Massachusetts"){ selstate = "MA" }
				if(v2=="Michigan"){ selstate = "MI" } 
				if(v2=="Minnesota"){ selstate = "MN" }
				if(v2=="Mississippi"){ selstate = "MS" }
				if(v2=="Missouri"){ selstate = "MO" } 
				if(v2=="Montana"){ selstate = "MI" } 
				if(v2=="Nebraska"){ selstate = "NE" }
				if(v2=="Nevada"){ selstate = "NV" } 
				if(v2=="New Hampshire"){ selstate = "NH" }
				if(v2=="New Jersey"){ selstate = "NJ" } 
				if(v2=="New Mexico"){ selstate = "NM" }
				if(v2=="New York"){ selstate = "NY" } 
				if(v2=="North Carolina"){ selstate = "NC" } 
				if(v2=="North Dakota"){ selstate = "ND" }
				if(v2=="Ohio"){ selstate = "OH" } 
				if(v2=="Oklahoma"){ selstate = "OK" }
				if(v2=="Oregon"){ selstate = "OR" } 
				if(v2=="Pennsylvania"){ selstate = "PA" }
				if(v2=="Rhode Island"){ selstate = "RI" }
				if(v2=="South Carolina"){ selstate = "SC" }
				if(v2=="South Dakota"){ selstate = "SD" } 
				if(v2=="Tennessee"){ selstate = "TN" } 
				if(v2=="Texas"){ selstate = "TX" } 
				if(v2=="Utah"){ selstate = "UT" } 
				if(v2=="Vermont"){ selstate = "VT" }
				if(v2=="Virginia"){ selstate = "VA" }
				if(v2=="Washington"){ selstate = "WA" }
				if(v2=="West Virginia"){ selstate = "WV" }
				if(v2=="Wisconsin"){ selstate = "WI" } 
				if(v2=="Wyoming"){ selstate = "WY" } 
				//////////////////////
				for (var i = 0; i < form1.state.options.length; i++) {  
					if (form1.state.options[i].value==selstate){ 
						form1.state.options[i].selected=true; 
					}
				}
				document.form1.city.disabled = false;
				document.form1.state.disabled = false;				
		 	 	}
	 		}
				xmlhttp.send(null)		
				return (false);
				document.form1.city.disabled = false;
				document.form1.state.disabled = false;								
			}
			//end IE Function			
		}else{
    		document.form1.city.disabled = false;
			document.form1.state.disabled = false;				
		}
	}
}
//////////////////////////

//////////////////////////
function PHPeventCharCode(e) {
   if (e.charCode) {
     return e.charCode;
   } else {
     var key = e.keyCode;
     var ch;
     if ((key>=96)&&(key<=105)) {
       ch = key - 48;
     } else {
       var t = String.fromCharCode(key);
       if (key == 222) t="'";
       if (key == 186) t=";";
       if (key == 188) t=",";
       if (key == 190) t=".";
       if (key == 191) t="/";
       if (e.shiftKey) {
         if (t=='`') t='~';
         if (t=='1') t='!';
         if (t=='2') t='@';
         if (t=='3') t='#';
         if (t=='4') t='$';
         if (t=='5') t='%';
         if (t=='6') t='^';
         if (t=='7') t='&';
         if (t=='8') t='*';
         if (t=='9') t='(';
         if (t=='0') t=')';
         if (t=='-') t='_';
         if (t=='=') t='+';
         if (t=="'") t='"';
         if (t=='.') t='>';
         if (t==',') t='<';
       }
       ch = t.charCodeAt(0);
     }
     return ch;
   }
}
function PHPcancelEvent (e) {
  if (document.all) {
    e.cancelBubble = true;
    e.returnValue = false;
  } else {
    e.preventDefault();
    e.stopPropagation();
  }
}
function PHPisGoodArrow(key, ch) {
  return (key==9) || (key==8) || (key==46) ||
    (key==37) || (key==39);
}
function PHPisGoodAlpha(key, ch) {
  return PHPisGoodArrow(key, ch) || (key==32)
    || ((ch>=65)&&(ch<=90)) || ((ch>=97)&&(ch<=122))
    || (ch==46) || (ch==39)
    || (ch>1000);
}
function PHPisGoodNumber(key, ch) {
  return PHPisGoodArrow(key, ch)
    || ((ch>=48)&&(ch<=57));
}
function PHPisGoodHexNumber(key, ch) {
  return PHPisGoodArrow(key, ch)
    || ((ch>=48)&&(ch<=57)) ||
    ((ch >= 97) && (ch <= 102)) ||
    ((ch >= 65) && (ch <= 70));
}
function PHPisGoodExtra(key, ch) {
  return ch == 32;
}
function PHPisGoodAlphaNumber(key, ch) {
  return PHPisGoodAlpha(key, ch) ||
    PHPisGoodNumber(key, ch) ||
    PHPisGoodExtra(key, ch);
}
function PHPallowAlphas(e, dn)
{
   if (dn == (!document.all)) return;
   if (e.ctrlKey) return;
   var key = e.keyCode;
   var ch = PHPeventCharCode(e);
   if (!PHPisGoodAlpha(key, ch))
     PHPcancelEvent(e);
}
function PHPallowNumbers(e, dn)
{
   if (dn == (!document.all)) return;
   if (e.ctrlKey) return;
   var key = e.keyCode;
   var ch = PHPeventCharCode(e);
   if (!PHPisGoodNumber(key, ch))
     PHPcancelEvent(e);
}
function PHPallowHexNumbers(e, dn)
{
   if (dn == (!document.all)) return;
   if (e.ctrlKey) return;
   var key = e.keyCode;
   var ch = PHPeventCharCode(e);
   if (!PHPisGoodHexNumber(key, ch))
     PHPcancelEvent(e);
}
function PHPallowAlphaNumbers(e, dn)
{
   if (dn == (!document.all)) return;
   if (e.ctrlKey) return;
   var key = e.keyCode;
   var ch = PHPeventCharCode(e);
   if (!PHPisGoodAlphaNumber(key, ch))
     PHPcancelEvent(e);
}
function PHPtrim(s) {
  var re = /^ +| +$/g;
  return s.replace(re, '');
}
function PHPvalidateJump(obj, e, pat, ctrl) {
  var regEx = RegExp(pat);
  var val = PHPtrim(obj.value);
  if ((e.keyCode != 8) && (e.keyCode != 9) && (e.keyCode != 16)
     && (e.keyCode != 37) && (e.keyCode != 39) && (e.keyCode != 46)
     && val.match(regEx))
  {
    document.getElementById(ctrl).focus();
  }
}
function PHPverifyExtra(testRes, fld, val, pat, fldName, mes) {
  var obj = document.getElementById(fld);
  var regEx = RegExp(pat);
  if (val.match(regEx)) {
    var mesEx = RegExp('("")');
    var addMes = mes.replace(mesEx, '"'+fldName+'"');
    if (testRes.mes != '')
      testRes.mes += '\n';
    testRes.mes += addMes;
    if (!(testRes.toFocus))
      testRes.toFocus = obj;
  }
}
function PHPverifyRequired(testRes, fld, fldName, opt, validFmt,
  valuePat, valueRepl, minLen, maxLen, minVal, maxVal)
{
  var obj = document.getElementById(fld);
  var rawVal = PHPtrim(obj.value);
  var val;
  if (valuePat != '') {
    var regEx = RegExp(valuePat);
    val = rawVal.replace(regEx, valueRepl);
  } else {
    val = rawVal;
  }
  if (val != '')
    testRes.hasData = true;
  var addMes = '';
  if (opt && (val == '')) return;
  if (val == '') {
    addMes = fldName+' is required';
  }
  if ((addMes == '') && (validFmt != '')) {
    var regEx = RegExp(validFmt);
    if (!rawVal.match(regEx))
      addMes = 'Formatting of '+fldName+' is invalid';
  }
  if ((addMes == '') && (minLen > 0)) {
    if (val.length < minLen) {
      if (minLen == maxLen) {
        addMes = fldName+' should be exactly '+minLen+' symbols long';
      } else {
        addMes = fldName+' should be at least '+minLen+' symbols long';
      }
    }
  }
  if ((addMes == '') && (maxLen > 0)) {
    if (val.length > maxLen) {
      if (minLen == maxLen) {
        addMes = fldName+' should be exactly '+maxLen+' symbols long';
      } else {
        addMes = fldName+' should be '+maxLen+' symbols long or shorter';
      }
    }
  }
  if ((addMes == '') && (minVal != -1)) {
    if (val < minVal) {
      if (maxVal != -1) {
        addMes = fldName+' should be between '+minVal+' and '+maxVal;
      } else {
        addMes = fldName+' should be at least '+minVal;
      }
    }
  }
  if ((addMes == '') && (maxVal != -1)) {
    if (val > maxVal) {
      if (minVal != -1) {
        addMes = fldName+' should be between '+minVal+' and '+maxVal;
      } else {
        addMes = fldName+' should be less then '+maxVal;
      }
    }
  }
  if (addMes != '') {
    if (testRes.mes != '')
      testRes.mes += '\n';
    testRes.mes += addMes;
    if (!(testRes.toFocus))
      testRes.toFocus = obj;
    return '';
  }
  return val;
}
function PHPverifySelection (testRes, fldName, sels) {
  var good = false;
  var i;
  var f = 0;
  for (i = 0; i<sels.length; i++) {
    if (!f) f = document.getElementById(sels[i]);
    if (document.getElementById(sels[i]).checked)
      good = true;
  }
  if (good)
    testRes.hasData = true;
  if ((!good) && f) {
    if (testRes.mes != '')
      testRes.mes += '\n';
    testRes.mes += 'Please specify if '+fldName;
    if (!(testRes.toFocus))
      testRes.toFocus = f;
  }
}
function PHPverifyList (testRes, fld, fldName, bad) {
  var f = document.getElementById(fld);
  if ((f.selectedIndex < 0) || (f.options[f.selectedIndex].value == bad)) {
    if (testRes.mes != '')
      testRes.mes += '\n';
    testRes.mes += 'Please select '+fldName;
    if (!(testRes.toFocus))
      testRes.toFocus = f;
  } else
    testRes.hasData = true;
}
function PHPvalidateForm(e, emptyOK) {
  var testRes = new Object();
  testRes.mes = '';
  testRes.toFocus = 0;
  testRes.hasData = false;
  var doTest;
PHPverifyList(testRes, 'ownrent', 'Do You Own or Rent', '00');  
PHPverifyList(testRes, 'hometime', 'Time Residing', '00');
PHPverifyRequired(testRes, 'homepay', 'Home Payment', false, '', '', '', 0, 0, -1, -1);
   
PHPverifyList(testRes, 'emplytime', 'Time Employed', '00');
PHPverifyRequired(testRes, 'emplyname', 'Employer', false, '', '', '', 0, 0, -1, -1);
var theVal=PHPverifyRequired(testRes, 'wp1', 'Word Phone Area Code', false, '', '', '', 3, 3, -1, -1);
if (theVal) {
  PHPverifyExtra(testRes, 'wp1', theVal, '411|900|911|^0|^1', 'Work Phone Area Code', '"" is invalid');
}
var theVal=PHPverifyRequired(testRes, 'wp2', 'Work Phone Prefix', false, '', '', '', 3, 3, -1, -1);
if (theVal) {
  PHPverifyExtra(testRes, 'wp2', theVal, '000|411|555|911|976|^1', ' Work Phone Prefix', '"" is invalid');
}
PHPverifyRequired(testRes, 'wp3', 'Work Phone Number', false, '', '', '', 4, 4, -1, -1);
PHPverifyRequired(testRes, 'emplytitle', 'Job Title', false, '', '', '', 0, 0, -1, -1);
PHPverifyRequired(testRes, 'moninc', 'Monthly Income', false, '', '', '', 0, 0, 1200, -1);
PHPverifyList(testRes, 'bmonth', 'Birth Month', '00');
PHPverifyList(testRes, 'bday', 'Birth Day', '00');
PHPverifyList(testRes, 'byear', 'Birth Year', '00');
PHPverifyRequired(testRes, 'ssn1', 'SSN', false, '', '', '', 3, 3, -1, -1);
PHPverifyRequired(testRes, 'ssn2', 'SSN', false, '', '', '', 2, 2, -1, -1);
PHPverifyRequired(testRes, 'ssn3', 'SSN', false, '', '', '', 4, 4, -1, -1);
PHPverifyRequired(testRes, 'firstname', 'First Name', false, '', '', '', 0, 0, -1, -1);
PHPverifyRequired(testRes, 'lastname', 'Last Name', false, '', '', '', 0, 0, -1, -1);
PHPverifyRequired(testRes, 'address', 'Address', false, '', '', '', 0, 0, -1, -1);
PHPverifyRequired(testRes, 'zipcode', 'ZIP Code', false, '', '', '', 5, 5, -1, -1);
PHPverifyRequired(testRes, 'city', 'City', false, '', '', '', 0, 0, -1, -1);
PHPverifyList(testRes, 'state', 'State', '00');
PHPverifyRequired(testRes, 'email', 'Email', false, '^[^ @]+@{1}[^ @]+$', '', '', 0, 0, -1, -1);
var theVal=PHPverifyRequired(testRes, 'hm1', 'Phone Area Code', false, '', '', '', 3, 3, -1, -1);
if (theVal) {
  PHPverifyExtra(testRes, 'hm1', theVal, '411|900|911|^0|^1', 'Phone Area Code', '"" is invalid');
}
var theVal=PHPverifyRequired(testRes, 'hm2', 'Phone Prefix', false, '', '', '', 3, 3, -1, -1);
if (theVal) {
  PHPverifyExtra(testRes, 'hm2', theVal, '000|411|555|911|976|^1', 'Phone Prefix', '"" is invalid');
}

PHPverifyRequired(testRes, 'hm3', 'Phone Number', false, '', '', '', 4, 4, -1, -1);
PHPverifyList(testRes, 'ctime', 'Contact Prefrence', '00');
  if (document.all) {
    e.cancelBubble = true;
    e.returnValue = false;
  } else {
    e.preventDefault();
    e.stopPropagation();
  }
  if (testRes.toFocus && (testRes.hasData || !emptyOK)) {
    window.alert(testRes.mes);
    testRes.toFocus.focus();
	} else {
	document.forms[0].Submit.value="+++Please Wait+++";
	document.forms[0].Submit.disabled=true;
    document.forms[0].submit();
  }
}