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

HOME_CHECK.DEFAULT_SORT_TYPE = "3";
HOME_CHECK.DEFAULT_SORT_ORDER = "2";
HOME_CHECK.DEFAULT_SEARCH_DIVISION = 0;

HOME_CHECK.home_realTotalRecord = 0;
// Thumbnail array
HOME_CHECK.thumbnailArr = [];
// Content type array.
HOME_CHECK.contentTypeArr = [];
HOME_CHECK.contentIdArray = [];
HOME_CHECK.totalPage;

// スクロール復帰
HOME_CHECK.scrollTop = 0;


HOME_CHECK.projectTypeArr = []; //ProjectType array.

// ==========================================================
$(document).ready(function() {

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

    document.title = I18N.i18nText('dspHome') + ' | ' + I18N.i18nText('sysAppTitle');

    $('#dspCommonContent').click(HOME_CHECK.viewCommonContent);
    $('#dspCommonContent').show();

    $('#dspBack').click(HOME_CHECK.backProjectList);

    // プロジェクト一覧　初期表示
    HOME_CHECK.initProjectView();

    // Go To Details Page
    //$('.button-report-details').live('click', HOME_CHECK.reportClickFunction);
    //$('.button-report-details').live('touchend', HOME_CHECK.reportClickFunction);

    // ビューア、共有表示パーツ読み込み
    $("#viewer").load("./inc_contentview.html?__UPDATEID__", function(myData, myStatus, xhr) {
        // 読み込み完了時の処理
        I18N.i18nReplaceText();
    });

});

HOME_CHECK.viewCommonContent = function() {
    HOME_CHECK.initContentView(null, "2");
};

// Initial Project Screen
HOME_CHECK.initProjectView = function() {

    var sid = ClientData.userInfo_sid();

    // Render Project
    HOME_CHECK.renderProject(sid);

};

// Initial Content Screen
HOME_CHECK.initContentView = function(relatedContentList, projectUse) {

    var sortType = HOME_CHECK.DEFAULT_SORT_TYPE;
    var sortOrder = HOME_CHECK.DEFAULT_SORT_ORDER;
    var searchText = '';
    var searchDivision = HOME_CHECK.DEFAULT_SEARCH_DIVISION;
    var genreId = '';
    var groupId = '';
    var sid = ClientData.userInfo_sid();

    var contentIds = '';
    if (relatedContentList) {
        $.each(relatedContentList, function(i, post) {
            if (contentIds != ''){
                contentIds = contentIds + ',' +  post.contentId;
            } else {
                contentIds = post.contentId;
            }
        });
    }

    var offsetPage = 0;
    var limitPage = 999; //暫定

    //初期化
    ClientData.searchCond_recordFrom(0);
    ClientData.searchCond_recordTo(0);

    ClientData.searchCond_sortType(sortType);
    ClientData.searchCond_sortOrder(sortOrder);
    ClientData.searchCond_searchText(searchText);
    ClientData.searchCond_searchDivision(searchDivision);
    ClientData.searchCond_genreId(genreId);
    ClientData.searchCond_groupId(groupId);

    // Language Handle
    //HOME.handleLanguage();
    // handle
    //HOME.handleSortDisp();

    $('#listValues').hide();
    $('#content-grid').show();

    $('#projectBar').hide();
    $('#contentBar').show();

    // Refresh GridView
    HOME_CHECK.refreshGrid();

    //HOME.resetShowNextRecordCount();

    // Render Gridview
    HOME_CHECK.renderContent(sid, searchText, searchDivision, sortType, sortOrder, offsetPage, limitPage, genreId, groupId, contentIds, projectUse);

    // Go To Details Page
    $('.button-details').live('click', HOME_CHECK.readSubmenuFunction);
    $('.button-details').live('touchend', HOME_CHECK.readSubmenuFunction);
    $('.button-details').live('touchmove', function() {
        //HOME_CHECK.home_isMove = true;
    });

};

// refresh GridView
HOME_CHECK.refreshGrid = function() {
    $('#control-nextrecord').hide();
    $('#content-grid').html('');
    $('.pageNumControl').css('visibility', 'hidden');
};

