﻿/*
<summary>
JavaScript library for the A1WEB project.
</summary>
<copyright>Copyright © 2006  Technology One Ltd</copyright>
<qisheader>
 $History: a1web.js $
  
  *****************  Version 11  *****************
  User: Eddieg       Date: 9/10/06    Time: 5:10p
  Updated in $/Source/dev10/A1WEB/dev/VB.Net/A1WEB/A1WEB.Web/Scripts
  Toolbar must not be shown.
  
  *****************  Version 10  *****************
  User: Eddieg       Date: 9/10/06    Time: 3:39p
  Updated in $/Source/dev10/A1WEB/dev/VB.Net/A1WEB/A1WEB.Web/Scripts
  A1 Change Request 024 - New Print Request Slip page.
  
  *****************  Version 9  *****************
  User: Eddieg       Date: 18/08/06   Time: 10:55a
  Updated in $/Source/dev10/A1WEB/dev/VB.Net/A1WEB/A1WEB.Web/Scripts
  Change to handling of request slip URL.
  
  *****************  Version 8  *****************
  User: Eddieg       Date: 15/08/06   Time: 11:54a
  Updated in $/Source/dev10/A1WEB/dev/VB.Net/A1WEB/A1WEB.Web/Scripts
  Changed popups to display status bar.
  
  *****************  Version 7  *****************
  User: Eddieg       Date: 15/08/06   Time: 7:51a
  Updated in $/Source/dev10/A1WEB/dev/VB.Net/A1WEB/A1WEB.Web/Scripts
  Fixed: window.open returns null when popup blocker blocks.
  
  *****************  Version 6  *****************
  User: Amarjeets    Date: 25/07/06   Time: 4:38p
  Updated in $/Source/dev10/A1WEB/dev/VB.Net/A1WEB/A1WEB.Web/Scripts
  
  *****************  Version 5  *****************
  User: Eddieg       Date: 14/07/06   Time: 8:15a
  Updated in $/Source/dev10/A1WEB/dev/VB.Net/A1WEB/A1WEB.Web/Scripts
  Added comments to functions.
  
  *****************  Version 4  *****************
  User: Eddieg       Date: 7/07/06    Time: 9:23a
  Updated in $/Source/dev10/A1WEB/dev/VB.Net/A1WEB/A1WEB.Web/Scripts
  Fixed relative paths to popup pages.
  
  *****************  Version 3  *****************
  User: Eddieg       Date: 7/07/06    Time: 9:18a
  Updated in $/Source/dev10/A1WEB/dev/VB.Net/A1WEB/A1WEB.Web/Scripts
  
  *****************  Version 2  *****************
  User: Eddieg       Date: 6/07/06    Time: 1:43p
  Updated in $/Source/dev10/A1WEB/dev/VB.Net/A1WEB/A1WEB.Web/Scripts
  Initial check-in
  
</qisheader>
*/


/*
    Opens a new popup browser window using the specified URL and window name.
    
    If a window with the specified name is already open, then that same window 
    is re-used to open the URL.
*/
function openPopupWindow(sUrl, sWindowName) {

    if (!sWindowName) {
        sWindowName = "A1WEBPopupWindow";
    }

    var sFeatures = 'height=600, width=800, status=yes, resizable=yes, scrollbars=yes, toolbar=no,location=no, menubar=no, modal=yes, dialog=yes';
    var popup = window.open(sUrl, sWindowName, sFeatures);
    if (popup) {
        popup.focus();
    }
    return popup;

}


/*  
    Sets the return value and the associated description selected in a popup window.
    Once the value and description are set, the popup window is closed and the parent
    window is displayed.
*/
function setPopupResult(valueControlId, value, descriptionControlId, description) {

    var valueControl = window.opener.document.getElementById(valueControlId)
    if (valueControl) {
        valueControl.value = value;
    }
    
    var descriptionControl = window.opener.document.getElementById(descriptionControlId)
    if (descriptionControl) {
        descriptionControl.value = description;        
    }
    
    if (window.opener) {
        window.opener.focus();
    }
    self.close();
    
    return true;

}

/* 
    Opens the Select Agency Dialog and specifies the controls into which the 
    selected agency's Agency ID and Title should be populated on return.
*/
function openSelectAgencyDialog(valueControlId, descriptionControlId) {

    var sUrl = '../Search/SelectAgency.aspx?valueControlId=' + escape(valueControlId) +
            '&descriptionControlId=' + descriptionControlId;
            
    var sWindowName = "SelectAgencyWindow";
    
    return openPopupWindow(sUrl, sWindowName);

}


/* 
    Opens the Select Series Dialog and specifies the controls into which the 
    selected agency's Series ID and Title should be populated on return.
*/
function openSelectSeriesDialog(valueControlId, descriptionControlId) {

    var sUrl = '../Search/SelectSeries.aspx?valueControlId=' + escape(valueControlId) +
            '&descriptionControlId=' + descriptionControlId;
    
    var sWindowName = "SelectSeriesWindow";
    
    return openPopupWindow(sUrl, sWindowName);

}


/* 
    Opens the Select Thesaurus Dialog and specifies the controls into which the 
    selected agency's Term ID and Description should be populated on return.
    The Term Type indicates the type of thesaurus term that a user can select.
*/
function openSelectThesaurusTermDialog(valueControlId, descriptionControlId, termTypeCd) {
    
    var sUrl = 
        '../Search/SelectThesaurusTerm.aspx?valueControlId=' + escape(valueControlId) + 
        '&descriptionControlId=' + descriptionControlId +
        '&TermTypeCd=' + termTypeCd;
    
    var sWindowName = "SelectThesaurusTermWindow";
    
    return openPopupWindow(sUrl, sWindowName);

}


/* 
    Opens a popup window displaying the Print Item Request Dialog.
    
    Parameters:
    - sURL: The URL to the print item request page.
*/
function openPrintItemRequestDialog(sPrintItemRequestURL) {
    
    var sUrl = sPrintItemRequestURL;
    var sWindowName = "PrintRequestSlip";
    var sFeatures = 'height=600, width=800, status=yes, resizable=yes, scrollbars=yes, toolbar=no, location=no, menubar=no, modal=yes, dialog=yes';
    var popup = window.open(sUrl, sWindowName, sFeatures);
    if (popup) {
        popup.focus();
    }
    return popup;

}

