
function numberFormat(nStr){
	 c =  parseFloat(nStr);
         d = c.toFixed(2);
	 return d;
}

function calcform()
{
 
  

  document.getElementById("total_mth").value  = parseFloat(document.getElementById("ext_mth_price").value) 
                                              + parseFloat(document.getElementById("ata_mth_total").value) 
				              + parseFloat(document.getElementById("phone_mth_total").value)                                                                      + parseFloat(document.getElementById("did_mth_price_total").value);
  
  document.getElementById("total_setup").value = parseFloat(document.getElementById("ext_buy_price").value) 
                                               + parseFloat(document.getElementById("ata_buy_total").value)
				               + parseFloat(document.getElementById("phone_buy_total").value) 
				               + parseFloat(document.getElementById("did_buy_price_total").value);


 

  document.getElementById("ext_buy_price").value       = numberFormat(document.getElementById("ext_buy_price").value);
  document.getElementById("ext_mth_price").value       = numberFormat(document.getElementById("ext_mth_price").value);
  document.getElementById("ata_buy_total").value       = numberFormat(document.getElementById("ata_buy_total").value);
  document.getElementById("ata_mth_total").value       = numberFormat(document.getElementById("ata_mth_total").value);
  document.getElementById("phone_buy_total").value     = numberFormat(document.getElementById("phone_buy_total").value);
  document.getElementById("phone_mth_total").value     = numberFormat(document.getElementById("phone_mth_total").value);
  document.getElementById("did_buy_price_total").value = numberFormat(document.getElementById("did_buy_price_total").value);
  document.getElementById("did_mth_price_total").value = numberFormat(document.getElementById("did_mth_price_total").value);
  document.getElementById("total_mth").value           = numberFormat(document.getElementById("total_mth").value);
  document.getElementById("total_setup").value         = numberFormat(document.getElementById("total_setup").value);

}


function calc_ext()    
{

 foo =  document.getElementById("ext_qty").value;
  
 
  if(foo == 10)  {  document.getElementById("ext_mth_price").value = "59.95";  document.getElementById("ext_buy_price").value = "0.00";}
  if(foo == 25)  {  document.getElementById("ext_mth_price").value = "95.95";  document.getElementById("ext_buy_price").value = "0.00";}
  if(foo == 50)  {  document.getElementById("ext_mth_price").value = "195.95"; document.getElementById("ext_buy_price").value = "49.00";}
  if(foo == 100) {  document.getElementById("ext_mth_price").value = "229.95"; document.getElementById("ext_buy_price").value = "99.00";}
  calcform();
}


function calc_ata()    
{
  var foo  =  document.getElementById("ata_qty").value;
  var moo = "";
  var rent = 0;
  var buy  = 0;
  
  for(i=1;i<4;i++) {  
      if (document.getElementById("ata_type[" + i + "]").checked ) { moo = document.getElementById("ata_type["+i+"]").value;}
     }
  
  if(moo == "buy")  {buy  = 49.95;rent = 0;}
  if(moo == "rent") {buy  = 0;rent = 7.95;}
  if(moo == "own")  {buy  = 0;rent = 0;}
  document.getElementById("ata_buy_total").value =  parseFloat(foo) * buy;
  document.getElementById("ata_mth_total").value =  parseFloat(foo) * rent;
  calcform();
}

function calc_phone()    
{
  var foo  =  document.getElementById("phone_qty").value;
  var moo = "";
  var rent = 0;
  var buy  = 0;

  for(i=1;i<4;i++) {  
      if (document.getElementById("phone_type[" + i + "]").checked ) { moo = document.getElementById("phone_type["+i+"]").value;}
     } 
  
  if(moo == "buy")  {buy  = 120.00;rent = 0.00;}
  if(moo == "rent") {buy  = 0.00  ;rent = 7.95;}
  if(moo == "own")  {buy  = 0.00  ;rent = 0.00;}

  document.getElementById("phone_buy_total").value =  parseFloat(foo) * buy;
  document.getElementById("phone_mth_total").value =  parseFloat(foo) * rent;

  calcform();
}




function show_dids() {
  foo = parseFloat(document.getElementById("did_qty").value);
  for(x=1; x<11; x++ ) {document.getElementById("did[" + x + "]").style.display="none";}
  for(i=1; i<foo+1 ; i++ ) {document.getElementById("did[" + i + "]").style.display="block";}
  
  // clear each did to NONOE
    for(i=1; i<11 ;i++) {
	  for(x=1;x<5;x++)
	    {             
             foo = document.getElementById("did_type[" + i + "][" + x + "]");	     
	     foo.checked = "";
	    }      
	    
	    document.getElementById("did_type[" + i + "][" + 5 + "]").checked = "checked";
	    
     }

  calc_did();
}


function calc_did() {
  
   var pm1 = 9.95;
   var pm2 = 19.95;
   var pm3 = 24.95;
   var pm4 = 42.95;
   var pm5 = 0;

   var pb1 = 0;
   var pb2 = 0;
   var pb3 = 0;
   var pb4 = 0;
   var pb5 = 0;
   
   
   var bt = 0;
   var mt = 0;
   
  for(i=1; i<11 ;i++) {
          
	  for(x=1;x<6;x++)
	    {             
             foo = document.getElementById("did_type[" + i + "][" + x + "]");
	     moo = foo.value;
	     moo2 = foo.checked;	     
	     
	     if(moo2) {x=7;}	     
	    }   
	    
          // Here we calc all dids setup and mth cost
	  if(foo.value == "plan1") {bt = bt + pb1; mt = mt + pm1;}
	  if(foo.value == "plan2") {bt = bt + pb2; mt = mt + pm2;}
	  if(foo.value == "plan3") {bt = bt + pb3; mt = mt + pm3;}
	  if(foo.value == "plan4") {bt = bt + pb4; mt = mt + pm4;}
	  if(foo.value == "plan5") {bt = bt + pb5; mt = mt + pm5;}
	  
	  document.getElementById("did_buy_price_total").value = bt;
	  document.getElementById("did_mth_price_total").value = mt;
     }
  calcform();
}

function initform()
{   
   calcform();
   show_dids();   
}

