function compare()
{
    this.items    = ExtractCookies('CComp').replace('none','');
    this.maxItems = 10;
}
compare.prototype.FillItem = function(value) {
    this.items = value;
}
compare.prototype.addItem = function(e)
{
    var src = (window.event)? window.event.srcElement : e.target;
    if (src.checked)
    {
        if ( this.items.split('|').length-1 > this.maxItems )
        {
            src.checked = false; 
            alert("Maximálně lze porovnávat " + this.maxItems + " produkty!"); 
            return false;
        }
        if (this.items.indexOf('|' + src.value + '|') < 0) { this.items += (this.items=='' ? '|' : '') +  src.value + '|'; }
    }
    else
    {
        this.items = this.items.replace('|'+src.value+'|', '|');
    }
    setCookiesNoExpire('CComp', this.items);
}
compare.prototype.clear = function()    { this.items=''; setCookiesNoExpire('CComp',this.items);}
compare.prototype.clearAll = function() 
{
    this.clear(); this.checkOnOff(false);
}
compare.prototype.checkOnOff = function(bOn)
{
	var ofrm = document.forms;
	for (var i=0; i < ofrm.length; i++) 
	{
		if (ofrm[i] && ofrm[i].ccompCh)
		{
		    if ( bOn && this.items.indexOf('|'+ofrm[i].ccompCh.value + '|') > -1 ) ofrm[i].ccompCh.checked = true;
		    else ofrm[i].ccompCh.checked = false;
		 }
	}
	if (!bOn) { this.clear(); }
}	
compare.prototype.compare = function()
{
    if (this.items == '')     { alert('Zvolte zboží k porovnání'); return false; }
    this.openwin();
	return false;
}
compare.prototype.prepare = function()
{
    var q = this.items;
	while(q.indexOf('|') > -1) q = q.replace('|', ','); while(q.indexOf('|') > -1)  q = q.replace('|', '');
	if (q.substring(0,1) == ',') q = q.substring(1, q.length-1);
	return q;
}
compare.prototype.showHideCols = function(e)
{
    var src = (window.event)? window.event.srcElement : e.target;
    var catId = src.options[src.selectedIndex].value;
    var Node = getE('CompareTbl').childNodes[0];
    
    for (var i=0; i<Node.childNodes.length;i++)
    {
        var TR = Node.childNodes[i];
        for (var j=1;j<TR.childNodes.length;j++)
            TR.childNodes[j].style.display = (TR.childNodes[j].name == 'col_'+catId || catId==0)  ? 'block' : 'none';
    }
    cCompare.showHideIdentical( getE('allprms').checked );
}
compare.prototype.showHideIdentical = function(bShow)
{
   var Node = getE('CompareTbl'); if (Node==null) return false;
   for (var i=0;i<Node.childNodes[0].childNodes.length;i++)
   {
        if (Node.childNodes[0].childNodes[i].name =='trParam') this.showHideRow( bShow, Node.childNodes[0].childNodes[i] );
   }
    
}
compare.prototype.showHideRow = function(bShow, Node)
{
   if (bShow)                      { Node.style.display = 'block'; return true; }
   if (Node.childNodes.length < 2) { return false; }
   bShow = true;
   var svalue = '###';
   for (var i=1; i<Node.childNodes.length;i++)
   {
       if (Node.childNodes[i].style.display != 'none')
       {
            if (svalue == '###') svalue=Node.childNodes[i].innerHTML; 
            if (svalue != Node.childNodes[i].innerHTML) { bShow = false; break;}
       }
   }
   Node.style.display = (bShow) ? 'none' : 'block';
}

compare.prototype.reload = function(value) {


    this.items = this.items.replace('|' + value + '|', '|'); setCookiesNoExpire('CComp', this.items);
    if (window.opener) { window.opener.transfer(this.items); }
    if (this.items == '') { document.location = '/'; return false; }
    this.openwin();
}
compare.prototype.openwin = function()
{
    var sUrl = '/compare.asp?DPGS=' + this.prepare();
    var msg = window.open(sUrl,'wincompare','toobar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,width=1024px,height=600px,left=20,top=20');
	if (msg) msg.focus();
}
var cCompare = new compare();
function transfer(value) {
    cCompare.FillItem(value);
}
