// JavaScript Document


var productTableFilters = function()
{
	var browser = navigator.appName;
	if(browser=="Microsoft Internet Explorer")
	{
	//Manufacturer Filter
	var selectedManufacturer = document.tableFilter.vendorSearch.options[document.tableFilter.vendorSearch.selectedIndex].firstChild.nodeValue;
	var productTable = document.getElementById("productTable");
	var allRowsArray = productTable.childNodes[0].childNodes;
	for(i=2; i<allRowsArray.length; i++)
	{
		var allCellsArray = allRowsArray[i].getElementsByTagName("td");
		var manufacturer = allCellsArray[0].firstChild.nodeValue;
		if(selectedManufacturer==manufacturer)
		{
			allRowsArray[i].style.display="inline";
		}
		else if(selectedManufacturer=="All Manufacturers")
		{				
			allRowsArray[i].style.display="inline";
		}
		else
		{
			allRowsArray[i].style.display="none";
		};
	};
	//Quality Filter
	var selectedQuality = document.tableFilter.qualitySearch.options[document.tableFilter.qualitySearch.selectedIndex].firstChild.nodeValue;
	var productTable = document.getElementById("productTable");
	for(i=2; i<allRowsArray.length; i++)
	{
		var allCellsArray = allRowsArray[i].getElementsByTagName("td");
		var qualityLevel = allCellsArray[2].firstChild.nodeValue;
		if(allRowsArray[i].style.display=="none")
		{
		}
		else if(selectedQuality==qualityLevel)
		{
			allRowsArray[i].style.display="inline";
		}
		else if(selectedQuality=="All Quality Levels")
		{				
			allRowsArray[i].style.display="inline";
		}
		else
		{
			allRowsArray[i].style.display="none";
		};
	};

	
	//Style and Finish Filters
	var selectedStyle = document.tableFilter.styleSearch.options[document.tableFilter.styleSearch.selectedIndex].firstChild.nodeValue;
	var selectedFinish = document.tableFilter.finishSearch.options[document.tableFilter.finishSearch.selectedIndex].firstChild.nodeValue;
	var styleSubTables = Core.getElementsByClass("productStyles");
	var finishSubTables = Core.getElementsByClass("productFinish");
	for(i=0; i<styleSubTables.length; i++)
	{
		var allStyles = styleSubTables[i].getElementsByTagName("td");
		var allFinishes = finishSubTables[i].getElementsByTagName("td");
		var nonMatchingStyles = new Array();
		for(j=0; j<allStyles.length; j++)
		{
			var styleType = allStyles[j].firstChild.nodeValue;
			if(styleType=='Double 6" Extra Long')
			{
				styleType='Double 6"'
			}
			else if(styleType=='Double 4" Extra Long')
			{
				styleType='Double 4"'
			}
			else if(styleType=='Double 4-1/2" Dutchlap Extra Long')
			{
				styleType='Double 4-1/2" Dutchlap'
			}
			else if(styleType=='Double 5" Dutchlap Extra Long')
			{
				styleType='Double 5" Dutchlap'
			};
			if(allRowsArray[i+2].style.display=="none")
			{
			}
			else if(selectedStyle=="All Styles")
			{
				allStyles[j].parentNode.style.display="inline";
				allFinishes[j].parentNode.style.display="inline";
			}
			else if(selectedStyle=="Shake & Shingle Siding")
			{
				var brandName = styleSubTables[i].parentNode.previousSibling.previousSibling.firstChild.firstChild.nodeValue;
				var thisRow = allRowsArray[i+2];
				if(brandName=="Cedar Impressions")
				{
					thisRow.style.display="inline";
					allStyles[j].parentNode.style.display="inline";
					allFinishes[j].parentNode.style.display="inline";
				}
				else if(brandName=="Northwoods")
				{
					thisRow.style.display="inline";
					allStyles[j].parentNode.style.display="inline";
					allFinishes[j].parentNode.style.display="inline";
				}
				else if(brandName=="Portsmouth Shake")
				{
					thisRow.style.display="inline";
					allStyles[j].parentNode.style.display="inline";
					allFinishes[j].parentNode.style.display="inline";
				}
				else if(brandName=="Cedar Discovery")
				{
					thisRow.style.display="inline";
					allStyles[j].parentNode.style.display="inline";
					allFinishes[j].parentNode.style.display="inline";
				}
				else
				{
					thisRow.style.display="none";
				};
			}
			else if(selectedStyle!=styleType)
			{
				allStyles[j].parentNode.style.display="none";
				allFinishes[j].parentNode.style.display="none";
				var k = nonMatchingStyles.length;
				nonMatchingStyles[k] = allStyles[j];
			}
			else if(selectedStyle==styleType)
			{
				allStyles[j].parentNode.style.display="inline";
				allFinishes[j].parentNode.style.display="inline";
			};
			var finishType = allFinishes[j].firstChild.nodeValue;			
			if(allRowsArray[i+2].style.display=="none")
			{
			}
			else if(allStyles[j].parentNode.style.display=="none")
			{
			}
			else if(selectedFinish=="All Finishes")
			{
				allStyles[j].parentNode.style.display="inline";
				allFinishes[j].parentNode.style.display="inline";
			}
			else if(selectedFinish==finishType)
			{
				allStyles[j].parentNode.style.display="inline";
				allFinishes[j].parentNode.style.display="inline";
			}
			else if(selectedFinish!=finishType)
			{
				allStyles[j].parentNode.style.display="none";
				allFinishes[j].parentNode.style.display="none";
				var k = nonMatchingStyles.length;
				nonMatchingStyles[k] = allStyles[j];
			};
		};
		if(styleSubTables[i].parentNode.parentNode.style.display=="none")
		{
		}
		else if(nonMatchingStyles.length==allStyles.length)
		{
			styleSubTables[i].parentNode.parentNode.style.display="none";
		};
	};

	//Formatting the table
	var productTable = document.getElementById("productTable");
	var productTableHeader = allRowsArray[0];
	productTableHeader.style.backgroundColor="#e8e8e8";
	productTableHeader.style.textAlign="center";
	productTableHeader.childNodes[0].style.width="150px";
	productTableHeader.childNodes[1].style.width="200px";
	productTableHeader.childNodes[2].style.width="150px";
	productTableHeader.childNodes[3].style.width="300px";	
	productTableHeader.childNodes[4].style.width="150px";
	var displayedRowsArray = new Array()
	for(i=2; i<allRowsArray.length; i++)
	{
		if(allRowsArray[i].style.display!="none")
		{
			var j = displayedRowsArray.length;
			displayedRowsArray[j]=allRowsArray[i];
		};
	};
	for(i=1; i<displayedRowsArray.length; i=i+2)
	{
		displayedRowsArray[i].style.backgroundColor = "lightyellow";
		displayedRowsArray[i].style.color = "#990000";
		displayedRowsArray[i].style.height="60px";
		displayedRowsArray[i].style.fontSize = "14px";
		var productLinks = displayedRowsArray[i].getElementsByTagName("a");
		productLinks[0].style.color="#990000";
		for(j=0;j<displayedRowsArray[i].childNodes.length;j++)
		{
			displayedRowsArray[i].childNodes[j].style.borderStyle="solid";
			displayedRowsArray[i].childNodes[j].style.borderWidth="1px";
			displayedRowsArray[i].childNodes[j].style.paddingLeft="10px";
		};
	};
	for(i=0; i<displayedRowsArray.length; i=i+2)
	{
		displayedRowsArray[i].style.backgroundColor = "#990000";
		displayedRowsArray[i].style.color = "#FFFF00";
		displayedRowsArray[i].style.height="60px";
		displayedRowsArray[i].style.fontSize = "14px";
		var productLinks = displayedRowsArray[i].getElementsByTagName("a");
		productLinks[0].style.color="#FFFF00";
		for(j=0;j<displayedRowsArray[i].childNodes.length;j++)
		{
			displayedRowsArray[i].childNodes[j].style.borderStyle="solid";
			displayedRowsArray[i].childNodes[j].style.borderWidth="1px";
			displayedRowsArray[i].childNodes[j].style.paddingLeft="10px";
		};
	};
	allRowsArray[1].style.backgroundColor="#e8e8e8";
	allRowsArray[1].style.textAlign="center";
	allRowsArray[1].style.height="30px";
	document.tableFilter.vendorSearch.style.fontSize="11px";
	document.tableFilter.qualitySearch.style.fontSize="11px";
	document.tableFilter.styleSearch.style.fontSize="11px";
	document.tableFilter.finishSearch.style.fontSize="11px";
	}
	else if(browser=="Netscape")
	{
		var selectedManufacturer = document.tableFilter.vendorSearch.options[document.tableFilter.vendorSearch.selectedIndex].firstChild.nodeValue;
		var productTable = document.getElementById("productTable");
		var allRowsArray = new Array();
		for(i=0; i<productTable.childNodes[1].childNodes.length; i++)
		{
			if(productTable.childNodes[1].childNodes[i].nodeName=="TR")
			{
				j = allRowsArray.length;
				allRowsArray[j] = productTable.childNodes[1].childNodes[i];
			};
		};
	//Manufacturer Filter
	for(i=2; i<allRowsArray.length; i++)
	{
		var allCellsArray = allRowsArray[i].getElementsByTagName("td");
		var manufacturer = allCellsArray[0].firstChild.nodeValue;
		if(selectedManufacturer==manufacturer)
		{
			allRowsArray[i].style.display="table-row";
		}
		else if(selectedManufacturer=="All Manufacturers")
		{				
			allRowsArray[i].style.display="table-row";
		}
		else
		{
			allRowsArray[i].style.display="none";
		};
	};
	//Quality Filter
	var selectedQuality = document.tableFilter.qualitySearch.options[document.tableFilter.qualitySearch.selectedIndex].firstChild.nodeValue;
	for(i=2; i<allRowsArray.length; i++)
	{
		var allCellsArray = allRowsArray[i].getElementsByTagName("td");
		var qualityLevel = allCellsArray[2].firstChild.nodeValue;
		if(allRowsArray[i].style.display=="none")
		{
		}
		else if(selectedQuality==qualityLevel)
		{
			allRowsArray[i].style.display="table-row";
		}
		else if(selectedQuality=="All Quality Levels")
		{				
			allRowsArray[i].style.display="table-row";
		}
		else
		{
			allRowsArray[i].style.display="none";
		};
	};
	//Style and Finish Filters
	var selectedStyle = document.tableFilter.styleSearch.options[document.tableFilter.styleSearch.selectedIndex].firstChild.nodeValue;
	var selectedFinish = document.tableFilter.finishSearch.options[document.tableFilter.finishSearch.selectedIndex].firstChild.nodeValue;
	var styleSubTables = Core.getElementsByClass("productStyles");
	var finishSubTables = Core.getElementsByClass("productFinish");
	for(i=0; i<styleSubTables.length; i++)
	{
		var allStyles = styleSubTables[i].getElementsByTagName("td");
		var allFinishes = finishSubTables[i].getElementsByTagName("td");
		var nonMatchingStyles = new Array();
		for(j=0; j<allStyles.length; j++)
		{
			var styleType = allStyles[j].firstChild.nodeValue;
			if(styleType=='Double 6" Extra Long')
			{
				styleType='Double 6"'
			}
			else if(styleType=='Double 4" Extra Long')
			{
				styleType='Double 4"'
			}
			else if(styleType=='Double 4-1/2" Dutchlap Extra Long')
			{
				styleType='Double 4-1/2" Dutchlap'
			}
			else if(styleType=='Double 5" Dutchlap Extra Long')
			{
				styleType='Double 5" Dutchlap'
			};
			if(allRowsArray[i+2].style.display=="none")
			{
			}
			else if(selectedStyle=="All Styles")
			{
				allStyles[j].parentNode.style.display="table-row";
				allFinishes[j].parentNode.style.display="table-row";
			}
			else if(selectedStyle=="Shake & Shingle Siding")
			{
				var brandName = styleSubTables[i].parentNode.parentNode.childNodes[2].firstChild.firstChild.nodeValue;
				var thisRow = allRowsArray[i+2];
				if(brandName=="Cedar Impressions")
				{
					thisRow.style.display="table-row";
					allStyles[j].parentNode.style.display="table-row";
					allFinishes[j].parentNode.style.display="table-row";
				}
				else if(brandName=="Northwoods")
				{
					thisRow.style.display="table-row";
					allStyles[j].parentNode.style.display="table-row";
					allFinishes[j].parentNode.style.display="table-row";
				}
				else if(brandName=="Portsmouth Shake")
				{
					thisRow.style.display="table-row";
					allStyles[j].parentNode.style.display="table-row";
					allFinishes[j].parentNode.style.display="table-row";
				}
				else if(brandName=="Cedar Discovery")
				{
					thisRow.style.display="table-row";
					allStyles[j].parentNode.style.display="table-row";
					allFinishes[j].parentNode.style.display="table-row";
				}
				else
				{
					thisRow.style.display="none";
				};
			}
			else if(selectedStyle!=styleType)
			{
				allStyles[j].parentNode.style.display="none";
				allFinishes[j].parentNode.style.display="none";
				var k = nonMatchingStyles.length;
				nonMatchingStyles[k] = allStyles[j];
			}
			else if(selectedStyle==styleType)
			{
				allStyles[j].parentNode.style.display="table-row";
				allFinishes[j].parentNode.style.display="table-row";
			};
			var finishType = allFinishes[j].firstChild.nodeValue;			
			if(allRowsArray[i+2].style.display=="none")
			{
			}
			else if(allStyles[j].parentNode.style.display=="none")
			{
			}
			else if(selectedFinish=="All Finishes")
			{
				allStyles[j].parentNode.style.display="table-row";
				allFinishes[j].parentNode.style.display="table-row";
			}
			else if(selectedFinish==finishType)
			{
				allStyles[j].parentNode.style.display="table-row";
				allFinishes[j].parentNode.style.display="table-row";
			}
			else if(selectedFinish!=finishType)
			{
				allStyles[j].parentNode.style.display="none";
				allFinishes[j].parentNode.style.display="none";
				var k = nonMatchingStyles.length;
				nonMatchingStyles[k] = allStyles[j];
			};
		};
		if(styleSubTables[i].parentNode.parentNode.style.display=="none")
		{
		}
		else if(nonMatchingStyles.length==allStyles.length)
		{
			styleSubTables[i].parentNode.parentNode.style.display="none";
		};
	};

	//Formatting the table
	var productTableHeader = allRowsArray[0];
	productTableHeader.style.backgroundColor="#e8e8e8";
	productTableHeader.style.textAlign="center";
	productTableHeader.childNodes[0].style.width="150px";
	productTableHeader.childNodes[1].style.width="200px";
	productTableHeader.childNodes[2].style.width="150px";
	productTableHeader.childNodes[3].style.width="300px";	
	productTableHeader.childNodes[4].style.width="150px";
	var displayedRowsArray = new Array()
	for(i=2; i<allRowsArray.length; i++)
	{
		if(allRowsArray[i].style.display!="none")
		{
			var j = displayedRowsArray.length;
			displayedRowsArray[j]=allRowsArray[i];
		};
	};
	for(i=1; i<displayedRowsArray.length; i=i+2)
	{
		displayedRowsArray[i].style.backgroundColor = "lightyellow";
		displayedRowsArray[i].style.color = "#990000";
		displayedRowsArray[i].style.height="60px";
		displayedRowsArray[i].style.fontSize = "14px";
		var productLinks = displayedRowsArray[i].getElementsByTagName("a");
		productLinks[0].style.color="#990000";
		for(j=0;j<displayedRowsArray[i].childNodes.length;j++)
		{
			if(displayedRowsArray[i].childNodes[j].nodeName=="TD")
			{
				displayedRowsArray[i].childNodes[j].style.borderStyle="solid";
				displayedRowsArray[i].childNodes[j].style.borderWidth="1px";
				displayedRowsArray[i].childNodes[j].style.paddingLeft="10px";
				displayedRowsArray[i].childNodes[j].style.borderColor="black";
			};
		};
	};
	for(i=0; i<displayedRowsArray.length; i=i+2)
	{
		displayedRowsArray[i].style.backgroundColor = "#990000";
		displayedRowsArray[i].style.color = "#FFFF00";
		displayedRowsArray[i].style.height="60px";
		displayedRowsArray[i].style.fontSize = "14px";
		var productLinks = displayedRowsArray[i].getElementsByTagName("a");
		productLinks[0].style.color="#FFFF00";
		for(j=0;j<displayedRowsArray[i].childNodes.length;j++)
		{
			if(displayedRowsArray[i].childNodes[j].nodeName=="TD")
			{
				displayedRowsArray[i].childNodes[j].style.borderStyle="solid";
				displayedRowsArray[i].childNodes[j].style.borderWidth="1px";
				displayedRowsArray[i].childNodes[j].style.paddingLeft="10px";
				displayedRowsArray[i].childNodes[j].style.borderColor="black";
			};
		};
	};
	allRowsArray[1].style.backgroundColor="#e8e8e8";
	allRowsArray[1].style.textAlign="center";
	allRowsArray[1].style.height="30px";
	document.tableFilter.vendorSearch.style.fontSize="11px";
	document.tableFilter.qualitySearch.style.fontSize="11px";
	document.tableFilter.styleSearch.style.fontSize="11px";
	document.tableFilter.finishSearch.style.fontSize="11px";
	};
};

var checkSearch = function()
{
		if(location.search=="?Alcoa")
		{
			document.tableFilter.vendorSearch.selectedIndex="1"
		}
		else if(location.search=="?Certainteed")
		{
			document.tableFilter.vendorSearch.selectedIndex="2"
		}
		else if(location.search=="?Crane")
		{
			document.tableFilter.vendorSearch.selectedIndex="3"
		}
		else if(location.search=="?Mastic")
		{
			document.tableFilter.vendorSearch.selectedIndex="4"
		}
		else if(location.search=="?Royal")
		{
			document.tableFilter.vendorSearch.selectedIndex="5"
		};
		else if(location.search=="?Wolverine")
		{
			document.tableFilter.vendorSearch.selectedIndex="6"
		};
		productTableFilters();
};

