﻿
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// 
//                      General Code                                            //
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// 
function msieversion()
{
    var ua = window.navigator.userAgent;
    var msie = ua.indexOf("MSIE ");  // note end-space

    if ( msie > 0 )      // If Internet Explorer, return version number
        return parseInt (ua.substring (msie+5, ua.indexOf (".", msie )));
    else                 // If another browser, return 0
        return 0;
}

function hideitem(itemname)
{
   document.getElementById(itemname).className="hideme";
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// 
//                      Code for Scrolling                                      //
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// 
var myscrolltop;
// Script to capture and restore scroll position in DIV entity & therefore in the GRID.
// The PageRequestManager work is needed for update panel/partial rendering work.

// Register Begin Request and End Request. 
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_beginRequest(BeginRequestHandler);
prm.add_endRequest(EndRequestHandler);

// Capture the Div Scroll Position.
function BeginRequestHandler(sender, args) {
    var m = document.getElementById("gridholder");
    myscrollTop=m.scrollTop;
}

// Set the Div Scroll Position.
function EndRequestHandler(sender, args)
{
    var m = document.getElementById("gridholder");
    m.scrollTop = myscrollTop;
} 

// This portion is needed to maintain scroll pos for full page load instances.
window.onload = function(){   
    var strCook = document.cookie;   
    if(strCook.indexOf("!~")!=0){   
        var intS = strCook.indexOf("!~");   
        var intE = strCook.indexOf("~!");   
        var strPos = strCook.substring(intS+2,intE);   
        document.getElementById("gridholder").scrollTop = strPos;   
    }   
}   

function SetDivPosition(){   
    var intY = document.getElementById("gridholder").scrollTop;   
    document.cookie = "yPos=!~" + intY + "~!";   
}   

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// 
//                      Code for Printing Prep                                  //
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// 

function PrintMe()
{
    // Nullify scrolling in the grid to allow proper printing.
    // The printing stylesheet only allows specification for "overflow" property in vs2005.
    // Here, need to specify the specific -x and -y property values.
    
    var info = "overflow-x:visible; overflow-y:visible; width: 98.2%;";
    var gridobj = document.getElementById("gridholder");
    
    if (msieversion() == 7) 
    { 
        // Syntax variation: set attribute via style property.
        gridobj.style.setAttribute("cssText", info);
    }
    else
    {
        gridobj.setAttribute("style", info);
    }      
   
    // Toggle the choice-links.
    document.getElementById("clickprint").className = "noprint visible_no";
    document.getElementById("clickview").className = "noprint visible_yes";

    // Give user some info.
    document.getElementById("divpopup").className="showme";
    document.getElementById("printtask").className="showme";
    document.getElementById("viewtask").className="hideme";
}

function ViewMe()
{
    // Modify scrolling in the grid for viewing (default). See comments in PrintMe.
    var info = "overflow-x:hidden; overflow-y:scroll; width:100%;";
    var gridobj = document.getElementById("gridholder");
    if (msieversion() == 7)
    {
        gridobj.style.setAttribute("cssText", info);
    }
    else
    {
        gridobj.setAttribute("style", info); 
    }
    
    // Toggle the choice-links.    
    document.getElementById("clickprint").className = "noprint visible_yes";
    document.getElementById("clickview").className = "noprint visible_no";    
    
    // Give user some info.
    document.getElementById("divpopup").className="showme";
    document.getElementById("printtask").className="hideme";
    document.getElementById("viewtask").className="showme";
}

function hidepopup()
{
    document.getElementById("divpopup").className="hideme";
    document.getElementById("printtask").className="hideme";
    document.getElementById("viewtask").className="hideme";
}

