// main menu scripts

var TimerId = null;
var VisibleId = "";

function findPos(obj) {
  var currtop = 0;
  var currleft = 0;
    if (obj.offsetParent) {
	  while (obj.offsetParent != null) {
		currtop += obj.offsetTop
		currleft += obj.offsetLeft
		// alert(curleft + ', ' + obj.offsetParent)
	  	obj = obj.offsetParent
	  }
	}
  return [currtop,currleft]
}

var calZakupData = null;

function ExtWarrantyCalendar() {
  calZakupData = new calendar3(document.forms['extwarranty'].elements['sdate']);
  calZakupData.year_scroll = true;
}

function ExtWarrantyActivity() {
  var cmbZakupSposob = document.forms['extwarranty'].elements['wayofp'];
  var txtZakupMiasto = document.forms['extwarranty'].elements['location'];
  if(cmbZakupSposob.options[0].selected)
    txtZakupMiasto.style.display = 'none';
  else
    txtZakupMiasto.style.display = 'block';
}

function OverMenu(LayerId,Obj) { 
  if(Obj) {
    yPos = findPos(Obj)[0]
	xPos = findPos(Obj)[1]
	Parent = Obj.offsetParent
    xPosParent = findPos(Parent)[1]
    var LayerWidth = parseInt(window.getComputedStyle(document.getElementById(LayerId),null).getPropertyValue("width"))
	if(xPos + LayerWidth > xPosParent + Parent.offsetWidth) {
      xPos = xPos - LayerWidth + Obj.offsetWidth - 24
    }
    if (document.layers)               {
      document.layer[LayerId].top = yPos + Obj.offsetHeight
      document.layer[LayerId].left = xPos
    }
    else if (document.all)             {
      document.all[LayerId].style.top = yPos + Obj.offsetHeight
      document.all[LayerId].style.left = xPos
    }
    else if (document.documentElement) {
	  document.getElementById(LayerId).style.top = yPos + Obj.offsetHeight + 'px'
	  document.getElementById(LayerId).style.left = xPos + 'px'
	}
  } 
  else { 
    var divs=document.getElementsByTagName('div')
    for(i=0; i<divs.length; i++) {
      if(divs[i].getAttribute('name')==LayerId) {
        divs[i].className = "mm-off-open"
      }
    }
  }  
  if((VisibleId != "") && (TimerId != null)) {
    if(LayerId != VisibleId) {
      RestoreOpenClass(VisibleId)
      SetVisibility(VisibleId, "hidden")
    }
    clearTimeout(TimerId)
  }
  SetVisibility(LayerId, "visible");
}

function OutMenu(LayerId) {
  TimerId = window.setTimeout("HideMenu()", 500);
}

function HideMenu() {
  if(VisibleId != "") {
    RestoreOpenClass(VisibleId)
    SetVisibility(VisibleId, "hidden")
  }
  if(TimerId != null) { clearTimeout(TimerId) }
}

function RestoreOpenClass(VisibleId) {
    var divs=document.getElementsByTagName('div')
    for(i=0; i<divs.length; i++) {
      if(divs[i].getAttribute('name')==VisibleId) {
        divs[i].className = "mm-off"
      }
    }
}

function SetVisibility(LayerId, Visibility) {
  if (document.layers)               { document.layer[LayerId].visibility = Visibility }
  else if (document.all)             { document.all[LayerId].style.visibility = Visibility }
  else if (document.documentElement) { document.getElementById(LayerId).style.visibility = Visibility }
  if(Visibility == "visible") { VisibleId = LayerId } else { VisibleId = "" }
}

// end of main menu scripts

function WriteMail(user,domain,style) {
  var address = user + "@" + domain;
  if(style!="") { var classname="class='" + style + "'" }
  document.write("<a href='mailto:" + address + "' " + classname +">" + address +"</a>");
}

// tabs scripts

function tabcontent(tabscontainerid) {
  this.tabscontainerid=tabscontainerid
  this.tabs=document.getElementById(tabscontainerid).getElementsByTagName("a")
  this.contentids=[]
  this.containerid=""
  this.currentTabIndex=0
  this.ActiveTabClassName=""
  this.InactiveTabClassName=""
  this.LoadingId=""
  this.enabletabpersistence=true
}

tabcontent.getCookie=function(Name){ 
  var re=new RegExp(Name+"=[^;]+", "i");
  if (document.cookie.match(re))
    return document.cookie.match(re)[0].split("=")[1]
  return ""
}

tabcontent.setCookie=function(name, value){
  document.cookie = name+"="+value+";path=/"
}

tabcontent.prototype={
  // standard mode 
  expandcontent:function(contentid) {
	for (var i=0; i<this.contentids.length; i++){
	  var content=document.getElementById(this.contentids[i])
	  content.style.display=(content.id==contentid)? "block" : "none"
	}
  },
  
  expandtab:function(tabref) {
    var contentid=tabref.getAttribute("rel")
	this.expandcontent(contentid)
	tabref.className=this.ActiveTabClassName
	this.tabs[this.currentTabIndex].className=this.InactiveTabClassName
	this.currentTabIndex=tabref.tabposition
    if (this.enabletabpersistence)
      tabcontent.setCookie(this.tabscontainerid, tabref.tabposition)
  },
  
  init:function() {
  	var persistedtab=tabcontent.getCookie(this.tabscontainerid)
    if ((this.enabletabpersistence) && (parseInt(persistedtab)>0))
	  this.currentTabIndex=parseInt(persistedtab)
    for (var i=0; i<this.tabs.length; i++) {
	  var tabinstance=this
      this.contentids[this.contentids.length]=this.tabs[i].getAttribute("rel")
	  this.tabs[i].tabposition=i
	  this.tabs[i].onclick=function() {
        tabinstance.expandtab(this)
        return false
	  }
	}
	this.tabs[this.currentTabIndex].className=this.ActiveTabClassName
	var contentid=this.contentids[this.currentTabIndex]
	this.expandcontent(contentid)
  },
  
  // Ajax mode 
  contentopacity:function(opacity) {
    document.getElementById(this.containerid).style.filter="alpha(opacity="+opacity+");"
    document.getElementById(this.containerid).style.KhtmlOpacity=opacity/100.0
    document.getElementById(this.containerid).style.MozOpacity=opacity/100.0
    document.getElementById(this.containerid).style.opacity=opacity/100.0
    this.degree=opacity
  },

  showloading:function() {
    this.contentopacity(0)
    var loadingobj=document.getElementById(this.LoadingId)
    loadingobj.style.visibility="visible"
  },

  hideloading:function() {
    var loadingobj=document.getElementById(this.LoadingId)
    loadingobj.style.visibility="hidden"
    this.contentopacity(100)
  },
  
  loadcontentx:function(contentid) {
    if (window.XMLHttpRequest)
      xmlhttp=new XMLHttpRequest()
    else
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
    var tabinstance=this
    xmlhttp.onreadystatechange=function() {
      if (xmlhttp.readyState==4 && xmlhttp.status==200) {
        document.getElementById(tabinstance.containerid).innerHTML=xmlhttp.responseText
        tabinstance.hideloading()
        // executing loaded scripts
        var scripts=document.getElementById(tabinstance.containerid).getElementsByTagName("script");
        for(var i=0;i<scripts.length;i++) {
           eval(scripts[i].text)
        }
      }
    }
    xmlhttp.open("GET",contentid,true)
    xmlhttp.send()   
  },
  
  expandtabx:function(tabref) {
    var contentid=tabref.getAttribute("rel")
	this.loadcontentx(contentid)
	tabref.className=this.ActiveTabClassName
    if(this.currentTabIndex!=tabref.tabposition)
      this.tabs[this.currentTabIndex].className=this.InactiveTabClassName
	this.currentTabIndex=tabref.tabposition
    if (this.enabletabpersistence)
      tabcontent.setCookie(this.tabscontainerid, tabref.tabposition)
  },
  
  initx:function(containerid) {
    this.containerid=containerid
    this.showloading()
  	var persistedtab=tabcontent.getCookie(this.tabscontainerid)
    if ((this.enabletabpersistence) && (parseInt(persistedtab)>0))
	  this.currentTabIndex=parseInt(persistedtab)
    if(this.currentTabIndex+1 > this.tabs.length)
      this.currentTabIndex=0
    for (var i=0; i<this.tabs.length; i++) {
	  var tabinstance=this
      this.contentids[this.contentids.length]=this.tabs[i].getAttribute("rel")
	  this.tabs[i].tabposition=i
	  this.tabs[i].onclick=function() {
        tabinstance.showloading()
        tabinstance.expandtabx(this)
        this.blur()
        return false
	  }
	}
	this.tabs[this.currentTabIndex].className=this.ActiveTabClassName
	var contentid=this.contentids[this.currentTabIndex]
	this.loadcontentx(contentid)
  } 
}

