/* Js for , Version=1790006968 */
 v.lang = {"confirmDelete":"Do you want to delete it?","deleteing":"Deleting","doing":"Doing","loading":"Loading","updating":"Updating","timeout":"Timeout. Please try it again.","errorThrown":"Error : ","continueShopping":"Continue shopping","required":"Required","back":"Back","continue":"Continue","bindWechatTip":"Posting sets the limit for binding WeChat. Please bind WeChat user first.","importTip":"Old layout data will be replaced","fullImportTip":"Old article, product, layout data will be replaced and import test data"};;v.formLayout = "global";; 
$(document).ready(function()
{
    $(".chosen").chosen({no_results_text: 'No match found!', placeholder_text:' ', disable_search_threshold: 10, width: '100%', search_contains: true});
    $('select.chosen-icons').chosenIcons({lang: 'en'});
});
;
$(function()
{
    
    $.fn.fixedDate = function()
    {
        return $(this).each(function()
        {
            var $this = $(this);
            if($this.offset().top + 200 > $(window).height())
            {
                $this.attr('data-picker-position', 'top-right');
            }

            if($this.val() == '0000-00-00')
            {
                $this.focus(function(){if($this.val() == '0000-00-00') $this.val('').datetimepicker('update');}).blur(function(){if($this.val() == '') $this.val('0000-00-00')});
            }
        });
    };
    
    
    var options = 
    {
        language: 'en',
        weekStart: 1,
        todayBtn:  1,
        autoclose: 1,
        todayHighlight: 1,
        startView: 2,
        forceParse: 0,
        showMeridian: 1,
        format: 'yyyy-mm-dd hh:ii'
    };

    
    var dateOptions = $.extend({}, options, {minView: 2, format: 'yyyy-mm-dd'});
    var timeOptions = $.extend({}, options, {startView: 1, minView: 0, maxView: 1, format: 'hh:ii'});

    $('.form-datetime').fixedDate().datetimepicker(options);
    $('.form-date').fixedDate().datetimepicker(dateOptions);
    $('.form-time').fixedDate().datetimepicker(timeOptions);

    $('.datepicker-wrapper').click(function()
    {
        $(this).find('.form-date, .form-datetime, .form-time').datetimepicker('show').focus();
    });

    $('.input-append.date').on('click', function(){
        $(this).find('input').datetimepicker('show').focus();
    }).find('input').datetimepicker($.extend({}, options, {pickerPosition: 'top-right'}));
    
});
;v.confirm = "Are you sure to submit?";;v.fullScreen = 0;;v.type = "form";;v.formID = 4;;v.itemTotal = 0;;v.pageTotal = 0;;v.page = 1;;$(function()
{
    //if(v.fullScreen == 0 && $('.col-side').length > 0)
    //{
    //    var screenHeight = $(window).height();
    //    var mainTop      = $('.col-main').offset().top;
    //    var mainHeight   = $('.col-main').height();
    //    var sideHeight   = $('.col-side').height();
    //    if(mainTop + mainHeight < screenHeight) 
    //    {
    //        if($('#pageFooter').length > 0)  $('#pageFooter').css('margin-top', sideHeight - mainHeight);
    //        if($('#pageFooter').length == 0) $('div[id^=form]').css('padding-bottom', sideHeight - mainHeight);
    //    }
    //}
    //else
    //{
    //    var documentHeight = $(document).height();
    //    var bodyHeight     = $('body').height();
    //    var screenHeight   = $(window).height();
    //    if(bodyHeight < screenHeight) 
    //    {
    //        if($('#pageFooter').length > 0)  $('#pageFooter').css('margin-top', documentHeight - bodyHeight);
    //        if($('#pageFooter').length == 0) $('div[id^=form]').css('padding-bottom', documentHeight - bodyHeight);
    //    }
    //}

    citySelector();
    $('input, select, textarea').change(function()
    {
        processProgress();
    });

    /* Add class clicked to avoid click twice. */
    $('.file-name label, .file-name input[type=checkbox]').click(function()
    {
        $(this).parents('.file-name').find('input[type=checkbox]').addClass('clicked');
    });

    /* Check the radio button or checkbox when click the image or div.*/
    $('.file-icon-image, .file-name').click(function()
    {
        $(this).parents('.file-wrapper').find('input[type=radio]').prop('checked', true).change();

        var checkbox = $(this).parents('.file-wrapper').find('input[type=checkbox]');
        if(!checkbox.hasClass('clicked'))
        {
            if(checkbox.prop('checked'))
            {
                checkbox.prop('checked', false).change();
            }
            else
            {
                checkbox.prop('checked', true).change();
            }
        }
        $('.clicked').removeClass('clicked');
    });

    $.setAjaxForm('[id^=form]', function(response)
    {
        if(v.page < v.pageTotal && $('[id^=form]').find('.submit').is(':hidden')) $('[id^=form]').find('.submit').popover('destroy');

        if(response.result == 'success' && response.locate)
        {
            return setTimeout(function(){location.href = response.locate;}, 1200);
        }

        if(response.result == 'fail' && $.type(response.message) == 'object')
        {
            var index = 1;
            var page  = 0;
            var e     = $(window);
            $('.items > .item').each(function()
            {
                var $item = $(this);
                var id    = $(this).find('.item-content').attr('id');
                if($(this).find('span#' + id + 'Label').length > 0)
                {
                    $item.css('border', '1px solid #953B39');
                    if(index == 1) 
                    {
                        page = $(this).parents('[id^=pageContent]').attr('data-id');
                        e    = $(this);
                    }
                    index++;
                }

                $(this).find('.item-content').find('input,select,textarea').change(function()
                {
                    $item.css('border', 'none');
                });
            });

            if(page > 0) changePage('goto', page, e);
        }
    });

    /* Submit form data. */
    $('#submit').click(function()
    {
        bootbox.confirm(v.confirm, function(result)
        {
            if(result) $('#submit').closest('form').submit();
            return true;
        });
        return false;
    });

    changePage();
});

