// JavaScript Document

     document.getElementById("F1").focus()

function hilite(cellid)   // *******   this function hilites cell with focus on it    ******************
        				 { 
        document.getElementById(cellid).style.backgroundColor="yellow"       // document.all[cellid]
		                  }    
function lolite(cellid)   // *******   this function UN-hilites cell that's lost focus    ******************
                          { 
        document.getElementById(cellid).style.backgroundColor="white"       
		                   }    


 function fiverF1()    { 
  if (document.getElementById("cup").value >=  0  &&  document.getElementById("cup").value <=  9 )  {  return   }
            else
           	 { ( document.getElementById("cup").value = 0 ) }
						}
 function fiverF2()    { 
  if (document.getElementById("adul").value >=  0  &&  document.getElementById("adul").value <=  9 )  {  return   }
            else
           	 { ( document.getElementById("adul").value = 0 ) }
						}
 function fiverF3()    { 
  if (document.getElementById("boyteen").value >=  0  &&  document.getElementById("boyteen").value <=  9 )  {  return   }
            else
           	 { ( document.getElementById("boyteen").value = 0 ) }
						}
 function fiverF4()    { 
  if (document.getElementById("girlteen").value >=  0  &&  document.getElementById("girlteen").value <=  9 )  {  return   }
            else
           	 { ( document.getElementById("girlteen").value = 0 ) }
						}
 function fiverF5()    { 
  if (document.getElementById("infboy").value >=  0  &&  document.getElementById("infboy").value <=  9 )  {  return   }
            else
           	 { ( document.getElementById("infboy").value = 0 ) }
						}
 function fiverF6()    { 
  if (document.getElementById("infgirl").value >=  0  &&  document.getElementById("infgirl").value <=  9 )  {  return   }
            else
           	 { ( document.getElementById("infgirl").value = 0 ) }
						}


