// Array.indexOf( value, begin, strict ) - Return index of the first element that matches value
Array.prototype.indexOf = function( v, b, s ) {
 for( var i = +b || 0, l = this.length; i < l; i++ ) {
  if( this[i]===v || s && this[i]==v ) { return i; }
 }
 return -1;
};

window.onload = page_onload;

function page_onload() {
//alert("onload");
    categoryList_onchange(document.selectCategory.Category_ID.value);
}

function categoryList_onchange(categoryID) {
    //clear old sub categories
    var selectSubCategory = document.selectCategory.Document_ID.options;
    //for (j=1;j<selectSubCategory.length;j++) {
    //    selectSubCategory[j]=null;
    //}
    selectSubCategory.length=1;
    for (i=0;i<productCategories.length;i++) {
        //alert(productCategories[i][1]);
        if(productCategories[i][0]==categoryID) {
            //alert(productCategories[i][2]);
            selectSubCategory[selectSubCategory.length] = new Option(productCategories[i][2],productCategories[i][1]);
            
        }
    }
}

function selectCategory_onsubmit() {
    if(document.selectCategory.Category_ID.selectedIndex == "") {
        alert("Please select a category");
        return false;
    } else if(document.selectCategory.Document_ID.selectedIndex == "") {
        alert("Please select a sub category");
        return false;
    } else {
        return true;
    }
}