// /Render Content
HOME_CHECK.renderContent = function(id, text, division, type, order, offset, limit, cateid, grpid, contentIds, projectUse) {
    var params = {
        sid : id,
        searchText : text,
        searchDivision : division,
        sortType : type,
        sortOrder : order,
        recordFrom : offset,
        recordTo : limit,
        genreId : cateid,
        groupId : grpid,
        contentIds : contentIds,
        projectUse : projectUse
    };

    HOME_CHECK.abapi('webContentList', params, 'POST', function(data) {

        var countCnt = 0;
        var versionArr = ClientData.ResourceVersion();
        var metaArr = ClientData.MetaVersion();
        var readArr = ClientData.ReadingContentIds();

        $.each(data.contentList, function(i, post) {

            var outputDate = COMMON.formatDeliveryDate(post.contentDeliveryDate);

            var gridHtml = '<section class="sectionhomelist">'
                + '	<div class="cnt_section_list">'
                + '		<a class="img">'
                + '			<canvas height="110" width="150" id="content-thumbnail' + post.contentId + '" contentid="' + post.contentId + '" style="display:none;"></canvas>'
                + '	        <img id="loadingIcon' + post.contentId + '" src="./img/data_loading.gif" height="25px" width="25px" style="padding: 46px; "/>'
                + '		</a>'
                + '		<div class="text">'
                + '         <a id="title' + post.contentId + '" class="dialog name lang" lang="lblTitle" contentid="' + post.contentId + '">'
                + '             <img class="listIcon" src="' + COMMON.getIconTypeContent(post.contentType) + '" width="20" height="20" style="float:left">'
                + ' 			<div class="content-list" style="">' + post.contentTitle + '</div>'
                + '         </a>'
                + '			<div class="info">'
                + '				<ul class="date">'
                + '					<li><span class="lang" lang="txtPubDt"> </span>：' + outputDate + '</li>'
                + '					<li><span class="lang" lang="txtViewDt"> </span>：<span id="lblVdate' + post.contentId + '"> </span></li>'
                + '				</ul>'
                + '				<ul class="pic">'
                //+ '					<li><img src="' + COMMON.DEFAULT_IMG_OPTION_MEMO + '" id="imgMemo' + post.contentId + '" class="sticker"  /></li>'
                //+ '					<li><img src="' + COMMON.DEFAULT_IMG_OPTION_MARKING + '" id="imgBookMark' + post.contentId + '" class="pen"  /></li>'
                + '					<li><ul class="iconList"><li><a class="read lang button-details" contentid="' + post.contentId + '" lang="txtRead">読む</a></li></ul></li>'
                + '				</ul>'
                + '			</div>'
                + '		</div>'
                + '	</div>'
                + '</section>';

            //var shareHtml = "";
            //if (post.readerShare == '1') {
            //    shareHtml = '<li><a class="read lang button-share" contentid="' + post.contentId + '" lang="txtShare">共有</a></li>';
            //}
            //gridHtml = gridHtml.replace(/\{share\}/g, shareHtml);

            $('#content-grid').append(gridHtml);

            //HOME.getNextRecordNumForList();

            // assign thumbnail to array
            var formatThumbnail = post.contentThumbnail;
            if ((formatThumbnail != null) && (formatThumbnail != 'undefined') && (formatThumbnail != '')) {
                formatThumbnail = COMMON.formatStringBase64(formatThumbnail);
            }

            HOME_CHECK.thumbnailArr.push({
                contentId : post.contentId,
                thumbnail : formatThumbnail
            });

            // assign content type to array
            HOME_CHECK.contentTypeArr.push({
                contentId : post.contentId,
                contentType : post.contentType
            });

            // save alert message level
            LIMIT_ACCESS_CONTENT.messageLevel[post.contentId] = {
                alertMessageLevel : post.alertMessageLevel,
                alertMessage : post.alertMessage
            };

            // Check if user has read this content or not.
            HOME_CHECK.checkUserHasReadContent(post.contentId, post.resourceVersion, post.metaVersion, versionArr, metaArr, readArr);
            // assign version to array
            COMMON.resourceVersionArr.push({
                contentid : post.contentId,
                resourceversion : post.resourceVersion
            });

            // assign meta version to array
            COMMON.metaVersionArr.push({
                contentid : post.contentId,
                metaversion : post.metaVersion
            });

            // Check if content has marking or memo
            //HOME_CHECK.checkContentMarkingMemoOption(post.contentId);

            // renderViewDate
            var viewdate = HOME_CHECK.renderViewDate(post.contentId,readArr);
            if (viewdate != null || viewdate != 'undefined') {
                $('#lblVdate' + post.contentId).html(viewdate);
            }
        });

        HOME_CHECK.home_realTotalRecord += data.contentList.length;
        // Save total record for tree:genere/group

        //if (cateid == '' && grpid == '') {
        //    if (HOME.genre_totalcontent == -1) {
        //        HOME.genre_totalcontent = data.totalRecord;
        //    }
        //    if (HOME.group_totalcontent == -1) {
        //        HOME.group_totalcontent = data.totalRecord;
        //    }
        //}

        ClientData.searchCond_recordFrom(data.recordFrom);
        ClientData.searchCond_recordTo(data.recordTo);
        HOME_CHECK.totalPage = data.totalRecord;

        //HOME.reRenderPageNumber(ClientData.searchCond_recordTo(), HOME.totalPage);

        // Toggle scroll to top Control
        //HOME.handleBackToTop();

        // I18N.changeLanguage(ClientData.userInfo_language());
        I18N.i18nReplaceText();
    });
};








