﻿// ################################################################################################################################################################## 

// ### Effects.js
// =================================================================================================================================================================

// JScript File
    
    var errorFlag;

    function lOvr(c)
    {
        c.style.color='#bfbfbf'; 
        c.style.cursor='pointer';
    }
    function lOut(c)
    {
        c.style.color='purple'; 
    }


    function changeColorThumb(pcolID, id, img)
    {
        var imagePath = img.replace(/ColorThumbs/, 'CatalogueThumbs');
        var c = document.getElementById(id);
        c.src = imagePath;
        c.name = pcolID;
    }    

    function opacity(id, opacStart, opacEnd, millisec) 
    {
        errorFlag = false;
        var speed = Math.round(millisec / 100); //speed for each frame
        var timer = 0;

        if(opacStart > opacEnd)  //determine the direction for the blending, if start and end are the same nothing happens
        {
            for(i = opacStart; i >= opacEnd; i--) 
            {
                setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
                timer++;
                if (errorFlag == true)
                    break;
            }
        } 
        else if(opacStart < opacEnd) 
        {
            for(i = opacStart; i <= opacEnd; i++)
            {
                setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
                timer++;
                if (errorFlag == true)
                    break;
            }
        }
    }
    
    function changeOpac(opacity, id)    //change the opacity for different browsers
    {
        var object = document.getElementById(id);
        if (object)
        {
            object.style.opacity = (opacity / 100);
            object.style.MozOpacity = (opacity / 100);
            object.style.KhtmlOpacity = (opacity / 100);
            object.style.filter = "alpha(opacity=" + opacity + ")";
            
            errorFlag = false;
        }
        else
        {
            errorFlag = true;
            return false;
            
        }
    } 
   

// End opacity scripts
    
    function changeVisibility( id, visible )
    {
        var element = document.getElementById(id);
        if (element)
        {
            if (visible)
            {
                element.style.visibility = 'visible'; 
                opacity(this.id, 30, 100, 500);
            }
            else
            {
                opacity(this.id, 100, 30, 4500);
            }
        }
        else
            return false;
    }


    function expandImage(id, makeBigger, changeLeftMargin)
    {
        var size;
        var object = document.getElementById(id);
        
        if (makeBigger)
            size = 10;
        else        
            size = -10;

        var w = object.style.width;
        var x = size + parseInt(w.replace('px', ''));

        var h = object.style.height;

        if(h != "")
        {
            var y = size + parseInt(h.replace('px', ''));


            object.style.width = x.toString() + 'px';
            object.style.height = y.toString() + 'px';
            
            if (makeBigger)
                object.style.marginTop = (size/-2) + 'px';
            else
                object.style.marginTop = '0px';

            if (changeLeftMargin)
            {
                if (makeBigger)
                    object.style.marginLeft = (size/-2) + 'px';
                else
                    object.style.marginLeft = '0px';
            }
        }
    }

    function slideOpenCloseControlTrigger(id, px, expandDown)
    {
        var s = document.getElementById(id);
        
        errorFlag = false;
        var speed = Math.round(slideMillisec / 100); //speed for each frame
        var timer = 0;
        
        if(px > 0)  
        {
            for(i = 0; i < px; i++) 
            {
                setTimeout("slideOpenCloseControl(1,'" + id + "', " + expandDown + ")",(timer * speed));
                timer++;
                if (errorFlag == true)
                    break;
            }
        } 
        else 
        {
            for(i = 0; i > px; i--)
            {
                setTimeout("slideOpenCloseControl(-1,'" + id + "', " + expandDown + ")",(timer * speed));
                timer++;
                if (errorFlag == true)
                    break;
            }
        }
    }

    function slideOpenCloseControl(pixels, id, expandDown)    
    {
        var object = document.getElementById(id);
        var pix = parseInt(pixels);
        var t = parseInt((object.style.top).replace('px', ''));
        var h = parseInt((object.style.height).replace('px', ''));
        
        var nt = (t - pix).toString() + 'px';
        var nh = (h + pix).toString() + 'px';
        if (nh == '-1px')
            nh = '0px';
        
        if (object)
        {
            if (!expandDown)
                object.style.top = nt;
            object.style.height = nh;
        }
        else
        {
            errorFlag = true;
            return false;
        }
    } 
    


