
// Vkladani cookie, jestli je uz vlozena - update, jestli neni - vlozi novou
function addCookie( name, value, expires, path, domain, secure )
{
	// Jestli bude existovat kukina
	if(getCookie(name))
	{
		// Zkontroluje pocet promennych
		if(checkValueCount(name))
		{
			updateCookie(name, value, expires, path, domain, secure);
		}
		
	}
	else
	{
		setCookie( name, value, expires, path, domain, secure );
	}
}


function getAlertForCompare()
{
	alert("Maximum of 4 funds");
	
}


// Zjistuje kolik je v kukine promennych 
function checkValueCount(name)
{
	// kukina
	var existingCookieValue = getCookie(name);
	//document.write(str.split("-") + "<br />");
	//Parsovani
	var mySplitResult = existingCookieValue.split("-");

	// Jestli bude ulozeno vice nez 4 zaznamy
	if(mySplitResult.length>3){
		getAlertForCompare();
		return false;
	}
	else
	{
		return true;
	}
}

	
	//alert(existingCookieValue.split("-",4));

	


// Metoda pro upravu existujici cookie
// Prida novou hodnotu
function updateCookie(name, value, expires, path, domain, secure)
{
	
	
	
	
	var existingCookieValue = getCookie(name);
	var mySplitResult = existingCookieValue.split("-");
	var isInCookie = 0;
	
	// Zjisti jestli je hodnota uz v kukine
	for(i = 0; i < mySplitResult.length; i++){
		if(mySplitResult[i]==value){isInCookie=1;} 
	}
	
	
	// Jestli hodnota jeste v kukine neni tak ji updatne
	if(isInCookie==0)
	{
		//document.write("UPDATE");
		var newValue = null;
		var exp = "-"
		var existingCookieValue = getCookie(name);
		
		newValue = existingCookieValue + exp + value;
		//document.write(newValue);
		setCookie(name, newValue, expires, path, domain, secure);
	}
}

function setCookie(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 getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}


function deleteCookieOLD(name) {
	document.write(name);
	document.cookie = name +
	'=; expires=Thu, 01-Jan-70 00:00:01 GMT;';
	} 

function deleteCookieOLD2(name)
{
    var d = new Date();
    document.cookie = name +";expires=" + d.toGMTString() + ";";
}

function deleteCookie(name)
{
	setCookie(name,"","-1","/","","");
	//alert("MAZU");
}



