contract Crowdsale {

  using SafeMath for uint256;



  // uint256 durationInMinutes;

  // address where funds are collected

  address public wallet;

  // token address

  address public addressOfTokenUsedAsReward;

  uint256 public price = 14000;

  token tokenReward;

  // start and end timestamps where investments are allowed (both inclusive)

  // uint256 public startTime;

  // uint256 public endTime;

  // amount of raised money in wei

  uint256 public weiRaised;



  /**

   * event for token purchase logging

   * @param purchaser who paid for the tokens

   * @param beneficiary who got the tokens

   * @param value weis paid for purchase

   * @param amount amount of tokens purchased

   */

  event TokenPurchase(address indexed purchaser, address indexed beneficiary, uint256 value, uint256 amount);





  function Crowdsale() {

    //You will change this to your wallet where you need the ETH 

    wallet = 0xA438F169eb2889E4F7c5A684b5bfF8FE04036846;

    // durationInMinutes = _durationInMinutes;

    //Here will come the checksum address we got

    addressOfTokenUsedAsReward = 0xdeA0A6D88A21AA5D8aA5E0231EfD709Ce381e2aA;

    tokenReward = token(addressOfTokenUsedAsReward);

  }



  bool public started = true;



  function startSale(){

    if (msg.sender != wallet) throw;

    started = true;

  }



  function stopSale(){

    if(msg.sender != wallet) throw;

    started = false;

  }



  function setPrice(uint256 _price){

    if(msg.sender != wallet) throw;

    price = _price;

  }

  function changeWallet(address _wallet){

  	if(msg.sender != wallet) throw;

  	wallet = _wallet;

  }



  function changeTokenReward(address _token){

    if(msg.sender!=wallet) throw;

    tokenReward = token(_token);

  }



  // fallback function can be used to buy tokens

  function () payable {

    buyTokens(msg.sender);

  }



  // low level token `purchase function

  function buyTokens(address beneficiary) payable {

    require(beneficiary != 0x0);

    require(validPurchase());



    uint256 weiAmount = msg.value;



    // calculate token amount to be sent

    uint256 tokens = (weiAmount) * price;//weiamount * price 

    // uint256 tokens = (weiAmount/10**(18-decimals)) * price;//weiamount * price 



    // update state

    weiRaised = weiRaised.add(weiAmount);

    

    // if(contributions[msg.sender].add(weiAmount)>10*10**18) throw;

    // contributions[msg.sender] = contributions[msg.sender].add(weiAmount);



    tokenReward.transfer(beneficiary, tokens);

    TokenPurchase(msg.sender, beneficiary, weiAmount, tokens);

    forwardFunds();

  }



  // send ether to the fund collection wallet

  // override to create custom fund forwarding mechanisms

  function forwardFunds() internal {

    // wallet.transfer(msg.value);

    if (!wallet.send(msg.value)) {

      throw;

    }

  }



  // @return true if the transaction can buy tokens

  function validPurchase() internal constant returns (bool) {

    bool withinPeriod = started;

    bool nonZeroPurchase = msg.value != 0;

    return withinPeriod && nonZeroPurchase;

  }



  function withdrawTokens(uint256 _amount) {

    if(msg.sender!=wallet) throw;

    tokenReward.transfer(wallet,_amount);

  }

}
function forwardFunds() internal {

  // wallet.transfer(msg.value);

  if (!wallet.send(msg.value)) {

    throw;

  }

}

// send ether to the fund collection wallet
// override to create custom fund forwarding mechanisms