header.js 41.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230

//名前空間用のオブジェクトを用意する
var HEADER = {};

HEADER.timeWaitCloseNewInfoPushMessage = 5000; // time wait close info new push message 5 seconds
HEADER.currentPagePushMessage = 1;
HEADER.isHoverOn = false;

$(document).ready(function () {

    if (!AVWEB.avwCheckLogin(COMMON.ScreenIds.Login)) return;

    // Set event to prevent leave
    //AVWEB.avwSetLogoutNortice();
    if (ClientData.requirePasswordChange() != 1) {
        COMMON.ToogleLogoutNortice();
    }

    //Toggle Searchbox
    $('input#searchbox-key').click(HEADER.toggleSearchPanel);

    $("#searchbox-key").attr('placeholder', I18N.i18nText('msgPlaceHolder'));

    //Go to Search Page
    $('#searchbox-search').click(HEADER.searchHeaderButtonFunction);

    //Change Language JP
    $('#language-jp').click(HEADER.changeLanguageJa);

    //Change Language KR
    $('#language-kr').click(HEADER.changeLanguageKo);

    //Change Language EN
    $('#language-en').click(HEADER.changeLanguageEn);

    //Go To Bookmark Page
    $('#dspShiori').click(HEADER.bookmarkFunction);

    //Go To update configuration
    $('#dspSetting').click(HEADER.updateConfigFunction);

    // hide logout button with anonymous user
    if (COMMON.isAnonymousLogin()) {
        $('#dspLogout').hide();
        $('#dspSetting').hide();
    }
    else {
        //Go To Login Page
        $('#dspLogout').click(HEADER.logoutFunction);
        $('#dspLogout').show();
        $('#dspSetting').show();
    }

    $('#dspViewHistory').click(HEADER.historyClickFunction);

    $('#dspHome').click(HEADER.homeClickFunction);

    //Hide search panel until click on text field
    $('div#header-searchbox').css('display', 'none');

    if (COMMON.isAnonymousLogin()) {
        $('#li-login-username').hide();
    }
    else {
        //li-login-username
        $('#li-login-username').show();
        //Display user name
        $('#login-username').text(ClientData.userInfo_userName());
        $('#login-username').attr("title", ClientData.userInfo_userName());
    }

    //ログアウト時バックアップ確認パーツ読み込み
    $("#inc_backup").load("./inc_backup.html", function (myData, myStatus, xhr){
    	I18N.i18nReplaceText();
        $('#dlgConfirmBackup-backup').click(HEADER.confirmWithBackupFunction);
        $('#dlgConfirmBackup-withoutbackup').click(HEADER.confirmWithoutBackupFunction);
        $('#dlgConfirmBackup1').hide();
    });

    $('#searchbox-key').keydown(HEADER.headerSearchKeyDownEventFunction);

    $('#searchbox-content-header').click(HEADER.headerSearchContentClickFunction);

    $('#searchbox-tag-header').click(HEADER.headerSearchTagClickFunction);

    $('#searchbox-body-header').click(HEADER.headerSearchBodyClickFunction);

    //init push message
    HEADER.initPushMessage();

    //$('*').click(handleHeaderSearchBoxEvent);

    if (COMMON.isTouchDevice() == false) {
        $('#searchbox-key').hover(HEADER.searchBoxHoverFunction, HEADER.searchBoxHoverOffFunction);

        $('#header-searchbox').hover(HEADER.searchBoxHoverFunction, HEADER.searchBoxHoverOffFunction);
    }

    if (COMMON.isTouchDevice() == true) {
        var bodyTag = document.getElementsByTagName('body')[0];
        bodyTag.addEventListener('touchstart', HEADER.bodyClickFunction, false);
    }
    else {
        $('body').click(HEADER.bodyClickFunction);
    }

});

HEADER.searchBoxHoverFunction = function(){
	HEADER.isHoverOn = true;
};

HEADER.searchBoxHoverOffFunction = function() {
	HEADER.isHoverOn = false;
};

// check disabled button
HEADER.checkDisabledButton = function(selector, buttonid) {
    $(selector).click(
            function () {
                HEADER.setDisabledButton(selector, buttonid);
            });
    HEADER.setDisabledButton(selector, buttonid);
};

HEADER.setDisabledButton = function(selector, buttonid) {
    var isDisabled = $(selector + ':checked').length == 0;
    if (isDisabled) {
        $(buttonid).addClass('disabled');
    }
    else {
        $(buttonid).removeClass('disabled');
    }
};


