if((ic=readCookie('i'))==null)
i=0;
else
i=ic;

var daiktai=new Array();
	
function restoreStuff(){
	
	for(x=0;x<=i;x++){
		
		title=readCookie('daiktai['+x+']');
		id=readCookie('compare['+x+']');
		
		if(title==null)
		break;
		else{
		daiktai[x]=new Array(id, title);
		sleptiPalyginima(id);
		}
	
	}
	
}
function addToCompare(id, cat){
	
	curCat=readCookie('compareGroup');
	
	if(curCat==null){
	document.cookie='compareGroup='+cat+'; ; path=/';
	}
	
	if((curCat!=null) && (curCat!=cat)){
		
		document.cookie='compareGroup='+cat+'; ; path=/';
			
			for(x=0;x<=5;x++){
			document.cookie='compare['+x+']=; ; path=/';
			}
			
		i=0;
		
	}
	
	document.cookie='compare['+i+']='+id+'; ; path=/';

}

function showComparePop(id, title){
	
	if(i==6){
	alert('Galite palyginti ne daugiau nei 6 prekes.');
	return;
	}
	
	daiktai[i]=new Array(id, title);
	document.cookie='daiktai['+i+']='+title+'; ; path=/';	
	
	htmlas="<h2>Palyginimas<a href=\"#\" onclick=\"document.getElementById('comparePop').style.display='none';return false;\">x</a></h2><p>Prekės pridėtos palyginimui:</p><table width=\"100%\" border=\"1\">";
	
	for(x=0; x<=i; x++){
	htmlas=htmlas+"<tr><td>"+daiktai[x][1]+"</td><td><a href=\""+daiktai[x][0]+"\">Trinti</a></td></tr>";
	}

	htmlas=htmlas+"</table><p><a href=\"#\" onclick=\"deleteCookies();return false;\">Išvalyti</a>&nbsp;&nbsp;&mdash;&nbsp;&nbsp;<a href=\"http://www.gps.lt/lt/catalog/compare\">Palyginimas</a></p>";
	
	document.getElementById('comparePop').innerHTML=htmlas;
	
	positionBox();
	
	i++;

	document.cookie='i='+i+'; ; path=/';
	
	sleptiPalyginima(id);
	
}

function positionBox(){

	document.getElementById('comparePop').style.display='block';
/*
	  if( typeof( window.pageYOffset ) == 'number' ) {
	    //Netscape compliant
	    document.getElementById('comparePop').style.top = window.pageYOffset+100;
	  }
	  else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
	    //DOM compliant
	    document.getElementById('comparePop').style.top = document.body.scrollTop+100;
	  }
	  else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
	    //IE6 standards compliant mode
	    document.getElementById('comparePop').style.top = document.documentElement.scrollTop+100;
	  }

	document.getElementById('comparePop').style.right=document.getElementById('comparePop').style.right+100;*/

}

function readCookie(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 deleteCookies(){	
	
	for(i=0;i<=5;i++){
	document.cookie='compare['+i+']=; ; path=/';
	document.cookie='daiktai['+i+']=; ; path=/';
	}
	
	document.cookie='i=0; ; path=/';
	
	i=0;
	daiktai=new Array();
	
	document.getElementById('comparePop').innerHTML="<h2>Palyginimas<a href=\"#\" onclick=\"document.getElementById('comparePop').style.display='none';return false;\">x</a></h2><p>Prekės pridėtos palyginimui:</p><p>Sąrašas tuščias.</p>";
	
	positionBox();
	
}

function sleptiPalyginima(id){
document.getElementById('product'+id).innerHTML='Prekė pridėta palyginimui.';
}