function Set_Cookie(name, value, expires, path, domain, secure)
{
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime(today.getTime());

	/*
	if the expires variable is set, make the correct
	expires time, the current script below will set
	it for x number of days, to make it for hours,
	delete * 24, for minutes, delete * 60 * 24
	*/
	if(expires)	expires = expires * 1000 * 60 * 60 * 24;

	var expires_date = new Date(today.getTime() + (expires));

	document.cookie = name + "=" +escape(value) +
	((expires)?";expires=" + expires_date.toGMTString() : "") +
	((path)?";path=" + path : "") +
	((domain)?";domain=" + domain : "") +
	((secure)?";secure" : "");
}

function Get_Cookie(name) {
	var start = document.cookie.indexOf(name + "=");
	var len = start + name.length + 1;
	if(!start && name!=document.cookie.substring(0,name.length)) return null;
	if(start==-1) return null;
	var end = document.cookie.indexOf(";",len);
	if(end==-1 ) end=document.cookie.length;
	return unescape(document.cookie.substring(len,end));
}

function Delete_Cookie(name, path, domain) {
	if(Get_Cookie(name)) {
    	document.cookie = name + "=" + ((path) ? ";path=" + path : "") + ((domain) ? ";domain=" + domain : "") + ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
    }
}

var bonus1_on=0;
var bonus1_timer="";
var bonus2_on=0;
var bonus2_timer="";
var missed_bonus=0;

function bonus_1()
{
	var today = new Date();

	first_bonus=Get_Cookie("first_bonus");
	if(!first_bonus) {
		Set_Cookie("first_bonus",today.getTime()+30*60*1000,30);
        first_bonus=today.getTime()+30*60*1000;
    }

    var left_time = document.getElementById("left_time1");
    first_bonus=first_bonus-today.getTime();

    days = first_bonus / 1000 / 60 / 60 / 24;
    daysRound = Math.floor(days);
    hours = first_bonus / 1000 / 60 / 60 - (24 * daysRound);
    hoursRound = Math.floor(hours);
    minutes = first_bonus / 1000 /60 - (24 * 60 * daysRound) - (60 * hoursRound);
    minutesRound = Math.floor(minutes);
    if(minutesRound < 10 ) minutesRound = "0" + minutesRound;
    seconds = first_bonus / 1000 - (24 * 60 * 60 * daysRound) - (60 * 60 * hoursRound) - (60 * minutesRound);
    secondsRound = Math.round(seconds);
    if(secondsRound < 10 ) secondsRound = "0" + secondsRound;

    if(first_bonus>=0) bonus1_timer=minutesRound + ":" + secondsRound;

    if(first_bonus<=0)
    {
		clearInterval(int);
        window.location.href=unescape(window.location.pathname);
        bonus1_on=0;
    }
    else bonus1_on=1;
}

function bonus_2()
{
	var today = new Date();

	second_bonus=Get_Cookie("second_bonus");
	if(!second_bonus) {
		Set_Cookie("second_bonus",today.getTime()+7*24*60*60*1000,30);
        second_bonus=today.getTime()+7*24*60*60*1000;
    }

    var left_time = document.getElementById("left_time2");
    second_bonus=second_bonus-today.getTime();

    days = second_bonus / 1000 / 60 / 60 / 24;
    daysRound = Math.floor(days);
    hours = second_bonus / 1000 / 60 / 60 - (24 * daysRound);
    hoursRound = Math.floor(hours);
    minutes = second_bonus / 1000 /60 - (24 * 60 * daysRound) - (60 * hoursRound);
    minutesRound = Math.floor(minutes);
    seconds = second_bonus / 1000 - (24 * 60 * 60 * daysRound) - (60 * 60 * hoursRound) - (60 * minutesRound);
    secondsRound = Math.round(seconds);

	var tmp="";

    if(daysRound) tmp=daysRound + " days ";
    if(hoursRound) tmp=tmp + hoursRound + " hours ";
    if(minutesRound) tmp=tmp + minutesRound + " minutes and ";
    if(second_bonus>=0) bonus2_timer=tmp + secondsRound;

    if(second_bonus<=0)
    {
		clearInterval(int);
        window.location.href=unescape(window.location.pathname);
		bonus2_on=0;
    }
    else bonus2_on=1;
}
