﻿// JScript File

// Menu left scripts

    var currentLeftMenuID;
    var currentLeftMenuSelectedID;
    
    function openMenu(id)
    {
        closeMenu(currentLeftMenuID); 

        if(currentLeftMenuID == id)
        {
            currentLeftMenuID = null;
        }
        else
        {
            var m = document.getElementById('mi_' + id);
            m.style.display='block';

            var p = document.getElementById('pmi_' + id);
            p.className = 'menuElement_Selected';
            opacity('mi_' + id, 0, 100, 600);
        
            currentLeftMenuID = id;

            highlihghtSelectedSubMenu();
    
            setCookie("cookieMenucategoryID", currentLeftMenuID);
        }  
    }
    
    function closeMenu(id)
    {
        if (id != null)
        {
            opacity('mi_' + id, 100, 0, 100);
            
            var m = document.getElementById('mi_' + id);
            m.style.display='none';

            var p = document.getElementById('pmi_' + id);
            p.className = 'menuElement';
            
            deleteCookie('cookieMenuSubCategoryID');
               
        }
    }


//   Left Menu Mouse oVer
    function LMMV(c) 
    {
        if(currentLeftMenuID != c.id && 'pmi_' + currentLeftMenuID != c.id )
            c.className = 'menuElement_Over';
    }
//   Left Menu Mouse ouT
    function LMMT(c)
    {
        if(currentLeftMenuID != c.id && 'pmi_' + currentLeftMenuID != c.id )
            c.className = 'menuElement';
    }


function __doPostBack(eventTarget, eventArgument) 
{
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) 
    {
        theForm.__EVENTTARGET.value = eventTarget;
        theForm.__EVENTARGUMENT.value = eventArgument;
        theForm.submit();
    }
}

var CurrentCategory;
function setCurrentCategory(val)
{
    CurrentCategory = val;
}



//function redirectToCatalogue()
//{
////    var l = window.location.toString();

////    if (l.indexOf("Products.aspx") > -1)
////        ;//do nothing
////    else
////        window.location = "http://new.manzoni.com.au/Products.aspx";
//    
//}       



function postBackHiddenField(hiddenFieldID, args, valueToSet) 
{

    var hiddenField = document.getElementById(hiddenFieldID);
    
    
    if (hiddenField) 
    {
        hiddenField.value = valueToSet;
        
        __doPostBack(hiddenFieldID,args);

    }

    return false;
}


// end Menu Left scripts


// Menu Vertical scripts


    var currentTopMenuID;

    function HighlightCurrent(id)
    {
        UnHighlightCurrent(currentTopMenuID); 

        if(currentTopMenuID == id)
        {

            currentTopMenuID = null;
        }
        else
        {

            var m = document.getElementById(id);
            m.className = 'menuElement_Selected';
            currentTopMenuID = id;
        }
    }

    function UnHighlightCurrent(id)
    {
        if (id != null)
        {
        var m = document.getElementById(id);
        m.className = 'menuElement';
//        m.style.color = '#926E5E';
        
        }
    }

    function MouseOver(c)
    {
        if(currentTopMenuID != c.id)
            c.className = 'menuElementHorizontal_Over';
        c.style.backgroundImage= "url('Images/Bckg/bg_green_roll.gif')"; 
        c.style.cursor = 'pointer';           
    }
    function MouseOut(c)
    {
        if(currentTopMenuID != c.id)
            c.className = 'menuElementHorizontal';
        c.style.backgroundImage = "url('Images/Bckg/bg_green.gif')";            
    }



// End Menu Vertical scripts


function setItemPage()
{
    var l = window.location.toString();
    //alert (l);
    if (l.indexOf("Item.aspx") > -1 )
    {
        var i = getQuerystringParameterValue('i');
        var pc = getQuerystringParameterValue('pc');
        
        setCurrPrColID(pc);
                        
        GetItemData(i, pc);
        
        
    }    
}


