// #################################################################################
// #    File Name   : satistics.js
// #    Project     : Able Web Site Development
// #    System      : Web Visitor Statistics
// #    Purpose     : Show Site Visitor Information
// #    Function    : mu2iafControl
// #    Model       : This program is based on the Document Object Model (DOM)
// #    Language    : JavaScript (Client Side Scripting. ver: 5.6)
// #    Include     : sitedata.js,
// #    Date Issued : 2006/09/12(Tsu)-17:21:15
// #    Base URL    : http://www.all.co.nz/
// #    Location    : js/
// #    Usage       : See each module functions
// #    Browsers    : (eg.) IE5.x and above
// #    Requirement : (eg.) <BODY ID='oBody'>
// #    Restriction : (eg.) inline style only
// #    Author      : Hiroto Sekine (Able LL Systems Dpt. CHC, NZL)
// #    Copyright   : (C) 2006 Southern Cross Virtual Co., Ltd. All Rights Reserved.
// #    Contact     : info@all.co.nz
// #    Tab Stop    : 4 (Suitable TAB stop size to view this Source Code)
// # ===============================================================================
// #    ** Revision **
// # Date   Description                                             Sign      Mark
// # ------+-------------------------------------------------------+---------+------
// #
// #################################################################################
@set @DEBUG = 0 // Program Debug Flag: ON(>=1)/OFF(=0)/(==9)Test Release Mode
// ###########################################################################
// #                            << NOTICE >>                                 #
// # THIS PROGRAM CODE BELONGS TO SOUTHERN CROSS VIRTUAL CO., LTD. IT IS     #
// # CONSIDERED A TRADE SECRET AND IS NOT TO BE DIVULUGED OR USED BY PARTIES #
// # WHO HAVE NOT RECEIVED WRITTEN AUTHORIZATION FROM THE OWNER.             #
// # ----------------------------------------------------------------------- #
// #                            << 通  知 >>                                 #
// # 本プログラムはSOUTHERN CROSS VIRTUAL CO., LTD.の財産です。本プログラム  #
// # はトレード・シークレットとみなされ、当該権利者の書面による許可なくして、#
// # 漏洩または使用を禁じます。                                              #
// ###########################################################################

var	saveCountryNum = 0;
var	saveLanguageNum = 0;

var oImageSize = new Array();
var	giImageOffset = new Array(3);
	giImageOffset[0] = -1;
	giImageOffset[1] = -1;
	giImageOffset[2] = -1;
var	gbImageSortDir = false;
function getImageSizes( sCode ){
    var oRetData = new Array(2);
    oRetData[0] = 0;
    oRetData[1] = 0;
    for (var i=0; i<oImageSize.length; i++){
        if (oImageSize[i].oCells[0] == sCode){
            oRetData[0] = oImageSize[i].oCells[1];	// Width
            oRetData[1] = oImageSize[i].oCells[2];	// Height
            return(oRetData);
        }
    }
    return(oRetData);
}
function fnGetImageSizeInAdvance( sID ){
    var x = F[ sID ];
    var sImageSrc, sCode, KeyNum;
    if (x != null){
        var oColl = x.children;
        var iCollLen = oColl.length;

        for (var i=0; i<iCollLen; i++){
            oImageSize[i] = new RMBPK2(3);
            sImageSrc = oColl[i].src
            if (i > 0){
                sCode  = sImageSrc.substr(sImageSrc.length-6,2);	// Country Code/Class Code(G1-G5)
                switch(sImageSrc.substr(sImageSrc.length-9,3)){
					case "geo":	// GEO Map
						if (giImageOffset[0] == -1){ giImageOffset[0] = i; }
						sCode += "1";
						break;
					case "lng":	// Language
						if (giImageOffset[1] == -1){ giImageOffset[1] = i; }
						sCode += "2";
						break;
					case "cnt":	// Contents
						if (giImageOffset[2] == -1){ giImageOffset[2] = i; }
						sCode += "3";
						break;
				}
            } else {	// i == 0
                sCode = "top";
            }
            with(oImageSize[i]){
                oCells[0] = sCode;
                oCells[1] = oColl[i].clientWidth;
                oCells[2] = oColl[i].clientHeight;
              @if (@DEBUG == 1) alert("sCode= " + oCells[0] + " Width= " + oCells[1] + " Height= " + oCells[2]); @end
            }
        }
        x.style.display = "none";
    }
}
/* *----------------------------------------------------------------------------* */
/* *    Common Global Constans, Variables, Constructors Definition              * */
/* *----------------------------------------------------------------------------* */

    @if (@DEBUG == 8)           // Adminitorator Mode
        var MAX_LIMIT = 100;    // Max Display Limit for Table Row
    @else
        var MAX_LIMIT = 30;     // Release Mode
    @end

    var Number_Of_Object    = 3;
    var OBJECT_ID0          = 0;
    var OBJECT_ID1          = 1;
    var OBJECT_ID2          = 2;

    var DISP_MORE_THAN  = 5;    // Display Detailed Info. more than this visitor

    var KEY_TOTAL   = 0;        // obj.oCells[0]
    var KEY_WEEKLY  = 1;        // obj.oCells[1]
    var KEY_ORGPOS  = 2;        // obj.oCells[2]
    var KEY_RATIO   = 3;        // obj.oCells[3]

    var gbSortOrder = false;    // Initial: DeAscendant
    var giSortKey   = new Array(Number_Of_Object); // Sort Key item Array Number(0,1,2,...)
    var giRmsgIdx   = new Array(Number_Of_Object); // Rich-Msg-Box Index
    var giSrtKeyPtr = 0;        // Which Sort Key to be used in qSort3

/* ############################################################################## */
/* *----------------------------------------------------------------------------* */
/* *    Web Statistics Module (1): Visitor's GEO Information                    * */
/* *----------------------------------------------------------------------------* */
/* ############################################################################## */

// *-----------------[: Module Global Variable Definition ]---------------------*

    var goCountry     = null;       // Country Data Object
    var giCountryLen  = 0;          // Country Data Record Length

    var DISP_MORE_THAN  = 5;        // Display Detailed Info. more than this visitor

    var SELECT_ID1  = "oSelID1";    // <SELECT id="oSelID1">
    var DIV_ID1     = "oTopCountry"; // <DIV id="oTopContry">
    var GRAPH_MAX1  = 800;

// *-----------------[: Main Procedure Devision    ]----------------------------*