// Get Thumnail base on contentid
HOME_CHECK.returnThumbnail = function(contentid) {
    var iArrCnt = HOME_CHECK.thumbnailArr.length;
    for ( var i = 0; i < iArrCnt; i++) {
        if (HOME_CHECK.thumbnailArr[i].contentId == contentid) {
            return HOME_CHECK.thumbnailArr[i].thumbnail;
        }
    }
};

// Get content type base on contentid
HOME_CHECK.returnContentType = function(contentid) {
    // Array Length
    var iArrCnt = HOME_CHECK.contentTypeArr.length;
    // Get contentType in array by contentId
    for ( var i = 0; i < iArrCnt; i++) {
        if (HOME_CHECK.contentTypeArr[i].contentId == contentid) {
            return HOME_CHECK.contentTypeArr[i].contentType;
        }
    }
};


// Check if User has read content
HOME_CHECK.checkUserHasReadContent = function(contId, resourceVer, metaVer, versionArr, metaArr, readArr) {

    var imgThumb = new Image();
    var imgIconNew = new Image();
    var imgIconEdit = new Image();

    var c = document.getElementById('content-thumbnail' + contId);
    var ctx = c.getContext('2d');

    var readFlg = false;

    var contentThumbnail = HOME_CHECK.returnThumbnail(contId);
    var contentType = HOME_CHECK.returnContentType(contId);

    if (readArr <= 0) {
        imgThumb.onload = function() {
            var resizeImg = COMMON.resizeResourceThumbnail(imgThumb, c.width, c.height);
            ctx.drawImage(imgThumb, (c.width / 2) - (resizeImg[0] / 2) + 4, c.height - resizeImg[1] + 4, resizeImg[0], resizeImg[1]);
            imgIconNew.onload = function() {
                ctx.drawImage(imgIconNew, c.width / 2 - resizeImg[0] / 2, c.height - resizeImg[1]);
                $("#loadingIcon" + contId).fadeOut('slow', function() {
                    $('#content-thumbnail' + contId).fadeIn('slow');
                });
            };
            imgIconNew.src = COMMON.DEFAULT_IMG_CONTENT_NEW;
        };

        if (contentThumbnail == '' || contentThumbnail == null) {
            if (!COMMON.isPdfContent(contentType)) {
                var src = COMMON.getThumbnailForOtherType(contentType);
                if (src != '') {
                    imgThumb.src = src;
                }
            }
        } else {
            imgThumb.src = contentThumbnail;
        }

    } else {
        // Check if user has read this content or not
        for ( var nIndex1 = 0; nIndex1 < ClientData.ReadingContentIds().length; nIndex1++) {
            if (ClientData.ReadingContentIds()[nIndex1].contentid == contId) {
                imgThumb.onload = function() {
                    var resizeImg = COMMON.resizeResourceThumbnail(imgThumb, c.width, c.height);
                    ctx.drawImage(imgThumb, (c.width / 2) - (resizeImg[0] / 2) + 4, c.height - resizeImg[1] + 4, resizeImg[0], resizeImg[1]);
                    $("#loadingIcon" + contId).fadeOut('slow', function() {
                        $('#content-thumbnail' + contId).fadeIn('slow');
                    });
                };

                if (contentThumbnail == '' || contentThumbnail == null) {
                    if (!COMMON.isPdfContent(contentType)) {
                        var src = COMMON.getThumbnailForOtherType(contentType);
                        if (src != '') {
                            imgThumb.src = src;
                        }
                    }
                } else {
                    imgThumb.src = contentThumbnail;
                }

                readFlg = true;
                break;
            }
        }
    }

    // Check if resource version has change
    if (readFlg) {
        if (versionArr == null || versionArr <= 0 || versionArr == 'undefined') {
        } else {
            for ( var nIndex2 = 0; nIndex2 < versionArr.length; nIndex2++) {
                if (versionArr[nIndex2].contentid == contId) {
                    if (versionArr[nIndex2].resourceversion != resourceVer) {
                        imgThumb.onload = function() {
                            var resizeImg = COMMON.resizeResourceThumbnail(imgThumb, c.width, c.height);
                            ctx.drawImage(imgThumb, (c.width / 2) - (resizeImg[0] / 2) + 4, c.height - resizeImg[1] + 4, resizeImg[0], resizeImg[1]);
                            imgIconEdit.onload = function() {
                                ctx.drawImage(imgIconEdit, c.width / 2 - resizeImg[0] / 2, c.height - resizeImg[1]);

                                $("#loadingIcon" + contId).fadeOut('slow', function() {
                                    $('#content-thumbnail' + contId).fadeIn('slow');
                                });
                            };
                            imgIconEdit.src = COMMON.DEFAULT_IMG_CONTENT_EDIT;
                        };

                        if (contentThumbnail == '' || contentThumbnail == null) {
                            if (!COMMON.isPdfContent(contentType)) {
                                var src = COMMON.getThumbnailForOtherType(contentType);
                                if (src != '') {
                                    imgThumb.src = src;
                                }
                            }
                        } else {
                            imgThumb.src = contentThumbnail;
                        }

                        break;
                    }
                }
            }
        }

        if (metaArr == null || metaArr <= 0 || metaArr == 'undefined') {
        } else {
            for ( var nIndex2 = 0; nIndex2 < metaArr.length; nIndex2++) {
                if (metaArr[nIndex2].contentid == contId) {
                    if (metaArr[nIndex2].metaversion != metaVer) {
                        imgThumb.onload = function() {
                            var resizeImg = COMMON.resizeResourceThumbnail(imgThumb, c.width, c.height);
                            ctx.drawImage(imgThumb, (c.width / 2) - (resizeImg[0] / 2) + 4, c.height - resizeImg[1] + 4, resizeImg[0], resizeImg[1]);
                            imgIconEdit.onload = function() {
                                ctx.drawImage(imgIconEdit, c.width / 2 - resizeImg[0] / 2, c.height - resizeImg[1]);
                                $("#loadingIcon" + contId).fadeOut('slow', function() {
                                    $('#content-thumbnail' + contId).fadeIn('slow');
                                });
                            };
                            imgIconEdit.src = COMMON.DEFAULT_IMG_CONTENT_EDIT;
                        };

                        if (contentThumbnail == '' || contentThumbnail == null) {
                            if (!COMMON.isPdfContent(contentType)) {
                                var src = COMMON.getThumbnailForOtherType(contentType);
                                if (src != '') {
                                    imgThumb.src = src;
                                }
                            }
                        } else {
                            imgThumb.src = contentThumbnail;
                        }

                        break;
                    }
                }
            }
        }
    } else {
        imgThumb.onload = function() {
            var resizeImg = COMMON.resizeResourceThumbnail(imgThumb, c.width, c.height);
            ctx.drawImage(imgThumb, (c.width / 2) - (resizeImg[0] / 2) + 4, c.height - resizeImg[1] + 4, resizeImg[0], resizeImg[1]);
            imgIconNew.onload = function() {
                ctx.drawImage(imgIconNew, c.width / 2 - resizeImg[0] / 2, c.height - resizeImg[1]);
                $("#loadingIcon" + contId).fadeOut('slow', function() {
                    $('#content-thumbnail' + contId).fadeIn('slow');
                });
            };
            imgIconNew.src = COMMON.DEFAULT_IMG_CONTENT_NEW;
        };

        if (contentThumbnail == '' || contentThumbnail == null) {
            if (!COMMON.isPdfContent(contentType)) {
                var src = COMMON.getThumbnailForOtherType(contentType);
                if (src != '') {
                    imgThumb.src = src;
                }
            }
        } else {
            imgThumb.src = contentThumbnail;
        }

    }
};

