﻿var needToConfirm = true;
var arrWindow = new Array(); //This will hold all opened pop-up windows.
var index = 0;
var isIE;
var checkflag = false;
var httpRequest  = null;
var success = "1", error = "2", timeout = "3", nosummary="4", eof ="5", accessdenied = "6";
var sid = "";
var docId,grpId,startExp, pollId;
var status, message, parameters;
var queueContentsDoc;
var WIDTH = 9;
var MAXCHARLENGTH = 8;
var dateErrMsg, numErrMsg, entryMsg, reqFieldErrMsg, uploadErrMsg, emailErrMsg;
var viewToolTip = "", indexToolTip = "", forwardToolTip = "", tooTipCopy = "", emailDocToolTip = "", delDocToolTip = "", saveAsToolTip = "";
var delConfirmMsg = "", loadingMsg = "";
var max_waiting_time = 0; //Set to 0 seconds by default. Value will be assigned in summary.asp
var oldPage = 0 //global variable to store the old page number

//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("error") )
            {
                initError()
            }
           
            if (    parent.location.href.match("quploadhandler") ||
                    parent.location.href.match("indexhandler") ||
                    parent.location.href.match("qdeletehandler") ||
                    parent.location.href.match("qforwardhandler") ||
                    parent.location.href.match("queue2_copytohandler") )
            {
                initInputQueueHandlers()
            }
            
            
        }

function initEditHandler()
{
    needToConfirm = true;
    
    if ( document.getElementById('btnBackError') != null )
    {
        needToConfirm = false;
        
   		//Issue 3684: Added a Back button so user would be able to go back
   		//to the reserved items page.
        document.getElementById('btnBackError').onclick = function () { window.history.back() }
    }
}

function initRelease()
{
    needToConfirm = true;
    
    if ( document.getElementById('btnBackError') != null )
    {
        needToConfirm = false;
        
   		//Issue 3684: Added a Back button so user would be able to go back
   		//to the reserved items page.
        document.getElementById('btnBackError').onclick = function () { window.history.back() }
    }
} 
        
function initError()
{
    needToConfirm = true;
    
    if ( document.getElementById('btnBackError') != null )
    {
        needToConfirm = false;
        
   		//Issue 3684: Added a Back button so user would be able to go back
   		//to the reserved items page.
        document.getElementById('btnBackError').onclick = function () { window.history.back() }
    }
}        
        
function showDocument(docId)
{
    if (docId != null )
    {
        arrWindow[index++] = window.open("docserver.asp?docid=" + docId + "&s="+sid, "_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(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";
	    
    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 = 500; 
        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?s="+sid+"&r="+page+"&tx="+sTxtObjName+"&cn="+sColumnName+"&frm=frmQuery", null, args);
    if (wnd!=null){
        wnd.opener = self;
        wnd.focus();
    }
    
    //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 = "";
    }
    
    //Hintlist pop-up window added to arrWindow array
    //to be closed when closeSession() is called
    arrWindow[index++] = wnd;   

}
	
function hintlist_onclick_type3(frmName, strTxtObjName, strColumnName, 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";
	    
    var wnd, args, x, y, strDepCtlContents;

    strDepCtlContents = 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 = 500; 
        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?s="+sid+"&r="+page+"&tx=" + strTxtObjName + "&cn=" + strColumnName + "&frm=" + frmName + "&search=" + strDepCtlContents, null, args);
    if (wnd!=null){
        wnd.opener = self;
        wnd.focus();
    }
    
    //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 = "";
    }  


    //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');
    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(msgPageNumberEnteredInvalid)
{
    
    needToConfirm = false;
    
    if ( document.getElementById("hidFormName") != null ) 
    {
        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);
                                    }
            }
        }
    }
    if ( document.getElementsByName('linkPage') != null )
        {
            links = document.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 s=this.id.split("_")[1]
                                    var r= this.id.split("_")[2]
                                    var tx= this.id.split("_")[3]
                                    var cn= this.id.split("_")[4]
                                    var frm= this.id.split("_")[5]
                                    document.location.href = "hintlist.asp?s="+s+"&r="+r+"&tx="+tx+"&cn="+cn+"&frm="+frm+"&pg="+pageNumber
                                    needToConfirm = true;
                                  }
            
            }
        }
     if (document.getElementById("buttonGoToPage")!= null )
    {
                
                document.getElementById("buttonGoToPage").onclick = function () 
                {
                    needToConfirm = false;
                    var pageNumber = parseInt(document.getElementById("txtGoToPage").value);
                    var s=document.getElementById("hidQueryString").value.split("_")[0];
                    var r=document.getElementById("hidQueryString").value.split("_")[1];
                    var tx=document.getElementById("hidQueryString").value.split("_")[2];   
                    var cn=document.getElementById("hidQueryString").value.split("_")[3];  
                    var frm=document.getElementById("hidQueryString").value.split("_")[4];
                    var lastPage=document.getElementById("hidQueryString").value.split("_")[5];
                    if ( isNaN(pageNumber) || pageNumber > lastPage || pageNumber < 1  )
                        {
                            alert(msgPageNumberEnteredInvalid);
                            return;
                        }
                    document.location.href = "hintlist.asp?s="+s+"&r="+r+"&tx="+tx+"&cn="+cn+"&frm="+frm+"&pg="+pageNumber
                    needToConfirm = true;

                  };
    
    }
}

function initEmailHandler(groupName, groupId)
{
    if ( document.getElementById('btnSubmit') != null ) 
        document.getElementById('btnSubmit').onclick = function () { needToConfirm = false; }

    if ( document.getElementById('btnBack') != null )
    {
        if ( parent.location.href.match("emailfromqueue") )
            document.getElementById('btnBack').onclick = function () { redirectTo("queue2main.asp?groupname="+groupName+"&grpid="+groupId); }
        else if ( parent.location.href.match("emailfromhitlist") || parent.location.href.match("releasemailfromhitlist") )
        {
            document.getElementById('btnBack').onclick = function () { redirectTo("query2main.asp?groupname="+groupName+"&grpid="+groupId); }
        }
    }  
    
    if ( document.getElementById('btnBackError') != null )
    {
        if ( parent.location.href.match("emailfromhitlist") || parent.location.href.match("releasemailfromhitlist") )
            document.getElementById('btnBackError').onclick = function () { redirectTo("query2main.asp?groupname="+groupName+"&grpid="+groupId); }
    }    
}

