﻿var productsPerPage = 10;
var loading = false;
var refineContainerCollapsed = true;
var storedResult;
var untickedImage = "images/cross.gif";
var tickedImage = "images/tick.gif";
var maxPageNumbers = 9;
var numberOfRows = 6;
var numberOfBrandColumns;
var columnCount;
var longBrandList = "";
var allChecked = true;
var longBrandListExists = false;
var longBrandListVisible = false;
var maxDescriptionLength = 500;

function DisplayFilterProducts()
{
    var refineContainerDiv = document.getElementById("refinecontainer");
    var divWidth = refineContainerDiv.offsetWidth;
    
    columnCount = parseInt((divWidth-8)/130);
    numberOfBrandColumns = columnCount - attributeCount;

    if (numberOfBrandColumns < 1)
    {
        numberOfBrandColumns = 1;
    }
       

    refineContainerDiv.innerHTML = "" + GenerateShortBrandList() + GenerateAttributes(); 


        

}

function DisplayCollapsedFilterProducts()
{
    var refineContainerDiv = document.getElementById("refinecontainer");
        refineContainerDiv.style.height = "0px"; 
        FillCollapsedFilterProducts();
}

function FilterProductsResized()
{
    
    var refineContainerDiv = document.getElementById("refinecontainer");

    var divWidth = refineContainerDiv.offsetWidth;
    
    //filtercontracted

    //SetCollapsedFilterProductsSize();
    var newColumnCount = parseInt((divWidth-8)/130);
    if (columnCount != newColumnCount)
    {
        DisplayFilterProducts();
    }
    SetCollapsedFilterProductsSize();
}

function SetCollapsedFilterProductsSize()
{
    if (refineContainerCollapsed == true)
    {
        var refineContainerDiv = document.getElementById("refinecontainer");
        var divWidth = refineContainerDiv.offsetWidth;
        var filterContracted = document.getElementById("filtercontracted");
        filterContracted.style.width = divWidth + "px"; 
        var filterTabTextWidth = divWidth-215;
        var filterTabText = document.getElementById("filtertabtext");
        filterTabText.style.width = filterTabTextWidth + "px"; 
    }
}

function FillCollapsedFilterProducts()
{
    var collapsedContainerDiv = document.getElementById("filtertabtext");
    var contents = GenerateCollapsedBrands();
    contents = contents  + GenerateCollapsedAttributes();
    if (contents.length > 0)
    {
        contents = "<span style=\"float:left;font-size:10px;margin-top:1px;\">Now Showing:</span>" + contents;
    }
    else
    {
        contents = "";
    }    
    collapsedContainerDiv.innerHTML = contents;
    
    SetCollapsedFilterProductsSize();

 }

function GenerateCollapsedAttributes()
{
    
    var i,j;
    i=0;
    j=0;
    var divContents = "";
    var numberOfItemsInCurrentColumn = 0;
    for(j = 0; j < attributeCount ; j++)
    {
        for (i=0; i < attributeTypeCount[j]; i++)
        {
            if (attributes[j][i][2] == "true")
            {
                divContents = divContents + "<div id=\"collapsedcheckbox+" + j + "+Attribute+" + i + "\" name=\"collapsedcheckboxtext+" + j + "+Attribute+" + i + "\" class=\"collapsedText\" onmouseover=\"CollapsedCheckBoxMouseOver(this);\" onmouseout=\"CollapsedCheckBoxMouseOut(this);\" onclick=\"checkBoxOnClick(this);\">"
                                            + "<img id=\"collapsedcheckbox+" + j + "+Attribute+" + i + "+Image\" src=\"images/checkbox-contracted.gif\" alt=\"" + attributes[j][i][0] + "\"></img>" + attributes[j][i][0] + "</div>";
            }
        }//
    }
    return (divContents);
}

