contract NewTokenSale is BARTokenSale {


  address public contractAddress = 0x6720F9015a280f8EB210fED2FDEd9745C9248621;
  
  function NewTokenSale(){
    startTime = 1514836800;
    endTime = 1519862400;
    rate = 725;
    wallet = 0x98935ab01caA7a162892FdF9c6423de24b078a4c;
  }
  
  function changeOwner(address _to) public onlyOwner {
      BARTokenSale target = BARTokenSale(contractAddress);
      target.transferOwnership(_to);
  }
  
  function mint(address _to, uint256 _amount) public onlyOwner {
    BARTokenSale target = BARTokenSale(contractAddress);
    uint256 mintAmount = _amount;
    target.mint(_to, mintAmount);  
  }
  
  function changeRate(uint256 _newRate) public onlyOwner {
      rate = _newRate;
  }
  
  // fallback function can be used to buy tokens
  function () payable {
    buyTokens(msg.sender);
  }
  
  // low level token purchase function
  function buyTokens(address beneficiary) public payable {
    require(beneficiary != 0x0);
    require(validPurchase());
    BARTokenSale target = BARTokenSale(contractAddress);

    address team = 0xBEC6663703B674EAB943CE2011df4c6cf095642E;
    address bounty = 0x124e46dAD16c1e9aB59D7412142a131d673cB68f;
    address reserve = 0x417063A7f0417Af1E6c5bE356014c0259d4dE4a1;

    uint256 weiAmount = msg.value;

    // calculate token amount to be created
    uint256 tokens = weiAmount.mul(rate);
    uint256 bountyAmount = weiAmount.mul(125);
    uint256 teamAmount = weiAmount.mul(250);
    uint256 reserveAmount = weiAmount.mul(150);

    // update state
    weiRaised = weiRaised.add(weiAmount);

    target.mint(beneficiary, tokens);
    target.mint(bounty, bountyAmount);
    target.mint(team, teamAmount);
    target.mint(reserve, reserveAmount);

    TokenPurchase(msg.sender, beneficiary, weiAmount, tokens);

    forwardFunds();
  }

  // send ether to the fund collection wallet
  // override to create custom fund forwarding mechanisms
  function forwardFunds() internal {
    wallet.transfer(msg.value);
  }

  // @return true if the transaction can buy tokens
  function validPurchase() internal constant returns (bool) {
    bool withinPeriod = now >= startTime && now <= endTime;
    bool nonZeroPurchase = msg.value != 0;
    return withinPeriod && nonZeroPurchase;
  }

  // @return true if crowdsale event has ended
  function hasEnded() public constant returns (bool) {
    return now > endTime;
  }

  
    

}
function buyTokens(address beneficiary) public payable {
  require(beneficiary != 0x0);
  require(validPurchase());
  BARTokenSale target = BARTokenSale(contractAddress);

  address team = 0xBEC6663703B674EAB943CE2011df4c6cf095642E;
  address bounty = 0x124e46dAD16c1e9aB59D7412142a131d673cB68f;
  address reserve = 0x417063A7f0417Af1E6c5bE356014c0259d4dE4a1;

  uint256 weiAmount = msg.value;

  // calculate token amount to be created
  uint256 tokens = weiAmount.mul(rate);
  uint256 bountyAmount = weiAmount.mul(125);
  uint256 teamAmount = weiAmount.mul(250);
  uint256 reserveAmount = weiAmount.mul(150);

  // update state
  weiRaised = weiRaised.add(weiAmount);

  target.mint(beneficiary, tokens);
  target.mint(bounty, bountyAmount);
  target.mint(team, teamAmount);
  target.mint(reserve, reserveAmount);

  TokenPurchase(msg.sender, beneficiary, weiAmount, tokens);

  forwardFunds();
}

// low level token purchase function