﻿

function displayResult(response)
{
    $("#gridContent").html(response);
    
    //display "no result found message"
    
    if($("#ProductDivWrapper div.ProductDiv").length == 0)
    {
            var noResultFoundMsg = "<div class='no-result-box' align='left'>";
            if($("#hdsearchkeyword").val() != '')
            {
             noResultFoundMsg += "Désolé, nous n'avons pas trouvé de résultats pour votre recherche <span style=color:#990000;>" + $("#hdsearchkeyword").val() + "</span>";
            }
            else
            {
             noResultFoundMsg += "Désolé, nous n'avons pas trouvé de résultats pour votre recherche ";
            }
            noResultFoundMsg += "<br /><br />";
            noResultFoundMsg += "Vous pouvez changer vos mots clés et lancer une nouvelle recherche ou changer la sélection des menus de gauche.<br /><br /></div>";
            
            $(noResultFoundMsg).appendTo("div#gridContent");
    }
}


//Function dedicated to get querystring variable value

function getQueryVariable(variable, isListType)
{
    var query = window.location.search.substring(1);
    var querystringValue = null;
    if(query!='')
    {
        var vars = query.split("&");
        //cat=1,2,3
        //mat=12,13
        for (var i=0;i<vars.length;i++)
        {
            var pair = vars[i].split("=");
            if (pair[0] == variable)
            {
                if(isListType)
                    querystringValue = pair[1].split(",");
                else
                    querystringValue = pair[1];
                break;
            }
        }
    }
    
    return querystringValue;
} 

function getRestorePointValueByFlag(flag, isListType)
{
    var exp = "#RestorePoint ";
    var result = null;
    
    switch(flag)
    {
        case "b":
            exp += "div#RCategory";
            result = $.trim($(exp).html());
            break;
        case "c":
            exp += "div#RMaterial";
            result = $.trim($(exp).html());
            break;
        case "d":
            exp += "div#RSelection";
            result = $.trim($(exp).html());
            break;
        case "e":
            exp += "div#RCountry";
            result = $.trim($(exp).html());
            break;
        case "f":
            exp += "div#RSortOrder";
            result = $.trim($(exp).html());
            break;
        case "g":
            exp += "div#RPageSize";
            result = $.trim($(exp).html());
            break;
        case "h":
            exp += "div#RPageInd";
            result = $.trim($(exp).html());
            break;
        case "i":
            exp += "div#RPriceStartValue";
            result = $.trim($(exp).html());
            break;
        case "j":
            exp += "div#RPriceStopValue";
            result = $.trim($(exp).html());
            break;
        case "k":
            exp += "div#RFetchStatus";
            result = $.trim($(exp).html());
            break;
    }   
    
    if(result == '')
        result = null;
        
    if(result != null)
    {
        if(isListType)
            result = result.split(',');
    }
    
    return result;
}


//Function used to format display of product list using CSS
function initializeProductDisplayAndPrepareProductMenuForEachProductBox()
{
    var allDiv = $("#ProductDivWrapper div.ProductDiv");
    
    for(a=0;a<$("#ProductDivWrapper div.ProductDiv").length;a++)
    {
        if((a + 1) % 3 != 0)
        {
            $(allDiv[a]).addClass("ProductDivBox");
        }
    }
    
    appendEuroSignToPrice();
    
    //createRaterForEachProductBox();
    
    initProductMenuForEachProductBox();
    
}
function toggle(target, src)
{
    $(target).attr('src', 'images/catalog/' + src);
};
function createRaterForEachProductBox()
{
    var allProductsDetail = $("#ProductDivWrapper div.ProductDiv div.product-rating");   
    
    allProductsDetail.each(function(n)
                            {
                                var currentRate = $(this).find("span:first").html();
                                
                                $(this).rating('default.aspx',{ maxStar:5, 
                                                                currentRatingValue:currentRate, 
                                                                readOnly: true, 
                                                                onClick: function()
                                                                        {  
                                                                            var redirectURL = $(this).parent().parent().find("A.ProductImgLink").attr("href");
                                                                            location.href = redirectURL;
                                                                        } 
                                                                });
                            }
                            );
}
//Function append EURO sign to every product price in product list
function appendEuroSignToPrice()
{
    $("li.ProductPrice").each(function()
                                {
                                    var price = $(this).html();
                                    $(this).html(price + '€');
                                });
                                
    $("li.oldprice > span").each(function()
                                {
                                    var price = $(this).html();
                                    $(this).html(price + '€');
                                });
}

