/**
   @file  pro-cm.js
   @brief Common part functions for posting/querying the post.

   <pre>
   Create: 2007/05/06, Sun, 11:17:59
   Update: 2007/05/06
   </pre>

   Copyright (C) 2007. All Rights Reserved.
   @author À¹§¡®a (Dai, Juin-Jia)
           [jjdai@mercury.cs.nthu.edu.tw, jjdai.bbs@moca.csie.chu.edu.tw]
*/

//@ ===== Global Variable(s) =====

//@ ===== Function(s) / Class(s) =====
function ProPost_Init(iInComId, sInComMsg, iInInduId, sInInduMsg, iInJobId, sInJobMsg)
{
    if ( 0 != iInComId )
    {
        ComName.innerHTML = '<b>' + sInComMsg + '</b>';
    }
    else
    {
        ComName.innerHTML = sInComMsg;
    }
    ComName.innerHTML += ' [ComId = ' + iInComId + ']';

    if ( 0 != iInInduId )
    {
        InduName.innerHTML = '<b>' + sInInduMsg + '</b>';
    }
    else
    {
        InduName.innerHTML = sInInduMsg;
    }
    InduName.innerHTML += ' [InduId = ' + iInInduId + ']';

    if ( 0 != iInJobId )
    {
        JobName.innerHTML = '<b>' + sInJobMsg + '</b>';
    }
    else
    {
        JobName.innerHTML = sInJobMsg;
    }
    JobName.innerHTML += ' [JobId = ' + iInJobId + ']';
}  //@ END OF ProPost_Init()

function ProModify_Init(iInComId, sInComMsg, iInInduId, sInInduMsg, iInJobId, sInJobMsg)
{
    ///if ( 0 != iInComId )
    ///{
    ///    ComName.innerHTML = '<b>' + sInComMsg + '</b>';
    ///}
    ///else
    ///{
    ///    ComName.innerHTML = sInComMsg;
    ///}
    ///ComName.innerHTML += ' [ComId = ' + iInComId + ']';

    if ( 0 != iInInduId )
    {
        InduName.innerHTML = '<b>' + sInInduMsg + '</b>';
    }
    else
    {
        InduName.innerHTML = sInInduMsg;
    }
    InduName.innerHTML += ' [InduId = ' + iInInduId + ']';

    if ( 0 != iInJobId )
    {
        JobName.innerHTML = '<b>' + sInJobMsg + '</b>';
    }
    else
    {
        JobName.innerHTML = sInJobMsg;
    }
    JobName.innerHTML += ' [JobId = ' + iInJobId + ']';
}  //@ END OF ProModify_Init()

function GetComName_OpenWin(sInHost, iAddNew)
{
    var sProps = 'scrollBars=yes,resizable=no,toolbar=no,menubar=no,location=no,directories=no,width=450,height=400';
    var sUrl = sInHost + 'company-get-name.php';

    if ( 0 == iAddNew )
    {
        sUrl += '?a=0';
    }

    window.open(sUrl, "", sProps);
}  //@ END OF GetComName_OpenWin()

function GetComName_OnSelect(sInComName, iInComId, iInInduId, sInInduName)
{
    if ( 0 == parent.opener.document.profile_fm.ComSelTp.value )
    {
        parent.opener.document.profile_fm.ComId.value   = iInComId;
        parent.opener.ComName.innerHTML = '<b>' + sInComName + '</b> [ComId = ' + iInComId + ']';

        if ( 0 != iInInduId )
        {
            parent.opener.document.profile_fm.InduId.value   = iInInduId;
            parent.opener.InduName.innerHTML = '<b>' + sInInduName + '</b> [InduId = ' + iInInduId + ']';
        }
    }
    else
    {
        parent.opener.document.profile_fm.ComName.value = sInComName;
    }

    window.close();
}  //@ END OF GetComName_OnSelect()

function GetInduName_OpenWin(sInHost)
{
    var sProps = 'scrollBars=yes,resizable=no,toolbar=no,menubar=no,location=no,directories=no,width=450,height=400';
    var sUrl = sInHost + '/industry-get-name.php';

    window.open(sUrl, "", sProps);
}  //@ END OF GetInduName_OpenWin()

function GetInduName_OnSelect(sInInduName, iInInduId)
{
    //parent.opener.document.profile_fm.InduName.value = sInInduName;
    parent.opener.document.profile_fm.InduId.value   = iInInduId;
    parent.opener.InduName.innerHTML = '<b>' + sInInduName + '</b> [InduId = ' + iInInduId + ']';

    window.close();
}  //@ END OF GetInduName_OnSelect()

function GetJobName_OpenWin(sInHost)
{
    var sProps = 'scrollBars=yes,resizable=no,toolbar=no,menubar=no,location=no,directories=no,width=450,height=400';
    var sUrl = sInHost + '/job-get-name.php';

    window.open(sUrl, "", sProps);
}  //@ END OF GetJobName_OpenWin()

function GetJobName_OnSelect(sInJobName, iInJobId)
{
    //parent.opener.document.profile_fm.JobName.value = sInJobName;
    parent.opener.document.profile_fm.JobId.value   = iInJobId;
    parent.opener.JobName.innerHTML = '<b>' + sInJobName + '</b> [JobId = ' + iInJobId + ']';

    window.close();
}  //@ END OF GetJobName_OnSelect()

function Location_OpenWin(sInHost)
{
    var sProps = 'scrollBars=yes,resizable=no,toolbar=no,menubar=no,location=no,directories=no,width=450,height=400';
    var sUrl = sInHost + '/location-get-name.php';

    window.open(sUrl, "", sProps);
}  //@ END OF Location_OpenWin()

function Location_Add(sInStr, iInLocaId)
{
    var oTarget = parent.opener.document.getElementById('LocaOpt');
    var oMsg = parent.opener.document.getElementById('LocaMsg');
    var iI;
    var iLen = oTarget.length;

    for ( iI = 0; iI < iLen; iI++ )
    {
        if ( sInStr == oTarget.options[iI].text )
        {
            oMsg.innerHTML = '[' + sInStr + '] was existed already.';
            window.close();

            return;
        }
    }

    var oOpt = parent.opener.document.createElement("OPTION");

    //parent.opener.document.profile_fm.LocaOpt.options[iLen] = new Option(sInStr, iInLocaId);
    //window.parent.opener.document.profile_fm.LocaOpt.add(new Option(sInStr, iInLocaId));
    oTarget.options.add(oOpt);
    oOpt.text  = sInStr;
    oOpt.value = iInLocaId;

    oMsg.innerHTML = '[' + sInStr + '] was added.';
    window.close();
}  //@ END OF Location_Add()

function Location_Remove()
{
    var oTarget = document.getElementById('LocaOpt');

    if ( 0 <= oTarget.selectedIndex )
    {
        LocaMsg.innerHTML = '[' + oTarget.options[oTarget.selectedIndex].text + '] was deleted.';
        oTarget.options[oTarget.selectedIndex] = null;
    }
}  //@ Location_Remove()

function Location_FormPara()
{
    var oTarget = document.getElementById('LocaOpt');
    var iI;
    var iLen = oTarget.length;

    for ( iI = 0; iI < iLen; iI++ )
    {
        var oEle = document.createElement('input');

        oEle.name  = 'LocationArr[' + iI + ']';
        oEle.type  = 'hidden';
        oEle.value = oTarget.options[iI].value;
        document.profile_fm.appendChild(oEle);
    }

    document.profile_fm.submit();
}  //@ END OF Location_FormPara()

