﻿
      var laCmdts = Array('Business Travel|Vehicle Hire',
                          'Business Travel|Taxis',
                          'Business Travel|Rail',
                          'Business Travel|Hotels',
                          'Business Travel|Ferry',
                          'Business Travel|Coach',
                          'Business Travel|Booking Services',
                          'Business Travel|Air',
                          'Clinical and Medical|Radiological & Other Diagnostic',
                          'Clinical and Medical|Patients Appliances',
                          'Clinical and Medical|Pathology',
                          'Clinical and Medical|Medical and Surgical Equipment',
                          'Clinical and Medical|Medical and Surgical Consumables',
                          'Clinical and Medical|Drugs & Biologicals',
                          'Construction|Construction Supplies',
                          'Construction|Building, Repair and Maintenance', 
                          'Energy and Utilities|Water',
                          'Energy and Utilities|Solid Fuels',
                          'Energy and Utilities|Gas',
                          'Energy and Utilities|Electricity',
                          'Engineering Goods|Tools',
                          'Engineering Goods|Non-Medical Chemicals',
                          'Engineering Goods|Industrial',
                          'Facilities|Security',
                          'Facilities|Office Furniture',
                          'Facilities|Food',
                          'Facilities|Construction Supplies',
                          'Facilities|Cleaning',
                          'Facilities|Catering',
                          'Facilities|Building, Repair and Maintenance',
                          'Facilities|Building Management',
                          'Facilities|Accomodation Services',
                          'Fuels, Lubricants & Gases|Lubricants',
                          'Fuels, Lubricants & Gases|Gases',
                          'Fuels, Lubricants & Gases|Fuels',
                          'ICT|Telecoms',
                          'ICT|Systems Delivery',
                          'ICT|Software',
                          'ICT|Networks',
                          'ICT|Managed/Outsourced Service',
                          'ICT|ICT Maintenance and Support',
                          'ICT|Hardware',
                          'Logistics|Warehousing & Storage',
                          'Logistics|Transport',
                          'Medical|Medical Equipment',
                          'Marketing and Media|Promotion',
                          'Marketing and Media|Marketing',
                          'Marketing and Media|Events Organisation',
                          'Marketing and Media|Advertising',
                          'Office Solutions|Reprographics',
                          'Office Solutions|Records Storage and Archiving',
                          'Office Solutions|Print',
                          'Office Solutions|Post & Courier',
                          'Office Solutions|Office Supplies',
                          'Office Solutions|Office Services',
                          'Office Solutions|Office Machines',
                          'Office Solutions|Office Consumables',
                          'Operational Goods|Non-Catering Vend Mach',
                          'Operational Goods|Learning and Development Materials',
                          'Operational Goods|Environmental Materials',
                          'Operational Goods|Domestic Goods',
                          'Operational Goods|Clothing',
                          'Operational Goods|Animal Related Goods',
                          'Operational Goods|Art & Exhibits',
                          'Personnel Related|Staff Subscriptions',
                          'Personnel Related|Staff Relocation',
                          'Personnel Related|Staff Medical Care',
                          'Personnel Related|Staff Health & Safety',
                          'Personnel Related|Staff Child Care',
                          'Professional Services Other|Technical Services',
                          'Professional Services Other|Operational Services',
                          'Professional Services Other|Learning and Development Services',
                          'Professional Services Other|Interpretation and Translation Services',
                          'Professional Services Other|Financial Services',
                          'Professional Services Other|Environmental Services',
                          'Professional Services Other|Construction Service Providers',
                          'Professional Services Other|Clinical Support Services',
                          'Professional Services Consultancy|Technical Consultancy',
                          'Professional Services Consultancy|Strategy Consultancy',
                          'Professional Services Consultancy|Procurement Consultancy',
                          'Professional Services Consultancy|Property/Estates Consultancy',
                          'Professional Services Consultancy|PPM Consultancy',
                          'Professional Services Consultancy|Org dev Consultancy',
                          'Professional Services Consultancy|Marketing Consultancy',
                          'Professional Services Consultancy|Legal Consultancy',
                          'Professional Services Consultancy|ICT Consultancy',
                          'Professional Services Consultancy|HR Consultancy',
                          'Professional Services Consultancy|Financial Consultancy',
                          'Professional Services Consultancy|Environmental Consultancy',
                          'Professional Services Temporary Staff|Specialist Contractors',
                          'Professional Services Temporary Staff|Admin/Clerical',
                          'Professional Services Temporary Staff|Interim Managers',
                          'Social Care|World Programmes',
                          'Social Care|Welfare to Work',
                          'Social Care|Transport Provision',
                          'Social Care|Operation of Custodial Facilities',
                          'Social Care|Legal Aid',
                          'Social Care|Entertainment Services',
                          'Social Care|Emergency Services',
                          'Social Care|Educational Programmes',
                          'Social Care|Adult Social Care',
                          'Social Care|Child Social Care',
                          'Vehicles|Vehicle Maintenance',
                          'Vehicles|Vehicle Disposal',
                          'Vehicles|Purchase',
                          'Vehicles|Lease',
                          'Vehicles|Fleet Management',
                          'Waste Management|Waste Services',
                          'Waste Management|Waste Equipment');


      function setCommodityField(frm) {
      
        fldFrom = frm.masterCategory;
        fldTo = frm.commodityArea;
        var fldFromVal = fldFrom.options[fldFrom.selectedIndex].value;
        // Remove all the options from the 'to' list
        fldTo.options.length = 0;
        // Populate the 'to' list with the relevant items
        for (i = 0; i <= laCmdts.length-1; i++) {
          // Insert the first option
          if (i == 0) {
            insertOldSchool(fldTo, '- Select a Commodity Area (optional) -', 'none');
          }
          
          if (laCmdts[i].indexOf(fldFromVal) != -1) {
            
            //alert(laCmdts[i]);
            lsListValue = laCmdts[i]
            delim = lsListValue.indexOf('|');
            
            sTemp = lsListValue.substring(0,delim);
           
            lsListValue = lsListValue.substring(delim+1, lsListValue.length);
            
            if(sTemp == fldFromVal) {
               // Append the subsequent options.
               appendOldSchool(fldTo, lsListValue, lsListValue);
            }
           
            
          }
        }
        fldTo.style.color = '#222';
        fldTo.disabled = 0;
        fldTo.onchange = '';
        
      }

      var ios = 0;
      var aos = 0;
      function insertOldSchool(theSel, newText, newValue) {
        if (theSel.length == 0) {
          var newOpt1 = new Option(newText, newValue);
          theSel.options[0] = newOpt1;
          theSel.selectedIndex = 0;
        } else if (theSel.selectedIndex != -1) {
          var selText = new Array();
          var selValues = new Array();
          var selIsSel = new Array();
          var newCount = -1;
          var newSelected = -1;
          var i;
          for(i=0; i<theSel.length; i++) {
            newCount++;
            if (newCount == theSel.selectedIndex) {
              selText[newCount] = newText;
              selValues[newCount] = newValue;
              selIsSel[newCount] = false;
              newCount++;
              newSelected = newCount;
            }
            selText[newCount] = theSel.options[i].text;
            selValues[newCount] = theSel.options[i].value;
            selIsSel[newCount] = theSel.options[i].selected;
          }
          for(i=0; i<=newCount; i++) {
            var newOpt = new Option(selText[i], selValues[i]);
            theSel.options[i] = newOpt;
            theSel.options[i].selected = selIsSel[i];
          }
        }
        theSel.options[0].selected = 1;
      }

      function appendOldSchool(theSel, newText, newValue) {
        if (theSel.length == 0) {
          var newOpt1 = new Option(newText, newValue);
          theSel.options[0] = newOpt1;
          theSel.selectedIndex = 0;
        } else if (theSel.selectedIndex != -1) {
          var selText = new Array();
          var selValues = new Array();
          var selIsSel = new Array();
          var newCount = -1;
          var newSelected = -1;
          var i;
          for(i=0; i<theSel.length; i++) {
            newCount++;
            selText[newCount] = theSel.options[i].text;
            selValues[newCount] = theSel.options[i].value;
            selIsSel[newCount] = theSel.options[i].selected;
            if (newCount == theSel.selectedIndex) {
              newCount++;
              selText[newCount] = newText;
              selValues[newCount] = newValue;
              selIsSel[newCount] = false;
              newSelected = newCount - 1;
            }
          }
          for(i=0; i<=newCount; i++) {
            var newOpt = new Option(selText[i], selValues[i]);
            theSel.options[i] = newOpt;
            theSel.options[i].selected = selIsSel[i];
          }
        }
      }

      function removeOldSchool(theSel,theIndex) {
        var selIndex = theSel.selectedIndex;
        if (theIndex != '') {
          var selIndex = theIndex;
        }
        if (selIndex != -1) {
          for(i=theSel.length-1; i>=0; i--)
          {
            if(theSel.options[i].selected)
            {
              theSel.options[i] = null;
            }
          }
          if (theSel.length > 0) {
            theSel.selectedIndex = selIndex == 0 ? 0 : selIndex - 1;
          }
        }
      }
      
      
      function validateMASTERForm(frm) {
        fldA = frm.masterCategory;
        frm.srchType.value = '1';
        if (fldA.selectedIndex == 0) {
          alert('Please select a Master Category and try again.');
          fldA.focus();
          return false;
        }
        return true;
      }
      function validateSECTORForm(frm) {
        fldA = frm.department;
        frm.srchType.value = '2';
        if (fldA.selectedIndex == 0) {
          alert('Please select a sector and try again.');
          fldA.focus();
          return false;
        }
        return true;
      }
      function validateREGIONForm(frm) {
        fldA = frm.region;
        frm.srchType.value = '3';
        if (fldA.selectedIndex == 0) {
          alert('Please select a Region and try again.');
          fldA.focus();
          return false;
        }
        return true;
      }
      function validateWHOLEForm(frm) {
        fldA = frm.masterCategory;
        fldB = frm.commodityArea;
        fldC = frm.department;
        fldD = frm.region;
        frm.srchType.value = 'all';
        if (fldA.selectedIndex == 0 && fldB.selectedIndex == 0 && fldC.selectedIndex == 0 && fldD.selectedIndex == 0)  {
          alert('Please make at least one selection and try again.');
          fldA.focus();
          return false;
        }
        return true;
      }
      function validateSEARCHForm(frm) {
        fldA = frm.query;
        if (fldA.value == '')  {
          alert('Please type a search term and try again.');
          fldA.focus();
          return false;
        }
        return true;
      }
      
