
function FilterOnLoad()
{
	var supplierList = document.getElementsByTagName('select')[1];
	//if(supplierList.selectedIndex > 0){
		FilterPatterns(supplierList);
	//}
	
}

function Guidelines()
{
	var win = window.open("/App/Design/COMGuidelines.aspx", "", "width=700 height=375 scrollbars=yes");
}


// recursively gets an object's height
function GetTotalOffsetTop(obj) {
    if (obj.parentNode == null) {
        return 0;
    }
    else {

        return obj.offsetTop + GetTotalOffsetTop(obj.parentNode.parentNode);
    }
}


function DisplaySubRow(obj) {

    var nextSib = obj.parentNode.parentNode.nextSibling;
    //var offsetHeight = GetTotalOffsetTop(obj.parentNode);

    if (nextSib.style.display == 'inline') {
        nextSib.style.display = 'none';
        //obj.firstChild.src = "./Images/nof_details_bullet.gif"
        obj.src = "/app/images/nof_details_bullet.gif"
    }
    else {
        nextSib.style.display = 'inline';
        //obj.firstChild.src = "./Images/nof_close_details_bullet.gif"
        obj.src = "/app/images/nof_close_details_bullet.gif"
    }
    
    //setTimeout("window.scrollTo(0," + offsetHeight + ")", 1); 
    
}

function FilterPatternsForThis(obj) {
    // get supplier dropdown
    var previousSelectionBox = obj.parentNode.parentNode.parentNode.firstChild.nextSibling.firstChild.nextSibling.firstChild;
    FilterPatterns(previousSelectionBox);

    obj.focus();
}

function ShowHideFooter(obj) {
    var footerMain = obj.parentNode.parentNode.nextSibling.firstChild.firstChild;
    //alert(footerMain);
    if (footerMain.style.display == "none") {
        footerMain.style.display = "inline";
        //obj.firstChild.src = "./Images/nof_button_hide.gif"
        obj.src = "/app/images/nof_button_hide.gif"
    }
    else{
        footerMain.style.display = "none";
        //obj.firstChild.src = "./Images/nof_button_show.gif"
        obj.src = "/app/images/nof_button_show.gif"
    }
}

function FilterPatterns(obj) {

    var allPatterns = obj.parentNode.parentNode.nextSibling.childNodes[1].firstChild;
    var subPatterns = allPatterns.nextSibling;

    var currentValue = subPatterns.options[subPatterns.selectedIndex].value;

    while (subPatterns.length > 0) {
        subPatterns.remove(0);
    }


    var i;


    for (i = 0; i < allPatterns.length; i++) {

        var bPass = false;

        if (obj.value == "-1") {
            bPass = true;
        }
        else if (allPatterns.options[i].getAttributeNode("SupplierID") == null) {
            
            bPass = true;
        }
        else if (allPatterns.options[i].getAttributeNode("SupplierID").value == obj.value) {
        
            bPass = true;
        }

        if (bPass) {
            var optn = document.createElement("OPTION");
            optn.text = allPatterns.options[i].text;
            optn.value = allPatterns.options[i].value;
            
            subPatterns.options.add(optn);

            if (optn.value == currentValue) {
                subPatterns.selectedIndex = subPatterns.length - 1;
            }

        }

    }
    

    var SeriesDropdownList = allPatterns.parentNode.parentNode.nextSibling.childNodes[1].firstChild;
	var searchButton = SeriesDropdownList.parentNode.parentNode.nextSibling.firstChild.firstChild;

	//alert(obj.selectedIndex + " " + subPatterns.selectedIndex);

    if (obj.selectedIndex == 0 && subPatterns.selectedIndex == 0) {
        SeriesDropdownList.disabled = true;
        SeriesDropdownList.selectedIndex = 0;
        searchButton.style.display = 'none';
        
    }
    else{
        SeriesDropdownList.disabled = false;
        searchButton.style.display = 'inline';
    }
    
} 