// end of tabs scripts

// params table scripts

function preftable(Id) {
  this.tableid=Id
  this.table=document.getElementById(Id)
  var anchors=this.table.getElementsByTagName('a')
  this.anchor=anchors[0]
  this.enabletablepersistence=true
  this.imgExpand="/img/plus.png"
  this.imgCollapse="/img/minus.png"
  this.imgObj=this.anchor.firstChild
  var tbodys=this.table.getElementsByTagName('tbody')
  this.tbodyObj=tbodys[0]
  if((! this.tbodyObj) || (this.tbodyObj.innerHTML=="")) {
    var divs=document.getElementsByTagName('div')
    for(i=0; i<divs.length; i++) {
      if(divs[i].getAttribute('name')==Id) {
        this.tbodyObj=divs[i]
      }
    }
  }
}

preftable.prototype={
  collapse:function() {
    this.tbodyObj.style.display="none"
    this.imgObj.src=this.imgExpand
  },

  expand:function() {
    this.tbodyObj.style.display=""
    this.imgObj.src=this.imgCollapse
  },

  ExpandOrCollapse:function(anchor) {
    if(this.tbodyObj.style.display=="none")
      this.expand()
    else
      this.collapse()
    if (this.enabletablepersistence)
      tabcontent.setCookie(this.tableid, this.tbodyObj.style.display)
    anchor.blur()  
  },

  init:function() {
    var anchor=this.anchor
    var instance=this
    this.anchor.onclick=function() {
      instance.ExpandOrCollapse(anchor)
      return false
    }
    if (this.enabletablepersistence) {
      var cookie=tabcontent.getCookie(this.tableid)
      if(cookie=="none")
        this.collapse()
    }
  }
}

// end of params table scripts

// product pictures

function prdpicture(pictureId, ctId, phId, enBkgId, enBoxId, enImgId, enTitleBarId, enLeftBtnId,
  enRightBtnId, enContentId, enCaptionId) {
  // picture
  this.pictureId=pictureId
  this.pictureObj=document.getElementById(this.pictureId)
  this.pictureAnch=this.pictureObj.parentNode
  this.pictureRel=this.pictureAnch.getAttribute("rel")
  // colour templates
  this.ctSelected=0
  this.ctId=ctId
  this.ctObj=document.getElementById(this.ctId)
  this.ctAnchors=this.ctObj.getElementsByTagName("a")
  this.ctRels=new Array()
  var instance=this
  for(var i=0;i<this.ctAnchors.length;i++) {
    this.ctAnchors[i].Index=i
    this.ctAnchors[i].href="javascript:void(0)"
    this.ctAnchors[i].onclick=function() {
      instance.ctChange(this.Index)
      this.blur()
      return false
    }  
    this.ctRels.push(this.ctAnchors[i].getAttribute("rel"))
  }
  // photo miniatures
  this.phId=phId
  this.phObj=document.getElementById(this.phId)
  this.phAnchors=new Array()
  this.phSelected=0
  this.ctdefClassName=""
  this.ctselClassName=""
  this.phdefClassName=""
  this.phselClassName=""
  // enlarged photo
  this.enBkgId=enBkgId
  this.enBkgObj=null
  this.enBoxId=enBoxId
  this.enBoxObj=null
  this.enLoadingImgObj=new Image()
  this.enLoadingImgHref="/img/loading.gif"
  this.enImgId=enImgId
  this.enImgObj=null
  this.enTitleBarId=enTitleBarId
  this.enTitleBarObj=null
  this.enTitleBarCloseObj=null
  this.enLeftBtnId=enLeftBtnId
  this.enLeftBtnObj=null
  this.enLeftBtnAnchorObj=null
  this.enRightBtnId=enRightBtnId
  this.enRightBtnObj=null
  this.enContentId=enContentId
  this.enContentObj=null
  this.enCaptionId=enCaptionId
  this.enCaptionObj=null
  this.containerCreate()
  this.enDegree=0
  this.enTimerId=null
  this.enInterval=50
  this.imgPreloader=null
  // various constants
  enContentObjMarginTop=parseInt($(this.enContentId).getStyle('margin-top'))
  enContentObjMarginLeft=parseInt($(this.enContentId).getStyle('margin-left'))
  enContentObjMarginRight=parseInt($(this.enContentId).getStyle('margin-right'))
  enContentObjMarginBottom=parseInt($(this.enContentId).getStyle('margin-bottom'))
  enTitleBarObjWidth=20
  enCaptionObjHeight=parseInt($(this.enCaptionId).getStyle('height'))
  enImgObjPaddingTop=parseInt($(this.enContentId).getStyle('padding-top'))
  enImgObjPaddingBottom=parseInt($(this.enContentId).getStyle('padding-bottom'))
  enImgObjPaddingLeft=parseInt($(this.enContentId).getStyle('padding-left'))
  enImgObjPaddingRight=parseInt($(this.enContentId).getStyle('padding-right'))
  enRightBtnObjWidth=30
}

