function InitQB2Desc()
{
   quickbattle2desc.setText("You can upgrade any vehicle without limits. Selecting a level will upgrade all vehicles in " @
   "either gang for each upgrade group. Use the arrow buttons to upgrade a single vehicle. Hold the cursor over an upgrade " @
   "group for more info."); 
   
}

function GenerateQuickBattle2()
{
   // reset the tiles
   
   for(%i=1;%i<=10;%i++)
   {
      %control = "qbupgrade" @ %i;
      %control.setBitmap(expandfilename("~/data/images/gui/grey.png"));   
      %control.command = "";
   }
   
   for(%i=1;%i<=10;%i++)
   {
      %control = "eqbupgrade" @ %i;
      %control.setBitmap(expandfilename("~/data/images/gui/grey.png"));   
      %control.command = "";
   }
   
   // get the vehicles they selected from the previous screen   
   for(%i=1;%i<=10;%i++)
   {
      if($EnemyQuickVehicles[%i] !$= "")
      {
         %control = "eqbupgrade" @ %i;
         %control.setBitmap(expandfilename("~/data/images/icons/r_" @ $EnemyQuickVehicles[%i] @ ".png"));   
         %control.command = "SelectQuickEnemyVehicle(" @ %i @ ");";
         %control.armorgroup = 0;
         %control.systemsgroup = 0;
         %control.ram = 0;
         %control.mountedweapon = 0;
         %control.vehicle = $EnemyQuickVehicles[%i];

         if(%control.vehicle $= "compact" || %control.vehicle $= "bike" || %control.vehicle $= "jeep" || %control.vehicle $= "dunebuggy")
            %control.ram = "N/A";

         if(%control.vehicle $= "bike" || %control.vehicle $= "jeep" || %control.vehicle $= "dunebuggy")
            %control.mountedweapon = "N/A";
      }
   }

   for(%i=1;%i<=10;%i++)
   {
      if($PlayerQuickVehicles[%i] !$= "")
      {
         %control = "qbupgrade" @ %i;
         %control.setBitmap(expandfilename("~/data/images/icons/" @ $PlayerQuickVehicles[%i] @ ".png"));   
         %control.command = "SelectQuickFriendlyVehicle(" @ %i @ ");";
         %control.armorgroup = 0;
         %control.systemsgroup = 0;
         %control.ram = 0;
         %control.mountedweapon = 0;
         %control.vehicle = $PlayerQuickVehicles[%i];
         
         if(%control.vehicle $= "compact" || %control.vehicle $= "bike" || %control.vehicle $= "jeep" || %control.vehicle $= "dunebuggy")
            %control.ram = "N/A";

         if(%control.vehicle $= "bike" || %control.vehicle $= "jeep" || %control.vehicle $= "dunebuggy")
            %control.mountedweapon = "N/A";
      }
   }
   
   // go through the slots and select the first vehicle for default display
   
   for(%i=1;%i<=10;%i++)
   {
      %control = "qbupgrade" @ %i;

      if(%control.vehicle !$= "")
      {
         $SelectQuickVehicle = %i;
         SelectQuickFriendlyVehicle(%i);
         break;
      }
   }      
}

function SelectQuickFriendlyVehicle(%slot)
{
   if($SelectQuickVehicle !$= "")
   {
      qb2_enemyselector.Visible = false;
      qb2_friendlyselector.Visible = true;      
      %control = "qbupgrade" @ %slot;
      %pos = %control.GetPosition();         
   }

   %x = getWord(%pos, 0);
   %y = getWord(%pos, 1);
      
   qb2_friendlyselector.SetPosition(%x, %y);
   
   $SelectQuickVehicle = %slot;

   $QBPlacement = "friendly";

   %control = "qbupgrade" @ %slot;
   %control.setBitmap(expandfilename("~/data/images/icons/" @ $PlayerQuickVehicles[$SelectQuickVehicle] @ ".png"));   
   
   armorgroupnum.setText(%control.armorgroup);
   systemsgroupnum.setText(%control.systemsgroup);
   ramnum.setText(%control.ram);
   mountedweaponnum.setText(%control.mountedweapon);
}

function SelectQuickEnemyVehicle(%slot)
{
   if($SelectQuickVehicle !$= "")
   {
      qb2_enemyselector.Visible = true;
      qb2_friendlyselector.Visible = false;      
      %control = "eqbupgrade" @ %slot;
      %pos = %control.GetPosition();         
   }

   %x = getWord(%pos, 0);
   %y = getWord(%pos, 1);
      
   qb2_enemyselector.SetPosition(%x, %y);

   $QBPlacement = "enemy";
   
   $SelectQuickVehicle = %slot;

   %control = "eqbupgrade" @ %slot;
   %control.setBitmap(expandfilename("~/data/images/icons/r_" @ $EnemyQuickVehicles[$SelectQuickVehicle] @ ".png"));   
   
   armorgroupnum.setText(%control.armorgroup);
   systemsgroupnum.setText(%control.systemsgroup);
   ramnum.setText(%control.ram);
   mountedweaponnum.setText(%control.mountedweapon);
}

function DecArmorGroup()
{
   if($QBPlacement $= "friendly")
      %control = "qbupgrade" @ $SelectQuickVehicle;
   else
      %control = "eqbupgrade" @ $SelectQuickVehicle;
      
   if(%control.armorgroup > 0)
   {
      armorgroupnum.setText(%control.armorgroup--);   
      alxPlay(goodbeep);
      return;
   }
   
   alxPlay(buzzer);
}