// ### Navigation.js
// =================================================================================================================================================================



// JScript File

// Menu left scripts

    var currentLeftMenuID;
    var currentLeftSubMenuID;
    var currentLeftMenuSelectedID;
    var currentVerticalMenuSelectedID;
    
    var flagToOpenCategoryOnLoad;    
    
    function openVerticalMenu(id)
    {
        unHighlihghtSelectedVerticalMenu(); 
        openVerticalLink(id); 
        setCookie('Menu', 'tmi_' + id); 
        HighlihghtSelectedVerticalMenu(); 
    }
    
    
    function openVerticalLink(text)
    {
        
        switch (text.toLowerCase()) 
        {
        case 'home': 
            window.location = "Manzoni.aspx?p=home";
            break;
        case 'shop online': 
            window.location = "Manzoni.aspx?p=shop";
            break;
        case 'contact manzoni': 
            window.location = "Manzoni.aspx?p=contact";
            break;
        case 'shipping': 
            window.location = "Manzoni.aspx?p=shipping";
            break;
        case 'returns': 
            window.location = "Manzoni.aspx?p=returns";
            break;
        case 'trade customers': 
            window.location = "http://www.manzoni.com.au";
            break;
        case 'in the media': 
            window.location = "Media.aspx";
            break;
        case 'terms & conditions': 
            window.location = "Manzoni.aspx?p=terms";
            break;
        case 'privacy & security': 
            window.location = "Manzoni.aspx?p=privacy";
            break;
        case 'cart': 
            if(getCookie('Menu').toLowerCase() != 'tmi_check out')//if (showBas != 1)
                showBas = (showBas == 1 ? 0 : 1); showBasket();
            break;
        case 'check out':
            if (document.getElementById('txtItemsInBasket').value != 0)
                window.location = "pay.aspx";
            else
                alert('Your shopping basket is empty, please order something first.');
            
            break;
        
        case 'ezine':
            window.location = "Subscribe.aspx";
            break;
        default:            
            setCookie('page', 'home');
            window.location = "Manzoni.aspx";
        }
    }    

    function openMenuTimeout(id, isOpen)
    {
        var m = document.getElementById(id);

        while (m.nodeType==3) { // Fix for Mozilla/FireFox Empty Space becomes a TextNode 
            m = (isOpen ? m.nextSibling : m.previousSibling);
        };
        
        if (m)
        {
            m.style.height = (isOpen ? '16px': '0px');
            m.style.display = (isOpen ? 'block' : 'none');
            
            var sibling = (isOpen ? m.nextSibling : m.previousSibling);
            
            if(sibling)
            {
                var x = sibling;
               
                while (x.nodeType==3) { // Fix for Mozilla/FireFox Empty Space becomes a TextNode 
                    
                    sibling = (isOpen ? x.nextSibling : x.previousSibling);
                    if (sibling)
                        x = sibling;
                    else 
                        return;
                };
                setTimeout("openMenuTimeout('" + x.id + "', " + isOpen + ")",1);
            }
        }       
   
    }
    
    
    function openMenu(id)
    {
        closeMenu(currentLeftMenuID); 

        if(currentLeftMenuID == id)
            currentLeftMenuID = null;
        else
        {
            var h = null;
            var x = null;
            
            var m = document.getElementById('mi_' + id);
           
            
            if(m)
            {
                h = m.offsetHeight; 
                x = m.firstChild;
                
                if (x)
                {
                    while (x.nodeType==3) 
                    { // Fix for Mozilla/FireFox Empty Space becomes a TextNode 
                        x = x.nextSibling;
                    };
                    
                    x.style.display = 'none';
                    x.style.height = '0px';
                    
                    
                    try
                    {
                        var y = x.nextSibling;
                        if(y)
                        {
                            while (y.nodeType==3)
                            { // Fix for Mozilla/FireFox Empty Space becomes a TextNode 
                                y = y.nextSibling;
                            };
                        
                        y.style.display = 'none';
                        y.style.height = '0px';
                        }
                    }
                    catch(ex)
                    {}
                                
                    var z;
                    var i = 1;
                    while (y)
                    {
                        z = y;
                        z.style.display = 'none';
                        z.style.height = '0px';
                        
                        if (z.nextSibling)
                        {
                            y = z.nextSibling;
                            try
                            {
                                while (y.nodeType==3) { // Fix for Mozilla/FireFox Empty Space becomes a TextNode 
                                    y = y.nextSibling;
                                }
                            }
                            catch(e)
                            {}
                        }
                        else
                            y = null;
                        
                        i++;
                    }
               }
              
              
               m.style.display='block';

               setTimeout("openMenuTimeout('" + x.id + "', true)",100);

               var p = document.getElementById('pmi_' + id);
               p.className = 'menuElement_Selected';
    //           opacity('mi_' + id, 0, 100, 600);
            
               currentLeftMenuID = id;

               highlihghtSelectedSubMenu();
        
               setCookie("cookieMenuDept", currentLeftMenuID);
               
           }
           
        }  
    }
    
    function closeMenu(id)
    {
        if (id != null)
        {
            
            var m = document.getElementById('mi_' + id);
            var x = m.lastChild;
            
            if(x)
            {
                while (x.nodeType==3) { // Fix for Mozilla/FireFox Empty Space becomes a TextNode 
                    x = x.previousSibling;
                };
           
                setTimeout("openMenuTimeout('" + x.id + "', false)",100);
            }
            
            var p = document.getElementById('pmi_' + id);
            p.className = 'menuElement';
            
            deleteCookie('cookieMenuDept');
               
        }
    }


