// JavaScript Document

     document.getElementById("BAAFC1").focus()
// *******   ******************  ******************    ******************

function Resetfunc()
	{
   document.getElementById("wbcForm1").reset() ; document.getElementById("BAAFC1").value = "0.00" ; document.getElementById("BAAFC4").value = "0.00"
    document.getElementById("BAAFC22").value = "0.00" ; document.getElementById("BAAFC30").selectedIndex = 2 
	}

function valit(obj, lowval, hival) 
  { 
 valmsg = "xxxx" ;  // **** set up variable valmsg
 
 if (obj == document.getElementById("BAAFC3")) 
	(valmsg = "Rent free weeks can't really exceed maximum of 52");

 if ((obj.value < lowval) || (obj.value > hival))
				alert(valmsg)   //***  whatever msg you want !
//   *  Call me with ----- onChange="valit(this, 18, 99)"
   }

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"       
	                   }    

// ****** ******    Not needed after Nov 09   ****** ****** 
function DoCB()        { }

function CAsafenet()        {    
    if (document.getElementById("BAAFC7").selectedIndex == 0 && document.getElementById("BAAFC13").selectedIndex == 1 ) document.getElementById("BAAFC13").selectedIndex = 0 
    if (document.getElementById("BAAFC7").selectedIndex == 0 && document.getElementById("BAAFC13").selectedIndex == 3 ) document.getElementById("BAAFC13").selectedIndex = 0 
    if (document.getElementById("BAAFC7").selectedIndex == 0 && document.getElementById("BAAFC13").selectedIndex == 5 ) document.getElementById("BAAFC13").selectedIndex = 0 
			      }

function chkdskds()        {    
  allkds = (document.getElementById("BAAFC14").value / 1) + (document.getElementById("BAAFC16").value / 1)
  if (document.getElementById("BAAFC17").value > allkds) document.getElementById("BAAFC17").value = allkds 
		}


// ****** this func stops   ***** Back50List   LabelBack50
function chk50()        {    
  if (document.getElementById("BAAFC8").value < 50) { (document.getElementById("BAAFC31").selectedIndex = 0) ; (document.getElementById("LabelBack50").style.color = "lightgrey") }  
	else
		document.getElementById("LabelBack50").style.color = "black"
	}

function knownPClock()        {    
  if (document.getElementById("BAAFC8").value < 60) { (document.getElementById("BAAFC44").value = 0) ; (document.getElementById("LabelknownPC").style.color = "lightgrey") }  
		else
     document.getElementById("LabelknownPC").style.color = "black"
	}


function nojob()        {    
  if (document.getElementById("BAAFC22").value < 9 && document.getElementById("BAAFC23").value < 9 ) document.getElementById("BAAFC30").selectedIndex = 2  
		else
      document.getElementById("BAAFC30").selectedIndex = 0 
				}

// *** combined locker/hider func  ***  
 function DoBFYslotlocker()        {    
  if (document.getElementById("BAAFC8").value < 60 || document.getElementById("BAAFC8").value > 61)
    { (document.getElementById("BAAFC8sp1").selectedIndex = 0 ) ; (document.getElementById("BAAFC8sp2").selectedIndex = 0 )
         ; (document.getElementById("LabelDoB").style.color = "lightgrey")  
            ; (document.getElementById("LabelFYslot").style.color = "lightgrey")  }
     	else
		 {	(document.getElementById("LabelDoB").style.color = "black") 
            ; (document.getElementById("LabelFYslot").style.color = "black") }
	}

// ****** this func  *****   Kcarebox locker - but once locked, it can't unlock itself ! so get sub16box to run the func !!!
 function kcarelock()        {    
   if (document.getElementById("BAAFC14").value < 1 || document.getElementById("BAAFC30").selectedIndex == 2 )   document.getElementById("BAAFC40").value = 0
		}

function lock30bet()        {    
      allkds = (document.getElementById("BAAFC14").value / 1) + (document.getElementById("BAAFC16").value / 1)
   if (document.getElementById("BAAFC30").selectedIndex == 0 )   document.getElementById("BAAFC45").selectedIndex = 0
   if (allkds  < 1    &&  document.getElementById("BAAFC12").selectedIndex == 0 )   document.getElementById("BAAFC45").selectedIndex = 0
   if (document.getElementById("BAAFC7").selectedIndex == 0 )     document.getElementById("BAAFC45").selectedIndex = 0  //*** single ewitches it off 

   if (document.getElementById("BAAFC30").selectedIndex > 0 && allkds  > 0 && document.getElementById("BAAFC7").selectedIndex == 1 )   document.getElementById("Label30bet").style.color = "black"
	  else
        if (document.getElementById("BAAFC30").selectedIndex > 0 && document.getElementById("BAAFC12").selectedIndex == 1)  document.getElementById("Label30bet").style.color = "black"
      else
           	 { ( document.getElementById("Label30bet").style.color = "lightgrey") }
	    }
 //***  If/Else  needs no  Then or End If


 function lockDSQs()     { 
     if ( document.getElementById("BAAFC9").selectedIndex == 1 ) 
    	 { (document.getElementById("LabeladDLA").style.color = "black" ) ; (document.getElementById("LabeladDSwrk").style.color = "black") ; (document.getElementById("LabelSDP1").style.color = "black") ; (document.getElementById("LabelSDP2").style.color = "black") ; (document.getElementById("LabelDsAAHR").style.color = "black") }
          else
      	 { (document.getElementById("LabeladDLA").style.color = "lightgrey" ) ; (document.getElementById("LabeladDSwrk").style.color = "lightgrey") ; (document.getElementById("LabelSDP1").style.color = "lightgrey") ; (document.getElementById("LabelSDP2").style.color = "lightgrey") ; (document.getElementById("LabelDsAAHR").style.color = "lightgrey")}
	    } 


//  ** ** ** If single this func supresses ESA Partner row 
function singleESA()        {    
     if (document.getElementById("BAAFC7").selectedIndex == 0 )  
  	      { ( document.getElementById("Label_pESA").style.color = "lightgrey" ) ; ( document.getElementById("BAAFC8d").selectedIndex = 0) }
     else
		  ( document.getElementById("Label_pESA").style.color = "black")
 		}

 function Labbabyhider()     {    }


 function Labdskidhider()     { 
  if ( document.getElementById("BAAFC14").value > 0 || document.getElementById("BAAFC16").value > 0 ) 
         	 { (document.getElementById("LabelDSk").style.color = "black") ; (document.getElementById("LabelDSkEN").style.color = "black") }
          else
           	 { (document.getElementById("LabelDSk").style.color = "lightgrey") ; (document.getElementById("LabelDSkEN").style.color = "lightgrey")}
			 }

 function LabSLPhider()     {	
  allkds = (document.getElementById("BAAFC14").value / 1) + (document.getElementById("BAAFC16").value / 1)
       if ( allkds  > 0  &&  document.getElementById("BAAFC7").selectedIndex == 0 ) 
         	 { ( document.getElementById("LabelSLP1").style.color = "black")  }
          else
           	 { (document.getElementById("LabelSLP1").style.color = "lightgrey")   }
			}


 function Labkcarehider()     {	 
     if ( document.getElementById("BAAFC14").value > 0 && document.getElementById("BAAFC30").selectedIndex < 2 ) 
         	 { (document.getElementById("Labelkcare").style.color = "black")  }
          else
           	 { (document.getElementById("Labelkcare").style.color = "lightgrey") }
				}