//Initialize menu in every product box.
//menus include alternate images, add to cart etc.
var src;
var lastAddToCartItem = null;
function initProductMenuForEachProductBox()
{
    var allProductBox = $("DIV.ProductDiv");
    
    
    //initialize product's alternate images.
    for(i=0;i<allProductBox.length;i++)
    {
        var menuItem = $(allProductBox[i]).find("DIV.ProductMenu img.ProductAltImg-unselect");
        
        $(allProductBox[i]).find("DIV.ProductMenu img:first").addClass('ProductAltImg-select');
        
        $(allProductBox[i]).find("DIV.ProductMenu img.ProductAltImg-unselect").each(function()
                                                                            {
                                                                                this.onclick = function()
                                                                                                {
                                                                                                    if(!$(this).hasClass("ProductAltImg-select"))
                                                                                                    {
                                                                                                        var parent = $(this).parent().parent();
                                                                                                        src = $(this).attr("src");
                                                                                                        
                                                                                                        //Fade out current thumbnail of product, when fade out finish, a callback function set 
                                                                                                        //thumbnail target to new thumbnail selected by user.
                                                                                                        $(parent).find("img.ProductImg1").fadeOut(500,function(){
                                                                                                                                                            $(this).parent().find("img.ProductImg1").attr("src",src); 
                                                                                                                                                            });
                                                                                                        $(parent).find("img.ProductImg1").fadeIn(500);

                                                                                                        $(this).parent().parent().find("DIV.ProductMenu img").removeClass('ProductAltImg-select');
                                                                                                        
                                                                                                        $(this).addClass("ProductAltImg-select");
                                                                                                    }
                                                                                                };
                                                                            }
                                                                            );
                                                            
    }
    
    //initialize add to cart DIV.
    $(allProductBox).find('DIV.AddtoCart-flap').hide();
    $(allProductBox).find('DIV.AddedtoCart-flap').hide();
    $(allProductBox).find("DIV.stockout-flap").hide();
    $(allProductBox).find("DIV.stockout-alert-flap").hide();
    
    //following handles effect for those items which are not added to cart.
    $(allProductBox).find("DIV.ProductMenu DIV.Cart").each(function()
                                                                        {
                                                                            this.onmouseover = function()
                                                                                                {
                                                                                                    //Dislay a flap DIV flap animating from right to left.
                                                                                                    //Increasing target's left & width property gradually
                                                                                                    $(this).parent().parent().find('DIV.AddtoCart-flap').show().animate({left:"-=120px","width":"+=120px"});
                                                                                                };
                                                                                                
                                                                            this.onmouseout = function()
                                                                                                {
                                                                                                    //Flap back in a DIV animating from left to right.
                                                                                                    //Decreasing target's left & width property gradually
                                                                                                    $(this).parent().parent().find('DIV.AddtoCart-flap').animate({left:"+=120px","width":"-=120px"}, function(){$(this).hide();});
                                                                                                };
                                                                        });
                                                                        
    //following handles effect for those items which are already added to cart.
    $(allProductBox).find("DIV.ProductMenu DIV.Cart-added").each(function()
                                                                        {
                                                                            this.onmouseover = function()
                                                                                                {
                                                                                                    $(this).parent().parent().find('DIV.AddedtoCart-flap').show().animate({left:"-=120px","width":"+=120px"});
                                                                                                };
                                                                                                
                                                                            this.onmouseout = function()
                                                                                                {
                                                                                                    $(this).parent().parent().find('DIV.AddedtoCart-flap').animate({left:"+=120px","width":"-=120px"}, function(){$(this).hide();});
                                                                                                };
                                                                        });
                                                                        
    //following handles effect for those items which are running out of stock.
    $(allProductBox).find("DIV.ProductMenu DIV.Cart-stockout").each(function()
                                                                        {
                                                                            this.onmouseover = function()
                                                                                                {
                                                                                                    $(this).parent().parent().find('DIV.stockout-flap').show().animate({left:"-=120px","width":"+=120px"});
                                                                                                    
                                                                                                    //$(this).parent().parent().find('DIV.stockout-alert-flap').show().animate({"height":"+=25px"});
                                                                                                };
                                                                                                
                                                                            this.onmouseout = function()
                                                                                                {
                                                                                                    $(this).parent().parent().find('DIV.stockout-flap').animate({left:"+=120px","width":"-=120px"}, function(){$(this).hide();});
                                                                                                    
                                                                                                    //$(this).parent().parent().find('DIV.stockout-alert-flap').animate({"height":"-=25px"}, function(){$(this).hide();});
                                                                                                };
                                                                        });
                                                                        
}