function GenerateCollapsedBrands()
{
    
    var divContents = "";
    var i;

    for(i=0; i < brandCount; i++)
    {
        if (brands[i][3] == "true")
        {
            divContents = divContents + "<div id=\"collapsedcheckbox+Brand+" + brands[i][0] + "\" name=\"collapsedcheckbox+Brand+" + brands[i][0] + "\" class=\"collapsedText\" onmouseover=\"CollapsedCheckBoxMouseOver(this);\" onmouseout=\"CollapsedCheckBoxMouseOut(this);\" onclick=\"checkBoxOnClick(this);\">"
                                      + "<img id=\"collapsedcheckbox+Brand+" + brands[i][0] + "+Image\" src=\"images/checkbox-contracted.gif\" alt=\"" + brands[i][1] + "\"></img>" + brands[i][1] + "</div>";
        }
    }

    return (divContents);
}

function GenerateAttributes()
{
    var i,j;
    i=0;
    j=0;
    var selectedString = "false";
    var allSelected;
    var columnClosed = true;
    var divContents = "";
    var numberOfItemsInCurrentColumn = 0;
    for(j = 0; j < attributeCount ; j++)
    {
        numberOfItemsInCurrentColumn = 0;
        divContents = divContents + "<div class=\"attributeplustitle\">";
        divContents = divContents + "<span class=\"atttitle\">" + attributesNames[j] + "</span><br />";
        allSelected = untickedImage;
        if (attributesAllChecked[j] == true)
        {
            allSelected = tickedImage;
        }
        
        divContents = divContents + "<span class=\"checkboxtext\" id=\"checkbox+" + j + "+Attribute+All\" name=\"checkbox+" + j + "+Attribute+All\"  onmouseover=\"checkBoxMouseOver(this);\"  onmouseout=\"checkBoxMouseOut(this);\" onclick=\"checkBoxOnClick(this);\">"
                                  + "<img id=\"checkbox+" + j + "+Attribute+All+Image\" src=\"" + allSelected + "\" alt=\"All\" />&nbsp;<strong>All " + attributesNames[j] + "s</strong></span><br />";
        columnClosed = false;
        numberOfItemsInCurrentColumn++;
        for (i=0; i < attributeTypeCount[j]; i++)
        {

            if (numberOfItemsInCurrentColumn == 0)
            {
                divContents = divContents + "<div class=\"attribute\">";
            }
            selectedString = untickedImage;
            if (attributes[j][i][2] == "true")
            {
                selectedString = tickedImage;
            }
            divContents = divContents + "<span class=\"checkboxtext\" id=\"checkbox+" + j + "+Attribute+" + i + "\" name=\"checkbox+" + j + "+Attribute+" + i + "\" onmouseover=\"checkBoxMouseOver(this);\"  onmouseout=\"checkBoxMouseOut(this);\" onclick=\"checkBoxOnClick(this);\">"
                                      + "<img id=\"checkbox+" + j + "+Attribute+" + i + "+Image\" src=\"" + selectedString + "\" alt=\"" + attributes[j][i][0] + "\"></img>&nbsp;" + attributes[j][i][0] + "</span><br />";

            columnClosed = false;

        
            numberOfItemsInCurrentColumn++;
            if (numberOfItemsInCurrentColumn > numberOfRows-1)
            {
                numberOfItemsInCurrentColumn = 0;
                divContents = divContents + "</div>";
                columnClosed = true;
            }
        }
        if (columnClosed == false)
        {
            divContents = divContents + "</div>";
        }
    }
    return (divContents);
}