HEADER.bodyClickFunction = function(event) {
    if (COMMON.isTouchDevice()) {

        // Check mouse is in rectangle of searching panel
        if ($('#header-searchbox').is(":visible"))  //if ($('#header-searchbox').css('display') != "none")
        {

            var currPosX, currPosY;
            var avwUserEnvObj = new UserEnvironment();

            if (avwUserEnvObj.os == 'android') {
                //$("#searchbox-key").val(event.targetTouches[0].pageX + "_" + $('#header-searchbox').position().left + ":" + ($('#header-searchbox').position().left + $('#header-searchbox').width()));
                currPosX = event.targetTouches[0].pageX;
                currPosY = event.targetTouches[0].pageY;
            }
            else {
                currPosX = event.targetTouches[0].clientX;
                currPosY = event.targetTouches[0].clientY;
            }

            var leftsearch = $('#header-searchbox').offset().left;
            var topsearch = $('#header-searchbox').offset().top;
            var rightsearch = $('#header-searchbox').width() + leftsearch;
            var bottomsearch = $('#header-searchbox').height() + topsearch;

            // check mouse position in search region
            if (currPosX >= leftsearch && currPosX <= rightsearch && currPosY >= topsearch && currPosY <= bottomsearch) {
                HEADER.isHoverOn = true;
            }
            else {
                HEADER.isHoverOn = false;
                $('#header-searchbox').hide();
            }


//            if (currPosX >= $('#header-searchbox').position().left
//                && currPosX <= ($('#header-searchbox').position().left + $('#header-searchbox').width())
//                && currPosY >= $('#header-searchbox').position().top
//                && currPosY <= ($('#header-searchbox').position().top + $('#header-searchbox').height())) {

//                HEADER.isHoverOn = true;
//            }
//            else {
//                HEADER.isHoverOn = false;
//            }
        }
    }
    else {
        if (!HEADER.isHoverOn) {
            $('#header-searchbox').hide();
        }
    }
};

HEADER.headerSearchBodyClickFunction = function() {

	$('#searchbox-body').attr('checked','checked');
	$('#searchbox-tag').removeAttr('checked');
	$('#searchbox-content').removeAttr('checked');
	HEADER.isHoverOn = true;
};

HEADER.headerSearchTagClickFunction = function() {

	$('#searchbox-tag').attr('checked','checked');
	$('#searchbox-body').removeAttr('checked');
	$('#searchbox-content').removeAttr('checked');
	HEADER.isHoverOn = true;
};

HEADER.headerSearchContentClickFunction = function() {

	$('#searchbox-content').attr('checked','checked');
	$('#searchbox-tag').removeAttr('checked');
	$('#searchbox-body').removeAttr('checked');
	HEADER.isHoverOn = true;
};


//function header search box key down function
HEADER.headerSearchKeyDownEventFunction = function(e){
 	var code = (e.keyCode ? e.keyCode : e.which);
 	if(code == 13) { //Enter keycode
   		$('#searchbox-search').click();
 }
 HEADER.isHoverOn = true;
};

//Toggle Search Panel Click function
HEADER.toggleSearchPanel = function(){
    if ($("div#header-searchbox").is(":hidden")) {

        // show radio options
        $('div#header-searchbox').slideDown('slow');

        // set default option search
        if ($('#header-searchbox input:checked').length == 0) {
            // set option default is searchbox content
            $('#searchbox-content').attr('checked', 'checked');
        }

	} else {
		$('div#header-searchbox').hide();
	}
};

//Button Search Event function
HEADER.searchHeaderButtonFunction = function(){
	var content = $('#searchbox-content').attr('checked');
	var tag = $('#searchbox-tag').attr('checked');
	var body = $('#searchbox-body').attr('checked');

	var searchDivision;
	var searchText = $('#searchbox-key').val();
	if(content == 'checked')
	{
		searchDivision = $('#searchbox-content').val();
	}
	if(tag == 'checked')
	{
		searchDivision = $('#searchbox-tag').val();
	}
	if(body == 'checked')
	{
		searchDivision = $('#searchbox-body').val();
	}

	ClientData.searchCond_searchText(searchText);
	ClientData.searchCond_searchDivision(searchDivision);
	//window.location = COMMON.ScreenIds.ContentSearch;
	AVWEB.avwScreenMove(COMMON.ScreenIds.ContentSearch);
};

HEADER.homeClickFunction = function(){
    //window.location = COMMON.ScreenIds.Home;
	AVWEB.avwScreenMove(COMMON.ScreenIds.Home);
};

//Change Language Japanese function
HEADER.changeLanguageJa = function(){
	I18N.changeLanguage(COMMON.Consts.ConstLanguage_Ja);
	//ClientData.userInfo_language(COMMON.Consts.ConstLanguage_Ja);
	//$('#control-sort-titlekana').css('display','inline-block');
	//$('#separate').css('display','inline-block');
	//formatDisplayMoreRecord();
	if(window.changeLanguageCallBackFunction){
		changeLanguageCallBackFunction();
	}
    $("#searchbox-key").attr('placeholder', I18N.i18nText('msgPlaceHolder'));
};

//Change Language English functions
HEADER.changeLanguageEn = function(){
	I18N.changeLanguage(COMMON.Consts.ConstLanguage_En);
	//ClientData.userInfo_language(COMMON.Consts.ConstLanguage_En);
	//$('#control-sort-titlekana').css('display','none');
	//$('#separate').css('display','none');
	//formatDisplayMoreRecord();
	if(window.changeLanguageCallBackFunction){
		changeLanguageCallBackFunction();
	}
    $("#searchbox-key").attr('placeholder', I18N.i18nText('msgPlaceHolder'));
};

//Change Language English function
HEADER.changeLanguageKo = function(){
	I18N.changeLanguage(COMMON.Consts.ConstLanguage_Ko);
	//ClientData.userInfo_language(COMMON.Consts.ConstLanguage_Ko);
	//$('#control-sort-titlekana').css('display','none');
	//$('#separate').css('display','none');
	//formatDisplayMoreRecord();
	if(window.changeLanguageCallBackFunction){
		changeLanguageCallBackFunction();
    }
    $("#searchbox-key").attr('placeholder', I18N.i18nText('msgPlaceHolder'));
};

