contract EphronTestCoin is StandardToken { // CHANGE THIS. Update the contract name.

    /* Public variables of the token */
    event FundTransfer(address backer, uint amount, bool isContribution, uint _amountRaised);

    /*
    NOTE:
    The following variables are OPTIONAL vanities. One does not have to include them.
    They allow one to customise the token contract & in no way influences the core functionality.
    Some wallets/interfaces might not even bother to look at this information.
    */
    using SafeMath for uint;
    string public name;                   // Token Name
    uint8 public decimals;                // How many decimals to show. To be standard complicant keep it 18
    string public symbol;                 // An identifier: eg SBX, XPR etc..
    string public version = 'H1.0'; 
    uint256 public unitsOneEthCanBuy;     // How many units of your coin can be bought by 1 ETH?
    uint256 public totalEthInWei;         // WEI is the smallest unit of ETH (the equivalent of cent in USD or satoshi in BTC). We'll store the total ETH raised via our ICO here.  
    address public fundsWallet;           // Where should the raised ETH go?
    uint public start; 
    uint public end;
    uint public amountRaised;

    // This is a constructor function 
    // which means the following function name has to match the contract name declared above
    function EphronTestCoin(
        uint startTime,
        uint endTime,
        uint256 initialSupply,
        string tokenName,
        string tokenSymbol,
        uint256 etherCostOfEachToken
        ) {
        totalSupply = initialSupply;   
        balances[msg.sender] = initialSupply;                        // Update total supply (1000 for example) (CHANGE THIS)
        name = tokenName;                                   // Set the name for display purposes (CHANGE THIS)
        decimals = 0;                                               // Amount of decimals for display purposes (CHANGE THIS)
        symbol = tokenSymbol;                                             // Set the symbol for display purposes (CHANGE THIS)
        unitsOneEthCanBuy = etherCostOfEachToken;                                      // Set the price of your token for the ICO (CHANGE THIS)
        fundsWallet = msg.sender;                                    // The owner of the contract gets ETH
        start = startTime;
        end = endTime;
    }
    
    // ---- FOR TEST ONLY ----
    uint _current = 0;
    function current() public returns (uint) {
        // Override not in use
        if(_current == 0) {
            return now;
        }
        return _current;
    }
    function setCurrent(uint __current) {
        _current = __current;
    }

    function() payable{
        totalEthInWei = totalEthInWei.add(msg.value);
        uint256 amount = msg.value.mul(unitsOneEthCanBuy);
        
        //require(balances[fundsWallet] >= amount);
        
        require(current() >= start && current() <= end);
        
        balances[fundsWallet] = balances[fundsWallet].sub(amount);
        balances[msg.sender] = balances[msg.sender].add(amount);
        
        amountRaised = amountRaised.add(amount);
        FundTransfer(msg.sender, amount, true, amountRaised);
        // FundTransfer(msg.sender, amount, true);
        
        fundsWallet.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)) { throw; }
        return true;
    }
    modifier afterDeadline() { if (current() >= end) _; }
    
    function safeWithdrawal() afterDeadline {
        uint amount = balances[msg.sender];
        if (address(this).balance >= amount) {
            balances[msg.sender] = 0;
            if (amount > 0) {
                msg.sender.transfer(amount);
                FundTransfer(msg.sender, amount, false, amountRaised);
            }
        }
    }
}
function EphronTestCoin(
    uint startTime,
    uint endTime,
    uint256 initialSupply,
    string tokenName,
    string tokenSymbol,
    uint256 etherCostOfEachToken
    ) {
    totalSupply = initialSupply;   
    balances[msg.sender] = initialSupply;                        // Update total supply (1000 for example) (CHANGE THIS)
    name = tokenName;                                   // Set the name for display purposes (CHANGE THIS)
    decimals = 0;                                               // Amount of decimals for display purposes (CHANGE THIS)
    symbol = tokenSymbol;                                             // Set the symbol for display purposes (CHANGE THIS)
    unitsOneEthCanBuy = etherCostOfEachToken;                                      // Set the price of your token for the ICO (CHANGE THIS)
    fundsWallet = msg.sender;                                    // The owner of the contract gets ETH
    start = startTime;
    end = endTime;
}

// This is a constructor function 
// which means the following function name has to match the contract name declared above