prdpicture.prototype={
  containerCreate: function() {
    var _self=this

    //man data box
    this.enBoxObj=document.createElement('div')
    this.enBoxObj.setAttribute("id",this.enBoxId)
    this.enBoxObj.onmouseover=function() { _self.enShowBtns(); return false }
    this.enBoxObj.onmouseout=function()  { _self.enHideBtns(); return false }

    // top title bar
    this.enTitleBarObj=document.createElement('div')
    this.enTitleBarObj.setAttribute("id",this.enTitleBarId)
    this.enTitleBarCloseObj=document.createElement('a')
    this.enTitleBarCloseObj.setAttribute("href","javascript:void(0)")
    this.enTitleBarCloseObj.onclick=function() { _self.closeAll(); return false }
    this.enTitleBarObj.appendChild(this.enTitleBarCloseObj)
    this.enBoxObj.appendChild(this.enTitleBarObj)

    // left button    
    this.enLeftBtnObj=document.createElement('div')
    this.enLeftBtnObj.setAttribute("id",this.enLeftBtnId)
    this.enLeftBtnAnchorObj=document.createElement('a')
    this.enLeftBtnAnchorObj.setAttribute("href","javascript:void(0)")
    this.enLeftBtnAnchorObj.onclick=function() { _self.enPrev(); this.blur(); return false }
    this.enLeftBtnObj.appendChild(this.enLeftBtnAnchorObj)
    this.enBoxObj.appendChild(this.enLeftBtnObj)

    // right button    
    this.enRightBtnObj=document.createElement('div')
    this.enRightBtnObj.setAttribute("id",this.enRightBtnId)
    this.enRightBtnAnchorObj=document.createElement('a')
    this.enRightBtnAnchorObj.setAttribute("href","javascript:void(0)")  
    this.enRightBtnAnchorObj.onclick=function() { _self.enNext(); this.blur(); return false }
    this.enRightBtnObj.appendChild(this.enRightBtnAnchorObj)
    this.enBoxObj.appendChild(this.enRightBtnObj)

    // main content
    this.enContentObj=document.createElement('div')
    this.enContentObj.setAttribute("id",this.enContentId)

    // loading image
    this.enLoadingImgObj=document.createElement('img')
    with(this.enLoadingImgObj) {
      setAttribute("src",this.enLoadingImgHref)
      style.position="absolute"
      style.top='100px'
      style.left='100px'
    }
    this.enContentObj.appendChild(this.enLoadingImgObj)
    // main image
    this.enImgObj=document.createElement('img')
    this.enImgObj.setAttribute("id",this.enImgId)
    this.enContentObj.appendChild(this.enImgObj)

    // adding loading image and main image
    this.enBoxObj.appendChild(this.enContentObj)

    // bottom caption
    this.enCaptionObj=document.createElement('div')
    this.enCaptionObj.setAttribute("id",this.enCaptionId)
    this.enBoxObj.appendChild(this.enCaptionObj)
    document.body.appendChild(this.enBoxObj)

    // shadow background
    this.enBkgObj=document.createElement('div')
    this.enBkgObj.setAttribute("id",this.enBkgId)
    document.body.appendChild(this.enBkgObj)
  },

  enBoxObjOnKeyUp:function(e) {
    var e=(e) ? e : ((window.event) ? event : null);
    if(e) {
      if(e.keyCode == 27)              { this.closeAll() } // <Esc>
      if(e.keyCode == 88 && e.ctrlKey) { this.closeAll() } // <Ctrl-X>
      if(e.keyCode == 37)              { this.enPrev() } // <Left Arrow>
      if(e.keyCode == 39)              { this.enNext() } // <Right Arrow>
    }
  },
  
  pictureLoad:function(Index) {
    var anchor=this.phAnchors[Index]
    this.pictureObj.src=anchor.getAttribute("rel")
    this.pictureObj.setAttribute("alt",anchor.getAttribute("title"))
    this.pictureObj.setAttribute("title",anchor.getAttribute("title"))
    for(var i=0; i<this.phAnchors.length; i++)
      this.phAnchors[i].parentNode.className=this.phdefClassName
    anchor.parentNode.className=this.phselClassName
    this.pictureAnch.href="javascript:void(0)"
    this.pictureAnch.rel=Index
    instance=this
    this.pictureAnch.onclick=function() {
      instance.phSelected=this.getAttribute("rel")
      instance.enShow()
      return false
    }
    this.phSelected=Index
    anchor.blur()
  },
  
  ctSelectSelected:function(Index) {
    for(var i=0; i<this.ctAnchors.length; i++)
      this.ctAnchors[i].parentNode.className=this.ctdefClassName
    this.ctAnchors[Index].parentNode.className=this.ctselClassName
    this.ctSelected=Index
  },
  
  phLoadMiniatures:function(Index) {
    this.phObj.innerHTML="<img src='"+this.enLoadingImgHref+"' />";
    if(window.XMLHttpRequest)
      this.xmlhttp=new XMLHttpRequest()
    else
      this.xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
    var instance=this
    this.xmlhttp.onreadystatechange=function() {
      if(instance.xmlhttp.readyState==4 && instance.xmlhttp.status==200) {
        instance.phObj.innerHTML=instance.xmlhttp.responseText
        instance.phAnchors=instance.phObj.getElementsByTagName("a")
        for(var i=0;i<instance.phAnchors.length;i++) {
          instance.phAnchors[i].Index=i
          if(i==0)
            instance.pictureLoad(instance.phAnchors[i].Index) // dodane .Index
          instance.phAnchors[i].href="javascript:void(0)"
          instance.phAnchors[i].onclick=function() {
            instance.pictureLoad(this.Index) // dodane .Index
            return false
          }
        }
        // executing loaded scripts
        var scripts=instance.phObj.getElementsByTagName("script");
        for(var i=0;i<scripts.length;i++) {
           eval(scripts[i].text)
        }
      }
    }
    this.xmlhttp.open("GET",this.ctRels[Index],true)
    this.xmlhttp.send()   
  },  
  
  ctChange:function(Index) {
    this.ctSelectSelected(Index)
    this.phLoadMiniatures(Index)
  },
  
  // enlarged photo
  // background fading
  enFade:function() {
    this.enDegree+=10
    with(this.enBkgObj.style) {
      opacity=(this.enDegree/100.0)
      MozOpacity=(this.enDegree/100.0)
      KhtmlOpacity=(this.enDegree/100.0)
      filter="alpha(opacity="+this.enDegree+")"
    }
    if(this.enDegree >= 70) {
      clearTimeout(this.enTimerId)
      this.enSetWindow()
    }
    else {
      var _self = this;
      this.enTimerId = setTimeout(function() { _self.enFade() }, this.enInterval)
    }
  },

  // resizing main data window (this.enBoxObj)
  // and moving navigation elements
  enResize:function() {
    var wt=0; var ht=1
    var ScreenSize=getScreenSize()

    // retriving current size
    currWidth=parseInt(window.getComputedStyle(this.enBoxObj,null).getPropertyValue("width"))
    currHeight=parseInt(window.getComputedStyle(this.enBoxObj,null).getPropertyValue("height"))
    
    // calculating step value, geometric progression
    var step=1
    var ratio=4
    if(currWidth<this.enBoxObj.goalWidth) {
      step=parseInt((this.enBoxObj.goalWidth-currWidth)/ratio)
      if(step==0) { step=1 }
      this.enBoxObj.style.width=currWidth+step+'px'
    }
    if(currWidth>this.enBoxObj.goalWidth) {
      step=parseInt((currWidth-this.enBoxObj.goalWidth)/ratio)
      if(step==0) { step=1 }
      this.enBoxObj.style.width=currWidth-step+'px'
    }
    if(currHeight<this.enBoxObj.goalHeight) {
      step=parseInt((this.enBoxObj.goalHeight-currHeight)/ratio)
      if(step==0) { step=1 }
      this.enBoxObj.style.height=currHeight+step+'px'
    }
    if(currHeight>this.enBoxObj.goalHeight) {
      step=parseInt((currHeight-this.enBoxObj.goalHeight)/ratio)
      if(step==0) { step=1 }
      this.enBoxObj.style.height=currHeight-step+'px'
    }

    // retriving size after resizing
    currWidth=parseInt(window.getComputedStyle(this.enBoxObj,null).getPropertyValue("width"))
    currHeight=parseInt(window.getComputedStyle(this.enBoxObj,null).getPropertyValue("height"))

    // calculating top left corner position
    var arrayPageScroll = document.viewport.getScrollOffsets();
    var boxTop = arrayPageScroll[1]
    var boxLeft = arrayPageScroll[0]
    
    with(this.enBoxObj.style) {
      top=(document.viewport.getHeight()/2)-(currHeight/2)+boxTop+'px'
      left=(ScreenSize[wt]/2)-(currWidth/2)+boxLeft+'px'
    }

    // calculating new positions for navigation elements  
    with(this.enTitleBarObj.style) {
      top=enContentObjMarginTop+'px'
      left=currWidth-enTitleBarObjWidth-enContentObjMarginRight-1+'px' // 1=border-left-width of enTitleBarObj
    }

    with(this.enLeftBtnObj.style) {
      top=currHeight/2-enCaptionObjHeight/2+'px'
      left=enContentObjMarginLeft+'px'
    }

    with(this.enRightBtnObj.style) {
      top=currHeight/2-enCaptionObjHeight/2+'px'
      left=currWidth-enRightBtnObjWidth-enContentObjMarginRight-1+'px' // 1=border-left-width of enRightBtnObj
    }
    
    with(this.enLoadingImgObj.style) {
      top=currHeight/2-this.enLoadingImgObj.height-enCaptionObjHeight/2+'px'
      left=currWidth/2-this.enLoadingImgObj.width+'px'
    }
    
    with(this.enContentObj.style) {
      if(currHeight-enImgObjPaddingTop-enImgObjPaddingBottom-enCaptionObjHeight-enContentObjMarginTop > 0)
        height=currHeight-enImgObjPaddingTop-enImgObjPaddingBottom-enCaptionObjHeight-enContentObjMarginTop+'px' // 2=margin-top + margin-bottom of enContentObj
    }  
  
    var _self = this;
    if((currWidth==this.enBoxObj.goalWidth) &&
       (currHeight==this.enBoxObj.goalHeight)) {
      clearTimeout(this.enTimerId)
      with(this.enLoadingImgObj.style) {
        display="none"
      }
      with(this.enImgObj.style) {
        display="block"
        top=(currHeight-this.enImgObj.height-enCaptionObjHeight)/2+'px'
        left=(currWidth-this.enImgObj.width)/2+'px'
      }
      document.onkeyup=function(e) {
        _self.enBoxObjOnKeyUp(e)
      }
    }
    else {
      this.enTimerId = setTimeout(function() { _self.enResize() }, this.enInterval)
    }    
  },
  
  resizeImageContainer:function(imgWidth,imgHeight) {
    var wt=0; var ht=1
    var ScreenSize=getScreenSize()
    this.enBoxObj.goalWidth=imgWidth+enImgObjPaddingLeft+enImgObjPaddingRight+enContentObjMarginLeft+enContentObjMarginRight
    if(this.enBoxObj.goalWidth < 600)
      this.enBoxObj.goalWidth = 600
    this.enBoxObj.goalHeight=imgHeight+enImgObjPaddingTop+enImgObjPaddingBottom+enCaptionObjHeight+enContentObjMarginTop+enContentObjMarginBottom
    if(this.enBoxObj.goalHeight < 400)
      this.enBoxObj.goalHeight = 400
    this.enBoxObj.goalTop=(ScreenSize[ht]/2)-(this.enBoxObj.goalHeight/2)
    this.enBoxObj.goalLeft=(ScreenSize[wt]/2)-(this.enBoxObj.goalWidth/2)
    with(this.enBoxObj.style) {
      zIndex=2
      display="block"
    }
    var _self = this;
    this.enTimerId = setTimeout(function() { _self.enResize() }, this.enInterval)    
  },
  
  enSetCaption:function() {
    var anchor=this.phAnchors[this.phSelected]
    this.enCaptionObj.innerHTML="<p>"+anchor.getAttribute("title")+"</p>"
  },
  
  enShow:function() {
    this.enSetCaption()
    var wt=0; var ht=1
    var ScreenSize=getScreenSize()
    var arrayPageScroll = document.viewport.getScrollOffsets();
    var boxTop = arrayPageScroll[1]
    var boxLeft = arrayPageScroll[0]
    with(this.enBkgObj.style) {
      position="absolute"
      top=boxTop+'px'
      left=boxLeft+'px'
      width=ScreenSize[wt]+'px'
      height=ScreenSize[ht]+'px'
      zIndex=1
      opacity=0
      MozOpacity=0
      KhtmlOpacity=0
      filter="alpha(opacity=0)"
      display="block"
    }
    var _self = this;
    this.enBkgObj.onclick=function() { _self.closeAll() }
    this.enDegree=0
    this.enTimerId = setTimeout(function() { _self.enFade() }, this.enInterval)
  },
  
  enSetWindow:function() {
    this.imgPreloader=new Image()
    _self=this
    this.imgPreloader.onload=function() {
      _self.enImgObj.src=this.src
      with(_self.enImgObj.style) {
        width=this.width+'px'
        height=this.height+'px'
        display="none"
      }
      with(_self.enLoadingImgObj.style) {
        display="block"
      }
      _self.resizeImageContainer(this.width,this.height)
    }
    this.imgPreloader.onerror=function() { _self.closeAll() }
    this.imgPreloader.src=this.phAnchors[this.phSelected].getAttribute("name")
  },

  enShowBtns:function() {
    if(this.phSelected>0)
      this.enLeftBtnObj.style.display="block"
    if(this.phSelected<(this.phAnchors.length-1))
      this.enRightBtnObj.style.display="block"
  },
  
  enHideBtns:function() {
    this.enLeftBtnObj.style.display="none"
    this.enRightBtnObj.style.display="none"
  },

  enPrev:function() {
    if(this.phSelected>0) {
      this.phSelected--
      this.enSetCaption()
      this.enSetWindow()
    }  
  },

  enNext:function() {
    if(this.phSelected<(this.phAnchors.length-1)) {
      this.phSelected++
      this.enSetCaption()
      this.enSetWindow()
    }
  },
  
  closeAll:function() {
    document.onkeyup=null
    this.enBoxObj.style.display="none"
    this.enBkgObj.style.display="none"
  },
  
  init:function() {
    this.ctSelectSelected(this.ctSelected)
    this.phLoadMiniatures(this.ctSelected)
  }
}

