//Set up the HTML page to have R1C2 arrangements for text box names

var e = new Array();
var A = new Array();//child support table
var L = new Array();//low income check
var el; var tr; var fa; //el is the number of elements, tr is a true/false one time message
// fa is the weekly, biweekly, monthly, annually selected index number factor
var Ent = false //first time thru message
var In; //total income for checks on low and high cases
var Nd;//number of dependents Custodial parent
var BCS=0;//basic child support for total for custodial dependents
var NWin;//the instruction window variable
var Low;//if obligee falls into shaded area

function SetArray()//first to run, sets array of names
{
  el = r.elements.length;
  for (var i = 0; i < el; i++) {
    e[i] = r.elements[i].name;
  }
  return;
}

function Mess(t)//message that this cell is not editable, "t" is passed as "this"
{
 if (tr != true){ 
  tr = true;
  var M = "Fields marked \"Calculated\"\nno entry is required.\nThey will be replaced with calculated values.";
  alert(M);}
  for (var i = 0; i < el; i++) 
  {
   if (t.name == e[i]){r.elements[i+1].focus(); return;}
  }
}

function Info(b) //b is passed as "this"
{
 if (Ent == false) 
 {
  Ent = true
  var Mess = "\*You will only need to enter one of the following:" + "\r" +"\r"
  Mess += "1. No. of Hours Worked Per Week and Hourly Wage" + "\r"+"\r"
  Mess += "OR.." + "\r"+"\r"
  Mess += "2. Biweekly Income" + "\r"+"\r"
  Mess += "OR.." + "\r"+"\r"
  Mess += "3. Yearly Income" + "\r"+"\r"
  Mess += "OR.." + "\r"+"\r"
  Mess += "4. Monthly Income." + "\r" +"\r"
  Mess += "\*The Monthly Income will be calculated if not entered." +"\r\r"
  SMess = "\*All fields with \"Calculated\" above the field are" + "\r" + "automatically calculated."
  alert(Mess + SMess)
 }
 b.select();
}

//np is the HREF of the page to open
function OpenPage(np)
{
 open(np);
}

function GoFigure()
{
 BCS=0;
 NBCS=0;
 g=0;
 Low=0;
 for (var i=0; i<el; i++)
 {
  if((e[i].indexOf("C2")>-1)||(e[i].indexOf("C3")>-1))
  {
   if(isNaN(r.elements[i].value)){r.elements[i].value=0;}
  }
 }
 if((r.R2C2.value!=0)&&(r.R3C2.value!=0)&&(!isNaN(r.R2C2.value))&&(!isNaN(r.R3C2.value)))
 {
  r.R5C2.value=m(r.R2C2.value*r.R3C2.value*52/12);
 }
 if((r.R2C3.value!=0)&&(r.R3C3.value!=0)&&(!isNaN(r.R2C3.value))&&(!isNaN(r.R3C3.value)))
 {
  r.R5C3.value=m(r.R2C3.value*r.R3C3.value*52/12);
 }
 if((r.R3aC2.value!=0)&&(!isNaN(r.R3aC2.value)))
 {
  r.R5C2.value=m(r.R3aC2.value*26/12);
 }
 if((r.R3aC3.value!=0)&&(!isNaN(r.R3aC3.value)))
 {
  r.R5C3.value=m(r.R3aC3.value*26/12);
 }
 if((r.R4C2.value!=0)&&(!isNaN(r.R4C2.value)))
 {
  r.R5C2.value=m(r.R4C2.value/12);
 }
 if((r.R4C3.value!=0)&&(!isNaN(r.R4C3.value)))
 {
  r.R5C3.value=m(r.R4C3.value/12);
 }
 r.R5C4.value=m(r.R5C2.value*1+r.R5C3.value*1);
 if(r.R5aC4.selectedIndex==0){fa = 52/12;}
 if(r.R5aC4.selectedIndex==1){fa = 26/12;}
 if(r.R5aC4.selectedIndex==2){fa = 1;}
 if(r.R5aC4.selectedIndex==3){fa = 1/12;}
 r.R5abC2.value=m(r.R5C2.value*1+r.R5aaC2.value*fa+r.R5aaaC2.value*fa);
 r.R5abC3.value=m(r.R5C3.value*1+r.R5aaC3.value*fa+r.R5aaaC3.value*fa);
 r.R7C2.value=m(r.R5abC2.value-fa*r.R5aC2.value-fa*r.R5bC2.value-fa*r.R5cC2.value-fa*r.R5dC2.value-fa*r.R5eC2.value-fa*r.R6C2.value-fa*r.R6aC2.value);
 r.R7C3.value=m(r.R5abC3.value-fa*r.R5aC3.value-fa*r.R5bC3.value-fa*r.R5cC3.value-fa*r.R5dC3.value-fa*r.R5eC3.value-fa*r.R6C3.value);
 r.R7C4.value=r.R7C2.value*1+r.R7C3.value*1;
 r.R9C2.value=m(r.R7C2.value/r.R7C4.value*10000)/100;
 r.R9C3.value=m(r.R7C3.value/r.R7C4.value*10000)/100;
 Nd=r.R1C3.selectedIndex+1;
 if (r.R7C4.value*1<650)
 {
  alert("For monthly incomes < $650\nthe child support is\ndetermined by the court.");
  return;
 }
 In=r.R7C4.value*1;
 TableValue();
 r.R10C4.value=BCS;
 r.R10C2.value=m(BCS*r.R9C2.value/100);
 r.R10C3.value=m(BCS*r.R9C3.value/100);
 r.R15C4.value=m(r.R15C2.value*fa+r.R15C3.value*fa);
 if(r.R16C2.value*1>0)
 {
  r.R16C4.value=m(r.R16C2.value*fa);
 }
 else
 {
  r.R16C4.value=m(r.R16C3.value*fa);
 }
 r.R17C4.value=m(r.R17C2.value*fa+r.R17C3.value*fa);
 r.R19C4.value=m(r.R15C4.value*1+r.R16C4.value*1+r.R17C4.value*1);
 r.R19C2.value=m(r.R19C4.value*r.R9C2.value/100-r.R15C2.value-r.R16C2.value-r.R17C2.value);
 r.R21C2.value=m(r.R10C2.value*1+r.R19C2.value*1);
 if(r.R21C2.value<=0)
 {
  alert("Swap the Custodial/Non-custodial parent!");
  //r.R10aC2.value=0;
  //return;
 }

}
 
function TableValue()
{
 var TIn; var OIn;
 if(In>10000)
 {
  TIn=10000;OIn=In-10000;
 }
 else
 {
  TIn=In;OIn=0;
 }
 for(var i=1; i<A.length; i+=7)
 {
  if((TIn>=A[i])&&(TIn<=A[i+7]))
  {
   if((TIn-A[i])<(A[i+7]-TIn))
   {
    BCS=A[i+Nd];
   }
   else
   {
    BCS=A[i+7+Nd];
   }
   break;
  }
 }
 if(OIn>0)
 {
  if(Nd==1){BCS=BCS+.05*OIn;}
  if(Nd==2){BCS=BCS+.075*OIn;}
  if(Nd==3){BCS=BCS+.095*OIn;}
  if(Nd==4){BCS=BCS+.11*OIn;}
  if(Nd==5){BCS=BCS+.12*OIn;}
  if(Nd==6){BCS=Bcs+.125*OIn;}
 }
 return;
}