function GenerateShortBrandList()
{
    var numberOfBrandsToShow = (numberOfRows * numberOfBrandColumns) - 1;
    var listAllButton = "";
    if (brandCount > numberOfBrandsToShow)
    {
        GenerateLongBrandList();
        listAllButton = "<a style=\"cursor: pointer;cursor: hand;\" onClick=\"SetScrollerDisplay('brandScroller');return;\">[List All]</a>";
    }
    else
    {
        numberOfBrandsToShow = brandCount;
    }
    SortBrandList(numberOfBrandsToShow);
    var selectedString = "false";
    var allSelected;
    var columnClosed = true;
    var divContents = "";
    var contractedDivContents = "";
    var i;
    var numberOfItemsInCurrentColumn = 0;

    for(i=-1; i < numberOfBrandsToShow; i++)
    {
        if (i == -1)
        {
        
            allSelected = untickedImage;
            if (allChecked == true)
            {
                allSelected = tickedImage;
            }
            divContents = divContents + "<div class=\"attributeplustitle\">";
            divContents = divContents + "<span class=\"atttitle\">Brand</span>&nbsp;" + listAllButton + "<br />";
            divContents = divContents + longBrandList;
            divContents = divContents + "<span class=\"checkboxtext\" id=\"checkbox+Brand+All\" name=\"checkbox+Brand+All\" onmouseover=\"checkBoxMouseOver(this);\"  onmouseout=\"checkBoxMouseOut(this);\" onclick=\"checkBoxOnClick(this);\">"
                                      + "<img id=\"checkbox+Brand+All+Image\" src=\"" + allSelected + "\" alt=\"All\" />&nbsp;<strong>All Brands</strong></span><br />";
            

            columnClosed = false;
        }
        else
        {
            if (numberOfItemsInCurrentColumn == 0)
            {
                divContents = divContents + "<div class=\"attribute\">";
            }
            selectedString = untickedImage;
            if (brands[i][3] == "true")
            {
                selectedString = tickedImage;
            }
            divContents = divContents + "<span class=\"checkboxtext\" id=\"checkbox+Brand+" + brands[i][0] + "\" name=\"checkbox+Brand+" + brands[i][0] + "\" onmouseover=\"checkBoxMouseOver(this);\"  onmouseout=\"checkBoxMouseOut(this);\" onclick=\"checkBoxOnClick(this);\">"
                                      + "<img id=\"checkbox+Brand+" + brands[i][0] + "+Image\" src=\"" + selectedString + "\" alt=\"" + brands[i][1] + "\"></img>&nbsp;" + brands[i][1] + "</span><br />";
            columnClosed = false;

        }
        numberOfItemsInCurrentColumn++;
        if (numberOfItemsInCurrentColumn > numberOfRows-1)
        {
            numberOfItemsInCurrentColumn = 0;
            divContents = divContents + "</div>";
            columnClosed = true;
        }
    }
    //var contractedDiv = document.getElementById("filtertabtext"); 
    //contractedDiv.innerHTML = contractedDivContents;
  
    if (columnClosed == false)
    {
        divContents = divContents + "</div>";
    }

    return (divContents);
}

function GenerateLongBrandList()
{
    var allSelected;
    var selectedString = "false";
    AlphabetiseBrands(-1);
    allSelected = untickedImage;
    if (allChecked == true)
    {
        allSelected = tickedImage;
    }
    var scrollerClass = "listallhidden";
    if (longBrandListVisible == true)
    {
        scrollerClass = "listallvisible";
    }
    
    longBrandList = "";
    
    
    
    //longBrandList = longBrandList + "<div class=\"attribute\"><strong>Brand</strong>";
    longBrandList = longBrandList + "<div id=\"brandScroller\" class=\"" + scrollerClass + "\">"
                                  + "<a onClick=\"SetScrollerDisplay('brandScroller');return;\"><img src=\"images/listall/icn-cross.gif\" class=\"listallclosebutton\" /></a>"
	                              + "<div class=\"listallinner\">";

    longBrandList = longBrandList + "<span class=\"checkboxtext\" id=\"checkbox+BrandLong+All\" name=\"checkbox+BrandLong+All\" onmouseover=\"checkBoxMouseOver(this);\"  onmouseout=\"checkBoxMouseOut(this);\" onclick=\"checkBoxOnClick(this);\">"
                                      + "<img id=\"checkbox+BrandLong+All+Image\" src=\"" + allSelected + "\" alt=\"All\" />&nbsp;<strong>All Brands</strong></span><br />";
    for(i=0; i < brandCount; i++)
    {
        selectedString = untickedImage;
        if (brands[i][3] == "true")
        {
            selectedString = tickedImage;
        }
        longBrandList = longBrandList + "<span class=\"checkboxtext\" id=\"checkbox+BrandLong+" + brands[i][0] + "\" name=\"checkbox+BrandLong+" + brands[i][0] + "\" onmouseover=\"checkBoxMouseOver(this);\"  onmouseout=\"checkBoxMouseOut(this);\" onclick=\"checkBoxOnClick(this);\">"
                                      + "<img id=\"checkbox+BrandLong+" + brands[i][0] + "+Image\" src=\"" + selectedString + "\" alt=\"" + brands[i][1] + "\"></img>&nbsp;" + brands[i][1] + "</span><br />";
    }

    longBrandList = longBrandList + "</div></div>";
                        
    
}

