﻿// JScript File
var needToConfirm = true
var arrWindow = new Array() //This will hold all opened pop-up windows.
var index = 0
var isIE;
var checkflag = false;

//This is called before the page unloads by closing (pressing ALT-F4, X button and closing the tab) and 
//refreshing (hitting F5 or the Refresh button in the browser toolbar). No confirmation dialog displayed.
onbeforeunload = function () {}

//This is called when the page unloads. This calls closeSession - the function responsible for closing
//the session and releasing the license.
onunload = closeSession

//This is called when the page loads.  This initializes all page elements of their javascript events.
onload = function () 
        {
            
            if ( parent.location.href.match("selectlibrary") || parent.location.href.match("selectgroup") )
                initSelectLibAndDocGroup()

            if ( parent.location.href.match("qforward"))
            {
                initForward()
            }
            if ( parent.location.href.match("queue2_copyto") )
            {
                initCopy()
            }
            if ( parent.location.href.match("edit") || parent.location.href.match("index") )
            {
                initEditAndIndex()
            }
        }
        
        
function showDocument(docId)
{
    if (docId != null )
    {
        arrWindow[index++] = window.open("docserver.asp?docid=" + docId, "_blank", "scrollbars=1,status=1,toolbar=0,menubar=0,location=0,fullscreen=0,resizable=1");
    }
    
}       
        
function msieversion()
{
  var ua = window.navigator.userAgent
  var msie = ua.indexOf ( "MSIE " )

  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

}

// recursive func to climb up the hierarchy summing the offsets until <BODY>
// note: all objects in the document must have unique names!
function hintlist_onclick(sTxtObj, sTxtObjName, sColumnName){
    var page;
	page="q";
	
	if ( parent.location.href.match("query") )
	    page = "q";
	else if ( parent.location.href.match("index") || parent.location.href.match("edit") )
	    page = "i";
	    
    if ( msieversion() > 0 )
    {
        var x, y, oTxt, result;
		var oChild, oParent, nOffsetLeft, nOffsetTop;

		oTxt = sTxtObj; 
		if(!oTxt) return;
		oChild = oTxt;
		x = 0; y = 0;
		//climb up the html hierarchy and sum up the offsets for all the parents
		while (oChild){
			x += oChild.offsetLeft;
			y += oChild.offsetTop;
			oChild = oChild.parentElement; //ie4+ (offsetParent in ie5+ behaves differently)
		}

		if(window.screenLeft){ //ie5+
			x += window.screenLeft;
			y += window.screenTop;
		}

		var args, url;
		
		url = "hintlist.asp?r="+page+"&cn=" + sColumnName;
		args = "center:1;dialogWidth:200px;dialogHeight:300px;scroll:1;help:0;status:0;left=" + x + ",top=" + y;
        
		result = window.showModalDialog(url, null,args);
		
		if (result)
			oTxt.value = result;   
			
	    //Checks if there is any parent-child dependency hintlist fields
        if ( document.getElementById("hid"+sTxtObjName) != null )
        {
            //If yes then refresh value of child/hierarchical hintlist
            var childField = document.getElementById("hid"+sTxtObjName).value;
            document.getElementById(childField).value = "";
        }      
    
    }
    else
    {
        var wnd, args, x, y, oTxt;

        // we can position the hintlist window if these properties are available
        if(window.screenLeft && window.screenLeft && document.body.clientWidth){
	        x = (window.screenLeft + document.body.clientWidth) - 200;
	        y = window.screenTop;
        } else {
	        x = 200; 
	        y = 200;
        }

        args = "scrollbars=1,status=1,toolbar=0,menubar=0,location=0,fullscreen=0,resizable=1,width=200,height=300";
        args = args + ",left=" + x + ",top=" + y;
        wnd = window.open("hintlist.asp?r="+page+"&tx="+sTxtObjName+"&cn="+sColumnName+"&frm=frmQuery", null, args);
        if (wnd!=null){
	        wnd.opener = self;
	        wnd.focus();
        }
        
        //Hintlist pop-up window added to arrWindow array
	    //to be closed when closeSession() is called
        arrWindow[index++] = wnd;    
    }

}
	