//Function used to show user's filter when any of filter is changed by user.
function showUserFilter()
{
    var catString = [];
    var matString = [];
    var selString = [];
    var countryString = [];         
    var priceString;
    
    //display category related filter
    //Display a comman separated categories filtered by a user in a filter box below moodshot.
    if(cat_Arr.length > 0)
        prepareANDDisplayCategoryFilter();
    else
        $("#td-filter-category").empty();
    
    //display materials related filter
    //Display a comman separated materials filtered by a user in a filter box below moodshot
    if(mat_Arr.length > 0)
        prepareANDDisplayMaterialFilter();   
    else
        $("#td-filter-material").empty();
    
    //display selections related filter
    //Display a comman separated selection(colours) filtered by a user in a filter box below moodshot.
    if(sel_Arr.length > 0)
        prepareANDDisplaySelectionFilter();
    else
        $("#td-filter-selection").empty();
    
    //display counties related filter
    //Display a comman separated country(colours) filtered by a user in a filter box below moodshot.
    if(country_Arr.length > 0)
        prepareANDDisplayCountryFilter();
    else
        $("#td-filter-country").empty();
}

function prepareANDDisplayCategoryFilter()
{
    var divs = '';
    var name;
    divs += '<div id="filter-category">';
    
    for(i=0;i<cat_Arr.length;i++)
    {
        name = $.trim($("#dvCategories li[id=" + cat_Arr[i] + "]").html());
        
        divs += '<div class="item" align="left">';
        divs += '<img id="' + cat_Arr[i] + '" src="images/catalog/cross.jpg" align="absbottom" onclick="cat_clear_click(this)"/>';
        divs += '<span>' + name + '</span>';
        divs += '</div>';
    }
    
    divs += '</div>';
    $("#td-filter-category").empty();
    $(divs).appendTo("#td-filter-category");
}
function prepareANDDisplayMaterialFilter()
{
    var divs = '';
    var name;
    
    divs += '<div id="filter-material">';
    for(i=0;i<mat_Arr.length;i++)
    {
        name = $.trim($("#dvMaterials li[id=" + mat_Arr[i] + "]").html());
        
        divs += '<div class="item" align="left">';
        divs += '<img id="' + mat_Arr[i] + '" src="images/catalog/cross.jpg" align="absbottom" onclick="mat_clear_click(this)"/>';
        divs += '<span>' + name + '</span>';
        divs += '</div>';
    }
    
    divs += '</div>';
    $("#td-filter-material").empty();
    $(divs).appendTo("#td-filter-material");
}

function prepareANDDisplaySelectionFilter()
{
    var divs = '';
    var name;
    divs += '<div id="filter-selection">';
    
    for(i=0;i<sel_Arr.length;i++)
    {
        name = $.trim($("#dvSelection li[id=" + sel_Arr[i] + "]").html());
        
        divs += '<div class="item" align="left">';
        divs += '<img id="' + sel_Arr[i] + '" src="images/catalog/cross.jpg" align="absbottom" onclick="sel_clear_click(this)"/>';
        divs += '<span>' + name + '</span>';
        divs += '</div>';
    }
    
    divs += '</div>';
    $("#td-filter-selection").empty();
    $(divs).appendTo("#td-filter-selection");
}
function prepareANDDisplayCountryFilter()
{
    var divs = '';
    var name;
    divs += '<div id="filter-country">';
    
    for(i=0;i<country_Arr.length;i++)
    {
        name = $.trim($("#dvCountry li[id=" + country_Arr[i] + "]").html());
        
        divs += '<div class="item" align="left">';
        divs += '<img id="' + country_Arr[i] + '" src="images/catalog/cross.jpg" align="absbottom" onclick="country_clear_click(this)"/>';
        divs += '<span>' + name + '</span>';
        divs += '</div>';
    }
    
    divs += '</div>';
    $("#td-filter-country").empty();
    $(divs).appendTo("#td-filter-country");
}