function openItem(controlId, itemID, prodColID, isAJAX)
{
    deleteCookie('SearchKeyword'); 
    
    setCookie('itemID', itemID);
    
    if (prodColID)
        setCookie('prodColID', prodColID);
    else
        deleteCookie('prodColID');
    
    
    if (isAJAX == 0)
    {
    
        var pcID;
        
        if (prodColID)
            pcID = prodColID;
        else
            {
                var p = document.getElementById(controlId);
                if (p)
                    pcID = p.name;
            }
        
        var qstr;

        if(pcID != null && pcID != '')
            qstr = '?i='+ itemID + '&pc=' + pcID;
        else
            qstr = '?i='+ itemID;
        

        self.location = 'http://new.manzoni.com.au/Item.aspx' + qstr;    

    } 
    else
    {
        postBackHiddenField('ctl00_ctl00_ContentPlaceHolder1_MasterContent1_hfItemID', controlId, itemID);
    }
}



//////////////////////////////////////////////////


function setSearchKeyword()
{
    var a = getCookie('SearchKeyword');
    if (a)
        document.getElementById('txtKeyword').value = a;
}



function unHighlihghtSelectedSubMenu()
{
//    var mc = getCookie('cookieMenuCat');
    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)
        document.getElementById('smi_' + a).className = 'menuElement_SubSelected';
    
    currentLeftMenuSelectedID = 'smi_' + a;
    
    return false;
}

function scrollItemPageCatalogue()
{
    var l = window.location.toString();
    if (l.indexOf("Item.aspx") > -1 )
    {
        var a = document.getElementById('ctl00_ctl00_ContentPlaceHolder1_MasterContent1_ctl00_ctl06_ucCatalogue1_hfScrollJump');
        if (a)
        {
            var s = document.getElementById('ScScrollDiv1_divCatalogueScroll');
            
            if (a.value > 5)
            {
                var u = document.getElementById('ScScrollDiv1_upArrow');
                u.style.visibility = 'visible';
                
                s.scrollTop = (a-2) * 70;
                
            }   
            var i = getQuerystringParameterValue('i');
            opacity(i, 100, 50, 500);
            changeVisibility('sp_' + i , true );
        }            
    }
         
}

function openCategory(CategoryID)
{
    openMenu(CategoryID); 
    setCurrentCategory(CategoryID); 
    setCookie('CategoryID', CategoryID);
}

function openSubCategory(SubCategoryID)
{
//    redirectToCatalogue(); 

//    restartXHR(); 

    setCookie('SubCategoryID', SubCategoryID); 
    highlihghtSelectedSubMenu(); 

//    getProdXHR(true);
    
   // alert(SubCategoryID);
    
}

function setCurrentMenuInfo(Category)
{
    setCookie('Category', Category);
    
    updateElementsText('currentMenuPositionInfo', Category);
    
    
}
function setCurrentSubMenuInfo(SubCategory)
{
    setCookie('SubCategory', SubCategory);
    updateElementsText('currentMenuPositionInfo', getCookie('Category') + ' > ' + SubCategory);
}


function leftMenuSubCatClick(SubCategoryID, Category,  SubCategory )
{
//    document.getElementById('enqEmail').style.display = 'none'; 
//    document.getElementById('actualContent').style.display = 'none';


    setCookie('SubCategoryID', SubCategoryID); 
    highlihghtSelectedSubMenu(); 
    
    var pi = document.getElementById('productsFirstOpenInfo');
    if(pi)
        document.getElementById('productsFirstOpenInfo').style.display = 'none';
//    removeFirstChild('actualContent');
//    document.getElementById('divLoading').style.visibility = 'visible'; 


//removed after implementing rewriting
//    redirectToCatalogue(); 
//    openSubCategory(SubCategoryID); 

//    setCurrentMenuInfo(Category);
//    setCurrentSubMenuInfo(SubCategory); 
//    hideCatInfo() 
}

function leftMenuCatClick(CategoryID, Category)
{
    
    setCookie('Category', Category);
    //openCategory(CategoryID); 
    
}

function horMenuClick(MenuID, Page)
{
//    window.location = host + Page;
}

function updateElementsText(element, text)
{

    var e; 
    var fc;
    e = document.getElementById(element);
    if(e)
    {
        fc = e.firstChild;
        
        if (fc)
        {
            fc.data = text; 
        }
        else
        {
            var txt = document.createTextNode(text);       
            e.appendChild(txt);
        }
    }
}

function setReturnedItemsCount(value)
{
    setCookie('returnedItemsCount', value); 
    
}
function getReturnedItemsCount()
{
    var result;
    result = getCookie('returnedItemsCount'); 
    
    if (result == undefined)
        result = 0;
        
            
    return parseInt(result); 
}

function openItem()
{
}