// ****** this func stops   *****
function chkEnhDPkids()        {    
  if (document.getElementById("BAAFC18").value > document.getElementById("BAAFC17").value) document.getElementById("BAAFC18").value = document.getElementById("BAAFC17").value 
		}

function chklpp()        {    
  allkds = (document.getElementById("BAAFC14").value / 1) + (document.getElementById("BAAFC16").value / 1)

 if (document.getElementById("BAAFC7").selectedIndex ==1  || allkds == 0 )   document.getElementById("BAAFC19").selectedIndex = 0  
		}

function chkdis()        {    
 if (document.getElementById("BAAFC9").selectedIndex == 0 )  
      {( document.getElementById("BAAFC11").selectedIndex = 0) ; ( document.getElementById("BAAFC11a").selectedIndex = 0) ;
 ( document.getElementById("BAAFC10").selectedIndex = 0 ) ; (document.getElementById("BAAFC46").selectedIndex = 0 ) } 

   if (document.getElementById("BAAFC9").selectedIndex == 0 && document.getElementById("BAAFC8a").selectedIndex == 0 && document.getElementById("BAAFC8d").selectedIndex == 0 )  
         ( document.getElementById("BAAFC12").selectedIndex = 0 )
		}

//    function jumpIS()     { 
//     if (document.wbcForm1.incsuplist.selectedIndex ==1)  (document.location.href='#1')   }


