

    function changeDiv(the_div, the_change) {
        document.getElementById(the_div).style.visibility = the_change;
    }
    
    function hideDiv(the_div, the_change) {
        try {
            document.getElementById(the_div).style.visibility = the_change;
        } catch (e) {
            
        }
    }
    
    function showSubMenu(the_div, caller_div, leftPost, the_change, level) 
    {
        //checking ajax load
        if(!checkSubMenuLoaded(caller_div))
        {
            AJAX_menuLoad(the_div, caller_div, leftPost, the_change, level);
            the_div = showSubMenuLoadingStatus(caller_div);
        }
        
        var callerLeft = leftPost;
        var callerWidth = getElementWidth(caller_div);
        var callerTop = getElementTop(caller_div);
        var menuHeight = getElementHeight(the_div);
        var menuLeft = getObjectLeft(caller_div);
        var menuTop = getObjectTop(caller_div);
        var menuWidth = getElementWidth(the_div);
        
    	if (window.innerHeight)
    	{
            var yScrollPos = window.pageYOffset;
    	}
    	else if (document.documentElement && document.documentElement.scrollTop)
    	{
    		var yScrollPos = document.documentElement.scrollTop;
    	}
    	else if (document.body)
    	{
            var yScrollPos = document.body.scrollTop;
    	}

        if (menuTop+menuHeight < screenHeightLimit)
            document.getElementById(the_div).style.top = callerTop - 2;
        else
        {
            if (menuTop+menuHeight < screenHeightLimit+yScrollPos)
                document.getElementById(the_div).style.top = callerTop - 20;
            else
                document.getElementById(the_div).style.top = (callerTop - menuHeight) - (menuTop - screenHeightLimit) - 20 + yScrollPos;
        }

        if (menuLeft+menuWidth+callerWidth < screenWidthLimit)
        {
            document.getElementById(the_div).style.left = callerLeft + callerWidth - 1;
        }
        else
        {
            var hehe = menuWidth - menuLeft;
            if (ie)
            {
                if(hehe > 0)
                {
                    document.getElementById(the_div).style.left = callerLeft - menuWidth + hehe;
                    document.getElementById(the_div).style.top = parseFloat(document.getElementById(the_div).style.top) + 40;  //move menu down
                }
                else
                    document.getElementById(the_div).style.left = callerLeft - menuWidth;
            }
            else
            {
                if(hehe + 8 > 0)
                {
                    document.getElementById(the_div).style.left = callerLeft + 8 - menuWidth + hehe;
                    document.getElementById(the_div).style.top = parseFloat(document.getElementById(the_div).style.top) + 40; //move menu down
                }
                else
                    document.getElementById(the_div).style.left = callerLeft + 8 - menuWidth;
            }
            
        }
        
        document.getElementById(the_div).style.visibility = the_change;

        currentlyShowingDIV[level] = the_div;
        
        try
        {
            var tempArray = the_div.split('_');
            document.getElementById('shadow_'+tempArray[1]).style.height = menuHeight - 4;
        }
        catch(e) {}
        
        //console.debug("caller_div:"+caller_div+" current show div["+level+"]:"+currentlyShowingDIV[level]);

    }
    
    function setActiveMenuColor(caller_div, level, menuDIV) {
        try {
            document.getElementById(currentPosition[level]).style.backgroundColor = document.getElementById(currentPosition[level]).oldColor; 
        } catch (e) {
        
        }

            //document.getElementById(currentPosition[level]).style.backgroundColor = "transparent";

        currentPosition[level] = caller_div;
        document.getElementById(currentPosition[level]).oldColor = document.getElementById(currentPosition[level]).style.backgroundColor; 
        document.getElementById(currentPosition[level]).style.backgroundColor = "#CECECE";

        try {
			if (ie)
			{
                document.getElementById(menuDIV).filters.alpha.opacity = 100;
			}
        } catch (e) {
            
        }
    }
    
    function closeAll() {
        for (var i = 0; i <= currentlyShowingDIV.length; i++) {
            hideDiv(currentlyShowingDIV[i], "hidden");
        }
        hideDiv(currentMenu, "hidden");
        for (var i = 0; i < div_array.length; i++) {
            try {
                document.getElementById(div_array[i]).style.display = "none";
            } catch (e) {}
        }
    }
    
    function closeSub(level) {
        try
        {
            hideDiv(currentlyShowingDIV[level+2], "hidden");
            hideDiv(currentlyShowingDIV[level+1], "hidden");
            hideDiv(currentlyShowingDIV[level], "hidden");
        } catch (e)
        {}
    }
    
    function menuOver() {
    	clearTimeout(timeOn);
    }

    function menuOut() {
    	timeOn = setTimeout("closeAll()", 500);
    }

    function displayLimit() {
        if (ie)
        {
            screenWidthLimit=document.body.clientWidth;
            screenHeightLimit=document.body.clientHeight;
        }
        else
        {
            screenWidthLimit=document.body.clientWidth-8;
            screenHeightLimit=document.body.clientHeight-4;
        }
        
    }



    function confirmSubmit(confirmMsg, targetFrm)
    {
        var isConfirmed = window.confirm(confirmMsg);
    
        if (isConfirmed==true)
        targetFrm.submit();
    }
    

        function checkSubMenuLoaded(caller_div)
    {
        var callerObj = document.getElementById(caller_div);
        if(callerObj.menuLoaded == true)
        {
            if(callerObj.menuString.length>0)
            {
                abortMenuRequest();
                return true
            }
            return false;
        }
        return false;
    }
    
    function setSubMenuStatus(caller_div, menuStr)
    {
        var callerObj = document.getElementById(caller_div);
        callerObj.menuLoaded = true;
        callerObj.menuString = menuStr;
    }

    function showSubMenuLoadingStatus(caller_div)
    {
        try
        {
            var elem = document.getElementById("subMenuLoaderAnimation");
            elem.parentNode.removeChild(elem);

            return createSubMenuLoadingObject(caller_div);
        }
        catch(e) 
        {
            return createSubMenuLoadingObject(caller_div);
        }
        
    }
    
    function createSubMenuLoadingObject(caller_div)
    {
        var temp = document.createElement("div");
        temp.id = "subMenuLoaderAnimation";
        if(!ie)
        {
            temp.setAttribute("style", "position:absolute;visibility:hidden;width:160px;padding:2px;border:2px solid #D2D2D2;background-color:#DEDEDE;text-align:center");
        }
        else
        {
            temp.style.position = "absolute";
            temp.style.visibility = "hidden";
            temp.style.width = "160px";
            temp.style.padding = "2px";
            temp.style.border = "2px solid #D2D2D2";
            temp.style.backgroundColor = "#DEDEDE";
            temp.style.textAlign = "center";
        }
        temp.onmouseout = "menuOut()";
        temp.onmouseover = "menuOver()";
        temp.innerHTML = "<div style='width:98%;font:12px arial;color:#000000;padding:2px'><img src='http://www.ipmart.com/main/en/image/product/progress.gif'> loading submenu...</div>";    

        var callerObj = document.getElementById(caller_div);
        callerObj.parentNode.appendChild(temp);

        return temp.id;
    }
    
    function destroySubmenuLoadingObject()
    {
        try
        {
            var elem = document.getElementById("subMenuLoaderAnimation");
            elem.parentNode.removeChild(elem);
        }
        catch (e) {}
    }


    function abortMenuRequest()
    {
        if(onLoadingMenuArray.length > 0)
        {
            onLoadingMenuArray.shift().abort();
        }
    }


    function AJAX_menuLoad(the_div, caller_div, leftPost, the_change, level)
    {
        abortMenuRequest();
        
        var frmData = "divCat="+the_div+"&level="+level+"&lang=en";

        var xmlHttp=GetXmlHttpObject();
        if (xmlHttp==null)
        {
            alert ("Browser does not support HTTP Request");
            return
        }
        
        var url = "";
        url="http://www.ipmart.com/main/menu_action_ajax.php?menuAction=get";

        xmlHttp.onreadystatechange = function() {menuStateChanged(xmlHttp, "GETMENU", Array(the_div, caller_div, leftPost, the_change, level));}; 
        xmlHttp.open("POST",url,true);
        xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlHttp.setRequestHeader("Content-length", frmData.length);
        xmlHttp.setRequestHeader("Connection", "close");
        xmlHttp.send(frmData);

        onLoadingMenuArray.push(xmlHttp);
        
    }
    
    function menuStateChanged(xmlHttp, action, optionArray)
    {
        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
        {
            if (xmlHttp.status == 200)
            {
                var temp = xmlHttp.responseText;

                if (action == "GETMENU")
                {
                    if (temp.length > 0)
                    {
                        var caller_div = optionArray[1];
                        var callerObj = document.getElementById(caller_div);
                        
                        setSubMenuStatus(caller_div, "Arc");

                        destroySubmenuLoadingObject();
                        
                        var tempDiv = document.createElement("div");
                        var splitTextArray = temp.split("|||");
                        tempDiv.id = "sM_"+splitTextArray[0];
                        tempDiv.className = "testing";
                        if(!ie)
                        {
                            tempDiv.setAttribute("style", splitTextArray[1]);
                            tempDiv.setAttribute("onmouseover", "menuOver()");
                        }
                        else
                        {
                            var attributeArray = splitTextArray[3].split("||");

                            tempDiv.style.zIndex = attributeArray[0];
                            tempDiv.style.width = attributeArray[1];

                            tempDiv.onmouseover = "menuOver()";
                        }
                        
                        tempDiv.innerHTML = splitTextArray[2];
                        callerObj.parentNode.appendChild(tempDiv);

                        showSubMenu(optionArray[0], optionArray[1], optionArray[2], optionArray[3], optionArray[4])
                        
                        abortMenuRequest();
                    }
                }
            }
        }
    } 