//   Vertical Menu Mouse oVer
    function VMMV(c) 
    {
        c.className = 'menuElement_Selected';
    }
//   Vertical Menu Mouse ouT
    function VMMT(c)
    {
        if(currentVerticalMenuSelectedID != c.id)
            c.className = 'menuElement';
    }

//   Left Menu Mouse oVer
    function LMMV(c) 
    {
        if(currentLeftMenuID != c.id && 'pmi_' + currentLeftMenuID != c.id )
            c.className = 'menuElement_Over';
        
        c.style.cursor = 'pointer';
    }
//   Left Menu Mouse ouT
    function LMMT(c)
    {
        if(currentLeftMenuID != c.id && 'pmi_' + currentLeftMenuID != c.id )
            c.className = 'menuElement';
    }

//   Left Sub Menu Mouse oVer
    function LSMMV(c) 
    {
        if(currentLeftSubMenuID != c.id && 'smi_' + currentLeftSubMenuID != c.id )
            c.className = 'menuElement_SubOver';

        c.style.cursor = 'pointer';
    }
//   Left Sub Menu Mouse ouT
    function LSMMT(c)
    {
        if(currentLeftSubMenuID != c.id && 'smi_' + currentLeftSubMenuID != c.id )
            c.className = 'menuElement_Sub';
    }


    function openCatalogue(CategoryID, splash)
    {
        unHighlihghtSelectedVerticalMenu();
        setCookie('Menu', 'tmi_Shop Online');
        HighlihghtSelectedVerticalMenu();


        var toRemove = document.getElementById(catalogueScrollID + '_tempCM'); 
        if(toRemove)
        {
            var parent = toRemove.parentNode;
            parent.removeChild(toRemove);
        }

        
        changeOpac(0, catalogueScrollID + '_divCatalogueScroll');


       if (checkLocation('products.aspx'))
       {
           if(splash)
                currentSplash = splash;
           flagToOpenCategoryOnLoad = false;
           resetImagesCount(); 
           opCat(CategoryID, this.id); 
           document.getElementById('productColoursContent').style.visibility = 'hidden';
           squeezeCatalogue(false); 
           scrollClickCountCatalogue = 0;
           

       }
       else
       {
           setCookie('Category', CategoryID); 
           setCookie('CategoryElementID', this.id); 
           
           flagToOpenCategoryOnLoad = true;
           redirectToCatalogue(); 
      
       }
    }


    function openCatalogueOnLoad()
    {
        if (flagToOpenCategoryOnLoad == true)
        {
            var id = getCookie('CategoryElementID');
            CategoryID = getCookie('Category');
            
            resetImagesCount(); 
            opCat(CategoryID, id); 
            document.getElementById('productColoursContent').style.visibility = 'hidden';
            squeezeCatalogue(false); 
            scrollClickCountCatalogue = 0;
            flagToOpenCategoryOnLoad = false;
        }    
    }



