contract DogezerPreICOCrowdsale is Haltable{
    using SafeMath for uint;
    string public name = "Dogezer preITO";

    address public beneficiary;
    uint public startTime;
    uint public duration;


    uint public fundingGoal; 
    uint public amountRaised; 
    uint public price; 
    preDGZToken public tokenReward;

    mapping(address => uint256) public balanceOf;

    event SaleFinished(uint finishAmountRaised);
    event FundTransfer(address backer, uint amount, bool isContribution);
    bool public crowdsaleClosed = false;


    /*  at initialization, setup the owner */
    function DogezerPreICOCrowdsale(
        address addressOfTokenUsedAsReward,
		address addressOfBeneficiary
    ) {
        beneficiary = addressOfBeneficiary;
        startTime = 1504270800;
        duration = 707 hours;
        fundingGoal = 4000 * 1 ether;
        amountRaised = 0;
        price = 0.00000000002 * 1 ether;
        tokenReward = preDGZToken(addressOfTokenUsedAsReward);
    }

    modifier onlyAfterStart() {
        require (now >= startTime);
        _;
    }

    modifier onlyBeforeEnd() {
        require (now <= startTime + duration);
        _;
    }

    /* The function without name is the default function that is called whenever anyone sends funds to a contract */
    function () payable stopInEmergency onlyAfterStart onlyBeforeEnd
    {
		require (msg.value >= 0.002 * 1 ether);
        require (crowdsaleClosed == false);
        require (fundingGoal >= amountRaised + msg.value);
        uint amount = msg.value;
        balanceOf[msg.sender] += amount;
        amountRaised += amount;  
        tokenReward.transfer(msg.sender, amount / price);
        FundTransfer(msg.sender, amount, true); 
        if (amountRaised == fundingGoal)
        {
            crowdsaleClosed = true;
            SaleFinished(amountRaised);
        }
    }
 
   function withdrawal (uint amountWithdraw) onlyOwner
   {
		beneficiary.transfer(amountWithdraw);
   }
   
   function changeBeneficiary(address newBeneficiary) onlyOwner {
		if (newBeneficiary != address(0)) {
		  beneficiary = newBeneficiary;
		}
	}
   
   function finalizeSale () onlyOwner
   {
       require (crowdsaleClosed == false);
       crowdsaleClosed = true;
       SaleFinished(amountRaised);
   }
}
function () payable stopInEmergency onlyAfterStart onlyBeforeEnd
{
quire (msg.value >= 0.002 * 1 ether);
    require (crowdsaleClosed == false);
    require (fundingGoal >= amountRaised + msg.value);
    uint amount = msg.value;
    balanceOf[msg.sender] += amount;
    amountRaised += amount;  
    tokenReward.transfer(msg.sender, amount / price);
    FundTransfer(msg.sender, amount, true); 
    if (amountRaised == fundingGoal)
    {
        crowdsaleClosed = true;
        SaleFinished(amountRaised);
    }
}

/* The function without name is the default function that is called whenever anyone sends funds to a contract */