//// NEW WINDOWS


function live(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=510,height=460,left=350,top = 150');");
}

function print(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=800,height=900,left=250,top = 150');");
}

function popSponsor(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=600,height=400,left = 300,top = 200');");
}

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');");
}

function results(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'titlebar=no,toolbar=no,scrollbars=yes,directories=no,location=no,statusbar=no,menubar=no,resizable=no,width=510,height=460,left=350,top = 150');");
}

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;
 }
}


// ADD COMMAS

function format(input){
var num = input.value.replace(/\,/g,'');
if(!isNaN(num)){
if(num.indexOf('.') > -1){ 
num = num.split('.');
num[0] = num[0].toString().split('').reverse().join('').replace(/(?=\d*\.?)(\d{3})/g,'$1,').split('').reverse().join('').replace(/^[\,]/,'');
if(num[1].length > 2){ 
alert('You may only enter two decimals!');
num[1] = num[1].substring(0,num[1].length-1);
} input.value = num[0]+'.'+num[1]; 
} else{ input.value = num.toString().split('').reverse().join('').replace(/(?=\d*\.?)(\d{3})/g,'$1,').split('').reverse().join('').replace(/^[\,]/,'') };
}
else{ alert('You may enter only numbers in this field!');
input.value = input.value.substring(0,input.value.length-1);
}
}

