document.onkeypress =function handleEstimatorPress(evnt)
{ 

 var evnt=window.event; 
 if(evnt.srcElement.type=="text")
 {
 var keyNumber=evnt.keyCode;  
 if (keyNumber >= 48 && keyNumber <= 57 || keyNumber == 8)
				
	{ 
	  
	  return keyNumber;   //changed to keynumber to allow for Mac bug                     
	}
	  else 
	{
	  return false;                        
	}
  }
}




///////////////////////////////////////////////////////////////////////////////////////////
function changeTabs()
{  
    var prefix="Content";

    allDIVs = document.all.tags("TR");

	 for (i=0; i<allDIVs.length; i++)
	 {
	  
	  DivID=allDIVs(i).id
	  SelectDivID=DivID.indexOf(prefix);
	    if (SelectDivID != -1)
	    {	      
          eval(DivID + ".style.display='none'");   
	    } 
	 }	
}

///////////////////////////////////////////////////////////////////////
//Checks to see which tab should be visible in CombinedBasket
//9/12/99 Charles Smith Aris corporation
///////////////////////////////////////////////////////////////////////
function checkVisible()
{
if(document.all.item("topTab"))
  {
          if(Content1.style.display=="inline")
            {
            topTabImg1.src="../../images/content/basket_tab1_on.gif"
            //topTab[2].style.borderBottom="none";
            //topTab[2].style.backgroundColor="#ffffcc";
            }
          else
            {
            topTabImg1.src="../../images/content/basket_tab1_off.gif"
            //topTab[2].style.borderBottom="1 silver outset" ;
            //topTab[2].style.backgroundColor="#eee8aa";
            }
          if(Content2.style.display=="inline")
            {
            topTabImg2.src="../../images/content/basket_tab2_on.gif"
            //topTab[1].style.borderBottom="none";
            //topTab[1].style.backgroundColor="#ffffcc";
            }
          else
            {
            topTabImg2.src="../../images/content/basket_tab2_off.gif"
            //topTab[1].style.borderBottom="1 silver outset" ;
            //topTab[1].style.backgroundColor="#eee8aa";
            }
          if(Content3.style.display=="inline")
            {
            topTabImg3.src="../../images/content/basket_tab3_on.gif"
            //topTab[0].style.borderBottom="none";
            //topTab[0].style.backgroundColor="#ffffcc";
            }
          else
            {
            topTabImg3.src="../../images/content/basket_tab3_off.gif"
            //topTab[0].style.borderBottom="1 silver outset" ;
            //topTab[0].style.backgroundColor="#eee8aa";
            }
   } 
}
///////////////////////////////////////////////////////////////////////
// this function makes a single  layer visible
///////////////////////////////////////////////////////////////////////
function showTabs(a) 
{
 
  changeTabs();              //it first hides all content by calling the above function
  
	
a.style.display='inline';  

  if (event.srcElement!=null && a!="initial")//if function is called by an click event
   {      
     a.style.display=="inline"; //then makes the object whose id was passed in visible
     checkVisible();                  
   }
  else  //if event is called by a load or refresh event
    { 
      nStrReferrer=document.referrer;           //user the document.referrer object to get the URL
      posFileName=nStrReferrer.lastIndexOf('/');//get the position of the beginning of the file name
      thisProdType=document.referrer.substr(posFileName +1);//get the substring from the file name on
      var strPackingType=['boxes', 'Boxes', 'covers','Covers', 'kits', 'Kits', 'KitDetails', 'packmaterials', 'PackMaterials']//set the value to match against
      
      
      if(nStrReferrer == document.URL)
        {
         
        showThis=eval(showThisTab.innerText);
        if(showThis)
         {
          showThis.style.display="inline";
         }
        }

      if (thisProdType.indexOf('storerec') != -1)
        {
        
          Content1.style.display='inline';           //if there is a match display the Content2 element
		  //topTab[2].style.backgroundColor='#ffffcc';     //also change the tab color
		  //topTab[2].style.borderBottom="none";           //and hide the bottom border

        }
      if (thisProdType.indexOf('STGRc') != -1)
        {
          Content3.style.display='inline';           //if there is a match display the Content2 element
		  //topTab[0].style.backgroundColor='#ffffcc';     //also change the tab color
		  //topTab[0].style.borderBottom="none";           //and hide the bottom border

        }
          
      else
        {
         
         for (i=0; i<strPackingType.length; i++) //loop through the possible values
		  {
		  if (thisProdType.indexOf(strPackingType[i]) != -1)//insert each value into the search string
		    {
			  
			  Content2.style.display='inline';        //if there is a match display the Content2 element
			  //topTab[1].style.backgroundColor='#ffffcc';  //also change the tab color
			  //topTab[1].style.borderBottom="none";        //and hide the bottom border
			}
		  
		  }

       }
     
    }
  checkVisible();   
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Sends estimator calculations to the opening window
///////////////////////////////////////////////////////////////////////
function sendCalc(a)
{
var indexSize;
var thisCubeFeet=a;
var sizeImgSrc
var indexSize
var sizeText
var thisSqareFeet
var numSTG
var numTrucks
var rndSTG
var rndTrucks

              
if (a != 0)
  {
    thisSquareFeet = a / 6;
	numTrucks = a/800;
	numSTG = a/280;
	rndSTG = Math.ceil(numSTG)
	rndTrucks = Math.ceil(numTrucks);
   }
   
if (a == 0 || a == "undefined")
   {
    thisSquareFeet=0   ///initialize variables when page loads
    thisCubeFeet =0;
	numTrucks = 0;
	numSTG = 0;
	rndSTG = 0;
	rndTrucks = 0;
	sizeText="none";
   }    
   
if (rndTrucks < 11 && rndSTG < 30 && thisSquareFeet < 7920)
{

   truckCounter.innerText = rndTrucks;
   STGCounter.innerText = rndSTG;
 
   if (thisSquareFeet == 0)
   {
	indexSize=0;
   } 
   if (thisSquareFeet > 0 && thisSquareFeet < 36)
   {
	indexSize=0;
	sizeText="extra small"
		      
   } 
   else if (thisSquareFeet > 35 && thisSquareFeet < 61)
   {  
	indexSize=1
	sizeText="small"
   } 
   else if (thisSquareFeet > 60 && thisSquareFeet < 89)
   {  
	 indexSize=2
	 sizeText="medium small"
   } 
   else if (thisSquareFeet > 88 && thisSquareFeet < 126)
   {  
	 indexSize=3
	 sizeText="medium"
   } 
   else if (thisSquareFeet >125 && thisSquareFeet < 176)
   {  
	 indexSize=4
	 sizeText="medium large"
   } 
   else if (thisSquareFeet > 175 && thisSquareFeet < 251)
   {  
	 indexSize=5
	 sizeText="large"
   } 
   else if (thisSquareFeet > 250 && thisSquareFeet < 401)
   {  
	 indexSize=6
	 sizeText="extra large"
   } 
   else if (thisSquareFeet > 400 && thisSquareFeet < 7920)
   {  
	 indexSize=7
	 sizeText="bulk"
   } 
   
  thisCubeFeet=thisCubeFeet.toString();                 //convert to string
  var beginCalc=thisCubeFeet.indexOf(".");          
  thisCubeFeet=thisCubeFeet.slice(0, (beginCalc + 3));  //round to 2 decimals
  
  
  thisSquareFeet=thisSquareFeet.toString();                 //convert to string
  var beginSqftCalc=thisSquareFeet.indexOf(".");          
  thisSquareFeet=thisSquareFeet.slice(0, (beginSqftCalc + 3));  //round to 2 decimals
                      
  
  
  Counter.innerText= thisCubeFeet  
  storageCounter.innerHTML = "<nobr>" + sizeText + "</nobr>";
  sqftCounter.innerText = thisSquareFeet;

 }
else
 {
   alert("Please contact Maximus for more information on bulk storage.")
 }
  
 if (window.opener !=null)
 {
 	var sWindow = window.opener
	//If the opener document have an object called StoreUnitSpec ?
	if (sWindow.document.StoreUnitSpec !=null)
	 {
  		sWindow.document.StoreUnitSpec.STRSizeList.selectedIndex=indexSize;
  		sWindow.document.StoreUnitSpec.EstSqFeet.value=thisSquareFeet;
	 }
 } 
  
}

function calculateFeet()
{ 
  var calcNumber=0
  var SubTotal=0
  var newSubTotal=0; 
  allInputs = document.all.tags("input");      
  for (i=0; i<allInputs.length; i++)
    {
        var valInput=allInputs[i].value;
        if(isNaN(valInput))
          {
            valInput=0;
            alert("please enter a valid number")
          }
        var inputName=allInputs[i].name
        var beginCalc=inputName.indexOf(",");
        calcNumber=inputName.slice(beginCalc + 1);
        calcNumber=Number(calcNumber);   
        valInput=valInput * calcNumber;
        SubTotal=valInput;
		newSubTotal=newSubTotal + SubTotal;
	  
    } 
  //newSubTotal=Math.round(newSubTotal);
 // Counter.innerText= newSubTotal
  
  sendCalc(newSubTotal);          ///send value to calling page 	          
}




