contract SellableToken is Multivest {

    using SafeMath for uint256;

    // The token being sold
    Spark public spark;

    // start and end timestamps where investments are allowed (both inclusive)
    uint256 public startTime;
    uint256 public endTime;

    // amount of sold tokens
    uint256 public soldTokens;

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

    // address where funds are collected
    address public etherHolder;

    address public tokensHolder;

    Bonus[] public bonuses;

    struct Bonus {
        uint256 maxAmount;
        uint256 bonus;
    }

    function SellableToken(
        address _multivestAddress,
        address _etherHolder,
        address _tokensHolder,
        address _spark,
        uint256 _startTime,
        uint256 _endTime
    ) public Multivest(_multivestAddress)
    {
        require(_spark != address(0) && _etherHolder != address(0) && _tokensHolder != address(0));
        spark = Spark(_spark);
        etherHolder = _etherHolder;
        tokensHolder = _tokensHolder;

        require(_startTime < _endTime);

        startTime = _startTime;
        endTime = _endTime;
    }

    function setSpark(address _spark) public onlyOwner {
        require(_spark != address(0));
        spark = Spark(_spark);
    }

    function setEtherHolder(address _etherHolder) public onlyOwner {
        require(_etherHolder != address(0));
        etherHolder = _etherHolder;
    }

    function setTokenHolder(address _tokensHolder) public onlyOwner {
        require(_tokensHolder != address(0));
        tokensHolder = _tokensHolder;
    }

    function transferEthers() public onlyOwner {
        etherHolder.transfer(this.balance);
    }

    // @return true if sale period is active
    function isActive() public constant returns (bool) {
        if (soldTokens == spark.maxSupply()) {
            return false;
        }
        return withinPeriod();
    }

    // @return true if the transaction can buy tokens
    function withinPeriod() public constant returns (bool) {
        return block.timestamp >= startTime && block.timestamp <= endTime;
    }
}
function withinPeriod() public constant returns (bool) {
        return block.timestamp >= startTime && block.timestamp <= endTime;
    }
// @return true if the transaction can buy tokens