﻿// copyright MAJENKA - http://majenka.net

// utils functions       

//================================================================================================    

function Utils() {}

// set the button to be clicked when the enter button is pressed
Utils.ClickButton = function(e, buttonId)
{
    var button = document.getElementById(buttonId); 
    
    if (typeof button == 'object')
    { 
        if(navigator.appName.indexOf("Netscape") > (-1))
        { 
            if (e.keyCode == 13)
            { 
                button.click(); 
                event.returnValue = false;
                
                return false; 
            } 
        } 
        
        if (navigator.appName.indexOf("Microsoft Internet Explorer") > (-1))
        { 
            if (event.keyCode == 13)
            { 
                button.click(); 
                event.returnValue = false;
                
                return false; 
            } 
        } 
    }
}

// clears the selection in a list box 
Utils.ClearListBoxSelection = function(elementId)
{
    var list = document.getElementById(elementId);
    
    if (list) list.selectedIndex = -1;
}
    
// pop up window function
// some possible features "toolbar = 0, scrollbars = 1, location = 0, 
//  statusbar = 0, menubar = 0, resizable = 0, width = 700, height = 500, 
//  left = 200, top = 100";

Utils.OpenWindow = function(url, width, height)
{       
    var left = parseInt((screen.availWidth / 2) - (width / 2));
    var top = parseInt((screen.availHeight / 2) - (height / 2));
    
    var windowFeatures = "width = " 
        + width 
        + ", height = " 
        + height 
        + ", toolbar = no, status = no, location = no, "
        + " resizable = no, directories = no, scrollbars = yes, "
        + "left = " 
        + left 
        + ", top = " 
        + top 
        + ", screenX = "
        + left 
        + ", screenY = " 
        + top;
            
    myWindow = window.open(url, "majWindow", windowFeatures);           
}
    
// confirmation pop up
Utils.Confirm = function(message)
{
    if (confirm(message))
    {            
        return true;
    }
    else
    {
        event.returnValue = false;
        
        return false;
    }
}
    
// to stop users click submit buttons more then once
Utils.ClickOnce = function(btn, causesValidation, msg)
{
    // Test if we are doing a validation
    if (causesValidation && typeof(Page_ClientValidate) == 'function') 
    {
        // if we are doing a validation, return if it's false
        if (Page_ClientValidate() == false) 
        { 
            return false; 
        }
    }
    
    // Ensure that the button is not of type "submit"
    if (btn.getAttribute('type') == 'button')
    {
        // The msg attibute is absolutely optional
        // msg will be the text of the button while it's disabled
        if (!msg || (msg == 'undefined')) 
        { 
            msg = 'Processing ...'; 
        }
        
        btn.value = msg;

        // The magic :D
        btn.disabled = true;
    }
    
    return true;
}