//prevzate z http://techpatterns.com/downloads/javascript_cookies.php
function setCookie( name, value, expires, path, domain, secure ) {
	var today = new Date();
	today.setTime( today.getTime() );
	
	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 getCookie(checkName) {
	var aAllCookies = document.cookie.split(';');
	var aTempCookie = '';
	var cookieName = '';
	var cookieValue = '';
	var bCookieFound = false; 
	
	for ( i = 0; i < aAllCookies.length; i++ ) {
		aTempCookie = aAllCookies[i].split( '=' );
		
		cookieName = aTempCookie[0].replace(/^\s+|\s+$/g, '');
		
		if ( cookieName == checkName ) {
			bCookieFound = true;
			
			if ( aTempCookie.length > 1 ) {
				cookieValue = unescape( aTempCookie[1].replace(/^\s+|\s+$/g, ''));
			}
			return cookieValue;
			break;
		}
		aTempCookie = null;
		cookieName = '';
	}
	if ( !bCookieFound )
	{
		return null;
	}
}

function deleteCookie(name, path, domain) {
	if (getCookie(name)) {
		document.cookie = name + "=" +
											((path) ? ";path=" + path : "") +
											((domain) ? ";domain=" + domain : "" ) +
											";expires=Thu, 01-Jan-1970 00:00:01 GMT";
	}
}

function getActualDate() {
	var date = new Date();
	return date.getTime();
}

function setInstance() {
	setCookie('instance', getActualDate(), 0, '', '', '');
}

function getInstance() {
	return getCookie('instance');
}

function unsetInstance() {
	deleteCookie('instance', '', '');
}

function checkInstance() {
	setInstance();
}