function initCheckOutCheckIn(noFileToUploadErrMsg, invalidFileErrMsg)
{
    if ( document.getElementById('btnBackError') != null )
    {
        document.getElementById('btnBackError').onclick = function () { window.history.back() }
    }
    
    if ( document.getElementById('frmCheckout') != null )
    {
        document.getElementById('frmCheckout').action = "checkouthandler.asp";
        document.getElementById('frmCheckout').method = "post";
    
        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";
        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="docserver.asp?rdocid=" + document.getElementById("linkDownload").name + "&d=1"
    }
    
    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('btnBackError') != null )
    {

   		//Issue 3684: Added a Back button so user would be able to go back
   		//to the reserved items page.
        document.getElementById('btnBackError').onclick = function () { window.history.back() }
    }
    
    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(noFileToUploadErrMsg);
                                                            
                                                            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(invalidFileErrMsg);
                                                                return false;
                                                            }
                                                            
                                                            document.getElementById('Filename').value = filename;
                                                            needToConfirm=false;
                                                            
                                                            return true;
                                                        }
                                                    }
    }


	     
}

//This will facilitate the form submission of frmResetPwd
//using the AJAX technology.
function makeRequest(doc)
{
    var result, parameters;  
    httpRequest  = null;
    
    //Set the key-value pairs by getting the values of
    //the text fields in frmResetPwd
    parameters = "user=" + encodeURIComponent(doc.getElementById('txtUsername').value);
    parameters = parameters + "&oldpwd=" +  encodeURIComponent(doc.getElementById('txtOldPwd').value);
    parameters = parameters + "&newpwd1=" + encodeURIComponent(doc.getElementById('txtNewPwd1').value);
    parameters = parameters + "&newpwd2=" + encodeURIComponent(doc.getElementById('txtNewPwd2').value);
    
    //Initialize the XMLHttpRequest object    
    if (window.XMLHttpRequest) // Mozilla, Safari,...
    { 
         httpRequest = new XMLHttpRequest();
         
         if (httpRequest.overrideMimeType) {
         	// set type accordingly to anticipated content type
            httpRequest.overrideMimeType('text/xml');
         }
    } 
    else if (window.ActiveXObject) // IE
    { 
        try 
        {
            httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
        } 
        catch (e) 
        {
            try 
            {
               httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
            } 
            catch (e) {}
        }
    }

    if (httpRequest == null) 
    {
        alert('Cannot create XMLHTTP instance');
        return false;
    }
    
    var loadingStr
    loadingStr = "Processing";
    doc.getElementById('errorMessage').style.color = "blue";
            

    //Set the XMLHTTPRequest.OnReadyStateChange handler
    httpRequest.onreadystatechange = function() {
        if (httpRequest.readyState > 0 && httpRequest.readyState < 4) {
                                                
            doc.getElementById('errorMessage').style.display = "block";
                                                doc.getElementById('errorMessage').innerHTML = loadingStr + "<img src='assets/images/mozilla_blue.gif' alt=''/>";
                                                
                                                doc.getElementById('txtUsername').disabled = "disabled";
                                                doc.getElementById('txtOldPwd').disabled = "disabled";
                                                doc.getElementById('txtNewPwd1').disabled = "disabled";
                                                doc.getElementById('txtNewPwd2').disabled = "disabled";
                                                doc.getElementById('btnSubmit').disabled = "disabled";
                                            }
                                                                                  
                                          //Checks if the request has been fulfilled
                                          if (httpRequest.readyState == 4) 
                                          {
                                            doc.getElementById('txtUsername').disabled = "";
                                            doc.getElementById('txtOldPwd').disabled = "";
                                            doc.getElementById('txtNewPwd1').disabled = "";
                                            doc.getElementById('txtNewPwd2').disabled = "";
                                            doc.getElementById('btnSubmit').disabled = "";
                                             
                                             //Checks if the status returned is OK
                                             if (httpRequest.status == 200) 
                                             {
                                                //Read the status and message returned by 
                                                //resetpwdhandler.asp
                                                var xmlDoc, status, message;
                                                xmlDoc = httpRequest.responseXML
                                                
                doc.getElementById('errorMessage').style.display = "block";

                                                if ( msieversion() )
                                                {
                                                    status = xmlDoc.selectNodes("/xml/status")[0].childNodes[0].nodeValue;
                                                    message = xmlDoc.selectNodes("/xml/message")[0].childNodes[0].nodeValue;
                                                    
                                                    doc.getElementById('errorMessage').innerText = evaluateResponse(status, message,doc);
                                                }
                                                else
                                                {
                                                    var xmlPathNodes;
                                                    xmlPathNodes = xmlDoc.evaluate("/xml/status", xmlDoc, null, XPathResult.ANY_TYPE, null).iterateNext();
                                                    status = xmlPathNodes.childNodes[0].nodeValue
                                                    xmlPathNodes = xmlDoc.evaluate("/xml/message", xmlDoc, null, XPathResult.ANY_TYPE, null).iterateNext();
                                                    message = xmlPathNodes.childNodes[0].nodeValue;
                                                    
                                                    doc.getElementById('errorMessage').innerHTML = evaluateResponse(status, message,doc);
                                                    
                                                }
                                                
                                                if ( status == success )
                                                {
                                                    doc.getElementById('txtUsername').value = "";
                                                    doc.getElementById('txtOldPwd').value = "";
                                                    doc.getElementById('txtNewPwd1').value = "";
                                                    doc.getElementById('txtNewPwd2').value = "";
                                                    doc.getElementById('btnSubmit').disabled = "disabled";
                                                }
                                                
                                             } 
                                             else 
                                             {
                                                alert("There was a problem with the request.");
                                             }
                                          }

                                    }
        
        //Post request asynchronously
        httpRequest.open("POST", "resetpwdhandler.asp", true);
        httpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        httpRequest.setRequestHeader("Content-length", parameters.length);
        httpRequest.setRequestHeader("Connection", "close");
        httpRequest.send(parameters);
}


//Evaluates the response sent by resetpwdhandler.asp
//and do appropriate actions.
function evaluateResponse(status, message, doc)
{
    var t;
    doc.getElementById('errorMessage').style.color = "red";    
    
            
    if (status == timeout)
    {
        needToConfirm = false;
        parent.location = "timeout.asp";
        message = "";
    }
    else if (status == success)
    {
        needToConfirm = false;
        doc.getElementById('errorMessage').style.color = "blue";
        t = setTimeout('javascript:parent.location.href = "default.asp"',3000);
    }

    return message;
}

    
function addRow(id,dbody)
{
    pTable = document.getElementById(id);
    pTable.innerHTML += dbody;
}