function hintlist_onclick_type3(strTxtObjName, strColumnName, strDepCtlName, strTxtObj, strDeptCtl)
{
    var page;
	page="q";
	
	if ( parent.location.href.match("query") )
	    page = "q";
	else if ( parent.location.href.match("index") || parent.location.href.match("edit") )
	    page = "i";
	    
    if ( msieversion() > 0 )
    {
		var x, y, oTxt, oDep, result;
		var oChild, oParent, nOffsetLeft, nOffsetTop, strDepValue;

		oTxt = strTxtObj; if(!oTxt) return;
		oDep = strDeptCtl; if(!oDep) return;
	
		strDepValue = escape(oDep.value);

		oChild = oTxt;
		x = 0; y = 0;

		//climb up the html hierarchy and sum up the offsets for all the parents
		while (oChild){
			x += oChild.offsetLeft;
			y += oChild.offsetTop;
			oChild = oChild.parentElement; //ie4+ (offsetParent in ie5+ behaves differently)
		}

		if(window.screenLeft){ //ie5+
			x += window.screenLeft;
			y += window.screenTop;
		}

        var url
		url = "hintlist.asp?r="+page+"&cn=" + strColumnName + "&search=" + strDepValue;
		var args
		args = "center:1;dialogWidth:200px;dialogHeight:300px;scroll:1;help:0;status:0;resize:1;left=" + x + ",top=" + y;
		result = window.showModalDialog(url, null, args);
		if (result)
			oTxt.value = result;  
			
		//Checks if there is any parent-child dependency hintlist fields
        if ( document.getElementById("hid"+strColumnName) != null )
        {
            //If yes then refresh value of child/hierarchical hintlist
            var childField = document.getElementById("hid"+strColumnName).value;
            document.getElementById(childField).value = "";
        }  
    }
    else
    {
        var wnd, args, x, y, strDepCtlContents;

        strDepCtlContents = escape(strDeptCtl.value);

        // we can position the hintlist window if these properties are available
        if(window.screenLeft && window.screenLeft && document.body.clientWidth){
            x = (window.screenLeft + document.body.clientWidth) - 200;
            y = window.screenTop;
        } else {
            x = 200; 
            y = 200;
        }

        args = "scrollbars=1,status=1,toolbar=0,menubar=0,location=0,fullscreen=0,resizable=1,width=200,height=300";
        args = args + ",left=" + x + ",top=" + y;
        wnd = window.open("hintlist.asp?r="+page+"&tx=" + strTxtObjName + "&cn=" + strColumnName + "&frm=frmQuery&search=" + strDepCtlContents, null, args);
        if (wnd!=null){
            wnd.opener = self;
            wnd.focus();
        }

        //Calendar pop-up window added to arrWindow array
	    //to be closed when closeSession() is called
        arrWindow[index++] = wnd;    
    }
}

function calendar_onclick(sTxtName, calObj){
    
    var aWidth, aHeight;
    
    if ( msieversion() > 0 )
    {
        var x, y, oTxt, oChild, result, aWidth, aHeight;

	    aWidth = 162; 
	    aHeight = 230;
	    
		x = 0; y = 0;
		
        oTxt = calObj; if(!oTxt) return;
		oChild = oTxt;

		//climb up the html hierarchy and sum up the offsets for all the parents
		while (oChild){
			x += oChild.offsetLeft;
			y += oChild.offsetTop;
			oChild = oChild.parentElement; //ie4+ (offsetParent in ie5+ behaves differently)
		}

		if(window.screenLeft){ //ie5+
			x += window.screenLeft;
			y += window.screenTop;
		}
		
		x = (screen.width) ? (screen.width-aWidth)/2 : 50;
		y = (screen.height) ? (screen.height-aHeight)/2 : 50;
		settings = 'dialogWidth:'+aWidth+'px;dialogHeight:'+aHeight+'px';
		settings += ';top=' + y + '; left=' + x;
		settings += ';center:1;scroll:0;help:0;status:0;resizable:1;status:1'
		result = window.showModalDialog("dtgcal.asp?n="+sTxtName+"&frm=frmQuery", null, settings);
		
        if (result)
			oTxt.value = result;
	} 
	else
	{
	    aWidth = 155; 
	    aHeight = 185;
	    
	    x = (screen.width) ? (screen.width-aWidth)/2 : 50;
	    y = (screen.height) ? (screen.height-aHeight)/2 : 50;
	    settings = 'height='+ aHeight + ',width=' + aWidth;
	    settings += ',top=' + y + ', left=' + x;
	    settings += ',heading=no,topbar=no,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,border=no'
    	
	    //Calendar pop-up window added to arrWindow array
	    //to be closed when closeSession() is called
	    arrWindow[index++] = window.open("dtgcal.asp?n="+sTxtName+"&frm=frmQuery","calendar",settings);
	}
	

}

// Netscape does not support modal dialog boxes
function SelectEntry (s,formname,textobjectname)
{
    var regEx = new RegExp("&dq&", 'gi');
    
    if (document.all)    
	{
        window.returnValue = s.replace(regEx, '"');
	}
	else
	{
	    var parentDoc;
        
        if ( window.opener.document.getElementById("query") != null )
        {
            if ( window.opener.document.getElementById("query").contentDocument )
                parentDoc = window.opener.document.getElementById("query").contentDocument;
            else
                parentDoc = window.opener.document.frames["query"].document;
        }
        else
        {
            parentDoc = window.opener.document;
        }
            
        var oTxtObj;
        
        oTxtObj = parentDoc.getElementById(textobjectname);  

        if (oTxtObj){
            oTxtObj.value = s.replace(regEx, '"')
        }
        
        //Checks if there is any parent-child dependency hintlist fields
        if ( parentDoc.getElementById("hid"+textobjectname) != null )
        {
            //If yes then refresh value of child/hierarchical hintlist
            var childField = parentDoc.getElementById("hid"+textobjectname).value;
            parentDoc.getElementById(childField).value = "";
        }
	}
    
    window.close();
}

function initHintlist()
{
    needToConfirm = false;
    var formname = document.getElementById("hidFormName").value;
    var textobjectname = document.getElementById("hidTextObjName").value;
    
    if ( document.getElementsByName('linkEntry') != null )
    {
        var links = document.getElementsByName('linkEntry');
        for (var i=0;i<links.length;i++)
        {
            links[i].href = "#";
            links[i].onclick = function() 
                                { 
                                    var s = this.id;
                                    
                                    SelectEntry(s,formname,textobjectname);
                                }
        }
    }
}

function initEmailHandler(groupName, groupId)
{
    if ( document.getElementById('btnBack') != null )
    {
        if ( parent.location.href.match("emailfromqueuehandler") )
            document.getElementById('btnBack').onclick = function () { redirectTo("queue2main.asp?groupname="+groupName+"&grpid="+groupId); }
        else if ( parent.location.href.match("emailfromhitlisthandler") || parent.location.href.match("releasemailfromhitlisthandler") )
            document.getElementById('btnBack').onclick = function () { redirectTo("query2main.asp?groupname="+groupName+"&grpid="+groupId); }
    }   
}