function SortBrandList(numberToShow)
{
    var orderChanged = false;
    
    var i;
    if (numberToShow > brandCount)
    {
        numberToShow = brandCount;
    }
    

    
    i=0;
    
    if (brandCount>1)
    {
        var swapPerformed = true;
        
        while (swapPerformed == true)
        {
            
            swapPerformed = false;
            for(i=0; i < brandCount-1; i++)
            {   
                if (brands[i+1][3] == "true")
                {
                    if (brands[i][3] == "false")
                    {
                        SwapBrands(i);
                        swapPerformed = true;
                        orderChanged = true;
                    }
                    else if ((parseInt(brands[i+1][2])) > (parseInt(brands[i][2])))
                    {
                        SwapBrands(i);
                        swapPerformed = true;
                        orderChanged = true;
                    }
                }
                else
                {
                    if ((brands[i][3] == "false") && ((parseInt(brands[i+1][2])) > (parseInt(brands[i][2]))))
                    {
                        SwapBrands(i);
                        swapPerformed = true;
                        orderChanged = true;
                    }
                }
            }
        }
        AlphabetiseBrands(numberToShow);
    }
}

function AlphabetiseBrands(numberToShow)
{
    
    var i;
    if (numberToShow > brandCount)
    {
        numberToShow = brandCount;
    }
    else if (numberToShow == -1)
    {
        numberToShow = brandCount;
    
    }
    i=0;
    var swapPerformed = true;
    while (swapPerformed == true)
    {
        swapPerformed = false;
        for(i=0; i < numberToShow-1; i++)
        {   
            if (brands[i][1] > brands[i+1][1])
            {
                SwapBrands(i);
                swapPerformed = true;
            }
        }
    } 
}


function SwapBrands(position)
{
    var tempBrand = brands[position];
    brands[position] = brands[position+1];
    brands[position+1] = tempBrand;

}

function BuildTwoDimensionalArray(sizeOfFirst, sizeOfSecond)
{
    var newArray = [sizeOfFirst];
    var i,j;
    for (i=0; i < sizeOfFirst; i++)
    {
        newArray[i] = [sizeOfSecond];
        for (j=0; j < sizeOfSecond; j++)
        {
            newArray[i][j] = "";
        }
    }
    
    return (newArray);
}

function BuildThreeDimensionalArray(sizeOfFirst, sizeOfSecond, sizeOfThird)
{
    
    var newArray = [sizeOfFirst];
    var i,j,k;
    for (i=0; i < sizeOfFirst; i++)
    {
        newArray[i] = [sizeOfSecond];
        for (j=0; j < sizeOfSecond; j++)
        {
            newArray[i][j] = [sizeOfThird];
            for (k=0; k < sizeOfThird; k++)
            {
                newArray[i][j][k] = "";
            }
        }
    }
    return (newArray);

}

function NothingSelected()
{
    var i=0;
    var nothingSelected = true;
    nothingSelected = allChecked;
    
    while((i < attributeCount) && (nothingSelected == true))
    {
        nothingSelected = attributesAllChecked[i];
        i++;
    }
    
    return nothingSelected;
}