// ***** ************* ************* ************* *************
 function Calcfunc()  {

FYdays = 366 ; Cr30hours = 17.1 ; ; cb = 0 ; cbrate = 13.4; cb1st = 6.9 ; esaWRcomp = 26.75 ; esaSCcomp = 32.35 
ram = 0 ; ContRent = 0 ; LHAamt = 0 ; frewks = 0 ; numfrewks = 0 ; CT = 0; CTweek = 0; altCT = 0
altCTwam = 0 ; CTwam = 0 ; hb = 0 ; maxhb = 0 ; exinc = 0 ; taper = 0 
CTexinc = 0 ; CTkoala = 0 ; CTpremaa = 0 ; ctb = 0 ; altctb = 0 
invca = "Na" ;  incsup = "No" ; age = 45 ; Status = "couple" ; hipenp = "No" ; sub16 = 0 ; sub18 = 0   

kidzAA = 0 ; dskids =  0 ; adaa = 0 ; dsable = "No" ; dissev = "No" ; aa = 0 ; premaa = 0 
WkWkhours = "ugh" ; empinc = 0 ; empcash = 0 ; empcashm = 0 ; minderm = 0 ; taxnim = 0 ; penconm = 0
erndis = 0 ; minder = 0 ; taxni = 0 ; pencon = 0 
maintinc = 0 ; subteninc = 0 ; brdsum = 0 ;  otheruninc = 0 ; maindis = 0     
Uncash = 0 ; Unearndis = 0 ; rnt = 0 ; canberra= 0 ; CapA = 0 ; CapB = 0 
Kcarekids = 0 ; Kcare = 0 ; StudiGC = 0 ; Pout = 0 ; EnhDP = 0   
HBndDeds = 0 ; CTndDeds = 0 ; ad2inc = "frog" ; prem = 0 ; DisWkWkhours = "ugh" ; BothWkhours = "yug" ; Back2Wk50 = "No"
Low = 0 ; High =  0	; SpenAge = "NotQ"
capinc = 0; OtherGI = 0; Otherall = 0; OtherpostDis = 0; grossinc = 0; Gemp4TC = 0; sw1 = "OFF"; AdEnhdsP = "No"
maxTC = 0; KcareFees = 0 ; TCthreshold = 0 ; familyelement = 0 ; k = 0 ; exsTCinc = 0 
taperTC = 0 ; annTC = 0 ; toptaper = 0 ; topslice = 0 ; exportTC = 0 ; WPC = 0 ; kkbal = 0
C_ESA_Phase = "None"; C_ESA_Elem = "None" ; C_ESA_Comp = "None" ; P_ESA_Phase = "None" ; P_ESA_Elem = "None"; P_ESA_Comp = "None"

// ''''''********   uprated for Sp 11   AA's + prems       ***************************** )

SCsub25AA = 53.45;  SCover25AA = 67.5 ;  CPLEsub18AA = 80.75;  CoupleAA = 105.95;  sub16AA = 62.33 ; sub18AA = 62.33
Sing60AA = 137.35 ; Sing65AA = 157.9 ; Coup60AA = 209.7 ; Coup65AA = 236.8

 HBndrat1 = 9.4 ; HBndrat2 = 21.55 ; HBndrat3 = 29.6 ; HBndrat4 = 48.45 ; HBndrat5 = 55.2
 HBndrat6 = 60.6 ; CTndrat1 = 2.85 ; CTndrat2 = 5.7 ;  CTndrat3 = 7.2 ; CTndrat4 = 8.6  

Familyprem = 17.4 ; LPP = 4.8 ; dsprem1 = 28.85 ; dsprem2 = 41.1 ; dssevprem1 = 55.3 ; dssevprem2 = 110.6 ; diskidprem = 53.62
careprem1 = 31 ; careprem2 = 62 ; enhdspremchld = 21.63 ; enhdsprem1 = 14.05 ; enhdsprem2 = 20.25

   CAsafenet() // ***  force extra run of CA safety net
//  -----------  VB form 2 LOGIC ----------------------------------------------- 

   ContRent = document.getElementById("BAAFC1").value / 1     // Contract Rent
   LHAamt =  document.getElementById("BAAFC1a").value / 1     // LHA amount

  if (document.getElementById("BAAFC2").selectedIndex == 1)  (ContRent = ContRent / 2)
  if (document.getElementById("BAAFC2").selectedIndex == 2) { ContRent = (ContRent * 12); ContRent = (ContRent / 52) }

  ram = ContRent  // *** these 4 rules set ram which feeds EliRent
   if (LHAamt > 0)  (ram = LHAamt)
    if (LHAamt > ContRent)  (ram = ContRent)
// ***  £15 cashback removed for April 2011     

   frewks = document.getElementById("BAAFC3").value  
   frewks =  frewks / 1

 if (frewks > 0)   { numfrewks = frewks ; frewks = (52 - frewks) }

    CT = document.getElementById("BAAFC4").value
    CT  =  CT / 1
    CTweek = (CT / FYdays * 7)
// Module1.revdisco = List3
    altCT = CT

   if (document.getElementById("BAAFC5").selectedIndex ==1)  (altCT = CT / 3 * 4)
   if (document.getElementById("BAAFC5").selectedIndex ==2)  (altCT = CT * 2)
   altCTwam = (altCT / FYdays * 7)

//  -----------  VB form 3 LOGIC -----------------------------------------------

   if (document.getElementById("BAAFC6").selectedIndex ==1)  (incsup = "Yes")
   if (document.getElementById("BAAFC7").selectedIndex ==0)  (Status = "single")
   age = document.getElementById("BAAFC8").value
   age = age / 1 

   if ( age > 61 ) ( SpenAge = "Q" ) 
 // *** find Pensioner status if aged 60ish
 if (age >= 60 && document.getElementById("BAAFC8sp1").selectedIndex == 0 ) ( SpenAge = "Q" )
 if (age >= 60 && document.getElementById("BAAFC8sp1").selectedIndex == 1 && document.getElementById("BAAFC8sp2").selectedIndex > 0) ( SpenAge = "Q" )
 if (age >= 60 && document.getElementById("BAAFC8sp1").selectedIndex == 2 && document.getElementById("BAAFC8sp2").selectedIndex > 1) ( SpenAge = "Q" )
 if (age >= 60 && document.getElementById("BAAFC8sp1").selectedIndex == 3 && document.getElementById("BAAFC8sp2").selectedIndex > 2) ( SpenAge = "Q" )
 if (age >= 60 && document.getElementById("BAAFC8sp1").selectedIndex == 4 && document.getElementById("BAAFC8sp2").selectedIndex > 3) ( SpenAge = "Q" )
 if (age >= 60 && document.getElementById("BAAFC8sp1").selectedIndex == 5 && document.getElementById("BAAFC8sp2").selectedIndex > 4) ( SpenAge = "Q" )
 if (age >= 60 && document.getElementById("BAAFC8sp1").selectedIndex == 6 && document.getElementById("BAAFC8sp2").selectedIndex > 5) ( SpenAge = "Q" )

//   ***    Claimant's ESA Phase - bit of validation here: no ESA no Elem or Comp: no Main no Comp
 if (document.getElementById("BAAFC8a").selectedIndex == 0) {(document.getElementById("BAAFC8b").selectedIndex = 0) ; (document.getElementById("BAAFC8c").selectedIndex = 0) }
 if (document.getElementById("BAAFC8a").selectedIndex == 1)  {(C_ESA_Phase = "Ass");(document.getElementById("BAAFC8c").selectedIndex = 0)}
 if (document.getElementById("BAAFC8a").selectedIndex == 2) (C_ESA_Phase = "Main")
// all ESA values default to "None"
 if (document.getElementById("BAAFC8b").selectedIndex == 1)  (C_ESA_Elem = "IR")
 if (document.getElementById("BAAFC8b").selectedIndex == 2)  (C_ESA_Elem = "C")
 if (document.getElementById("BAAFC8b").selectedIndex == 3)  (C_ESA_Elem = "cred")
 if (document.getElementById("BAAFC8c").selectedIndex == 1)  (C_ESA_Comp = "Work-rel")
 if (document.getElementById("BAAFC8c").selectedIndex == 2)  (C_ESA_Comp = "Supp")

// *** Partner's ESA Phase -  
 if (document.getElementById("BAAFC8d").selectedIndex == 0) {(document.getElementById("BAAFC8e").selectedIndex = 0) ; (document.getElementById("BAAFC8f").selectedIndex = 0) }
 if (document.getElementById("BAAFC8d").selectedIndex == 1)  {(P_ESA_Phase = "Ass");(document.getElementById("BAAFC8f").selectedIndex = 0)}
 if (document.getElementById("BAAFC8d").selectedIndex == 2) (P_ESA_Phase = "Main")
 if (document.getElementById("BAAFC8e").selectedIndex == 1)  (P_ESA_Elem = "IR")
 if (document.getElementById("BAAFC8e").selectedIndex == 2)  (P_ESA_Elem = "C")
 if (document.getElementById("BAAFC8e").selectedIndex == 3)  (P_ESA_Elem = "cred")
 if (document.getElementById("BAAFC8f").selectedIndex == 1)  (P_ESA_Comp = "Work-rel")
 if (document.getElementById("BAAFC8f").selectedIndex == 2)  (P_ESA_Comp = "Supp")

  if (document.getElementById("BAAFC9").selectedIndex == 1)  (dsable = "Yes")
//  *  set dissev = "No" [no SDP], "One" [single rate SDP] or "Both" [couple/double rate SDP]

// if (Status == "single" && document.wbcForm1.dissevlist[11].selectedIndex == 1 && document.wbcForm1.CAlist[11a].selectedIndex == 0 )  (dissev = "One")
   if (Status == "single" && document.getElementById("BAAFC11").selectedIndex == 1 && document.getElementById("BAAFC11a").selectedIndex == 0 )  (dissev = "One")
   if (Status == "couple" && document.getElementById("BAAFC11").selectedIndex == 1 && document.getElementById("BAAFC11a").selectedIndex == 1 )  (dissev = "One")
   if (Status == "couple" && document.getElementById("BAAFC11").selectedIndex == 1 && document.getElementById("BAAFC11a").selectedIndex == 0 )  (dissev = "Both")

// "invcalist" id="BAAFC13"
   if (document.getElementById("BAAFC13").selectedIndex == 0)  (invca = "No CA is payable")
   if (document.getElementById("BAAFC13").selectedIndex == 1) (invca = "Both of us get a CA")
    if (document.getElementById("BAAFC13").selectedIndex == 2)  (invca = "I work and get CA")
    if (document.getElementById("BAAFC13").selectedIndex == 3)  (invca = "Partner works & gets CA")
     if (document.getElementById("BAAFC13").selectedIndex == 4)  (invca = "I get CA but don't work")
     if (document.getElementById("BAAFC13").selectedIndex == 5)  (invca = "Partner has CA, not work")



 		  if (age > 79) (hipenp = "Yes")
//			'Not quite as precise as conditions in VB5  
     if (age > 59 && dsable == "Yes") (hipenp = "Yes") 	

//	***Not quite as precise as conditions in VB form3A1 & form4   '***  Adult EnhDP Checker ***  and AdEnhdsP setter 
//		"hrccdlalist" =  id="BAAFC10"
 if (Status == "single" && document.getElementById("BAAFC10").selectedIndex == 1 && SpenAge == "NotQ"  && dsable == "Yes" ) { (EnhDP = enhdsprem1) ; (AdEnhdsP = "Yes")}
 if (Status == "couple" && document.getElementById("BAAFC10").selectedIndex == 1 && SpenAge == "NotQ"  && dsable == "Yes" ) { (EnhDP = enhdsprem2) ; (AdEnhdsP = "Yes")} 

 if (Status == "single" && C_ESA_Comp == "Supp"  && SpenAge == "NotQ" ) { (EnhDP = enhdsprem1) ; (AdEnhdsP = "Yes")}
 if (Status == "couple" && C_ESA_Comp == "Supp"  && SpenAge == "NotQ" ) { (EnhDP = enhdsprem2) ; (AdEnhdsP = "Yes")}

 if (document.getElementById("BAAFC12").selectedIndex == 1 ) (DisWkWkhours = "16plus")
// *******   DisWkWkhours = "16plus"

//  -----------  VB form 4 LOGIC -----------------------------------------------
//   !!!!!  '* Logic to pre assess entlement to enhanced disability premium
//   !!!!!  '* NB this Logic duplicated in func DoCB 4 real-time cb

    sub16 = document.getElementById("BAAFC14").value ;  sub18 = document.getElementById("BAAFC16").value
	  cb = (sub16 / 1 + sub18 / 1)
	    cb = (cb * cbrate)
		  if (cb > 0)   (cb = cb + cb1st)

    kidzAA = (sub16 * sub16AA + sub18 * sub18AA)

 if (Status == "single" && age < 25 && cb == 0) (adaa = SCsub25AA) 
 if (Status == "single" && age > 24 && cb == 0) (adaa = SCover25AA)
 if (Status == "single"  && cb > 0) (adaa = SCover25AA)
 if (Status == "single" && cb > 0 && age < 18) (adaa = SCsub25AA)
//   ***   single ESA cust under 25 gets promoted  !
 if (Status == "single" && C_ESA_Phase == "Main") (adaa = SCover25AA)

 if (Status == "couple" ) (adaa = CoupleAA)
 if (Status == "couple" && age < 18  && C_ESA_Phase !=  "Main" ) (adaa = CPLEsub18AA)

  if (Status == "single" && SpenAge == "Q" ) (adaa = Sing60AA) 
  if (Status == "single" && age > 64) (adaa = Sing65AA) 
  if (Status == "couple" && SpenAge == "Q" ) (adaa = Coup60AA)
  if (Status == "couple" && age > 64 ) (adaa = Coup65AA)

// ** add  ESA components onto HB/CTB PA's .. in certain circos ... under 60's only !
 if ( C_ESA_Comp == "Work-rel"  && SpenAge == "NotQ" ) ( adaa = adaa + esaWRcomp ) // £ 24
 if ( C_ESA_Comp == "Supp"  && SpenAge == "NotQ" ) ( adaa = adaa + esaSCcomp ) // £ 29
 if ( C_ESA_Comp == "None" && P_ESA_Comp == "Work-rel" && dsable == "No" && SpenAge == "NotQ" ) ( adaa = adaa + esaWRcomp )
 if ( C_ESA_Comp == "None" && P_ESA_Comp == "Supp" && dsable == "No" && SpenAge == "NotQ" ) ( adaa = adaa + esaSCcomp )

//  ----------- End  VB form 4 LOGIC 'cept needs bit of enhanced disability -----------
//  -----------  VB form 5 LOGIC -----------------------------------------------
//			wbcForm1.wkwklist  = 30
 if (document.getElementById("BAAFC30").selectedIndex ==0 ) (WkWkhours = "30plus")
 if (document.getElementById("BAAFC30").selectedIndex ==1 ) (WkWkhours = "16plus")
 if (document.getElementById("BAAFC30").selectedIndex ==2 ) (WkWkhours = "under16")

 if (document.getElementById("BAAFC45").selectedIndex ==1 ) (BothWkhours = "30ish")

 empcashm = document.getElementById("BAAFC23").value            // id="BAAFC23"
 empcashm = (empcashm * 12) ; empcashm = (empcashm / 52)  
 minderm = (document.getElementById("BAAFC25").value /3 )	  // id="BAAFC25"
 minderm = (minderm * 12) ; minderm = (minderm / 52)     
 taxnim = document.getElementById("BAAFC27").value		 //  id="BAAFC27"
 taxnim = (taxnim * 12) ; taxnim = (taxnim / 52)
 penconm = (document.getElementById("BAAFC29").value / 2)
 penconm = (penconm * 12) ; penconm = (penconm / 52)		//  id="BAAFC29"

 empcash = (document.getElementById("BAAFC22").value /1 + empcashm)
 minder = (document.getElementById("BAAFC24").value /3 + minderm )
 taxni = (document.getElementById("BAAFC26").value / 1 + taxnim)
 pencon = (document.getElementById("BAAFC28").value / 2 + penconm)

 empinc = (empcash / 1 + minder / 1 - taxni - pencon)   

 if (document.getElementById("BAAFC31").selectedIndex ==1 )   ( Back2Wk50 = "Yes" )

// ----------------				Safety net 
 if (empinc < 0) (empinc = 0)
//<!-------------------  ---------------->
//  -----------  VB form 6 LOGIC -----------------------------------------------        

 maintinc = (document.getElementById("BAAFC36").value / 1)
 subteninc = (document.getElementById("BAAFC33").value / 1)
 brdsum = (document.getElementById("BAAFC34").value / 2)

 otheruninc = (document.getElementById("BAAFC37").value / 1)

 if (maintinc > 0) (maindis = 15)
 if (maintinc < 15) (maindis = maintinc)
 if (cb < 1) (maindis = 0)  
// amended June 05  to drop "If age > 59 And" clause

  Uncash = (maintinc + subteninc + brdsum  + otheruninc)
  Unearndis = maindis 
//'*** Unearndis is subtracted from Uncash at Form10
 rnt = (subteninc + brdsum)  //rnt needed later ?

//  -----------  VB form 7 LOGIC -----------------------------------------------
 CapA = (document.getElementById("BAAFC38").value / 1)
 CapB = (document.getElementById("BAAFC39").value / 1)

 canberra= (CapA  + CapB)

//'If canberra>= 16000 Then Exit Sub
 if ( SpenAge == "NotQ" )  { (canberra = canberra - 6000) ; ( divby = 250 ) }
 if ( SpenAge == "Q" ) { (canberra = canberra - 10000)  ; ( divby = 500 ) }
   
   tar1 = (canberra / divby )
   tar2 =  parseInt (tar1)  //  '*** returns integer
	 if (tar1 > tar2)  (tar2 = tar2 + 1)
	 canberra= tar2

// ----------------				Safety net 
 if (canberra < 0) (canberra= 0)	 
 
//  -----------  VB form 8 LOGIC ----------------------------------------------- 
 Kcarekids = sub16

 Kcare = (document.getElementById("BAAFC40").value / 1 )

 if (Kcarekids == 1 && Kcare > 175) (Kcare = 175)
 if (Kcarekids > 1 && Kcare > 300) (Kcare = 300)
// ----------------				Safety net  --- NOT IN QBC 
 if (Kcarekids < 1) (Kcare = 0)

 StudiGC = (document.getElementById("BAAFC41").value / 1 ) ; Pout = StudiGC

//  -----------  VB form 9 LOGIC -----------------------------------------------
//  ---    VB has some ds LOGIC here
 
TopRate = (document.getElementById("BAAFC47").value / 1 )
Fifth   = (document.getElementById("BAAFC48").value / 1 ) 
Fourth  = (document.getElementById("BAAFC49").value / 1 )
ThreeA1 = (document.getElementById("BAAFC49a").value / 1 )        // new in 07 field 4 SAR
Third   = (document.getElementById("BAAFC50").value / 1 )
TwoA1 =   (document.getElementById("BAAFC50a").value / 1 )        // new in 07 field 4 SAR
Second  = (document.getElementById("BAAFC51").value / 1 )
Lowest  = (document.getElementById("BAAFC52").value / 1 )
AnyWPC   = (document.getElementById("BAAFC53").value / 1 )    // keep field value 4 SAR
esa_C  = (document.getElementById("BAAFC53b").value / 1 )     // new in 08 field 4 ESA
Residual = (document.getElementById("BAAFC54").value / 1 )
Issub25 =  (document.getElementById("BAAFC55").value / 1 )
Isplus25 = (document.getElementById("BAAFC56").value / 1 )

 x = (TopRate * HBndrat6 ) 
  x = (x + Fifth * HBndrat5 )
   x = (x + Fourth * HBndrat4 )
    x = (x + ThreeA1 * HBndrat3 )
     x = (x + Third * HBndrat3 )
      x = (x + TwoA1 * HBndrat2 )
        x = (x + Second * HBndrat2 )
	  x = (x + Lowest * HBndrat1 )
	   x = (x + esa_C * HBndrat1 )
            x = (x + Residual * HBndrat1 )
              x = (x + Isplus25 * HBndrat1 )
 HBndDeds = x 				

//'*** Don't forget to adjust 
  if (frewks > 0) {HBndDeds = (HBndDeds * 52); HBndDeds = (HBndDeds / frewks) }

 x = (TopRate * CTndrat4 )
  x = (x + Fifth * CTndrat3 )
   x = (x + Fourth * CTndrat2 )
    x = (x + ThreeA1 * CTndrat2)
     x = (x + Third * CTndrat2 )
       x = (x + TwoA1 * CTndrat1 )
         x = (x + Second * CTndrat1 )
	  x = (x + Lowest * CTndrat1 )
            x = (x + esa_C * CTndrat1 )
             x = (x + Residual * CTndrat1 )
 CTndDeds = x

 CTwam = (CTweek - CTndDeds) // NEEDS Safety net  --- NOT IN QBC

//Call SARinc  //Sub SARinc() 
//'****  be sure to xref the Alt CT CALC Sub in form11  ***************
//QotherAd = "frog"   !!!!!!    'Not setting a  value for  QotherAd

 if (TopRate == 0 && Fifth == 0 && Fourth == 0 && Third == 0 && ThreeA1 == 0 && Second == 0 && TwoA1 == 0 && Lowest == 0  && AnyWPC == 0  && Residual == 0 && esa_C == 0 && Issub25 == 0 && Isplus25 == 0) (ad2inc = "none")
 if (Issub25 > 0  || Isplus25 > 0  || AnyWPC > 0 ) (ad2inc = "25%")
 if (Residual > 0 || Lowest > 0 || Second > 0 || esa_C > 0 ) (ad2inc = "15%")
 if (Third > 0 || TwoA1 > 0 ) (ad2inc = "7.5%")
 if (TopRate > 0 || Fifth > 0 || Fourth > 0 || ThreeA1 > 0 ) (ad2inc = "none")

//  -----------  VB  formWoF TC  LOGIC ----------------------------------------------- 
//  -----------  3 new fields validated ok ----------------------------------------------- 
//'*** Let's find the ANNUAL gross income first *********************************************
 capinc = ( (CapA + CapB) * 0.045)  // '*** give 4.5% interest ANNUAL fig ie a realistic rate of interest on savings.
//  don't use value of maintinc directly, better to built unearn fig up from components    
 OtherGI = ((subteninc + brdsum + otheruninc) * 52)  // *** These figs are weekly so make them ANNUAL * take Maintinc out, cb was never in
 Otherall = (OtherGI + capinc)  //'*** total "other" annual inc
 OtherpostDis = (Otherall - 300)  // '*** take off the IR Disreg on "other" weekly inc (£300 p/a)
 if (OtherpostDis < 0) (OtherpostDis = 0) //'*** don't let it go below zero

 Gemp4TC =  (document.getElementById("BAAFC22").value / 1 + empcashm) 
  Gemp4TC = (Gemp4TC + (document.getElementById("BAAFC24").value / 1 + (minderm * 3))) 
    Gemp4TC = (Gemp4TC - (document.getElementById("BAAFC28").value / 1 + (+ penconm * 2))) 
                //  ***  Gemp4TC is coming here weekly minus Pension Contribs but includes fire, ch-mind, tax & NI !
 grossinc = ((Gemp4TC * 52) + OtherpostDis)     //'*** grossinc can be monthly !
//'*** Found the ANNUAL gross income  then choose which calc to run here (joint WTC/CTC  or the CTC ONLY)
//'*** Default is to run CTC ONLY - which will Exit safely if NO kids
 sw1 = "CTC ONLY"
//'***  Let's satisfy the WTC tests which will run the joint WTC/CTC  *****
 if (WkWkhours == "30plus" && cb > 0  ) ( sw1 = "WTC/CTC" )
 if (WkWkhours == "16plus" && cb > 0  ) ( sw1 = "WTC/CTC" )
 if (WkWkhours == "30plus" && dsable == "Yes") ( sw1 = "WTC/CTC" )
 if (WkWkhours == "16plus" && dsable == "Yes" && DisWkWkhours == "16plus" ) ( sw1 = "WTC/CTC" )
 if (WkWkhours == "30plus" && dsable == "Yes") ( sw1 = "WTC/CTC" )
 if (WkWkhours == "30plus" && age >= 25 ) ( sw1 = "WTC/CTC" )
 if (WkWkhours == "16plus" && document.getElementById("BAAFC31").selectedIndex ==1 ) ( sw1 = "WTC/CTC" )
 if (WkWkhours == "16plus" && age >= 60 ) ( sw1 = "WTC/CTC" ) //** for over 60's in 2011 

// '*** Call TC_sub '***  always gets Called and tries to give CTC ! Sub TC_sub() '***  is going to aggregate  WTC/CTC calc - ! **********
//        '*** maxTC  comes back here from WTC_OK Qual sub with the WTC elements   
  if (sw1 == "WTC/CTC")  subfunWTC_OK()  // ***** call external (sub) function and come back here for CTC

 if (sw1 == "CTC ONLY")   //***  If/Else  needs no  Then or End If
	TCthreshold = 15860
   else
	TCthreshold = 6420
// '*** insert the CTC elements  ! **************************
 if (cb > 0) { maxTC = (maxTC + 545) ; familyelement = (familyelement + 545)  } // ' *** Family element
    //    ' *** Baby element gone in 2011

//'************** if no children then no CTC can happen  **************************
 k = (sub16 / 1 + sub18 / 1)  //***   ' find no of Children
 maxTC = (maxTC + (k * 2555) )  
 maxTC = (maxTC + (document.getElementById("BAAFC17").value / 1 * 2800) )  
 maxTC = (maxTC + (document.getElementById("BAAFC18").value / 1 * 1130) )  

//' *** That's the CTC elements  *****************************************************
//'*** apply taper  for every pound above TCthreshold p/a  ***************************************

 if (grossinc > TCthreshold)  (exsTCinc = (grossinc - TCthreshold))
//'****  CALC it ***********************
 if (exsTCinc >= 0) { taperTC = (exsTCinc * 0.41) ; annTC = (maxTC - taperTC)} 
 if (annTC < 0 ) (annTC = 0 )
 if (cb > 0 && annTC <= familyelement) (annTC = familyelement)

 if (grossinc >= 40000)  { topslice = (grossinc - 40000) ; toptaper = (topslice * 0.41)} 
// toptaper =  parseInt (toptaper)  //  '*** returns a true integer, no rounding up or down - better than VB
 if (grossinc >= 50000)  (annTC = (annTC - toptaper))
 if (annTC < 0) (annTC = 0) // '*** don't let it go negative like
//'***  final safety net ....  Not rounding up annTC here ! 
 if (grossinc <= TCthreshold) (annTC = maxTC)  

// '*** Finally Call PC_sub '***  always gets Called for OAP and tries to give WPC ! 
		 if ( SpenAge == "Q" )    do_PC()  

// ***  zeroize all Tax Credits estimates if checkbox is unchecked
 if (document.getElementById("BAAFC42").checked == false)  { annTC = 0 ; WPC = 0 } 

//'***  SWING back to  pencilA_Click Sub      '***  pick up knownTC's if entered 
 if  (document.getElementById("BAAFC43").value > 0  || document.getElementById("BAAFC44").value > 0 ) { (annTC  = document.getElementById("BAAFC43").value) ; (WPC = document.getElementById("BAAFC44").value)}

// '***  Need to pick up TC & PC ....add weekly sum ....    
 if (annTC > 0 && document.getElementById("BAAFC43").value == 0 ) (exportTC = annTC / 366 * 7)  //'***  picks up calc'd annTC or knownTCbox
 if (annTC > 0 && document.getElementById("BAAFC43").value > 0 ) (exportTC = annTC ) //'***  picks up known weekly TC
 if (WPC > 0 ) (exportTC = exportTC / 1  + WPC / 1)  //'***  picks up WPC or knownPCbox

//***##########   going to Show (weekly not ann) Credits detected by Shunting them into TCbox readonly 
   Uncash = (Uncash + exportTC / 1) // '**** Add on the weekly Creds  !!!

//  -----------  VB form 10 LOGIC ----------------------------------------------- 

 if (incsup == "Yes") { empinc = 0 ; erndis = 0 ; canberra= 0 ; Uncash = 0 ; Unearndis = 0 ; Pout = 0} 

// Call Premit   //  //Sub Premit()
//'***** carer premium   *****
   if (document.getElementById("BAAFC13").selectedIndex ==1 ) {prem = (prem + careprem2)}
   if (document.getElementById("BAAFC13").selectedIndex > 1 ) {prem = (prem + careprem1)}
//'*** Family premium  Use CB to test for kidz *****
 if (cb > 0)  (prem = (prem + Familyprem))

 if (document.getElementById("BAAFC19").selectedIndex ==1 && SpenAge == "NotQ" && dsable == "No") (prem = (prem + LPP)) 

 dskids = (document.getElementById("BAAFC17").value / 1 )
   if (dskids > 0)   {dskids = (dskids * diskidprem); prem = (prem + dskids) }

 if ( SpenAge == "NotQ" && Status == "single" && dsable == "Yes" && C_ESA_Phase == "None" ) (prem = (prem + dsprem1) )
 if ( SpenAge == "NotQ" && Status == "couple" && dsable == "Yes" && C_ESA_Phase == "None" ) (prem = (prem + dsprem2) )

 if (age < 60 && Status == "single" && dsable == "Yes" && dissev == "One" ) (prem = (prem + dssevprem1) )
 if (age < 60 && Status == "couple" && dsable == "Yes" && dissev == "Both"  ) (prem = (prem + dssevprem2) )
 if (age < 60 && Status == "couple" && dsable == "Yes" && dissev == "One"  ) (prem = (prem + dssevprem1) )

 //  penprems gone  !
 if (age > 59 && Status == "single" && hipenp == "Yes"  && dissev == "One") (prem = (prem + dssevprem1 ) )
 if (age > 59 && Status == "couple" && hipenp == "Yes"  && dissev == "Both" ) (prem = (prem + dssevprem2 ) )
 if (age > 59 && Status == "couple" && hipenp == "Yes"  && dissev == "One" ) (prem = (prem + dssevprem1 ) )

 EnhDP = ( EnhDP + (enhdspremchld * document.getElementById("BAAFC18").value) )
 prem = (prem + EnhDP)
 
//                  Sub Total()
  maxhb = (ram - HBndDeds)
    if (maxhb < 0) (maxhb = 0)
		
//Call discal1 //Sub discal1()    fire is OUT !
 if (Status == "single") (erndis = 5)
  if (Status == "couple") (erndis = 10)
   if (invca == "I work and get CA" || invca == "Partner works & gets CA" ) (erndis = 20)
   if (invca == "Both of us get a CA" && empinc >= 20 ) (erndis = 20) //prog detects if one of 'em is working & gives £20

 if (C_ESA_Comp == "Work-rel" || C_ESA_Comp == "Supp" || P_ESA_Comp == "Work-rel" || P_ESA_Comp == "Supp") (erndis = 20)
   //    '*** award it on any of 4 ESA components
 if (dsable == "Yes" && C_ESA_Phase == "None" && P_ESA_Phase == "None") (erndis = 20)
   //    '*** award it on dsable if no ESA claim - this works ok cos ESA_Phases will surely get set

 if (dsable == "Yes"  && P_ESA_Phase == "Ass") (erndis = 20)
  //  *** award it on dsable if P_ESA claim is "Ass" ! Dec '08 fix

 if (cb > 0 && Status == "single")   (erndis = 25)
//End Sub '***** End of discal1 ********)

//Call discal3 //Sub discal3() '*** New WTC style disregard here
//'****** we need to run  discal3()  first
//    '***'***'***'*** ok 04 & let's be sure to award it only once   ***************************
  if (age > 24 && WkWkhours == "30plus") { erndis = (erndis + Cr30hours)  }  // ok 
	else if (cb > 0  && WkWkhours == "30plus") { erndis = (erndis + Cr30hours)  }  // ok 
     else if (cb > 0  && WkWkhours == "16plus") { erndis = (erndis + Cr30hours)  }  // ok 
  else if (dsable == "Yes" && WkWkhours == "30plus" && C_ESA_Phase == "None" && P_ESA_Phase == "None") { erndis = (erndis + Cr30hours) }  // ok 
    else if (dsable == "Yes" && WkWkhours == "16plus" && DisWkWkhours == "16plus" && C_ESA_Phase == "None" && P_ESA_Phase == "None") { erndis = (erndis + Cr30hours) }  // ok 
	    else if (Back2Wk50 == "Yes" && WkWkhours == "16plus")   { erndis = (erndis + Cr30hours)  }  //   ok
	else if ( WkWkhours == "30plus" && C_ESA_Comp == "Work-rel") { erndis = (erndis + Cr30hours) }
	 else if ( WkWkhours == "30plus" && C_ESA_Comp == "Supp") { erndis = (erndis + Cr30hours) }
	  else if ( WkWkhours == "30plus" && P_ESA_Comp == "Work-rel") { erndis = (erndis + Cr30hours) }
	   else if ( WkWkhours == "30plus" && P_ESA_Comp == "Supp") { erndis = (erndis + Cr30hours) }
   else if (WkWkhours == "16plus" && DisWkWkhours == "16plus" && C_ESA_Comp == "Work-rel") { erndis = (erndis + Cr30hours) }
    else if (WkWkhours == "16plus" && DisWkWkhours == "16plus" && C_ESA_Comp == "Supp") { erndis = (erndis + Cr30hours) }
     else if (WkWkhours == "16plus" && DisWkWkhours == "16plus" && P_ESA_Comp == "Work-rel") { erndis = (erndis + Cr30hours) }
      else if (WkWkhours == "16plus" && DisWkWkhours == "16plus" && P_ESA_Comp == "Supp") { erndis = (erndis + Cr30hours) }

  if (empinc < erndis) (erndis = empinc)

//Call discal2 Sub discal2()
 if (Kcare > 0)  (erndis =  (erndis + Kcare) )

  if (exportTC > 0  &&  empinc < erndis )   { kkbal = (erndis - empinc)  }	
// If FormWof.exportTC > 0 And empinc < erndis Then kkbal = erndis - empinc

  Uncash = ( Uncash - kkbal )
// Uncash = Uncash - kkbal  '**** take off unused balance of Childcare costs !!!  !!!

  if ( Uncash < 0 ) ( Uncash = 0 )
//If Uncash < 0 Then Uncash = 0   '** don't let Uncash go below 0

	if (empinc < erndis) (erndis = empinc)
//   ***** End of discal2  ********
 
 koala = (empinc - erndis + Uncash - Unearndis + canberra- Pout)
    koala52 = koala          

 aa = (kidzAA / 1 + adaa / 1)
 premaa = (prem + aa)
     
//'**** N.B. 
//'**** so that 
 if (frewks > 0) { koala = (koala * 52) ; koala = (koala / frewks) ; premaa = (premaa * 52) ; premaa = (premaa / frewks) }

 exinc = (koala - premaa)

//          '****  HBCALC ***********************
 if (exinc <= 0)  (hb = maxhb)
 if (exinc >= 0) { taper = (exinc * 0.65) ; hb = (maxhb - taper) }
  if (hb < 0)  (hb = 0)
			
//  -----------  VB form 11 LOGIC -----------------------------------------------
     CTexinc = exinc //'*** set CTexinc initially
 if (frewks > 0) { CTkoala = koala52 ; CTpremaa = (premaa / 52) ; CTpremaa = (CTpremaa * frewks) ; CTexinc = (CTkoala - CTpremaa) }

// '****  CT CALC ***********************
 if (CTexinc <= 0) (ctb = CTwam)
 if (CTexinc >= 0) { taper = (CTexinc * 0.2) ;  ctb = (CTwam - taper) } 
 if (ctb < 0) (ctb = 0) 

// '****  Alt CT CALC ( SAR )  ***********************
 if (ad2inc == "25%")  { altctb = (altCTwam * 0.25) }
 if (ad2inc == "15%")  { altctb = (altCTwam * 0.15) }
 if (ad2inc == "7.5%")  { altctb = (altCTwam * 0.075) }
 if (ad2inc == "none")  (altctb = 0.00)
 if (rnt > 0) (altctb = 0.00)
if (Status == "couple") (altctb = 0.00)
 
//'******* look out 
 if (canberra > 40)  { (hb = 0) ; (ctb = 0)  }
 if ( SpenAge == "Q" && canberra > 12 )  { (hb = 0) ; (ctb = 0)  }
 
// Could do a really neat Final 2 dec place format on numbers here but sadly older browsers will give error. 
// Needs Java Scri ipt 1.5, J Scri ipt - 5.5, IE 5.5 or Netscape - 6.0 - 'cos toFixed function not supported earlier.
//    e.g. would be .....  hb = (hb.toFixed (2))  

//    */*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/      write OUTPUT answers to screen   /*/*/*/*/*/*/*/*

     s = premaa ; 	Formatit(s) ;   premaa = s     //***** Format & display AA
 document.getElementById("BAAFC57").value =  premaa       

       //  rounding nwi  
     s = koala ; 	Formatit(s) ;   koala = s     //***** Format & display nwi
  document.getElementById("BAAFC58").value =  koala

       s = exportTC ; 	Formatit(s) ;   exportTC = s     //***** Format & display exportTC
  document.getElementById("BAAFC59").value = exportTC     //annTC  

       //  rounding hb !  
       s = hb ; 	Formatit(s) ;   hb = s     //***** Format & display hb
  document.getElementById("BAAFC60").value =  hb   

       //  rounding ctb !  
       s = ctb ; 	Formatit(s) ;   ctb = s     //***** Format & display ctb
  document.getElementById("BAAFC61").value =  ctb   

       //  rounding altctb !  
       s = altctb ; 	Formatit(s) ;   altctb = s     //***** Format & display altctb
 document.getElementById("BAAFC62").value =   altctb   //    //   document.wbcForm1.rambox.value     //    

   }