function initCheckOutCheckIn()
{
    if ( document.getElementById('frmCheckout') != null )
    {
        document.getElementById('frmCheckout').action = "checkouthandler.asp";
        document.getElementById('frmCheckout').method = "get";
    
        document.getElementById("btnYes").onclick= function() 
                                                        { 
                                                            needToConfirm=false;
                                                            document.getElementById('frmCheckout').submit();
                                                        }
        document.getElementById("btnNo").onclick= function() { 
                                                                needToConfirm=false;
                                                                window.history.back() 
                                                             }                                     
                                                        
    }
    
    if ( document.getElementById('frmCheckin') != null )
    {
        document.getElementById('frmCheckin').action = "checkin_upload.asp?file=" + document.getElementById('reservedFile').value;
        document.getElementById('frmCheckin').method = "post";
    
        document.getElementById("btnYes").onclick= function() 
                                                        { 
                                                            needToConfirm=false;
                                                            document.getElementById('frmCheckin').submit();
                                                        }
        document.getElementById("btnNo").onclick= function() { redirectTo("reserveditemsmain.asp"); }                                     
    }
    
    if ( document.getElementById('linkDownload') != null )
    {
        document.getElementById("linkDownload").href="#"
        document.getElementById("linkDownload").onclick= function()
                                                         {
                                                            redirectTo("downloadmanager.asp?docid=" + this.name);
                                                            needToConfirm=true;
                                                         }
    }
    
    if ( document.getElementById('btnBack') != null )
    {

   		//Issue 3684: Added a Back button so user would be able to go back
   		//to the reserved items page.
        document.getElementById('btnBack').onclick = function () { redirectTo("reserveditemsmain.asp"); }
    }
    
    if (  document.getElementById('frmUpload') != null )
    {
       
        document.getElementById('frmUpload').action = "bin\\uploadext.dll";
        document.getElementById('frmUpload').target = "_parent";

        document.getElementById("btnUpload").onclick = function () 
                                                    { 
                                                        
                                                        var s, ndx, fn;
                                                        s = document.getElementById('Filedata').value;
                                            	        
                                                        if (s.length==0) 
                                                        {
                                                            alert("Must specify a file for uploading.");
                                                            
                                                            return false;
                                                        } 
                                                        else 
                                                        {
                                                            ndx = s.lastIndexOf("\\");
                                                            if (ndx > -1)
                                                                filename = s.substr(ndx + 1);
                                                            else 
                                                                filename = s;
                                                            
                                                            origname = document.getElementById('origName').value;
                                                                
                                                            if (filename != origname)
                                                            {
                                                                alert("File is invalid. This should be the same as the file checked out from ManagePoint.");
                                                                return false;
                                                            }
                                                            
                                                            document.getElementById('Filename').value = filename;
                                                            
                                                            needToConfirm=false;
                                                            
                                                            return true;
                                                        }
                                                    }
    }


	     
}


function initEditAndIndex()
{
    if ( document.getElementById("linkEditHelp") != null )
    {                                                        
        document.getElementById("linkEditHelp").href="#" 
        document.getElementById("linkEditHelp").onclick= function() 
                                                        { 
                                                            var args = "scrollbars=1,status=1,toolbar=0,menubar=0,location=0,fullscreen=0,resizable=1,width=400,height=300";
		                                                    window.open("help/edit_help.htm", null, args); 
                                                        }
    }
    
    if ( document.getElementById("linkIndexHelp") != null )
    {                                                        
        document.getElementById("linkIndexHelp").href="#" 
        document.getElementById("linkIndexHelp").onclick= function() 
                                                        { 
                                                            var args = "scrollbars=1,status=1,toolbar=0,menubar=0,location=0,fullscreen=0,resizable=1,width=400,height=300";
		                                                    window.open("help/index_help.htm", null, args); 
                                                        }
    }
    
    if ( document.getElementsByName('linkHitlist') != null )
    { 
        
        var links = document.getElementsByName('linkHitlist');
        for (var i=0;i<links.length;i++)
        {
            links[i].href = "#"
            links[i].onclick = function() 
                                { 
                                    var length = this.id.split(",").length;
                                    
                                    if ( length == 2 ) 
                                    {
                                        var strTxtObjName = this.id.split(",")[0];
                                        var strTxtObj = document.getElementById(strTxtObjName);
                                        var strColumnName = this.id.split(",")[1];
                                        
                                        
                                        if (  strTxtObj != null )
                                            hintlist_onclick(strTxtObj, strTxtObjName, strColumnName);
                                        
                                    }
                                    else if ( length == 3 )
                                    {
                                        
                                        var strTxtObjName = this.id.split(",")[0];
                                        var strColumnName = this.id.split(",")[1];
                                        var strDeptCtlName = this.id.split(",")[2];
                                        var strTxtObj = document.getElementById(strTxtObjName);
                                        var strDeptCtl = document.getElementById(strDeptCtlName);
                                        
                                        if ( strTxtObj != null &&  strDeptCtl != null )
                                            hintlist_onclick_type3(strTxtObjName,strColumnName, strDeptCtlName, strTxtObj, strDeptCtl);
                                    }
                                    
                                    
                                }
        }
    
        if ( document.getElementsByName('linkCalendar') != null )
        { 
            var links = document.getElementsByName('linkCalendar');
            for (var i=0;i<links.length;i++)
            {
                links[i].href = "#"
                links[i].onclick = function() 
                                    { 
                                        var fieldName = this.id;
                                        calendar_onclick(fieldName, document.getElementById(fieldName));
                                    }
            }
        }
    }
}

