var FastFinder = {
   // Elements names
   form_name : "catcustomcontentform88680", // Form name
   el1_name  : "CAT_Custom_119182",         // Core service (radio button)
   el2_name  : "CAT_Custom_119183",         // Service (dropdown)
   el3_name  : "CAT_Custom_119184",         // Solution (dropdown)

   form      : null,
   el1       : null,
   el2       : null,
   el3       : null,

   // List of all services and solutions
   services  : {
   'Utilities Services':[
      {
      'name':'Civil engineering services',
      'options':['Civil engineering project management','Horizontal directional drilling/open excavation/pit installation/cable hauling','Underground civil construction'   ]
      },{
      'name':'Consulting and Analysis',
      'options':['Business process analysis','Consulting and implementation services to the utility sector','Data management and analysis','Data warehousing (for Utilities)','Electricity pole reinstatement design','Smart grid technologies','Smart meters','Spatial data consulting','Utilities data management']
      },{
      'name':'Engineering services',
      'options':['Advanced operational network management technologies','Applications for metered energy consumption','Critical infrastructure security','Electrical construction','Electrical engineering','Engineering solutions (for Utilities)','Technical consulting','Works management']
      },{
      'name':'Environmental services',
      'options':['Energy and Water Conservation','Vegetation management']
      },{
      'name':'Field services',
      'options':['Asset inspection','Asset management services','Billing and asset management','Condition monitoring','Emergency response','Meter data services','Meter installation','Meter reading','New connections','Servicing','Utility labour services','Water/ electrical and gas metering']
      }
   ],
   'ICT Services':[
      {
      'name':'Development and Integration',
      'options':['Application Development']
      },{
      'name':'Packaged Applications',
      'options':['Application Management Services','Business Process Management','Employee Management','Enterprise application implementation and optimisation','ERP Application Solutions and integration - e5','CRM Application Solutions and integration - e5','ERP Application Solutions and integration - JD Edwards','CRM Application Solutions and integration - JD Edwards','ERP Application Solutions and integration - Microsoft','CRM Application Solutions and integration - Microsoft','ERP Application Solutions and integration - Oracle','CRM Application Solutions and integration - Oracle','ERP Application Solutions and integration - Peoplesoft','CRM Application Solutions and integration - Peoplesoft','ERP Application Solutions and integration - SAP','Enterprise Content Management','Human Capital Management','Sharepoint services','Supply Chain Management']
      },{
      'name':'Business Intelligence',
      'options':['Data Warehousing','Information Intelligence','Performance Management and Business Intelligence']
      },{
      'name':'Content Services',
      'options':['IP entertainment solutions (film/television/gaming)']
      },{
      'name':'Green IT',
      'options':['Green IT']
      },{
      'name':'ICT Consulting Services',
      'options':['Business Tranformation and Change','Business Process Mapping','COBIT','ICT Consulting Services','ICT Strategy and Architecture','ICT Strategy Consulting','ITIL Service Management Consulting','ITIL Service Management Education and Training','Management and Technology Consulting','Service Oriented Architecture (SOA) advice and guidance','Information Management']
      },{
      'name':'ICT Outsourcing',
      'options':['ICT Outsourcing Services']
      },{
      'name':'ICT Infrastructure',
      'options':['Critical ICT infrastructure','Data Centre Solutions','Data Storage Management','Enterprise infrastructure architecture','Hardware Maintenance Services','ICT Optimisation Services','IT Infrastructure Services','Network Management','Service Desk','Storage Solutions','Sustainable workspace']
      },{
      'name':'Project Management',
      'options':['Project and Programme Management']
      },{
      'name':'Security Services Customer',
      'options':['Customer Data Integrity and Identity Management']
      },{
      'name':'Telephony and Contact Centre',
      'options':['Contact Centre Implementation and Optimisation','On-demand IP Telephony Services','Telecommunications and Network Consulting','Telecommunications Advisory Services','Telecommunications Benchmarking','Telecommunications Expense Management','Telecommunications Planning and Design Services','Telecommunications Research and Analysis','Unified Communications Advice and Guidance','Unified Communications Solutions','Voice and Data Networking Solutions']
      },{
      'name':'Training Services',
      'options':['Best Practices Training','Change Management Training','ITIL Training','PMBOK Training','Project Management Education and Training','Training Services']
      }
   ]},

   on_load : function(){
      var ff = FastFinder;

      for(var i = 0; i < document.forms.length; i++){
         if(document.forms[i].name == ff.form_name){ ff.form = document.forms[i]; break; }
      }

      if(!ff.form){ return; }

      if(ff.form.addEventListener){
        ff.form.addEventListener('submit', ff.on_submit, false);
      } else if (window.attachEvent) {
        ff.form.attachEvent('onsubmit', ff.on_submit);
      } else {
        ff.form.onsubmit = ff.on_submit;
      }

      ff.el1  = ff.form[ff.el1_name];
      ff.el2  = ff.form[ff.el2_name];
      ff.el3  = ff.form[ff.el3_name];
      ff.el2.options.length = 1;
      ff.el2.options[0] = new Option("Please select ICT or Utilities services","",true,true);

      ff.el3.options.length = 1;
      ff.el3.options[0] = new Option("Please select a service","",true,true);

      ff.el1[0].onclick = ff.el1[1].onclick = ff.on_core_service_change;
      ff.el2.onchange = ff.on_service_change;

      ff.on_core_service_change();
   },

   on_core_service_change : function(e){
      var ff = FastFinder;

      if(!ff.el1[0].checked && !ff.el1[1].checked){ return; }
      var group_name = (ff.el1[0].checked) ? ff.el1[0].value : ff.el1[1].value;

      ff.el2.options.length = ff.services[group_name].length + 1;
      ff.el2.options[0] = new Option("(Click here to select)","",true,true);
      for(var i = 0; i < ff.services[group_name].length; i++){
         ff.el2.options[i + 1] = new Option(ff.services[group_name][i]['name'],ff.services[group_name][i]['name'],false,false);
      }
      ff.el2.selectedIndex = 0;

      ff.el3.options.length = 1;
      ff.el3.options[0] = new Option("Please select a service first","",true,true);
   },

   on_service_change : function(e){
      var ff = FastFinder;

      if(!ff.el1[0].checked && !ff.el1[1].checked){ return; }
      var group_name = (ff.el1[0].checked) ? ff.el1[0].value : ff.el1[1].value;

      if(ff.el2.selectedIndex < 1){
         ff.el3.options.length = 1;
         ff.el3.options[0] = new Option("Please select a service first","",true,true);
         return;
      }

      var solutions = ff.services[group_name][ff.el2.selectedIndex - 1]['options'];
      ff.el3.options.length = solutions.length + 1;
      ff.el3.options[0] = new Option("(Click here to select)","",true,true);
      for(var i = 0; i < solutions.length; i++){
         ff.el3.options[i + 1] = new Option(solutions[i],solutions[i],false,false);
      }
      ff.el3.selectedIndex = 0;
   },

   on_submit : function(e){
      var ff = FastFinder;

      if(!ff.el1[0].checked && !ff.el1[1].checked){
         alert("Please select a group of services first.");
         return false;
      }

      if(ff.el2.selectedIndex < 1){
         alert("Please select a service.");
         return false;
      }

      if(ff.el3.selectedIndex < 1){
         alert("Please select a solution.");
         return false;
      }

      return true;
   }
};

if(window.addEventListener){
  window.addEventListener('load', FastFinder.on_load, false);
} else if (window.attachEvent) {
  window.attachEvent('onload', FastFinder.on_load);
} else {
  window.onload = FastFinder.on_load;
}