// end of product pictures

// balloons

function balloon(containerId, className, shadowImg, loadingImgHref) {
  var _self=this
  this.className=className
  this.anchorsArr=new Array()
  this.activeId=null
  this.timeoutId=null
  this.timeoutInterval=500
  this.loadingImgHref=loadingImgHref
  this.containerId=containerId
  this.containerObj=document.createElement("div")
  with(this.containerObj) {
    setAttribute("id",containerId)
  }
  this.contentOuterObj=document.createElement("div")
  with(this.contentOuterObj) {
    setAttribute("id",containerId+'-content')
	onmouseover=function() {
      if(_self.timeoutId!=null) { clearTimeout(_self.timeoutId) }
	  return false
	}
	onmouseout=function() {
      if(_self.timeoutId!=null) { clearTimeout(_self.timeoutId) }
	  _self.timeoutId=setTimeout(function() { _self.hideBalloon() }, _self.timeoutInterval)
	  return false
	}
  }
  this.contentObj=document.createElement("div")
  this.contentOuterObj.appendChild(this.contentObj) 
  this.containerObj.appendChild(this.contentOuterObj) 
  document.body.appendChild(this.containerObj)
  this.shadowObj=document.createElement("img")
  with(this.shadowObj) {
    setAttribute("id",containerId+'-shadow')
    src=shadowImg
  }
  document.body.appendChild(this.shadowObj)
}

