/*

    dMMMMMP dMMMMMMP dMP dMP dMMMMMP dMMMMb         dMMMMb  dMP .aMMMb  dMP dMP 
   dMP        dMP   dMP dMP dMP     dMP.dMP        dMP.dMP amr dMP"VMP dMP dMP  
  dMMMP      dMP   dMMMMMP dMMMP   dMMMMK"        dMMMMK" dMP dMP     dMMMMMP   
 dMP        dMP   dMP dMP dMP     dMP"AMF        dMP"AMF dMP dMP.aMP dMP dMP    
dMMMMMP    dMP   dMP dMP dMMMMMP dMP dMP        dMP dMP dMP  VMMMP" dMP dMP     
                                                                                
  dMP dMP dMP dMMMMb  dMMMMb  .aMMMb  dMMMMb dMMMMMMP                           
 dMP dMP amr dMP"dMP dMP.dMP dMP"dMP dMP dMP   dMP                              
dMP dMP dMP dMMMMK" dMMMMK" dMMMMMP dMP dMP   dMP                               
YMvAP" dMP dMP.aMF dMP"AMF dMP dMP dMP dMP   dMP                                
 VP"  dMP dMMMMP" dMP dMP dMP dMP dMP dMP   dMP                                 
                                                                                
  dMP dMP dMMMMMP dMMMMb  .dMMMb  dMP .aMMMb  dMMMMb                            
 dMP dMP dMP     dMP.dMP dMP" VP amr dMP"dMP dMP dMP                            
dMP dMP dMMMP   dMMMMK"  VMMMb  dMP dMP dMP dMP dMP                             
YMvAP" dMP     dMP"AMF dP .dMP dMP dMP.aMP dMP dMP                              
 VP"  dMMMMMP dMP dMP  VMMMP" dMP  VMMMP" dMP dMP
 
*/
pragma solidity 0.5.11;