//Shiori function
HEADER.bookmarkFunction = function(){
    //window.location = COMMON.ScreenIds.BookmarkList;
	AVWEB.avwScreenMove(COMMON.ScreenIds.BookmarkList);
};

//Update Config function
HEADER.updateConfigFunction = function(){
    //window.location = COMMON.ScreenIds.Setting;
	AVWEB.avwScreenMove(COMMON.ScreenIds.Setting);
};

//Logout function
HEADER.logoutFunction = function() {

    // check content is changed, update status option backup

    if (ClientData.isChangedBookmark())
    {
        if (ClientData.userOpt_bkShioriFlag() == 0) {
            $("#chkBkAllShiori").removeAttr('checked');
        }
        else {
            $("#chkBkAllShiori").attr('checked', 'checked');
        }
    }
    else {
        $('#chkBkAllShiori').attr('disabled', 'disabled').removeAttr('checked');
    }

    if (ClientData.isChangedMemo()) {

        if (ClientData.userOpt_bkMemoFlag() == 0) {
            $("#chkBkAllMemo").removeAttr('checked');
        }
        else {
            $("#chkBkAllMemo").attr('checked', 'checked');
        }
    }
    else
    {
        $('#chkBkAllMemo').attr('disabled', 'disabled').removeAttr('checked');
    }

    if (ClientData.isChangedMarkingData())
    {
        if (ClientData.userOpt_bkMakingFlag() == 0) {
            $("#chkBkAllMarking").removeAttr('checked');
        }
        else {
            $("#chkBkAllMarking").attr('checked', 'checked');
        }
    }
    else {
        $('#chkBkAllMarking').attr('disabled', 'disabled').removeAttr('checked');
    }


    if (ClientData.isChangedBookmark() == true || ClientData.isChangedMarkingData() == true || ClientData.isChangedMemo() == true) {
        // In case: user_data_backup = "Y" -> backup
        if (ClientData.serviceOpt_user_data_backup() == "Y") {

            if (ClientData.userOpt_bkConfirmFlg() == 1) {  // Show confirming dialog
                //$('#dlgConfirmBackup1').dialog({ width: 600, height: 200, modal: true });
                COMMON.lockLayout();
                $('#dlgConfirmBackup1').show();
                $('#dlgConfirmBackup1').center();

                // check disabled button backup
                HEADER.checkDisabledButton('#dlgConfirmBackup1 .option_backup input', '#dlgConfirmBackup-backup');
            }
            else {  // Do not show confirming dialog
                if (ClientData.userOpt_logoutMode() == null || ClientData.userOpt_logoutMode() == undefined) {
                    //$('#dlgConfirmBackup1').dialog({ width: 600, height: 200, modal: true });
                    COMMON.lockLayout();
                    $('#dlgConfirmBackup1').show();
                    $('#dlgConfirmBackup1').center();
                }
                else {
                    if (ClientData.userOpt_logoutMode() == 0) {  // Logout with backup

                        var isBackupMarking=ClientData.userOpt_bkMakingFlag() == 1;
                        var isBackupMemo=ClientData.userOpt_bkMemoFlag() == 1;
                        var isBackupBookmark = ClientData.userOpt_bkShioriFlag() == 1;

                        HEADER.DoBackup(isBackupMarking, isBackupMemo, isBackupBookmark, true);
                    }
                    else if (ClientData.userOpt_logoutMode() == 1) {  // Logout without backup
                        // Do nothing
                        //Logout
                        HEADER.webLogoutEvent();
                    }
                }
            }
        }
        // In case: user_data_backup != "Y" -> No backup, logout
        else {
            HEADER.webLogoutEvent();
        }
	}
	else{
		HEADER.webLogoutEvent();
	}
};

HEADER.historyClickFunction = function(){
    //window.location = COMMON.ScreenIds.History;
	AVWEB.avwScreenMove(COMMON.ScreenIds.History);
};

//Web Logout Event
HEADER.webLogoutEvent = function(){

    var isExisted = false;

    var params = {
        sid: ClientData.userInfo_sid()
    };

    AVWEB.avwCmsApiSync(ClientData.userInfo_accountPath(), "webLogout", "GET", params,
                    function (data) {
                        isExisted = true;
                        SessionStorageUtils.clear();
                        AVWEB.avwUserSetting().remove(COMMON.Keys.userInfo_sid);
                        AVWEB.avwUserSetting().remove(COMMON.Keys.userInfo_sid_bak);
                        // Move to login screen
                        //window.location = COMMON.ScreenIds.Login;
                        AVWEB.avwScreenMove(COMMON.ScreenIds.Login);
                    },
                    function (xmlHttpRequest, txtStatus, errorThrown) {
                        if (xmlHttpRequest.status == 403) {
                            isExisted = false;
                        }
                        else {
                            // Show system error
                            isExisted = true;
                        }
                    });

    return isExisted;
};