function fnSiteCountryList( oObject, iTopNum, bDir, KeyPos ){

    // IN: oObject: Target Object ID where to be displayd the list
    // IN: iTopNum: Top Recent Modified Chapter number to be showed(3-10)
    // IN: bDir:    List sorting direction (True = A, false = D)
    // IN: KeyPos:  Key Position(0:Total, 1:Weekly)

    // *-------------------------------------------------------
    // *    Initial Procedure
    // *-------------------------------------------------------

    var oOL = F[ oObject ];
    if (oOL == null){
        alert("Fatal Error: HTML TAG Element '" + oObject + "' is not found.\nContact H. Sekine at info@all.co.nz, Thank you.");
        return;
    }

    goCountry     = new makeGEOPack();  // Construct Data Object
    goAreaData	  = new makeAreaObj();	// Area Data Object	v2.00 2006/12/18(Mon)-16:57:59
    giCountryLen  = goCountry.length;   // Save Data Record Length
    giSortKey[OBJECT_ID0]  = KeyPos;    // Set Sort KEY Position
    giSrtKeyPtr   = OBJECT_ID0;
    gbSortOrder   = bDir;

    var START_DATE1 = (KeyPos == KEY_TOTAL) ? MOST_GEO_PERIOD_START1 : MOST_GEO_PERIOD_START1;
    var END_DATE1   = MOST_GEO_PERIOD_END1;
    var dtArray = new Array();
    var oCell, oRow, Loop, iWidth, oImg;
    var i, j, k, idx;
    var iCount = 0;
    var iRealNum = 0;
    var iRankNo = 0;
    var iPrevNo = 0;
    var ua = window.navigator;

    if (ua.cookieEnabled){
        var cookieVal = getCookieValue( coABLESITE_STAT1 );
        if (cookieVal != null && cookieVal != iTopNum){
            iTopNum = cookieVal;
            @if (@DEBUG == 1) window.status = "iTopNum is stored as: " + iTopNum + "."; @end
        }
    }
    if (iTopNum <= 0){
        oOL.style.display = 'none';
        F.oTopCountryCap.style.display = 'none';
        return;
    }

    // *----------------------------------------------------------------------------
    // *    Make Work Array to Sort Visitor Data by the Number (TOTAL/WEEKLY)
    // *----------------------------------------------------------------------------

    for (i=0, j=0; i<giCountryLen; i++){

        oCell = goCountry[i];
        if (oCell.Total == 0) continue;
        iRealNum ++;

        dtArray[j] = new pkCells(6);	// v2.00 6 --> 7
        with(dtArray[j]){
            Cells[KEY_TOTAL]  = oCell.Total;    // 0
            Cells[KEY_WEEKLY] = oCell.Weekly;   // 1
            Cells[KEY_ORGPOS] = i;              //
            Cells[4]          = oCell.CID;      // 4
            Cells[5]          = oCell.WRK;      // 5
//          Cells[6]		  = oCell.ARC;		// 6: Area Code v2.00
        }
        iCount += dtArray[j].Cells[KeyPos];
        if (oCell.CID == "ZZ"){
			saveCountryNum = oCell.Total;
			dtArray[j].Cells[KEY_TOTAL] = 0;
		}
        j++;
    }

    MAX_LIMIT = iRealNum;
    iTopNum = (iTopNum > MAX_LIMIT) ? MAX_LIMIT : iTopNum;

    // *----------------------------------------------------------------------------
    // *    Sorting the Work Data Array & Calculate the Ratio
    // *----------------------------------------------------------------------------

    qSort3(dtArray, 0, iRealNum);
    if (saveCountryNum != 0) dtArray[iRealNum-1].Cells[KeyPos] = saveCountryNum;
    fnSetRMB2Info(dtArray, iRealNum, 0);

    for (i=0; i<iRealNum; i++){
        dtArray[i].Cells[KEY_RATIO] = (dtArray[i].Cells[KeyPos]/iCount) * 100;
    }

    // *----------------------------------------------------------------------------
    // *    Make Work Array to Sort Chapter Title by Modified Date Order
    // *----------------------------------------------------------------------------

    var head = new Array();
    i = 0;
    head[i++] = "Rank";
    head[i++] = "Flag";
    head[i++] = "Country";
    head[i++] = "NUM";
    head[i++] = "  ";
    var iColLen = i;

    with( document ){
        var oTable  = createElement( "TABLE" );
        var oTHead  = createElement( "THEAD" );
        var oTBody  = createElement( "TBODY" );
        var oCaps   = createElement( "CAPTION" );
    }
    oRow = document.createElement( "TR" );
    with( oTHead ){
        appendChild( oRow );
        bgColor = "lightgrey";
    }
    with( oCaps ){
        innerText = "Created Using DOM.";
        align = "bottom";
    }
    for (i=0; i<iColLen; i++){
        oCell = document.createElement( "TH" );
        oCell.innerText = head[i];
        if (i == (iColLen-1)){
            with( oCell ){
                width = GRAPH_MAX1;
                align = "left";
            }
            for (var p=1; p<=200; p++){
                if ((p % 20) == 0){
                    oCell.innerText += "|";
                } else {
                    oCell.innerText += ".";
                }
            }
        }
        oRow.appendChild( oCell );
    }

    head = null;

    with( oTable ){
        appendChild( oTHead );
        appendChild( oTBody );
        appendChild( oCaps  );
    }

    Loop = (iTopNum > iRealNum) ? iRealNum : iTopNum;
    k = giRmsgIdx2[OBJECT_ID0];

    // *-------------------------------------------------------
    // *    Main Procedure
    // *-------------------------------------------------------

    for (var q=0, i=0; i<Loop; i++){
        if (dtArray[i].Cells[KeyPos] != iPrevNo){
            iRankNo = iRankNo + q + 1; q = 0;
            iPrevNo = dtArray[i].Cells[KeyPos];
        } else {
            q ++;
        }
        oRow = document.createElement( "TR" );
        oRow.style.height = "0.5cm";

        idx = dtArray[i].Cells[KEY_ORGPOS];

        for (j=0; j<iColLen; j++){
            oCell = document.createElement( "TD" );
            switch(j){
                case 0: // Ranking No
                    with( oCell ){
                        innerText = iRankNo;
                        align = "center";
                    }
                    break;

                case 1: // Country Flag image
                    oImg = document.createElement( "IMG" );
                    with( oImg ){
                        src     = goCountry[idx].Flag;
                        width   = 56/2;
                        height  = 38/2;
                    }
                    oCell.appendChild( oImg );
                    break;

                case 2: // Country Name
                    if ((dtArray[i].Cells[5] > 0) && (k != -1)){
                        oCell.innerHTML = "<a href='javascript:fnShowRichMbox2(" + (k++) + ");' title='Click to view more info. of " + goCountry[idx].Name + "'>" + goCountry[idx].Name + "</a>";
                    } else {
                        oCell.innerText = goCountry[idx].Name;
                    }
                    break;

                case 3: // Actual Visitor Number (Total/Weekly)
                    with( oCell ){
                        innerText = dtArray[i].Cells[KeyPos];
                        align = "center";
                    }
                    break;

                case 4: // Draw Graph Bar based on the Ratio Value
                    oImg = document.createElement( "IMG" );
                    iWidth = Math.floor((dtArray[i].Cells[KEY_RATIO] / 150) * 1200);
                    iWidth = (iWidth > GRAPH_MAX1) ? GRAPH_MAX1 : iWidth;
                    with( oImg ){
                        src     = "graph.gif";
                        width   = iWidth;
                        height  = 12;
                        title   = (dtArray[i].Cells[KEY_RATIO].toString()).substr(0,5) + " %";
                    }
                    oCell.appendChild( oImg );
                    break;

                default:
                    break;
            }
            oRow.appendChild( oCell );
        }
        oTBody.appendChild( oRow );
    }   // for Loop end
    oOL.appendChild( oTable );

    // *-------------------------------------------------------
    // *    Closing Procedure
    // *-------------------------------------------------------

    with( document ){
        var oSelect = createElement( "SELECT" );
        var oOption = createElement( "OPTION" );
        var oSpan1  = createElement( "SPAN"   );
        var oSpan2  = createElement( "SPAN"   );
        var oSpan3  = createElement( "SPAN"   );
        var oSpan4  = createElement( "SPAN"   );
        var oSpan5  = createElement( "SPAN"   );
    }
    for (i=0; i<MAX_LIMIT; i++){
        oOption = document.createElement( "OPTION" );
        oOption.innerText = (i + 1);
        oSelect.appendChild( oOption );
    }
    with( oSelect ){
        selectedIndex = iTopNum - 1;
        id = SELECT_ID1;
        onchange = fnSiteCountryList2;
        title = "Select Num to be showed at onece.";
    }

    oSpan1.innerHTML = "Most recent top <span style='color:red;'>" + Loop + "</span> Visitor's Countries( <span style='color:red;'>" + iRealNum + "</span> ): ";
    oSpan2.appendChild( oSelect );
    oSpan3.innerHTML = "　Period【" + START_DATE1 + "-" + END_DATE1 + "】";
    oSpan4.innerHTML = "　Total Visitors【 <span style='color:red;font-weight:bold;'>" + iCount + "</span> 】<a href='javascript:fnShowRichMbox2(0);' title='Click to view GEO Map Overlay.'>GEO Map</a>";
    oSpan5.innerHTML = "　Total Cities【 <span style='color:red;font-weight:bold;'>" + giTotalCities + "</span> 】";
    with( F.oTopCountryCap ){
        appendChild( oSpan1 );
        appendChild( oSpan2 );
        appendChild( oSpan3 );
        appendChild( oSpan4 );
        appendChild( oSpan5 );
        style.display = "";
    }
    var x = F[ "GEOMAP" ];
    if (x != null) x.title = "Period【" + START_DATE1 + "-" + END_DATE1 + "】";
    oOL.style.display = "";

//    var goCountry     = null;   // Country Data Object release
//    var giCountryLen  = 0;      // Country Data Record Length

}   // End of "fnSiteCountryList"

