contract O9CoinCrowdsale is  TimedCrowdsale, MintedCrowdsale,Ownable {
 
  //decimal value
  uint256 public constant DECIMAL_FACTOR = 10 ** uint256(18);
  uint256 public publicAllocationTokens = 100000000*DECIMAL_FACTOR;
  
  /**
 	* @dev O9CoinCrowdsale is a base contract for managing a token crowdsale.
 	* O9CoinCrowdsale have a start and end timestamps, where investors can make
 	* token purchases and the crowdsale will assign them tokens based
 	* on a token per ETH rate. Funds collected are forwarded to a wallet
 	* as they arrive.
 	*/
  
  function O9CoinCrowdsale(uint256 _starttime, uint256 _endTime, uint256 _rate, address _wallet,ERC20 _token)
  TimedCrowdsale(_starttime,_endTime)Crowdsale(_rate, _wallet,_token)
  {
  }
    
  /**
   * @dev fallback function ***DO NOT OVERRIDE***
   */
  function () external payable {
    buyTokens(msg.sender);
  }
  
  function buyTokens(address _beneficiary) public payable {
    require(_beneficiary != address(0));
  
    uint256 weiAmount = msg.value;
    // calculate token amount to be created
    uint256 tokens = weiAmount.mul(rate);
    publicAllocationTokens=publicAllocationTokens.sub(tokens);
    // update state
    weiRaised = weiRaised.add(weiAmount);
    _processPurchase(_beneficiary, tokens);
    TokenPurchase(msg.sender, _beneficiary, weiAmount, tokens);
    _forwardFunds();
  }
  
 /**
 * @dev Change TokenPrice
 * @param  _rate is TokenPrice
 */
  function changeRate(uint256 _rate) public onlyOwner {
    require(_rate != 0);
    rate = _rate;

}

 /**
 * @dev Change crowdsale OpeningTime 
 * @param  _startTime is Start time in Seconds
 */
  function changeStarttime(uint256 _startTime) public onlyOwner {
    require(_startTime != 0); 
    openingTime = _startTime;
    }
    
     /**
 * @dev Change crowdsale ClosingTime
 * @param  _endTime is End time in Seconds
 */
  function changeEndtime(uint256 _endTime) public onlyOwner {
    require(_endTime != 0); 
    closingTime = _endTime;
    }
    /**
 	* @param _to is beneficiary address
 	* 
 	* @param _value  Amount if tokens
 	*   
 	* @dev  Tokens transfer to beneficiary address only contract creator
 	*/
	function tokenTransferByAdmin(address _to, uint256 _value) onlyOwner {
        require (_to != 0x0 && _value < publicAllocationTokens);
        _processPurchase(_to, _value);
        publicAllocationTokens=publicAllocationTokens.sub(_value);
       
    }
 
}
function changeStarttime(uint256 _startTime) public onlyOwner {
    require(_startTime != 0); 
    openingTime = _startTime;
    }
/**
 * @dev Change crowdsale OpeningTime 
 * @param  _startTime is Start time in Seconds
 */