//Logout Without Backup function
HEADER.confirmWithoutBackupFunction = function(e) {
    e.preventDefault();
	var remember = $('#chkRememberBackup').attr('checked');

	if(remember == 'checked'){
	    ClientData.userOpt_bkConfirmFlg(0); // Do not show dialog in next time
	}
	else{
	    ClientData.userOpt_bkConfirmFlg(1); // Show dialog in next time
	}

	ClientData.userOpt_logoutMode(1); // In next time, if choose: [do not show dialog], will not backup and logout
	//window.location = COMMON.ScreenIds.Login;
	HEADER.webLogoutEvent();
};

//Logout With Backup function
HEADER.confirmWithBackupFunction = function(e) {
    e.preventDefault();

    // check button is disabled
    if ($(this).hasClass('disabled'))
        return;

    // update status flag update options No.17

    var isBackupMarking=$("#chkBkAllMarking").attr('checked') == 'checked';
    var isBackupMemo = $("#chkBkAllMemo").attr('checked') == 'checked';
    var isBackupBookmark = $("#chkBkAllShiori").attr('checked') == 'checked';

	var remember = $('#chkRememberBackup').attr('checked');
	COMMON.unlockLayout();
	$('#dlgConfirmBackup1').css('z-index', '99');
	COMMON.lockLayout();

	if (remember == 'checked') {

	    ClientData.userOpt_bkConfirmFlg(0);  // Do not show dialog in next time

	    // update status backup in setting
	    ClientData.userOpt_bkMakingFlag(isBackupMarking);
	    ClientData.userOpt_bkMemoFlag(isBackupMemo);
	    ClientData.userOpt_bkShioriFlag(isBackupBookmark);

        HEADER.DoBackup(isBackupMarking, isBackupMemo, isBackupBookmark, true);
	}
	else{
		ClientData.userOpt_bkConfirmFlg(1);  // Show dialog in next time
		HEADER.DoBackup(isBackupMarking, isBackupMemo, isBackupBookmark, true);
	}

	ClientData.userOpt_logoutMode(0);  // In next time, if choose: [do not show dialog], will backup and logout
	//HEADER.webLogoutEvent();
};
//Confirm Back Up Ok
HEADER.DoBackup = function(isBackupMarking, isBackupMemo, isBackupBookmark,isLogout,funcCallback) {
    // ----------------------------
    // Process backup here
    // ----------------------------

     //Bakup memo/marking/bookmark

//    var params = [
//        { name: 'sid', content: ClientData.userInfo_sid() },
//        { name: 'deviceType', content: '4' },
//        { name: 'formFile', content: JSON.stringify(buildBackupData()), fileName: 'webBackupData.json', contentType: 'text-plain' }
//    ];
//        AVWEB.avwUploadBackupFile(ClientData.userInfo_accountPath(), params, false,
//                        function (data) {
//                            if (JSON.parse(data).result == "success") {
//                                ClientData.isChangedBookmark(false);
//                                ClientData.isChangedMarkingData(false);
//                                ClientData.isChangedMemo(false);
//                                //alert(I18N.i18nText('msgBackupSuccess'));
//
//                               // Show message: msgBackupSuccess
//                               $().toastmessage({ position: 'middle-center' });
//                               $().toastmessage('showToast', {
//                                   type: 'success',
//                                   sticky: true,
//                                   text: I18N.i18nText('msgBackupSuccess'),
//                               });
//                               $('.toast-position-middle-center').css('width', '500px');
//                               $('.toast-position-middle-center').css('margin-left', '-250px');
//                               $('.toast-item-close').live('click', HEADER.webLogoutEvent);
//                            }
//                            else {
//                                //alert(I18N.i18nText('msgBackupFailed'));
//                               // Show error message: msgBackupFailed
//                               $().toastmessage({ position: 'middle-center' });
//                               $().toastmessage('showToast', {
//                                   type: 'error',
//                                   sticky: true,
//                                   text: I18N.i18nText('msgBackupFailed')
//                               });
//                               $('.toast-position-middle-center').css('width', '500px');
//                               $('.toast-position-middle-center').css('margin-left', '-250px');
//                               $('.toast-item-close').live('click', HEADER.webLogoutEvent);
//                            }
//                        },
//                        function (a, b, c) {
//                            //alert(I18N.i18nText('msgBackupFailed'));
//                           // Show error message: msgBackupFailed
//                           $().toastmessage({ position: 'middle-center' });
//                           $().toastmessage('showToast', {
//                               type: 'error',
//                               sticky: true,
//                               text: I18N.i18nText('msgBackupFailed')
//                           });
//                           $('.toast-position-middle-center').css('width', '500px');
//                           $('.toast-position-middle-center').css('margin-left', '-250px');
//                           $('.toast-item-close').live('click', HEADER.webLogoutEvent);
//                            });

    // Backup for No.17

//    if (!isBackupMarking && !isBackupMemo && !isBackupBookmark)
//        return;

    // check if data is changed and has option backup
    if ((ClientData.isChangedBookmark() == true && isBackupBookmark) || (ClientData.isChangedMarkingData() == true && isBackupMarking) || (ClientData.isChangedMemo() == true && isBackupMemo)) {

        if (isLogout) {
            COMMON.lockLayout();
        }

        $().toastmessage({ position: 'middle-center' });
        $().toastmessage('showToast', {
            type: '',
            sticky: true,
            text: '',
            customMessages: 'divResultMessage'
        });

        // show item loading
        $('#divResultMessage').append("<div class='toast-item-loading'></div>");

        setTimeout(function () {

            // backup Marking
            var isBackupMarkingOK = true;
            var isBackupMemoOK = true;
            var isBackupBookmarkOK = true;

            if (isBackupMarking && ClientData.isChangedMarkingData() == true) {
                isBackupMarkingOK = HEADER.sendSignalBackupStart(2); // start backup type marking
                if (isBackupMarkingOK) {
                    isBackupMarkingOK = HEADER.backupFile(JSON.stringify({ "type": 2, "data": ClientData.MarkingData() }), 'Marking.json', 2);
                    if (isBackupMarkingOK) {
                        ClientData.isChangedMarkingData(false);
                        $('#divResultMessage').append("<div class='toast-item-image-success toast-item-message'>" + I18N.i18nText('txtBkMarking') + " " + I18N.i18nText('msgBackupSuccess') + "</div>");
                    }
                    // finish backup marking if start backup marking success
                    HEADER.sendSignalBackupFinish(2);
                }
                if (!isBackupMarkingOK) {
                    $('#divResultMessage').append("<div class='toast-item-image-error toast-item-message'>" + I18N.i18nText('txtBkMarking') + " " + I18N.i18nText('msgBackupFailed') + "</div>");
                }
            }

            // Backup bookmark
            if (isBackupBookmark && ClientData.isChangedBookmark() == true) {
                isBackupBookmarkOK = HEADER.sendSignalBackupStart(4); // start backup type bookmark
                if (isBackupBookmarkOK) {
                    isBackupBookmarkOK = HEADER.backupFile(JSON.stringify({ "type": 3, "data": ClientData.BookMarkData() }), 'Bookmark.json', 4);
                    if (isBackupBookmarkOK) {
                        ClientData.isChangedBookmark(false);

                        $('#divResultMessage').append("<div class='toast-item-image-success toast-item-message'>" + I18N.i18nText('txtBkShiori') + " " + I18N.i18nText('msgBackupSuccess') + "</div>");
                    }
                    // finish backup bookmark if start backup bookmark ok
                    HEADER.sendSignalBackupFinish(4);
                }
                if (!isBackupBookmarkOK) {
                    $('#divResultMessage').append("<div class='toast-item-image-error toast-item-message'>" + I18N.i18nText('txtBkShiori') + " " + I18N.i18nText('msgBackupFailed') + "</div>");
                }
            }

            // Backup Memo

            if (isBackupMemo && ClientData.isChangedMemo() == true) {
                isBackupMemoOK = HEADER.sendSignalBackupStart(1); // start backup type memo
                if (isBackupMemoOK) {
                    isBackupMemoOK = HEADER.backupFile(JSON.stringify({ "type": 1, "data": ClientData.MemoData() }), 'ContentMemo.json', 1);
                    if (isBackupMemoOK) {
                        ClientData.isChangedMemo(false);
                        $('#divResultMessage').append("<div class='toast-item-image-success toast-item-message'>" + I18N.i18nText('txtBkMemo') + " " + I18N.i18nText('msgBackupSuccess') + "</div>");
                    }
                    // finish backup memo if start backup memo ok
                    HEADER.sendSignalBackupFinish(1);
                }
                if (!isBackupMemoOK) {
                    $('#divResultMessage').append("<div class='toast-item-image-error toast-item-message'>" + I18N.i18nText('txtBkMemo') + " " + I18N.i18nText('msgBackupFailed') + "</div>");
                }
            }

            // hide item loading
            $('#divResultMessage .toast-item-loading').hide();

            // active close toast button
            $('.toast-item-close').click(function () { $().toastmessage('removeToast', $('#divResultMessage'), null) });

            if (isLogout) {
                $('.toast-position-middle-center').css('width', '500px');
                $('.toast-position-middle-center').css('margin-left', '-250px');
                $('.toast-item-close').live('click', HEADER.webLogoutEvent);
            }

            // check call back function
            if (funcCallback) {
                funcCallback();
            }

        }, 1000);
    }
    else
    {
        if (isLogout) {
            HEADER.webLogoutEvent();
        }
    }
};