//  *********  end of Calcfunc *****************
// *****  ************************** *************************

 function subfunWTC_OK() //***  
    {  
 maxTC = 1920
 if (Status == "couple" || cb > 0)  (maxTC = maxTC + 1950)
 if (Status == "couple" && cb < 1  && document.getElementById("BAAFC31").selectedIndex ==1 && WkWkhours == "16plus") (maxTC = maxTC - 1950)
// '*** but take the blipping thing  off again in this one circo

 if (WkWkhours == "30plus") (maxTC = maxTC + 790) 
     else   if (BothWkhours == "30ish" && DisWkWkhours == "16plus" )   (maxTC = maxTC + 790) 
            else   if (BothWkhours == "30ish" &&  cb > 0 )   (maxTC = maxTC + 790) 

 if (dsable == "Yes" && DisWkWkhours == "16plus" ) (maxTC = maxTC + 2650) 
 if (AdEnhdsP == "Yes"  || document.getElementById("BAAFC46").selectedIndex ==1 ) (maxTC = maxTC + 1130) 
       //   '*** NB New field DsAAHRList to pick up adult on Attendance allowance(Higher Rate) in WTC
       // '* can't rely on EnhDP for a true result !! Added AdEnhdsP setter (Y/N) at Screen 4 ok 
 if (age >= 50 && document.getElementById("BAAFC31").selectedIndex ==1 && WkWkhours == "30plus") (maxTC = maxTC + 2030) 
 if (age >= 50 && document.getElementById("BAAFC31").selectedIndex ==1 && WkWkhours == "16plus") (maxTC = maxTC + 1365) 
//'*** want to give Kcare tax cred for WTC *** Kcarekids  is no. of potential Kcare kids
 KcareFees =  (document.getElementById("BAAFC40").value / 1 ) // ****'get actual Fees paid and peg them
 if (Kcarekids == 1 && KcareFees > 175) (KcareFees = 175)
 if (Kcarekids > 1 && KcareFees > 300) (KcareFees = 300)
 if (Kcarekids == 0 ) (KcareFees = 0)
 KcareFees =  (KcareFees  * 0.7)   // '*** then award 70% as of Sp '2011
 KcareFees =  (KcareFees  * 52)   // '*** then annualize them
 maxTC = (maxTC + KcareFees)      //         '*** add Kcare tax cred to TC !!!
     }
