﻿    // Description:  This function prevents the enter key from submitting
    //               a form.  It can be applied to the form as a whole or
    //               a specific element in the form such as a textbox.
    //
    // Here is a C# example:
    // txtName.Attributes.Add("onKeyDown", "return DisableEnterKey(event);");
    //
    // http://www.w3schools.com/jsref/jsref_onkeydown.asp
    // http://www.bloggingdeveloper.com/post/Disable-Form-Submit-on-Enter-Key-Press.aspx
    function DisableEnterKey(e)
    {
        var keynum;
        
        // IE
        if (window.event)
        {
            keynum = e.keyCode;
        }
        // Firefox/Netscape/Opera
        else if (e.which)
        {
            keynum = e.which;
        }    
    
        // If the "Enter" key was pressed then
        // cancel the event.
        return (keynum != 13);
    }
    
    
    
    
    //_________________________________________________________________________________________________________________________
    // Description:  Opens a pop-up window.
    // Author:  John Hanold
    // Created:  3/20/2008.
    // Notes:
    //
    // url:  The url to be opened in the window.
    // name:  The unique name of the window.
    // width:  The width of the window.
    // height:  The height of the window.
    // toolbar:  Display the toolbar. 1 = yes, 0 = no.
    // menubar:  Display the menubar. 1 = yes, 0 = no.
    // resizalbe:  Allow the window to be resizable.  1 = yes, 0 = no.
    // scrollbars:  Display scrollbars.  1 = yes, 0 = no.
    // status:  Display the status bar.  1 = yes, 0 = no.
    // location: Display the location bar.  1 = yes, 0 = no.
    function PopUpWindow(url, name, width, height, toolbar, menubar, resizable, scrollbars, status, location)
    {
        var options = "width=" + width + ",height=" + height + 
                    ",toolbar=" + toolbar + ",menubar=" + menubar + ",resizable=" + resizable + 
                    ",scrollbars=" + scrollbars + ",status=" + status + ",location=" + location;
    
        newwindow = window.open(url, name, options);
    }




    //_________________________________________________________________________________________________________________________
    // Description: Closes the current window.
    // Author:  John Reiner
    // Created: 02/16/2009
    // Notes:   Exceptions will not be handled.
    function CloseWindow(reloadParent) {
        try {
            if (reloadParent) {
                var myOpener = window.opener;
                if (myOpener != null || myOpener != undefined) {
                    myOpener.focus();
                    myOpener.location.reload(true);
                }
            }
            window.close();
        } catch (e) {
        }
    }

    //_________________________________________________________________________________________________________________________
    // Description: Sets height and width of an iframe so that it fills a MyCrossCom page at any window size.
    // Author:  John Reiner
    // Created: 05/02/2009
    // Notes:   You must specify the id of the iframe element to size.
    //          Specify the height and width (as integers) of any other content, excluding the template header, on your page.
    //          This function works best when used in the document onload or onresize events.
    //          Because of an IE6 bug that causes the onresize event to trigger itself in an infinite loop,
    //          set a flag to false and then reset later when it is safe to proceed.
    var canResize = true;
    function SetIframeDimensions(id, additonalContentHeight, additionalContentWidth) {
        if (canResize) {
            canResize = false;
            // Get handles to the iframe and the divContent element.
            var iframe = document.getElementById(id);
            var divContent = document.getElementById('divContent');

            // Set the height of the MyCrossCom template header and menus.
            var headerHeight = 120;

            // Subtract additional content dimensions, plus template height.
            var iframeHeight = divContent.offsetHeight - (additonalContentHeight || 0) - headerHeight;
            var iframeWidth = divContent.offsetWidth - (additionalContentWidth || 0);

            // Set the dimensions.
            iframe.style.height = iframeHeight + 'px';
            iframe.style.width = iframeWidth + 'px';

            // Reset the canResize flag in 1/10th of a second.
            setTimeout("canResize = true;", 100);
        }
    }

