var vis,prev,a,aon,cat,bigimg,mywidth,myheight,pic,key=0
/*document.onmouseover=function(e){
   e=e||window.event
   var x=y=z=e.target||e.srcElement
   while(z.parentNode&&z.id!='menu')z=z.parentNode
   if(z.id=='menu'){
      key=1
      if(x.tagName=='A'&&x.parentNode.parentNode.id=='line'){
         while(y&&y.tagName!='UL')y=y.nextSibling
         if(prev){
            vis='hidden'
            show()
         }
         if(a)a.className=''
         if(aon)aon.className=''
         if(x.parentNode.getElementsByTagName('UL').length!=0){
            x.className='on'
            a=x
         }
         if(y&&y.tagName=='UL'){
            prev=y
            vis='visible'
            show()
         }
      }
   }
   else if(key==1){
      key=0
      vis='hidden'
      if(a)a.className=''
      if(aon){
         show()
         vis='visible'
         prev=cat
         show()
         aon.className='on'
      }
      show()
      prev=cat
   }
}*/
document.onclick=function(e){
   e=e||window.event
   var x=e.target||e.srcElement
   if(x.tagName=='A'){
      var y,k,address=''
      if(/article_/.test(x.className)){
         glossary(x.className.replace('article_',''))
         return false
      }
      else if(x.parentNode.parentNode.className=='view'){
         popup(x.parentNode.parentNode.parentNode.getElementsByTagName('IMG')[0])
         return false
      }
      else if(x.parentNode.className=='print'){
         print()
         return false
      }
      else if(y=x.parentNode.getElementsByTagName('INPUT')[0]){
         var z=y.form.getElementsByTagName('INPUT')
         for(i=k=0;z[i];i++){
            if(z[i].checked){
               address+=','+z[i].value
               k++
            }
         }
         if(k>1){
            // var d=location.href.substring(0,location.href.lastIndexOf('/')+1)
	    location.href=y.form.action+'?models='+address.substring(1)
         }
         else alert('Для сравнения необходимо выбрать 2 или более товара')
         return false
      }
   }
   else if(x.tagName=='IMG'){
      if(x.parentNode.className=='view'){
         var img=x.parentNode.parentNode.parentNode.getElementsByTagName('IMG')[0]
         img.src=x.src.replace('\/s_','\/m_')
         img.width=x.getAttribute('xm')
         img.height=x.getAttribute('ym')
         img.setAttribute('x',x.getAttribute('x'))
         img.setAttribute('y',x.getAttribute('y'))
      }
      else if(x.parentNode.className=='pic'){
        if(x.className&&/article_/.test(x.className))glossary(x.className.replace('article_',''))
      }
      else if(x.parentNode.parentNode.className=='desription'||x.parentNode.parentNode.className=='detail')popup(x)
   }
}
function popup(z){
   mywidth=z.getAttribute('x')
   myheight=z.getAttribute('y')
   pic=z
   var width=screen.availWidth
   var height=screen.availHeight
   var props=''
   var left=width<mywidth?0:(width-mywidth)/2
   var top=height<myheight?0:(height-myheight)/2
   props='scrollbars=0,directories=0,menubar=0,status=0,toolbar=0,resizable=0,location=0,left='+left+',top='+top+',height='+myheight+',width='+mywidth
   bigimg=window.open('/products/view.htm','bigimg',props)
   return false
}
/*function insert_img(){
   var newimg=bigimg.document.createElement('IMG')
   src=pic.src.replace('\/m_','\/b_')
   newimg.src=src
   bigimg.document.body.appendChild(newimg)
}*/
function confirm_load(){
   return confirm('Ваш текущий заказ не был сохранён. При загрузке заказа из архива текущее состояние корзины будет утеряно.\r\nВы можете сохранить текущий заказ и после этого загрузить для редактирования сохранённый ранее.\r\n\r\nНажмите [OK] для загрузки заказа или [Отмена] для продолжения работы с текущим.');
}
function glossary(x){
   var url='/glossary/index.html?'+x
   var props=''
   var width=screen.availWidth
   var height=screen.availHeight
   var left=(screen.availWidth-1000)/2
   var top=(screen.availHeight-500)/2
   props='scrollbars=0,directories=0,menubar=0,status=0,toolbar=0,resizable=0,location=0,left='+left+',top='+top+',height=500,width=1000'
   window.open(url,'new_glossary',props)
}
/*function show(){if(prev)prev.className=vis}
function init(){
   var k
   var x=document.getElementById('line').getElementsByTagName('A')
   for(i=0;x[i];i++){
      if(x[i].parentNode.parentNode.id=='line'){
         if(x[i].className=='on')k=a=aon=x[i]
         if(x[i].parentNode.getElementsByTagName('UL').length!=0){
            var y=x[i].parentNode
            var w=x[i].parentNode.getElementsByTagName('UL')[0].getElementsByTagName('LI')
            var z=w[w.length-1]
          

  var f=y.offsetLeft+y.offsetWidth/2
            var g=z.offsetLeft+z.offsetWidth
            if(f+g/2>950)w[0].style.marginLeft=(950-g)+'px'
            else if(f-g/2<0)w[0].style.marginLeft='0'
            else w[0].style.marginLeft=(f-g/2)+'px'

         }
      }
   }
   while(k&&k.tagName!='UL')k=k.nextSibling
   if(k&&k.tagName=='UL'){
      key=0
      prev=cat=k
      vis='visible'
      show()
   }
}*/
