﻿// JScript File

//-------------------------------------------------------------------------------------------------
//--- show and hide div functions
function ShowHideDiv(divID)
{
    
    var oDiv = document.getElementById(divID);
    if(oDiv)
    {
        if ( oDiv.style.display == '' ) 
        {
            HideDiv(divID);            
        }
        else 
        {
            ShowDiv(divID)                   
        }        
    }     
}

function HideDiv(divID)
{
    var oDiv = document.getElementById(divID);
    if(oDiv)
    {
        oDiv.style.display = 'none';           
    }     
}

function ShowDiv(divID)
{
    var oDiv = document.getElementById(divID);
    if(oDiv)
    {
        oDiv.style.display = '';           
    }     
}
//--- end show and hide div functions
//-------------------------------------------------------------------------------------------------


//-------------------------------------------------------------------------------------------------
//--- Text and Image swapping functions
//--- used on the inventory image selection control
function imageSwap(id, img)
{
    var control = document.getElementById(id);        
    if(control)control.src = img;   
}

function textSwap(id, text)
{
    var control = document.getElementById(id);
    if(control) control.innerHTML = text;
}

function styleSwap(id, className)
{
    var control = document.getElementById(id);
    if(control) control.className = className;
}

function classSwap(id, className)
{
    var control = document.getElementById(id);
    if(control) control.className = className;
}
//--- end text and image swapping function
//-------------------------------------------------------------------------------------------------


function DisableControl(oControl)
{
    oControl.enabled = false;
}

function WindowHeight()
{
    if(document.documentElement && document.documentElement.clientHeight) return document.documentElement.clientHeight;
    if(document.body.clientHeight != null) return document.body.clientHeight;
    if(window.innerHeight != null) return window.innerHeight;
    
    return null;
}


function WindowWidth()
{
    if(document.documentElement && document.documentElement.clientWidth) return document.documentElement.clientWidth;
    if(window.innerWidth != null) return window.innerWidth;
    if(document.body.clientWidth != null) return document.body.clientWidth;
    return null;
}

/****************************************************************************************************
* Activate/Deactivate with a function call to grayOut(vis, options). “vis” is a true/false variable. 
* If you pass true, the screen will be grayed out. If you pass false, the gray-out will be removed. 
* “options” is an optional JSON object this allows you to send only the properties you want modified. 
* You don't have to pass options if you don't want. grayOut(true) and grayOut(false) will work quite 
* nicely. The three properties looked for in options are zindex, opacity, and bgcolor. 
*
* By default the gray-out creates a layer with a z-index of 50 and you will need to create or raise 
* elements's z-indexes to be higher than 50 to appear on top of the gray-out. If you need to, however, 
* you can set an option of {'zindex':'50'} where “50” is is changed to the z-index you wish to use. 
*****************************************************************************************************/

