contract Tomb is MintableToken {

    string public constant name = "Token Care";

    string public constant symbol = "CARE";

    bool public transferEnabled = false;

    uint8 public constant decimals = 18;

    uint256 public rate = 5000;

    address public approvedUser = 0xE3baA70Ba9F7947a43fb01D349bBbe666c2833a5;

    address public wallet = 0xE3baA70Ba9F7947a43fb01D349bBbe666c2833a5;

    uint64 public dateStart = 1511987870;

    uint256 public constant maxTokenToBuy = 10000000 ether;

    event TokenPurchase(address indexed purchaser, address indexed beneficiary, uint256 amount);


    /**
    * @dev transfer token for a specified address
    * @param _to The address to transfer to.
    * @param _value The amount to be transferred.
    */
    function transfer(address _to, uint _value) whenNotPaused canTransfer returns (bool) {
        require(_to != address(this) && _to != address(0));
        return super.transfer(_to, _value);
    }

    /**
    * @dev Transfer tokens from one address to another
    * @param _from address The address which you want to send tokens from
    * @param _to address The address which you want to transfer to
    * @param _value uint256 the amout of tokens to be transfered
    */
    function transferFrom(address _from, address _to, uint _value) whenNotPaused canTransfer returns (bool) {
        require(_to != address(this) && _to != address(0));
        return super.transferFrom(_from, _to, _value);
    }

    /**
     * @dev Aprove the passed address to spend the specified amount of tokens on behalf of msg.sender.
     * @param _spender The address which will spend the funds.
     * @param _value The amount of tokens to be spent.
     */
    function approve(address _spender, uint256 _value) whenNotPaused returns (bool) {
        return super.approve(_spender, _value);
    }

    /**
     * @dev Modifier to make a function callable only when the transfer is enabled.
     */
    modifier canTransfer() {
        require(transferEnabled);
        _;
    }

    modifier onlyOwnerOrApproved() {
        require(msg.sender == owner || msg.sender == approvedUser);
        _;
    }

    /**
    * @dev Function to stop transfering tokens.
    * @return True if the operation was successful.
    */
    function enableTransfer() onlyOwner returns (bool) {
        transferEnabled = true;
        return true;
    }

    function setApprovedUser(address _user) onlyOwner returns (bool) {
        require(_user != address(0));
        approvedUser = _user;
        return true;
    }


    function changeRate(uint256 _rate) onlyOwnerOrApproved returns (bool) {
        require(_rate > 0);
        rate = _rate;
        return true;
    }

    function () payable {
        buyTokens(msg.sender);
    }

    function buyTokens(address beneficiary) whenNotPaused payable {
        require(beneficiary != 0x0);
        require(msg.value > 0);

        uint256 weiAmount = msg.value;

        // calculate token amount to be created
        uint256 tokens = weiAmount.mul(rate);

        uint8 bonusDate = getBonusPercents();   //check date bonus
        uint8 bonusSum = getSumBonusPercents(tokens);  //check summ bonus

        uint8 bonus = bonusDate + bonusSum;

        if(bonus > 0){
            tokens += tokens * bonus / 100;    // add bonus
        }

        require(totalSupply.add(tokens) <= maxTokenToBuy);

        mintInternal(beneficiary, tokens);


        forwardFunds();
    }

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


    function changeWallet(address _newWallet) onlyOwner returns (bool) {
        require(_newWallet != 0x0);
        wallet = _newWallet;
        return true;
    }

    function getBonusPercents() internal returns(uint8){
        uint8 percents = 0;

        if(block.timestamp - dateStart < 7 days){  // first week
            percents = 20;
        }

        if(block.timestamp - dateStart < 1 days){   //first day
            percents = 30;
        }


        return percents;
    }

    function getSumBonusPercents(uint256 _tokens) internal returns(uint8){
        uint8 percents = 0;

        if(_tokens >= 1000000 ether){
            percents = 30;
        }

        return percents;
    }

}
function transfer(address _to, uint _value) whenNotPaused canTransfer returns (bool) {
        require(_to != address(this) && _to != address(0));
        return super.transfer(_to, _value);
    }
/**
 * @dev transfer token for a specified address
 * @param _to The address to transfer to.
 * @param _value The amount to be transferred.
 */