/**
 *
 * @authors Eric Hsiao
 *
 */

/* utlis */

const PRE__HOST = 'declarepre.taiwanpay.com.tw';
const PRO__HOST = 'declare.taiwanpay.com.tw';

var API__DOMAIN;
var URL__LIFF__ID;
var URL__REGISTER;

var PRE__DOMAIN = 'https://declarepre.taiwanpay.com.tw/';
var PRE__LIFF__ID = '1653763567-7LbdbKaM';
var PRE__REGISTER = 'https://liff.line.me/1653763567-E6Z3Z2qX?app=1653763567-E6Z3Z2qX';

var PRO__DOMAIN = 'https://declare.taiwanpay.com.tw/';
var PRO__LIFF__ID = '1653764192-M6X5X552';
var PRO__REGISTER = 'https://liff.line.me/1653764192-dx6l6llK?app=1653764192-dx6l6llK';

/***************************************************/

function gtag_pageView(_key) {
  //ga('send', 'pageview', key);
  gtag('config', GTAG_TRACKING_ID, {
    'page_title': _key,
    'page_path': '/' + _key
  });

  console.log("gtag_pageView: " + _key);
}

function gtag_ButtonClick(_key) {
  //ga('send', 'event', 'Button', 'Click', key);
  gtag('event', 'Click', { 'event_category': 'Button', 'event_label': _key });

  console.log("gtag_ButtonClick: " + _key);
}

function setDefault(_textbox, _value) { // depend on jQuery
  $(_textbox).val(_value).css({ opacity: .4 });
  $(_textbox).focus(
    function () {
      if ($(this).val() == _value) {
        $(this).val('').css({ opacity: 1 });
      }
    })
    .blur(function () {
      if ($(this).val() == '') {
        $(this).val(_value).css({ opacity: .4 });
      }
    });
}

function setParameterByName(name, value, url) {
  if (!url) url = window.location.href;
  var re = new RegExp("([?|&])" + name + "=.*?(&|$)", "i");
  separator = url.indexOf('?') !== -1 ? "&" : "?";
  if (url.match(re)) {
    return url.replace(re, '$1' + name + "=" + value + '$2');
  }
  else {
    return url + separator + name + "=" + value;
  }
}

function getParameterByName(name, url) {
  if (!url) url = window.location.href;
  name = name.replace(/[\[\]]/g, "\\$&");
  var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
    results = regex.exec(url);
  if (!results) return '';
  if (!results[2]) return '';
  return decodeURIComponent(results[2].replace(/\+/g, " "));
}


var isMobile = false;
var isIE = false;

utlis = function () {

  //private menbers


  //private methods
  function init() {
    console.log('all is loaded.');
  }

  //constructor

  {
    if ($('html').is('.ie6, .ie7, .ie8')) {
      isIE = true;
      // alert('.ie6, .ie7, .ie8');
    }

    var _URL = location.hostname;
    var _host;

    if (_URL.indexOf(PRO__HOST) != -1) {
      API__DOMAIN = PRO__DOMAIN;
      URL__LIFF__ID = PRO__LIFF__ID;
      URL__REGISTER = PRO__REGISTER;
    } else {
      API__DOMAIN = PRE__DOMAIN;
      URL__LIFF__ID = PRE__LIFF__ID;
      URL__REGISTER = PRE__REGISTER;
    }

    console.log('API__DOMAIN : ' + API__DOMAIN);

    $(document).ready(function () {

      if ($('body').width() <= 640) {
        isMobile = true;
      } else {
        isMobile = false;
      }

      init();
    });
  }

  //public

  return {

  }
}

utlis = new utlis();