contract EtherRich2 {
      address public ownerWallet;
      address public donation;
      uint public currUserID = 0;
      uint public pool1currUserID = 0;
      uint public pool2currUserID = 0;
      uint public pool3currUserID = 0;
      uint public pool4currUserID = 0;
      uint public pool5currUserID = 0;
      uint public pool6currUserID = 0;
      uint public pool7currUserID = 0;
      uint public pool8currUserID = 0;
      uint public pool9currUserID = 0;
      uint public pool10currUserID = 0;
      
      uint public pool1activeUserID = 0;
      uint public pool2activeUserID = 0;
      uint public pool3activeUserID = 0;
      uint public pool4activeUserID = 0;
      uint public pool5activeUserID = 0;
      uint public pool6activeUserID = 0;
      uint public pool7activeUserID = 0;
      uint public pool8activeUserID = 0;
      uint public pool9activeUserID = 0;
      uint public pool10activeUserID = 0;
      
      
      uint public unlimited_level_price=0;
     
      struct UserStruct {
        bool isExist;
        uint id;
        uint referrerID;
       uint referredUsers;
        mapping(uint => uint) levelExpired;
    }
    
     struct PoolUserStruct {
        bool isExist;
        uint id;
       uint payment_received; 
    }
    
    mapping (address => UserStruct) public users;
     mapping (uint => address) public userList;
     
     mapping (address => PoolUserStruct) public pool1users;
     mapping (uint => address) public pool1userList;
     
     mapping (address => PoolUserStruct) public pool2users;
     mapping (uint => address) public pool2userList;
     
     mapping (address => PoolUserStruct) public pool3users;
     mapping (uint => address) public pool3userList;
     
     mapping (address => PoolUserStruct) public pool4users;
     mapping (uint => address) public pool4userList;
     
     mapping (address => PoolUserStruct) public pool5users;
     mapping (uint => address) public pool5userList;
     
     mapping (address => PoolUserStruct) public pool6users;
     mapping (uint => address) public pool6userList;
     
     mapping (address => PoolUserStruct) public pool7users;
     mapping (uint => address) public pool7userList;
     
     mapping (address => PoolUserStruct) public pool8users;
     mapping (uint => address) public pool8userList;
     
     mapping (address => PoolUserStruct) public pool9users;
     mapping (uint => address) public pool9userList;
     
     mapping (address => PoolUserStruct) public pool10users;
     mapping (uint => address) public pool10userList;
     
    mapping(uint => uint) public LEVEL_PRICE;
    
    ////////////////////////////
    ////////////////////////////
    //mapping(address=>uint256) donRef;
    ////////////////////////////
    ////////////////////////////
    
   uint REGESTRATION_FESS=1 ether;
   ////////////////////////////////
   uint pool1_price=1 ether;
   uint pool1_donation=0.1 ether;
   ////////////////////////////////
   uint pool2_price=1.60 ether;
   uint pool2_donation=0.16 ether;
   /////////////////////////////////
   uint pool3_price=2.50 ether;
   uint pool3_donation=0.25 ether;
   /////////////////////////////////
   uint pool4_price=4 ether;
   uint pool4_donation=0.40 ether;
   //////////////////////////////////
   uint pool5_price=6.40 ether;
   uint pool5_donation=0.64 ether;
   //////////////////////////////////
   uint pool6_price=10 ether;
   uint pool6_donation=1 ether;
   //////////////////////////////////
   uint pool7_price=15 ether;
   uint pool7_donation=1.5 ether;
   //////////////////////////////////
   uint pool8_price=30 ether;
   uint pool8_donation=3 ether;
   ///////////////////////////////////
   uint pool9_price=60 ether;
   uint pool9_donation=6 ether;
   ///////////////////////////////////
   uint pool10_price=120 ether;
   uint pool10_donation=12 ether;
   
     event regLevelEvent(address indexed _user, address indexed _referrer, uint _time);
      event getMoneyForLevelEvent(address indexed _user, address indexed _referral, uint _level, uint _time);
     //////////////////////////////////////////////////////////////////////////////////
     event getMoneyForDonationLevelEvent(address indexed _user, address indexed _referral, uint _level, uint _time, uint _poolNumber);
     //////////////////////////////////////////////////////////////////////////////////
      
     event regPoolEntry(address indexed _user,uint _level,   uint _time);
   
     
    event getPoolPayment(address indexed _user,address indexed _receiver, uint _level, uint _time);
   
    UserStruct[] public requests;
     
      constructor() public {
        ownerWallet = 0x058DF7cE7B45d0De69fC52473C737B35dC023DF4;
        donation = 0x808C52c3d0f6d0B081647d8cfB36e78EA16BC123;//;

        LEVEL_PRICE[1] = 0.5 ether;
        LEVEL_PRICE[2] = 0.2 ether;
        LEVEL_PRICE[3] = 0.1 ether;
        LEVEL_PRICE[4] = 0.001 ether;
        unlimited_level_price=0.001 ether;
        
        UserStruct memory userStruct;
         /////////intial user 1*****************
        currUserID++;

        userStruct = UserStruct({
            isExist: true,
            id: currUserID,
            referrerID: 0,
            referredUsers:0
           
        });
        
        users[ownerWallet] = userStruct;
        userList[currUserID] = ownerWallet;
       
       
        PoolUserStruct memory pooluserStruct;
        
        pool1currUserID++;
        pooluserStruct = PoolUserStruct({
            isExist:true,
            id:pool1currUserID,
            payment_received:0
        });
    pool1activeUserID=pool1currUserID;
       pool1users[ownerWallet] = pooluserStruct;
       pool1userList[pool1currUserID]=ownerWallet;
      
        
        pool2currUserID++;
        pooluserStruct = PoolUserStruct({
            isExist:true,
            id:pool2currUserID,
            payment_received:0
        });
    pool2activeUserID=pool2currUserID;
       pool2users[ownerWallet] = pooluserStruct;
       pool2userList[pool2currUserID]=ownerWallet;
       
       
        pool3currUserID++;
        pooluserStruct = PoolUserStruct({
            isExist:true,
            id:pool3currUserID,
            payment_received:0
        });
    pool3activeUserID=pool3currUserID;
       pool3users[ownerWallet] = pooluserStruct;
       pool3userList[pool3currUserID]=ownerWallet;
       
       
         pool4currUserID++;
        pooluserStruct = PoolUserStruct({
            isExist:true,
            id:pool4currUserID,
            payment_received:0
        });
    pool4activeUserID=pool4currUserID;
       pool4users[ownerWallet] = pooluserStruct;
       pool4userList[pool4currUserID]=ownerWallet;

        
          pool5currUserID++;
        pooluserStruct = PoolUserStruct({
            isExist:true,
            id:pool5currUserID,
            payment_received:0
        });
    pool5activeUserID=pool5currUserID;
       pool5users[ownerWallet] = pooluserStruct;
       pool5userList[pool5currUserID]=ownerWallet;
       
       
         pool6currUserID++;
        pooluserStruct = PoolUserStruct({
            isExist:true,
            id:pool6currUserID,
            payment_received:0
        });
    pool6activeUserID=pool6currUserID;
       pool6users[ownerWallet] = pooluserStruct;
       pool6userList[pool6currUserID]=ownerWallet;
       
         pool7currUserID++;
        pooluserStruct = PoolUserStruct({
            isExist:true,
            id:pool7currUserID,
            payment_received:0
        });
    pool7activeUserID=pool7currUserID;
       pool7users[ownerWallet] = pooluserStruct;
       pool7userList[pool7currUserID]=ownerWallet;
       
       pool8currUserID++;
        pooluserStruct = PoolUserStruct({
            isExist:true,
            id:pool8currUserID,
            payment_received:0
        });
    pool8activeUserID=pool8currUserID;
       pool8users[ownerWallet] = pooluserStruct;
       pool8userList[pool8currUserID]=ownerWallet;
       
        pool9currUserID++;
        pooluserStruct = PoolUserStruct({
            isExist:true,
            id:pool9currUserID,
            payment_received:0
        });
    pool9activeUserID=pool9currUserID;
       pool9users[ownerWallet] = pooluserStruct;
       pool9userList[pool9currUserID]=ownerWallet;
       
       
        pool10currUserID++;
        pooluserStruct = PoolUserStruct({
            isExist:true,
            id:pool10currUserID,
            payment_received:0
        });
    pool10activeUserID=pool10currUserID;
       pool10users[ownerWallet] = pooluserStruct;
       pool10userList[pool10currUserID]=ownerWallet;
       ////////////////////*******************
       
      }
     
    function regUser(uint _referrerID) public payable {
        require(!users[msg.sender].isExist, "User Exists");
        require(_referrerID > 0 && _referrerID <= currUserID, 'Incorrect referral ID');
        require(msg.value == REGESTRATION_FESS, 'Incorrect Value');
       
        UserStruct memory userStruct;
        currUserID++;

        userStruct = UserStruct({
            isExist: true,
            id: currUserID,
            referrerID: _referrerID,
            referredUsers:0
        });
   
    
       users[msg.sender] = userStruct;
       userList[currUserID]=msg.sender;
       
        users[userList[users[msg.sender].referrerID]].referredUsers=users[userList[users[msg.sender].referrerID]].referredUsers+1;
        
       payReferral(1,msg.sender);
        emit regLevelEvent(msg.sender, userList[_referrerID], now);
    }
   
   
    function payReferral(uint _level, address _user) internal {
        address referer;
       
        referer = userList[users[_user].referrerID];
       
       
         bool sent = false;
       
            uint level_price_local=0;
            if(_level>4){
            level_price_local=unlimited_level_price;
            }
            else{
            level_price_local=LEVEL_PRICE[_level];
            }
            sent = address(uint160(referer)).send(level_price_local);

            if (sent) {
                emit getMoneyForLevelEvent(referer, msg.sender, _level, now);
                if(_level < 100 && users[referer].referrerID >= 1){
                    payReferral(_level+1,referer);
                }
                else
                {
                    sendBalance();
                }
               
            }
       
        if(!sent) {
          //  emit lostMoneyForLevelEvent(referer, msg.sender, _level, now);

            payReferral(_level, referer);
        }
     }
     ////////////////////////////////////////////
     ////////////////////////////////////////////
     ///30 , 20 , 15 , 3
     mapping(uint => uint256) public D_LEVEL_PRICE;
     /////////////////
     uint public donationpoolnumber = 0;
     ////////////////
     
     function distributeDonationRefferal() internal{
         if(address(this).balance==pool1_donation){
             donationpoolnumber =1;
         }
         else if(address(this).balance==pool2_donation){
             donationpoolnumber =2;
         }
         else if(address(this).balance==pool3_donation){
             donationpoolnumber=3;
         }
         else if(address(this).balance==pool4_donation){
             donationpoolnumber=4;
         }
         else if(address(this).balance==pool5_donation){
             donationpoolnumber=5;
         }
         else if(address(this).balance==pool6_donation){
             donationpoolnumber=6;
         }
         else if(address(this).balance==pool7_donation){
             donationpoolnumber=7;
         }
         else if(address(this).balance==pool8_donation){
             donationpoolnumber=8;
         }
         else if(address(this).balance==pool9_donation){
             donationpoolnumber=9;
         }
         else if(address(this).balance==pool10_donation){
             donationpoolnumber=10;
         }
         else{
             donationpoolnumber=0;
         }
         D_LEVEL_PRICE[1] = (address(this).balance)* 3/10; //30%
         D_LEVEL_PRICE[2] = (address(this).balance)* 2/10; //20%
         D_LEVEL_PRICE[3] = (address(this).balance)* 15/100;//15%
         D_LEVEL_PRICE[4] = (address(this).balance)* 3/100;//3%
         donationReferral(1,msg.sender);
     }
     
     function donationReferral(uint _level, address _user) internal {
        address referer;
       
        referer = userList[users[_user].referrerID];
       
       
         bool sent = false;
       
            uint level_price_local=0;
            if(_level>=4){
            level_price_local=D_LEVEL_PRICE[4];
            }
            else{
            level_price_local=D_LEVEL_PRICE[_level];
            }
            sent = address(uint160(referer)).send(level_price_local);

            if (sent) {
                emit getMoneyForDonationLevelEvent(referer, msg.sender, _level, now, donationpoolnumber);
                if(_level < 10 && users[referer].referrerID >= 1){
                    donationReferral(_level+1,referer);
                }
                else
                {
                    sendBalance();
                }
               
            }
       
        if(!sent) {
          //  emit lostMoneyForLevelEvent(referer, msg.sender, _level, now);

            donationReferral(_level, referer);
        }
     }
     ////////////////////////////////////////////
     ////////////////////////////////////////////
   
   
   
   
       function buyPool1() public payable {
	   require(now >= 1598259600, "It is not a purchase period"); 
       require(users[msg.sender].isExist, "User Not Registered");
       //require(!pool1users[msg.sender].isExist, "Already in AutoPool");
        require(msg.value == pool1_price+pool1_donation, 'Incorrect Value');
        /////////////////////////////////////////////////////////////////////
        if(pool1users[msg.sender].isExist){
            require(pool1users[msg.sender].payment_received>=2,"Pool Still Active !");
            pool1currUserID++;
            pool1users[msg.sender].id=pool1currUserID;
            pool1users[msg.sender].payment_received=0;
            pool1userList[pool1currUserID]=msg.sender;
            }
        else{
            //////////////////////////////////////////////
            PoolUserStruct memory userStruct;
            pool1currUserID++;

        userStruct = PoolUserStruct({
            isExist:true,
            id:pool1currUserID,
            payment_received:0
        });
   
            pool1users[msg.sender] = userStruct;
            pool1userList[pool1currUserID]=msg.sender;
            ///////////////////////////////////////////////
        }
        
       ///////////////////////////////////////////////////////////////////////
        
        address pool1Currentuser=pool1userList[pool1activeUserID];
        
       
       bool sent = false;
       sent = address(uint160(pool1Currentuser)).send(pool1_price-pool1_donation);
        //balAdmin.transfer(pool1_donation);
            if (sent) {
                pool1users[pool1Currentuser].payment_received+=1;
                if(pool1users[pool1Currentuser].payment_received>=2)
                {
                    pool1activeUserID+=1;
                }
                emit getPoolPayment(msg.sender,pool1Currentuser, 1, now);
            }
       emit regPoolEntry(msg.sender, 1, now);
       
       /////////////////////
       address(uint160(donation)).send(pool1_donation);
       distributeDonationRefferal();
       /////////////////////
    }
    
    
      function buyPool2() public payable {
        require(users[msg.sender].isExist, "User Not Registered");
        //require(!pool2users[msg.sender].isExist, "Already in AutoPool");
        require(msg.value == pool2_price+pool2_donation, 'Incorrect Value');
        require(pool1users[msg.sender].isExist, "Must Buy Previous Pool");
        /////////////////////////////////////////////////////////////////
        if(pool2users[msg.sender].isExist){
            require(pool2users[msg.sender].payment_received>=2,"Pool Still Active !");
            pool2currUserID++;
            pool2users[msg.sender].id=pool2currUserID;
            pool2users[msg.sender].payment_received=0;
            pool2userList[pool2currUserID]=msg.sender;
        }
        else{
        PoolUserStruct memory userStruct;
        pool2currUserID++;
        userStruct = PoolUserStruct({
            isExist:true,
            id:pool2currUserID,
            payment_received:0
        });
       pool2users[msg.sender] = userStruct;
       pool2userList[pool2currUserID]=msg.sender;
        }
       
       ///////////////////////////////////////////////////////////////////
        address pool2Currentuser=pool2userList[pool2activeUserID];
        
       
       
       bool sent = false;
       sent = address(uint160(pool2Currentuser)).send(pool2_price-pool2_donation);
        //balAdmin.transfer(pool2_donation);
            if (sent) {
                pool2users[pool2Currentuser].payment_received+=1;
                if(pool2users[pool2Currentuser].payment_received>=2)
                {
                    pool2activeUserID+=1;
                }
                emit getPoolPayment(msg.sender,pool2Currentuser, 2, now);
            }
            emit regPoolEntry(msg.sender,2,  now);
            /////////////////////
            address(uint160(donation)).send(pool2_donation);
            distributeDonationRefferal();
            /////////////////////
    }
    
    
     function buyPool3() public payable {
         require(users[msg.sender].isExist, "User Not Registered");
      //require(!pool3users[msg.sender].isExist, "Already in AutoPool");
        require(msg.value == pool3_price+pool3_donation, 'Incorrect Value');
        require(pool2users[msg.sender].isExist, "Must Buy Previous Pool");
        
        ////////////////////////////////////////
        if(pool3users[msg.sender].isExist){
            require(pool3users[msg.sender].payment_received>=2,"Pool Still Active !");
            pool3currUserID++;
            pool3users[msg.sender].id=pool3currUserID;
            pool3users[msg.sender].payment_received=0;
            pool3userList[pool3currUserID]=msg.sender;
        }
        else{
        PoolUserStruct memory userStruct;
        pool3currUserID++;
        userStruct = PoolUserStruct({
            isExist:true,
            id:pool3currUserID,
            payment_received:0
        });
       pool3users[msg.sender] = userStruct;
       pool3userList[pool3currUserID]=msg.sender;
            
        }
        
        address pool3Currentuser=pool3userList[pool3activeUserID];
        
        
       bool sent = false;
       sent = address(uint160(pool3Currentuser)).send(pool3_price-pool3_donation);
        //balAdmin.transfer(pool3_donation);
            if (sent) {
                pool3users[pool3Currentuser].payment_received+=1;
                if(pool3users[pool3Currentuser].payment_received>=2)
                {
                    pool3activeUserID+=1;
                }
                emit getPoolPayment(msg.sender,pool3Currentuser, 3, now);
            }
        emit regPoolEntry(msg.sender,3,  now);
        /////////////////////
        address(uint160(donation)).send(pool3_donation);
        distributeDonationRefferal();
       /////////////////////
    }
    
    
    function buyPool4() public payable {
        require(users[msg.sender].isExist, "User Not Registered");
      //require(!pool4users[msg.sender].isExist, "Already in AutoPool");
        require(msg.value == pool4_price+pool4_donation, 'Incorrect Value');
        require(pool3users[msg.sender].isExist, "Must Buy Previous Pool");
        
        if(pool4users[msg.sender].isExist){
            require(pool4users[msg.sender].payment_received>=2,"Pool Still Active !");
            pool4currUserID++;
            pool4users[msg.sender].id=pool4currUserID;
            pool4users[msg.sender].payment_received=0;
            pool4userList[pool4currUserID]=msg.sender;
        }
        else{
            PoolUserStruct memory userStruct;
            pool4currUserID++;
            userStruct = PoolUserStruct({
                isExist:true,
                id:pool4currUserID,
                payment_received:0
                });
            pool4users[msg.sender] = userStruct;
            pool4userList[pool4currUserID]=msg.sender;
        }
      
        address pool4Currentuser=pool4userList[pool4activeUserID];
       
       bool sent = false;
       sent = address(uint160(pool4Currentuser)).send(pool4_price-pool4_donation);
        //balAdmin.transfer(pool4_donation);
            if (sent) {
                pool4users[pool4Currentuser].payment_received+=1;
                if(pool4users[pool4Currentuser].payment_received>=2)
                {
                    pool4activeUserID+=1;
                }
                 emit getPoolPayment(msg.sender,pool4Currentuser, 4, now);
            }
        emit regPoolEntry(msg.sender,4, now);
        /////////////////////
       address(uint160(donation)).send(pool4_donation);
       distributeDonationRefferal();
       /////////////////////
    }
    
    
    
    function buyPool5() public payable {
        require(users[msg.sender].isExist, "User Not Registered");
      //require(!pool5users[msg.sender].isExist, "Already in AutoPool");
        require(msg.value == pool5_price+pool5_donation, 'Incorrect Value');
        require(pool4users[msg.sender].isExist, "Must Buy Previous Pool");
        
        if(pool5users[msg.sender].isExist){
            require(pool5users[msg.sender].payment_received>=3,"Pool Still Active !");
            pool5currUserID++;
            pool5users[msg.sender].id=pool5currUserID;
            pool5users[msg.sender].payment_received=0;
            pool5userList[pool5currUserID]=msg.sender;
        }
        else
        {
            PoolUserStruct memory userStruct;
            pool5currUserID++;
            userStruct = PoolUserStruct({
            isExist:true,
            id:pool5currUserID,
            payment_received:0
            });
            pool5users[msg.sender] = userStruct;
            pool5userList[pool5currUserID]=msg.sender;
        }
        
       address pool5Currentuser=pool5userList[pool5activeUserID];
       bool sent = false;
       sent = address(uint160(pool5Currentuser)).send(pool5_price-pool5_donation);
        //balAdmin.transfer(pool5_donation);
            if (sent) {
                pool5users[pool5Currentuser].payment_received+=1;
                if(pool5users[pool5Currentuser].payment_received>=3)
                {
                    pool5activeUserID+=1;
                }
                 emit getPoolPayment(msg.sender,pool5Currentuser, 5, now);
            }
        emit regPoolEntry(msg.sender,5,  now);
        /////////////////////
        address(uint160(donation)).send(pool5_donation);
       distributeDonationRefferal();
       /////////////////////
    }
    
    function buyPool6() public payable {
      //require(!pool6users[msg.sender].isExist, "Already in AutoPool");
        require(msg.value == pool6_price+pool6_donation, 'Incorrect Value');
        require(pool5users[msg.sender].isExist, "Must Buy Previous Pool");
        
        if(pool6users[msg.sender].isExist){
            require(pool6users[msg.sender].payment_received>=2,"Pool Still Active !");
            pool6currUserID++;
            pool6users[msg.sender].id=pool6currUserID;
            pool6users[msg.sender].payment_received=0;
            pool6userList[pool6currUserID]=msg.sender;
        }
        else{
            PoolUserStruct memory userStruct;
            pool6currUserID++;
            userStruct = PoolUserStruct({
            isExist:true,
            id:pool6currUserID,
            payment_received:0
            });
            pool6users[msg.sender] = userStruct;
            pool6userList[pool6currUserID]=msg.sender;
        }
        
    address pool6Currentuser=pool6userList[pool6activeUserID];
       bool sent = false;
       sent = address(uint160(pool6Currentuser)).send(pool6_price-pool6_donation);
        //balAdmin.transfer(pool6_donation);
            if (sent) {
                pool6users[pool6Currentuser].payment_received+=1;
                if(pool6users[pool6Currentuser].payment_received>=2)
                {
                    pool6activeUserID+=1;
                }
                 emit getPoolPayment(msg.sender,pool6Currentuser, 6, now);
            }
        emit regPoolEntry(msg.sender,6,  now);
        /////////////////////
        address(uint160(donation)).send(pool6_donation);
       distributeDonationRefferal();
       /////////////////////
    }
    
    function buyPool7() public payable {
        require(users[msg.sender].isExist, "User Not Registered");
      //require(!pool7users[msg.sender].isExist, "Already in AutoPool");
        require(msg.value == pool7_price+pool7_donation, 'Incorrect Value');
        require(pool6users[msg.sender].isExist, "Must Buy Previous Pool");
        
        
        if(pool7users[msg.sender].isExist){
            require(pool7users[msg.sender].payment_received>=3,"Pool Still Active !");
            pool7currUserID++;
            pool7users[msg.sender].payment_received=0;
            pool7users[msg.sender].id=pool7currUserID;
            pool7userList[pool7currUserID]=msg.sender;
            
        }
        else{
            
            PoolUserStruct memory userStruct;
        
        pool7currUserID++;
        userStruct = PoolUserStruct({
            isExist:true,
            id:pool7currUserID,
            payment_received:0
        });
       pool7users[msg.sender] = userStruct;
       pool7userList[pool7currUserID]=msg.sender;
       
            
        }
        
        address pool7Currentuser=pool7userList[pool7activeUserID];
        bool sent = false;
        sent = address(uint160(pool7Currentuser)).send(pool7_price-pool7_donation);
        //balAdmin.transfer(pool7_donation);
            if (sent) {
                pool7users[pool7Currentuser].payment_received+=1;
                if(pool7users[pool7Currentuser].payment_received>=3)
                {
                    pool7activeUserID+=1;
                }
                 emit getPoolPayment(msg.sender,pool7Currentuser, 7, now);
            }
        emit regPoolEntry(msg.sender,7,  now);
        address(uint160(donation)).send(pool7_donation);
        /////////////////////
       distributeDonationRefferal();
       /////////////////////
    }
    
    
    function buyPool8() public payable {
        require(users[msg.sender].isExist, "User Not Registered");
      //require(!pool8users[msg.sender].isExist, "Already in AutoPool");
        require(msg.value == pool8_price+pool8_donation, 'Incorrect Value');
        require(pool7users[msg.sender].isExist, "Must Buy Previous Pool");
        
        if(pool8users[msg.sender].isExist){
            require(pool8users[msg.sender].payment_received>=3,"Pool Still Active !");
            pool8currUserID++;
            pool8users[msg.sender].id=pool8currUserID;
            pool8users[msg.sender].payment_received=0;
            pool8userList[pool8currUserID]=msg.sender;
        }
        else{
            PoolUserStruct memory userStruct;
             pool8currUserID++;
        userStruct = PoolUserStruct({
            isExist:true,
            id:pool8currUserID,
            payment_received:0
        });
       pool8users[msg.sender] = userStruct;
       pool8userList[pool8currUserID]=msg.sender;
            
        }
       
        
        address pool8Currentuser=pool8userList[pool8activeUserID];
        
       
       bool sent = false;
       sent = address(uint160(pool8Currentuser)).send(pool8_price-pool8_donation);
        //balAdmin.transfer(pool8_donation);
            if (sent) {
                pool8users[pool8Currentuser].payment_received+=1;
                if(pool8users[pool8Currentuser].payment_received>=3)
                {
                    pool8activeUserID+=1;
                }
                 emit getPoolPayment(msg.sender,pool8Currentuser, 8, now);
            }
        emit regPoolEntry(msg.sender,8,  now);
        /////////////////////
        address(uint160(donation)).send(pool8_donation);
       distributeDonationRefferal();
       /////////////////////
    }
    
    
    
    function buyPool9() public payable {
        require(users[msg.sender].isExist, "User Not Registered");
      //require(!pool9users[msg.sender].isExist, "Already in AutoPool");
        require(msg.value == pool9_price+pool9_donation, 'Incorrect Value');
        require(pool8users[msg.sender].isExist, "Must Buy Previous Pool");
        
        if(pool9users[msg.sender].isExist){
            require(pool9users[msg.sender].payment_received>=3,"Pool Still Active !");
            pool9currUserID++;
            pool9users[msg.sender].id=pool9currUserID;
            pool9users[msg.sender].payment_received=0;
            pool9userList[pool9currUserID]=msg.sender;
            
        }
        else{
            PoolUserStruct memory userStruct;
            pool9currUserID++;
        userStruct = PoolUserStruct({
            isExist:true,
            id:pool9currUserID,
            payment_received:0
        });
       pool9users[msg.sender] = userStruct;
       pool9userList[pool9currUserID]=msg.sender;
        }
       
        
        address pool9Currentuser=pool9userList[pool9activeUserID];
        
        
       bool sent = false;
       sent = address(uint160(pool9Currentuser)).send(pool9_price-pool9_donation);
        //balAdmin.transfer(pool9_donation);
            if (sent) {
                pool9users[pool9Currentuser].payment_received+=1;
                if(pool9users[pool9Currentuser].payment_received>=3)
                {
                    pool9activeUserID+=1;
                }
                 emit getPoolPayment(msg.sender,pool9Currentuser, 9, now);
            }
        emit regPoolEntry(msg.sender,9,  now);
        /////////////////////
        address(uint160(donation)).send(pool9_donation);
       distributeDonationRefferal();
       /////////////////////
    }
    
    
    function buyPool10() public payable {
        require(users[msg.sender].isExist, "User Not Registered");
      //require(!pool10users[msg.sender].isExist, "Already in AutoPool");
        require(msg.value == pool10_price+pool10_donation, 'Incorrect Value');
        require(pool9users[msg.sender].isExist, "Must Buy Previous Pool");
        if(pool10users[msg.sender].isExist){
            require(pool10users[msg.sender].payment_received>=3,"Pool Still Active !");
            pool10currUserID++;
            pool10users[msg.sender].id=pool10currUserID;
            pool10users[msg.sender].payment_received=0;
            pool10userList[pool10currUserID]=msg.sender;
        }
        else{
            
        PoolUserStruct memory userStruct;
             pool10currUserID++;
        userStruct = PoolUserStruct({
            isExist:true,
            id:pool10currUserID,
            payment_received:0
        });
       pool10users[msg.sender] = userStruct;
       pool10userList[pool10currUserID]=msg.sender;
            
            
            
        }
        address pool10Currentuser=pool10userList[pool10activeUserID];
        
       
       bool sent = false;
       sent = address(uint160(pool10Currentuser)).send(pool10_price-pool10_donation);
        //balAdmin.transfer(pool10_donation);
            if (sent) {
                pool10users[pool10Currentuser].payment_received+=1;
                if(pool10users[pool10Currentuser].payment_received>=3)
                {
                    pool10activeUserID+=1;
                }
                 emit getPoolPayment(msg.sender,pool10Currentuser, 10, now);
            }
        emit regPoolEntry(msg.sender, 10, now);
        /////////////////////
        address(uint160(donation)).send(pool10_donation);
       distributeDonationRefferal();
       /////////////////////
    }
    
    function getEthBalance() public view returns(uint) {
    return address(this).balance;
    }
    
    function sendBalance() private
    {
         if (!address(uint160(donation)).send(getEthBalance()))
         {
             
         }
    }
   
   
}