﻿/*************************************************************
*     Copyright (C) WISEnut                                 *
**************************************************************/

// WiseNut Search JavaScript Function
//******************************************************************************
/**
* 各検索ページでSubmitするのに使用する。
*/
//******************************************************************************
function searchSubmit() {
    var searchForm = document.frmSearch;
    searchForm.method = "post";

    var locate = location.href;
    if (locate.indexOf("?") != -1) {
        locate = locate.split("?")[0];
    }
   
    searchForm.action = locate;
    
    var query = document.getElementById("query").value;
    if (query == "") {
        alert("検索語を入力して下さい。");
        searchForm.query.focus();
        return;
    }
    if ("undefined" != (typeof (searchForm.categoryCD))) {
        document.getElementById("categoryCD").value = "";
    }
    if ("undefined" != (typeof (searchForm.categoryCDB))) {
        document.getElementById("categoryCDB").value = "";
    }
    if ("undefined" != (typeof (searchForm.listCount))) {
        document.getElementById("listCount").value = "";
    }
    if ("undefined" != (typeof (searchForm.sortName))) {
        document.getElementById("sortName").value = "";
    }
    document.getElementById("collectionName").value = "ALL";
    document.getElementById("startCount").value = 0;
    
    searchForm.submit();
}
   
//******************************************************************************
/**
* 各検索ページで検索キーワードを入力した後、Enter キーを処理する
* @param e イベント
*/
//******************************************************************************
function onKeyPress(event) {
    var NS4 = (document.layers) ? true : false;
    var whichCode;
    if (NS4) {
        whichCode = event.which;
    } else {
        whichCode = event.keyCode;
    }
    if (whichCode == 13) {
        var button = document.getElementById("submitButton");
        if (button) {
            button.click();
            return (false);
        } else {
            return (false);
        }
    }
}


//******************************************************************************
/**
* 各検索ページで最初移動する時、詳細検索 DIV Layerを表示する。
*/
//******************************************************************************
function show_detail_request() {
    var d_value = document.getElementById("isDetailSearch");
    document.getElementById("div_detail").style.display = "block";
}

//******************************************************************************
/**
*詳細検索 DIV Layerを表示/閉じるのを処理する。
*/
//******************************************************************************
function show_detail() {
    var d_value = document.getElementById("isDetailSearch");    
    if (d_value.value == "n") {
        d_value.value = "y";
        document.getElementById("div_detail").style.display = "block";
    } else {
        
        d_value.value = "n";        
        document.getElementById("div_detail").style.display = "none";
        //
        //init_detail();
    } 
}

//******************************************************************************
/**
* 詳細検索 DIV Layerを検索画面で表示するのかをチェックする
* @param check 検索ウィンドウが最初なのかをチェック
*/
//******************************************************************************
function check_detail(check) {
    var d_value = document.getElementById("isDetailSearch");
    if (check == "T") {
        d_value.value = "n";
    }
    if (d_value.value == "y") {
        document.getElementById("div_detail").style.display = "block";
    } else {
        document.getElementById("div_detail").style.display = "none";
    }

}

//******************************************************************************
/**
* 詳細検索条件 DIV Layerが閉じられる時、入力された値だちを全て初期化する。
*/
//******************************************************************************
function init_detail() {
    var searchForm = document.frmSearch;
	//
    //チェックボックス初期化
    if (document.getElementById("DetailSearch_chkAnalyzer").checked == false) {
        document.getElementById("DetailSearch_chkAnalyzer").checked = true;
    }
    if (document.getElementById("DetailSearch_chkPhrase").checked) {
        document.getElementById("DetailSearch_chkPhrase").checked = false;
    }
    //追加検索語初期化
    document.getElementById("DetailSearch_txtOrQuery").value = "";
    document.getElementById("DetailSearch_txtAndQuery").value = "";
    document.getElementById("DetailSearch_txtNotQuery").value = "";
    
}
//検索対象の選択初期化
//	if ("undefined" != (typeof (searchForm.DetailSearch$ddlStyledoc))) {
//        document.getElementById("DetailSearch_ddlStyledoc")[0].selected = "selected";
//    }
//	if ("undefined" != (typeof (searchForm.DetailSearch$ddlQnA))) {
//        document.getElementById("DetailSearch_ddlQnA")[0].selected = "selected";
//    }
//	if ("undefined" != (typeof (searchForm.DetailSearch$ddlNews))) {
//        document.getElementById("DetailSearch_ddlNews")[0].selected = "selected";
//    }
//    //期間設定初期化
//    document.getElementById("DetailSearch_txtSYear").value = "";
//    document.getElementById("DetailSearch_txtSMonth").value = "";
//    document.getElementById("DetailSearch_txtSDay").value = "";
//    document.getElementById("DetailSearch_txtEYear").value = "";
//    document.getElementById("DetailSearch_txtEMonth").value = "";
//    document.getElementById("DetailSearch_txtEDay").value = "";  

