//COPY FIELDS

function CopyFields(f) {
  if(f.same.checked == true) {
  	if (f.state.value !=='Texas'){
  	alert('We Are Only Licensed To Preform Inspections In Texas');
  	}
    else {
	    f.PAddress.value = f.street.value;
	    f.PCity.value = f.city.value;
	    f.PZip.value = f.zip.value;
	    }
  }
    else if (f.same.checked == false) {
    f.PAddress.value = '';
    f.PCity.value = '';
    f.PZip.value = '';
  }
}


function autoTab(element, nextElement) {
    if (element.value.length == element.maxLength && nextElement != null) {
        element.form.elements[nextElement].focus();
    }
}



//// NEW WINDOWS


function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'titlebar=no,toolbar=no,scrollbars=no,directories=no,location=no,statusbar=no,menubar=no,resizable=no,width=350,height=250,left = 515,top = 259');");
}

function popformwhatsthis(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=400,height=255,left = 515,top = 259');");
}

function forgot(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=300,height=110,left = 540,top = 234');");
}


var newwindow;
function pop(url)
{
	
	newwindow=window.open(url,'name','height=200,width=200');
	if (window.focus) {newwindow.focus()}
}




var win = null;
function NewWindow(mypage,myname,w,h,scroll){
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
settings =
'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable'
win = window.open(mypage,myname,settings)

if (window.focus) {NewWindow.focus()}


}



///SHOW HIDE DIVS

function showHide(inID) {
     if (document.getElementById(inID).style.display == 'none') {
          document.getElementById(inID).style.display = 'block';
     } else {
          document.getElementById(inID).style.display = 'none';
     }
}

function Show(inID) {
     if (document.getElementById(inID).style.display == 'none') {
          document.getElementById(inID).style.display = 'block';
     } else {
          document.getElementById(inID).style.display = 'block';
     }
}

function Hide(inID) {
     if (document.getElementById(inID).style.display == 'block') {
          document.getElementById(inID).style.display = 'none';
     } else {
          document.getElementById(inID).style.display = 'none';
     }
}

// AGREE SUBMIT

function ButtonCheck(f) {
  if(f.agree.checked == false) {
  	alert('We Are Only Licensed To Preform Inspections In Texas');
  	}
  	}
	
	
var checkobj

function agreesubmit(el){
checkobj=el
if (document.all||document.getElementById){
for (i=0;i<checkobj.form.length;i++){  //hunt down submit button
var tempobj=checkobj.form.elements[i]
if(tempobj.type.toLowerCase()=="submit")
tempobj.disabled=!checkobj.checked
}
}
}

function defaultagree(el){
if (!document.all&&!document.getElementById){
if (window.checkobj&&checkobj.checked)
return true
else{
alert("Please read/accept terms to submit form")
return false
}
}
}

// PHONE

function formatTelNo (telNo)
{
if (telNo.value == "") return;

var phone = new String (telNo.value);

phone = phone.substring(0,14);

if (phone.match (".[0-9]{3}.[0-9]{3}-[0-9]{4}") == null)
{

if (phone.match (".[0-9]{2}.[0-9]{3}-[0-9]{4}|" + ".[0-9].[0-9]{3}-[0-9]{4}|" +
".[0-9]{3}.[0-9]{2}-[0-9]{4}|" + ".[0-9]{3}.[0-9]-[0-9]{4}") == null)
{

var phoneNumeric = phoneChar = "", i;
for (i=0;i<phone.length;i++)
{
phoneChar = phone.substr (i,1);

if (!isNaN (phoneChar) && (phoneChar != " ")) phoneNumeric = phoneNumeric + phoneChar;
}

phone = "";
for (i=0;i<phoneNumeric.length;i++)
{
if (i == 0) phone = phone + "(";
if (i == 3) phone = phone + ") ";
if (i == 6) phone = phone + "-";
phone = phone + phoneNumeric.substr (i,1)
}
}
}
else
{ 
phone = "(" + phone.substring (1,4) + ") " + phone.substring (5,8) + "-" + phone.substring(9,13); 
}
if (phone != telNo.value) telNo.value = phone;
}

function checkTelNo (telNo)
{
if (telNo.value == "") return;
if (telNo.value.match (".[0-9]{3}.[0-9]{3}-[0-9]{4}") == null)
{
if (telNo.value.match ("[0-9]{10}") != null)
formatTelNo (telNo) 
}
}

function checkEnterForFindListing(e){ 
var characterCode;

if(e && e.which){ 
e = e;
characterCode = e.which ;
}
else{
e = event;
characterCode = e.keyCode; 
}

if(characterCode == 13){ //13 = the code for pressing ENTER 
document.forms[getNetuiTagName("findListingForm")].submit();
return false; 
}
else{
return true ;
}

}

function age(bDay){
 now = new Date()
 bD = bDay.value.split('-');
 if(bD.length==3){
   born = new Date( bD[2],bD[0], bD[1]*1-1 );
   years = Math.floor((now.getTime() - born.getTime()) / (365.25 * 24 * 60 * 60 * 1000));
   document.getElementById('age').value = years;
 }
}