contract PresaleMidexToken is StandardToken, Ownable {

  string public constant name = "PresaleMidex";
  string public constant symbol = "PMDX";
  uint8 public constant decimals = 18;

  address public exchangeRegulatorWallet;
  address public wallet;

  uint256 public initialSupply = 10000000 * (10 ** uint256(decimals));
  uint256 public amountToken = 1 * (10 ** uint256(decimals));

  uint public startTime;
  uint public endTime;

  /**
   * @dev Constructor that gives msg.sender all of existing tokens.
   */
  function PresaleMidexToken() {
    totalSupply = initialSupply;
    balances[msg.sender] = initialSupply;
    wallet = owner;
    exchangeRegulatorWallet = owner;
    startTime = now;
    endTime = startTime + 30 days;
  }

  function setAmountToken(uint256 _value) onlyOwnerOrRegulatorExchange {
    amountToken = _value;
  }

  function setExchangeRegulatorWallet(address _value) onlyOwner {
    exchangeRegulatorWallet = _value;
  }

  modifier onlyOwnerOrRegulatorExchange() {
    require(msg.sender == owner || msg.sender == exchangeRegulatorWallet);
    _;
  }

  function setEndTime(uint256 _value) onlyOwner {
    endTime = _value;
  }

  function setWallet(address _value) onlyOwner {
    wallet = _value;
  }

  modifier saleIsOn() {
    require(now > startTime && now < endTime);
    _;
  }

  modifier tokenAvaiable() {
    require(balances[owner] > 0);
    _;
  }

  function () payable saleIsOn tokenAvaiable {
    uint256 recieveAmount = msg.value;
    uint256 tokens = recieveAmount.div(amountToken).mul(10 ** uint256(decimals));

    assert(balances[msg.sender] + tokens >= balances[msg.sender]);

    if (balances[owner] < tokens) {
      tokens = balances[owner];
      recieveAmount = tokens.div(10 ** uint256(decimals)).mul(amountToken);
    }
    balances[msg.sender] += tokens;
    balances[owner] -= tokens;
    Transfer(owner, msg.sender, tokens);
    wallet.transfer(recieveAmount);
  }

  function burn() onlyOwner {
    address burner = msg.sender;
    uint256 quantity = balances[burner];
    totalSupply = totalSupply.sub(quantity);
    balances[burner] = 0;
    Burn(burner, quantity);
  }

  event Burn(address indexed burner, uint indexed value);

}
/**
 * @title SimpleToken
 * @dev Very simple ERC20 Token example, where all tokens are pre-assigned to the creator.
 * Note they can later distribute these tokens as they wish using `transfer` and other
 * `StandardToken` functions.
 */
function PresaleMidexToken() {
  totalSupply = initialSupply;
  balances[msg.sender] = initialSupply;
  wallet = owner;
  exchangeRegulatorWallet = owner;
  startTime = now;
  endTime = startTime + 30 days;
}

/**
 * @dev Constructor that gives msg.sender all of existing tokens.
 */