HEADER.backupFile = function(data, file,type) {
    var result = false;
    var params = [
        { name: 'sid', content: ClientData.userInfo_sid() },
        //{ name: 'deviceType', content: '4' },
        //{name: 'fileType', content: type },
        { name: 'formFile', content: data, fileName: file, contentType: 'text-plain' }
    ];
    AVWEB.avwUploadBackupFile(ClientData.userInfo_accountPath(), params, false,
                function (data)
                {
                    if (JSON.parse(data).result == "success")
                    {
                        result = true;
                    }
                }, function (a, b, c) { });
    return result;
};

// send signal backup start
HEADER.sendSignalBackupStart = function(typeBackup)
{
    var result = false;
    var params = { "sid": ClientData.userInfo_sid(), "fileType": typeBackup };
    AVWEB.avwCmsApiSync(ClientData.userInfo_accountPath(), "notifyBackupStart", "post", params,
                    function (data) {
                        if (data.result == "success") {
                            result = true;
                        }
                    },
                    function (xhr, b, c) { });
    return result;
};

// send signal backup finish
HEADER.sendSignalBackupFinish = function(typeBackup)
{
    var result = false;
    var params = { "sid": ClientData.userInfo_sid(), "fileType": typeBackup };
    AVWEB.avwCmsApiSync(ClientData.userInfo_accountPath(), "notifyBackupFinish", "post", params,
                    function (data) {
                        if (data.result == "success") {
                            result = true;
                        }
                    },
                    function (xhr, b, c) { });
    return result;
};

