﻿var operator_selector = {

  subtitle1: {},
  pricing1: {},

  init: function(subtitle1_json, pricing_text1_json) {
    this.subtitle1 = subtitle1_json;
    this.pricing1 = pricing_text1_json;

    if (!this.subtitle1['default']) this.subtitle1['default'] = '';
    if (!this.pricing1['default']) this.pricing1['default'] = '';

    if (Get_Cookie('retry') == 'telco') {
      alert('It looks like the number you submitted doesn\'t match the carrier you selected.');
      Set_Cookie('retry', null);
    }
  },

  handle: function() {
    try {
      var operatorlist = $('#operatorlist');
      if (operatorlist.attr('selectedIndex') == 0) return;

      var operator_code = operatorlist.val();
      this.showSpecificText(operator_code);

      $('#inputzone_p1').hide();
      $('#inputzone_p2').show();
    } catch (e) {
//      alert (e.message);
    }
  },

  handleGridSelect: function(operator_code) {
    if (operator_code === null) {
//      alert ('oops');
      $('#operator_hidden').attr('disabled', 'disabled');
    }
    else {
//      alert (operator_code);
      $('#operator_hidden').val(operator_code);
//      alert ($('#operator_hidden').val());

      this.showSpecificText(operator_code);
    }

    $('#inputzone_p1').hide();
    $('#inputzone_p2').show();
  },

  showSpecificText: function(operator_code) {
    if ($('#subtitle1').length > 0) {
      if ((typeof this.subtitle1[operator_code]).toLowerCase() == 'string') { // check if it exists
        $('#subtitle1').html(this.subtitle1[operator_code]); // this may be empty
      } else {
        $('#subtitle1').html(this.subtitle1['default']); // use default one
      }
    }

    if ($('#pricing1').length > 0) {
      if ((typeof this.pricing1[operator_code]).toLowerCase() == 'string') { // check if it exists
        $('#pricing1').html(this.pricing1[operator_code]); // this may be empty
      } else {
        $('#pricing1').html(this.pricing1['default']); // use default one
      }
    }
  }
};