// draw Edit Image
HOME_CHECK.drawEditImage = function(id) {
    var img = new Image();
    var imgSrc = HOME_CHECK.returnThumbnail(id);

    if (imgSrc != null) {
    } else {
        var contentType = HOME_CHECK.returnContentType(id);

        var src = COMMON.getThumbnailForOtherType(contentType);
        if (src != '') {
            imgSrc = src;
        }
    }

    var c = document.getElementById('content-thumbnail' + id);

    // use getContext to use the canvas for drawing
    var ctx = c.getContext('2d');
    ctx.clearRect(0, 0, c.width, c.height);
    img.onload = function() {
        var resizeImg = COMMON.resizeResourceThumbnail(img, c.width, c.height);
        ctx.drawImage(img, (c.width / 2) - (resizeImg[0] / 2) + 4, c.height - resizeImg[1] + 4, resizeImg[0], resizeImg[1]);
        $("#loadingIcon" + id).fadeOut('slow', function() {
            $('#content-thumbnail' + id).fadeIn('slow');
        });
    };

    img.src = imgSrc;
};

// Render User view date
HOME_CHECK.renderViewDate = function(id, readArr) {
    for ( var i = 0; i < readArr.length; i++) {
        if (readArr[i].contentid == id) {
            return readArr[i].viewdate;
        }
    }
};