// *-----------------[: Module Spelialised Utility Tools ]----------------------*

function fnSiteCountryList2(){
    var ua = window.navigator;
    var x = F[ SELECT_ID1 ];

    if (x != null){
        var iValue = x.selectedIndex+1;
        with( F ){
            oTopCountry.innerHTML = "";
            oTopCountryCap.innerHTML = "";
        }
        if (ua.cookieEnabled){
            setCookieValue( coABLESITE_STAT1, iValue, twoWeeks );
            @if (@DEBUG == 1) window.status = "Top Caps value: " + iValue + " saved."; @end
        }
        fnSiteCountryList(DIV_ID1, iValue, false, giSortKey[OBJECT_ID0]);
    }
}

/* ############################################################################## */
/* *----------------------------------------------------------------------------* */
/* *    Web Statistics Module (2): Visitor's Language Information               * */
/* *----------------------------------------------------------------------------* */
/* ############################################################################## */

// *-----------------[: Module Global Variable Definition ]---------------------*

    var goLanguage    = null;
    var giLanguageLen = 0;

    var DISP_MORE_THAN  = 5;        // Display Detailed Info. more than this visitor

    var SELECT_ID2  = "oSelID2";        // <SELECT id="oSelID1">
    var DIV_ID2     = "oTopLanguage";   // <DIV id="oTopContry">
    var GRAPH_MAX2  = 800;

// *-----------------[: Main Procedure Devision    ]----------------------------*

function fnSiteLanguageList( oObject, iTopNum, bDir, KeyPos ){
    // *-------------------------------------------------------
    // *    Initial Procedure
    // *-------------------------------------------------------

    var oOL = F[ oObject ];
    if (oOL == null){
        alert("Fatal Error: HTML TAG Element '" + oObject + "' is not found.\nContact H. Sekine at info@all.co.nz, Thank you.");
        return;
    }

    goLanguage    = new makeLNGPack();
    giLanguageLen = goLanguage.length;
    giSortKey[OBJECT_ID1]  = KeyPos;    // Set Sort KEY Position
    giSrtKeyPtr   = OBJECT_ID1;
    gbSortOrder   = bDir;

    var START_DATE2 = (KeyPos == KEY_TOTAL) ? MOST_GEO_PERIOD_START2 : MOST_GEO_PERIOD_START2;
    var END_DATE2   = MOST_GEO_PERIOD_END2;
    var dtArray = new Array();
    var oCell, oRow, Loop, iWidth, oImg;
    var i, j, k, idx;
    var iCount = 0;
    var iRealNum = 0;
    var iRankNo = 0;
    var iPrevNo = 0;
    var ua = window.navigator;

    if (ua.cookieEnabled){
        var cookieVal = getCookieValue( coABLESITE_STAT2 );
        if (cookieVal != null && cookieVal != iTopNum){
            iTopNum = cookieVal;
            @if (@DEBUG == 1) window.status = "iTopNum is stored as: " + iTopNum + "."; @end
        }
    }
    if (iTopNum <= 0){
        oOL.style.display = 'none';
        F.oTopLanguageCap.style.display = 'none';
        return;
    }

    // *----------------------------------------------------------------------------
    // *    Make Work Array to Sort Visitor Data by the Number (TOTAL/WEEKLY)
    // *----------------------------------------------------------------------------

    for (i=0, j=0; i<giLanguageLen; i++){

        oCell = goLanguage[i];
        if (oCell.Total == 0) continue;
        iRealNum ++;

        dtArray[j] = new pkCells(6);
        with(dtArray[j]){
            Cells[KEY_TOTAL]  = oCell.Total;    // 0
            Cells[KEY_WEEKLY] = oCell.Weekly;   // 1
            Cells[KEY_ORGPOS] = i;              // 2
            Cells[4]          = oCell.Lname;    // 4: Lname
            Cells[5]          = oCell.WRK;      // 5: NUM
        }
        iCount += dtArray[j].Cells[KeyPos];
        if (oCell.Lname == "UnKnown"){
			saveLanguageNum = oCell.Total;
			dtArray[j].Cells[KEY_TOTAL] = 0;
		}
        j++;
    }

    MAX_LIMIT = iRealNum;
    iTopNum = (iTopNum > MAX_LIMIT) ? MAX_LIMIT : iTopNum;

    // *----------------------------------------------------------------------------
    // *    Sorting the Work Data Array & Calculate the Ratio
    // *----------------------------------------------------------------------------

    qSort3(dtArray, 0, iRealNum);
    if (saveLanguageNum != 0) dtArray[iRealNum-1].Cells[KeyPos] = saveLanguageNum;
    fnSetRMB2Info(dtArray, iRealNum, 1);

    for (i=0; i<iRealNum; i++){
        dtArray[i].Cells[KEY_RATIO] = (dtArray[i].Cells[KeyPos]/iCount) * 100;
    }

    // *----------------------------------------------------------------------------
    // *    Make Work Array to Sort Chapter Title by Modified Date Order
    // *----------------------------------------------------------------------------

    var head = new Array();
    i = 0;
    head[i++] = "Rank";
    head[i++] = "Language";
    head[i++] = "NUM";
    head[i++] = "  ";
    var iColLen = i;

    with( document ){
        var oTable  = createElement( "TABLE" );
        var oTHead  = createElement( "THEAD" );
        var oTBody  = createElement( "TBODY" );
        var oCaps   = createElement( "CAPTION" );
    }
    oRow = document.createElement( "TR" );
    with( oTHead ){
        appendChild( oRow );
        bgColor = "lightgrey";
    }
    with( oCaps ){
        innerText = "Created Using DOM.";
        align = "bottom";
    }
    for (i=0; i<iColLen; i++){
        oCell = document.createElement( "TH" );
        oCell.innerText = head[i];
        if (i == (iColLen-1)){
            with( oCell ){
                width = GRAPH_MAX1;
                align = "left";
            }
            for (var p=1; p<=200; p++){
                if ((p % 20) == 0){
                    oCell.innerText += "|";
                } else {
                    oCell.innerText += ".";
                }
            }
        }
        oRow.appendChild( oCell );
    }

    head = null;

    with( oTable ){
        appendChild( oTHead );
        appendChild( oTBody );
        appendChild( oCaps  );
    }

    Loop = (iTopNum > iRealNum) ? iRealNum : iTopNum;
    k = giRmsgIdx2[OBJECT_ID1];

    // *-------------------------------------------------------
    // *    Main Procedure
    // *-------------------------------------------------------

    for (var q=0, i=0; i<Loop; i++){
        if (dtArray[i].Cells[KeyPos] != iPrevNo){
            iRankNo = iRankNo + q + 1; q = 0;
            iPrevNo = dtArray[i].Cells[KeyPos];
        } else {
            q ++;
        }
        oRow = document.createElement( "TR" );
        oRow.style.height = "0.5cm";

        idx = dtArray[i].Cells[KEY_ORGPOS];

        for (j=0; j<iColLen; j++){
            oCell = document.createElement( "TD" );
            switch(j){
                case 0: // Ranking No
                    with( oCell ){
                        innerText = iRankNo;
                        align = "center";
                    }
                    break;

                case 1: // Language Name
                    if ((dtArray[i].Cells[5] > 0) && (k != -1)){
                        oCell.innerHTML = "<a href='javascript:fnShowRichMbox2(" + (k++) + ");' title='Click to view more info. of " + goLanguage[idx].Lname + "'>" + goLanguage[idx].Lname + "</a>";
                    } else {
                        oCell.innerText = goLanguage[idx].Lname;
                    }
                    break;

                case 2: // Actual Visitor Number (Total/Weekly)
                    with( oCell ){
                        innerText = dtArray[i].Cells[KeyPos];
                        align = "center";
                    }
                    break;

                case 3: // Draw Graph Bar based on the Ratio Value
                    oImg = document.createElement( "IMG" );
                    iWidth = Math.floor((dtArray[i].Cells[KEY_RATIO] / 150) * 1200);
                    iWidth = (iWidth > GRAPH_MAX1) ? GRAPH_MAX1 : iWidth;
                    with( oImg ){
                        src     = "graph.gif";
                        width   = iWidth;
                        height  = 12;
                        title   = (dtArray[i].Cells[KEY_RATIO].toString()).substr(0,5) + " %";
                    }
                    oCell.appendChild( oImg );
                    break;

                default:
                    break;
            }
            oRow.appendChild( oCell );
        }
        oTBody.appendChild( oRow );
    }   // for Loop end
    oOL.appendChild( oTable );

    // *-------------------------------------------------------
    // *    Closing Procedure
    // *-------------------------------------------------------

    with( document ){
        var oSelect = createElement( "SELECT" );
        var oOption = createElement( "OPTION" );
        var oSpan1  = createElement( "SPAN"   );
        var oSpan2  = createElement( "SPAN"   );
        var oSpan3  = createElement( "SPAN"   );
        var oSpan4  = createElement( "SPAN"   );
    }
    for (i=0; i<MAX_LIMIT; i++){
        oOption = document.createElement( "OPTION" );
        oOption.innerText = (i + 1);
        oSelect.appendChild( oOption );
    }
    with( oSelect ){
        selectedIndex = iTopNum - 1;
        id = SELECT_ID2;
        onchange = fnSiteLanguageList2;
        title = "Select Num to be showed at onece.";
    }

    oSpan1.innerHTML = "Most recent top <span style='color:red;'>" + Loop + "</span> Visitor's Languages( <span style='color:red;'>" + iRealNum + "</span> ): ";
    oSpan2.appendChild( oSelect );
    oSpan3.innerHTML = "　Period【" + START_DATE2 + "-" + END_DATE2 + "】";
    oSpan4.innerHTML = "　Total Visitors【 <span style='color:red;font-weight:bold;'>" + iCount + "</span> 】";
    with( F.oTopLanguageCap ){
        appendChild( oSpan1 );
        appendChild( oSpan2 );
        appendChild( oSpan3 );
        appendChild( oSpan4 );
        style.display = "";
    }
    var x = F[ "GEOMAP" ];
    if (x != null) x.title = "Period【" + START_DATE2 + "-" + END_DATE2 + "】";
    oOL.style.display = "";

//    var goLanguage     = null;   // Country Data Object release
//    var giLanguageLen  = 0;      // Country Data Record Length

}   // End of "fnSiteCountryList"

