// JavaScript Document

function Login(){
var done=0;
var username=document.login.username.value;
username=username.toLowerCase();
var password=document.login.password.value;
password=password.toLowerCase();
if (username=="homebuilder" && password=="handbook") { window.location="http://cnb-host4.clickandbuild.com/cnb/shop/insulation?listPos=&op=catalogue-products-null&prodCategoryID=10"; done=1; }
if (username=="billy" && password=="bear") { window.location="success2.html"; done=1; }
if (username=="member3" && password=="password3") { window.location="page3.html"; done=1; }
if (done==0) { alert("Invalid login!"); }
}
function Login(){
var done=0;
var username=document.login.username.value;
username=username.toLowerCase();
var password=document.login.password.value;
password=password.toLowerCase();
if (username=="homebuilder" && password=="handbook") { window.location="http://cnb-host4.clickandbuild.com/cnb/shop/insulation?listPos=&op=catalogue-products-null&prodCategoryID=10"; done=1; }
if (username=="billy" && password=="bear") { window.location="success2.html"; done=1; }
if (username=="member3" && password=="password3") { window.location="page3.html"; done=1; }
if (done==0) { alert("Invalid login!"); }
}

function popUp(sURL, sName, sWidth, sHeight)
{var win
var sProperties = 'scrollbars=yes,status=no,location=no,menubar=no,toolbar=no,resizable=no,width=' + sWidth + ',height=' + sHeight
if(win){
if (!win.closed)
{
win.focus()
win.location = sURL;
}else{
win = window.open(sURL,sName,sProperties);
win.focus()
}
}else{
win = window.open(sURL,sName,sProperties);
win.focus()
}
}
function flip(id,s,m){
 for(n=1;n<=m;n++){
    div=id+n
     n==s?sShow(div):sHide(div)
 } }
  
function sShow(div){
  if(document.getElementById){
    obj=eval("document.getElementById('"+div+"')")
    }
  else if(document.all){
    obj=eval("document.all."+div)
    }
  else if(document.layers){
    obj=eval("document.layers['"+div+"']")
    }
  !document.layers?obj.style.display='block':obj.visibility='show'
  }

function sHide(div){
  if(document.getElementById){
    obj=eval("document.getElementById('"+div+"')")
    }
  else if(document.all){
    obj=eval("document.all."+div)
    }
  else if(document.layers){
    obj=eval("document.layers['"+div+"']")
    }
  !document.layers?obj.style.display='none':obj.visibility='hidden'
  }

function validate(a,b){
pass = true
for (i=0;i<=b;i++){
if(document.getElementById(i).value==""){
alert('Please specify a value for '+ document.getElementById(i).name)
document.getElementById(i).focus()
i = b+1
pass = false
}
}
if(pass){
document.CF.submit()
}
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


startList = function() {
if (document.all&&document.getElementById) {
navRoot = document.getElementById("menunav");
for (i=0; i<navRoot.childNodes.length; i++) {
node = navRoot.childNodes[i];
if (node.nodeName=="LI") {
node.onmouseover=function() {
this.className+=" over";
  }
  node.onmouseout=function() {
  this.className=this.className.replace(" over", "");
   }
   }
  }
 }
}
window.onload=startList;

// Thermilate Tell A Friend

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_validateForm() { //v3.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (val!=''+num) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}

// Thermilate Calculator

function isNumber(numin) {
	inputLength = numin.length;

	for(var i=0; i<inputLength; i++) {
		var eachchar = numin.substring(i,i+1);	// grab each character and test
		if (! (eachchar > "0" || "9" > eachchar || eachchar == ".") ){
			return -1;
		}
	}
	return numin;
}  


function calcPaint() {

	var width = isNumber(document.paintCalcFrm.width.value);
	if (width == -1) {
		document.forms[0].width.value = 0;
		alert('You entered an invalid character.\nPlease check your form');
		width = 0;
	}

	var length = isNumber(document.paintCalcFrm.length.value);
	if (length == -1) {
	document.paintCalcFrm.length.value = 0;
		alert('You entered an invalid character.\nPlease check your form');
	length = 0;
	}

	var height = isNumber(document.paintCalcFrm.height.value);
	if (height == -1) {
		document.paintCalcFrm.height.value = 0;
		alert('You entered an invalid character.\nPlease check your form');
		height = 0;
	}
	
	var num_doors = isNumber(document.paintCalcFrm.num_doors.value);
	if (num_doors == -1) {
		document.paintCalcFrm.num_doors.value = 0;
		alert('You entered an invalid character.\nPlease check your form');
		num_doors = 0;
	}
	
	var num_windows = isNumber(document.paintCalcFrm.num_windows.value);
	if (num_windows == -1) {
		document.paintCalcFrm.num_doors.value = 0;
		alert('You entered an invalid character.\nPlease check your form');
		num_windows = 0;
	}
	
	if (document.paintCalcFrm.coats[1].checked) {
		coats = 2;
	}
	else {
		coats = 1;
	}

	feet = 2 * (height * width) + 2 * (height * length);
	feet = feet - num_doors * 15 - num_windows * 12;
	
	if (document.paintCalcFrm.ceiling.checked) {
		feet = feet + (width * length);
	}

	if (feet > 0) {
		safe_feet = feet + 25
		gallons = safe_feet * coats / 70;
		if ((gallons % 1) > 0) { // add a gallon to handle fractions
		gallons = gallons - (gallons % 1) + 1
		}
		gallons_prime = safe_feet * coats / 80;
		if ((gallons_prime % 1) > 0) { // add a gallon to handle fractions
		gallons_prime = gallons_prime - (gallons_prime % 1) + 1
		}
		safe_feet = Math.round(safe_feet);
		feet = Math.round(feet);
	}
	else {
		feet = 0;
		gallons_prime = 0;
		gallons = 0;
	}
	
}

function showCalc() {
	calcPaint();
	document.paintCalcFrm.results.value = feet;
	document.paintCalcFrm.gall_prime.value = gallons_prime;
	document.paintCalcFrm.gall_no_prime.value = gallons;
}

function formFocus() {
	document.paintCalcFrm.elements[0].focus();
}

function jumpBox(list) {
   location.href = list.options[list.selectedIndex].value
   }

//1997 All Rights Reserved, Daniel C. Peterson
//For commercial user rates please email a quote request to
//&#119&#101&#98&#109&#97&#115&#116&#101&#114&#64&#119&#101&#98&#119&#105&#110&#100&#101&#114&#46&#99&#111&#109

function compute(form)  {
   form.hours.value = (form.mhb.value * 0.2);

   } 

function ClearForm(form)  {
   form.mhb.value = "";
   form.money.value = "";
   form.hours.value = "";
   
   }


function bookmarksite(title, url){
if (document.all)
window.external.AddFavorite(url, title);
else if (window.sidebar)
window.sidebar.addPanel(title, url, "")
}