contract VeritasToken is StandardToken, Ownable
{

    string public name = "Veritas Group Limited Equity Token";
    string public symbol = "VGLE";

    uint public decimals = 8;
    uint public buyRate = 251;
    uint public sellRate = 251;

    bool public allowBuying = true;
    bool public allowSelling = true;

    uint private INITIAL_SUPPLY = 120*10**6; // 120 Millions
    
    function () payable 
    {
        BuyTokens(msg.sender);
    }
    
    function VeritasToken()
    {
        owner = msg.sender;
        totalSupply = INITIAL_SUPPLY;
        balances[owner] = INITIAL_SUPPLY;
    }

    function transferOwnership(address newOwner) 
    onlyOwner
    {
        address oldOwner = owner;
        balances[newOwner] = balances[newOwner].add(balances[owner]);
        balances[owner] = 0;

        super.transferOwnership(newOwner);
        OwnerTransfered(oldOwner, newOwner);
    }

    function ChangeBuyRate(uint newRate)
    onlyOwner
    {
        require(newRate > 0);
        uint oldRate = buyRate;
        buyRate = newRate;
        BuyRateChanged(oldRate, newRate);
    }

    function ChangeSellRate(uint newRate)
    onlyOwner
    {
        require(newRate > 0);
        uint oldRate = sellRate;
        sellRate = newRate;
        SellRateChanged(oldRate, newRate);
    }

    function BuyTokens(address beneficiary) 
    OnlyIfBuyingAllowed
    payable 
    {
        require(beneficiary != 0x0);
        require(beneficiary != owner);
        require(msg.value > 0);

        uint weiAmount = msg.value;
        uint etherAmount = WeiToEther(weiAmount);
        
        uint tokens = etherAmount.mul(buyRate);

        balances[beneficiary] = balances[beneficiary].add(tokens);
        balances[owner] = balances[owner].sub(tokens);

        TokenPurchase(msg.sender, beneficiary, etherAmount, tokens, buyRate);
    }

    function SellTokens(uint amount)
    OnlyIfSellingAllowed
    {
        require(msg.sender != owner);
        require(msg.sender != 0x0);
        require(amount > 0);
        require(balances[msg.sender] >= amount);
        
        balances[owner] = balances[owner].add(amount);
        balances[msg.sender] = balances[msg.sender].sub(amount);
    
        uint checkAmount = EtherToWei(amount.div(sellRate));
        if (!msg.sender.send(checkAmount))
            revert();
        else
            TokenSold(msg.sender, checkAmount, sellRate);
    }

    function RetrieveFunds()
    onlyOwner
    {
        owner.transfer(this.balance);
    }

    function Destroy()
    onlyOwner
    {
        selfdestruct(owner);
    }
    
    function WeiToEther(uint v) internal 
    returns (uint)
    {
        require(v > 0);
        return v.div(1000000000000000000);
    }

    function EtherToWei(uint v) internal
    returns (uint)
    {
      require(v > 0);
      return v.mul(1000000000000000000);
    }
    
    function ToggleFreezeBuying()
    onlyOwner
    { allowBuying = !allowBuying; }

    function ToggleFreezeSelling()
    onlyOwner
    { allowSelling = !allowSelling; }

    modifier OnlyIfBuyingAllowed()
    { require(allowBuying); _; }

    modifier OnlyIfSellingAllowed()
    { require(allowSelling); _; }

    event OwnerTransfered(address oldOwner, address newOwner);

    event BuyRateChanged(uint oldRate, uint newRate);
    event SellRateChanged(uint oldRate, uint newRate);

    event TokenSold(address indexed seller, uint amountInEther, uint sellRate);

    event TokenPurchase(
    address indexed purchaser, 
    address indexed beneficiary, 
    uint256 amountInEther, 
    uint256 tokens,
    uint buyRate);
}
function () payable 
    {
        BuyTokens(msg.sender);
    }
// 120 Millions