balloon.prototype={
  showBalloon:function(anchor) {
    if((anchor.getAttribute("rel")==this.activeId) &&
       ($(this.containerId).getStyle("display")=="block")) { return }
    var _self=this
    var _anchor=anchor
    var regexp=""
  	var Pos=findPos(anchor)
    var balloonLeft=Pos[1]
	with(this.containerObj) {
	  style.left=balloonLeft+'px'
	  style.display="block"
	}
	var balloonHeight=parseInt($(this.containerId).getStyle("height"))
    var balloonTop=Pos[0]-balloonHeight
	with(this.containerObj) {
	  style.top=balloonTop+'px'
    }
	with(this.shadowObj) {
	  style.top=balloonTop+'px'
	  style.left=balloonLeft+'px'
	  style.display="block"
	}
    if(anchor.Content!=undefined) {
      this.contentObj.innerHTML=anchor.Content
      this.activeId=anchor.getAttribute("rel")
      return
    }
    this.contentObj.innerHTML="<img src='"+this.loadingImgHref+"' />";
    // loading content with Ajax
    if(window.XMLHttpRequest)
      this.xmlhttp=new XMLHttpRequest()
    else
      this.xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
    this.xmlhttp.onreadystatechange=function() {
      if(_self.xmlhttp.readyState==4) {
        if(_self.xmlhttp.status==200) {
          _self.contentObj.innerHTML=_self.xmlhttp.responseText
          _anchor.Content=_self.xmlhttp.responseText
          // executing loaded scripts
          var scripts=_self.contentObj.getElementsByTagName("script");
          for(var i=0;i<scripts.length;i++) { eval(scripts[i].text) }
        }
        regexp=/^4/;
        if(regexp.exec(_self.xmlhttp.status)) {
          _self.contentObj.innerHTML="<p>HTTP Error: "+_self.xmlhttp.status+"</p>"
        }
        regexp=/^5/;
        if(regexp.exec(_self.xmlhttp.status)) {
          _self.contentObj.innerHTML="<p>HTTP Error: "+_self.xmlhttp.status+"</p>"
        }
      }
    }
    this.xmlhttp.open("GET","/bin/getfeature.cgi?id="+anchor.getAttribute("rel"),true)
    this.xmlhttp.send()
    this.activeId=anchor.getAttribute("rel")
  },
  
  hideBalloon:function() {
    if(this.timeoutId!=null) { clearTimeout(this.timeoutId) }
	with(this.containerObj) {
	  style.display="none"
	}	
	with(this.shadowObj) {
	  style.display="none"
	}	
  },
  
  refresh:function() { 
  	var _self=this
    var anchors=document.body.getElementsByTagName("a")
    for(var i=0;i<anchors.length;i++) {
	  if(anchors[i].className==this.className) {
	    anchors[i].setAttribute("href", "javascript:void(0)")
		anchors[i].onmouseover=function() {
		  _self.showBalloon(this)
          if(_self.timeoutId!=null) { clearTimeout(_self.timeoutId) }
		  return false
		}
		anchors[i].onmouseout=function() {
          if(_self.timeoutId!=null) { clearTimeout(_self.timeoutId) }
		  _self.timeoutId=setTimeout(function() { _self.hideBalloon() }, _self.timeoutInterval)
		  return false
		}
	    this.anchorsArr.push(anchors[i].className)
	  }
	}
  }
}					 

// end of balloons

// ajaxgetdata

function ajaxgetdata(containerId,loadingImgHref) {
  this.containerId=containerId
  this.containerObj=document.getElementById(this.containerId)
  this.loadingImgHref=loadingImgHref
  this.timeoutId=null
  this.timeoutInterval=0
  this.script=""
  this.id=""
  this.site=""
  this.lg=""
  this.p1=""
  this.p2=""
  this.p3=""
  this.p4=""
  this.of=""
  this.li=""
  this.s1=""
  this.s2=""
  this.s3=""
  this.s4=""
  this.s5=""
  this.s6=""
}

ajaxgetdata.prototype={
  reload:function() {
    var _self=this
    var regexp=""
    this.containerObj.innerHTML="<img src='"+this.loadingImgHref+"' alt='loading data...' />"
    if(window.XMLHttpRequest)
      this.xmlhttp=new XMLHttpRequest()
    else
      this.xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
    this.xmlhttp.onreadystatechange=function() {
      if(_self.xmlhttp.readyState==4) {
        if(_self.xmlhttp.status==200) {
          _self.containerObj.innerHTML=_self.xmlhttp.responseText
          if(_self.containerObj.innerHTML == "")
            _self.containerObj.style.display="none"
          else
            _self.containerObj.style.display="block"
          // executing loaded scripts
          var scripts=_self.containerObj.getElementsByTagName("script");
          for(var i=0;i<scripts.length;i++) { eval(scripts[i].text) }
          // creating timeout event for reloading
          if(_self.timeoutInterval > 0)
            _self.timeoutId=setTimeout(function() { _self.reload() }, _self.timeoutInterval)
        }
        regexp=/^4/;
        if(regexp.exec(_self.xmlhttp.status)) {
          _self.containerObj.innerHTML="<p>HTTP Error: "+_self.xmlhttp.status+"</p>"
        }
        regexp=/^5/;
        if(regexp.exec(_self.xmlhttp.status)) {
          _self.containerObj.innerHTML="<p>HTTP Error: "+_self.xmlhttp.status+"</p>"
        }
      }
    }
    this.xmlhttp.open(
      "GET",
      this.script+"?cid="+this.containerId+"&id="+this.id+"&site="+this.site+"&lg="+this.lg+"&p1="+this.p1+"&p2="+this.p2+"&p3="+this.p3+"&p4="+this.p4+"&of="+this.of+"&li="+this.li+"&s1="+this.s1+"&s2="+this.s2+"&s3="+this.s3+"&s4="+this.s4+"&s5="+this.s5+"&s6="+this.s6,
      true
    )
    this.xmlhttp.send()
  }
}