// *-----------------[: Module Spelialised Utility Tools ]----------------------*

function fnSiteLanguageList2(){
    var ua = window.navigator;
    var x = F[ SELECT_ID2 ];

    if (x != null){
        var iValue = x.selectedIndex+1;
        with( F ){
            oTopLanguage.innerHTML = "";
            oTopLanguageCap.innerHTML    = "";
        }
        if (ua.cookieEnabled){
            setCookieValue( coABLESITE_STAT2, iValue, twoWeeks );
            @if (@DEBUG == 1) window.status = "Top Caps value: " + iValue + " saved."; @end
        }
        fnSiteLanguageList(DIV_ID2, iValue, false, giSortKey[OBJECT_ID1]);
    }
}

/* ############################################################################## */
/* *----------------------------------------------------------------------------* */
/* *    Web Statistics Module (3): Site Contents Page Views Information         * */
/* *----------------------------------------------------------------------------* */
/* ############################################################################## */

// *-----------------[: Module Global Variable Definition ]---------------------*

    var goContent    = null;
    var goContentLen = 0;

    var SELECT_ID3  = "oSelID3";        // <SELECT id="oSelID3">
    var DIV_ID3     = "oTopContent";    // <DIV id="oTopContent">
    var GRAPH_MAX3  = 800;
    var	giKeyPos3	= -1;
    var	giSelMunu2Index = -1;
    var	giSelMunu3Index = -1;
    var	giSaveIndex3 = -1;
    var	giSaveTopNum3 = -1;
//    var	gbList2UsedFlag = false;
//    var	gbClassUsedFlag = false;

// *-----------------[: Main Procedure Devision    ]----------------------------*