// Dialog Read Button CLick
HOME_CHECK.readSubmenuFunction = function(e) {
    if (e) {
        e.preventDefault();
    }
    //HOME_CHECK.allowTimerCloseSubMenu = false;

    //if (HOME_CHECK.home_isMove == true) {
    //    HOME_CHECK.home_isMove = false;
    //    return;
    //}

    // hide dialog sub menu
    //$('#dlgSubMenu').hide();

    var contentId = $(this).attr('contentid');
    // check limit of content
    LIMIT_ACCESS_CONTENT.checkLimitContent(contentId, function() {
        HOME_CHECK.readSubmenuFunction_callback(contentId);
    }, function() {
    });

};

// Dialog Read Button CLick callback
HOME_CHECK.readSubmenuFunction_callback = function(contentId) {
    var contentThumbnail = HOME_CHECK.returnThumbnail(contentId);

    var date = new Date();
    var month = date.getMonth() + 1;
    var day = date.getDate();

    var outputDate = COMMON.formatNormalDate(day, month, date.getFullYear());

    ClientData.contentInfo_contentId(contentId);
    ClientData.contentInfo_contentThumbnail(contentThumbnail);

    var contentType = HOME_CHECK.returnContentType(contentId);
    ClientData.contentInfo_contentType(contentType);

    var checkflag = false;

    // Store Content id that user has read
    HOME_CHECK.contentIdArray = ClientData.ReadingContentIds();
    if (HOME_CHECK.contentIdArray.length > 0) {

        for ( var nIndex = 0; nIndex < HOME_CHECK.contentIdArray.length; nIndex++) {
            if (HOME_CHECK.contentIdArray[nIndex].contentid == contentId) {
                checkflag = true;
                if (HOME_CHECK.contentIdArray[nIndex].viewdate == '' || HOME_CHECK.contentIdArray[nIndex].viewdate == null || HOME_CHECK.contentIdArray[nIndex].viewdate == 'undefined') {
                    HOME_CHECK.contentIdArray[nIndex].viewdate = outputDate;
                    HOME_CHECK.contentIdArray[nIndex].originviewdate = date;
                }
                break;
            }
        }

        if (!checkflag) {
            HOME_CHECK.contentIdArray.push({
                contentid : contentId,
                viewdate : outputDate,
                originviewdate : date
            });
        }
    } else {
        HOME_CHECK.contentIdArray.push({
            contentid : contentId,
            viewdate : outputDate,
            originviewdate : date
        });
    }

    // Renew ReadingContentID
    var newArray = [];
    ClientData.ReadingContentIds(newArray);

    // Set ResouceVersion for content
    COMMON.setResourceVersionData(contentId);

    // Set MetaVersion for content
    COMMON.setMetaVersionData(contentId);

    // Set data for readingcontentid
    ClientData.ReadingContentIds(HOME_CHECK.contentIdArray);

    // Close Submenu
    $('#dlgSubMenu').hide();

    // $('body,html').animate({ scrollTop: 0 }, 0);
    ClientData.IsRefresh(false);

    // For testing without other Type.
    if (contentType == COMMON.ContentTypeKeys.Type_Others) {
        // Download content
        COMMON.downloadResourceById(contentId);
        // redraw content remove new icon
        HOME_CHECK.drawEditImage(contentId);
    } else if (contentType == COMMON.ContentTypeKeys.Type_Link) {
        // link content
        COMMON.viewLinkContentById(contentId, true);
        // redraw content remove new icon
        HOME_CHECK.drawEditImage(contentId);
    } else {
        // Go to Conten view page
        HOME_CHECK.drawEditImage(contentId);
        HOME_CHECK.showContentView();
    }
};