var CurrentDepartment;
function setCurrentDepartment(val)
{
    CurrentDepartment = val;
}



//function redirectToCatalogue()
//{

//    if (checkLocation("products.aspx"))
//        ;//do nothing
//    else
//        window.location = "products.aspx";//window.location = host + "products.aspx";
//    
//}       



// end Menu Left scripts


// Menu Vertical scripts


    var currentTopMenuID;

    function HighlightCurrent(id)
    {
    
        currentTopMenuID = getCookie('currentTopMenuID');
    
        UnHighlightCurrent(currentTopMenuID); 

        if(currentTopMenuID == id)
        {
            deleteCookie('currentTopMenuID');
        }
        else
        {

            var m = document.getElementById(id);
            m.className = 'menuElement_Selected';
            setCookie('currentTopMenuID', id);
        }
    }

    function UnHighlightCurrent(id)
    {
        if (id != null)
        {
            var m = document.getElementById(id);
            m.className = 'menuElement';
        }
    }


// End Menu Vertical scripts


//////////////////////////////////////////////////


function setSearchKeyword()
{
    var a = getCookie('SearchKeyword');
    if (a)
        document.getElementById('txtKeyword').value = a;
}



function unHighlihghtSelectedSubMenu()
{
    if (currentLeftMenuSelectedID)
    {
        var mc = document.getElementById(currentLeftMenuSelectedID);
        if (mc)
            mc.className = 'menuElement_Sub';
    }
    return false;
}

function highlihghtSelectedSubMenu()
{
    unHighlihghtSelectedSubMenu();
    
    var a = getCookie('SubCategoryID');
    if (a != null && a != 0)
        document.getElementById('smi_' + a).className = 'menuElement_SubSelected';
    
    currentLeftMenuSelectedID = 'smi_' + a;
    currentLeftSubMenuID = 'smi_' + a; 
    
    return false;
}


function unHighlihghtSelectedVerticalMenu()
{
    var mc = document.getElementById(getCookie('Menu'));
    if (mc)
        mc.className = 'menuElement';

    return false;
}

function HighlihghtSelectedVerticalMenu()
{
    var a = getCookie('Menu');
    if (a != null && a != 0)
    {
        document.getElementById(a).className = 'menuElement_Selected';
        currentVerticalMenuSelectedID = a;
    }
    return false;
}

function scrollItemPageCatalogue()
{
    if (checkLocation("Item.aspx"))
    {
        var a = document.getElementById('ctl00_ctl00_ContentPlaceHolder1_MasterContent1_ctl00_ctl06_ucCatalogue1_hfScrollJump');
        if (a)
        {
            var s = document.getElementById(catalogueScrollID + '_divCatalogueScroll');
            
            if (a.value > 5)
            {
                var u = document.getElementById(catalogueScrollID + '_upArrow');
                u.style.visibility = 'visible';
                
                s.scrollTop = (a-2) * 70;
                
            }   
            var i = getQuerystringParameterValue('i');
            opacity(i, 100, 50, 500);
            changeVisibility('sp_' + i , true );
        }            
    }
         
}