function fnSiteContentList( oObject, iTopNum, bDir, KeyPos ){
    // KeyPos: 0: Visitr(T), 1:Visitor(W), 2:View(T), 3:View(W)
    // *-------------------------------------------------------
    // *    Initial Procedure
    // *-------------------------------------------------------

    var oOL = F[ oObject ];
    if (oOL == null){
        alert("Fatal Error: HTML TAG Element '" + oObject + "' is not found.\nContact H. Sekine at info@all.co.nz, Thank you.");
        return;
    }

    goContent    = new makeRANKPack();
    goContentLen = goContent.length;
    giSortKey[OBJECT_ID2] = ((giSelMunu3Index != -1) ? giSelMunu3Index : KeyPos);      // Set Sort KEY Position
    giSrtKeyPtr  = OBJECT_ID2;           // Which Sort Key to be used in qSort3
    giKeyPos3	 = ((giSelMunu3Index != -1) ? giSelMunu3Index : KeyPos);
    gbSortOrder  = bDir;

    var	VIW_POS	= 0;
    var	PVW_POS	= 1;
    var	CLS_POS	= 2;
    var	ORG_POS	= 3;
    var	RAT_POS = 4;
    var	RNK_POS	= 5;
    var	WRK_POS	= 6;

    var START_DATE3 = (KeyPos == KEY_TOTAL) ? MOST_GEO_PERIOD_START3 : MOST_GEO_PERIOD_START3;
    var END_DATE3   = MOST_GEO_PERIOD_END3;
    var dtArray = new Array();
    var dtArray2 = new Array();
    var oCell, oRow, Loop, iWidth, oImg, strRatio, oClassObj, oAnc, sFullPath;
    var i, j, k, v, idx;
    var iCount = 0;
    var iRealNum = 0;
    var iRankNo = 0;
    var iPrevNo = 0;
    var ua = window.navigator;

    if (ua.cookieEnabled){
        var cookieVal = getCookieValue( coABLESITE_STAT3 );
        if (cookieVal != null && cookieVal != iTopNum){
            iTopNum = cookieVal;
            @if (@DEBUG == 1) window.status = "iTopNum is stored as: " + iTopNum + "."; @end
        }
    }
    if (iTopNum <= 0){
        oOL.style.display = 'none';
        F.oTopContentCap.style.display = 'none';
        return;
    }

    // *----------------------------------------------------------------------------
    // *    Make Work Array to Sort Visitor Data by the Number (TOTAL/WEEKLY)
    // *----------------------------------------------------------------------------

    for (i=0, j=0, v=0; i<goContentLen; i++){

        oCell = goContent[i];
        if (oCell.vCells[giKeyPos3] == 0) continue;	// Skip No-data
        iRealNum ++;

        dtArray[j] = new pkCells(7);
        with(dtArray[j]){
            Cells[VIW_POS] = oCell.vCells[VIW_POS];	// [0]:Visitor/Week
            Cells[PVW_POS] = oCell.vCells[PVW_POS];	// [1]:Page Views/Week
            Cells[CLS_POS] = oCell.CLASS;			// [2]:Class Code(G1-G5)
            Cells[ORG_POS] = i;						// [3]:Save Original Data Position
            Cells[WRK_POS] = oCell.WRK;				// [6]:Save Worl Cell data
        }
        if (oCell.WRK > 0){ dtArray2[v++] = dtArray[j]; }
        iCount += dtArray[j].Cells[giKeyPos3];
        j++;
    }

    MAX_LIMIT = iRealNum;
    iTopNum = (iTopNum > MAX_LIMIT) ? MAX_LIMIT : iTopNum;

    // *----------------------------------------------------------------------------
    // *    Sorting the Work Data Array & Calculate the Ratio
    // *----------------------------------------------------------------------------

    qSort3(dtArray, 0, iRealNum);
    fnSetRMB2Info(dtArray2, v, 2);

    for (i=0; i<iRealNum; i++){
		with(dtArray[i]){
        	Cells[RAT_POS] = (Cells[giKeyPos3]/iCount) * 100;	// [4]: Ratio
        }
    }

    // *----------------------------------------------------------------------------
    // *    Make Work Array to Sort Chapter Title by Modified Date Order
    // *----------------------------------------------------------------------------

    var head = new Array();
    i = 0;
    head[i] = new pkCells(2);
    head[i].Cells[0] = "Rank";
    head[i].Cells[1] = "Rank Order";
         i++;
    head[i] = new pkCells(2);
    head[i].Cells[0] = "Ratio";
    head[i].Cells[1] = "Each Value/Total Value";
         i++;
    head[i] = new pkCells(2);
    head[i].Cells[0] = "PV";
    head[i].Cells[1] = "Total Page Views";
         i++;
    head[i] = new pkCells(2);
    head[i].Cells[0] = "UV";
    head[i].Cells[1] = "Total Unique Visitors";
         i++;
    head[i] = new pkCells(2);
    head[i].Cells[0] = "Class";
    head[i].Cells[1] = "Site Categories";
         i++;
    head[i] = new pkCells(2);
    head[i].Cells[0] = "Page Titles";
    head[i].Cells[1] = "Site Titles";
         i++;
    head[i] = new pkCells(2);
    head[i].Cells[0] = "Total Rank";
    head[i].Cells[1] = "Total Rank";
    var iColLen = ++i;

    with( document ){
        var oTable  = createElement( "TABLE" );
        var oTHead  = createElement( "THEAD" );
        var oTBody  = createElement( "TBODY" );
        var oCaps   = createElement( "CAPTION" );
    }
    oTBody.id = "oTbody";
    oTHead.id = "oHead";
    oRow = document.createElement( "TR" );
    with( oTHead ){
        appendChild( oRow );
        bgColor = "lightgrey";
    }
    with( oCaps ){
        innerText = "Created Using DOM.";
        align = "bottom";
    }
    for (i=0; i<iColLen; i++){
        oCell = document.createElement( "TH" );
        with(oCell){
            innerText = head[i].Cells[0];
            title     = head[i].Cells[1];
            if (i == (iColLen-1)){
				style.display = "none";
			}
        }
        oRow.appendChild( oCell );
    }

    head = null;

    with( oTable ){
        appendChild( oTHead );
        appendChild( oTBody );
        appendChild( oCaps  );
    }

    Loop = (iTopNum > iRealNum) ? iRealNum : iTopNum;
    giSaveTopNum3 = Loop;
    goClassData = new makeClassObj();
    k = giRmsgIdx2[OBJECT_ID2];

    // *-------------------------------------------------------
    // *    Main Procedure
    // *-------------------------------------------------------

    for (var q=0, i=0; i<iRealNum; i++){
//    for (var q=0, i=0; i<Loop; i++){
        if (dtArray[i].Cells[giKeyPos3] != iPrevNo){
            iRankNo = iRankNo + q + 1; q = 0;
            iPrevNo = dtArray[i].Cells[giKeyPos3];
        } else {
            q ++;
        }

        dtArray[i].Cells[RNK_POS] = iRankNo;	// [5]:Save Total Rank No
        oRow = document.createElement( "TR" );
        oRow.style.height = "0.5cm";

        idx = dtArray[i].Cells[ORG_POS];
        oClassObj = fnGetClassInfoByCID(dtArray[i].Cells[CLS_POS]);

        for (j=0; j<iColLen; j++){
            oCell = document.createElement( "TD" );
            switch(j){
                case 0: // Ranking No
                    with( oCell ){
                        innerText = iRankNo;
                        align = "center";
                    }
                    break;

                case 1: // Ratio
                    strRatio = (dtArray[i].Cells[RAT_POS].toString()).substr(0,4) + " %";
                    oCell.innerText = strRatio;
                    break;

                case 2: // PV (Total/Weekly)
                    with( oCell ){
                        innerText = dtArray[i].Cells[PVW_POS];    // CURRENT_PV_KEY
                        align = "center";
                    }
                    break;

                case 3: // UV (Total/Weekly)
                    with( oCell ){
                        innerText = dtArray[i].Cells[VIW_POS];    // CURRENT_VT_KEY
                        align = "center";
                    }
                    break;

                case 4: // CLass Name
                    if ((dtArray[i].Cells[WRK_POS] > 0) && (k != -1)){ // DISP_MORE_THAN3
                        oCell.innerHTML = "<a href='javascript:fnShowRichMbox2(" + (k++) + ");' title='Click to view more info. of " + oClassObj[0] + "'>" + oClassObj[0] + "</a>";
                    } else {
                        oCell.innerText = oClassObj[0];
                    }
                    break;

                case 5: // Page Title with link
					if (goContent[idx].FILE.indexOf("http://www") != -1){
						sFullPath = goContent[idx].FILE;
                    } else {
                    	sFullPath = oClassObj[1] + goContent[idx].FILE;	// Make Full Path
					}
                    sFullPath += ((dtArray[i].Cells[CLS_POS] == "G1") ||
                    			  (dtArray[i].Cells[CLS_POS] == "G5") ||
                    			  (dtArray[i].Cells[CLS_POS] == "G6") ||
                    			  (goContent[idx].FILE.lastIndexOf( "index" ) != -1) ||
                    			  (goContent[idx].FILE.indexOf( "/" ) != -1)) ? ".htm" : FILE_EXT;
                    oAnc = document.createElement( "A" );
                    with( oAnc ){
                        href = sFullPath;
                        target = "_blank";
                    }
                    oAnc.innerText = goContent[idx].TITLE;
                    oCell.appendChild( oAnc );
                    break;

                case 6:
                	with(oCell){
						style.display = "none";
						style.textAlign = "center";
                		innerText = dtArray[i].Cells[RNK_POS];
                	}
                	break;
                default:
                    break;
            }
            oRow.appendChild( oCell );
        }
        if (i >= Loop){ oRow.style.display = "none"; }
        oTBody.appendChild( oRow );
//        if (!gbList2UsedFlag) oTBody.appendChild( oRow );
    }   // for Loop end
    oOL.appendChild( oTable );

    goClassData = null;

    // *-------------------------------------------------------
    // *    Closing Procedure
    // *-------------------------------------------------------

	var	sText1, sText2;

	if (giKeyPos3 == 0){	// Visitors/Week
		sText1 = "Visited";
		sText2 = "Visitors";
	} else {
		sText1 = "Viewed";
		sText2 = "Views";
	}
	var	oOption, option2;
    with( document ){
        var oSelect1 = createElement( "SELECT" );
        var oSelect2 = createElement( "SELECT" );
        var oSelect3 = createElement( "SELECT" );
        var oSpan1   = createElement( "SPAN"   );
        var oSpan2   = createElement( "SPAN"   );
        var oSpan3   = createElement( "SPAN"   );
        var oSpan4   = createElement( "SPAN"   );
        var oSpan5   = createElement( "SPAN"   );
        var oSpan6   = createElement( "SPAN"   );
    }
    for (i=0; i<MAX_LIMIT; i++){
        oOption = document.createElement( "OPTION" );
        oOption.innerText = (i + 1);
        oSelect1.appendChild( oOption );
    }
    with( oSelect1 ){
        selectedIndex = iTopNum - 1;
        id = SELECT_ID3;
        onchange = fnClearSavedIndex;
        title = "Select Num to be showed at onece.";
    }
    options2 = new Array();
	options2[0] = "ALL CLASSES";
	options2[1] = "WD Analyzer";
	options2[2] = "JPL Lesson";
	options2[3] = "JPL Reading";
	options2[4] = "Edo History";
	options2[5] = "MISC";
	options2[6] = "CCEL";	// v2.10
//    for (i=0; i<6; i++){
    for (i=0; i<options2.length; i++){	// v2.10
        oOption = document.createElement( "OPTION" );
        oOption.innerText = options2[i];
        oOption.value = ((i == 0) ? "ALL" : options2[i]);
        oSelect2.appendChild( oOption );
    }
    with( oSelect2 ){
        selectedIndex = ((giSelMunu2Index != -1) ? giSelMunu2Index : 0);
        id = "oSelMenu2";
        onchange = fnFilterListByClass;
        title = "Select Class for filtering.";
    }
    options2 = new Array();
	options2[0] = "U, Visitors";
	options2[1] = "Page Views";
    for (i=0; i<2; i++){
        oOption = document.createElement( "OPTION" );
        with(oOption){
	        innerText = options2[i];
	        value 	  = options2[i];
        }
        oSelect3.appendChild( oOption );
    }
    with( oSelect3 ){
        selectedIndex = ((giSelMunu3Index != -1) ? giSelMunu3Index : giKeyPos3);	// Default is "Views/Week"
        id = "oSelMenu3";
        onchange = fnChangeListByKey;
        title = "Select Ranking Type.";
    }

    oSpan1.innerHTML = "Most recent top <span style='color:red;' id='DispVal0'>" + Loop + "</span> Contents " + sText1 +" Pages ( <span style='color:red;' id='DispVal1'>" + iRealNum + "</span> ): ";
    oSpan2.appendChild( oSelect1 );
    oSpan3.innerHTML = "　Period【" + START_DATE3 + "-" + END_DATE3 + "】";
    oSpan4.innerHTML = "　Total " + sText2 + "【 <span style='color:red;font-weight:bold;' id='DispVal2'>" + iCount + "</span> 】";
    oSpan5.appendChild( oSelect2 );
    oSpan6.appendChild( oSelect3 );
    with( F.oTopContentCap ){
        appendChild( oSpan1 );
        appendChild( oSpan2 );
        appendChild( oSpan3 );
        appendChild( oSpan4 );
        appendChild( oSpan5 );
        appendChild( oSpan6 );
        style.display = "";
    }
    var x = F[ "GEOMAP" ];
    if (x != null) x.title = "Period【" + START_DATE3 + "-" + END_DATE3 + "】";
    oOL.style.display = "";

//    var goContent     = null;   // Country Data Object release
//    var goContentLen  = 0;      // Country Data Record Length

    if (giSelMunu2Index != -1){
		fnFilterListByClass();
	}

}   // End of "fnSiteContentList"

