﻿/* The purpose of this functio is to avoid getting focus on the GridView on Tab or Shift-tab
   tried to set tabindex = -1 on the GridView but that didn't work */
function CheckClearFields(e)
{               
    var srcElem = null;   
           
    // if e = false then must be IE 
	if (!e) var e = window.event;
	
	// Need to validate for IE or FF 			
	var srcElem = window.event ? e.srcElement.id : e.target.id;
						
	// Tested in IE and FF only
	if (e != null && srcElem != null)
	{			    	           
	    if (srcElem == 'lname' || srcElem == 'fname')
	    {
            if ((e.keyCode > 64 && e.keyCode < 91) || (e.which > 64 && e.which < 91))
            {                            
                var clearControl = $get('TextBox1').value;
                if (clearControl != "")
                {
                    $get('TextBox1').value = "";
                }            
            }	    
	    }
	    else 
	    if (srcElem == 'TextBox1')
	    {
	        //alert(srcElem + " " + e.keyCode);		
	        
	        if ($get('TextBox1').value != "" && $get('lname').value != "")
	        {
	            $get('lname').value = "";
	        }	        
	        
	        if ($get('TextBox1').value != "" && $get('fname').value != "")
	        {
	            $get('fname').value = "";
	        }	                
	        
	    }
    }
}   
   
function tabValidate(e)
{               
    var srcElem = null;   
           
    // if e = false then must be IE 
	if (!e) var e = window.event;
	
	// Need to validate for IE or FF 			
	var srcElem = window.event ? e.srcElement.id : e.target.id;
				
	// Tested in IE and FF only
	if (e != null && srcElem != null)
	{			    	           	 	
	    // If the key pressed is the tab-key
	    if (e.keyCode == 9 || e.which == 9)
	    {	    	    
	        // If the tab-key was pressed, we select the caseID textbox to avoid getting into the browser
            if (srcElem == 'btnClear' && !e.shiftKey)     
            {                              
               $get('TextBox1').focus();	          
               return false;                       
            } 
	    }			
	    else 
	    {                      
            var ua   = window.navigator.userAgent;
            var msie = ua.indexOf ( "MSIE " );
                                  
            // If the browser isn't IE we need to set focus on the button's after the ENTER key
            if (msie < 0 && (e.keyCode == 13 || e.which == 13))
	        {  // SHOULD ONLY BE FOR FIREFOX!!!
	           if (srcElem == 'lname' || srcElem == 'fname')
	           {	            
	              $get('btnFind').focus();	          
	           }   
    	       
	        }
	    }
    }
    return true;    
}

function initproc()
{
    FreezeGridViewHeader('gridNames','WrapperDiv');

    // set the lastname's textbox background to light blue
    var txtbox = $get("lname");
    if (txtbox != null)
    {           
       txtbox.click();       
    }
}

function FreezeGridViewHeader(gridID,wrapperDivCssClass) 
{    
    /// <summary>
    ///   Used to create a fixed GridView header and allow scrolling
    /// </summary>
    /// <param name="gridID" type="String">
    ///   Client-side ID of the GridView control
    /// </param>
    /// <param name="wrapperDivCssClass" type="String">
    ///   CSS class to be applied to the GridView's wrapper div element.  
    ///   Class MUST specify the CSS height and width properties.  
    ///   Example: width:800px;height:400px;border:1px solid black;
    /// </param>
    var grid = document.getElementById(gridID);
    if (grid != undefined)
    {
        grid.style.visibility = 'hidden';
        var div = null;
        if (grid.parentNode != undefined) 
        {                    
            //Find wrapper div output by GridView
            div = grid.parentNode;
            if (div.tagName == "DIV")
            {
                // We need to assign an ID to the div, for some reason I was not able to
                // do this in the .aspx                     
                div.id = 'divWrap'
                div.className = wrapperDivCssClass;                  
                div.style.overflow = "auto";                   
            }
        }                
        //Find DOM TBODY element and remove first TR tag from 
        //it and add to a THEAD element instead so CSS styles
        //can be applied properly in both IE and FireFox
        var tags = grid.getElementsByTagName('TBODY');
        if (tags != undefined)
        {
            var tbody = tags[0];
            var trs = tbody.getElementsByTagName('TR');
            var headerHeight = 8;
            if (trs != undefined) 
            {
                headerHeight += trs[0].offsetHeight;
                var headTR = tbody.removeChild(trs[0]);
                var head = document.createElement('THEAD');
                head.appendChild(headTR);
                
                headTR.id = 'mytest';
                
                grid.insertBefore(head, grid.firstChild);
            }
            //Needed for Firefox
            //tbody.style.height = (div.offsetHeight -  headerHeight) + 'px';
            tbody.style.overflowX = 'hidden';
            tbody.overflow = 'auto';
            tbody.overflowX = 'hidden';
        }
        grid.style.visibility = 'visible';        
    }   
}

function hideDiv(divId)
{	
    var div = document.getElementById(divId);
    if (div != null)
    {        
        div.style.display = 'none';               
    }    		
}

function showDiv(divId) 
{
    var div = document.getElementById(divId);
    if (div != null)
    {        
        repositionDiv(divId);   
        div.style.display = 'block';               
    }    
}

function repositionDiv(divId) 
{
    var div = document.getElementById(divId);

    var ua = window.navigator.userAgent;
    var msie = ua.indexOf ( "MSIE " );

    // If the browser isn't IE we need to reposition the div
    if ( msie < 0 )      
    {     
      div.className = "divProgressFF";      
    } 
}

function ClearNameFields()
{
    var textbox = $get('fname');
    if (textbox != null)
        textbox.value = '';
    
    textbox = $get('lname');
    if (textbox != null)
    {
        textbox.value = '';        
        textbox.focus();                        
    }
               
    return true;
}

function setHourglass(type)
{    
    document.body.style.cursor = type;
}

function openPopUp(strOpen)
{        
    var win_width = 828;
    var win_height = 460;
    var win_name = 'CaseDetail';

    myString = new String(strOpen)
    if (myString.indexOf('DispoList.aspx') >= 0)   
    {
        win_width = 578;
        win_height = 505;    
        win_name = 'DispoList';
    }

    var centerWidth = (window.screen.width - win_width) / 2;
    var centerHeight = (window.screen.height - win_height) / 2;

    winref = window.open(strOpen, win_name, "dialog=yes,minimizable=yes,status=no,resizable=no,width=" + win_width + ", height=" + win_height + ", left=" + centerWidth + ", top=" + centerHeight);    
    winref.focus();      
}

function openDispoList(strOpen)
{        
    var win_width = 578;
    var win_height = 505;
   
    var centerWidth = (window.screen.width - win_width) / 2;
    var centerHeight = (window.screen.height - win_height) / 2;

    test = window.open(strOpen, "Info2", "dialog=yes,minimizable=yes,status=0,resizable=0,width=" + win_width + ", height=" + win_height + ", left=" + centerWidth + ", top=" + centerHeight);
    test.focus();          
}


function resetRowStyle(rowIdx)
{      
    myString = new String(rowIdx / 2);
    if (myString.indexOf('.') >= 0)   
    {
        return 'altrow';        
    }
    else    
    {        
        return 'separators';        
    }                                        
}

/*****************************************************************************/

if(typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded(); 