function initForward()
{
    if ( document.getElementById("linkNoUsers") != null )
    {
        document.getElementById("linkNoUsers").href="#";
        document.getElementById("linkNoUsers").onclick = function () { redirectTo("queue2main.asp") };
    }
    
    if ( document.getElementById("spanViewFile") != null )
    {
        document.getElementById("spanViewFile").onclick = function()
                                                            {
                                                                
                                                                arrWindow[index++] = window.open("docserver.asp?qfilename=" + this.name, "_blank", 
                                                                        "scrollbars=1,status=1,toolbar=0,menubar=0,location=0,fullscreen=0,resizable=1");
                                                                
                                                            }
    }
    
    if (document.getElementsByName("linkForward") != null )
    {
        var links = document.getElementsByName("linkForward");
        var userId, fileName, original;
        
        for (var i=0; i < links.length; i++ )
        { 
            links[i].href = "#"
            links[i].onclick = function ()
                                  {
                                    userId = this.id.split("_")[0]
                                    fileName = this.id.split("_")[1]
                                    original = this.id.split("_")[2]
                                    
                                    redirectTo ("qforwardhandler.asp?to=" + userId + 
                                                    "&qfilename=" + fileName + 
                                                    "&original=" + original)
                                  } 
        }
    }
}

function initCopy()
{
    if ( document.getElementById("linkNoUsers") != null )
    {
        document.getElementById("linkNoUsers").href="#";
        document.getElementById("linkNoUsers").onclick = function () { redirectTo("queue2main.asp") };
    }

    if ( document.getElementById('frmCopyTo') != null )
        {
            
            document.getElementById('frmCopyTo').action = "queue2_copytohandler.asp?" + document.getElementById('frmCopyTo').name;
            document.getElementById('frmCopyTo').target = "_parent";
        }
        
        document.getElementById("btnCopy").onclick = function () 
                                                            { 
                                                                needToConfirm = false;
                                                            }
}

function initQueueUpload()
{
    var queueUploadDoc;
    
    if ( parent.document.getElementById("queue2upload").contentDocument )
        queueUploadDoc = parent.document.getElementById("queue2upload").contentDocument;
    else
        queueUploadDoc = parent.document.frames["queue2upload"].document;
        
     if ( queueUploadDoc )
     {
        if ( queueUploadDoc.getElementById('frmUpload') != null )
        {
            queueUploadDoc.getElementById('frmUpload').action = "bin\\uploadext.dll";
            queueUploadDoc.getElementById('frmUpload').target = "_parent";
        }
        
        queueUploadDoc.getElementById("btnUpload").onclick = function () 
                                                            { 
                                                                var s, ndx, fn;
                                                                s = queueUploadDoc.getElementById('Filedata').value;
                                                    	        
                                                                if (s.length==0) 
                                                                {
	                                                                alert("Must specify a file for uploading.");
	                                                                
	                                                                return false;
                                                                } 
                                                                else 
                                                                {
	                                                                ndx = s.lastIndexOf("\\");
	                                                                if (ndx > -1){
		                                                                fn = s.substr(ndx + 1);
		                                                                queueUploadDoc.getElementById('Filename').value = fn;
	                                                                } else {
		                                                                queueUploadDoc.getElementById('Filename').value = s;
	                                                                }
	                                                                
	                                                                needToConfirm = false;
	                                                                
	                                                                return true;
                                                                }
                                                            }
	     
     }
}

function initQueueContents()
{
       
    var queueContentsDoc;
    
    if ( parent.document.getElementById("queue2contents").contentDocument )
        queueContentsDoc = parent.document.getElementById("queue2contents").contentDocument;
    else
        queueContentsDoc = parent.document.frames["queue2contents"].document;
        
     if (queueContentsDoc)
     {
        if ( queueContentsDoc.getElementsByName('linkView') != null )
        {	
            links = queueContentsDoc.getElementsByName('linkView');
            for (var i=0;i<links.length;i++)
            {
                //This still needs fixing for Issue 3130
                links[i].href = "#"
                links[i].onclick = function ()
                                  {
                                        arrWindow[index++] = window.open ("docserver.asp?qfilename=" + this.id,"_blank",
                                                                "scrollbars=1,status=1,toolbar=0,menubar=0,location=0,fullscreen=0,resizable=1");
                                  }
                
                if ( queueContentsDoc.getElementsByName('linkIndex')[i] != null )
                {
                    queueContentsDoc.getElementsByName('linkIndex')[i].href = "#"
                    queueContentsDoc.getElementsByName('linkIndex')[i].onclick =  function () { redirectTo ("index.asp?qfilename="+ this.id) }
                }
                
                if ( queueContentsDoc.getElementsByName('linkForward')[i] != null )
                {
                    queueContentsDoc.getElementsByName('linkForward')[i].href = "#"
                    queueContentsDoc.getElementsByName('linkForward')[i].onclick = function () { redirectTo ("qforward.asp?qfilename=" + this.id) }
                }
                
                if ( queueContentsDoc.getElementsByName('linkCopy')[i] != null )
                {
                    queueContentsDoc.getElementsByName('linkCopy')[i].href = "#"
                    queueContentsDoc.getElementsByName('linkCopy')[i].onclick = function () { redirectTo ("queue2_copyto.asp?qfilename=" + this.id) }
                }
                
                if ( queueContentsDoc.getElementsByName('linkEmailQueue')[i] != null )
                {
                    queueContentsDoc.getElementsByName('linkEmailQueue')[i].href = "#"
                    queueContentsDoc.getElementsByName('linkEmailQueue')[i].onclick = function () 
                                                                                        {
                                                                                            parent.location.href = "emailfromqueue.asp?qfilename=" + this.id + "&original=1", null, 
		                                                                                        "scrollbars=1,status=1,toolbar=0,menubar=0,location=0,fullscreen=0,resizable=1,width=500,height=300";
                                                                                        }
                }
                
                if ( queueContentsDoc.getElementsByName('linkDeleteQueue')[i] != null )
                {
                    queueContentsDoc.getElementsByName('linkDeleteQueue')[i].href = "#"
                    queueContentsDoc.getElementsByName('linkDeleteQueue')[i].onclick = function () 
                                                                                        { 
                                                                                            if (confirm("Are you sure you want to delete '" + this.id.split("&")[0] + "'?"))
                                                                                            {
                                                                                                redirectTo ("qdeletehandler.asp?qfilename=" + this.id)
		                                                                                    }
                                                                                        }
                }

                if ( queueContentsDoc.getElementsByName('linkViewFile')[i] != null )
                {                                                                                                    
                    //Right-click and select 'Save target as'
                    queueContentsDoc.getElementsByName('linkViewFile')[i].href = "downloadmanager.asp?qfilename=" + queueContentsDoc.getElementsByName('linkViewFile')[i].id;
                }                                                                 
            }
        }
    }
}

