﻿function showDiv(div, menu) {
    try {
        var obj = document.getElementById(div);
        var obj1 = document.getElementById(menu);
        obj.style.left = obj1.getBoundingClientRect().left;
        obj.style.top = obj1.getBoundingClientRect().top + 22;
        obj.style.display = "";
    }
    catch (e) { }
}

function hiddenDiv(div) {
    try {
        var obj = document.getElementById(div);
        obj.style.display = "none";
    }
    catch (e) { }
}

var DDSPEED = 2;
var DDTIMER = 20;
// 处理鼠标动作的主函数 //
function ddMenu(menuid, smenuid, d) {
    try {
        var h = document.getElementById(menuid);
        var c = document.getElementById(smenuid);

        clearInterval(c.timer);
        if (d == 1) {
            clearTimeout(h.timer);
            if (c.maxh && c.maxh <= c.offsetHeight) { return }
            else if (!c.maxh) {
            //debugger
                c.style.display = 'block';
                c.style.height = 'auto';
                c.maxh = c.offsetHeight;
                c.style.height = '0px';
                c.style.left = h.offsetLeft + 120;
                c.style.top = h.offsetTop + 110;
                
//                c.style.left = document.getElementById(menuid).getBoundingClientRect().left;
//                c.style.top = document.getElementById(menuid).getBoundingClientRect().top + 22;
            }
            c.timer = setInterval(function() { ddSlide(c, 1) }, DDTIMER);
        } else {
            h.timer = setTimeout(function() { ddCollapse(c) }, 50);
        }
    }
    catch (e) { }
}

// 回缩菜单 //
function ddCollapse(c) {
    c.timer = setInterval(function() { ddSlide(c, -1) }, DDTIMER);
}

// 如果有用户将鼠标放置在菜单上则取消回溯 //
function cancelHide(menuid, smenuid) {
    var h = document.getElementById(menuid);
    var c = document.getElementById(smenuid);
    clearTimeout(h.timer);
    clearInterval(c.timer);
    if (c.offsetHeight < c.maxh) {
        c.timer = setInterval(function() { ddSlide(c, 1) }, DDTIMER);
    }
}

// 展开/回缩菜单，并设置透明度 //
function ddSlide(c, d) {
    var currh = c.offsetHeight;
    var dist;
    if (d == 1) {
        dist = (Math.round((c.maxh - currh) / DDSPEED));
    } else {
        dist = (Math.round(currh / DDSPEED));
    }
    if (dist <= 1 && d == 1) {
        dist = 1;
    }
    c.style.height = currh + (dist * d) + 'px';
    c.style.opacity = currh / c.maxh;
    c.style.filter = 'alpha(opacity=' + (currh * 100 / c.maxh) + ')';
    if ((currh < 2 && d != 1) || (currh > (c.maxh - 2) && d == 1)) {
        clearInterval(c.timer);
    }
}

function showHideLayers() {
  var i,p,v,obj,args=showHideLayers.arguments,dxSoft,dxSofttimer;
  for (i=0; i<(args.length-2); i+=3) if ((obj=findObj(args[i]))!=null) 
  { v=args[i+2];
	 if (obj.style) 
    { 
		dxSoft=obj; 
		obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; 
		}
			clearTimeout(dxSofttimer);
			dxSofttimer=setTimeout(function(){obj.visibility=v;},300)
			dxSoft.onmouseover=function(){clearTimeout(dxSofttimer);
		}
			dxSoft.onmouseout=function(){showHideLayers(this.id,'','hide')
		}
    }
}

function findObj(n, d) { 
  var p,i,x;  
  if(!d) 
	d=document; 
  if((p=n.indexOf("?"))>0&&parent.frames.length) 
  {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
   }
  if(!(x=d[n])&&d.all) 
	x=d.all[n]; 
  for (i=0;!x&&i<d.forms.length;i++) 
	x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++)	
	x=findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n);
   return x;
}