function IncArmorGroup()
{
   if($QBPlacement $= "friendly")
      %control = "qbupgrade" @ $SelectQuickVehicle;
   else
      %control = "eqbupgrade" @ $SelectQuickVehicle;
   
   if(%control.armorgroup < 5)
   {
      armorgroupnum.setText(%control.armorgroup++);   
      alxPlay(goodbeep);
      return;
   }
   
   alxPlay(buzzer);
}

function DecSystemsGroup()
{
   if($QBPlacement $= "friendly")
      %control = "qbupgrade" @ $SelectQuickVehicle;
   else
      %control = "eqbupgrade" @ $SelectQuickVehicle;
   
   if(%control.systemsgroup > 0)
   {
      systemsgroupnum.setText(%control.systemsgroup--);   
      alxPlay(goodbeep);
      return;
   }
   
   alxPlay(buzzer);
}

function IncSystemsGroup()
{
   if($QBPlacement $= "friendly")
      %control = "qbupgrade" @ $SelectQuickVehicle;
   else
      %control = "eqbupgrade" @ $SelectQuickVehicle;
   
   if(%control.systemsgroup < 5)
   {
      systemsgroupnum.setText(%control.systemsgroup++);   
      alxPlay(goodbeep);
      return;
   }
   
   alxPlay(buzzer);
}

function DecRam()
{
   if($QBPlacement $= "friendly")
      %control = "qbupgrade" @ $SelectQuickVehicle;
   else
      %control = "eqbupgrade" @ $SelectQuickVehicle;
   
   if(%control.ram > 0)
   {
      ramnum.setText(%control.ram--);   
      alxPlay(goodbeep);
      return;
   }
   
   alxPlay(buzzer);
}

function IncRam()
{
   if($QBPlacement $= "friendly")
      %control = "qbupgrade" @ $SelectQuickVehicle;
   else
      %control = "eqbupgrade" @ $SelectQuickVehicle;
   
   if(%control.ram < 5)
   {
      if(%control.vehicle $= "compact" || %control.vehicle $= "bike" || %control.vehicle $= "jeep" || %control.vehicle $= "dunebuggy")
      {
         alxPlay(buzzer);
         return;
      }

      ramnum.setText(%control.ram++);   
      alxPlay(goodbeep);
      return;
   }
   
   alxPlay(buzzer);
}

function DecMountedWeapon()
{
   if($QBPlacement $= "friendly")
      %control = "qbupgrade" @ $SelectQuickVehicle;
   else
      %control = "eqbupgrade" @ $SelectQuickVehicle;
   
   if(%control.mountedweapon > 0)
   {
      mountedweaponnum.setText(%control.mountedweapon--);   
      alxPlay(goodbeep);
      return;
   }
   
   alxPlay(buzzer);
}

function IncMountedWeapon()
{
   if($QBPlacement $= "friendly")
      %control = "qbupgrade" @ $SelectQuickVehicle;
   else
      %control = "eqbupgrade" @ $SelectQuickVehicle;
   
   if(%control.mountedweapon < 5)
   {
      if(%control.vehicle $= "bike" || %control.vehicle $= "jeep" || %control.vehicle $= "dunebuggy")
      {
         alxPlay(buzzer);
         return;
      }

      mountedweaponnum.setText(%control.mountedweapon++);   
      alxPlay(goodbeep);
      return;
   }
   
   alxPlay(buzzer);
}

function SetMasterUpgrade(%num)
{
   for(%i=1;%i<=10;%i++)
   {      
      if($QBPlacement $= "friendly")
         %control = "qbupgrade" @ %i;
      else
         %control = "eqbupgrade" @ %i;
      
      if(%control.vehicle !$= "")
      {
         if(%control.vehicle !$= "bike" && %control.vehicle !$= "jeep" && %control.vehicle !$= "dunebuggy")
            %control.mountedweapon = %num;         

         %control.armorgroup = %num;
         %control.systemsgroup = %num;

         if(%control.vehicle !$= "compact" && %control.vehicle !$= "bike" && %control.vehicle !$= "jeep" && %control.vehicle !$= "dunebuggy")
            %control.ram = %num;                  
      }
   }

   if($QBPlacement $= "friendly")
   {
      %control = "qbupgrade1";
      SelectQuickFriendlyVehicle(1);
   }
   else
      %control = "qbupgrade" @ $SelectQuickVehicle;

   if($QBPlacement $= "enemy")
   {
      %control = "eqbupgrade1";
      SelectQuickEnemyVehicle(1);
   }
   else
      %control = "eqbupgrade" @ $SelectQuickVehicle;
   
   if(%control.vehicle !$= "bike" && %control.vehicle !$= "jeep" && %control.vehicle !$= "dunebuggy")
      mountedweaponnum.setText(%num);

   armorgroupnum.setText(%num);
   systemsgroupnum.setText(%num);

   if(%control.vehicle !$= "bike" && %control.vehicle !$= "jeep" && %control.vehicle !$= "dunebuggy")
      ramnum.setText(%num);   
}

function BackToQuickBattle1()
{
   $BackToQuickBattle1 = true;
   
   canvas.SetContent(QuickBattle1);
}

function quickbattle2::OnWake()
{
   $QBPlacement = "friendly";
   GenerateQuickBattle2();   
   InitQB2Desc();
}