/* ------ */

HEADER.checkForceChangePassword = function(){
	if(ClientData.BookmarkScreen() != COMMON.ScreenIds.Setting){
	   if(ClientData.requirePasswordChange() == 1){
	   		//alert(I18N.i18nText('msgPWDNeedChange'));
			HEADER.showErrorScreenForceChangePassword();
	   }
	}
};

HEADER.showErrorScreenForceChangePassword = function(){
	var tags = '<div id="avw-auth-error">' +
				   '<div style="display:table; width:100%; height:100%;">' +
				   '<div style="display:table-cell; text-align:center; vertical-align:middle;">' +
				   '<p>'+I18N.i18nText('msgPWDNeedChange')+'</p>' +
				   '<div><button id="avw-unauth-ok">OK</button></div>' +
				   '</div></div></div>';
		$('body').prepend(tags);
		$('#avw-auth-error').css( {
			'opacity': 1,
			'position': 'fixed',
			'top': '0',
			'left': '0',
			'width': $(window).width(),
			'height': $(window).height(),
			'zIndex': '10000'
		});
		// resize error page
		$(window).resize(function() {
			$('#avw-auth-error').css( {
				'width': $(window).width(),
				'height': $(window).height()
			});
		});

		$('#avw-unauth-ok').click(function() {
			ClientData.BookmarkScreen(COMMON.ScreenIds.Setting);
			AVWEB.avwScreenMove(COMMON.ScreenIds.Setting);
		});
};

/* region for Push message */

// init for push message
HEADER.initPushMessage = function()
{
    $('#liPushMessage').click(
        function () {

            if ($(this).hasClass('show')) {
                $(this).removeClass('show').addClass('hide');
                $('#accordion').slideUp();
            }
            else {

                $('.notification-pushmessage').hide(); // hide notification
                $(this).removeClass('hide').addClass('show');

                HEADER.currentPagePushMessage = 1;
                HEADER.getPushMessageList();
            }
        }
    );

    // set default hide list message
    $('#liPushMessage').removeClass('show').addClass('hide');

        $('#prev-page-message').click(function (e) {
            HEADER.previousPushMessageClick();
            e.stopPropagation();
            return false;
        });
        $('#next-page-message').click(function (e) {
            HEADER.nextPushMessageClick();
            e.stopPropagation();
            return false;
        });

//        $('#list-push-message').click(
//            function (e) {

//                $('#liPushMessage').removeClass('show').addClass('hide');
//                $('#list-push-message').slideUp();

//                e.stopPropagation();
//                return false;
//            }
//        );

            $('.notification-pushmessage').click(
            function () {
                $(this).slideUp();
            }
        );

        // check new push message
        if (COMMON.isAnonymousLogin() == false ) {
        	if((ClientData.serviceOpt_apns() == 'Y') || (ClientData.serviceOpt_usable_push_message() == 'Y')) {
        		 HEADER.getPushMessageNew();
            }

        }
    };

// get time wait check new push message
HEADER.getTimeWaitCheckNewPushMessage = function()
{
    return AVWEB.avwSysSetting().pushTimePeriod * 1000;// time unit is seconds
};

// get message new
HEADER.getPushMessageNew = function()
{
	//ロック中かビューア画面ならチェックしない
	if ($("#viewer").length) {
		//表示状態か
		if( $('#viewer').is(':visible')){
			return;
		}
	}
	//$('.notification-pushmessage').hide();
	var params = {
			"sid": ClientData.userInfo_sid()
	};
	AVWEB.avwCmsApi(
			ClientData.userInfo_accountPath(),
			"webPushMessageNew",
			"post",
			params,
			HEADER.callbackGetPushMessageNewSuccess,
			function (xhr, b, c) { }
	);
};

// callback get number new message success
HEADER.callbackGetPushMessageNewSuccess = function(data) {

    if (data) {
        // get current number message in session
        var currentMessage = parseInt(ClientData.pushInfo_newMsgNumber());
        if (isNaN(currentMessage)) {
            currentMessage = 0;
        }
        var totalMessage = currentMessage + data.count;
        if ($('#liPushMessage').hasClass('hide')) {
            // update new number message to session
            ClientData.pushInfo_newMsgNumber(totalMessage);

            // only show number new message when total messages greater than 0
            if (totalMessage > 0) {
                // show current number message
                $('#numbermessage').html(totalMessage);
            }
            else $('#numbermessage').html('');
        }
        // show notification for new message
        if (data.count > 0)
        {
            $('.notification-pushmessage').html(I18N.i18nText("msgPushAlert")).slideDown();

            // auto off notification push message after timeWaitCloseNewInfoPushMessage
            setTimeout(function () {
                $('.notification-pushmessage').slideUp();

            }, HEADER.timeWaitCloseNewInfoPushMessage);
        }
    }

    // continue check new push message
    setTimeout(HEADER.getPushMessageNew, HEADER.getTimeWaitCheckNewPushMessage());

};

