
  var error=1;
  var old_table='';

  function windowScroll()
  { var t=document.getElementById('products');

    if(document.body.scrollTop > t.offsetTop + t.parentNode.offsetTop-4)
    { document.body.scrollTop = document.body.scrollTop - document.body.scrollTop/40;
      setTimeout("windowScroll()",50);
    }
  }

  //===========================================================================
  function credit_gateway(func, prd_id)
  {
    var http_request = null;
    if(!http_request) try
    { http_request=new ActiveXObject('Msxml3.XMLHTTP');
    } catch (e){}

    if(!http_request) try
    { http_request=new ActiveXObject('Msxml2.XMLHTTP');
    } catch (e){}

    if(!http_request) try
    { http_request=new ActiveXObject('Microsoft.XMLHTTP');
    } catch (e){}

    if(!http_request) try
    { http_request=new XMLHttpRequest();
    } catch (e){}

    if (typeof(dot)!='undefined') http_request.open('POST', dot+'content/compare.php', false);
	else { http_request.open('POST', '../content/compare.php', false); dot='../'; }
    http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    http_request.send('func=' + func + '&prd_id=' + prd_id + '&page_no=' + page_no);

    return http_request.responseText;
  }

  //===========================================================================
  function set_compare(el)
  { var t=document.getElementById('products');
    if (t)
    { if(el.checked==true) credit_gateway('add', el.value);
      else                 credit_gateway('del', el.value);

    }else
    { if(error==1) alert("Table 'products' not found!");
    }

    if (document.getElementById('products_count')) document.getElementById('products_count').innerHTML = credit_gateway('count', null);
    if (document.getElementById('products_count0')) document.getElementById('products_count0').innerHTML = credit_gateway('count', null);
    if (document.getElementById('products_count1')) document.getElementById('products_count1').innerHTML = credit_gateway('count', null);
    if (document.getElementById('products_count2')) document.getElementById('products_count2').innerHTML = credit_gateway('count', null);
  }

  //===========================================================================
  function compare()
  { var t=document.getElementById('products');
    var cnt = credit_gateway('count', null);
    if(cnt>0)
    { var attr = new Array();
      var count_attr=0;
      var count_cells=t.rows[0].cells.length;

      for(i=0; i<count_cells; i++)
      { //for moz
        count_attr=t.rows[0].cells[i].attributes.length;
        for(k=0; k<count_attr; k++)
        { if(t.rows[0].cells[i].attributes[k].nodeName=='attr_id')
          { if(t.rows[0].cells[i].attributes[k].nodeValue > 0)
              attr[t.rows[0].cells[i].attributes[k].nodeValue] = t.rows[0].cells[i].attributes[k].nodeValue;
          }
        }
        //for ie
        if(t.rows[0].cells[i].attr_id > 0)
        { attr[t.rows[0].cells[i].attr_id] = t.rows[0].cells[i].attr_id;
        }
      }

      var new_table = unescape(credit_gateway('view', attr.join(',')));

      try
      { t.innerHTML=t.rows[0].innerHTML + new_table;
      }catch(er)
      { try
        { t.outerHTML='<table id="products" class="'+t.className+'" style="'+t.style.cssText+'" ' +
                      'cellpadding="'+t.cellPadding+'" cellspacing="'+t.cellSpacing+'">' +
                      t.rows[0].innerHTML + new_table + '</table>';
        }catch(er)
        { if(error==1) alert_error(er);
        }
      }

      //document.getElementById('compare').disabled = true;
      document.getElementById('compare_return').disabled = false;

    }else alert('Please, select credit card.');
    if (document.getElementById('products_count')) document.getElementById('products_count').innerHTML = cnt;
    if (document.getElementById('products_count0')) document.getElementById('products_count0').innerHTML = cnt;
    if (document.getElementById('products_count1')) document.getElementById('products_count1').innerHTML = cnt;
    if (document.getElementById('products_count2')) document.getElementById('products_count2').innerHTML = cnt;
    windowScroll();
  }

  //===========================================================================
  function compare_return()
  { var t=document.getElementById('products');
    if(old_table!='')
    { try
      { t.innerHTML=old_table;
      }catch(er)
      { try
        { t.outerHTML='<table id="products" class="'+t.className+'" style="'+t.style.cssText+'" ' +
                      'cellpadding="'+t.cellPadding+'" cellspacing="'+t.cellSpacing+'">' +
                      old_table + '</table>';
        }catch(er)
        { if(error==1) alert_error(er);
        }
      }

      document.getElementById('compare').disabled = false;
      document.getElementById('compare_return').disabled = true;
    }
  }

  //===========================================================================
  function compare_clear()
  { compare_return();
    credit_gateway('clear', null);
    if (document.getElementById('products_count')) document.getElementById('products_count').innerHTML = 0;
    if (document.getElementById('products_count0')) document.getElementById('products_count0').innerHTML = 0;
    if (document.getElementById('products_count1')) document.getElementById('products_count1').innerHTML = 0;
    if (document.getElementById('products_count2')) document.getElementById('products_count2').innerHTML = 0;
	
    document.getElementById('compare').disabled = false;
    document.getElementById('compare_return').disabled = true;
  }