
/***************************************************************************
'// Function: OpenPopUpWin2
'// ARGUMENTS: sFilename	- file to be load in new window
'//				sWinName 	- name of the new window
'//				iWidth		- width of the new window
'//				iHeight 		- height of the new window
'// Return Value: (N/A)
'// Purpose: Open a pop up window
'// Last Modified By: Larry Yu (21Sep2001, 16:20)
'//----------------------------Change History-----------------------------
'// History:
'//
***************************************************************************/
function OpenPopUpWin2(sFilename, sWinName, iWidth, iHeight) {
    var oNewWindow;
    
    oNewWindow = window.open(sFilename,sWinName,"width="+iWidth+",height="+iHeight+",resizable=yes,alwaysRaised=yes,scrollbars=yes,status=no,toolbar=no,menubar=no,locationbar=no");
	return true;
}

/***************************************************************************
'// Function: trim
'// ARGUMENTS: sString  - String to be trimmed
'// Return Value: a string without the leading and trailing spaces
'// Purpose: Remove any leading and trailing spaces in a string
'// Last Modified By: Stanley Lee (16Jun2000, 16:20)
'//----------------------------Change History-----------------------------
'// History:
'//
***************************************************************************/
function trim(sString) {
    var sChar, iCounter0, iCounter1;
    
    if (sString=="" || sString==null) return sString;
    
    iCounter0 = 0;
    sChar = sString.charAt(0);
    while (sChar==" " && iCounter0<sString.length) {
        sChar = sString.charAt(iCounter0);
        if (sChar==" ") iCounter0++;
    }
    
    iCounter1 = sString.length-1;
    sChar = sString.charAt(sString.length-1);
    while (sChar==" " && iCounter1>=0) {
        sChar = sString.charAt(iCounter1);
        if (sChar==" ") iCounter1--;
    }

    if (iCounter0>iCounter1) return "";
    return sString.substring(iCounter0, iCounter1+1);
}


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

/***************************************************************************
'// Function: changeCheckboxStatus
'// ARGUMENTS: oForm    - the form object contains the checkboxes
'//            iFlag    - determine to select or deselect all checkboxes in
'//                       a form (0 deselect all; 1 select all; -1 inverse
'//                       selection)
'// Return Value: false
'// Purpose: to select or deselect checkboxes in a form
'// Last Modified By: Stanley Lee (23Jun2000, 10:53)
'//----------------------------Change History-----------------------------
'// History:
'//
***************************************************************************/
function changeCheckboxStatus(oForm, iFlag) {
    for (var i=0; i<oForm.elements.length; i++) {
        if (oForm.elements[i].type.toLowerCase()=="checkbox") {
            switch (iFlag) {
            case -1:
                oForm.elements[i].checked = !(oForm.elements[i].checked);
                break;
            case 0:
                oForm.elements[i].checked = false;
                break;
            case 1:
                oForm.elements[i].checked = true;
                break;
            default:
                break;
            }
        }
    }
    return false;
}

/***************************************************************************
'// Function: showtip
'// ARGUMENTS: current  - the layer object
'//            e        - event object
'//            text     - the text to be displayed
'// Return Value: (N/A)
'// Purpose: to display the text
'// Last Modified By: Stanley Lee (23Jun2000, 10:53)
'//----------------------------Change History-----------------------------
'// History:
'//
***************************************************************************/
function showtip(current,e,text)
{
   if (document.all)                    // for Internet Explorer
   {
      thetitle=text.split('<br>')
      if (thetitle.length > 1)
      {
        thetitles=""
        for (i=0; i<thetitle.length; i++)
           thetitles += thetitle[i] + "\r\n"
        current.title = thetitles
      }
      else current.title = text
   }
   else if (document.layers)            // for Netscape
   {
       document.tooltip.document.write( 
           '<layer bgColor="#FFFFE7" style="border:1px ' +
           'solid black; font-size:12px;color:#000000;">' + text + '</layer>')
       document.tooltip.document.close()
       document.tooltip.left=e.pageX+5
       document.tooltip.top=e.pageY+5
       document.tooltip.visibility="show"
   }
}

/***************************************************************************
'// Function: hidetip
'// ARGUMENTS: (N/A)
'// Return Value: (N/A)
'// Purpose: to hide the text
'// Last Modified By: Stanley Lee (23Jun2000, 10:53)
'//----------------------------Change History-----------------------------
'// History:
'//
***************************************************************************/
function hidetip()
{
    if (document.layers)
        document.tooltip.visibility="hidden"
}

/***************************************************************************
'// Function: checkCheckedCheckbox
'// ARGUMENTS: oForm        - the form object
'//            sQuestion    - the question ask for the user when at least
'//                            one checked boxes is found
'//            sMesg        - the message displayed to user when no checked
'//                            check box
'// Return Value: true if there is any checked checkboxes and user press
'//               YES; otherwise, false
'// Purpose: To check in a form, if there is any checked checkboxes, prompt
'//          a YES/NO box to ask for the user, returns a true or false
'//          value depending on whether there is checked checkboxes and
'//          the response of the user to the question
'// Note: If sQuestion is null or an empty string or contains spaces only,
'//       and there is checked checkbox in oForm, then returns true without
'//       prompting the question
'// Last Modified By: Stanley Lee (08Jul2000, 12:05)
'//----------------------------Change History-----------------------------
'// History:
'//
***************************************************************************/
function checkCheckedCheckbox(oForm, sQuestion, sMesg) {
    for (var i=0; i<oForm.elements.length; i++) {
        if (oForm.elements[i].type.toLowerCase()=="checkbox") {
            if (oForm.elements[i].checked) {
                // If sQuestion is null or empty string or contains
                // spaces only, return true without prompting the
                // question
                if (sQuestion==null || trim(sQuestion).length==0)
                    return true;
                    
                if (confirm(sQuestion))
                    return true;
                else
                    return false;
            }
        }
    }
    
    alert(sMesg);
    return false;
}

/***************************************************************************
'// Function: checkRemoveItem
'// ARGUMENTS: oForm
'// Return Value: true if there is any selected items to be removed, and
'//               user confirm to remove; otherwise, false
'// Purpose: To check for any selected items to be removed, and require
'//          the user to confirm for removal operation before removal
'// Last Modified By: Stanley Lee (08Jul2000, 12:15)
'//----------------------------Change History-----------------------------
'// History:
'//
***************************************************************************/
function checkRemoveItem(oForm){
    var sQuestion = "Remove selected item(s)?";
    var sMesg = "Please select at least one item!";
    
    return checkCheckedCheckbox(oForm, sQuestion, sMesg);
}

/***************************************************************************
'// Function: checkApproveItem
'// ARGUMENTS: oForm
'// Return Value: true if there is any selected items to be approved, and
'//               user confirm to approve; otherwise, false
'// Purpose: To check for any selected items to be approved, and require
'//          the user to confirm for approval operation before approval
'// Last Modified By: Stanley Lee (08Jul2000, 12:25)
'//----------------------------Change History-----------------------------
'// History:
'//
***************************************************************************/
function checkApproveItem(oForm){
    var sQuestion = "Approve selected item(s)?";
    var sMesg = "Please select at least one item!";
    
    return checkCheckedCheckbox(oForm, sQuestion, sMesg);
}