$(function() {
    //HOME_CHECK.cssInit();
});

HOME_CHECK.cssInit = function() {
    $('html').css({
        'overflow-y' : 'scroll'
    });
    $('html,body').css({
        'height' : '100%',
        'margin' : '0',
        'padding' : '0'
    });
    //$('html>body').css({
    //   'font-size' : '16px',
    //    'font-size' : '68.75%'
    //});
    $('body').css({
        'background' : '#f4f4f4',
        'color' : '#333'
    });
};


HOME_CHECK.showContentView = function() {

    var y = 0;
    if (document.documentElement.scrollTop) {
        y = document.documentElement.scrollTop;
    }
    if (document.body.scrollTop) {
        if (y == undefined || y == 0) {
            y = document.body.scrollTop;
        }
    }
    if (y == undefined || y == null) {
        y = 0;
    }
    HOME_CHECK.scrollTop = y;
    window.scrollTo(0, 0);

    // 試験
    $("#header-ws").hide();
    $("#ws-body").hide();
    $("#topcontrol").hide();

    CONTENTVIEW_INITOBJECT.clearViewerComponent();
    CONTENTVIEW.cssInit();
    $("#viewer").show();

    // CONTENTVIEW_FILESYSTEM.initFS(CONTENTVIEW.ready);
    CONTENTVIEW.ready();

};











// /Render Project
HOME_CHECK.renderProject = function(sid) {
    var params = {
        sid : sid
    };

    HOME_CHECK.checkApi('webProjectList', params, 'POST', function(data) {

        var countCnt = 0;

        $.each(data.projectList, function(i, post) {

            HOME_CHECK.renderAddProject(post);

            // assign content type to array
            HOME_CHECK.projectTypeArr.push({
                projectId : post.projectId,
                projectType : post.projectType
            });

        });

    });
};

