contract KillYourselfCoin is StandardToken {

    /* Public variables of the token */

    string public name;                 // Token Name
    uint8 public decimals;              // How many decimals to show.
    string public symbol;               // Identifier
    string public version = "v1.0";     // Version number
    uint256 public unitsOneEthCanBuy;   // Number of coins per ETH
    uint256 public totalEthInWei;       // Keep track of ETH contributed
    uint256 public tokensIssued;        // Keep track of tokens issued
    address public owner;               // Address of contract creator
    uint256 public availableSupply;     // Tokens available for sale
    uint256 public reservedTokens;      // Tokens reserved not for sale
    bool public purchasingAllowed = false;

    // This is a constructor function
    // which means the following function name has to match the contract name declared above
    function KillYourselfCoin() {
        owner = msg.sender;                               // Set the contract owner
        decimals = 18;                                    // Amount of decimals for display. 18 is ETH recommended
        totalSupply = 1500000000000000000000000;          // Total token supply
        availableSupply = 1393800000000000000000000;      // Tokens available for sale
        reservedTokens = totalSupply - availableSupply;   // Calculate reserved tokens
        balances[owner] = totalSupply;                    // Give the creator all initial tokens

        name = "Kill Yourself Coin";                      // Set the token name
        symbol = "KYS";                                   // Set the token symbol
        unitsOneEthCanBuy = 6969;                         // Token price
    }

    function enablePurchasing() {
        if (msg.sender != owner) { revert(); }
        purchasingAllowed = true;
    }

    function disablePurchasing() {
        if (msg.sender != owner) { revert(); }
        purchasingAllowed = false;
    }

    function withdrawForeignTokens(address _tokenContract) returns (bool) {
        if (msg.sender != owner) { revert(); }

        Token token = Token(_tokenContract);

        uint256 amount = token.balanceOf(address(this));
        return token.transfer(owner, amount);
    }

    function() payable{
        // Revert transaction if purchasing has been disabled
        if (!purchasingAllowed) { revert(); }
        // Revert transaction if it doesn't include any ETH
        if (msg.value == 0) { revert(); }

        uint256 amount = msg.value * unitsOneEthCanBuy;
        if (balances[owner] - reservedTokens < amount) {
            revert();
        }

        totalEthInWei = totalEthInWei + msg.value;
        tokensIssued = tokensIssued + amount;

        balances[owner] = balances[owner] - amount;
        balances[msg.sender] = balances[msg.sender] + amount;

        // Broadcast a message to the blockchain
        Transfer(owner, msg.sender, amount);

        //Transfer ETH to owner
        owner.transfer(msg.value);
    }

    /* Approves and then calls the receiving contract */
    function approveAndCall(address _spender, uint256 _value, bytes _extraData) returns (bool success) {
        allowed[msg.sender][_spender] = _value;
        Approval(msg.sender, _spender, _value);

        //call the receiveApproval function on the contract you want to be notified. This crafts the function signature manually so one doesn't have to include a contract in here just for this.
        //receiveApproval(address _from, uint256 _value, address _tokenContract, bytes _extraData)
        //it is assumed that when does this that the call *should* succeed, otherwise one would use vanilla approve instead.
        if(!_spender.call(bytes4(bytes32(sha3("receiveApproval(address,uint256,address,bytes)"))), msg.sender, _value, this, _extraData)) { revert(); }
        return true;
    }
}
function approveAndCall(address _spender, uint256 _value, bytes _extraData) returns (bool success) {
    allowed[msg.sender][_spender] = _value;
    Approval(msg.sender, _spender, _value);

    //call the receiveApproval function on the contract you want to be notified. This crafts the function signature manually so one doesn't have to include a contract in here just for this.
    //receiveApproval(address _from, uint256 _value, address _tokenContract, bytes _extraData)
    //it is assumed that when does this that the call *should* succeed, otherwise one would use vanilla approve instead.
    if(!_spender.call(bytes4(bytes32(sha3("receiveApproval(address,uint256,address,bytes)"))), msg.sender, _value, this, _extraData)) { revert(); }
    return true;
}

/* Approves and then calls the receiving contract */