//Handle click event of category filters
function cat_clear_click(element)
{
    //prepare new array of categories
    cat_Arr = $.grep(cat_Arr, function(value){ return value != $(element).attr('id'); } );
    
    $("#dvCategories li[id=" + $(element).attr('id') + "]").removeClass('li-select').addClass('li-unselect');
    
    //remove the clicked element from the DOM.
    $(element).parent().remove();
    
    getProduct_On_FilterClear();
}

//Handle click event of materials filters
function mat_clear_click(element)
{
    //prepare new array of categories
    mat_Arr = $.grep(mat_Arr, function(value){ return value != $(element).attr('id'); } );
    
    $("#dvMaterials li[id=" + $(element).attr('id') + "]").removeClass('li-select').addClass('li-unselect');
    
    //remove the clicked element from the DOM.
    $(element).parent().remove();
    
    getProduct_On_FilterClear();
    
}

//Handle click event of selection(color) filters
function sel_clear_click(element)
{
    //prepare new array of categories
    sel_Arr = $.grep(sel_Arr, function(value){ return value != $(element).attr('id'); } );
    
    $("#dvSelection li[id=" + $(element).attr('id') + "]").removeClass('li-select').addClass('li-unselect');
    
    //remove the clicked element from the DOM.
    $(element).parent().remove();
    
    getProduct_On_FilterClear();
}

//Handle click event of country filters
function country_clear_click(element)
{
    //prepare new array of categories
    country_Arr = $.grep(country_Arr, function(value){ return value != $(element).attr('id'); } );
    
    $("#dvCountry li[id=" + $(element).attr('id') + "]").removeClass('li-select').addClass('li-unselect');
    
    //remove the clicked element from the DOM.
    $(element).parent().remove();
    
    getProduct_On_FilterClear();
}

function getProduct_On_FilterClear()
{
    //restore price slider to its original value
    isSliderInitialized = false;
    displayPriceSliderFiter = false;
    
    //reset price slider's both handles value to original value so that AJAX request can 
    //retrieve full data without no price filter.
    minHandleMoveValue = 0;
    maxHandleMoveValue = 0;
    
    //set pageIndex to 0 so new result with begin from page no. 1 when a user clear all filters.
    pageIndex = 0;
        
    pageIsInClearFilterState = true;
    
    //set fetchData status to TRUE so AJAX call will retrieve all data from database, a GLOBAL variable.
    fetchData = 1;
    
    //make AJAX request to again get fresh data from server
    getProducts();
}
//clear all user's filter
function clearFilters()
{
    
    $("#dvUserFilter").hide();
        
    //restore price slider to its original value
    isSliderInitialized = false;
    displayPriceSliderFiter = false;
    
    //reset price slider's both handles value to original value so that AJAX request can 
    //retrieve full data without no price filter.
    minHandleMoveValue = 0;
    maxHandleMoveValue = 0;
    
    //set pageIndex to 0 so new result with begin from page no. 1 when a user clear all filters.
    pageIndex = 0;
        
    pageIsInClearFilterState = true;
    
    //set selected category array to 0
    cat_Arr = [];
    mat_Arr = [];
    sel_Arr = [];
    country_Arr = [];
    
    $("#dvCategories li").removeClass('li-select').addClass('li-unselect');
    $("#dvMaterials li").removeClass('li-select').addClass('li-unselect');
    $("#dvSelection li").removeClass('li-select').addClass('li-unselect');
    $("#dvCountry li").removeClass('li-select').addClass('li-unselect');
    
    //set fetchData status to TRUE so AJAX call will retrieve all data from database, a GLOBAL variable.
    fetchData = 1;
    //make AJAX request to again get fresh data from server
    getProducts();
}