/* Process progress style. */
function processProgress()
{
    var finished = 0;
    $('.item-content').each(function()
    {
        if($(this).find('input[type=text], select, textarea').length > 0)
        {
            if($(this).find('input[type=text], select, textarea').val() != '') finished++; 
        }
        if($(this).find('input[type=radio], input[type=checkbox]').length > 0)
        {
            $(this).find('input[type=radio], input[type=checkbox]').each(function()
            {
                if($(this).prop('checked'))
                {
                    finished++; 
                    return false;
                }
            });
        }
    });

    if(v.itemTotal > 0)
    {
        var percent = Math.round(finished / v.itemTotal * 10000) / 100;
        $('.progress-bar').attr('aria-valuenow', percent).css('width', percent + '%');
        $('.percent').html(percent + '%');
        $('.progressbar').addClass('show');
    }
}

function changePage(type, page, e)
{
    $('[id^=pageContent]').hide();
    $('#pageFooter .pager li').hide();

    if(type == 'prev') v.page--;
    if(type == 'next') v.page++;
    if(type == 'goto') v.page = page;

    if(v.page <= 1) $('#pageFooter .pager .previous.disabled').show();
    if(v.page >  1) $('#pageFooter .pager .previous').not('.disabled').show();
    if(v.page <  v.pageTotal) $('#pageFooter .pager .next').not('.disabled').show();
    if(v.page >= v.pageTotal) $('#pageFooter .pager .next.disabled').show();
    if(v.page >= v.pageTotal) $('#pageFooter .pager .submit').addClass('lastPageShowed').show();

    $('#pageFooter .pager .submit.lastPageShowed').show();

    $('#pageContent' + v.page).show();

    if(e === undefined) 
    {
        $(window).scrollTop($('div[id^=form]').offset().top);
    }
    else
    {
        $(window).scrollTop(e.offset().top);
    }
}

$('#foot').insertBefore('#footer');// $('.article').removeAttr('id');
$('select').parent().addClass('select');
$('#form5').parent().addClass('form5');
$('.form5').next().addClass('partner');
$('.partner .panel-heading strong').text('Registration Fee: $200');
;
  var formId = '#form' + 'a87ff679a2f3e71d9181a67b7542122c';
  var fingerprint = getFingerprint();
  $(formId).append("<input type='hidden' id='fingerprint' name='fingerprint' value='" + fingerprint + "'>");
  
  $.post(createLink('misc', 'ping'), {id: 4, fingerprint: fingerprint});

  if(v.type == 'exam')
  {
      $.get(createLink('form', 'ajaxGetTimeLeft', 'formID=' + v.formID), function(timeLeft)
      {
          if(!timeLeft) return false;
          
          interval = setInterval(function()
          {
              var hour   = Math.floor(timeLeft / 3600);
              var minute = Math.floor(timeLeft % 3600 / 60);
              var second = timeLeft % 60;

              if(hour   < 10) hour   = '0' + hour;
              if(minute < 10) minute = '0' + minute;
              if(second < 10) second = '0' + second;

              if(timeLeft >  0) $('.timeLeft').html('<i class="icon icon-time"> </i>' + hour + ':' + minute + ':' + second);
              if(timeLeft <= 0)
              {
                  $('#submit').closest('form').submit();
                  clearInterval(interval);
              }

              timeLeft--;
          }, 1000);
      });
  }
  ;
function loadCartInfo(twinkle)
{
    $('#siteNav').load(createLink('misc', 'printTopBar'),
        function()
        {
            if(twinkle) 
            {
                bootbox.dialog(
                {  
                    message: v.addToCartSuccess,  
                    buttons:
                    {  
                        back:
                        {  
                            label:     v.lang.continueShopping,
                            className: 'btn-primary',  
                            callback:  function(){location.reload();}  
                        },
                        cart:
                        {  
                            label:     v.gotoCart,  
                            className: 'btn-primary',  
                            callback:  function(){location.href = createLink('cart', 'browse');}  
                        }  
                    }  
                });
            }
        }
    );
}
