/*
* 05/24/2007 Prakash Seetharaman(Wipro Technologies)
* Element tool ticket No: 3611
* Description: To sort the Manufacturer Drop down list. Changed one function and added one function.
* Modified function: function processMfrCodesForTopCatKey()
*/

// ET - 3611 - Adding Sort Function : Start
function bubbleSort(arrayName,length) {
    for (var i=1; i<(length-1); i++) {
        for (var j=i+1; j<length; j++) {
            if (arrayName[j].text < arrayName[i].text) {
                var dummy = arrayName[i];
                arrayName[i] = arrayName[j];
                arrayName[j] = dummy;
            }
        }
     }   
}

// ET - 3611 : End 

   function processMfrCodesForTopCatKey(){
            var f = this.document.query;
            f.manufacturer.options.length = 1;
            f.categoryIDs.value = f.by_category.options[f.by_category.selectedIndex].value;
            var cKey = f.by_category.options[f.by_category.selectedIndex].value;
            if ( cKey == null ) {
                cKey = "";
            }
            var iI = 1;
            if(cKey!='') {
	            //	ET - 3611  : Start
	            
				//	Creating a new array.
    		    var sortMfr = new Array();
				
				// Commenting the existing code and storing the values into the new array.
				for( var ii=0; ii<cA.length; ii++ ) {
					if ( (cA[ii].C == cKey)) {
					//	f.manufacturer.options[iI] = new Option();
					//	f.manufacturer.options[iI].value = cA[ii].M;
					//	f.manufacturer.options[iI++].text = cA[ii].N;
						sortMfr[iI] = new Option();
						sortMfr[iI].value = cA[ii].M;
						sortMfr[iI++].text = cA[ii].N;
					}

				}
				//	Calling the Sort function and then assigning teh sorted result to the Select Box
				bubbleSort(sortMfr, sortMfr.length);		
				for (var ij = 1; ij < sortMfr.length; ij++) {
					f.manufacturer.options[ij] = sortMfr[ij];				
				}
	            //	ET - 3611  : End
            }else{

              for( var ii=0; ii<defAllMfr.length; ii++ ) {

                   f.manufacturer.options[iI] = new Option();
				   f.manufacturer.options[iI].value = defAllMfr[ii].M;
				   f.manufacturer.options[iI++].text = defAllMfr[ii].N;
               }
            }
        }
        function processSearchTips()
		{
		    searchTipWindow = window.open( "../htdocs/search/CatalogNormalSearchTips.html", "SearchTips", "directories=no,toolbar=no,menubar=no,scrollbars=yes,resizable=no,height=540,width=720");
		}
        		function processDotDotDot()
		{
			this.document.query.showAll2ndLink.value = "true";
			gotoPage(++document.query.currPageNum.value);
		}
        	///////////////////////////////////////////////////
		// functions for picker
			var pickerWindow = null;
		function browsePartner()
		{
				// invoke the picker
			    pickerWindow = window.open( "", "AssignPartner", "directories=no,toolbar=no,menubar=no,scrollbars=no,resizable=no,height=500,width=350");
			    document.picker.target = "AssignPartner";
			    document.picker.submit();
			}
			// This is the function get invoked by the picker
			function processPick(val)
			{
				entity = val[0];
				opt = new Option();
				opt.text = entity.dispName;
				opt.value = entity.ID;
				//opt.selected = true;
				//this.document.query.filterByPartner.value = val[0].ID;
				this.document.query.filterByPartner.options[0] = opt;
				this.document.query.partnerName.value=entity.dispName;
				//this.document.query.filterByPartner.selectedIndex=0;

				pickerWindow = null;
			}

			function resetPartner()
			{
				this.document.query.filterByPartner.options[0] = null;
				this.document.query.partnerName.value="";

				if(this.document.query._search_filter_supplierID)
				{
					this.document.query._search_filter_supplierID.value="";
				}
			}
        