function AllItemsOfAttributeSetToFalse(attributeId)
{
    var i=0;
    var found = false;
    while((i < attributeTypeCount[attributeId]) && (found == false))
    {
        if (attributes[attributeId][i][2] == "true")
        {
            found = true;
        }
        else
        {
            i++;
        }
    }
    if (found == true)
    {
        return false;
    }
    else
    {
        return true;
    }
    
}

function AllBrandsSetToFalse()
{
    var i=0;
    var found = false;
    while((i < brandCount) && (found == false))
    {
        if (brands[i][3] == "true")
        {
            found = true;
        }
        else
        {
            i++;
        }
    }
    
    if (found == true)
    {
        return false;
    }
    else
    {
        return true;
    }
    
}

function GetBrandOfId(id)
{
    
    var i=0;
    var found = false;
    while((i < brandCount) && (found == false))
    {
        try
        {
            if (parseInt(brands[i][0]) == id)
            {
                found = true;
            }
            else
            {
                i++;
            }
        }
        catch (err)
        {
            i++;
        }
    }
    
    if (found == true)
    {
        return (i);
    }
    else
    {
        return -1;
    }
    
}

function DeselectAllBrands()
{
    var i, brandElement;
    try{
        for(i=0; i < brandCount; i++)
        {   
            brands[i][3] = "false";
            brandElement = document.getElementById("checkbox+Brand+" + brands[i][0] + "+Image");
            if (brandElement != null)
            {
                brandElement.src = untickedImage;
            }
            
            if (longBrandListExists == true)
            {
                brandElement = document.getElementById("checkbox+BrandLong+" + brands[i][0] + "+Image");
                if (brandElement != null)
                {
                    brandElement.src = untickedImage;
                }
            }
            
        }
    }
    catch (err)
    {
        window.alert("ERROR Deselecting brands: i= " + i + " of " + brandCount + ", element: \"" + "checkbox+Brand+" + brands[i][0] + "+Image\" error: "  + err);
    }

}



function DeselectAllItemsOfAttribute(attributeId)
{
    var i;
    for (i=0; i < attributeTypeCount[attributeId]; i++)
    {   
        attributes[attributeId][i][2] = "false";
        document.getElementById("checkbox+" + attributeId + "+Attribute+" + i + "+Image").src = untickedImage;
    }
}

function GetSenderType(sender)
{
    var idString;
    var separated = sender.id.split("+");
    if (separated.length > 1)
    {
        if (separated[0] == "CHECKBOX")
        {
        
        }
    }

}

function SetMouseOver(sender, on)
{
    if (on == true)
    {   
        sender.className = "checkboxtextmouseover";
    
    }
    else
    {
        sender.className = "checkboxtext";
    }    
    
    var id = -1;
    var idString;
    var separated = sender.id.split("+");
    var currentBrand = null;
    var selectedString =  "";
    if (separated.length > 1)
    {
        if (separated[0].toUpperCase() == "CHECKBOX")
        {
            if (separated[1].toUpperCase() == "BRAND")
            {
                idString = separated[2];
                
                if (longBrandListExists == true)
                {
                    var brandLongBox = document.getElementById("checkbox+BrandLong+" + idString);
                    if (brandLongBox != null)
                    {
                        if (on == true)
                        {   
                            
                            brandLongBox.className = "checkboxtextmouseover";
                        
                        }
                        else
                        {
                            brandLongBox.className = "checkboxtext";
                        } 
                    }
                }
                
            }
            else if (separated[1].toUpperCase() == "BRANDLONG")
            {
                idString = separated[2];
                var brandBox = document.getElementById("checkbox+Brand+" + idString);
                if (brandBox != null)
                {
                    if (on == true)
                    {   
                        
                        brandBox.className = "checkboxtextmouseover";

                    }
                    else
                    {
                        brandBox.className = "checkboxtext";
                    } 
                }
            }
        }
    }
}

