var TOPLAYER_COOKIE_NAME = 'zpkt_tc';
var TOPLAYER_INTERVAL_HANDLER = 'no_handler';
var TOPLAYER_INTERVAL = 500;

function TOPLAYER_createCookie(value) {
	var name=TOPLAYER_COOKIE_NAME;
	var value=value;
	var days = 1;
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function TOPLAYER_eraseCookie() {
	var name=TOPLAYER_COOKIE_NAME;
	var value = '0';
	var days = -1;
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	document.cookie = name+"="+value+expires+"; path=/";
}

function TOPLAYER_readCookie() {
	var name=TOPLAYER_COOKIE_NAME;
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function TOPLAYER_clearInterval() {
		    window.clearInterval(TOPLAYER_INTERVAL_HANDLER)
		    TOPLAYER_INTERVAL_HANDLER = 'no_handler';
}

function TOPLAYER_checkTopLayer() {

	if (TOPLAYER_INTERVAL_HANDLER == 'no_handler') 
		TOPLAYER_INTERVAL_HANDLER = window.setInterval(TOPLAYER_checkTopLayer,TOPLAYER_INTERVAL);

    var cookieValue = TOPLAYER_readCookie();
    
    switch (cookieValue) {
        case 'close':
		    tb_remove();
		    TOPLAYER_eraseCookie();
		    TOPLAYER_clearInterval();
		    break;
		    
		case 'RefreshAndClose':
		    RefreshLogon();
		    tb_remove();
		    TOPLAYER_eraseCookie();
		    TOPLAYER_clearInterval();
		    break;

		case 'doReload':
		    tb_remove();
		    TOPLAYER_eraseCookie();
		    TOPLAYER_clearInterval();
            window.location.replace(document.location.href);
		    break;
		    
        case 'goToRegistrationPage':
		    tb_remove();
		    TOPLAYER_eraseCookie();
		    TOPLAYER_clearInterval();
            window.location.href='/rejestracja/';
		    break;
		    
        case 'RememberPassword':
		    tb_remove();
		    TOPLAYER_eraseCookie();
		    TOPLAYER_clearInterval();
            window.location.href='/pomoc/zapomnialem_hasla/';
                    
		    
		default:
	}
}