// end of home page random products

// product filter

function prfilter(containerId,filterId,loadingImgHref) {
  this.containerId=containerId
  this.containerObj=document.getElementById(this.containerId)
  this.filterId=filterId
  this.filterObj=document.getElementById(this.filterId)
  this.loadingImgHref=loadingImgHref
  this.script=""
  this.id=""
  this.site=""
  this.lg=""
  this.p1=""
  this.p2=""
  this.p3=""
  this.p4=""
  this.of=0
  this.li=0
  this.s1=""
  this.s2=""
  // setting events on filter inputs
  if(this.filterObj != null) {
    var _self=this
    var CheckBoxesArr=this.filterObj.getElementsByTagName("input")
    for(var i=0;i<CheckBoxesArr.length;i++) {
      if(CheckBoxesArr[i].getAttribute("type")=="checkbox") {
        CheckBoxesArr[i].checked=getCookie(CheckBoxesArr[i].name)=="true"
        CheckBoxesArr[i].onclick=function() { _self.onclick(this) }
      }
    }
  }
}

prfilter.prototype={
  // (re)loading product list
  filter:function() {
    var _self=this
    var regexp=""
    this.containerObj.innerHTML="<img src='"+this.loadingImgHref+"' alt='loading data...' />"
    if(window.XMLHttpRequest)
      this.xmlhttp=new XMLHttpRequest()
    else
      this.xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
    this.xmlhttp.onreadystatechange=function() {
      if(_self.xmlhttp.readyState==4) {
        if(_self.xmlhttp.status==200) {
          _self.containerObj.innerHTML=_self.xmlhttp.responseText
          // executing loaded scripts
          var scripts=_self.containerObj.getElementsByTagName("script");
          for(var i=0;i<scripts.length;i++) { eval(scripts[i].text) }
        }
        regexp=/^4/;
        if(regexp.exec(_self.xmlhttp.status)) {
          _self.containerObj.innerHTML="<p>HTTP Error: "+_self.xmlhttp.status+"</p>"
        }
        regexp=/^5/;
        if(regexp.exec(_self.xmlhttp.status)) {
          _self.containerObj.innerHTML="<p>HTTP Error: "+_self.xmlhttp.status+"</p>"
        }
      }
    }
    this.xmlhttp.open("GET",this.script+
      "?cid="+this.containerId+
      "&id="+this.id+
      "&site="+this.site+
      "&lg="+this.lg+
      "&p1="+this.p1+
      "&p2="+this.p2+
      "&p3="+this.p3+
      "&p4="+this.p4+
      "&of="+this.of+
      "&li="+this.li+
      "&s1="+this.s1+
      "&s2="+this.s2,
      true)
    this.xmlhttp.send()
  },
  
  onclick:function(checkbox) {
    setCookie(checkbox.name,checkbox.checked)
    this.of=0
    this.filter()
  }
  
}

// end of product filter

// products comaprison

getCookie=function(Name){ 
  var re=new RegExp(Name+"=[^;]+", "i");
  if (document.cookie.match(re))
    return document.cookie.match(re)[0].split("=")[1]
  return ""
}

setCookie=function(name, value){
  document.cookie = name+"="+value+";path=/"
}

function prcomparer(containerId,loadingImgHref,btnCompareTopId,btnCompareBottomId,imgCompareOff,imgCompareOn,aCompareTopId,aCompareBottomId) {
  this.containerId=containerId
  this.containerObj=document.getElementById(this.containerId)
  this.loadingImgHref=loadingImgHref
  this.btnCompareTopId=btnCompareTopId
  this.btnCompareBottomId=btnCompareBottomId
  this.btnCompareTopObj=document.getElementById(this.btnCompareTopId)
  this.btnCompareBottomObj=document.getElementById(this.btnCompareBottomId)
  this.imgCompareOffObj=new Image()
  this.imgCompareOnObj=new Image()
  this.imgCompareOffObj.src=imgCompareOff
  this.imgCompareOnObj.src=imgCompareOn
  this.aCompareTopId=aCompareTopId
  this.aCompareBottomId=aCompareBottomId
  this.aCompareTopObj=document.getElementById(this.aCompareTopId)
  this.aCompareBottomObj=document.getElementById(this.aCompareBottomId)
  this.lg=""
  this.site=""
  this.p1=""
  this.p2=""
  this.p3=""
  this.p4=""
}

prcomparer.prototype={
  init:function() {
    var _self=this
    var CheckBoxesArr=this.containerObj.getElementsByTagName("input")
    for(var i=0;i<CheckBoxesArr.length;i++) {
      if(CheckBoxesArr[i].getAttribute("type")=="checkbox") {
        CheckBoxesArr[i].checked=getCookie(CheckBoxesArr[i].name)=="true"
        CheckBoxesArr[i].onclick=function() { _self.onclick(this) }
      }
    }
    this.setCompareBtnState()
  },
  
  onclick:function(checkbox) {
    setCookie(checkbox.name,checkbox.checked)
    this.setCompareBtnState()
  },
  
  setCompareBtnState:function() {
    var re=new RegExp("compare,"+this.lg+","+this.site+","+this.p1+","+this.p2+","+this.p3+","+this.p4+",[0-9]+=true", "g")
    var results=document.cookie.match(re)
    if(results && (results.length>1)) {
      this.btnCompareTopObj.src=this.imgCompareOnObj.src
      this.btnCompareBottomObj.src=this.imgCompareOnObj.src
      this.aCompareTopObj.href="/_compare/"+this.lg+","+this.site+","+this.p1+","+this.p2+","+this.p3+","+this.p4
      this.aCompareBottomObj.href=this.aCompareTopObj.href
    }
    else {
      this.btnCompareTopObj.src=this.imgCompareOffObj.src
      this.btnCompareBottomObj.src=this.imgCompareOffObj.src
      this.aCompareTopObj.href="javascript:void(0);"
      this.aCompareBottomObj.href="javascript:void(0);"
    }
  }
}

// Compare Manager

