﻿
mobileMsg = '- Mobile Number.';
mobileMsg2 = '- Do not include 0 as the first digit of cell phone number.';
operatorMsg = '- Operator.';
alertMsg1 = 'The following information is missing or invalid:';
alertMsg2 = 'Please make sure you have provided the above information correctly before submitting the data.';
pinCodeMsg = 'Please enter the PIN';

function checkPhone()
{
  if ($('body').hasClass('iphone') || $('#msisdn').length > 0) {
    var p = $('#msisdn').val().length;
    return (p == 10);
  }

  var a = $('#msisdn_areacode').val().length;
  var p = $('#msisdn_prefix').val().length;
  var s = $('#msisdn_suffix').val().length;

  if (a == 3 && p == 3 && (s == 4 || s == 5)) {
    return true;
  }
  return false;
}

function checkPhone2()
{
  if ($('body').hasClass('iphone') || $('#msisdn_areacode').length == 0)
    return true;

  if ($('#msisdn_areacode').val().charAt(0) != 0) {
    return true;
  }
  return false;
}

/**
 * @param inputtext1_txt
 * @param lp_result_txt
 */
function sc_telco_txt_decorator_31003(inputtext1_txt, lp_result_txt)
{
  var $inputtext1 = $('#inputzone #inputtext1');

  if (inputtext1_txt) {
    $inputtext1.html(inputtext1_txt);

    lp_result_txt += '<p><a href="#" onclick="$(\'#popup1\').dialog(\'close\'); return false;">Continue</a></p>';

    // Create dialog
    $('#popup1').html(lp_result_txt).dialog({
      autoOpen: 0,
      closeOnEscape: 0,
      draggable: 0,
      position: ['center', 200],
      modal: 1,
      resizable: 0,
      width: 800,
      close: function(event, ui) {
        if ($('#msisdn_areacode').length) {
          if ($('#msisdn_areacode').val().length < 3)     $('#msisdn_areacode').focus();
          else if ($('#msisdn_prefix').val().length < 3)  $('#msisdn_prefix').focus();
          else if ($('#msisdn_suffix').val().length < 4)  $('#msisdn_suffix').focus();
        }
      }
    });

    $('#pricing1, #pricing1 a').css({
      'color':        $inputtext1.css('color'),
      'font-family':  $inputtext1.css('font-family'),
      'font-size':    $inputtext1.css('font-size'),
      'font-weight':  $inputtext1.css('font-weight'),
      'font-style':   $inputtext1.css('font-style'),
      'text-align':   $inputtext1.css('text-align')
    });

    $('#pricing1 a.lp_result_popup').click(function(e) {
      e.preventDefault();
      $('#popup1').dialog('open');
    });
  }
}

/**
 * @param inputtext1_txt not used
 * @param lp_result_txt
 */
function sc_telco_txt_decorator_31003_v2(inputtext1_txt, lp_result_txt)
{
  var $inputtext1 = $('#inputzone #inputtext1');

  if ($inputtext1.length) {
//    $inputtext1.html(inputtext1_txt);

    lp_result_txt += '<p><a href="#" onclick="$(\'#popup1\').dialog(\'close\'); return false;">Continue</a></p>';

    // Create dialog
    $('#popup1').html(lp_result_txt).dialog({
      autoOpen: 0,
      closeOnEscape: 0,
      draggable: 0,
      position: ['center', 200],
      modal: 1,
      resizable: 0,
      width: 800,
      close: function(event, ui) {
        if ($('#msisdn_areacode').length) {
          if ($('#msisdn_areacode').val().length < 3)     $('#msisdn_areacode').focus();
          else if ($('#msisdn_prefix').val().length < 3)  $('#msisdn_prefix').focus();
          else if ($('#msisdn_suffix').val().length < 4)  $('#msisdn_suffix').focus();
        }
      }
    });

    $('#pricing1').css({
      'margin-bottom': '10px'
    });
    $('#pricing1, #pricing1 a').css({
      'color':        $inputtext1.css('color'),
      'font-family':  $inputtext1.css('font-family'),
      'font-size':    '16px',
      'font-weight':  $inputtext1.css('font-weight'),
      'font-style':   $inputtext1.css('font-style'),
      'text-align':   $inputtext1.css('text-align')
    });

    $('#pricing1 a.lp_result_popup').click(function(e) {
      e.preventDefault();
      $('#popup1').dialog('open');
    });
  }
}

/**
 * @param destination string: url ended with '?' or '&'
 * @param operator_code string
 */
function operater_redirect(destination, operator_code)
{
  var url = window.location.href;
  var url_params = url.substr(url.indexOf('?') + 1);
  if (typeof landingControlHolder['precontroller'] == 'object') {
    if (typeof (landingControlHolder['precontroller'].getParamString) == 'function') {
      // new params should be append at beginning
      url_params = landingControlHolder['precontroller'].getParamString() + '&' + url_params;
    }
  }
  url_params = 'operator=' + operator_code + '&' + url_params;

  var glue = '';
  if ($.inArray(destination.charAt(destination.length-1), ['?', '&']) == -1) { // last character is neither '?' nor '&'
    glue = (destination.indexOf('?') == -1 ? '?' : '&');
  }

  window.location.href = destination + glue + url_params;
}