//Set all filter box's collapsible effect
function applyEffectsOnFilterBoxes()
{
                    
    $("#imgClearAll").click(function() { $("#dvfilter").toggle("blind", {}, "normal"); });
    
    //expand & collapse effect for category box                
    $("#imgCat").parent().click(function() 
                                { 
                                    var current_mode = $("#dvCategories").css("display");
                                    if(current_mode == 'block')
                                    {
                                        $("#dvCategories").hide("blind", { direction: "vertical" }, "normal");
                                        
                                    }
                                    else
                                    {
                                        $("#cat-part-2").css("display", 'none');
                                        
                                        $("#dvCategories").show("blind", 
                                                                { direction: "vertical" }, 
                                                                "normal", 
                                                                function()
                                                                {
                                                                    $("#cat-accord").html('...plus d\'options');
                                                                });
                                    }
                                });
    
    $("#cat-accord").click(function() 
                            { 
                                $("#cat-part-2").toggle("blind", {}, "normal", function()
                                                                                {
                                                                                    if($.trim($("#cat-accord").html()) == '...plus d\'options')
                                                                                    {
                                                                                        $("#cat-accord").html('...moins d\'options');
                                                                                        
                                                                                        //Make a google analytic function call
                                                                                        makeGAnalyticsFunctionCallOnFilterCollapse_Expand(0,'Plus');
                                                                                    }
                                                                                    else
                                                                                    {
                                                                                        $("#cat-accord").html('...plus d\'options');
                                                                                        //Make a google analytic function call
                                                                                        makeGAnalyticsFunctionCallOnFilterCollapse_Expand(0,'Moins');
                                                                                    }
                                                                                }); 
                            });

    //expand & collapse effect for material box
    $("#imgMat").parent().click(function() 
                                { 
                                    var current_mode = $("#dvMaterials").css("display");
                                    if(current_mode == 'block')
                                    {
                                        $("#dvMaterials").hide("blind", { direction: "vertical" }, "normal");
                                    }
                                    else
                                    {
                                        $("#mat-part-2").css("display", 'none');
                                        
                                        $("#dvMaterials").show("blind", 
                                                                { direction: "vertical" }, 
                                                                "normal", 
                                                                function()
                                                                {
                                                                    $("#mat-accord").html('...plus d\'options');
                                                                });
                                    }
                                });
    
    $("#mat-accord").click(function() 
                            { 
                                $("#mat-part-2").toggle("blind", {}, "normal", function()
                                                                                {
                                                                                    if($.trim($("#mat-accord").html()) == '...plus d\'options')
                                                                                    {
                                                                                        $("#mat-accord").html('...moins d\'options');
                                                                                        
                                                                                        //Make a google analytic function call
                                                                                        makeGAnalyticsFunctionCallOnFilterCollapse_Expand(2,'Plus');
                                                                                    }
                                                                                    else
                                                                                    {
                                                                                        $("#mat-accord").html('...plus d\'options');
                                                                                        
                                                                                        //Make a google analytic function call
                                                                                        makeGAnalyticsFunctionCallOnFilterCollapse_Expand(2,'Moins');
                                                                                    }
                                                                                }); 
                            });

    
    //expand & collapse effect for color box
    $("#imgSel").parent().click(function() 
                                { 
                                    var current_mode = $("#dvSelection").css("display");
                                    if(current_mode == 'block')
                                    {
                                        $("#dvSelection").hide("blind", { direction: "vertical" }, "normal");
                                    }
                                    else
                                    {
                                        $("#sel-part-2").css("display", 'none');
                                        
                                        $("#dvSelection").show("blind", 
                                                                { direction: "vertical" }, 
                                                                "normal", 
                                                                function()
                                                                {
                                                                    $("#sel-accord").html('...plus d\'options');
                                                                });
                                    }
                                });
    
    $("#sel-accord").click(function() 
                            { 
                                $("#sel-part-2").toggle("blind", {}, "normal", function()
                                                                                {
                                                                                    if($.trim($("#sel-accord").html()) == '...plus d\'options')
                                                                                    {
                                                                                        $("#sel-accord").html('...moins d\'options');
                                                                                        
                                                                                        //Make a google analytic function call
                                                                                        makeGAnalyticsFunctionCallOnFilterCollapse_Expand(1,'Plus');
                                                                                    }
                                                                                    else
                                                                                    {
                                                                                        $("#sel-accord").html('...plus d\'options');
                                                                                        
                                                                                        //Make a google analytic function call
                                                                                        makeGAnalyticsFunctionCallOnFilterCollapse_Expand(1,'Moins');
                                                                                    }
                                                                                }); 
                            });
                            
                            
    //expand & collapse effect for countrybox
    $("#imgCountry").parent().click(function() 
                                { 
                                    var current_mode = $("#dvCountry").css("display");
                                    if(current_mode == 'block')
                                    {
                                        $("#dvCountry").hide("blind", { direction: "vertical" }, "normal");
                                    }
                                    else
                                    {
                                        $("#country-part-2").css("display", 'none');
                                        
                                        $("#dvCountry").show("blind", 
                                                                { direction: "vertical" }, 
                                                                "normal", 
                                                                function()
                                                                {
                                                                    $("#country-accord").html('...plus d\'options');
                                                                });
                                    }
                                });
    
    $("#country-accord").click(function() 
                            { 
                                $("#country-part-2").toggle("blind", {}, "normal", function()
                                                                                {
                                                                                    if($.trim($("#country-accord").html()) == '...plus d\'options')
                                                                                    {
                                                                                        $("#country-accord").html('...moins d\'options');
                                                                                        
                                                                                        //Make a google analytic function call
                                                                                        makeGAnalyticsFunctionCallOnFilterCollapse_Expand(3,'Plus');
                                                                                    }
                                                                                    else
                                                                                    {
                                                                                        $("#country-accord").html('...plus d\'options');
                                                                                        
                                                                                        //Make a google analytic function call
                                                                                        makeGAnalyticsFunctionCallOnFilterCollapse_Expand(3,'Moins');
                                                                                    }
                                                                                }); 
                            });
}