function SetSelected(sender)
{
   var id = -1;
    var idString;
    var separated = sender.id.split("+");
    var currentBrandLocation = -1;
    var selectedString =  "";
    if (separated.length > 1)
    {
        if (separated[0].toUpperCase() == "CHECKBOX")
        {
            if (CharIsNumber(separated[1].charAt(0)))
            {
                try
                {
                    var attributeId = parseInt(separated[1]);
                    if ((separated[2].toUpperCase()  == "ATTRIBUTE") || (separated[2].toUpperCase() == "ATTRIBUTELONG"))
                    {
                        idString = separated[3];
                        var selectedString = "cross.gif";
                        if (idString.toUpperCase() == "ALL")
                        {
                            if (attributesAllChecked[attributeId] == true)
                            {
                                      
                            }
                            else
                            {
                                attributesAllChecked[attributeId] = true;  
                                selectedString = "tick.gif";
                                DeselectAllItemsOfAttribute(attributeId);
                                document.getElementById("checkbox+" + attributeId + "+Attribute+All+Image").src = tickedImage;
                                RequestNewProductList(0);
                            }        
                        }
                        else
                        {          
                            id = parseInt(idString);              
                            if (attributes[attributeId][id][2] == "true")
                            {
                                attributes[attributeId][id][2] = "false";
                                document.getElementById("checkbox+" + attributeId + "+Attribute+" + id + "+Image").src = untickedImage;
                                if (AllItemsOfAttributeSetToFalse(attributeId))
                                {
                                    attributesAllChecked[attributeId] = true;  
                                    document.getElementById("checkbox+" + attributeId + "+Attribute+All+Image").src = tickedImage;
                                }
                            }
                            else
                            {
                                if (attributesAllChecked[attributeId] == true)
                                {
                                    attributesAllChecked[attributeId] = false;
                                    document.getElementById("checkbox+" + attributeId + "+Attribute+All+Image").src = untickedImage;           
                                }
                                attributes[attributeId][id][2] = "true";
                                

                                document.getElementById("checkbox+" + attributeId + "+Attribute+" + id + "+Image").src = tickedImage;
                            }
                            RequestNewProductList(0);
                        }
                    }
                }
                catch(err)
                {
                }
            }
            else if ((separated[1].toUpperCase() == "BRAND") || (separated[1].toUpperCase() == "BRANDLONG"))
            {
                idString = separated[2];
                var checkboxObject = document.getElementById("checkbox+Brand+" + idString + "+Image");
                if (longBrandListExists == true)
                {
                    checkboxObjectLong = document.getElementById("checkbox+BrandLong+" + idString + "+Image");
                }
                var imageElement;
                if (idString.toUpperCase() == "ALL")
                {
                    if (allChecked == true)
                    {
                           
                    }
                    else
                    {
                        allChecked = true;
                        document.getElementById("checkbox+Brand+All+Image").src = tickedImage;
                        if (longBrandListExists == true)
                        {
                            document.getElementById("checkbox+BrandLong+All+Image").src = tickedImage;   
                        }   
                        DeselectAllBrands();
                        RequestNewProductList(0);
                    }        
                }
                else
                {
                    try
                    {
                        id = parseInt(idString);
                        currentBrandLocation = GetBrandOfId(id);
                        if (currentBrandLocation != -1)
                        {                            
                            if (brands[currentBrandLocation][3] == "true")
                            {
                                brands[currentBrandLocation][3] = "false";
                                imageElement = document.getElementById("checkbox+Brand+" + id + "+Image");
                                
                                if (imageElement != null)
                                {
                                    imageElement.src = untickedImage;
                                }
                                
                                if (longBrandListExists == true)
                                {
                                    imageElement = document.getElementById("checkbox+BrandLong+" + id + "+Image");
                                }
                                
                                if (imageElement != null)
                                {
                                    imageElement.src = untickedImage;
                                }
                                
              
                                if (AllBrandsSetToFalse())
                                {
                                    allChecked = true;
                                    document.getElementById("checkbox+Brand+All+Image").src = tickedImage;
                                    if (longBrandListExists == true)
                                    {
                                        document.getElementById("checkbox+BrandLong+All+Image").src = tickedImage;
                                    }
                                }
                            }
                            else
                            {
                                if (allChecked == true)
                                {
                                    allChecked = false;    
                                    document.getElementById("checkbox+Brand+All+Image").src = untickedImage;
                                    if (longBrandListExists == true)
                                    {
                                        document.getElementById("checkbox+BrandLong+All+Image").src = untickedImage;
                                    }
                                }
                                brands[currentBrandLocation][3] = "true";
                                
                                imageElement = document.getElementById("checkbox+Brand+" + id + "+Image");
                                
                                if (imageElement != null)
                                {
                                    imageElement.src = tickedImage;
                                }
                                
                                if (longBrandListExists == true)
                                {
                                    imageElement = document.getElementById("checkbox+BrandLong+" + id + "+Image");
                                }
                                
                                if (imageElement != null)
                                {
                                    imageElement.src = tickedImage;
                                }
                            }
                            RequestNewProductList(0);
                        }
                        
                    }
                    catch(err)
                    {
                    }
                }
                
                if (separated[1].toUpperCase() == "BRANDLONG")
                {
                    DisplayFilterProducts();
                }
            }
            
        }
        else if (separated[0].toUpperCase() == "COLLAPSEDCHECKBOX")
        {   
            ResizeRefineContainer();
            RequestNewProductList(0);
            
        }
        
        
        
    }
}

