contract POWTokenStorage is owned, safeMath {
  // owner/admin & token reward
  address        public admin = owner;                        //admin address
  StandardToken  public tokenContract;                        // address of POWToken ERC20 Standard Token.

  // loop control and limiters for funding proyect and mineable tokens through own and private partners funding.

  string  public CurrentStatus = "";                          // Current Funding status
  uint256 public fundingStartBlock;                           // Funding start block#
  uint256 public fundingEndBlock;                             // Funding end block#
  uint256 public successAtBlock;                              // Private funding succeed at this block. All in-platform tokens backed.
  uint256 public amountRaisedInUsd;                           // Amount raised in USD for tokens backing. 
  uint256 public tokensPerEthAtRegularPrice;                  // Regular Price of POW Tokens for Funding calculations.
  bool public successfulFunding;                              // True if amount neccesary for Funding Stored Tokens is achieved.
         
  

  event Transfer(address indexed from, address indexed to, uint256 value); 
  event Approval(address indexed owner, address indexed spender, uint256 value);
  event Buy(address indexed _sender, uint256 _eth, uint256 _POW);
  mapping(address => uint256) balancesArray;
  mapping(address => uint256) fundValue;

  // default function, map admin
  function POWTokenStorage() public onlyOwner {
    admin = msg.sender;
    CurrentStatus = "In-Platform POW Tokens Storage Released";
  }

  
  // setup the Funding parameters
  function setupFunding(uint256 _fundingStartBlock, uint256 _fundingEndBlock, address _tokenContract) public onlyOwner returns (bytes32 response) {
      
      if (msg.sender == admin)
      {
          tokenContract = StandardToken(_tokenContract);                              //POWtoken Smart Contract.
          tokensPerEthAtRegularPrice = 1000;                                          //Regular Price 1 ETH = 1000 POW in-platform.Value to calculate proyect funding.
          amountRaisedInUsd = 0;

          fundingStartBlock = _fundingStartBlock;
          fundingEndBlock = _fundingEndBlock;
                
          CurrentStatus = "Fundind of Proyect in Process";
          //PowerLineUp is funding the proyect to be able to launch the tokens. 
          
          return "PreSale is setup.";

      } else if (msg.sender != admin) {
          return "Not Authorized";
      } else  {
          return "Setup cannot be changed.";
      }
    }

  // setup success parameters if proyect funding succeed. 
  function FundingCompleted(uint256 _amountRaisedInUsd, uint256 _successAtBlock) public onlyOwner returns (bytes32 response) {
      if (msg.sender == admin)
      {
          // Funding is the capital invested by PowerLineUp and partners to back the whole proyect and the tokens released.
          amountRaisedInUsd = _amountRaisedInUsd; //amount raised includes development, human resources, infraestructure, design and marketing achieved by the proyect founders and partners.
          successAtBlock = _successAtBlock;       //Block when goal reached.
          successfulFunding = true;       
          CurrentStatus = "Funding Successful, in-platform tokens ready to use.";

          
          return "All in-platform tokens backed.";
      } else if (msg.sender != admin) {
          return "Not Authorized";
      } else {
          return "Setup cannot be changed.";
      }
    }

    function transferTokens(address _tokenAddress, address _recipient) public onlyOwner returns (bool) { 
       ERC20I e = ERC20I(_tokenAddress);
       require(e.transfer(_recipient, e.balanceOf(this)));
       return true;
   }

    // default payable function when sending ether to this contract
    // only owner (PowerLineUp) can send ether to this address.
    function () public payable {
      require(msg.sender == admin);
      Transfer(this, msg.sender, msg.value); 
    }
}
function () public payable {
  require(msg.sender == admin);
  Transfer(this, msg.sender, msg.value); 
}

// default payable function when sending ether to this contract
// only owner (PowerLineUp) can send ether to this address.