function initQuery()
{
    
    var queryDoc;
    
    if ( parent.document.getElementById("query").contentDocument )
        queryDoc = parent.document.getElementById("query").contentDocument;
    else
        queryDoc = parent.document.frames["query"].document;
       
    if ( queryDoc.getElementById('cmbbxLibraries') != null ) queryDoc.getElementById('cmbbxLibraries').onchange = function() { redirectTo(this.value) }
    if ( queryDoc.getElementById('cmbbxGroups') != null ) queryDoc.getElementById('cmbbxGroups').onchange = function() { redirectTo(this.value) }
    
    if ( queryDoc.getElementsByName('linkHitlist') != null )
    { 
        var links = queryDoc.getElementsByName('linkHitlist');
        for (var i=0;i<links.length;i++)
        {
            links[i].href = "#"
            links[i].onclick = function() 
                                { 
                                    var length = this.id.split(",").length;
                                    
                                    if ( length == 2 ) 
                                    {
                                        var strTxtObjName = this.id.split(",")[0];
                                        var strTxtObj = queryDoc.getElementById(strTxtObjName);
                                        var strColumnName = this.id.split(",")[1];
                                        
                                        
                                        if (  strTxtObj != null )
                                            hintlist_onclick(strTxtObj, strTxtObjName, strColumnName);
                                        
                                    }
                                    else if ( length == 3 )
                                    {
                                        var strTxtObjName = this.id.split(",")[0];
                                        var strColumnName = this.id.split(",")[1];
                                        var strDeptCtlName = this.id.split(",")[2];
                                        var strTxtObj = queryDoc.getElementById(strTxtObjName);
                                        var strDeptCtl = queryDoc.getElementById(strDeptCtlName);
                                        
                                        if ( strTxtObj != null &&  strDeptCtl != null )
                                            hintlist_onclick_type3(strTxtObjName,strColumnName, strDeptCtlName, strTxtObj, strDeptCtl);
                                    }
                                }
        }
    }
    
    if ( queryDoc.getElementsByName('linkCalendar') != null )
    { 
        var links = queryDoc.getElementsByName('linkCalendar');
        for (var i=0;i<links.length;i++)
        {
            links[i].href = "#"
            links[i].onclick = function() 
                                { 
                                    var fieldName = this.id;
                                    
                                    calendar_onclick(fieldName, queryDoc.getElementById(fieldName));
                                }
        }
    }
}                                                    


