function grayOut(vis, options) {
  // 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
  // offsetY:              // Offset Y from Actual Top Position
  // mpwidth               // Modal Popup Width
  // 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 || 998;
  var opacity = options.opacity || 85;
  var opaque = (opacity / 100);
  var bgcolor = options.bgcolor || 'Gray';
  var dark=document.getElementById('darkenScreenObject');
  
  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.overflow='hidden';                   // Try to avoid making scroll bars            
        tnode.style.display='none';                      // Start out Hidden
        tnode.style.top= '0px';             // In the top
        tnode.style.left='0px';                          // Left corner of the page
        tnode.id='darkenScreenObject';                   // Name it so we can find it later
    //tnode.className = "modalBackground";
    tbody.appendChild(tnode);                            // Add it to the web page
    dark=document.getElementById('darkenScreenObject');  // Get the object.
  }
  if (vis) {
    
    var pageWidth = GetWindowWidth();
    var pageHeight = GetWindowHeight();
    
    
    //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.backgroundColor=bgcolor;  
    dark.style.display='block';            
    dark.style.width= pageWidth;
    dark.style.height= pageHeight;
    dark.style.zIndex=zindex;
                  
  } else {
     dark.style.display='none';
  }
}

function Load(bLoad, oImgLoading, options){
  // 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
  // offsetY:              // Offset Y from Actual Top Position
  // mpwidth               // Modal Popup Width
	
	var divLoader=document.getElementById('divLoader');
	
	var v_offsetY = options.offsetY || 50;
	var v_ScrollPositionY = GetScrollPositionY() + v_offsetY;
	
	if (!divLoader) {
		var options = options || {}; 
		var posVertical = options.posVertical || v_ScrollPositionY;		
		var posHorizontal = options.posHorizontal || 10;

		var tbody = document.getElementsByTagName("body")[0];
		var tnode = document.createElement('div');           // Create the layer.
        tnode.style.position='absolute';                 // Position absolutely
        tnode.style.top= posVertical + "px";                           // In the top
        tnode.style.left= posHorizontal + "px";                          // Left corner of the page
        tnode.style.overflow='hidden';                   // Try to avoid making scroll bars            
        tnode.style.display='none';                      // Start out Hidden
		tnode.style.zIndex=999;   
		tnode.innerHTML='<img src=' + oImgLoading + '>';                      // Start out Hidden	
		tnode.id='divLoader';                   // Name it so we can find it later
		tbody.appendChild(tnode);                            // Add it to the web page
		divLoader=document.getElementById('divLoader');  // Get the object.
	} else {
	    var posVertical = options.posVertical || v_ScrollPositionY;		
		var posHorizontal = options.posHorizontal || 10;
		
	    divLoader.style.top= posVertical + "px";
	    divLoader.style.left= posHorizontal + "px";
	}

    if (bLoad)
	{
		divLoader.style.display ="block";
	}else{
	    
		divLoader.style.display ="none";		
	}
	
	grayOut(bLoad, options);
	
}

function LoadModalPopup(p_bLoad, p_popup, p_options){
  // 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
  // offsetY:              // Offset Y from Actual Top Position
  // mpwidth               // Modal Popup Width
  
	var divPopup=document.getElementById('divPopup');
	
	var v_offsetY = p_options.offsetY || 50;
	var v_ScrollPositionY = parseInt(GetScrollPositionY()) + parseInt(v_offsetY);
	
	if (!divPopup) {
		var p_options = p_options || {}; 
		var posVertical = p_options.posVertical || v_ScrollPositionY;		
		var posHorizontal = p_options.posHorizontal || 10;
		var mpWidth = p_options.mpwidth;
		
		var v_popup = document.getElementById(p_popup);
		
		//var tbody = document.getElementsByTagName("body")[0];
		var tbody = document.getElementById("mainContent");
		var tnode = document.createElement('div');           // Create the layer.
        tnode.style.position='absolute';                 // Position absolutely
        tnode.style.top= posVertical + "px";                           // In the top
        //tnode.style.left= posHorizontal + "px";                          // Left corner of the page
        tnode.style.overflow='hidden';                   // Try to avoid making scroll bars            
        tnode.style.display='none';                      // Start out Hidden
		tnode.style.zIndex=999;   
		tnode.style.left='50%';
		tnode.style.width=mpWidth + "px";
		tnode.style.marginLeft="-" + Math.ceil(mpWidth / 2) + "px";
		v_popup.style.display = 'block';
		tnode.appendChild(v_popup);            // Start out Hidden	
		tnode.id='divPopup';                   // Name it so we can find it later
		tbody.appendChild(tnode);                            // Add it to the web page
		divLoader=document.getElementById('divPopup');  // Get the object.
	} /*else {
	    var posVertical = p_options.posVertical || v_ScrollPositionY;		
		//var posHorizontal = p_options.posHorizontal || 10;
		var mpWidth = p_options.mpwidth;
		
	    divLoader.style.top= posVertical + "px";
	    divLoader.style.left= posHorizontal + "px";
	    divLoader.style.width=mpWidth + "px";
	}*/
	
	if (p_bLoad)
	{
		divLoader.style.display ="block"
	}else{
	    
		divLoader.style.display ="none"		
	}
	grayOut(p_bLoad, p_options);
	
}

/***********************************************************************************
* Descripción: Obtener el alto de la pantalla del usuario
***********************************************************************************/

function GetWindowHeight()
{
    var v_height = 0;
    var v_browser = navigator.appName
    if (v_browser == "Microsoft Internet Explorer")    
        v_height = document.body.scrollHeight;   
    else    
        v_height = window.innerHeight + window.scrollMaxY;
        
    return v_height + "px";
}

/***********************************************************************************
* Descripción: Obtener el ancho de la pantalla del usuario
***********************************************************************************/

function GetWindowWidth()
{
    if ( document.body && document.body.scrollWidth ) {
        var pageWidth = document.body.scrollWidth+'px';
    } else if( document.body.offsetWidth ) {
      var pageWidth = document.body.offsetWidth+'px';
    } else {
       var pageWidth='100%';
    }   
    
    return pageWidth;
}

function GetScrollPositionY()
{
    var v_scrollTop = document.body.scrollTop;
    
    if (v_scrollTop == 0)
    {
        if (window.pageYOffset)
            v_scrollTop = window.pageYOffset;
        else
            v_scrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
    }
    
    return v_scrollTop;
        
}