function grayOut(vis, options, content, loading) 
{  
    // Pass true to gray out screen, false to ungray  
    // options are optional.  This is a JSON object with the following (optional) properties  
    // opacity:0-100         
    // Lower number = less grayout higher = more of a blackout   
    // zindex: #             
    // HTML elements with a higher zindex appear on top of the gray out  
    // bgcolor: (#xxxxxx)    
    // Standard RGB Hex color code  
    // grayOut(true, {'zindex':'50', 'bgcolor':'#0000FF', 'opacity':'70'});  
    // Because options is JSON opacity/zindex/bgcolor are all optional and can appear  
    // in any order.  Pass only the properties you need to set.  
    var options = options || {};  
    var zindex = options.zindex || 50;  
    var opacity = options.opacity || 70;  
    var opaque = (opacity / 100);  
    var bgcolor = options.bgcolor || '#000000';  
    var dark=document.getElementById('darkenScreenObject');  
    // Calculate the page width and height     
    if( document.body && ( document.body.scrollWidth || document.body.scrollHeight ) ) 
    {        
        var pageWidth = document.body.scrollWidth+'px';        
        var pageHeight = document.body.scrollHeight+'px';    
    } 
    else if( document.body.offsetWidth ) 
    {      
        var pageWidth = document.body.offsetWidth+'px';      
        var pageHeight = document.body.offsetHeight+'px';    
    } 
    else 
    {       
        var pageWidth='100%';       
        var pageHeight='100%';    
    }   
        
    if (!dark) 
    {    
        // The dark layer doesn't exist, it's never been created.  So we'll    
        // create it here and apply some basic styles.    
        // If you are getting errors in IE see: http://support.microsoft.com/default.aspx/kb/927917    
        var tbody = document.getElementsByTagName("body")[0];    
        var tnode = document.createElement('div');           // Create the layer.        
            tnode.style.position='absolute';                 // Position absolutely        
            tnode.style.top='0px';                           // In the top        
            tnode.style.left='0px';                          // Left corner of the page        
            tnode.style.overflow='hidden';                   // Try to avoid making scroll bars                    
            tnode.style.display='none';                      // Start out Hidden        
            tnode.id='darkenScreenObject';                   // Name it so we can find it later    
            tbody.appendChild(tnode);                        // Add it to the web page    
            dark=document.getElementById('darkenScreenObject');  // Get the object.  
            
        if(content || content.length > 0)
        {
            var topOffset = Math.max(document.body.scrollTop,document.documentElement.scrollTop);
            var scrollTop = Math.max(document.body.scrollTop,document.documentElement.scrollTop);
    	    var scrollLeft = Math.max(document.body.scrollLeft,document.documentElement.scrollLeft);
    	    var scrollBottom = Math.max(document.body.scrollBottom,document.documentElement.scrollBottom);
    	    var winHeight = WindowHeight() + scrollTop;
    	    var winWidth = WindowWidth() + scrollLeft;
    	    var height = '200';
    	    var width = '300';
    	    var top = (winHeight - height) / 2  + 'px';
    	    var left = (winWidth / 2) - (width / 2) + 'px';
    	      
        
    	    var divContent = document.createElement('div');
    	    divContent.style.position='absolute';                 // Position absolutely        
            divContent.style.top='0px';                           // In the top        
            divContent.style.left='0px';                          // Left corner of the page        
            divContent.style.overflow='hidden';                   // Try to avoid making scroll bars                    
            divContent.style.display='none';                      // Start out Hidden   
            divContent.style.opacity="100%";                          
            divContent.style.MozOpacity="100%";;                       
            divContent.style.filter='alpha(opacity='+"100%";+')';     
            divContent.style.zIndex=zindex + 1;            
            divContent.style.backgroundColor="white";      
            divContent.style.width= width + "px";    
            divContent.style.height= height + "px";    
            divContent.style.display='block'; 
            divContent.style.top = top;
            divContent.style.left = left;
            
    	    var spacing = "<br>&nbsp;<br>&nbsp;<br>&nbsp;"; 
    	    var spacing1 = "<br>&nbsp;";
    	    content = spacing + "<center> " + content + "</center>";
    	    
    	    if(loading) content += spacing1 + "<center><img src='/images/global/progressimages/loading-bluebar-horizontal.gif' border='0'></center>";
    	    content += spacing;
    	
            divContent.innerHTML = "<table style='text-align:center;width:" + width + "px;'>"
               
                + "<tr><td>" + content 
                
                + "</td></tr></table>";
           
           tbody.appendChild(divContent);          
        }
        
        
            
    }  
    
    if (vis)
    {    
            
        //set the shader to cover the entire page and make it visible.    
        dark.style.opacity=opaque;                          
        dark.style.MozOpacity=opaque;                       
        dark.style.filter='alpha(opacity='+opacity+')';     
        dark.style.zIndex=zindex;            
        dark.style.backgroundColor=bgcolor;      
        dark.style.width= pageWidth;    
        dark.style.height= pageHeight;    
        dark.style.display='block';                            
    } 
    else 
    {     
        dark.style.display='none';  
    }
}