function cmpman(prlistId,prboxprefId,showdiffId,prevtopId,nexttopId,prevbottomId,nextbottomId,msgShowDiffs,msgShowAll) {
  var _self=this
  this.prlistId=prlistId
  this.prlistObj=document.getElementById(prlistId)
  this.prinputObjArr=this.prlistObj.getElementsByTagName("input")
  this.prboxObjArr=new Array(this.prinputObjArr.length)
  for(var i=0; i<this.prinputObjArr.length; i++) {
    var _name=this.prinputObjArr[i].name
    this.prboxObjArr[i]=document.getElementById(prboxprefId+_name)
    this.prinputObjArr[i].onclick=function() { _self.onclickprbox(this); this.blur() }
    var _removeAnch=document.getElementById(prboxprefId+"-remove"+_name)
    if(_removeAnch != null) {
      _removeAnch.setAttribute("name",i)
      _removeAnch.onclick=function() { _self.hideBox(this) }
    }
  }
  this.showdiffObj=document.getElementById(showdiffId)
  this.showdiffObj.onclick=function() { _self.onclickDifferences(); this.blur() }
  this.prevtopObj=document.getElementById(prevtopId)
  this.prevtopImgObj=this.prevtopObj.childNodes[0]
  this.prevtopAnchObj=this.prevtopObj.childNodes[1]
  this.nexttopObj=document.getElementById(nexttopId)
  this.nexttopImgObj=this.nexttopObj.childNodes[0]
  this.nexttopAnchObj=this.nexttopObj.childNodes[1]
  this.prevbottomObj=document.getElementById(prevbottomId)
  this.prevbottomImgObj=this.prevbottomObj.childNodes[0]
  this.prevbottomAnchObj=this.prevbottomObj.childNodes[1]
  this.nextbottomObj=document.getElementById(nextbottomId)
  this.nextbottomImgObj=this.nextbottomObj.childNodes[0]
  this.nextbottomAnchObj=this.nextbottomObj.childNodes[1]
  // table
  this.tablesObjArr=new Array()
  var _tables=document.getElementsByTagName("table")
  var count=0
  for(var i=0; i<_tables.length; i++) {
    _tables[i].className
    if((_tables[i].className=="compare-table-product") ||
       (_tables[i].className=="compare-table-section")) {
      this.tablesObjArr[count]=_tables[i]
      count++;
    }
  }
  this.msgShowDiffs=msgShowDiffs
  this.msgShowAll=msgShowAll
  this.maxBoxes=4
  this.shift=0
  this.diffsOn=false
}

cmpman.prototype={
  init:function() {
    this.showBoxes()    
  },
  
  selectVisibleProducts:function() {
    for(var i=0; i<this.prinputObjArr.length; i++)
      if(this.prboxObjArr[i].style.display=="block")
        document.getElementById(this.prlistId+i).style.fontWeight="bold"
      else
        document.getElementById(this.prlistId+i).style.fontWeight=""
  },
  
  onclickprbox:function(checkbox) {
    var visible=0
    var clicked=0
    for(var i=0; i<this.prinputObjArr.length; i++) {
      if(this.prboxObjArr[i].style.display=="block")
        visible++
      if(this.prinputObjArr[i].getAttribute('name')==checkbox.getAttribute('name'))
        clicked=i
    }
    if(clicked>=this.shift+visible) { }
    else
      if((! checkbox.checked) && (clicked<this.shift) && (visible=4)) { this.shift-- }
      else { this.shift=0 }

    this.showBoxes()
  },
  
  deactivatePrev:function() {
    this.prevtopImgObj.src="/img/compare-off-btn.png"
    this.prevtopAnchObj.onclick=function() { this.blur(); return false }
    this.prevbottomImgObj.src="/img/compare-off-btn.png"
    this.prevbottomAnchObj.onclick=function() { this.blur(); return false }
  },
  
  activatePrev:function() {
    var _self=this
    this.prevtopImgObj.src="/img/compare-on-btn.png"
    this.prevtopAnchObj.onclick=function() { _self.onclickPrev(); this.blur(); return false }
    this.prevbottomImgObj.src="/img/compare-on-btn.png"
    this.prevbottomAnchObj.onclick=function() { _self.onclickPrev(); this.blur(); return false }
  },
  
  onclickPrev:function() {
    this.shift--
    this.showBoxes()
  },

  deactivateNext:function() {
    this.nexttopImgObj.src="/img/compare-off-btn.png"
    this.nexttopAnchObj.onclick=function() { this.blur(); return false }
    this.nextbottomImgObj.src="/img/compare-off-btn.png"
    this.nextbottomAnchObj.onclick=function() { this.blur(); return false }
  },
  
  activateNext:function() {
    var _self=this
    this.nexttopImgObj.src="/img/compare-on-btn.png"
    this.nexttopAnchObj.onclick=function() { _self.onclickNext(); this.blur(); return false }
    this.nextbottomImgObj.src="/img/compare-on-btn.png"
    this.nextbottomAnchObj.onclick=function() { _self.onclickNext(); this.blur(); return false }
  },
  
  onclickNext:function() {
    this.shift++
    this.showBoxes()
  },
  
  hideBoxes:function() {
    // hidding all boxes and columns
    for(var i=0; i<this.prboxObjArr.length; i++) {
      // box
      this.prboxObjArr[i].style.display="none"
      // column
      for(var j=0; j<this.tablesObjArr.length; j++) {
        // th
        var cellArr=new Array()
        cellArr=this.tablesObjArr[j].getElementsByTagName("th")
        for(var k=0; k<cellArr.length; k++) {
          if(cellArr[k].getAttribute("name")==i) {
            this.hideCell(cellArr[k])
          }
        }
        // td
        var cellArr=new Array()
        cellArr=this.tablesObjArr[j].getElementsByTagName("td")
        for(var k=0; k<cellArr.length; k++) {
          if(cellArr[k].getAttribute("name")==i) {
            this.hideCell(cellArr[k])
          }
        }
      }
    }
  },

  hideBox:function(name) {
    // alert(name.getAttribute("name"))
    this.prinputObjArr[name.getAttribute("name")].checked=false
    this.shift=0
    this.showBoxes()
  },
  
  showTHead:function(thead) {
    if(navigator.appName=="Microsoft Internet Explorer")
      thead.style.display="block"
    else
      thead.style.display="table-header-group"
  },
  
  showCell:function(cell) {
    if(navigator.appName=="Microsoft Internet Explorer")
      cell.style.display="block"
    else
      cell.style.display="table-cell"
  },
  
  hideCell:function(cell) {
    cell.style.display="none"
  },

  showBoxes:function() {
    // showing selected boxes and columns
    this.hideBoxes()
    var checked=0
    this.deactivatePrev()
    this.deactivateNext()
    for(var i=0; i<this.prinputObjArr.length; i++) {
      // box
      if(this.prinputObjArr[i].checked) {
        if(checked>=this.shift) {
          if((checked-this.shift)<this.maxBoxes) {
            this.prboxObjArr[i].style.display="block"
            // column
            for(var j=0; j<this.tablesObjArr.length; j++) {
              // th
              var ctsTHeadObj=this.tablesObjArr[j].getElementsByTagName('thead')[0]
              this.showTHead(ctsTHeadObj)
              var cellArr=new Array()
              cellArr=this.tablesObjArr[j].getElementsByTagName("th")
              for(var k=0; k<cellArr.length; k++) {
                if(cellArr[k].getAttribute("name")==i) {
                  this.showCell(cellArr[k])
                }
              }
              // td
              var cellArr=new Array()
              cellArr=this.tablesObjArr[j].getElementsByTagName("td")
              for(var k=0; k<cellArr.length; k++) {
                if(cellArr[k].getAttribute("name")==i) {
                  this.showCell(cellArr[k])
                }
                if(cellArr[k].getAttribute("name")=="caption") {
                  this.showCell(cellArr[k])
                }
              }
            }
          }
          else { this.activateNext() }
        }
        else { this.activatePrev() }
        checked++;
      }
    }
    this.selectVisibleProducts()
    this.showDifferences()
  },

  onclickDifferences:function() {
    this.diffsOn=!this.diffsOn
    if(this.diffsOn)
      this.showdiffObj.innerHTML=this.msgShowAll
    else
      this.showdiffObj.innerHTML=this.msgShowDiffs
    this.showDifferences()
  },
  
  showDifferences:function() {
    var Index=null  
    for(var j=0; j<this.tablesObjArr.length; j++) {
      if(this.tablesObjArr[j].className=="compare-table-product")
        var ctpTableObj=this.tablesObjArr[j]
      if(this.tablesObjArr[j].className=="compare-table-section") {
        var ctsTableObj=this.tablesObjArr[j]     
        var ctsTHeadObj=ctsTableObj.getElementsByTagName('thead')[0]
        var ctsTBodyObj=ctsTableObj.getElementsByTagName('tbody')[0]
        var ctsTRowsArr=ctsTBodyObj.getElementsByTagName('tr')
        var hiddenRows=0
        for(var r=0; r<ctsTRowsArr.length; r++) {
          var ctsTCellsArr=ctsTRowsArr[r].getElementsByTagName('td')
          var visibleCellsArr=new Array()
          var count=0
          var diffs=false
          var prevValue="-^+^-"
          for(var i=0; i<ctsTCellsArr.length; i++) {
            if(i>0) {
              Index=ctsTCellsArr[i].getAttribute('name')
              if(this.prboxObjArr[Index].style.display=="block") {
                currValue=ctsTCellsArr[i].getAttribute('rel')
                if(prevValue!="-^+^-")
                  if(currValue!=prevValue) { diffs=true }
                prevValue=currValue
                visibleCellsArr[count]=ctsTCellsArr[i]
                count++
              }
            }
            else {
              visibleCellsArr[count]=ctsTCellsArr[i]
              count++
            }
          }
          if(!diffs) { hiddenRows++ }
          for(var i=0; i<visibleCellsArr.length; i++) {
            if(this.diffsOn) {
              if(!diffs)
                this.hideCell(visibleCellsArr[i])
            }
            else {
              this.showCell(visibleCellsArr[i])
            }
          }
        }
        if(this.diffsOn) {
          if(hiddenRows==ctsTRowsArr.length) {
            this.hideCell(ctsTHeadObj)
          }
        }
        else {
          this.showTHead(ctsTHeadObj)
        }
      }
    }
  } 
}

