contract Crowdsale is Ownable {

  using SafeMath for uint256;

  // The token being sold
  GMPToken public token;

  // Flag setting that investments are allowed (both inclusive)
  bool public saleIsActive;

  // address where funds are collected
  address public wallet;

  // Price for 1 token in wei. i.e. 562218890554723
  uint256 public rate;

  // amount of raised money in wei
  uint256 public weiRaised;

  /**
   * event for token purchase logging
   * @param purchaser who paid for the tokens
   * @param beneficiary who got the tokens
   * @param value weis paid for purchase
   * @param amount amount of tokens purchased
   */
  event TokenPurchase(address indexed purchaser, address indexed beneficiary, uint256 value, uint256 amount);


  /* -----------   A D M I N        F U N C T I O N S    ----------- */

  function Crowdsale(uint256 _initialRate, address _targetWallet) {

    //Checks
    require(_initialRate > 0);
    require(_targetWallet != 0x0);

    //Init
    token = new GMPToken();
    rate = _initialRate;
    wallet = _targetWallet;
    saleIsActive = true;

  }

  function close() onlyOwner {
    selfdestruct(owner);
  }

  //Transfer token to
  function transferToAddress(address _targetWallet, uint256 _tokenAmount) onlyOwner {
    token.transfer(_targetWallet, _tokenAmount);
  }


  //Setters
  function enableSale() onlyOwner {
    saleIsActive = true;
  }

  function disableSale() onlyOwner {
    saleIsActive = false;
  }

  function setRate(uint256 _newRate)  onlyOwner {
    rate = _newRate;
  }

  //Mint new tokens
  function mintToken(uint256 _mintedAmount) onlyOwner {
    token.mintToken(_mintedAmount);
  }



  /* -----------   P U B L I C      C A L L B A C K       F U N C T I O N     ----------- */

  function () payable {

    require(msg.sender != 0x0);
    require(saleIsActive);
    require(msg.value > rate);

    uint256 weiAmount = msg.value;

    //Update total wei counter
    weiRaised = weiRaised.add(weiAmount);

    //Calc number of tokents
    uint256 tokenAmount = weiAmount.div(rate);

    //Forward wei to wallet account
    wallet.transfer(weiAmount);

    //Transfer token to sender
    token.transfer(msg.sender, tokenAmount);
    TokenPurchase(msg.sender, wallet, weiAmount, tokenAmount);

  }



}
function Crowdsale(uint256 _initialRate, address _targetWallet) {

  //Checks
  require(_initialRate > 0);
  require(_targetWallet != 0x0);

  //Init
  token = new GMPToken();
  rate = _initialRate;
  wallet = _targetWallet;
  saleIsActive = true;

}

/* -----------   A D M I N        F U N C T I O N S    ----------- */