// get message
HEADER.getPushMessageList = function() {

    var sysSettings = AVWEB.avwSysSetting();
    var pushPageCount=sysSettings.pushPageCount;

    var from = (HEADER.currentPagePushMessage - 1) * pushPageCount + 1;
    var to = HEADER.currentPagePushMessage * pushPageCount;

    var params = {
    		"sid": ClientData.userInfo_sid(),
    		"recordFrom": from,
    		"recordTo": to
    };
    AVWEB.avwCmsApiSync(
    		ClientData.userInfo_accountPath(),
    		"webPushMessageList",
    		"post",
    		params,
    		function (data) {
    			// reset number message
    			ClientData.pushInfo_newMsgNumber(0);
    			// hide number new message
    			$('#numbermessage').html('');
    			HEADER.showListPushMessage(data);
    		},
    		function (xhr, b, c) {
    			AVWEB.showSystemError();
    		}
    );
};

// get string from date crate pushmessage

HEADER.getDateCreatePushMessage = function(data) {
	var flagMonth = "";
	var flagDate = "";
	var flagHours = "";
	var flagMinutes = "";
	if((data.month >=1) && (data.month <= 9)) {
		flagMonth = "0";
	}
	if((data.date >=1) && (data.date <= 9)) {
		flagDate = "0";
	}
	if((data.hours >=1) && (data.hours <= 9)) {
		flagHours = "0";
	}
	if((data.minutes >=1) && (data.minutes <= 9)) {
		flagMinutes = "0";
	}

    return (data.year + 1900) + "/" + flagMonth +(data.month + 1) + "/" + flagDate + data.date + " " + flagHours + data.hours + ":" + flagMinutes + data.minutes;
};
// show push message list
HEADER.showListPushMessage = function(data)
{
    $('#show-push-message').html('');
    for (var i = 0; i < data.messageList.length && i <= (data.recordTo - data.recordFrom); i++)
    {
        var titleMessage = COMMON.truncate(data.messageList[i].messageDetail, 30).replace(/</g, '&lt;').replace(/>/g, '&gt;');
        var detailMessage = data.messageList[i].messageDetail.replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\n/g, '<br/>');
        var message = '<div class="newmsg">';
        message += '<h5 class="postItem"><a href="#">' + titleMessage + '</a></h5>';
        message += '<p>' + detailMessage + '<span class="date">' + HEADER.getDateCreatePushMessage(data.messageList[i].messageSendDate) + '</span></p></div>';
        $('#show-push-message').append(message);
    }

    // hide all detail message
    $('#show-push-message .newmsg p').hide();

    // show list title message
    $('#accordion').slideDown();

    if (HEADER.currentPagePushMessage > 1 || data.recordTo < data.totalRecord) {
        $('#accordion .pagechange').show();
    }
    else {
        $('#accordion .pagechange').hide();
    }

    // check show next button
    if (data.recordTo < data.totalRecord) {
        $('#next-page-message').show();
    }
    else {
        $('#next-page-message').hide();
    }

    // check show previous button
    if (HEADER.currentPagePushMessage > 1) {
        $('#prev-page-message').css({ "visibility": "visible" });
    }
    else {
        $('#prev-page-message').css({ "visibility":"hidden"});
    }


    // show detail message when click at title
    $('#show-push-message .newmsg h5').click(
        function () {
            var isshow = !$(this).parent().find('p').is(':visible');
            $('#show-push-message .newmsg p').slideUp();
            if (isshow) {
                $(this).parent().find('p').slideDown();
            }
        }
    );
};

// load next page message
HEADER.nextPushMessageClick = function() {
    HEADER.currentPagePushMessage++;
    HEADER.getPushMessageList();
};

// load previous page message
HEADER.previousPushMessageClick = function() {
    if (HEADER.currentPagePushMessage > 1){
        HEADER.currentPagePushMessage--;
    } else {
        HEADER.currentPagePushMessage = 1;
    }
    HEADER.getPushMessageList();
};

HEADER.setStatusSort = function(currentid, isAsc) {
    $('#menu_sort li a').removeClass('descending_sort').removeClass('ascending_sort');

    if($('#menu_sort li a#off-default').size()){
        $('#menu_sort li a#off-default').addClass('descending_sort');
    }

    $('#menu_sort li').removeClass('current');
    $(currentid).addClass(isAsc ? 'ascending_sort' : 'descending_sort').parent().addClass("current");
};