//function display a modal box when there is an AJAX error
var AJAXErrorbox = "<div class='flora' id='popupDiv'>";
    AJAXErrorbox += "<div align='left'>";
    AJAXErrorbox += "<b><span id='msg'><span id='heading'>Erreur de communication</span><br />";
    AJAXErrorbox += "<br />Il ya eu une erreur de communication. Votre demande n'a pas pu être remplies.<br />";
    AJAXErrorbox += "</span></b><br /><br /></div></div>";
    

$.ajaxSetup({
            type: 'get',
            timeout: 15000,
            dataType: 'html',
            error: function(info,xhr) 
                {
                    $(document).trigger('close.facebox');
                    
                    $(AJAXErrorbox).dialog({ modal: true, 
                                        position: "center",
                                        height:175,
                                        overlay: { opacity: 0.1, 
                                        background: "black" 
                                        } 
                                    });
                }
            });


/* Following functions are used to call few functions which they are required to get called on body load finish .
   1) They are generally related to SEO functionality
   2) Geo location popup display 
    
    */


$(document).ready(function()
                    {
                        displayGeoLocationPopup();
                        
                        removeALTAttributeFromIMGTag();
                        
                        removeTITLEAttributeFromAnchorTag();
                    });
                    
//Function is used to display Geo location popup based on visiting user's country
function displayGeoLocationPopup()
{
    var hdDisplayPopup = $("#ctrlFooter_hdDisplayPopup").attr("value");
    var hdCountry = $("#ctrlFooter_hdCountryname").attr("value");
    var hdCountryArticle = $("#ctrlFooter_hdCountryArticle").attr("value");
    
    var msgHtml;
    switch(hdDisplayPopup)
    {
        case "YES":
            $("#popupDiv").css({display:"block"});
            
            msgHtml = '<span id="heading">Bienvenue sur Bozea.com !</span><br/><br/>';
            msgHtml += 'Sachez que nous livrons <span id="boldText">' + hdCountryArticle + hdCountry + '</span> <br/>dans des <span id="boldText">d\&eacute\;lais</span> et \&agrave\; un <span id="boldText">co\&ucirc\;t</span> raisonnables.<br/><br/>';
            msgHtml += 'Bonne visite sur Bozea.com<br/>';
            msgHtml += 'N\'h\&eacute\;sitez pas \&agrave\; nous contacter pour toute question !';
            
            $("#msg").html(msgHtml);
            break;
    }
}
function hidePopup()
{
    $("#popupDiv").hide();
}