//This function starts polling for any event and fetches data from the database.
/*function startPolling2()
{ 
    pollId = setInterval("detectScroll2()",500); 
}*/

//This detects the scrolling event.
/*function detectScroll2()
{
    needToConfirm = true;
    
    var intElemScrollHeightOuter = queueContentsDoc.getElementById("new_items_div").clientHeight;        
    var intElemScrollHeightInner = queueContentsDoc.getElementById("new_items").scrollHeight;
    var intElemScrolled = queueContentsDoc.getElementById("new_items_div").scrollTop;    
        
    var height = intElemScrollHeightInner - intElemScrollHeightOuter;  

    //Fetch data when user scrolls 70% down.      
    if (intElemScrolled >= (height * 0.70))
    { 
        getQueueTable();
    }

    return true;
} */


function startPolling()
{ 
    pollId = setInterval("detectScroll()",500); 
}

function detectScroll(){
    needToConfirm = false;
    
    var intElemScrollHeightOuter = document.getElementById("new_items_div").clientHeight;        
    var intElemScrollHeightInner = document.getElementById("new_items").scrollHeight;
    var intElemScrolled = document.getElementById("new_items_div").scrollTop;    
        
    var height = intElemScrollHeightInner - intElemScrollHeightOuter;  
      
    if (intElemScrolled >= height-500)
    { 
        getSummaryText();
    }        
        
    return true;
} 

//This glues back together string that were sent as 4096-character chunks.
function getNodeText(node) {
    var r = "";
    for (var x = 0;x < node.childNodes.length; x++) {
        r = r + node.childNodes[x].nodeValue;
    }
    return r;
}

