var filteredArray = new Array(0); var tmpInnerHTML = ""; var init = true; function sortIgnoreCase (a, b) { try { a = a.toLowerCase(); b = b.toLowerCase(); if(a>b) { return 1; } if(a realHeight/height) { img.width = width; img.height = realHeight * width/realWidth; } else { img.height = height; img.width = realWidth * height/realHeight; } } //The function populates a dropdown based on values from the filtered product list function populateDropdown(number) { var categoryArray = new Array(0); //Get actual dropdown var categoryDropdown = document.getElementById("category" + number); j = 0; //Create list of actual category for (i = 0; i < filteredArray.length; i++) { tmpArr = (filteredArray[i].category[number]).split("&&"); for (g = 0; g < tmpArr.length; g++) { categoryArray[j] = tmpArr[g]; j++; } } //Make sure every instance is unique categoryArray = unique(categoryArray); //Sort elements in list categoryArray.sort(sortIgnoreCase); //Save old values and empty dropdown selectedValue = categoryDropdown.options[categoryDropdown.selectedIndex].text categoryDropdown.length = 0; //Add default value var e = document.createElement('option'); e.text = '- Any -'; e.value = ''; categoryDropdown.options.add(e); //Populate dropdown with the new list for (i = 0; i < categoryArray.length; i++) { e = document.createElement('option'); if (categoryArray[i].indexOf('|') != -1) { tmpArr = categoryArray[i].split("|"); e.text = tmpArr[1]; } else { e.text = categoryArray[i]; } e.value = categoryArray[i]; categoryDropdown.options.add(e); } //Set old saved value to selected for (i = 0; i < categoryDropdown.length; i++) { if (selectedValue == categoryDropdown.options[i].text) { categoryDropdown.selectedIndex = i; } } } //Filter product list so that the list correspond to the values selected in the dropdown lists function filter() { filteredArray = new Array(0); count = 0; selectedArray = getSelectedValues(); for (i = 0; i < myArray.length; i++) { if (checkProduct(i, selectedArray)) { filteredArray[count] = myArray[i]; count++; } } return filteredArray; } function checkProduct(i, selectedArray) { for (j = 0; j < 10; j++) { if(selectorArray[j].show || (selectorArray[j].show == 0 && selectedArray[j] != '' && selectedArray[j] != undefined)) { if ( (myArray[i].category[j]).match("&&") != null && (selectedArray[j] != "")) { if (filterMultiCategory(selectedArray[j], myArray[i].category[j]) == false) return false; } else if ( selectedArray[j] != myArray[i].category[j] && (selectedArray[j] != "")) { return false; } } } return true; } function filterMultiCategory(selected, values) { tmpArr = values.split("&&"); for (g = 0; g < tmpArr.length; g++) { if (tmpArr[g] == selected) { return true; } } return false; } //Get list with selected dropdown values function getSelectedValues() { var selectedArray = new Array(0); for (i = 0; i < 10; i++) { if(selectorArray[i].show && init == false) { categoryDropdown = document.getElementById("category" + i); selectedArray[i] = categoryDropdown.options[categoryDropdown.selectedIndex].value; } else { if (predefinedArray[i].predefinedValue != '' && predefinedArray[i].predefinedValue != 'undefined') { selectedArray[i] = predefinedArray[i].predefinedValue; } else { selectedArray[i] = ''; } } } return selectedArray; } //The function makes sure that every element in a list is unique function unique(a) { tmp = new Array(0); for (i=0; i < a.length; i++){ if (!contains(tmp, a[i]) && a[i] != ''){ tmp.length += 1; tmp[tmp.length-1] = a[i]; } } return tmp; } //The function checks if a list contains a certain value function contains(a, e) { for(j=0; j < a.length; j++) { if (a[j] == e) { return true; } } return false; } //Write the list in grid version function dumpFilteredArray1Columns(obj) { var outerCellColor = "bgcolor=\"#D5D9DF\""; var rowColor = "bgcolor=\"#ffffff\""; var innerTableStart = ""; tmpInnerHTML = ""; for (i = 0; i < filteredArray.length; i++) { if(filteredArray[i].title != ""){ tmpInnerHTML = tmpInnerHTML + innerTableStart + "" + "" + "
" + "" + "" + "" + ""; /* Write out the products attributes */ for (j = 0; j < 10; j++) { if (selectorArray[j].table) { tmpList = ""; tmpArr = filteredArray[i].category[j].split("&&"); for (g = 0; g < tmpArr.length; g++) { if (tmpArr[g].indexOf('|') != -1) {; tmpArr2 = tmpArr[g].split("|"); tmpList = tmpList + tmpArr2[1]; } else { tmpList = tmpList + tmpArr[g]; } if (g != (tmpArr.length-1)) { tmpList = tmpList + ", "; } } tmpInnerHTML += "" + "" + "" + ""; } } tmpInnerHTML += "
" + filteredArray[i].title + ""; if (bilde) { tmpInnerHTML += ""; tmpInnerHTML += ""; } tmpInnerHTML += "
" + selectorArray[j].title+""+ tmpList +" 
" + "
"; } } return tmpInnerHTML; } function writeTableStart() {return "";} function writeTableEnd() {return "
";} function getSingleSelectors(i) { var tmp = "
"+selectorArray[i-1].title+"
"; if (predefinedArray[i-1].predefinedValue != '') { tmp += ""; } else { tmp += ""; } return tmp; } function writeSelectors() { var resetButton = "

"; var tmpSelectors = //"
" + ""+ "" + "
" for (i = 1; i < 11; i++) { if(selectorArray[i-1].show) { tmpSelectors += "
" + getSingleSelectors(i) + "
"; } } tmpSelectors = tmpSelectors + "
"; //"
"; var formObj = document.getElementById('selectors'); formObj.innerHTML = tmpSelectors + resetButton; } function resetSelectors() { for (i = 0; i < predefinedArray.length; i++) { predefinedArray[i].predefinedValue = ""; } writeSelectors(); update(); } //Write the list in table version function dumpFilteredArray2Columns(obj) { tmpInnerHTML = ''; var tableHeader = ""; var tableHeaderContent = ""; var tmpTableHeaderContent = ""; if (bilde) {tmpTableHeaderContent += ""} tmpTableHeaderContent +=""; for(j = 0; j < selectorArray.length;j++){ if(selectorArray[j].table == "1") { tmpTableHeaderContent += ""; } tableHeaderContent = "" + tmpTableHeaderContent + ""; } tmpInnerHTML = tmpInnerHTML + tableHeader + tableHeaderContent; for (i = 0; i < filteredArray.length; i++) { if(filteredArray[i].title != ""){ tmpInnerHTML += ""; if (bilde) { tmpInnerHTML += ""; } tmpInnerHTML += ""; for(j = 0; j < selectorArray.length;j++) { tmpList = ""; tmpArr = filteredArray[i].category[j].split("&&"); for (g = 0; g < tmpArr.length; g++) { if (tmpArr[g].indexOf('|') != -1) {; tmpArr2 = tmpArr[g].split("|"); tmpList = tmpList + tmpArr2[1]; } else { tmpList = tmpList + tmpArr[g]; } if (g != (tmpArr.length-1)) { tmpList = tmpList + ", "; } } if(selectorArray[j].table == "1") {tmpInnerHTML += "";} } ""; } } tmpInnerHTML += "
"+selectorArray[j].title+"
"; tmpInnerHTML += ""; tmpInnerHTML += "" + filteredArray[i].title + "" + tmpList + " 
"; return tmpInnerHTML; }