//******************************************************************************
/**
* 様式ダウンロード検索で結果を Text形態で見る時、使用する。
* @param collection 検索対象コレクション
*/
//******************************************************************************
function show_text(collection) {
    setCookie("show_option", "1", "7");
 }

//******************************************************************************
/**
* 様式ダウンロード検索で結果をイメージ形態で見る時、使用する。
* @param collection 検索対象コレクション
*/
//******************************************************************************
function show_image(collection) {
    setCookie("show_option", "0", "7");
}

//******************************************************************************
/**
* 様式ダウンロード検索で結果を Textまたはイメージ形態で見るの値をクーキーに貯蔵する時、使用する。
* @param name クーキー名
* @param value クーキー値
* @param expiredays クーキーを使用する期間（日）
*/
//******************************************************************************
function setCookie(name, value, expiredays) {
    var todayDate = new Date();
    todayDate.setDate(todayDate.getDate() + expiredays);
    document.cookie = name + "=" + escape(value) + ";path=/;expires=" + todayDate.toGMTString() + ";";
}

//******************************************************************************
/**
* 各検索ページの下端のページネイゲイションで使用する。
* @param nextPgNum 次のページの番号
* @param collection 検索対象コレクション
*/
//******************************************************************************
function goPage(nextPgNum, collection) {
    var searchForm = document.frmSearch;
    document.getElementById("startCount").value = nextPgNum;
    document.getElementById("collectionName").value = collection;
    searchForm.submit();
}

//******************************************************************************
/**
* 各検索ページで人気検索語で検索する時に使用する。
* @param query 人気検索語
*/
//******************************************************************************
function searchPopWord(query) {    
    var searchPage = location.href;
    if (searchPage.indexOf("?") != -1) {
        searchPage = searchPage.split("?")[0];
    }
    if (searchPage.indexOf("#") != -1) {
        searchPage = searchPage.split("#")[0];
    }   
    var url = searchPage + "?query=" + encodeURI(query);
    location.href = url;    
}

//******************************************************************************
/**
* 様式ダウンロード検索で検索結果を整列するのに使用する。
* @param sortName 整列フィールド
* @param collection 整列対象コレクション
*/
//******************************************************************************
function doSort(sortName, collection) {
    document.getElementById("sortName").value = sortName;
    document.getElementById("collectionName").value = collection;
}

//******************************************************************************
/**
* 様式ダウンロード検索で検索結果を出力するリストの個数を指定するのに使用する。
* @param clientID (SelectBox)の(Client ID)
* @param collection 検索対象コレクション
*/
//******************************************************************************
function doChangeList(clientID, collection) {
    var selectObj = document.getElementById(clientID);
    var idx = document.getElementById(clientID).selectedIndex;
    var selectValue = selectObj.options[idx];
    document.getElementById("listCount").value = selectValue.value;
    document.getElementById("startCount").value = 0;
    document.getElementById("collectionName").value = collection;
   
    document.frmSearch.submit();
}

