﻿var mvqTimeout = 125;
var mvqPContent;
var mvqGTlb;
var mvqPDisplayed = false;
var mvqPDiv, mvqPStyle;
var mvqIsIE;
var mvqPTd;
var msvi_qldir="LTR";

if(document.all)
    mvqIsIE = true;
else
    mvqIsIE = false;

function mvqPanel()
{
    if(typeof mvqPContent == "undefined") 
        mvqPContent = GCContentDiv.innerHTML;
    if(!mvqIsIE)mvqPClearHide();
    if(mvqPContent != "" && typeof mvqPContent != "undefined" && mvqPDisplayed == false)
    {
        mvqPSetDisplay(true);
        mvqPDiv = document.getElementById("GoodsClassPanel");
        mvqPStyle = mvqPDiv.style;
        mvqGTlb = document.getElementById("Header");
        mvqPStyle.top = mvqGTlb.offsetTop + mvqGTlb.offsetHeight + "px";
        mvqPDir();
        if(document.body.clientWidth && document.body.clientWidth > 475)
        {
            var re = /([\r\n])/gi;
            mvqPAnimate(true);
            if(msvi_qldir == 'RTL')
                window.setTimeout("mvqPShow('" + mvqPContent.replace(re, " ") + "', " + "125)", mvqTimeout);
            else
                window.setTimeout("mvqPShow('" + mvqPContent.replace(re, " ") + "', " + "-150)", mvqTimeout);
        }
    }
}
function mvqPDir()
{
    if(mvqPDiv && msvi_qldir == "RTL")
    {
        mvqPContent = mvqPContent.replace("dir=\"LTR\"", "dir=\"" + msvi_qldir + "\"");
    }
}
function mvqPSetDisplay(value)
{
    mvqPDisplayed = value;
}

function mvqPAnimate(bOpen)
{
    var animAdj;
   
    if(msvi_qldir == "RTL")
        animAdj = new Array(165, 165, 165);
    else
        animAdj = new Array(-250, -200, -150);

    var animDelay = new Array(50, 75, 100);
    var arr = mvqPGetAnimateArr();
    if(bOpen)
    {
        for(i=0; i<arr.length; i++)
          window.setTimeout("mvqPShow('" + arr[i] + "'," + animAdj[i] + ")", animDelay[i]);
    }
    else
    {
        animDelay = animDelay.reverse();
        for(i=0; i<arr.length; i++)
            window.setTimeout("mvqPShow('" + arr[i] + "'," + animAdj[i] + ")", animDelay[i]);
        window.setTimeout(mvqPReset, mvqTimeout-20);
    }
}

function mvqPReset()
{
    mvqPStyle.visibility = "hidden";
    mvqPStyle.display = "none";
    mvqPSetDisplay(false);
}

function mvqPGetAnimateArr()
{
    var arr = new Array(3);
    var width=0;
    var height=0;
    var wAddLeng=(530-(530%arr.length))/arr.length;
    var hAddLeng=(50-(50%arr.length))/arr.length;
    for(i=0; i<arr.length; i++)
    {
        if(i<arr.length){
            width+=wAddLeng;
            height+=hAddLeng;
        }else{
            width=mvqGCCDiv.style.width;
            height=mvqGCCDiv.style.height;
        }
        arr[i]='<div style=\"width:'+width+'px;height:'+height+'px;border:solid 1px #999999\"></div>';
    }
    return arr;
}

function mvqPShow(mvqPContent, adj)
{
    if(mvqPContent != "undefined")
    {
        if(msvi_qldir == "RTL")
            mvqPStyle.left = mvqGTlb.offsetLeft + adj + "px";
        else
            mvqPStyle.left = mvqGTlb.offsetLeft - adj + "px";
        mvqPDiv.innerHTML = mvqPContent;
        if(mvqPStyle)
        {
            mvqPStyle.visibility = "visible";
            mvqPStyle.display = "";
        }
    }
}

function mvqPHide()
{
    if(mvqPStyle)
    {
        mvqPStyle.visibility = "hidden";
        mvqPStyle.display = "none";
    }
    if(mvqPDisplayed)
    {
        if(document.body.clientWidth && document.body.clientWidth > 475)
        {
            mvqPAnimate(false);
        }
    }
}

function mvqPClearHide()
{
    if (typeof delayHide != "undefined") 
    {
         clearTimeout(delayHide);
    }
}

function mvqPDecideHide(e)
{
    e = (e) ? e : (window.event ? window.event : "");
    if(e)
    {
        if (mvqIsIE && !mvqPTd.contains(e.toElement)) mvqPDelayHide();
        else if (!mvqIsIE && !mvqPCheckParent(e.currentTarget, e.relatedTarget)) mvqPDelayHide();
    }
}

function mvqPDelayHide()
{
    delayHide = setTimeout(mvqPHide, mvqTimeout);
}

function mvqPCheckParent(a, b)
{
    while(b)
    {
        if (b == a) return true;
        b = b.parentNode;
    }
    return false;
}

window.onresize = mvqPDelayHide;
mvqAEvt(window, "load", mvqInit);

function mvqInit()
{
    mvqPTd = document.getElementsByName("IsChildTab")[0];
    if(mvqPTd)
    {
        mvqAEvt(mvqPTd, "mouseover", mvqMOv);
        mvqAEvt(mvqPTd, "mouseout", mvqMOu);
        mvqAEvt(mvqPTd, "keypress", mvqKPr);

        if(mvqIsIE)
        {
            mvqAEvt(mvqPTd, "focus", mvqMOv);
            mvqAEvt(mvqPTd, "focusout", mvqFOu);
        }
        if(!mvqIsIE)
        {
            mvqAEvt(mvqPTd, "focus", mvqMOv);
            mvqAEvt(mvqPTd, "blur", mvqFOu);
        }
    }
}

function mvqAEvt(oName, eName, fName)
{
    if(window.attachEvent) oName.attachEvent("on" + eName, fName);
    if(window.addEventListener) oName.addEventListener(eName, fName, false);
}

function mvqKPr()
{
    var e = (e) ? e : (window.event ? window.event : "");
    if(e)
    {
        if(e.which == 13 && !mvqIsIE || e.keyCode == 13 && mvqIsIE) mvqMOv();
    }
}

function mvqMOv()
{
    if(mvqPTd)
    {
        mvqPanel();
    }
}

function mvqMOu()
{
    if(mvqPTd)
    {
        if(mvqIsIE) mvqPDecideHide();
        if(!mvqIsIE) mvqPTd.onmouseout = mvqPDecideHide;
    }
}

function mvqFOu()
{
    if(mvqPTd)
    {
        if(mvqIsIE) mvqPDecideHide();
        if(!mvqIsIE) mvqPTd.onblur = mvqPDecideHide;
    }
}