function ShowForm(){document.getElementById("pnlForm").style.display="block"}function RoundTo(a,b){b=Math.pow(10,b);return d=Math.round(a*b)/b}window.addEventListener("load",SetScroll,false);function SetScroll(){window.scrollTo(0,1)}function CommaFormat(a){a+="";x=a.split(".");x1=x[0];x2=x.length>1?"."+x[1]:"";for(a=/(\d+)(\d{3})/;a.test(x1);)x1=x1.replace(a,"$1,$2");return x1+x2}
function SetInput(){var a=document.createElement("input");a.setAttribute("type","number");for(var a=a.type!="text",b=document.getElementsByTagName("input"),c=0;c<b.length;c++)if(b[c].type=="text"){if(b[c].className=="Num")b[c].onkeypress=CheckMetric;else if(b[c].className=="Imp")b[c].onkeypress=CheckImperial;if(a)b[c].type="number"}SetupStorage()}var inputProbs=0;if(top!=self)top.location=self.document.location;
function CheckMetric(a){var b=document.all?event.srcElement:a.target,c=document.all?event.keyCode:a.which;if(c>47&&c<58||c==8)return true;if(b.id.indexOf("_")==0&&c==46&&b.value.indexOf(".")==-1)return true;inputProbs++;inputProbs%5==0&&alert("Use Numeric Keypad\n\n0 to 9"+(b.id.indexOf("_")==0?" and .":""));if(document.all)return false;else a.preventDefault()}
function CheckImperial(a){var b=document.all?event.srcElement.value:a.target.value,c=document.all?event.keyCode:a.which;if(c>47&&c<58||c==8)return true;if(c==46&&b.indexOf(".")==-1&&b.length>0)return true;if(c==32&&b.substring(b.length-1)!=" "&&b.length>0)return true;if(c==47&&b.indexOf("/")==-1&&b.length>0)return true;inputProbs++;inputProbs%5==0&&alert("Use Numeric Keypad\n\n eg: 12 1/2 ~ 12 1 2 ~ 12.5");if(document.all)return false;else a.preventDefault()}var dloc=document.location.toString().toLowerCase();
(dloc.indexOf("blocklayer.mobi")==-1&&dloc.indexOf("localhost")==-1||dloc.indexOf("file:")>-1)&&location.replace("http://blocklayer.mobi");function LogRun(a,b){(new Image).src="http://www.blocklayer.com/Logger.ashx?p="+b+"&a="+a}function ConvertTo32nds(a){if(a.length==0)return 0;if(a.indexOf(".")>-1)return a*32;else{a.indexOf("/")>-1&&(a=a.replace("/"," "));var b=a.split(" ");if(b.length==1)return a*32;if(b.length==2)return 32/b[1]*b[0];if(b.length==3)return a=b[0]*32,a+=32/b[2]*b[1],a}return 0}
function ConEng(a,b){if(a==0)return"0";var c=Math.round(a),e=0,g=0,e=0,h=32,f="";c>=384&&b&&(e=Math.floor(c/384),c-=e*384,f+=e.toString()+"'");var i=false;c>=32&&(g=Math.floor(c/32),c-=g*32,f+=g.toString(),i=true);if(Math.floor(c)>0){i=true;g>0&&(f+="~");e=Math.floor(c);for(h=32;e%2==0&&e>1&&e<32;)e/=2,h/=2;f+=e.toString()+"/"+h.toString()}i&&(f+='"');return f}
function GetState(){for(var a="",b=document.getElementById("form1"),c=0;c<b.length;c++){var e=b[c];e.type=="text"||e.type=="number"?a+=e.value==""?"0,":e.value.replace(/\s+/g,"_")+",":e.type=="radio"||e.type=="checkbox"?a+=(e.checked?"1":"0")+",":e.type=="select-one"&&e.id!="ddJobs"&&(a+=e.selectedIndex+",")}return a=a.substring(0,a.length-1)}
function RestoreFromQs(){var a=document.location.toString();a.indexOf("?frm=")>-1&&(a=a.substring(a.indexOf("?frm=")+5),a.indexOf("&")>-1&&(a=a.substring(0,a.indexOf("&"))),RestoreState(a))}
function RestoreState(a){if(a!=null&&a.length>0)for(var a=a.split(","),b=0,c=document.getElementById("form1"),e=0;e<c.length;e++)if(c[e].type=="text"||c[e].type=="number")c[e].value=a[b++].replace(/_+/g," ");else if(c[e].type=="radio"||c[e].type=="checkbox")c[e].checked=a[b++]=="1"?"true":"";else if(c[e].type=="select-one"&&c[e].id!="ddJobs")c[e].selectedIndex=a[b++]}
function SendStateLink(){var a=document.location.toString();a.indexOf("?")>-1&&(a=a.substring(0,a.indexOf("?")));a.indexOf("#")>-1&&(a=a.substring(0,a.indexOf("#")));GetState().length>1?window.open("SendLink.aspx?pg="+a+"&frm="+GetState()+"&ttl="+document.title):window.open("SendLink.aspx?pg="+a+"&ttl="+document.title)}
function ParseCheck(a,b,c,e){if(b.value=="")return alert(a+" Value Required"),-1;b=parseFloat(b.value);if(isNaN(b))return alert(a+" Numbers Only"),-1;else if(b<c)return alert(a+" Must be larger than or = "+c),-1;else if(b>e)return alert(a+" Must be smaller than or = "+e),-1;return b}
function ShowQR(){var a=document.location.toString();a.indexOf(".aspx")!=a.length-5&&(a=a.substring(0,a.indexOf(".aspx")+5));var b=GetState();b.length>0&&(a+="?frm="+b);var b=a.length<180?"200x200":"300x300",c=new Image;c.src="http://chart.apis.google.com/chart?cht=qr&chs="+b+"&chl="+a;document.getElementById("spnQRf").appendChild(c);document.getElementById("divQRf").style.display="block"}
function LargeRun(a){a=a.innerHTML.replace(/\s+/g,"").replace(/'+/g,"f").replace(/"+/g,"i");window.open("rundisplay.aspx?r="+a)}function ShowTwitter(){var a=window.location.toString()+(window.location.toString().indexOf("?")>-1?"&r=t":"?r=t");window.open("http://twitter.com/share?url="+escape(a),null,"height=400,width=600,scrollbars=0,resizable=1,status=0,toolbar=0,menubar=0,location=0").focus()}
function LinkedInShare(){var a=window.location.toString()+(window.location.toString().indexOf("?")>-1?"&r=li":"?r=li"),a="http://www.linkedin.com/shareArticle?mini=true&url="+escape(a)+"&title="+escape("Blocklayer.mobi Mobile Construction Calculators")+"&summary="+escape(document.title)+"&source="+escape("Blocklayer.com");window.open(a,null,"height=400,width=600,scrollbars=0,resizable=1,status=0,toolbar=0,menubar=0,location=0").focus()}
function SetupStorage(){var a=GetLoc().toLowerCase();if(a.indexOf("concrete.a")==-1&&a.indexOf("concreteeng")==-1&&HasStorage())document.getElementById("divStorage").style.display="block",GetJobs()}function SaveJob(){var a=prompt("Save Current Input Values this Page as:","");if(a.length>0){var b=GetState();b.length>2&&(localStorage.setItem(GetLoc()+";"+a,b),GetJobs())}}
function GetJobs(){if(localStorage.length>0){for(var a=GetLoc(),b=0,c=document.getElementById("ddJobs").options.length=0;c<localStorage.length;c++)localStorage.key(c).substring(0,localStorage.key(c).indexOf(";"))==a&&(document.getElementById("ddJobs").options[b++]=new Option(localStorage.key(c).substring(localStorage.key(c).indexOf(";")+1)));document.getElementById("divJobs").style.display=b>0?"block":"none"}}
function DeleteJob(){confirm("Delete "+document.getElementById("ddJobs").value)&&(localStorage.removeItem(GetLoc()+";"+document.getElementById("ddJobs").value),GetJobs())}
function DeleteAllJobsPage(){if(confirm("Delete all Jobs This Page?")&&localStorage.length>0){for(var a=GetLoc(),b=0;b<document.getElementById("ddJobs").length;b++)localStorage.removeItem(a+";"+document.getElementById("ddJobs").options[b].value);document.getElementById("ddJobs").options.length=0;document.getElementById("divJobs").style.display="none"}}
function DeleteAllJobsSite(){if(confirm("Clear all saved jobs this site?"))localStorage.clear(),document.getElementById("ddJobs").options.length=0,document.getElementById("divJobs").style.display="none",alert("All Jobs Removed")}
function GetJob(){try{RestoreState(localStorage.getItem(GetLoc()+";"+document.getElementById("ddJobs").value))}catch(a){alert("Failed to load form data");return}typeof theForm=="undefined"?Calculate():alert("Form has been re-filled with saved data from job "+document.getElementById("ddJobs").value+"\n\nHit 'Calc' to re-calculate")}function GetLoc(){var a=document.location.toString();return a.substring(a.indexOf("www.")>-1?11:7,a.indexOf(".aspx")+5)}
function HasStorage(){try{return"localStorage"in window&&window.localStorage!==null}catch(a){return false}};
