if (typeof(oPopup) == "undefined"){
    var oPopup = window.createPopup();
}
var popupBody   = oPopup.document.body;

/* *--------------------------------------------------------------------* */
/* *    Rich Message Box for Photo                                      * */
/* *--------------------------------------------------------------------* */
var giBoxNum    = 0;
var TheRichMbox = null;

var aTit = new Array();
var aCap = new Array();
var aPic = new Array();
var aWid = new Array();
var aHgt = new Array();
var aMsg = new Array();
var aTip = new Array();

function stPack(title, cap, pic, width, height, msg, tip){
    this.Title  = title;    // 0
    this.Cap    = cap;      // 1
    this.Pic    = pic;      // 2
    this.Width  = width;    // 3
    this.Height = height;   // 4
    this.Msg    = msg;      // 5
    this.Tip    = tip;      // 6
}

function makeRichMbox(){
    var i = 0;
    for (var i=0; i<giBoxNum; i++){
        this[i] = new stPack( aTit[i], aCap[i], aPic[i], aWid[i], aHgt[i], aMsg[i], aTip[i] );
    }
    this.length = i;
}

function fnRichMsfBoxErr( sObjName ){
    var strErrMsg = "Fatal Error: Rich-Message-Box Object '" + sObjName + "' might be NOT defined in the HTML source code."
                  + "\n\n    Please contact with Mr H. Sekine at info@all.co.nz.";
    window.alert( strErrMsg );
}

function fnShowRichMbox(n){
    if (typeof( oBoxTitle ) != "object"){ fnRichMsfBoxErr( "oBoxTitle" ); return; }
    if (typeof( oBoxMsg   ) != "object"){ fnRichMsfBoxErr( "oBoxMsg"   ); return; }
    if (typeof( oBoxCap   ) != "object"){ fnRichMsfBoxErr( "oBoxCap"   ); return; }
    if (typeof( oBoxPic   ) != "object"){ fnRichMsfBoxErr( "oBoxPic"   ); return; }
    if (typeof( oImgFrm   ) != "object"){ fnRichMsfBoxErr( "oImgFrm"   ); return; }
    if (typeof(TheRichMbox[n]) != "object"){ alert("Sorry! This RichMsgBox is still under construnction."); return; }
    var TheBox     = TheRichMbox[n];
    var lineWidth  = TheBox.Width  + 20;
    var lineHeight = TheBox.Height +  5;

    with( TheBox ){
        oBoxTitle.innerHTML       = Title;
        oBoxMsg.innerHTML         = Msg;
        oBoxCap.innerHTML         = Cap;
        oBoxPic.src               = Pic;
        oBoxPic.title             = Tip;
        oBoxPic.style.pixelWidth  = Width;
        oBoxPic.style.pixelHeight = Height;
        oImgFrm.style.pixelWidth  = lineWidth;
        oImgFrm.style.pixelHeight = lineHeight;
    }
    fnShowPooupDialog();
}

function fnShowRichMbox2(n){
    if (typeof( oBoxTitle ) != "object"){ fnRichMsfBoxErr( "oBoxTitle" ); return; }
    if (typeof( oBoxMsg   ) != "object"){ fnRichMsfBoxErr( "oBoxMsg"   ); return; }
    if (typeof( oBoxCap   ) != "object"){ fnRichMsfBoxErr( "oBoxCap"   ); return; }
    if (typeof( oBoxPic   ) != "object"){ fnRichMsfBoxErr( "oBoxPic"   ); return; }
    if (typeof( oImgFrm   ) != "object"){ fnRichMsfBoxErr( "oImgFrm"   ); return; }
    if (typeof(TheRichMbox2[n]) != "object"){ alert("Sorry! This RichMsgBox2[" + n + "] is still under construnction."); return; }
    var TheBox     = TheRichMbox2[n];
    var lineWidth  = TheBox.Width  + 20;
    var lineHeight = TheBox.Height +  5;

    with( TheBox ){
        oBoxTitle.innerHTML       = oCells[0];
        oBoxMsg.innerHTML         = oCells[5];
        oBoxCap.innerHTML         = oCells[1];
        oBoxCap.style.width       = oCells[3];
        oBoxPic.src               = oCells[2];
        oBoxPic.title             = oCells[6];
        oBoxPic.style.pixelWidth  = oCells[3];
        oBoxPic.style.pixelHeight = oCells[4];
        oImgFrm.style.pixelWidth  = lineWidth;
        oImgFrm.style.pixelHeight = lineHeight;
    }
    fnShowPooupDialog();
}