//******************************************************************************
/**
* 様式ダウンロード検索で検索結果を出力するリストの個数をスタートする行を指定するのに使用する。
* @param clientID (SelectBox)の(Client ID)
* @param collection 検索対象コレクション
*/
//******************************************************************************
function doChangeListWithStartCount(clientID, collection, startCount) {
    var selectObj = document.getElementById(clientID);
    var idx = document.getElementById(clientID).selectedIndex;
    var selectValue = selectObj.options[idx];
    document.getElementById("listCount").value = selectValue.value;
    document.getElementById("startCount").value = startCount;
    document.getElementById("collectionName").value = collection;
   
    document.frmSearch.submit();
}
//******************************************************************************
/**
* 各検索ページでコレクションの検索結果をもっと見るため使用する。
* @param collection 検索対象コレクション
*/
//******************************************************************************
function goMore(collection) {
    document.getElementById("collectionName").value = collection;
    if ("undefined" != (typeof (document.frmSearch.listCount))) {
        document.getElementById("listCount").value = "";
    }
}

//******************************************************************************
/**
* 各検索ページに移動する時に使用する。
* @param searchPage 検索対象コレクション
*/
//******************************************************************************
function goMove(searchPage) {
    document.frmSearch.action = searchPage;
}

//******************************************************************************
/**
* 様式ダウンロード検索で種類別書式と部署別書式の選択検索に使用する。
* @param searchPage 検索対象コレクション
*/
//******************************************************************************
function searchCategory(code, type) {
    document.getElementById("collectionName").value = 'styledoc';
    if (type == "C") {
        document.getElementById("categoryCD").value = code;
        document.getElementById("categoryCDB").value = "";
    } else if (type == "B") {
        document.getElementById("categoryCD").value = "";
        document.getElementById("categoryCDB").value = code;
    }    
    document.getElementById("startCount").value = 0;
}


// ポップウィンドウ座標設定して開ける
var IE = false;
if (navigator.appName == "Microsoft Internet Explorer") {
    IE = true;
}
var dd = document.documentElement; //最新バージョンのブラウザーだち
var db = document.body; //以前バージョンのブラウザーだち
if (!IE) document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = getMouseXY;
var posX = 0;
var posY = 0;
var scrollLeft = 0; scrollTop = 0;

//******************************************************************************
/**
* マウス位置座標を探しすために使用する。
* @param e イベント
*/
//******************************************************************************
function getMouseXY(e) {
    if (IE) {
        if (dd) {
            scrollLeft += dd.scrollLeft;
            scrollTop += dd.scrollTop;
        } else if (db) {
            scrollLeft += db.scrollLeft;
            scrollTop += db.scrollTop;
        }

        posX = event.clientX;
        posY = event.clientY;

        if (dd) {
            posX += dd.scrollLeft;
            posY += dd.scrollTop;
        } else if (db) {
            posX += db.scrollLeft;
            posY += db.scrollTop;
        }
        
    } else {
        posX = e.pageX;
        posY = e.pageY;
    }

    if (posX < 0) { posX = 0; } //初期値より少ない時 0
    if (posY < 0) { posY = 0; } //初期値より少ない時 0 
    return true;
}

//******************************************************************************
/**
* 様式ダウンロード検索でプレビューウィンドウを開ける時使用する。
 미리보기 창을표시합니다
* @param docId プレビューする文書のID
*/
//******************************************************************************
function PopupMenu(docId) {
    if (event.clientX > 460) {
        document.getElementById('PMenu').style.left = (dd.scrollLeft + 460) + 'px';
    }
    else {
        document.getElementById('PMenu').style.left = (dd.scrollLeft + event.clientX) +'px';
    }
    if ((event.clientY + 195) > (dd.clientHeight)) {
        document.getElementById('PMenu').style.top = (posY - 211) + 'px';
    }
    else {
        document.getElementById('PMenu').style.top = (posY + 5) + 'px';
    }

    document.getElementById('view_list').src = "./StyledocPreview.aspx?docId=" + docId;
    document.getElementById('PMenu').style.visibility = 'visible';
}

//******************************************************************************
/**
* 様式ダウンロード検索でプレビューウィンドウを秘める時に使用する。
* @param obj プレビュー Layer
*/
//******************************************************************************
function CMenu(obj) {
    obj.style.visibility = 'hidden';
}