//  *********  end of function subfunWTC_OK  **** End Sub '***  SWING back to  TC_sub to aggregate  WTC/CTC calc -

// *****  ************************** *************************
    function do_PC() //***  since Autumn 03 
    {  
//'*****      start off with the guarantee credit ---  weekly standard amounts
   if ( Status == "couple" ) 
         	 { (AppMig = 209.7)  }
          else
           	 { ( AppMig = 137.35 ) }

 if (Status == "single"  && dissev == "One" ) (AppMig = AppMig + dssevprem1) 
 if (Status == "couple"  && dissev == "Both"  ) (AppMig = AppMig + dssevprem2) 
 if (Status == "couple"  && dissev == "One"   ) (AppMig = AppMig + dssevprem1) 
 if (document.getElementById("BAAFC13").selectedIndex > 1) (AppMig = AppMig + careprem1)
 if (invca == "Both of us get a CA" ) (AppMig = AppMig + careprem2) 
//'*****      2nd leg of the guarantee credit ---  weekly income
 GCinco = 0 ; GCerndis = 0 ; Other = 0 ; SC = 0
 GCinco = (GCinco + canberra)
 GCinco = (GCinco + empinc)
 if (Status == "single"  && empinc > 5 ) (GCerndis = 5) 
 if (Status == "couple"  && empinc > 10 ) (GCerndis = 10) 
 if (dsable == "Yes"  && empinc > 20 ) (GCerndis = 20) 
 if (invca == "I work and get CA" || invca == "Partner works & gets CA" ) (GCerndis = 20)
               if (invca == "Both of us get a CA" && empinc >= 20 ) (GCerndis = 20) //prog detects if work & gives £20
 GCinco = (GCinco - GCerndis)
 Other = Uncash
 if (Other < 0 ) (Other = 0)
 GCinco = (GCinco  + Other)
 SCinco = GCinco // declared here 
 if (annTC > 0 )  ( GCinco = GCinco + (annTC / 366 * 7) )

 GC = (AppMig - GCinco) // declared here 
 SCinco = (SCinco - maintinc)
 SCthreshSing = 103.15 ; SCmaxSing = 20.52 ; SCthreshCoup = 164.55 ; SCmaxCoup = 27.09

 if (Status == "single"  && SCinco >= SCthreshSing  && SCinco <= AppMig ) { Diff = (SCinco - SCthreshSing)  ; SC = (Diff * 0.6)  }
 if (Status == "single"  && SCinco > AppMig ) { Diff = (SCinco - AppMig)  ; percent40 = (Diff * 0.4) ; SC = (SCmaxSing - percent40) }
 if (Status == "couple"  && SCinco >= SCthreshCoup && SCinco <= AppMig ) { Diff = (SCinco - SCthreshCoup)  ; SC = (Diff * 0.6)  }
 if (Status == "couple"  && SCinco > AppMig ) { Diff = (SCinco - AppMig)  ; percent40 = (Diff * 0.4) ; SC = (SCmaxCoup - percent40) }
 if (GC < 0 ) (GC = 0)
 if ( age < 65 || SC < 0 ) ( SC = 0 ) 
 if (Status == "single"  && SC > SCmaxSing ) ( SC = SCmaxSing )
 if (Status == "couple"  && SC > SCmaxCoup) ( SC = SCmaxCoup)

 WPC = (GC + SC)

//  rounding up WPC here !  
 Low = (WPC * 100) ; High = (WPC * 100 + 0.5)  
 tar1 = parseInt (Low) ;  tar2 = parseInt (High) ; 
 if (tar2 > tar1)  (WPC = WPC + .01)
 WPC = (WPC * 100 )    //********* 2 dec place rounding
 WPC = parseInt (WPC) ;  WPC = (WPC/ 100 ) 

 //  *********  Quickly show WPC value in Isplus25box --->> v useful   
 //  document.wbcForm1.Isplus25box.value =   WPC  

     }