// get icon of content type
HEADER.getIconTypeContent = function(contentType) {

    var src = '';
    switch (contentType) {
        case COMMON.ContentTypeKeys.Type_PDF:
            {
                src = 'img/bookshelf/icon_01.png';
                break;
            }
        case COMMON.ContentTypeKeys.Type_Enquete:
            {
                src = 'img/bookshelf/icon_09.png';
                break;
            }
        case COMMON.ContentTypeKeys.Type_Exam:
        	{
	            src = 'img/bookshelf/icon_10.png';
	            break;
        	}
        case COMMON.ContentTypeKeys.Type_Html:
            {
                src = 'img/bookshelf/icon_05.png';
                break;
            }
        case COMMON.ContentTypeKeys.Type_Image:
            {
                src = 'img/bookshelf/icon_02.png';
                break;
            }
        case COMMON.ContentTypeKeys.Type_Music:
            {
                src = 'img/bookshelf/icon_06.png';
                break;
            }
        case COMMON.ContentTypeKeys.Type_NoFile:
            {
                src = 'img/bookshelf/icon_07.png';
                break;
            }
        case COMMON.ContentTypeKeys.Type_Others:
            {
                src = 'img/bookshelf/icon_03.png';
                break;
            }
        case COMMON.ContentTypeKeys.Type_Video:
            {
                src = 'img/bookshelf/icon_04.png';
                break;
            }
        case COMMON.ContentTypeKeys.Type_Link:
            {
                src = 'img/bookshelf/icon_08.png';
                break;
            }
        case COMMON.ContentTypeKeys.Type_PanoMovie:
	        {
	            src = 'img/bookshelf/icon_11.png';
	            break;
	        }
        case COMMON.ContentTypeKeys.Type_PanoImage:
		    {
		        src = 'img/bookshelf/icon_12.png';
		        break;
		    }
        case COMMON.ContentTypeKeys.Type_ObjectVR:
		    {
		        src = 'img/bookshelf/icon_13.png';
		        break;
		    }
        default: break;
    }
    return src;
};

// download resouce content id
HEADER.downloadResourceById = function(contentId){
    var params = {
        sid: ClientData.userInfo_sid(),
        contentId: contentId,
        getType: '2'
    };
    AVWEB.avwCmsApiSync(ClientData.userInfo_accountPath(), "webGetContent", "get", params,
    		function (data) {
    			//Get resourceurl
    			if( data.contentData.content ){
    				var resourceUrl = HEADER.getResourceByIdFromAPI(data.contentData.content.resourceId);
    				// open url to download file
    				if (HEADER.isSafariNotOnIpad()) {
    					window.onbeforeunload = null;
    					window.open(resourceUrl, "_self"); // open url to download file on safari not for ipad
    					var toogleTime = setTimeout(function () { COMMON.ToogleLogoutNortice() }, 200);
    				}
    				else {
    					window.open(resourceUrl); //open url to download file on orther browser
    				}
    			} else {
    				alert("ダウンロード出来ません。");
    			}
    		},
    		function (xhr, b, c) { }
    );
};

//Download resource
HEADER.getResourceByIdFromAPI = function(resourceId){
	return AVWEB.getURL("webResourceDownload") + "&sid=" + ClientData.userInfo_sid() + "&resourceId=" + resourceId + "&isDownload=true";
};

// check is browser safari on Mac and Window devide ( not Ipad )
HEADER.isSafariNotOnIpad = function() {
    if (!window.chrome) {
        var ua = navigator.userAgent.toLowerCase();
        if (!/ipad/.test(ua) && /safari/.test(ua)) {
            return true;
        }
    }
    return false;
};

//link content
HEADER.viewLinkContentById = function(contentId){
    var params = {
        sid: ClientData.userInfo_sid(),
        contentId: contentId,
        getType: '2'
    };
    AVWEB.avwCmsApiSync(ClientData.userInfo_accountPath(), "webGetContent", "get", params,
            function (data) {
                //Get linkUrl
                var linkUrl = data.contentData.content.url;
                if( !linkUrl ){
                    return;
                }

                window.open(linkUrl, "_blank", "new window, scrollbars=yes");

                /*
                //httpで始まる場合は別ウィンドウで開く
                if (linkUrl.toLowerCase().indexOf('http') === 0) {
                    window.open(linkUrl, "_blank", "new window, scrollbars=yes");
                }
                else if( linkUrl.toLowerCase().indexOf('mailto') === 0 ){
                    //window.open(linkUrl, "_self");
                    location.href=linkUrl;
                }
                else {
                    // open url to download file
                    if (HEADER.isSafariNotOnIpad()) {
                        window.onbeforeunload = null;
                        window.open(linkUrl, "_self"); // open url to download file on safari not for ipad
                        var toogleTime = setTimeout(function () { COMMON.ToogleLogoutNortice() }, 200);
                    }
                    else {
                        window.open(linkUrl); //open url to download file on orther browser
                    }
                }
                */
            },
        function (xhr, b, c) { });
};

// get ThumbnailForOtherType
HEADER.getThumbnailForOtherType = function(contentType){

    var src = '';
    if(contentType == COMMON.ContentTypeKeys.Type_Image){
        src = COMMON.ThumbnailForOtherType.Thumbnail_ImageType;
    }
    else if(contentType == COMMON.ContentTypeKeys.Type_Music){
        src = COMMON.ThumbnailForOtherType.Thumbnail_MusicType;
    }
    else if(contentType == COMMON.ContentTypeKeys.Type_Video){
        src = COMMON.ThumbnailForOtherType.Thumbnail_VideoType;
    }
    else if(contentType == COMMON.ContentTypeKeys.Type_NoFile){
        src = COMMON.ThumbnailForOtherType.Thumbnail_NoFileType;
    }
    else if(contentType == COMMON.ContentTypeKeys.Type_Others){
        src = COMMON.ThumbnailForOtherType.Thumbnail_OthersType;
    }
    else if(contentType == COMMON.ContentTypeKeys.Type_Html){
        src = COMMON.ThumbnailForOtherType.Thumbnail_HtmlType;
    }
    else if(contentType == COMMON.ContentTypeKeys.Type_Link){
        src = COMMON.ThumbnailForOtherType.Thumbnail_LinkType;
    }

    return src;
};