ResetAll()
var pop = 0
var pow = 0
var cnt = 0
var NewPow = 0

function Region(target) {
   for (a=0;a<Nation.length;a++) {
      if (Nation[a][1]==target) {
         if (document.TSNationsForm.Nations[a].checked == false) {
            document.TSNationsForm.Nations[a].checked = true
            Modify(a)
         }
      }
   }
}

function Alliance(target) {
   for (a=0;a<Nation.length;a++) {
      if (Nation[a][3]==target) {
         if (document.TSNationsForm.Nations[a].checked == false) {
            document.TSNationsForm.Nations[a].checked = true
            Modify(a)
         }
      }
   }
}

function Modify(target) {
   if (document.TSNationsForm.Nations[target].checked == true) {
      pop += Nation[target][4]
      pow += Nation[target][6]
      cnt += 1
   } else {
      pop -= Nation[target][4]
      pow -= Nation[target][6]
      cnt -= 1
   }

   if (cnt == 0) { pow = 0 }
   if (pow==0) {
      NewPow = 0
   } else {
      NewPow = Math.round((Math.log(pow) / Math.LN2)*100)/100
   }

   var PopNew = pop.toString()
   var PopNew2 = PopNew

   if ( PopNew2 > 10000000000 ) {
      PopNew  = PopNew2.substring(0, 2) + ','
      PopNew += PopNew2.substring(2, 5) + ','
      PopNew += PopNew2.substring(5, 8) + ','
      PopNew += PopNew2.substring(8)
   } else {
   if ( PopNew2 > 1000000000 ) {
      PopNew  = PopNew2.substring(0, 1) + ','
      PopNew += PopNew2.substring(1, 4) + ','
      PopNew += PopNew2.substring(4, 7) + ','
      PopNew += PopNew2.substring(7)
   } else {
   if ( PopNew2 > 100000000 ) {
      PopNew  = PopNew2.substring(0, 3) + ','
      PopNew += PopNew2.substring(3, 6) + ','
      PopNew += PopNew2.substring(6)
   } else {
   if ( PopNew2 > 10000000 ) {
      PopNew  = PopNew2.substring(0, 2) + ','
      PopNew += PopNew2.substring(2, 5) + ','
      PopNew += PopNew2.substring(5)
   } else {
   if ( PopNew2 > 1000000 ) {
      PopNew  = PopNew2.substring(0, 1) + ','
      PopNew += PopNew2.substring(1, 4) + ','
      PopNew += PopNew2.substring(4)
   } else {
   if ( PopNew2 > 100000 ) {
      PopNew  = PopNew2.substring(0, 3) + ','
      PopNew += PopNew2.substring(3)
   } else {
   if ( PopNew2 > 10000 ) {
      PopNew  = PopNew2.substring(0, 2) + ','
      PopNew += PopNew2.substring(2)
   }}}}}}}

   document.TSform.TSPop.value = "  " + PopNew
   document.TSform.TSPow.value = "  " + NewPow
   document.TSform.TSCnt.value = "  " + cnt
   self.status = "The new alliance consists of " + cnt + " countries, with a power of " + NewPow + " and a population of " + PopNew + "."
}

function ResetAll() {
   document.TSform.TSPop.value = ""
   document.TSform.TSPow.value = ""
   document.TSform.TSCnt.value = ""
   self.status = ""
 pop = 0
   pow = 0
   cnt = 0
   NewPow = 0
}


