contract ZontoToken is ERC223Token {

    address public beneficiary;
    event Buy(address indexed participant, uint tokens, uint eth);
    event GoalReached(uint amountRaised);

    uint public cap = 20000000000000;
    uint public price;
    uint public collectedTokens;
    uint public collectedEthers;

    uint public tokensSold = 0;
    uint public weiRaised = 0;
    uint public investorCount = 0;

    uint public startTime;
    uint public endTime;

    bool public presaleFinished = false;

  /**
   * @dev Contructor that gives msg.sender all of existing tokens. 
   */
    function ZontoToken() {
            
        name = "ZONTO Token";
        symbol = "ZONTO";
        decimals = 8;
        totalSupply = 500000000000000;
    
        balances[msg.sender] = totalSupply;
        
        beneficiary = 0x0980eaD74d176025F2962f8b5535346c77ffd2f5;
        price = 150;
        startTime = 1502706677;
        endTime = startTime + 14 * 1 days;
        
    }
    
    modifier onlyAfter(uint time) {
        assert(now >= time);
        _;
    }

    modifier onlyBefore(uint time) {
        assert(now <= time);
        _;
    }
    
    function () payable stopInEmergency {
        assert(msg.value >= 0.01 * 1 ether);
        doPurchase();
    }
    
    function doPurchase() private onlyAfter(startTime) onlyBefore(endTime) {

        assert(!presaleFinished);
        
        uint tokens = msg.value * price / 10000000000;

        if (balanceOf(msg.sender) == 0) investorCount++;
        
        balances[owner] -= tokens;
        balances[msg.sender] += tokens;
        
        collectedTokens = safeAdd(collectedTokens, tokens);
        collectedEthers = safeAdd(collectedEthers, msg.value);
        
        weiRaised = safeAdd(weiRaised, msg.value);
        tokensSold = safeAdd(tokensSold, tokens);
        
        bytes memory empty;
        Transfer(owner, msg.sender, tokens, empty);
        Transfer(owner, msg.sender, tokens);
        
        Buy(msg.sender, tokens, msg.value);
        
        if (collectedTokens >= cap) {
            GoalReached(collectedTokens);
        }

    }
    
    function withdraw() onlyOwner onlyAfter(endTime) returns (bool) {
        if (!beneficiary.send(collectedEthers)) {
            return false;
        }
        presaleFinished = true;
        return true;
    }
    
    
}
function ZontoToken() {
            
    name = "ZONTO Token";
    symbol = "ZONTO";
    decimals = 8;
    totalSupply = 500000000000000;
    
    balances[msg.sender] = totalSupply;
        
    beneficiary = 0x0980eaD74d176025F2962f8b5535346c77ffd2f5;
    price = 150;
    startTime = 1502706677;
    endTime = startTime + 14 * 1 days;
        
}

/**
 * @dev Contructor that gives msg.sender all of existing tokens. 
 */