//This function creates a row in the Input Queue table.
function addRowInQueueTable(queueContentsDoc, table_id, id, orig, filename, filetype, desc){  
    var pTable, row1, cell1, cell2, cell3, cell4
    pTable = queueContentsDoc.getElementById(table_id);
    row1 = pTable.insertRow(pTable.rows.length);    
    row1.className = "row_results";
    
    var toolbar = "";

    if ( orig == "1" ) 
    {
        toolbar = "<a id='linkView"+id+"' name='"+filename+"&original=1&s="+sid+"' title='"+viewToolTip+"'><IMG ALT='"+viewToolTip+"' BORDER=0 SRC='"+queueContentsDoc.getElementById("viewButtonImage").value+"'></a>&nbsp;"
        toolbar = toolbar + "<a id='linkIndex"+id+"' name='"+filename+"' title='"+indexToolTip+"'><IMG BORDER=0 ALT='"+indexToolTip+"' SRC='"+queueContentsDoc.getElementById("indexButtonImage").value+"'></a>&nbsp;";
        toolbar = toolbar + "<a id='linkForward"+id+"' name='"+filename+"&original=1' title='"+forwardToolTip+"'><IMG ALT='"+forwardToolTip+"' BORDER=0 SRC='"+queueContentsDoc.getElementById("forwardButtonImage").value+"'></a>&nbsp;";
        toolbar = toolbar + "<a id='linkCopy"+id+"' name='"+filename+"&original=1' title='"+copyToolTip+"'><IMG ALT='"+copyToolTip+"' BORDER=0 SRC='"+queueContentsDoc.getElementById("copyToButtonImage").value+"'></a>&nbsp;";
        toolbar = toolbar + "<a id='linkEmailQueue"+id+"' name='"+filename+"&original=1' title='"+emailDocToolTip+"'><IMG ALT='"+emailDocToolTip+"' BORDER=0 SRC='"+queueContentsDoc.getElementById("emailButtonImage").value+"'></a>&nbsp;";
        toolbar = toolbar + "<a id='linkDeleteQueue"+id+"' name='"+filename+"&original=1' title='"+delDocToolTip+"'><IMG ALT='"+delDocToolTip+"' BORDER=0 SRC='"+queueContentsDoc.getElementById("deleteButtonImage").value+"'></a>&nbsp;";

    }
    else
    {
        toolbar = "<a id='linkView"+id+"' name='"+filename+"&original=0&s="+sid+"' title='"+viewToolTip+"'><IMG ALT='"+viewToolTip+"' BORDER=0 SRC='"+queueContentsDoc.getElementById("viewButtonImage").value+"'></a>&nbsp;"
        toolbar = toolbar + "<a id='linkForward"+id+"' name='"+filename+"&original=0' title='"+forwardToolTip+"'><IMG ALT='"+forwardToolTip+"' BORDER=0 SRC='"+queueContentsDoc.getElementById("forwardButtonImage").value+"'></a>&nbsp;";
        toolbar = toolbar + "<a id='linkCopy"+id+"' name='"+filename+"&original=0' title='"+copyToolTip+"'><IMG ALT='"+copyToolTip+"' BORDER=0 SRC='"+queueContentsDoc.getElementById("copyToButtonImage").value+"'></a>&nbsp;";
        toolbar = toolbar + "<a id='linkEmailQueue"+id+"' name='"+filename+"&original=0' title='"+emailDocToolTip+"'><IMG ALT='"+emailDocToolTip+"' BORDER=0 SRC='"+queueContentsDoc.getElementById("emailButtonImage").value+"'></a>&nbsp;";
        toolbar = toolbar + "<a id='linkDeleteQueue"+id+"' name='"+filename+"&original=0' title='"+delDocToolTip+"'><IMG ALT='"+delDocToolTip+"' BORDER=0 SRC='"+queueContentsDoc.getElementById("deleteButtonImage").value+"'></a>&nbsp;";

    }

    cell1 =  row1.insertCell(0);
    cell1.innerHTML = toolbar;


    cell2 = row1.insertCell(1);
    cell2.innerHTML = "<A id='linkViewFile"+id+"' name='" + filename +"' " +  
			            "title=\""+saveAsToolTip+"\">" + 
				        filename + "</A>";
    cell3 = row1.insertCell(2);
    cell3.innerHTML = filetype;  
    cell4 = row1.insertCell(3);
    cell4.innerHTML = desc;     
    
    
    if ( queueContentsDoc.getElementById('linkView'+id) != null )
    {
        queueContentsDoc.getElementById('linkView'+id).href = "#"
        queueContentsDoc.getElementById('linkView'+id).onclick =  function ()
                                                                      {
                                                                            needToConfirm = true;
                                                                            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 ( queueContentsDoc.getElementById('linkIndex'+id) != null )
    {
        queueContentsDoc.getElementById('linkIndex'+id).href = "#"
        queueContentsDoc.getElementById('linkIndex'+id).onclick =  function () { redirectTo ("index.asp?qfilename="+ this.name) }
    }

    if ( queueContentsDoc.getElementById('linkForward'+id) != null )
    {
        queueContentsDoc.getElementById('linkForward'+id).href = "#"
        queueContentsDoc.getElementById('linkForward'+id).onclick = function () { redirectTo ("qforward.asp?qfilename=" + this.name) }
    }

    if ( queueContentsDoc.getElementById('linkCopy'+id) != null )
    {
        queueContentsDoc.getElementById('linkCopy'+id).href = "#"
        queueContentsDoc.getElementById('linkCopy'+id).onclick = function () { redirectTo ("queue2_copyto.asp?qfilename=" + this.name) }
    }

    if ( queueContentsDoc.getElementById('linkEmailQueue'+id) != null )
    {
        queueContentsDoc.getElementById('linkEmailQueue'+id).href = "#"
        queueContentsDoc.getElementById('linkEmailQueue'+id).onclick = function () 
                                                                            {
                                                                                needToConfirm = false;
                                                                                parent.location.href = "emailfromqueue.asp?qfilename=" + this.name , null, 
                                                                                    "scrollbars=1,status=1,toolbar=0,menubar=0,location=0,fullscreen=0,resizable=1,width=500,height=300";
                                                                            }
    }

    if ( queueContentsDoc.getElementById('linkDeleteQueue'+id) != null )
    {
        queueContentsDoc.getElementById('linkDeleteQueue'+id).href = "#"
        queueContentsDoc.getElementById('linkDeleteQueue'+id).onclick = function () 
                                                                            { 
                                                                                if (confirm(delConfirmMsg + " '" + this.name.split("&")[0] + "'?"))
                                                                                {
                                                                                    redirectTo("qdeletehandler.asp?qfilename=" + this.name)
                                                                                }
                                                                            }
    }

    if ( queueContentsDoc.getElementById('linkViewFile'+id) != null )
    {                                                                                                   
        queueContentsDoc.getElementById('linkViewFile'+id).onclick =  function ()
                                                                      {
                                                                            needToConfirm = true;
                                                                       }
        //Right-click and select 'Save target as'
        queueContentsDoc.getElementById('linkViewFile'+id).href = "docserver.asp?qfilename=" + queueContentsDoc.getElementById('linkViewFile'+id).name + "&d=1";
    }                     

}	

//This function gets the data from the database asynchronously.
/*function getQueueTable()
{
    var doc
    doc = queueContentsDoc;
    
    var parameters;  
    httpRequest  = null;
    
    //Set the key-value pairs by getting the values of
    //the text fields in frmResetPwd
    parameters = "p=" + doc.getElementById("hidCurPage").value;
    
    //Initialize the XMLHttpRequest object    
    if (window.XMLHttpRequest) // Mozilla, Safari,...
    { 
        try 
        {
            httpRequest = new XMLHttpRequest();

            if (httpRequest.overrideMimeType) {
            // set type accordingly to anticipated content type
            httpRequest.overrideMimeType('text/xml');
            }
        }
        catch (e)
        {
            clearInterval(pollId); 
            alert('Cannot create XMLHTTP instance');
        }            
    } 
    else if (window.ActiveXObject) // IE
    { 
        try 
        {
            httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
        } 
        catch (e) 
        {
            try 
            {
               httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
            } 
            catch (e) 
            {
                clearInterval(pollId); 
                alert('Cannot create XMLHTTP instance');
            }
        }
    }

    if (httpRequest != null) 
    {
        
        var filename, filetype, desc, id, orig 
        var loadingStr
        loadingStr = loadingMsg
        
        //Set the XMLHTTPRequest.OnReadyStateChange handler
        httpRequest.onreadystatechange = function() 
                                          {
                                              if ( httpRequest.readyState < 4 ) 
                                              {
                                                
                                                doc.getElementById("divMessage").style.visibility = "visible";
                                                
                                                loadingStr = loadingStr + ".";
                                                doc.getElementById("divMessage").innerHTML = loadingStr;
                                                
                                              }
                                               
                                              //Checks if the request has been fulfilled
                                              if (httpRequest.readyState == 4)
                                              {
                                                
                                                doc.getElementById("divMessage").style.visibility = "hidden";
                                                doc.getElementById("divMessage").innerHTML = "";
                                                 
                                                 //Checks if the status returned is OK
                                                 if (httpRequest.status == 200) 
                                                 {
                                                    //Read the status and message returned by 
                                                    //queue2contentshandler.asp
                                                    var xmlDoc;
                                                    xmlDoc = httpRequest.responseXML
                                                    var files;
                                                    
                                                    if ( msieversion() )
                                                    {
                                                        status = xmlDoc.selectNodes("/xml/status")[0] == null ? "" : xmlDoc.selectNodes("/xml/status")[0].childNodes[0].nodeValue;
                                                        message = xmlDoc.selectNodes("/xml/message")[0] == null ? "" : xmlDoc.selectNodes("/xml/message")[0];
                                                        
                                                        if ( evaluateResponse3(status) )
                                                        {
                                                            files = xmlDoc.selectNodes("/xml/message/file") == null ? "" : xmlDoc.selectNodes("/xml/message/file"); //message.childNodes;
                                                            doc.getElementById("new_items").style.visibility = "visible";
                                                            
                                                            for (i=0;i<files.length;i++)
                                                            {
                                                                id = files[i].childNodes[0].childNodes[0].nodeValue;
                                                                orig = files[i].childNodes[1].childNodes[0].nodeValue;      
                                                                filename = files[i].childNodes[2].childNodes[0].nodeValue;    
                                                                filetype = files[i].childNodes[3].childNodes[0].nodeValue;    
                                                                desc = files[i].childNodes[4].childNodes[0].nodeValue;        
                                                                
                                                                addRowInQueueTable(doc, "new_items", id, orig, filename, filetype, desc);
                                                            }
                                                         
                                                            doc.getElementById("hidCurPage").value = eval(doc.getElementById("hidCurPage").value) + 1;   
                                                            
                                                        }
                                                        else
                                                        {
                                                            if ( status == accessdenied ) 
                                                            {
                                                                doc.getElementById("divMessage").style.visibility = "visible";
                                                                doc.getElementById("divMessage").innerHTML = "<div class=\"header_label\">Access Denied</div>" +
                                                                "<p class=\"par_header\">Sorry, you do not currently have access to sqlci3.<p/>" +
                                                                "<p>If you believe you should have access to this Library, " + 
                                                                "please see your system administrator about updating your access rights.</p>"
                                                            }
                                                            else
                                                            {
                                                                if ( message.childNodes[0] != null )
                                                                {
                                                                    doc.getElementById("divMessage").style.visibility = "visible";
                                                                    doc.getElementById("divMessage").innerHTML = message.childNodes[0].nodeValue;
                                                                }
                                                             }
                                                            
                                                            clearInterval(pollId); 
                                                        }
                                                        
                                                    }
                                                    else
                                                    {
                                                        var xmlPathNodes;
                                                        xmlPathNodes = xmlDoc.evaluate("/xml/status", xmlDoc, null, XPathResult.ANY_TYPE, null).iterateNext();
                                                        status = xmlPathNodes != null ? xmlPathNodes.childNodes[0].nodeValue : error;
                                                        xmlPathNodes = xmlDoc.evaluate("/xml/message", xmlDoc, null, XPathResult.ANY_TYPE, null).iterateNext();
                                                        //message = xmlPathNodes.childNodes[0].nodeValue;
                                                        
                                                        if ( evaluateResponse3(status) )
                                                        {
                                                            files = xmlPathNodes.childNodes;
                                                            doc.getElementById("new_items").style.visibility = "visible";
                                                            
                                                            for (i=0;i<files.length;i++)
                                                            {
                                                                id = files[i].childNodes[0].childNodes[0].nodeValue;
                                                                orig = files[i].childNodes[1].childNodes[0].nodeValue;      
                                                                filename = files[i].childNodes[2].childNodes[0].nodeValue;    
                                                                filetype = files[i].childNodes[3].childNodes[0].nodeValue;    
                                                                desc = files[i].childNodes[4].childNodes[0].nodeValue;        
                                                                
                                                                addRowInQueueTable(doc, "new_items", id, orig, filename, filetype, desc);
                                                            }
                                                            
                                                            doc.getElementById("hidCurPage").value = eval(doc.getElementById("hidCurPage").value) + 1; 
                                                        }
                                                        else
                                                        {
                                                            doc.getElementById("divMessage").style.visibility = "visible";
                                                            
                                                            if ( status == accessdenied ) 
                                                            {
                                                                doc.getElementById("divMessage").innerHTML = "<div class=\"header_label\">Access Denied</div>" +
                                                                "<p class=\"par_header\">Sorry, you do not currently have access to sqlci3.<p/>" +
                                                                "<p>If you believe you should have access to this Library, " + 
                                                                "please see your system administrator about updating your access rights.</p>"
                                                            }
                                                            else
                                                                doc.getElementById("divMessage").innerHTML = xmlPathNodes != null ? xmlPathNodes.childNodes[0].nodeValue : "";
                                                                
                                                            clearInterval(pollId); 
                                                        }
                                                    }
                                                 } 
                                                 else 
                                                 {
                                                    clearInterval(pollId); 
                                                    alert("There was a problem with the request.");
                                                 }
                                              }
                                              
                                              

                                        }
            
        //Post request asynchronously
        httpRequest.open("GET", "queue2contentshandler.asp?"+parameters, true);
        httpRequest.send();    
    }
    else
    {
        clearInterval(pollId); 
        alert('Cannot create XMLHTTP instance');
    }        
        
}*/

function getSummaryText()
{
    needToConfirm = false;
    
    var result, parameters;  
    httpRequest  = null;
    
    //Set the key-value pairs by getting the values of
    //the text fields in frmResetPwd
    parameters = "docid=" + encodeURIComponent(docId);
    parameters = parameters + "&grpid=" +  encodeURIComponent(grpId);
    parameters = parameters + "&startexp=" +  encodeURIComponent(startExp);
    parameters = parameters + "&s=" + sid;
    
    //Initialize the XMLHttpRequest object    
    if (window.XMLHttpRequest) // Mozilla, Safari,...
    { 
        try 
        {
            httpRequest = new XMLHttpRequest();
        }
        catch (e)
        {
            
            alert('Cannot create XMLHTTP instance');
        }            
    } 
    else if (window.ActiveXObject) // IE
    { 
        try 
        {
            httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
        } 
        catch (e) 
        {
            try 
            {
               httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
            } 
            catch (e) 
            {
                alert('Cannot create XMLHTTP instance');
            }
        }
    }

    if (httpRequest != null) 
    {
        //Post request asynchronously
        httpRequest.open("POST", "summaryhandler.asp?"+parameters, true);

		var y = 0;

		// Handle timeout situation, e.g. Retry or inform user.
 		var requestTimer = setTimeout(function() {
					httpRequest.abort();
					alert("It takes a long time for the server to load the summary text. Reload the browser to try again.");	
					}, max_waiting_time);

    	var processRequest = false;
    	
        //Set the XMLHTTPRequest.OnReadyStateChange handler
        //Set the XMLHTTPRequest.OnReadyStateChange handler
    	httpRequest.onreadystatechange = function() 
                                      {
                                          //Checks if the request has been fulfilled
                                          if (httpRequest.readyState == 4) 
                                          {
                                            clearTimeout(requestTimer);

                                            //Checks if the status returned is OK
                                            if (httpRequest.status == 200) 
                                            {
                                                //Read the status and message returned by 
                                                //summaryhandler.asp
                                                var xmlDoc;
                                                xmlDoc = httpRequest.responseText;

                                                if ( msieversion() )
                                                {
                                                    try
                                                    {
                                                        status = xmlDoc.substring(xmlDoc.search(/<status>/)+8, xmlDoc.search(/<\/status>/));
                                                        message = xmlDoc.substring(xmlDoc.search(/<message>/)+9, xmlDoc.search(/<\/message>/));
                                                        parameters = xmlDoc.substring(xmlDoc.search(/<parameters>/)+12, xmlDoc.search(/<\/parameters>/));
                                                        processRequest = evaluateResponse2(status);
                                                        
                                                        addRow("new_items",message);
                                                        docId = parameters.split("_")[0];
                                                        grpId = parameters.split("_")[1];
                                                        startExp = parameters.split("_")[2];
                                                        
                                                        if ( !processRequest || parameters == "#")
                                                        {
                                                            return processRequest;
                                                        }
                                                                                                                    
                                                        
                                                    }
                                                    catch (e)
                                                    {
                                                        alert("There was a problem with the request.");
                                                    }
                                                    
                                                    
                                                }
                                                else
                                                {
                                                    try
                                                    {
                                                        
                                                        status = xmlDoc.substring(xmlDoc.search(/<status>/)+8, xmlDoc.search(/<\/status>/));
                                                        message = xmlDoc.substring(xmlDoc.search(/<message>/)+9, xmlDoc.search(/<\/message>/));
                                                        parameters = xmlDoc.substring(xmlDoc.search(/<parameters>/)+12, xmlDoc.search(/<\/parameters>/));
                                                        processRequest = evaluateResponse2(status);
                                                        
                                                        addRow("new_items",message);
                                                        
                                                        docId = parameters.split("_")[0];
                                                        grpId = parameters.split("_")[1];
                                                        startExp = parameters.split("_")[2];
                                                        
                                                        if ( !processRequest || parameters == "#")
                                                        {
                                                            return processRequest; 
                                                        }
                                                    
                                                        
                                                    }
                                                    catch(e)
                                                    {
                                                        alert("There was a problem with the request.");
                                                    }
                                                    
                                                }
                                            } 
                                            else 
                                            {
                                                y++;

                                                //This prevents double alert display
                                                if ( y < 2 ) alert("There was a problem with the request.");
                                            }
                                        }
                                        
                                        if (processRequest) getSummaryText();
                                        
                                    }
            
        //Post request asynchronously
        httpRequest.send();    
    }
    else
    {
        alert('Cannot create XMLHTTP instance');
    }        
        
}

function setHiddenParams(docid,grpid,startexp)
{
    docId = docid;
    grpId = grpid;
    startExp = startexp;
    
    getSummaryText();
}

//Evaluates the response sent by resetpwdhandler.asp
//and do appropriate actions.
function evaluateResponse3(status)
{
        
    if (status == timeout)
    {
        parent.location = "timeout.asp";
        return false;
    }
    else if (status == error || status == nosummary || status == eof || status == accessdenied)
    {
        return false;
    }

    return true;
}

//Evaluates the response sent by resetpwdhandler.asp
//and do appropriate actions.
function evaluateResponse2(status)
{
    needToConfirm = false;
        
    if (status == timeout)
    {
        parent.location = "timeout.asp";
        return false;
    }
    else if (status == error || status == nosummary )
    {
        return false;
    }
    else if ( status == eof ) 
    {
        message = ""
        return false;
    }

    return true;
}

//Function that will initialize the event handlers
//for resetpassword.asp
function initResetPassword(maxval, errormessage)
{
    //Assigns the action propery of frmResetPwd
    if ( document.getElementById('frmResetPwd') != null )
    {
        document.getElementById('frmResetPwd').action="javascript:makeRequest(document);"

    }

    //Assigns the onclick property of btnBack button    
    if ( document.getElementById('btnBack') != null )
    {
        document.getElementById('btnBack').onclick = function () 
                                                     { 
                                                        window.history.back();
                                                        return false; 
                                                     }
    }
                                                 //Check the length of new password
                                                 ResetPasswordCountCharacter(maxval, errormessage);
}

function ResetPasswordCountCharacter(maxval,errormessage) {

        if (document.getElementById('txtNewPwd1') != null) {

            document.getElementById('txtNewPwd1').onkeydown = function() {
                var newpswd = document.getElementById('txtNewPwd1');
                if (newpswd.value.length > parseInt(maxval)) {
                    newpswd.value = newpswd.value.substring(0, parseInt(maxval));
                    document.getElementById('errorMessage').style.display = 'block';
                    document.getElementById('errorMessage').innerHTML =errormessage;
                    
                }
            }
            document.getElementById('txtNewPwd1').onkeyup = function() {
                var newpswd = document.getElementById('txtNewPwd1');
                if (newpswd.value.length > parseInt(maxval)) {
                    newpswd.value = newpswd.value.substring(0, parseInt(maxval));
                    document.getElementById('errorMessage').style.display = 'block';
                    document.getElementById('errorMessage').innerHTML = errormessage;
                    
                 }
            }
         }
}

function initInputQueueHandlers()
{
    //Assigns the onclick property of btnBack button    
    if ( document.getElementById('btnBackError') != null )
    {
        document.getElementById('btnBackError').onclick = function () 
                                                     { 
                                                        redirectTo ("queue2main.asp");
                                                     }
    }
    
        
     //Assigns the onclick property of btnBack button    
    if ( document.getElementById('btnBackError2') != null )
    {
        document.getElementById('btnBackError2').onclick = function () 
                                                     { 
                                                        redirectTo ("queue2main.asp");
                                                     }
    }
    
    if ( document.getElementById('btnBackError3') != null )
    {
        document.getElementById('btnBackError3').onclick = function () 
                                                     { 
                                                        redirectTo ("queue2main.asp");
                                                     }
    }
}

function initEmailFromHitlistAndQueue(toFieldIsRequiredErrMsg, docgrpname, docgrpid)
{
    needToConfirm = false;
    
    emailErrMsg = toFieldIsRequiredErrMsg;
    
    window_onload(docgrpname,docgrpid);
    
}

function initEditAndIndex(invalidDateErrMsg, invalidNumErrMsg, invalidEntryMsg, reqFieldMsg)
{
    dateErrMsg = invalidDateErrMsg;
    numErrMsg = invalidNumErrMsg;
    entryMsg = invalidEntryMsg;
    reqFieldErrMsg = reqFieldMsg;
    
    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); 
                                                        }
    }
    
    //Assigns the onclick property of btnBack button    
    if ( document.getElementById('btnBack') != null )
    {
        document.getElementById('btnBack').onclick = function () 
                                                     { 
                                                        needToConfirm = false;
                                                        window.history.back();
                                                     }
    }

    //Assigns the onclick property of btnBack button    
    if ( document.getElementById('btnBack2') != null )
    {
        document.getElementById('btnBack2').onclick = function () 
                                                     { 
                                                        redirectTo ("queue2main.asp");
                                                     }
    }
    
    //Assigns the onclick property of btnBack button    
    if ( document.getElementById('btnBackEdit') != null )
    {
        needToConfirm = false;

        document.getElementById('btnBackEdit').onclick = function () { window.history.back() }
    }
        
    
    if ( document.getElementsByName('linkHintlist') != null )
    { 
        var frmName = "";
        
        if ( parent.location.href.match("edit") )
            frmName = "frmEdit";
        else
            frmName = "frmIndex";
        
        var links = document.getElementsByName('linkHintlist');
        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(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(frmName, strTxtObjName,strColumnName, 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()
{

    //Assigns the onclick property of btnBackError button    
    if ( document.getElementById('btnBackError') != null )
    {
        document.getElementById('btnBackError').onclick = function () 
                                                     { 
                                                        redirectTo ("queue2main.asp");
                                                     }
    }
    
    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()
{

   //Assigns the onclick property of btnBackError button    
    if ( document.getElementById('btnBackError') != null )
    {
        document.getElementById('btnBackError').onclick = function () 
                                                     { 
                                                        redirectTo ("queue2main.asp");
                                                     }
    }
    
    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";
    }
        
       
	//Issue 3684: Added a Back button so user would be able to go back
	//to the reserved items page.
    document.getElementById('btnBack').onclick = function () { needToConfirm = false; window.history.back() } 
    
    if (  document.getElementById("btnCopy") != null )
    {        
        document.getElementById("btnCopy").onclick = function () 
                                                            { 
                                                                needToConfirm = false;
                                                                document.getElementById('frmCopyTo').submit();
                                                            }
    }         
    

}

function initQueueUpload(noFileToUploadErrMsg)
{
    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 () 
                                                            { 
                                                                needToConfirm = false;

                                                                var s, ndx, fn;
                                                                s = queueUploadDoc.getElementById('Filedata').value;
                                                    	        
                                                                if (s.length==0) 
                                                                {
	                                                                alert(noFileToUploadErrMsg);
	                                                                
	                                                                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;
	                                                                }
	                                                                
	                                                                return true;
                                                                }
                                                            }
	     
     }
}

function IsStringNumeric(input) {
    return (input - 0) == input && input.length > 0;
}

function TrimString(s) {
    var l = 0; var r = s.length - 1;
    while (l < s.length && s[l] == ' ')
    { l++; }
    while (r > l && s[r] == ' ')
    { r -= 1; }
    return s.substring(l, r + 1);
}

function initQueueContents(deleteConfirmMsg)
{
    delConfirmMsg = deleteConfirmMsg;
    
    if ( parent.document.getElementById("queue2contents").contentDocument )
        queueContentsDoc = parent.document.getElementById("queue2contents").contentDocument;
    else
        queueContentsDoc = parent.document.frames["queue2contents"].document;
        
     if (queueContentsDoc) {

         if (queueContentsDoc.getElementsByName('linkQueuePage') != null) {
             links = queueContentsDoc.getElementsByName('linkQueuePage');
             for (var i = 0; i < links.length; i++) {
                 links[i].href = "#"
                 links[i].onclick = function () {
                     needToConfirm = false; //needs to be deleted?
                     var pageNumber = this.id;
                     queueContentsDoc.location.href = "queue2contents.asp?pg=" + pageNumber;
                     needToConfirm = true; //not needed?
                 }
             }
         }

         if (queueContentsDoc.getElementById("buttonGoToPage") != null) {

             queueContentsDoc.getElementById("buttonGoToPage").onclick = function () {
                 needToConfirm = false;

                 var pageNumber = parseInt(queueContentsDoc.getElementById("txtGoToPage").value);
                 var lastPage = parseInt(queueContentsDoc.getElementById("hidTotalPage").value);
                 var strValuePageNumber = queueContentsDoc.getElementById("txtGoToPage").value;

                 strValuePageNumber = TrimString(strValuePageNumber);
                 if (pageNumber > lastPage || pageNumber < 1 || strValuePageNumber == "" || IsStringNumeric(strValuePageNumber) == false) {
                     alert("Page number entered invalid.");
                     return;
                 }

                 queueContentsDoc.location.href = "queue2contents.asp?pg=" + pageNumber;
                 needToConfirm = true;

             };
         }         


        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 , 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(delConfirmMsg + " '" + 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 = "docserver.asp?qfilename=" + queueContentsDoc.getElementsByName('linkViewFile')[i].id + "&d=1";
                }                                                                 
            }
        }
    }
}