HOME_CHECK.renderAddProject = function(post) {

	var listLi = $("<li></li>", {
		id: "list_" + post.projectId,
		class: "read"
	});

	var startDate = "-/-/-";
	var endDate = "-/-/-";
    startDate = post.projectStartDate.replace(/-/g, '/');
    endDate = post.projectEndDate.replace(/-/g, '/');

	var taskInfo = $("<div/>", {class: "taskInfoDiv"});
	var codeAndExpiration = $("<ul/>", {class: "codeAndExpiration"});

	codeAndExpiration.append($("<li/>", {class: "period"}).text("期間：" + startDate + " ～ " + endDate));
	taskInfo.append(codeAndExpiration);

	taskInfo.append($("<p/>").text(post.projectName));
	taskInfo.append($("<p/>", {class: "workContent"}).text(post.projectDescriptions));

	listLi.append(taskInfo);

	var actionBtnDiv = $("#actionBtnDiv").clone().attr("id", post.projectId + "_actionBtnDiv");
	actionBtnDiv.css("display", "flex");

    $(actionBtnDiv.children()[0]).on("click", function() {
        //CHK.reportMode = "1";
        HOME_CHECK.createSession(post.projectId, post.projectType, post.projectReportType); 
    });
    $(actionBtnDiv.children()[1]).hide();

    if (post.relatedContentList.length > 0) {
        $(actionBtnDiv.children()[2]).on("click", function() {
            HOME_CHECK.initContentView(post.relatedContentList);
        });
    } else {
        $(actionBtnDiv.children()[2]).find('img').attr("src","img/check/ic_common_content_off.png");
        $(actionBtnDiv.children()[2]).prop("disabled", true);
    }

	listLi.append(actionBtnDiv);

	$(".addition_list").append(listLi);

};




// Report Click function
HOME_CHECK.reportClickFunction = function(e) {
    if (e) {
        e.preventDefault();
    }

    //if (HOME.home_isMove == true) {
    //    HOME.home_isMove = false;
    //    return;
    //}

    var projectId = $(this).attr('id');

    HOME_CHECK.createSession(projectId);

};

HOME_CHECK.createSession = function(projectId, projectType, projectReportType) {
    
    var checkApiUrl = AVWEB.getCheckApiUrl(ClientData.userInfo_accountPath()) + "/webCreateSession/";

    //var type = HOME_CHECK.returnProjectType(projectId);
    var linkUrl = AVWEB.getShopApiUrl(ClientData.userInfo_accountPath()) + "/vtour/report/" + projectId + "/?view_mode=1&project_type=" + projectType + "&project_report_type=" + projectReportType + "&is_cms=0&is_web=1";

    console.log("linkUrl:" + linkUrl);

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

	var sysSettings = AVWEB.avwSysSetting();
	// ajax によるAPIの実行（dataType text）
	$.ajax( {
		async:		false,
		type:		'GET',
		url:		checkApiUrl,
		dataType:	'text',
		data:		params,
		crossDomain: true,
  		beforeSend: function(xhr) {
  			xhr.setRequestHeader('X-AGT-AppId', sysSettings.appName);
			xhr.setRequestHeader('X-AGT-AppVersion', sysSettings.appVersion);
   		},
		success: function(data) {
            //var linkUrlTmp2 = linkUrl + "&;jsessionid=" + data;
            window.open().location.href = linkUrl;
		},
		error: function(xmlHttpRequest, txtStatus, errorThrown) {
			/* call custom error process */
			AVWEB.avwLog("error" + errorThrown);
		}
	});
};

// Get project type base on projectId
HOME_CHECK.returnProjectType = function(projectId) {
    // Array Length
    var iArrCnt = HOME_CHECK.projectTypeArr.length;

    // Get contentType in array by contentId
    for ( var i = 0; i < iArrCnt; i++) {
        if (HOME_CHECK.projectTypeArr[i].projectId == projectId) {
            return HOME_CHECK.projectTypeArr[i].projectType;
        }
    }
    return -1;
};

// Call API
HOME_CHECK.checkApi = function(name, params, method, callback) {
    var checkApiUrl = AVWEB.getCheckApiUrl(ClientData.userInfo_accountPath())
	AVWEB.avwCmsApiWithUrl(checkApiUrl, ClientData.userInfo_accountPath(), name, method, params, callback, null);
};

// Call API
HOME_CHECK.abapi = function(name, param, method, callback) {
    AVWEB.avwCmsApiSync(ClientData.userInfo_accountPath(), name, method, param, callback, null);
};



HOME_CHECK.backProjectList = function() {

    $('#listValues').show();
    $('#content-grid').hide();

    $('#projectBar').show();
    $('#contentBar').hide();

};