// Download search

function downloadsearch(formId) {
  _self=this
  this.formObj=document.getElementById(formId)
  this.groupObj=document.getElementById(formId + "-group")
  this.groupObj.onchange=function() { _self.changegroup(this) }
  this.symbolObj=document.getElementById(formId + "-symbol")
  this.symbolObj.onchange=function() { _self.changesymbol(this) }
  this.dticodeObj=document.getElementById(formId + "-dticode")
  this.dticodeObj.onchange=function() { _self.changedticode(this) }
  this.site="";
  this.lg="";
  this.s1=""
  this.s2=""
  this.s3=""
  this.s4=""
  this.s5=""
  this.s6=""
}

downloadsearch.prototype={
  init:function() { },
  
  changegroup:function(Obj) {
    _self=this
    if(window.XMLHttpRequest)
      this.xmlhttp=new XMLHttpRequest()
    else
      this.xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
    this.xmlhttp.onreadystatechange=function() {
      if(_self.xmlhttp.readyState==4)
        if(_self.xmlhttp.status==200) {
          var otpArr=new Array
          otpArr=_self.xmlhttp.responseText.split(String.fromCharCode(10))
          for(var i=0; i<otpArr.length; i++) {
            valArr=otpArr[i].split("|")
            var optObj=document.createElement('option');
            optObj.value=valArr[0]
            optObj.text=valArr[1]
            try {
              _self.symbolObj.add(optObj, null); // standards compliant; doesn't work in IE
            }
            catch(ex) {
              _self.symbolObj.add(optObj); // IE only
            }
          }
        }
    }
    this.xmlhttp.open("GET","/bin/getoptions.cgi?"+
      "&id="+Obj.value+
      "&lg="+this.lg+
      "&site="+this.site+
      "&form="+this.formObj.name+
      "&select="+Obj.name+
      "&s1="+this.s1+
      "&s2="+this.s2+
      "&s3="+this.s3+
      "&s4="+this.s4+
      "&s5="+this.s5+
      "&s6="+this.s6,
      true)
    this.symbolObj.options.length=0
    this.xmlhttp.send()
  },
  
  changesymbol:function(Obj) {
    // alert(Obj.value)
  },
  
  changedticode:function(Obj) {
    // alert(Obj.value)
  }
}

// Banners

function banner(containerId,loadingImgHref) {
  _self=this
  this.containerObj=document.getElementById(containerId)
  this.loadingImgHref=loadingImgHref
  this.lg=""
  this.p1=""
  this.p2=""
  this.p3=""
  this.p4=""
  this.id=""
  this.script="/bin/banner.cgi"
}

banner.prototype={
  load:function(ICode) {
    var _self=this
    var regexp=""
    // this.containerObj.innerHTML="<img src='"+this.loadingImgHref+"' alt='loading data...' />"
    if(window.XMLHttpRequest)
      this.xmlhttp=new XMLHttpRequest()
    else
      this.xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
    this.xmlhttp.onreadystatechange=function() {
      if(_self.xmlhttp.readyState==4) {
        if(_self.xmlhttp.status==200) {
          _self.containerObj.innerHTML=_self.xmlhttp.responseText
          if(_self.containerObj.innerHTML == "")
            _self.containerObj.style.display="none"
          else
            _self.containerObj.style.display="block"
          // executing loaded scripts
          var scripts=_self.containerObj.getElementsByTagName("script");
          for(var i=0;i<scripts.length;i++) { eval(scripts[i].text) }
          // creating timeout event for reloading
          if(_self.timeoutInterval > 0)
            _self.timeoutId=setTimeout(function() { _self.reload() }, _self.timeoutInterval)
        }
        regexp=/^4/;
        if(regexp.exec(_self.xmlhttp.status)) {
          _self.containerObj.innerHTML="<p>HTTP Error: "+_self.xmlhttp.status+"</p>"
        }
        regexp=/^5/;
        if(regexp.exec(_self.xmlhttp.status)) {
          _self.containerObj.innerHTML="<p>HTTP Error: "+_self.xmlhttp.status+"</p>"
        }
      }
    }
    this.xmlhttp.open(
      "GET",
      this.script+"?icode="+ICode+"&lg="+this.lg+"&p1="+this.p1+"&p2="+this.p2+"&p3="+this.p3+"&p4="+this.p4+"&id="+this.id,
      true
    )
    this.xmlhttp.send()
  }
}

