
var D=document, W=window;

function OnAsk(){
var F=D.F;

if (!CheckInputData(F)) return false;

getbyid('sending').style.visibility='visible';
ShowWaitCursor(F);
return CommonSubmit(F, "submit");
}

function OnComment(){
var F=D.F;

if (!CheckInputData(F, '-url')) return false;
if (!CheckEmail(F.email)) return false;

getbyid('sending').style.visibility='visible';
ShowWaitCursor(F);
return CommonSubmit(F, "submit");
}

function ShowWaitCursor(F, bRestore){
var i, aCh, Cursor=(!bRestore ? 'wait' : '');

F.style.cursor=Cursor; aCh=F.childNodes;
for(i=0; i<aCh.length; i++){
	if (aCh[i].nodeType!=1) continue;
	aCh[i].style.cursor=Cursor;
	}

aCh=F.getElementsByTagName('INPUT');
for(i=0; i<aCh.length; i++) aCh[i].style.cursor=Cursor;
}

function getbyid(id){return D.getElementById(id);}

function ThankYou(){

ShowWaitCursor(D.F, true);
//D.F.style.display='none'; //display='none';
getbyid("ThankYou").style.display='inline';
getbyid('sending').style.display='none';
//W.CommentTarget.location.href='about:blank';
window.CommentTarget.location.replace("about:blank");
//D.F.submit.disabled=false;
}

function CommonSubmit(F, Button){

_F=(!F ? W.F : F);
if (!Button) Button='Submit';
setTimeout("_F."+Button+".disabled=true; W.focus();", 1);
//setTimeout("_F."+Button+".disabled=false;", 15000);

return true;
}

function SetCalcState(){
//Auto select state

//Only when not yet
if (F.CalcState.value) return;
if (W.StateAbbr==null){
	setTimeout("SetCalcState()", 100); return;
	}
F.CalcState.value=W.StateAbbr;
}

function OnCalc(){

//If any then check
if (F.zip.value!=''){	
	if (!ValidateForm(F)) return false;
	}
else if (!F.CalcState.value) return false;

if (!F.Footage.value){
	alert('Please enter square footage'); F.Footage.focus(); return false;
	}

return CommonSubmit(F, "submit");
}

function SetText(o, Txt){o.firstChild.data=Txt;} 

function ShowBuildCost(Cost, StateAbbr, ErrMsg){
var oTD=getbyid('CostTD'), oTR, A, HRef, p;

if (!W.F) return;
F.submit.disabled=false;
if (StateAbbr) F.CalcState.value=StateAbbr;

if (ErrMsg){
	SetText(oTD, '-'); alert(ErrMsg);
	}
else{
	oTR=getbyid('CostTR');
	oTR.style.display=(IEVer ? 'block' : 'table-row-group');
	SetText(oTD, '$'+Cost);
	A=getbyid('CostLink'); HRef=A.href; p=HRef.lastIndexOf('=');
	A.href=HRef.substr(0, p+1)+F.CalcState.value;
	}
}

function ClearZip(){
if (F.CalcState.value) F.zip.value='';
}

function ClearState(){
F.CalcState.value='';
}
