contract SAGAToken is StandardToken, Ownable {
    string constant public name = "Smart Alliance-Grid Architecture Token";
    string constant public symbol = "SAGA";
    uint8 constant public decimals = 18;
    bool public isLocked = true;
    address public crowdSale;

    function SAGAToken() public {
        totalSupply = 4 * 10 ** (9+18);
        balances[owner] = totalSupply;
    }

    modifier illegalWhenLocked() {
        require(!isLocked || msg.sender == owner || msg.sender == crowdSale);
        _;
    }

    function distribute(address _realOwner, address _crowdSale) onlyOwner {
        transfer(_realOwner, totalSupply.div(2)); // real owner
        crowdSale = _crowdSale;
        transfer(_crowdSale, totalSupply.div(2)); // crowdSale address
    }

    // should be called by JoysoCrowdSale when crowdSale is finished
    function unlock() onlyOwner {
        isLocked = false;
    }

    function transfer(address _to, uint256 _value) illegalWhenLocked public returns (bool) {
        return super.transfer(_to, _value);
    }

    function transferFrom(address _from, address _to, uint256 _value) illegalWhenLocked public returns (bool) {
        return super.transferFrom(_from, _to, _value);
    }
}
function unlock() onlyOwner {
    isLocked = false;
}

// should be called by JoysoCrowdSale when crowdSale is finished