function initQuery(invalidDateErrMsg, invalidNumErrMsg, invalidEntryMsg)
{
    dateErrMsg = invalidDateErrMsg;
    numErrMsg = invalidNumErrMsg;
    entryMsg = invalidEntryMsg;
    
    needToConfirm = false;
    
    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('linkHintlist') != null )
    { 
        var links = queryDoc.getElementsByName('linkHintlist');
        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(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("frmQuery", strTxtObjName,strColumnName, 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") }
        }
       
       if (  toolbarDoc.getElementById("linkresetpassword") != null )
       { 
            toolbarDoc.getElementById("linkresetpassword").href="#"
            toolbarDoc.getElementById("linkresetpassword").onclick=function() { redirectTo("resetpassword.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="+encodeURI(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()
                                                                 {
                                                                    redirectTo("docserver.asp?rdocid=" + this.id + "&d=1");
                                                                    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(msgPageNumberEnteredInvalid, msgDeleteselected)
{
    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(msgDeleteselected))
                                                                  {
                                                                    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 ()
                                  {
                                        var docid = this.id.split("_")[0]
                                        var sessid= this.id.split("_")[1]
                                        arrWindow[index++] = window.open ("docserver.asp?docid=" + docid + "&s="+sessid,"_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 = "docserver.asp?docid=" + hitlistDoc.getElementsByName('linkIdDownload')[i].id + "&d=1"
                
                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]
                                                    
                                                    arrWindow[index++] = window.open ('summary.asp?docid=' + docid + '&grpid=' + grpid+ '&startexp=1&s=' + sid,"_blank", 
                                                                        "status=1,toolbar=0,scrollbars=0,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;
                                    var sortByHTML= hitlistDoc.getElementById("hidSort").value.split("_")[0];
                                    
                                    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 )
    {
        //checks the current page of the hitlist then sets the
		//checkallrecords accordingly
        var currPage = hitlistDoc.getElementById("currPage").value
        if (currPage == "")
        {
            currPage = 1;
            oldPage = 1;
         
        }
        if (currPage != oldPage)
        {
            hitlistDoc.getElementById("checkallrecords").checked = false;
            checkflag = false;
            oldPage = currPage;
        }
        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;
                                                                        
                                                                    }

                                                                };
    }

    if (hitlistDoc.getElementById("buttonGoToPage") != null )
    {
                                                                
        hitlistDoc.getElementById("buttonGoToPage").onclick = function () 
                                                                {
                                                                    needToConfirm = false;
                                                                    
                                                                    var pageNumber = parseInt(hitlistDoc.getElementById("txtGoToPage").value);
                                                                    
                                                                    var sortByHTML= hitlistDoc.getElementById("hidSort").value.split("_")[0];
                                                                    var lastPage= parseInt(hitlistDoc.getElementById("hidSort").value.split("_")[1]);
                                                                    
                                                                    if ( isNaN(pageNumber) || pageNumber > lastPage || pageNumber < 1  )
                                                                    {
                                                                        alert(msgPageNumberEnteredInvalid);
                                                                        return;
                                                                    }
                                                                    
                                                                    hitlistDoc.location.href = "hitlist2.asp?pg=" + pageNumber + sortByHTML + "&forceallrecords=1&requeryafterupdate=1";
                                                                    
                                                                    needToConfirm = 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 initLogin()
{
    if ( document.getElementById('frmLogin') != null )
    {
        document.getElementById("btnLogin").onclick = function () 
                                                        { 
                                                            needToConfirm = false;
                                                            document.getElementById('frmLogin').submit();
                                                            
                                                        }
        
    }
}

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?s=' + sid,'spyWin', 'width=100,height=100,left=4000,top=0,status=1');
}

function replaceStyleRule(styleClass, oldCssAttribute, newCssAttribute, length) 
{
    var cssRules = document.all ? "rules" : "cssRules";
    var cssText;

    styleSheet = document.styleSheets[0];
    
    for (var j = 0; j < styleSheet[cssRules].length; j++ )
    {
        
        if ( document.all )
        {   
            cssText = styleSheet[cssRules][j].selectorText;

            if (styleClass.match(cssText) != null)
		    {
                var newLength
                newLength = length * WIDTH;

                if ( styleClass.match("login") && length < MAXCHARLENGTH ) 
                    styleSheet[cssRules][j].style.width = "88 px"; 
                else
                {
                    styleSheet[cssRules][j].style.width = newLength.toString() + " px"; 
                    styleSheet.addRule(cssText, newCssAttribute[0] + "; " + newCssAttribute[1]);
                }
                
				break;
		    }	        
        }
        else
        {
            cssText = styleSheet[cssRules][j].cssText;
            
            if ( styleClass.match(".btn_login") ) 
            {
                if ( newCssAttribute != null )
                {
                    if ( length < 10 )
                        cssText = cssText.replace("{", "{width: 88px;");
                    else
                        cssText = cssText.replace("{", "{" + newCssAttribute[0] + newCssAttribute[1] );
	            }
	            else
	                cssText = "";

	            styleSheet.deleteRule(j);
                styleSheet.insertRule(cssText, j);
                
                break;
	        }
	        else
	        {
	            if (cssText.match(styleClass) != null && cssText.match(oldCssAttribute) != null)
	            {
                    if ( newCssAttribute != null )
                    {
                        cssText = cssText.replace(oldCssAttribute, newCssAttribute[0] + newCssAttribute[1] );
	                }
	                else
	                    cssText = "";
	                    
	                styleSheet.deleteRule(j);
                    styleSheet.insertRule(cssText, j);
    	     
	                break;
	            }
	        }
        }
    }

	
    styleSheet = null;

}

// a generic date validator function
function isvaliddate(ctlname, ctlcaption, ctlvalue, frmName){
	if (String(ctlvalue).length > 0){
	    
        var ctl, d;
	    d = checkIfValidDate(ctlvalue);
	    
        if ( d == null )
        {
            var message = dateErrMsg;
		    alert(message.replace("{0}",ctlcaption));
		    scrolltoview(ctlname, frmName);
		    return false;
	    }
	    
        ctlvalue = formatValidDate(d); 
        
	    ctl = eval("document."+frmName+"." + ctlname);
	    ctl.value = ctlvalue;
	}
	    
	return true;
}

function validateNumericField(sOjbName, frmName)
{
	var o, x;

	//  get reference to object
	o = eval("document."+frmName+"."+sOjbName); 
	if(!o){
	    var message = entryMsg; 
		alert(message.replace("{0}",sOjbName));
		return false;
		}

	if(o.value.length == 0) return true;

	x = parseFloat(o.value);

	if(isNaN(x)){
	    alert(numErrMsg);
		if(o.focus){//ie4+
			o.focus();
			if (o.select) 
				o.select();
			}
		else if (o.setfocus){//ns4+
			o.setfocus();
			}
		return false;
		}

	o.value = x;
	return true;
}

function scrolltoview (ctlname, frmName){
	var ctl;

	ctl = eval("document."+frmName+"." + ctlname);
	if (ctl.select)
		ctl.select();
	if (ctl.scrollIntoView)//scroll for IE
		ctl.scrollIntoView();
	ctl.focus();
}


// Generic validator (points user to element in error by scrolling the
// browser's view and highlighting entry if applicable)
function testcondition(ctlname, cond, caption, frmName){

	if (eval(cond)) {
		alert(reqFieldErrMsg.replace("{0}",caption));
		scrolltoview(ctlname, frmName);
		return true;
	}
	return false;
}


function frmUpload_onSubmit()
{
    var s, ndx, fn;
    s = document.getElementById('Filedata').value;

    if (s.length==0) 
    {
        alert(uploadErrMsg); 
        
        return false;
    } 
    else 
    {
        ndx = s.lastIndexOf("\\");
        if (ndx > -1){
            fn = s.substr(ndx + 1);
            document.getElementById('Filename').value = fn;
        } else {
            document.getElementById('Filename').value = s;
        }
        
        return true;
    }
}

function window_onload(docgrpname,docgrpid) {
    
	    if ( document.getElementById("txtSenderAddress") != null ) 
    {
	    if(document.getElementById("txtSenderAddress").setfocus) //ns
		    document.getElementById("txtSenderAddress").setfocus();
	    else if(document.getElementById("txtSenderAddress").focus) //ie4+
	    { 
		    document.getElementById("txtSenderAddress").focus(); //must have TABINDEX set for ie5+
		
		    if (document.getElementById("txtSenderAddress").select)
			    document.getElementById("txtSenderAddress").select();
        }    
    }

	initEmailHandler(docgrpname,docgrpid);
}

function frmEMail_onsubmit(){
	if (document.getElementById("txtRecipientAddress").value.length == 0){
		
	    alert(emailErrMsg);
	    
		if(document.getElementById("txtRecipientAddress").focus)
			document.getElementById("txtRecipientAddress").focus();
			
		return false;
	}
	
	return true;
		
}