var currentSplash;
function opDep(departmentID, splash)
{
    openMenu(departmentID); 
    setCurrentDepartment(departmentID); 
    setCookie('Department', departmentID);
    
    currentSplash = splash;
}

function opCat(category, id)
{
    var im = document.getElementById('imgLoadingCatalogue');
    if (im)
        im.style.visibility = 'visible';
    setCookie('Category', category); 
 
    currentLeftSubMenuID = id;    
    restartXHR(); 
    highlihghtSelectedSubMenu(); 
    getProdXHR(true);

    var s = document.getElementById('splash');
    if(s)
        s.src = 'Images/Splashes/' + currentSplash;
    }


function bold(id, isBold)
{
    var a = document.getElementById(id);
    if (a)
    {
        if (isBold == 1)
            a.style.fontWeight = 'bold';
        else
            a.style.fontWeight = 'normal';
    }
}

//// JScript File

//    
//    var changeImageTimeout;
//    var errorFlag;

//    function changeThumb(pcolID, id, img, timeout)
//    {
//        changeImageTimeout = window.setTimeout('changeColorThumb(\'' + pcolID + '\',\'' + id + '\', \'' + img + '\')', timeout);
//    }

//    function changeColorThumb(pcolID, id, img)
//    {
//        var imagePath = img.replace(/ColorThumbs/, 'CatalogueThumbs');
//        var c = document.getElementById(id);
//        c.src = imagePath;
//        c.name = pcolID;
//    }    

//    function cancelChangeThumb()
//    {
//        window.clearTimeout (changeImageTimeout);
//    }
//    

//    function opacity(id, opacStart, opacEnd, millisec) 
//    {
//        errorFlag = false;
//        var speed = Math.round(millisec / 100); //speed for each frame
//        var timer = 0;

//        if(opacStart > opacEnd)  //determine the direction for the blending, if start and end are the same nothing happens
//        {
//            for(i = opacStart; i >= opacEnd; i--) 
//            {
//                setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
//                timer++;
//                if (errorFlag == true)
//                    break;
//            }
//        } 
//        else if(opacStart < opacEnd) 
//        {
//            for(i = opacStart; i <= opacEnd; i++)
//            {
//                setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
//                timer++;
//                if (errorFlag == true)
//                    break;
//            }
//        }
//    }
//    

//    function changeOpac(opacity, id)    //change the opacity for different browsers
//    {
//        var object = document.getElementById(id);
//        if (object)
//        {
//            object.style.opacity = (opacity / 100);
//            object.style.MozOpacity = (opacity / 100);
//            object.style.KhtmlOpacity = (opacity / 100);
//            object.style.filter = "alpha(opacity=" + opacity + ")";
//            
//            errorFlag = false;
//        }
//        else
//        {
//            errorFlag = true;
//            return false;
//            
//        }
//    } 
//   

//// End opacity scripts
//    
//    function changeVisibility( id, visible )
//    {
//        var element = document.getElementById(id)
//        if (element)
//        {
//            if (visible)
//            {
//                element.style.visibility = 'visible'; 
//                opacity(this.id, 30, 100, 500);
//                
//            }
//            else
//            {
//                opacity(this.id, 100, 30, 4500);
//            //    element.style.visibility = 'hidden'; 
//            }
//        }
//        else
//            return false;
//        
//    }

//function bold(id, isBold)
//{
//    var a = document.getElementById(id);
//    if (a)
//    {
//        if (isBold == 1)
//            a.style.fontWeight = 'bold';
//        else
//            a.style.fontWeight = 'normal';
//    }
//}