function CharIsNumber(c)
{
    if ((c == '1') || (c == '2') || (c == '3') || (c == '4') || (c == '5') || (c == '6') || (c == '7') || (c == '8') || (c == '9') || (c == '0'))
    {
        return true;
    }
    else
    {
        return false;
    }
}

function SetScrollerDisplay(scrollerName)
{
    
    var scroller = document.getElementById(scrollerName);
    if (scroller.className == "listallhidden")
    {
        scroller.className = "listallvisible"
        longBrandListVisible = true;
    }
    else
    {
        longBrandListVisible = false;
        scroller.className = "listallhidden"
    }
    
}

function checkBoxMouseOver(sender)
{
    SetMouseOver(sender, true);
    
}

function checkBoxMouseOut(sender)
{
     SetMouseOver(sender, false);

}

function CollapsedCheckBoxMouseOver(sender)
{
    sender.className = "collapsedTextOver";
    
}

function CollapsedCheckBoxMouseOut(sender)
{
     sender.className = "collapsedText";

} 

function checkBoxOnClick(sender)
{
    SetSelected(sender);

}

function GenerateRequestString(firstResultNumber)
{
    var requestString = "ProductSearch.aspx?category=" + categoryId;
    var j, i;
    var parametersAdded = false;
    
    if (allChecked == false)
    {      
        requestString = requestString + "&brand=[";  
        for(i=0; i<brandCount; i++)
        {
            if (brands[i][3] == "true")
            {
                requestString = requestString + brands[i][1] + ",";
                parametersAdded = true;
            }
        }
        requestString = requestString + "]";
        
    }
    var currentAttributeName;
    
    for(j = 0; j < attributeCount ; j++)
    {
        currentAttributeName = attributesNames[j]
        if (attributesAllChecked[j] == false)
        {
            requestString = requestString + "&" + attributesParameters[j] + "=[";
            for (i=0; i < attributeTypeCount[j]; i++)
            {
                if (attributes[j][i][2] == "true")
                {
                    requestString = requestString + attributes[j][i][1] + ",";
                    parametersAdded = true;
                }
                
            }  
            requestString = requestString + "]";
            
        }
    }
    requestString = requestString + "&firstResult=" + firstResultNumber;
    return requestString;
}

function RequestNewProductList(firstResultNumber)
{

    var requestString = GenerateRequestString(firstResultNumber);

    location.href=requestString;
}

window.onresize = FilterProductsResized;