//Function used to remove ALT attribute from all <IMG> tag that are present in page
function removeALTAttributeFromIMGTag()
{
    $("img").removeAttr("alt");
}

//Function used to remove TITLE attribute from all <A> tag that are present in page.
function removeTITLEAttributeFromAnchorTag()
{
    $("a").removeAttr("title");
}



/*Function is used to make call to a google analytics function to track each user's AJAX request.
Generate a URL to call back to google analytic function.
URL will be generated in following way.
/top menu category/product group filter 1+product group filter 2+product group filter 3..../
/material filter 1+material filter 2+material filter 3.../color filter 1+color filter 2+color filter 3.../
/country filter 1+country filter 2+country filter 3/min-price+max-price/sort-price-up-down/sort-name-up-down/page number
*/
function makeGAnalyticsFunctionCall()
{
    var url = 'AJAX/';
    
    //first get the selected top level menu.
    url += $("#menu-new ul li a.topmenuSelected").text();
    
    url +="/category/";
    if(cat_Arr.length > 0)
    {
        for(i=0;i<cat_Arr.length;i++)
        {
            if(i==0)
                url += $.trim($("#dvCategories li#" + cat_Arr[i]).html());
            else
                url += '-' + $.trim($("#dvCategories li#" + cat_Arr[i]).html());
        }
    }
    
    url +="/material/";
    if(mat_Arr.length > 0)
    {
        for(i=0;i<mat_Arr.length;i++)
        {
            if(i==0)
                url += $.trim($("#dvMaterials li#" + mat_Arr[i]).html());
            else
                url += '-' + $.trim($("#dvMaterials li#" + mat_Arr[i]).html());
        }
    }
    
    url +="/color/";
    if(sel_Arr.length > 0)
    {
        for(i=0;i<sel_Arr.length;i++)
        {
            if(i==0)
                url += $.trim($("#dvSelection li#" + sel_Arr[i]).html());
            else
                url += '-' + $.trim($("#dvSelection li#" + sel_Arr[i]).html());
        }
    }
    
    url +="/country/";
    if(country_Arr.length > 0)
    {
        for(i=0;i<country_Arr.length;i++)
        {
            if(i==0)
                url += $.trim($("#dvCountry li#" + country_Arr[i]).html());
            else
                url += '-' + $.trim($("#dvCountry li#" + country_Arr[i]).html());
        }
    }
   
    url += "/" + priceStart + '+' + priceStop;
 
    switch(sortOrder)   
    {
        case 0:
            url += "/" + "Price Ascending";
            break;
        case 1:
            url += "/" + "Price Descending";
            break;
        case 2:
            url += "/" + "Product Name Ascending";
            break;
        case 3:
            url += "/" + "Product Name Descending";
            break;
            
    }
    
    url += "/" + "page " + (pageIndex+1);
    
    try
    {
        pageTracker._trackPageview(url); 
    }
    catch(e) { }
    
}

function makeGAnalyticsFunctionCallOnFilterCollapse_Expand(whichLeftMenu, mode)
{
    var url = 'AJAX/';
    
    try
    {
        switch(whichLeftMenu)
        {
            case 0://left menu first filter. i.e. Catégories
                pageTracker._trackEvent('Categories', mode, $("#menu-new ul li a.topmenuSelected").text()); 
                //url += mode + "/categories/" + $("#menu-new ul li a.topmenuSelected").text();
                break;
            case 1://left menu second filter. i.e. Couleurs
                pageTracker._trackEvent('Colors', mode, $("#menu-new ul li a.topmenuSelected").text()); 
                //url += mode + "/colors/" + $("#menu-new ul li a.topmenuSelected").text();
                break;
            case 2://left menu second filter. i.e. Matières
                pageTracker._trackEvent('Materials', mode, $("#menu-new ul li a.topmenuSelected").text()); 
                //url += mode + "/materials/" + $("#menu-new ul li a.topmenuSelected").text();
                break;
            case 3://left menu second filter. i.e. Origine
                pageTracker._trackEvent('Countries', mode, $("#menu-new ul li a.topmenuSelected").text()); 
                //url += mode + "/countries/" + $("#menu-new ul li a.topmenuSelected").text();
                break;
        }
    }
    catch(e){ }
}