// *-----------------[: Module Spelialised Utility Tools ]----------------------*
function fnClearSavedIndex(){
	giSaveIndex3 = -1;
	fnSiteContentList2();
}
function fnChangeListByKey(){
	giKeyPos3 = oSelMenu3.selectedIndex;
	giSelMunu3Index = giKeyPos3;
	fnSiteContentList2();
}

function fnFilterListByClass(){
	giSelMunu2Index = oSelMenu2.selectedIndex;
	var	oRows = oTbody.rows;
	var	iTargetCol = ((giKeyPos3 == 1) ? 2 : 3);
	var	iCount  = 0;
	var	iTotal  = 0;
	var	iPrevNo = 0;
	var	iRankNo = 0;
	var	q = 0;
	var	j = 1;
	var	sFilterText = oSelMenu2.options[oSelMenu2.selectedIndex].value;
	for (var i=0; i<oRows.length; i++){
		with(oRows[i]){
			style.display = "none";
			if (sFilterText == "ALL"){
				if (i==0) oHead.children(0).children(6).style.display = "none";
				children(6).style.display = "none";
				children(0).innerText = children(6).innerText;
				if (i < giSaveTopNum3) style.display = "";
				iCount ++;
				iTotal += eval(children(iTargetCol).innerText);
			} else {
				if (i==0) oHead.children(0).children(6).style.display = "";
				if (children(4).innerText == sFilterText){
			        if (children(iTargetCol).innerText != iPrevNo){
			            iRankNo = iRankNo + q + 1; q = 0;
			            iPrevNo = children(iTargetCol).innerText;
			        } else {
			            q ++;
			        }
					children(0).innerText = iRankNo;
					children(6).style.display = "";
					style.display = "";
					iCount ++;
					iTotal += eval(children(iTargetCol).innerText);
				} else {
					style.display = "none";
				}
			}
		}
	}
	oSelID3.selectedIndex = (sFilterText == "ALL") ? giSaveTopNum3-1 : iCount-1;
	DispVal0.innerText = (sFilterText == "ALL") ? giSaveTopNum3 : iCount;
	DispVal1.innerText = iCount;
	DispVal2.innerText = iTotal;
}

function fnSiteContentList2(){
    var ua = window.navigator;
    var x = F[ SELECT_ID3 ];

    if (x != null){
        var iValue = ((giSaveIndex3 != -1) ? giSaveIndex3+1 : x.selectedIndex+1);
        with( F ){
            oTopContent.innerHTML       = "";
            oTopContentCap.innerHTML    = "";
        }
        if (ua.cookieEnabled){
            setCookieValue( coABLESITE_STAT3, iValue, twoWeeks );
            @if (@DEBUG == 1) window.status = "Top Caps value: " + iValue + " saved."; @end
        }
        giSortKey[OBJECT_ID2] = giKeyPos3;
        fnSiteContentList(DIV_ID3, iValue, false, giSortKey[OBJECT_ID2]);
        gbClassUsedFlag = false;
    }
}