function initToolbar()
{
    
    
    var toolbarDoc;
    
    if ( parent.document.getElementById("toolbar").contentDocument )
        toolbarDoc = parent.document.getElementById("toolbar").contentDocument;
    else
        toolbarDoc = parent.document.frames["toolbar"].document;
    

        
    if ( toolbarDoc )
    {
        if ( toolbarDoc.getElementById("linkHelp") != null )
        {                                                        
            toolbarDoc.getElementById("linkHelp").href="#" 
            toolbarDoc.getElementById("linkHelp").onclick= function() 
                                                            { 
                                                                var args = "scrollbars=1,status=1,toolbar=0,menubar=0,location=0,fullscreen=0,resizable=1,width=400,height=300";
		                                                        
		                                                        window.open("help/query3_help.htm", "help", args); 
                                                            }
        }
        
        if ( toolbarDoc.getElementById("linkHelp2") != null )
        {                                                        
            toolbarDoc.getElementById("linkHelp2").href="#" 
            toolbarDoc.getElementById("linkHelp2").onclick= function() 
                                                            { 
                                                                var args = "scrollbars=1,status=1,toolbar=0,menubar=0,location=0,fullscreen=0,resizable=1,width=400,height=300";
		                                                        window.open("help/queue2contents_help.htm", "winHelp", args); 
                                                            }
        }
        
        if ( toolbarDoc.getElementById("linkHelp3") != null )
        {                                                        
            toolbarDoc.getElementById("linkHelp3").href="#" 
            toolbarDoc.getElementById("linkHelp3").onclick= function() 
                                                            { 
                                                                var args = "scrollbars=1,status=1,toolbar=0,menubar=0,location=0,fullscreen=0,resizable=1,width=400,height=300";
		                                                        window.open("help/editing_files_and_data/Reserved_Items_.htm", "winHelp", args); 
                                                            }
        }
        
        if ( toolbarDoc.getElementById("linkLibrary") != null )
        {
            toolbarDoc.getElementById("linkLibrary").href="#" 
            toolbarDoc.getElementById("linkLibrary").onclick= function() { redirectTo("selectlibrary.asp") } 
        }
        
        if ( toolbarDoc.getElementById("linkDocGroup") != null )
        {
            toolbarDoc.getElementById("linkDocGroup").href="#" 
            toolbarDoc.getElementById("linkDocGroup").onclick= function() { redirectTo("selectgroup.asp?libraryname=" + this.name) } 
        }
        
        if ( toolbarDoc.getElementById("linkQueue") != null )
        {
            toolbarDoc.getElementById("linkQueue").href="#"
            toolbarDoc.getElementById("linkQueue").onclick = function() { redirectTo("queue2main.asp?" + this.name) }
        }
        
        if ( toolbarDoc.getElementById("linkQueue2") != null )
        {
            toolbarDoc.getElementById("linkQueue2").href="#"
            toolbarDoc.getElementById("linkQueue2").onclick = function() { redirectTo("queue2main.asp?" + this.name) }
        }
        
        if ( toolbarDoc.getElementById("linkQuery") != null )
        {
            toolbarDoc.getElementById("linkQuery").href="#"
            toolbarDoc.getElementById("linkQuery").onclick = function() { redirectTo("query2main.asp?" + this.name) }
        }
        
        if ( toolbarDoc.getElementById("linkQuery2") != null )
        {
            toolbarDoc.getElementById("linkQuery2").href="#"
            toolbarDoc.getElementById("linkQuery2").onclick = function() { redirectTo("query2main.asp?" + this.name) }
        }
        
        if ( toolbarDoc.getElementById("linkReserved") != null )
        {
            toolbarDoc.getElementById("linkReserved").href="#"
            toolbarDoc.getElementById("linkReserved").onclick = function() { redirectTo("reserveditemsmain.asp") }
        }
        
        if ( toolbarDoc.getElementById("linkReserved2") != null )
        {
            toolbarDoc.getElementById("linkReserved2").href="#"
            toolbarDoc.getElementById("linkReserved2").onclick = function() { redirectTo("reserveditemsmain.asp") }
        }
        
        if ( toolbarDoc.getElementById("linkLogout") != null )
        {
            toolbarDoc.getElementById("linkLogout").href = "#"
            toolbarDoc.getElementById("linkLogout").onclick = function() { redirectTo("logout.asp") }
        }
    }
}

function initReserved()
{
    var reservedDoc;
    
    if ( parent.document.getElementById("reserved").contentDocument )
        reservedDoc = parent.document.getElementById("reserved").contentDocument;
    else
        reservedDoc = parent.document.frames["reserved"].document;
    
    if (reservedDoc)
    {
        if ( reservedDoc.getElementsByName('linkCheckin') != null )
        {	
            links = reservedDoc.getElementsByName('linkCheckin');
            for (var i=0;i<links.length;i++)
            {
                links[i].href = "#"
                links[i].onclick = function ()
                                  {
                                    var itemid = this.id.split("_")[0]
                                    var strFileName = this.id.split("_")[1]
                                    
                                    redirectTo("checkin.asp?docid="+itemid+"&"+"file="+strFileName)
                                  }
                
                
                reservedDoc.getElementsByName('linkRelease')[i].href = "#"
                reservedDoc.getElementsByName('linkRelease')[i].onclick = function ()
                                              {
                                                var itemid = this.id.split("_")[0]
                                                var library = this.id.split("_")[1]
                                                
                                                needToConfirm = false;
                                                reservedDoc.location.href = "release.asp?docid=" + itemid + "&lib=" + library;

                                                needToConfirm = true;
                                              }
				//Issue 3692 : OnClick handler for edit link is added (linkEdit) so
				//user would be able to download the item in case 
				//he was not able to do so upon check-out.
                reservedDoc.getElementsByName("linkEdit")[i].href="#"
                reservedDoc.getElementsByName("linkEdit")[i].onclick= function()
                                                                 {
                                                                    var itemid = this.id.split("_")[0]
                                                                    var library = this.id.split("_")[1]
                                                
                                                                    redirectTo("downloadmanager.asp?docid=" + itemid + "&lib=" + library);
                                                                    needToConfirm=true;
                                                                 }
                
            }
        }
        
        if ( reservedDoc.getElementById("linkReservedItemsHelp") != null )
        {
            reservedDoc.getElementById("linkReservedItemsHelp").href = "#"
            reservedDoc.getElementById("linkReservedItemsHelp").onclick = function () 
                                                            { 
                                                                var args = "scrollbars=1,status=1,toolbar=0,menubar=0,location=0,fullscreen=0,resizable=1,width=400,height=300";
	                                                            window.open("help/editing_files_and_data/Reserved_Items_.htm", "winHelp", args); 
	                                                         }
            
        }
    }
}