function fnShowPooupDialog(){
    if (typeof( oRichMsgBox ) != "object"){
        fnRichMsfBoxErr( "oRichMsgBox" );
        return;
    }
    popupBody.innerHTML = oRichMsgBox.innerHTML;
    oPopup.show(0, 0, 300, 0);
    with( popupBody ){
        var realHeight = scrollHeight;
        var realWidth  = scrollWidth;
    }
    oPopup.hide();
    oPopup.show(100, 50, realWidth+10, realHeight+10);
}

/* *--------------------------------------------------------------------* */
/* *    Rich Message Box for Text                                       * */
/* *--------------------------------------------------------------------* */

//var giBoxNum2    = 0;
//var TheRichMbox2 = null;

function RTPK(){        // Data Entry Constructor
    this.Title  = "";   // Msg Box Title: String
    this.Cap    = "";   // Data Entry Caption: String
    this.Div    = "";   // Data Entry Container <DIV id="oBoxDiv2">:(innerHTML)
    this.Width  = "";
    this.Height = "";
    this.Msg    = "";   // Extended Description
    this.Tip    = "";   // Data Entry Tip: String
}


function fnRichMsfBoxErr2( sObjName ){
    var strErrMsg = "Fatal Error: Rich-Message-Box Object '" + sObjName + "' might be NOT defined in the HTML source code."
                  + "\n\n    Please contact with Mr H. Sekine at info@all.co.nz.";
    window.alert( strErrMsg );
}

function fnShowRichMbox22(n){
    // n: Data Object Array number (0,1,2...) to be showed
    if (typeof( oBoxTitle2 ) != "object"){ fnRichMsfBoxErr( "oBoxTitle2" ); return; }
//    if (typeof( oBoxMsg2   ) != "object"){ fnRichMsfBoxErr( "oBoxMsg2"   ); return; }
//    if (typeof( oBoxCap2   ) != "object"){ fnRichMsfBoxErr( "oBoxCap2"   ); return; }
    if (typeof( oBoxDiv2   ) != "object"){ fnRichMsfBoxErr( "oBoxDiv2"   ); return; }
    if (typeof( oImgFrm2   ) != "object"){ fnRichMsfBoxErr( "oImgFrm2"   ); return; }
//    if (typeof(TheRichMbox2[n]) != "object"){ fnRichMsfBoxErr( "Object ID: " + n.toString() ); return; }
    if (typeof(TheRichMbox2[n]) != "object"){ alert("Sorry! This RichMsgBox is still under construnction."); return; }

    var TheBox     = TheRichMbox2[n];   // Extract Target Data Structure
    var lineWidth  = TheBox.Width  + 20;    // 20
    var lineHeight = TheBox.Height +  5;    // 5

    with( TheBox ){ // Data binding to WorkSpace HTML Tag Elements
        oBoxTitle2.innerHTML       = Title;
//        oBoxMsg2.innerHTML         = Msg;
        oBoxDiv2.title             = Tip;
        oBoxDiv2.innerHTML         = Div;
        oBoxDiv2.style.pixelWidth  = oBoxDiv2.clientWidth;      // Modify with real data
        oBoxDiv2.style.pixelHeight = oBoxDiv2.clientHeight;     // Modify with real data
        oImgFrm2.style.pixelWidth  = lineWidth;     // Adjust to fit real size
        oImgFrm2.style.pixelHeight = lineHeight;    // Adjust to fit real size
//        oBoxCap2.innerHTML         = Cap;
    }
    fnShowPooupDialog2();
}
function fnShowPooupDialog2(){
    if (typeof( oRichMsgBox2 ) != "object"){
        fnRichMsfBoxErr( "oRichMsgBox2" );
        return;
    }
    popupBody.innerHTML = oRichMsgBox2.innerHTML;
    oPopup.show(0, 0, 300, 0);
    with( popupBody ){
        var realHeight = scrollHeight;
        var realWidth  = scrollWidth;
    }
    oPopup.hide();
    oPopup.show(100, 50, realWidth+10, realHeight+10);
}