/* *----------------------------------------------------------------------------* */
/* *    Common Global Utilities                                                 * */
/* *----------------------------------------------------------------------------* */

function pkCells(n){
    this.Cells = new Array(n);
    // Don't change 'Cells' name, to be used other functions
    // 0: A Total Number
    // 1: A Weekly Number
    // 2: Original data position
    // 3: Ratio: to be calculate dynamically by PG
}

function fnSiteStatisticsLoader(){
    fnSiteCountryList ( DIV_ID1, 10, false, 0 );	// GEO
    fnSiteLanguageList( DIV_ID2,  5, false, 0 );	// LANG
    fnSiteContentList ( DIV_ID3, 15, false, 1 );	// Pages
}

/* *--------------------------------------------------------------------* */
function RMBPK2(n){
    this.oCells = new Array(n);
}
var goTit   = 0;
var goCap   = 1;
var goPic   = 2;
var goWid   = 3;
var goHgt   = 4;
var goMsg   = 5;
var goTip   = 6;
var goWrk   = 7;	// Work Space

var TheRichMbox2 = new Array();
var giRmsgIdx2   = new Array(3);
    giRmsgIdx2[0] = -1;
    giRmsgIdx2[1] = -1;
    giRmsgIdx2[2] = -1;

function fnSetRMB2Info(oRows, iRecNum, KeyIdx){
	var	wp = (KeyIdx == 2) ? 6 : 5;
    for (var n=0; n<iRecNum; n++){
        if (oRows[n].Cells[wp] == 0) break;
    }
    var i;
    var j;
    var oImageSizes;
    if (KeyIdx == 0){	// GEO Top
        j = 0;
        TheRichMbox2[j] = new RMBPK2(8);
        oImageSizes = getImageSizes( "top" );
        with(TheRichMbox2[j]){
            oCells[goTit] = "Site Statistics (S)-" + itoStr(2, (j+1));
            oCells[goCap] = "<B>GEO Map Overlay</B>";
            oCells[goPic] = "geol.jpg";
                            F.oBoxPic.src  = "geol.jpg";
                            @if (@DEBUG == 1) alert("File[" + j + "]= " + F.oBoxPic.src + " Width= " + oImageSizes[0] + " Height= " + oImageSizes[1]); @end
            oCells[goWid] = oImageSizes[0];
            oCells[goHgt] = oImageSizes[1];
            oCells[goMsg] = "<B>GEO Map Overlay:</B><br /><br />"
                          + "Period:<br />"
                          + "From: " + MOST_GEO_PERIOD_START1 + "<br />"
                          + "To　: " + MOST_GEO_PERIOD_END1 + "<br /><br />"
                          + "Total Cities:【 <span style='color:red;font-weight:bold;'>" + giTotalCities +  "</span> 】<br /><br />"
                          + "The Geo Map Overlay represents the volume of visitors coming from locations around the world. "
                          + "The largest points indicate locations driving the most visitors to our website.";
            oCells[goTip] = "Period:[ " + MOST_GEO_PERIOD_START1 + " - " + MOST_GEO_PERIOD_END1 + " ]";
        }
        j++;
    }
    giRmsgIdx2[KeyIdx] = giImageOffset[KeyIdx];
    // [j] should be 1.
    if (KeyIdx == 0){	// GEO/Top
        for (i=0; i<n; i++){
            TheRichMbox2[j] = new RMBPK2(8);
            oImageSizes = getImageSizes( (oRows[i].Cells[4]).toLowerCase() + "1" );
            with(TheRichMbox2[j]){
                oCells[goTit] = "Site Statistics (C)-" + itoStr(2, (i+1));
                oCells[goCap] = "<b>" + goCountry[oRows[i].Cells[2]].Name + " Details</b>";
                oCells[goPic] = "geo" + (oRows[i].Cells[4]).toLowerCase() + ".jpg";
                                F.oBoxPic.src  = oCells[goPic];
                                @if (@DEBUG == 1) alert("File[" + j + "]= " + F.oBoxPic.src + " Width= " + oImageSizes[0] + " Height= " + oImageSizes[1]); @end
                oCells[goWid] = oImageSizes[0];
                oCells[goHgt] = oImageSizes[1];
                oCells[goMsg] = "<B>" + goCountry[oRows[i].Cells[2]].Name + " Details:</B><br /><br />"
                              + "Total Cities; " + oRows[i].Cells[wp] + "<br />"
                              + "Period:<br />"
                              + "From: " + MOST_GEO_PERIOD_START1 + "<br />"
                              + "To　: " + MOST_GEO_PERIOD_END1 + "<br /><br />"
                              + "How do visitors from different regions compare with respect to conversions and average visit value? "
                              + "This report compares each geographic region's number of visits, pageviews per visit, conversion rates, "
                              + "and the average value of each visit.";
                oCells[goTip] = "Period:[ " + MOST_GEO_PERIOD_START1 + " - " + MOST_GEO_PERIOD_END1 + " ]";
            }
            j++;
        }
    } else if (KeyIdx == 1){	// Language
        goLangNames = new makeLANGType();
        j = giImageOffset[KeyIdx];
        for (i=0; i<n; i++){
            TheRichMbox2[j] = new RMBPK2(8);
            oImageSizes = getImageSizes( getLSM(oRows[i].Cells[4]).toLowerCase() + "2" );
            with(TheRichMbox2[j]){
                oCells[goTit] = "Site Statistics (L)-" + itoStr(2, (i+1));
                oCells[goCap] = "<b>" + oRows[i].Cells[4] + " Details</b>";
                oCells[goPic] = "lng" + getLSM(oRows[i].Cells[4]).toLowerCase() + ".jpg";
                                F.oBoxPic.src  = oCells[goPic];
                                @if (@DEBUG == 1) alert("File[" + j + "]= " + F.oBoxPic.src + " Width= " + oImageSizes[0] + " Height= " + oImageSizes[1]); @end
                oCells[goWid] = oImageSizes[0];
                oCells[goHgt] = oImageSizes[1];
                oCells[goMsg] = "<B>'" + oRows[i].Cells[4] + "' Details:</B><br /><br />"
                              + "Total Countries; " + oRows[i].Cells[wp] + "<br />"
                              + "Period:<br />"
                              + "From: " + MOST_GEO_PERIOD_START2 + "<br />"
                              + "To　: " + MOST_GEO_PERIOD_END2 + "<br /><br />"
                              + "How do visitors with different language preferences compare with respect to conversions "
                              + "and average visit value? This report compares number of visits, pageviews per visit, "
                              + "conversion rates, and average visit value for visitors according to the language preference "
                              + "they have set on their computer.";
                oCells[goTip] = "Period:[ " + MOST_GEO_PERIOD_START2 + " - " + MOST_GEO_PERIOD_END2 + " ]";
            }
            j++;
        }
        goLangNames = null;
    } else {	// KeyIdx == 2 Contents
		var	gPicInfo;
        j = giImageOffset[KeyIdx];
        for (i=0; i<n; i++){
			gPicInfo = getGCode(goContent[oRows[i].Cells[3]].FILE);
			sMsgCap  = goContent[oRows[i].Cells[3]].TITLE;
            TheRichMbox2[j] = new RMBPK2(8);
            oImageSizes = getImageSizes( gPicInfo[0] );	// [0]: sCode
            with(TheRichMbox2[j]){
                oCells[goTit] = "Site Statistics (T)-" + itoStr(2, (i+1));
                oCells[goCap] = "<b>" + sMsgCap + " Details</b>";
                oCells[goPic] = gPicInfo[1];	// [1]: Full-path name
                                F.oBoxPic.src  = oCells[goPic];
                                @if (@DEBUG == 1) alert("File[" + j + "]= " + F.oBoxPic.src + " Width= " + oImageSizes[0] + " Height= " + oImageSizes[1]); @end
                oCells[goWid] = oImageSizes[0];
                oCells[goHgt] = oImageSizes[1];
                oCells[goMsg] = "<B>'" + sMsgCap.substr(sMsgCap.length-4) + "' Details:</B><br /><br />"
                              + "Total Countries; " + oRows[i].Cells[wp] + "<br />"
                              + "Period:<br />"
                              + "From: " + MOST_GEO_PERIOD_START3 + "<br />"
                              + "To　: " + MOST_GEO_PERIOD_END3 + "<br /><br />"
                              + "Which HTML title tags are used on the most popular pages? This report compares pages "
                              + "by HTML title tag, aggregating as a single page those pages which have the same HTML title. "
                              + "Pages are compared in terms of the number of unique views, number of pageviews, the average "
                              + "time spent on the page(s), the percentage of time the page(s) is an exit page, and the $Index. "
                              + "The highest $Index indicate pages that were commonly visited prior to high-value conversions "
                              + "during the same visit. ";
                oCells[goTip] = "Period:[ " + MOST_GEO_PERIOD_START3 + " - " + MOST_GEO_PERIOD_END3 + " ]";
                oCells[goWrk] = oRows[i].Cells[giKeyPos3];	// Store Page View/Week
            }
            j++;
        }
        qSort4(TheRichMbox2, giImageOffset[KeyIdx], TheRichMbox2.length);
	}
}
function getGCode( sPath ){
	var	sRetObject = new Array(2);
	var	oWorkPath  = new Array();
	var	i = 0;									// Don't change G1-G6 Order (see sitedata.js ORDER)
//var W_PATH1 = "http://www.all.co.nz/word/";             // G1:ANALYZER
//var W_PATH2 = "http://www.all.co.nz/support/edo/";      // G2:HISTORY
//var W_PATH3 = "http://www.all.co.nz/support/lesson/";   // G3:LESSON
//var W_PATH4 = "http://www.all.co.nz/support/jpread/";   // G4:READING
//var W_PATH5 = "http://www.all.co.nz/";                  // G5:MISC
//var W_PATH6 = "http://www.all.co.nz/ccel/";             // G6:CCEL
	oWorkPath[i++] = W_PATH1 + "verbs";	// [G1]:動詞C
	oWorkPath[i++] = W_PATH2 + "index";	// [G2]:エッセイ
	oWorkPath[i++] = W_PATH3 + "index";	// [G3]:初級
	oWorkPath[i++] = W_PATH4 + "index";	// [G4]:大奥
	oWorkPath[i++] = W_PATH5 + "index";	// [G5]:Able Top
	oWorkPath[i++] = W_PATH6 + "index";	// [G6]:CCEL	v2.10
	var	n = i;
	for (i=0; i<n; i++){
		if (sPath == oWorkPath[i]){
			sRetObject[0] = "g" + (i+1) + "3";				// make sCode for "fnGetImageSizeInAdvance"
			sRetObject[1] = "cnt" + "g" + (i+1) + ".jpg";	// make full path for data pic file
			return( sRetObject );
		}
	}
	sRetObject[0] = "g53";				// make default sCode for "fnGetImageSizeInAdvance"
	sRetObject[1] = "cntg5.jpg";		// make default full path for data pic file
	return( sRetObject );
}
/* *--------------------------------------------------------------------* */
function partition4( rows, l, r ){
    // rows: Data Object Array to be partitioned
    // l: Left side object array number
    // r: Right side object array number

    var wkRow, PIVOT;

    var i = l - 1;
    var j = r;

    PIVOT = rows[r].oCells[7];   //

    if (gbImageSortDir == true){   // A
        do{
            while(rows[++i].oCells[7] < PIVOT);
            while((i < --j) && (PIVOT < rows[j].oCells[7]));
            if (i >= j) break;
            wkRow   = rows[i];
            rows[i] = rows[j];
            rows[j] = wkRow;
        }while(1);
    } else {                // D
        do{
            while(rows[++i].oCells[7] > PIVOT);
            while((i < --j) && (PIVOT > rows[j].oCells[7]));
            if (i >= j) break;
            wkRow   = rows[i];
            rows[i] = rows[j];
            rows[j] = wkRow;
        }while(1);
    }

    wkRow   = rows[i];
    rows[i] = rows[r];
    rows[r] = wkRow;

    return(i);
}
function qSort4( rows, start, end ){
    // rows:    Data Array to be sorted
    // start:   First record number to be sorted(0)
    // end:     Last  record number to be sorted(record length)

    var left;
    var right;
    var v;
    var sp;
    var low  = new Array();
    var high = new Array();

    low[0]  = start;
    high[0] = end-1;
    sp = 1;

    while(sp > 0){
        sp --;
        left    = low[sp];
        right   = high[sp];
        if (left >= right){
        } else {
            v = partition4(rows, left, right);
            if ((v - left) < (right - v)){
                low[sp]     = v + 1;
                high[sp++]  = right;
                low[sp]     = left;
                high[sp++]  = v - 1;
            } else {
                low[sp]     = left;
                high[sp++]  = v - 1;
                low[sp]     = v + 1;
                high[sp++]  = right;
            }
        }
    }
}