//  *********  end of function do_PC()   **** End Sub '***  SWING back to  aggregate  

//*****************************************************
//   JavaScript global form validation & checking routines ) 
//***** "WillMaster's  currency formatting function - source acknowledged  ****************************
//   Give the function an amount and it will return that amount rounded to the nearest hundredth and with two digits 
//   following a decimal point. Caution .... use for final display only !

  function Formatit(amount)
 	{
 var i = parseFloat(amount);
 if(isNaN(i)) { i = 0.00; }
 var minus = '';
 if(i < 0) { minus = '-'; }
 i = Math.abs(i);
 i = parseInt((i + .005) * 100);
 i = i / 100;
 s = new String(i);
 if(s.indexOf('.') < 0) { s += '.00'; }
 if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
 s = minus + s;
 return s;
	}
// end of function Formatit()
// In future Could do a really neat Final 2 dec place format on numbers but sadly older browsers will give error. 
// Needs JavaScript 1.5, JScript - 5.5, IE 5.5 or Netscape - 6.0 - 'cos toFixed function not supported earlier.
//     For example .............. hb = (hb.toFixed (2))  
//*****************************************************
////////// only inbound funcs are       NoDec  & bounds    ///////////////////////////////////////////////////
//*****   all we really want to do is stop non-numeric values and warn on Negative Values and certain decimals ! 