// ***** ************* ************* ************* *************
 function Calcfunc()  {

 shbr =   " category A = shared room rate"
 onebr =  "  category B = 1 bedroom"
 twobr =  "  category C = 2 bedrooms"
 threbr = "  category D = 3 bedrooms"
 fourbr = "  category E = 4 bedrooms"
 fivebr = "  category F = 5 bedrooms"
 sixbr =  "  category G = 6 bedrooms"


  if ( document.getElementById("fastlane").selectedIndex == 0  || document.getElementById("fastlane").selectedIndex == 3 )   
	  	{ (document.getElementById("F7").value = onebr ) ; blanker() ;  return   }  

 if ( document.getElementById("fastlane").selectedIndex == 1  ||  document.getElementById("fastlane").selectedIndex == 4 ||  document.getElementById("fastlane").selectedIndex == 2  )   
  		{ (document.getElementById("F7").value = shbr ) ; blanker() ;  return   }  
  if ( document.getElementById("fastlane").selectedIndex == 5  ||  document.getElementById("fastlane").selectedIndex == 6 )   
	  	{ (document.getElementById("F7").value = onebr ) ; blanker() ;  return   }  
 if ( document.getElementById("fastlane").selectedIndex == 7   )   
	  	{ (document.getElementById("F7").value = " no household description selected")    }   //  don't return/exit
 
 
 rooms = 0 ; room_msg = "room_msg" ; punits = 0 ; people  = 0 
 cups =  0 ; aduls =  0 ; boyteens = 0 ; girlteens = 0 ;  infboys =  0 ; infgirls =  0
 spareboyteen = 0 ; btrms = 0 ; sparegirlteen = 0 ; gtrms = 0
 spareinfboy = 0 ; ibrms = 0 ; spareinfgirl = 0 ;  igrms = 0 
 
   cups = document.getElementById("cup").value ; people = cups * 2 

   aduls = document.getElementById("adul").value ; people = ( people + aduls )

  boyteens = document.getElementById("boyteen").value ; people = ( people + boyteens )
	if ( boyteens  == 1 ) spareboyteen = 1 
	 if ( boyteens  == 2 ) btrms = 1 
      if ( boyteens  == 3 ) { (spareboyteen = 1) ;  (btrms = 1) }
       if ( boyteens  == 4 )  btrms = 2
        if ( boyteens  == 5 ) { (spareboyteen = 1) ;  (btrms = 2) }
         if ( boyteens  == 6 )  btrms = 3
           if ( boyteens  == 7 ) { (spareboyteen = 1) ;  (btrms = 3) }
            if ( boyteens  == 8 )  btrms = 4
             if ( boyteens  == 9 ) { (spareboyteen = 1) ;  (btrms = 4) }
				if ( boyteens  == 10 )  btrms = 5

  girlteens = document.getElementById("girlteen").value; people = ( people + girlteens )
	if ( girlteens  == 1 ) sparegirlteen = 1 
	 if ( girlteens  == 2 ) gtrms = 1 
      if ( girlteens  == 3 ) { (sparegirlteen  = 1 ) ; (gtrms = 1 ) }
	   if ( girlteens  == 4 ) gtrms = 2 
        if ( girlteens  == 5 ) { (sparegirlteen  = 1 ) ; (gtrms = 2 ) }
	     if ( girlteens  == 6 ) gtrms = 3 
          if ( girlteens  == 7 ) { (sparegirlteen  = 1 ) ; (gtrms = 3 ) }
	       if ( girlteens  == 8 ) gtrms = 4 
            if ( girlteens  == 9 ) { (sparegirlteen  = 1 ) ; (gtrms = 4 ) }
	          if ( girlteens  == 10 ) gtrms = 5 

  infboys = document.getElementById("infboy").value ; people = ( people + infboys )
	if ( infboys  == 1 ) spareinfboy = 1 
	 if ( infboys  == 2 ) ibrms = 1 
      if ( infboys  == 3 ) { (spareinfboy  = 1 ) ; (ibrms = 1 ) }
	   if ( infboys  == 4 ) ibrms = 2 
        if ( infboys  == 5 ) { (spareinfboy  = 1 ) ; (ibrms = 2 ) }
	     if ( infboys  == 6 ) ibrms = 3 
          if ( infboys  == 7 ) { (spareinfboy  = 1 ) ; (ibrms = 3 ) }
	       if ( infboys  == 8 ) ibrms = 4 
            if ( infboys  == 9 ) { (spareinfboy  = 1 ) ; (ibrms = 4 ) }
	         if ( infboys  == 10 ) ibrms = 5 

  infgirls = document.getElementById("infgirl").value ; people = ( people + infgirls )
	if ( infgirls  == 1 ) spareinfgirl = 1 
	 if ( infgirls  == 2 ) igrms = 1 
      if ( infgirls  == 3 ) { (spareinfgirl  = 1 ) ; (igrms = 1 ) }
	   if ( infgirls  == 4 ) igrms = 2 
        if ( infgirls  == 5 ) { (spareinfgirl  = 1 ) ; (igrms = 2 ) }
	     if ( infgirls  == 6 ) igrms = 3 
          if ( infgirls  == 7 ) { (spareinfgirl  = 1 ) ; (igrms = 3 ) }
	       if ( infgirls  == 8 ) igrms = 4 
            if ( infgirls  == 9 ) { (spareinfgirl  = 1 ) ; (igrms = 4 ) }
	         if ( infgirls  == 10 ) igrms = 5 

//*****  start Adding up
  rooms =  (cups / 1) + (aduls / 1) + (btrms / 1) + (gtrms / 1) + (ibrms / 1) + (igrms / 1) 
 
 if ( spareboyteen == 1 && spareinfboy  == 1 )  { 
    ( rooms = rooms + 1 ) ; ( spareboyteen = 0 ) ; ( spareinfboy = 0 )
        }
 if ( sparegirlteen == 1 && spareinfgirl  == 1 )  { 
    ( rooms = rooms + 1 ) ; ( sparegirlteen = 0 ) ; ( spareinfgirl = 0 )
        }
 if (  spareinfboy  == 1  && spareinfgirl  == 1 )  { 
    ( rooms = rooms + 1 ) ; ( spareinfgirl = 0 ) ; ( spareinfboy = 0 )
        }
 
//*****  catch that xgender over count (1) [ 1cup, 3 boys 7,9,12 1 girl 8 ] 
 if ( sparegirlteen == 1 && spareinfboy  == 1  && igrms > 0 )  { 
    ( rooms = rooms + 1 ) ; ( sparegirlteen = 0 ) ; ( spareinfboy = 0 )  }
//*****  catch that xgender over count (2) [ 1cup, 3 girls 7,9,12 1 boy 8 ] 
 if ( spareboyteen == 1 && spareinfgirl  == 1  && ibrms > 0 )  { 
    ( rooms = rooms + 1 ) ; ( spareboyteen = 0 ) ; ( spareinfgirl = 0 )  }

  if ( spareboyteen == 1 )  { ( rooms = rooms + 1 ) ; ( spareboyteen = 0 )   }
  if ( sparegirlteen == 1 ) { ( rooms = rooms + 1 ) ; ( sparegirlteen = 0 )  }
  if ( spareinfboy == 1 )   { ( rooms = rooms + 1 ) ; ( spareinfboy = 0 )    }
  if ( spareinfgirl == 1 )  { ( rooms = rooms + 1 ) ; ( spareinfgirl = 0 )   }

      //*****  display Ans
 if ( rooms == 0 ) ( room_msg = " no household description selected") 

 if ( rooms == 1 ) ( room_msg = onebr ) 
 if ( rooms == 2 ) ( room_msg = twobr ) 
 if ( rooms == 3 ) ( room_msg = threbr ) 
 if ( rooms == 4 ) ( room_msg = fourbr ) 
 if ( rooms == 5 ) ( room_msg = fivebr ) 
 if ( rooms  > 5 ) ( room_msg = fivebr )  // capped

	// ***** xtra xtra validation  *****   *****   *****   *****    *****   *****   *****

 if ( cups == 1  && aduls == 0 && boyteens  == 0 && girlteens  == 0 && infboys == 0 && infgirls == 0 ) 
 							{ room_msg = " select one of the basic households" }
  if ( cups == 0  && aduls == 1 && boyteens  == 0 && girlteens  == 0 && infboys == 0 && infgirls == 0 ) 
 							{ room_msg = " select one of the basic households" }
  if ( cups == 0  && aduls == 0 && boyteens  > 0  ) 
 							{ room_msg = " this household needs some adults" }
  if ( cups == 0  && aduls == 0 && girlteens  > 0  ) 
 							{ room_msg = " this household needs some adults" }
  if ( cups == 0  && aduls == 0 && infboys  > 0  ) 
 							{ room_msg = " this household needs some adults" }
  if ( cups == 0  && aduls == 0 && infgirls  > 0  ) 
 							{ room_msg = " this household needs some adults" }


 	   document.getElementById("F7").value =  room_msg    //  rooms   //   "9"       
   }
//  *********  end of Calcfunc *****************

 function blanker()    {  
    document.getElementById("cup").value = 0 ;  document.getElementById("adul").value = 0
    document.getElementById("boyteen").value = 0 ;  document.getElementById("girlteen").value = 0
    document.getElementById("infboy").value = 0 ;  document.getElementById("infgirl").value = 0
				   }  