// ******************************************************************
// *    QUICK SORT Partition (To be called by "qSort3")
// ******************************************************************

function partition( rows, l, r ){
    // rows: Data Object Array to be partitioned
    // l: Left side object array number
    // r: Right side object array number

    var wkRow, PIVOT;

    var i = l - 1;
    var j = r;
    var iSpt = giSortKey[giSrtKeyPtr];

    PIVOT = rows[r].Cells[iSpt];   //

    if (gbSortOrder == true){   // A
        do{
            while(rows[++i].Cells[iSpt] < PIVOT);
            while((i < --j) && (PIVOT < rows[j].Cells[iSpt]));
            if (i >= j) break;
            wkRow   = rows[i];
            rows[i] = rows[j];
            rows[j] = wkRow;
        }while(1);
    } else {                // D
        do{
            while(rows[++i].Cells[iSpt] > PIVOT);
            while((i < --j) && (PIVOT > rows[j].Cells[iSpt]));
            if (i >= j) break;
            wkRow   = rows[i];
            rows[i] = rows[j];
            rows[j] = wkRow;
        }while(1);
    }

    wkRow   = rows[i];
    rows[i] = rows[r];
    rows[r] = wkRow;

    return(i);
}

// ******************************************************************
// *    QUICK SORT Engine for Web Site Statistics Use
// ******************************************************************

function qSort3( rows, start, end ){
    // rows:    Data Array to be sorted
    // start:   First record number to be sorted(0)
    // end:     Last  record number to be sorted(record length)

    var left;
    var right;
    var v;
    var sp;
    var low  = new Array();
    var high = new Array();

    low[0]  = start;
    high[0] = end-1;
    sp = 1;

    while(sp > 0){
        sp --;
        left    = low[sp];
        right   = high[sp];
        if (left >= right){
        } else {
            v = partition(rows, left, right);
            if ((v - left) < (right - v)){
                low[sp]     = v + 1;
                high[sp++]  = right;
                low[sp]     = left;
                high[sp++]  = v - 1;
            } else {
                low[sp]     = left;
                high[sp++]  = v - 1;
                low[sp]     = v + 1;
                high[sp++]  = right;
            }
        }
    }
}

// #################################################################################
// #    << End of satistics.js >> (C) 2006 Southern Cross Virtual Co., Ltd. (v1.3)
// #################################################################################