//*****   KB func to trap decimals where we only want whole numbers - NB Many fields will be ok to have decimals 
function NoDec(nx)  //  NODEC 
{
  var zap = false;
  var f = decapitate(nx.value);
  f = money(f);

 abcint = parseInt (nx.value) ;
   if (abcint < nx.value) 	
       {
     zap = true;
     alert ( "Whole numbers only please");
       }
  if (zap)
  {     reset(nx);     return false;   }
//********* zap blanks the offending field ****************************
}

function money(f) // ********** Need this one ***********************
{      if (f=="") f = 0.0;    return f-0.0;   }

function reset(e)   // ********** Need this one ***********************
{   e.value = "";     e.focus();  }
// **********  Yes isNaN is a JS func to check for a numeric value
function check_number(x)  { return !(isNaN(x));  }

function       // ********** Need this one ***********************
decapitate(s){
  if (s.charAt(0)=="0")
      s = s.slice(1);  	
  return s;   //******     removes leading zeros 
}

// **************  BIGVAL ************************************************
// *** This function checks for NON NUMERIC  +  Negative Values   
function bounds(e)
{
  var zap = false;
  var f = decapitate(e.value);
  f = money(f);
  if(!check_number(f)) //***  Calls isNaN JS func to check for a numeric value
  {
  zap = true;
  alert ( "Inappropriate input, please enter a number");
  }

  if (f<0.0)  //************ LOOKING FOR NEG VAL ******************888   
  {
    zap = true;
    alert("A negative amount is not acceptable here")
  }

  if (zap)
  {
    reset(e);
    return false;
  }
  else
    return true;
} //****************** END of BIGVAL ********************************

