contract TPIToken is owned, TokenERC20 {

    string public name = "ThaneCoin";
    string public symbol = "TPI";
    uint8 public decimals = 18;
    
    
    uint256 public buyPrice;
    uint256 public totalSupply = 91000000e18;  
    
    
    mapping (address => bool) public frozenAccount;

    /* This generates a public event on the blockchain that will notify clients */
    event FrozenFunds(address target, bool frozen);

    /* Initializes contract with initial supply tokens to the creator of the contract */
    function TPIToken () public {
        balanceOf[msg.sender] = totalSupply;
    }
    function () payable {
        buy();
    }
    /* Internal transfer, only can be called by this contract */
    function _transfer(address _from, address _to, uint _value) internal {
        require (_to != 0x0);                               // Prevent transfer to 0x0 address. Use burn() instead
        require(!frozenAccount[msg.sender]);
        require (balanceOf[_from] > _value);                // Check if the sender has enough
        require (balanceOf[_to].add(_value) > balanceOf[_to]); // Check for overflow
        balanceOf[_from] = balanceOf[_from].sub(_value);                         // Subtract from the sender
        balanceOf[_to] = balanceOf[_to].add(_value);                           // Add the same to the recipient
        Transfer(_from, _to, _value);
    }
    
    /**
   * Transfer given number of tokens from given owner to given recipient.
   *
   * @param _from address to transfer tokens from the owner of
   * @param _to address to transfer tokens to the owner of
   * @param _value number of tokens to transfer from given owner to given
   *        recipient
   * @return true if tokens were transferred successfully, false otherwise
   */
  function transferFrom(address _from, address _to, uint256 _value)
    returns (bool success) {
	require(!frozenAccount[_from]);
    return TokenERC20.transferFrom(_from, _to, _value);
  }
  
  /**
   * Transfer given number of tokens from message sender to given recipient.
   * @param _to address to transfer tokens to the owner of
   * @param _value number of tokens to transfer to the owner of given address
   * @return true if tokens were transferred successfully, false otherwise
   */
  function transfer(address _to, uint256 _value) public {
    require(!frozenAccount[msg.sender]);
    return TokenERC20.transfer(_to, _value);
  }


    /// @notice `freeze? Prevent | Allow` `target` from sending & receiving tokens
    /// @param target Address to be frozen
    /// @param freeze either to freeze it or not
    
    function freezeAccount(address target, bool freeze) onlyOwner public {
        frozenAccount[target] = freeze;
        FrozenFunds(target, freeze);
    }

    /// @notice Allow users to buy tokens for `newBuyPrice` eth and sell tokens for `newSellPrice` eth
    /// @param newBuyPrice Price users can buy from the contract
    function setbuyPrice( uint256 newBuyPrice) onlyOwner public {
        require(newBuyPrice > 0);
        buyPrice = newBuyPrice;
    }
    
    function withdrawEther() onlyOwner {
       require(this.balance >= 100 ether);
       owner.transfer(this.balance);
    }
   
	
    /// @notice Buy tokens from contract by sending ether
    function buy() payable public {
        require(msg.value > 0);
        require(buyPrice > 0);
         uint amount = msg.value.mul(buyPrice); 
        _transfer(owner, msg.sender, amount);              // makes the transfers
    }


}
/******************************************/
function transferFrom(address _from, address _to, uint256 _value)
    returns (bool success) {
	require(!frozenAccount[_from]);
    return TokenERC20.transferFrom(_from, _to, _value);
  }
/**
 * Transfer given number of tokens from given owner to given recipient.
 *
 * @param _from address to transfer tokens from the owner of
 * @param _to address to transfer tokens to the owner of
 * @param _value number of tokens to transfer from given owner to given
 *        recipient
 * @return true if tokens were transferred successfully, false otherwise
 */