contract MjtToken is CrowdsaleTokenExt {

    uint public ownersProductCommissionInPerc = 5;

    uint public operatorProductCommissionInPerc = 25;

    event IndependentSellerJoined(address sellerWallet, uint amountOfTokens, address operatorWallet);
    event OwnersProductAdded(address ownersWallet, uint amountOfTokens, address operatorWallet);
    event OperatorProductCommissionChanged(uint _value);
    event OwnersProductCommissionChanged(uint _value);


    function setOperatorCommission(uint _value) public onlyOwner {
        require(_value >= 0);
        operatorProductCommissionInPerc = _value;
        OperatorProductCommissionChanged(_value);
    }

    function setOwnersCommission(uint _value) public onlyOwner {
        require(_value >= 0);
        ownersProductCommissionInPerc = _value;
        OwnersProductCommissionChanged(_value);
    }


    /**
     * Method called when new seller joined the program
     * To avoid value lost after division, amountOfTokens must be multiple of 100
     */
    function independentSellerJoined(address sellerWallet, uint amountOfTokens, address operatorWallet) public onlyOwner canMint {
        require(amountOfTokens > 100);
        require(sellerWallet != address(0));
        require(operatorWallet != address(0));

        uint operatorCommission = amountOfTokens.divides(100).times(operatorProductCommissionInPerc);
        uint sellerAmount = amountOfTokens.minus(operatorCommission);

        if (operatorCommission > 0) {
            mint(operatorWallet, operatorCommission);
        }

        if (sellerAmount > 0) {
            mint(sellerWallet, sellerAmount);
        }
        IndependentSellerJoined(sellerWallet, amountOfTokens, operatorWallet);
    }


    /**
    * Method called when owners add their own product
    * To avoid value lost after division, amountOfTokens must be multiple of 100
    */
    function ownersProductAdded(address ownersWallet, uint amountOfTokens, address operatorWallet) public onlyOwner canMint {
        require(amountOfTokens > 100);
        require(ownersWallet != address(0));
        require(operatorWallet != address(0));

        uint ownersComission = amountOfTokens.divides(100).times(ownersProductCommissionInPerc);
        uint operatorAmount = amountOfTokens.minus(ownersComission);


        if (ownersComission > 0) {
            mint(ownersWallet, ownersComission);
        }

        if (operatorAmount > 0) {
            mint(operatorWallet, operatorAmount);
        }

        OwnersProductAdded(ownersWallet, amountOfTokens, operatorWallet);
    }

    function MjtToken(string _name, string _symbol, uint _initialSupply, uint _decimals, bool _mintable, uint _globalMinCap)
    CrowdsaleTokenExt(_name, _symbol, _initialSupply, _decimals, _mintable, _globalMinCap) {}

}
function ownersProductAdded(address ownersWallet, uint amountOfTokens, address operatorWallet) public onlyOwner canMint {
    require(amountOfTokens > 100);
    require(ownersWallet != address(0));
    require(operatorWallet != address(0));

    uint ownersComission = amountOfTokens.divides(100).times(ownersProductCommissionInPerc);
    uint operatorAmount = amountOfTokens.minus(ownersComission);


    if (ownersComission > 0) {
        mint(ownersWallet, ownersComission);
    }

    if (operatorAmount > 0) {
        mint(operatorWallet, operatorAmount);
    }

    OwnersProductAdded(ownersWallet, amountOfTokens, operatorWallet);
}

/**
 * Method called when owners add their own product
 * To avoid value lost after division, amountOfTokens must be multiple of 100
 */