﻿/* 05/28/2008 JPB: General JavaScript methods. */

        onerror=handleErr;
        var excMsg="";
        
        /// Handles unhandled exceptions.
        function handleErr(msg,url,l)
        {
            excMsg="There was an unhandled JS error on this page.\n\n";
            excMsg+="Error: " + msg + "\n";
            excMsg+="URL: " + url + "\n";
            excMsg+="Line: " + l + "\n\n";
            
            var divEx = document.getElementById('divException');
            if (divEx!=null)
            {
                var divExDet = document.getElementById('divExceptionDetails');
                divEx.style.visibility="visible";
                divExDet.innerHTML = excMsg;
            } else {
                excMsg+="Click OK to continue.\n\n";
                alert(excMsg);
            }
            return true;
        }
        
        /// Try/Catch block method.
        function handleException(ex)
        {
            var exMsg;
            exMsg="There was an error on this page.\n\n";
            //exMsg+="Error description: " + ex.description + "\n\n";
            exMsg+="Error description: " + ex + "\n\n";
            
            var divEx = document.getElementById('divException');
            if (divEx!=null)
            {
                var divExDet = document.getElementById('divExceptionDetails');
                divEx.style.visibility="visible";
                divExDet.innerHTML = exMsg;
            } else {
                exMsg+="Click OK to continue.\n\n";
                alert(exMsg);
            }
            return false; // 06/19/2008 JPB: This may need to be changed back to true.
        }

        /// Call from an element passing itself as the sender.
        function setVal(sender,targetId)
        {
            try
            {
                if (sender != null)
                {
                    if ((sender.value != null) && (sender.value != ''))
                    {
                        setValAndEnable(targetId, sender.value);
                    }
                }
            } catch(ex) { handleException(ex); }
        }
        
        /// Set an element value to the given value.
        function setValAndEnable(targetId,value)
        {
            try
            {
                var objTarget = document.getElementById(targetId);
                if (objTarget != null)
                {
                    objTarget.value = value;
                    //This acts like an enable feature. The item is not submitted unless it is visible.
                    objTarget.visible = true;
                }
            } catch(ex) { handleException(ex); }
        }

        /// Open a new pop-up window.
        function openWindow(theURL,winName,features) {
            try
            {
              window.open(decodeURI(theURL),winName,features);
            } catch(ex) { handleException(ex); }
        }
        
        /// Open a new pop-up window for large gallery images with pre-defined options.
        function openWindowForLargeGalleryPiece(theURL) {
            openWindow(encodeURI(theURL), '', 'resizable=yes,scrollbars=yes,toolbar=no,menubar=no,statusbar=no,directories=no,width=1040,height=470');
        }
        /// Open a new pop-up window for the primary gallery.
        function openWindowForGallery(theURL) {
            openWindow(encodeURI(theURL), '', 'toolbar=yes,toolbar=no,menubar=no,statusbar=no,directories=no,width=740,height=545');
        }

        /// Open a new pop-up window for the frames on the info page.
        function openWindowForFramePicture(theURL) {
            openWindow(encodeURI(theURL), '', 'resizable=yes,scrollbars=yes,toolbar=no,menubar=no,statusbar=no,directories=no,width=472,height=475');
        }

        /// To support legacy. Remove once migration is complete.
        function MM_openBrWindow(theURL, winName, features) {
            openWindow(theURL, winName, features);
        }