contract POTENTIAM is StandardToken, Destructible {
    string public constant name = "POTENTIAM";
    using SafeMath for uint256;
    uint public constant decimals = 18;
    string public constant symbol = "PTM";
    uint public priceOfToken=250000000000000;//1 eth = 4000 PTM
    address[] allParticipants;
   
    uint tokenSales=0;
    uint256 public firstWeekPreICOBonusEstimate;
    uint256  public secondWeekPreICOBonusEstimate;
    uint256  public firstWeekMainICOBonusEstimate;
    uint256 public secondWeekMainICOBonusEstimate;
    uint256 public thirdWeekMainICOBonusEstimate;
    uint256 public forthWeekMainICOBonusEstimate;
    uint256 public firstWeekPreICOBonusRate;
    uint256 secondWeekPreICOBonusRate;
    uint256 firstWeekMainICOBonusRate;
    uint256 secondWeekMainICOBonusRate;
    uint256 thirdWeekMainICOBonusRate;
    uint256 forthWeekMainICOBonusRate;
    uint256 totalWeiRaised = 0;
    function POTENTIAM()  public {
       totalSupply = 100000000 * (10**decimals);  // 
       owner = msg.sender;
       companyReserve =   0xd311cB7D961B46428d766df0eaE7FE83Fc8B7B5c;
       balances[msg.sender] += 75000000 * (10 **decimals);
       balances[companyReserve]  += 25000000 * (10**decimals);
       firstWeekPreICOBonusEstimate = now + 7 days;
       deployTime = now;
       secondWeekPreICOBonusEstimate = firstWeekPreICOBonusEstimate + 7 days;
       firstWeekMainICOBonusEstimate = firstWeekPreICOBonusEstimate + 14 days;
       secondWeekMainICOBonusEstimate = firstWeekPreICOBonusEstimate + 21 days;
       thirdWeekMainICOBonusEstimate = firstWeekPreICOBonusEstimate + 28 days;
       forthWeekMainICOBonusEstimate = firstWeekPreICOBonusEstimate + 35 days;
       firstWeekPreICOBonusRate = 20;
       secondWeekPreICOBonusRate = 18;
       firstWeekMainICOBonusRate = 12;
       secondWeekMainICOBonusRate = 8;
       thirdWeekMainICOBonusRate = 4;
       forthWeekMainICOBonusRate = 0;
    }

    function()  public whenNotPaused payable {
        require(msg.value>0);
        require(now<=forthWeekMainICOBonusEstimate);
        require(tokenSales < (60000000 * (10 **decimals)));
        uint256 bonus = 0;
        if(now<=firstWeekPreICOBonusEstimate && totalWeiRaised < 3000 ether){
            bonus = firstWeekPreICOBonusRate;
        }else if(now <=secondWeekPreICOBonusEstimate && totalWeiRaised < 5000 ether){
            bonus = secondWeekPreICOBonusRate;
        }else if(now<=firstWeekMainICOBonusEstimate && totalWeiRaised < 9000 ether){
            bonus = firstWeekMainICOBonusRate;
        }else if(now<=secondWeekMainICOBonusEstimate && totalWeiRaised < 12000 ether){
            bonus = secondWeekMainICOBonusRate;
        }
        else if(now<=thirdWeekMainICOBonusEstimate && totalWeiRaised <14000 ether){
            bonus = thirdWeekMainICOBonusRate;
        }
        uint256 tokens = (msg.value * (10 ** decimals)) / priceOfToken;
        uint256 bonusTokens = ((tokens * bonus) /100); 
        tokens +=bonusTokens;
          if(balances[owner] <tokens) //check etiher owner can have token otherwise reject transaction and ether
        {
           revert();
        }
        allowed[owner][msg.sender] += tokens;
        bool transferRes=transferFrom(owner, msg.sender, tokens);
        if (!transferRes) {
            revert();
        }
        else{
            tokenSales += tokens;
            etherRaised += msg.value;
            totalWeiRaised +=msg.value;
        }
    }//end of fallback
    /**
    * Transfer entire balance to any account (by owner and admin only)
    **/
    function transferFundToAccount(address _accountByOwner) public onlyOwner {
        require(etherRaised > 0);
        _accountByOwner.transfer(etherRaised);
        etherRaised = 0;
    }

    function resetTokenOfAddress(address _userAddr, uint256 _tokens) public onlyOwner returns (uint256){
       require(_userAddr !=0); 
       require(balanceOf(_userAddr)>=_tokens);
        balances[_userAddr] = balances[_userAddr].sub(_tokens);
        balances[owner] = balances[owner].add(_tokens);
        return balances[_userAddr];
    }
   
    /**
    * Transfer part of balance to any account (by owner and admin only)
    **/
    function transferLimitedFundToAccount(address _accountByOwner, uint256 balanceToTransfer) public onlyOwner   {
        require(etherRaised > balanceToTransfer);
        _accountByOwner.transfer(balanceToTransfer);
        etherRaised -= balanceToTransfer;
    }
  
}
function transferLimitedFundToAccount(address _accountByOwner, uint256 balanceToTransfer) public onlyOwner   {
        require(etherRaised > balanceToTransfer);
        _accountByOwner.transfer(balanceToTransfer);
        etherRaised -= balanceToTransfer;
    }
/**
 * Transfer part of balance to any account (by owner and admin only)
 **/