function initHitlist()
{
    
    
    var hitlistDoc;
    
    if ( parent.document.getElementById("hitlist").contentDocument )
        hitlistDoc = parent.document.getElementById("hitlist").contentDocument;
    else
        hitlistDoc = parent.document.frames["hitlist"].document;
    
    if (hitlistDoc)
    {
        if ( hitlistDoc.getElementById("linkHitlistHelp") != null )
        {
            hitlistDoc.getElementById("linkHitlistHelp").href = "#"
            hitlistDoc.getElementById("linkHitlistHelp").onclick = function () 
                                                            { 
                                                                var args = "scrollbars=1,status=1,toolbar=0,menubar=0,location=0,fullscreen=0,resizable=1,width=400,height=300";
	                                                            window.open("help/hitlist2_help.htm", "winHelp", args); 
                                                            }
        }
        
        if ( hitlistDoc.getElementById("linkHere") != null )
        {
            hitlistDoc.getElementById("linkHere").href = "#"
            hitlistDoc.getElementById("linkHere").onclick = function () 
                                                            { 
                                                                needToConfirm = false;
                                                                
                                                                hitlistDoc.location.href = "hitlist2.asp?forceallrecords=1";
                                                                
                                                                needToConfirm = true;
                                                            }
        }
        
        if ( hitlistDoc.getElementById("linkEmail") != null )
        {
            hitlistDoc.getElementById("linkEmail").href = "#"
            hitlistDoc.getElementById("linkEmail").onclick = function () { 
                                                                            needToConfirm = false;
                                                                            
                                                                            var frm = hitlistDoc.getElementById("frmHitlist");
                                                                            frm.setAttribute("action", "emailfromhitlist.asp");
                                                                            frm.setAttribute("target", "_parent");
                                                                            frm.submit();
                                                                            
                                                                            needToConfirm = true;
                                                                          }
        }
        
        if ( hitlistDoc.getElementById("linkDelete") != null )
        {
            hitlistDoc.getElementById("linkDelete").href = "#"
            hitlistDoc.getElementById("linkDelete").onclick = function ()
                                                              {
                                                                  if (confirm("Are you sure you want to delete the selected records?"))
                                                                  {
                                                                    needToConfirm = false;

                                                                    var frm = hitlistDoc.getElementById("frmHitlist");
                                                                    frm.setAttribute("action", "deletehandler.asp");
                                                                    frm.setAttribute("target", "_self");
                                                                    frm.submit();
                                                                    
                                                                    needToConfirm = true;
                                                                  }
                                                              }
        }
        
        if ( hitlistDoc.getElementById("linkRelease") != null )
        {
            hitlistDoc.getElementById("linkRelease").href = "#"
            hitlistDoc.getElementById("linkRelease").onclick = function () 
                                                                          { 
                                                                            needToConfirm = false;
                                                                            
                                                                            var frm = hitlistDoc.getElementById("frmHitlist");
                                                                            frm.setAttribute("action", "releasemailfromhitlist.asp");
                                                                            frm.setAttribute("target", "_parent");
                                                                            frm.submit();
                                                                            
                                                                            needToConfirm = true;
                                                                          } 
        }
        
        
        
        var links = null;
        
        if ( hitlistDoc.getElementsByName("linkSort") != null )
        {
            links = hitlistDoc.getElementsByName('linkSort');
            for (var i=0;i<links.length;i++)
            {
                links[i].href = "#"
                links[i].onclick = function () { 
                                                    needToConfirm = false;
                                                    
                                                    var colName = this.id.split("_")[0]
                                                    var sortOrder= this.id.split("_")[1]
                                                    
                                                    hitlistDoc.location.href = "hitlist2.asp?sortby=" + colName +
                                                                                "&sortorder=" + sortOrder;
                                                    needToConfirm = true;
                                                                                                                                    
                                                }
            }
        }
        
    
        if ( hitlistDoc.getElementsByName('linkDownload') != null )
        {	
            links = hitlistDoc.getElementsByName('linkDownload');
            for (var i=0;i<links.length;i++)
            {
                //This still needs fixing for Issue 3130
                links[i].href = "#"
                links[i].onclick = function ()
                                  {
                                        arrWindow[index++] = window.open ("docserver.asp?docid=" + this.id,"_blank",
                                                                "scrollbars=1,status=1,toolbar=0,menubar=0,location=0,fullscreen=0,resizable=1");
                                  }
                
                //Right-click and select 'Save target as'               
                hitlistDoc.getElementsByName('linkIdDownload')[i].href = "downloadmanager.asp?docid=" + hitlistDoc.getElementsByName('linkIdDownload')[i].id

                                                                           
                if ( hitlistDoc.getElementsByName('linkEdit')[i] != null )
                {
                    hitlistDoc.getElementsByName('linkEdit')[i].href = "#"
                    hitlistDoc.getElementsByName('linkEdit')[i].onclick = function ()
                                                  {
                                                    redirectTo ("edit.asp?docid=" + this.id)
                                                  }
                }
                
                if ( hitlistDoc.getElementsByName('linkSummary')[i] != null )
                {
                    hitlistDoc.getElementsByName('linkSummary')[i].href = "#"
                    hitlistDoc.getElementsByName('linkSummary')[i].onclick = function ()
                                                  {
                                                    var docid = this.id.split("_")[0]
                                                    var grpid= this.id.split("_")[1]
                                                    
                                                    if ( msieversion() )
                                                    {
                                                        window.showModalDialog('summary.asp?docid=' + docid + '&grpid=' + grpid,"_blank",
                                                                                    "scroll:yes;status:yes;resizable:yes");
                                                                            
                                                    }
                                                    else
                                                    {
                                                        arrWindow[index++] = window.open ('summary.asp?docid=' + docid + '&grpid=' + grpid,"_blank", 
                                                                            "status=1,toolbar=0,scrollbars=1,menubar=0,location=0,fullscreen=0,resizable=1,width=400,height=380");
                                                    }
                                                  }
                }
                
                if ( hitlistDoc.getElementsByName('linkCheckout')[i] != null )
                {                            
                    hitlistDoc.getElementsByName('linkCheckout')[i].href = "#"
                    hitlistDoc.getElementsByName('linkCheckout')[i].onclick = function ()
                                                  {
                                                    redirectTo("checkout.asp?docid=" + this.id);
                                                  }                                              
                }
                          
            }
        }
        
        if ( hitlistDoc.getElementsByName('linkMoreMemo') != null )
        {	
            links = hitlistDoc.getElementsByName('linkMoreMemo');

            for (var i=0;i<links.length;i++)
            {
                links[i].href = "#"
                links[i].onclick = function ()
                                  {
                                    var docid = this.id.split("_")[0]
                                    var colname= this.id.split("_")[1]
                                    
                                    if ( msieversion() )
                                    {
                                        
                                        window.showModalDialog('morememo.asp?docid=' + docid + '&colname=' + colname,"_blank",
                                                                "scroll:yes;status:yes;resizable:yes");
                                    }
                                    else
                                    {
                                        arrWindow[index++] = window.open ('morememo.asp?docid=' + docid + '&colname=' + colname, "_blank", 
                                                                "status=1,toolbar=0,scrollbars=1,menubar=0,location=0,fullscreen=0,resizable=1,width=400,height=380");

                                    }

                                  }
            }
        }               
        
        if ( hitlistDoc.getElementsByName('linkPage') != null )
        {
            links = hitlistDoc.getElementsByName('linkPage');
            for (var i=0;i<links.length;i++)
            {
                links[i].href = "#"
                links[i].onclick = function ()
                                  {
                                    needToConfirm = false;
                                    
                                    var pageNumber = this.id.split("_")[0]
                                    var sortByHTML= this.id.split("_")[1]
                                    
                                    hitlistDoc.location.href = "hitlist2.asp?pg=" + pageNumber + sortByHTML + "&forceallrecords=1&requeryafterupdate=1";
                                    
                                    needToConfirm = true;
                                  }
            }
        }
        
        if ( hitlistDoc.getElementById("hidDocId") != null )
        {
            showDocument(hitlistDoc.getElementById("hidDocId").value)
        }
    }
    
    if (hitlistDoc.getElementById("checkallrecords") != null )
    {
        if ( hitlistDoc.getElementById("checkallrecords").checked ) checkflag = true;
        
        hitlistDoc.getElementById("checkallrecords").onclick = function () 
                                                                {
                                                                    var field = hitlistDoc.getElementsByName("selectedrecords");
                                                                   
                                                                    if (checkflag) 
                                                                    {
                                                                        for (i = 0; i < field.length; i++) 
                                                                            field[i].checked = false; 
                                                                        
                                                                        checkflag = false;
                                                                        
                                                                    }
                                                                    else 
                                                                    {
                                                                        for (i = 0; i < field.length; i++) 
                                                                            field[i].checked = true;
                                                                        
                                                                        checkflag = true;
                                                                        
                                                                    }

                                                                };
    }
    
}

function initSelectLibAndDocGroup()
{
    if ( document.getElementById('tblLibraries') != null )
    {
        var nav = document.getElementById('tblLibraries');
        var links = nav.getElementsByTagName('a');
        	
        for (var i=0;i<links.length;i++)
        {
	        links[i].href = "#"
	        links[i].onclick= function () { redirectTo('selectgroup.asp?libraryname=' + this.id )  }
	                            
        }
        
    }
    
    if ( document.getElementById('selectlibrary_help') != null )
    {
        document.getElementById('selectlibrary_help').href = "#"
        document.getElementById('selectlibrary_help').onclick = function () 
                                                                { 
                                                                    window.open("help/selectlibrary_help.htm", "winHelp", 
                                                                                            "scrollbars=1,status=1,toolbar=0,menubar=0,location=0,fullscreen=0,resizable=1,width=400,height=300");  
                                                                }
    
    }
    
    if (document.getElementById('tblDocGroups') != null )
    {
        
        var nav = document.getElementById('tblDocGroups');
        var links = nav.getElementsByTagName('a');
        	
        for (var i=0;i<links.length;i++)
        {
	        links[i].onclick= function () { redirectTo(this.href) }
        }
    }
    
    if ( document.getElementById('selectgroup_help') != null )
    {
        document.getElementById('selectgroup_help').href = "#"
        document.getElementById('selectgroup_help').onclick = function () 
                                                              { 
                                                                window.open("help/selectgroup_help.htm", "winHelp", 
                                                                                        "scrollbars=1,status=1,toolbar=0,menubar=0,location=0,fullscreen=0,resizable=1,width=400,height=300");  
                                                              }

    }
    
}

function redirectTo(hrefstr)
{
    needToConfirm = false;
    parent.location.href = hrefstr;
}

// This function invokes a spy window that detects 
//if the parent window is closed or not. If parent window gets closed, the spy window closes the current session
//and subsequently releases the license held by the session.
function closeSession() 
{
    //This closes all opened pop-up windows (eg. help window)
    if ( arrWindow.length > 0 )
    {
        for (var i = 0; i < arrWindow.length; i++ )
        {
            arrWindow[i].close()
        }
        
        index = 0;
    }
    
    if ( needToConfirm )
        spyWin = window.open('spywin.asp','spyWin', 'width=100,height=100,left=4000,top=0,status=1');
}






