﻿//Created by Lokesh Goyal
//Modified by Vivek Sharma gratisaccount@gmail.com


var xml, idColumn, columns, gridBody, rowsInPage = 100, tr, txt, record, th, td, imgBtn, currentPageIndex = 0, lastPageIndex = 0, noOfRecords = 0;
var browserName = navigator.appName;


function trim(inputString) {
        // Removes leading and trailing spaces from the passed string. Also removes
        // consecutive spaces and replaces it with one space. If something besides
        // a string is passed in (null, custom object, etc.) then return the input.
        if (typeof inputString != "string") { return inputString; }
        var retValue = inputString;
        var ch = retValue.substring(0, 1);
        while (ch == " ") { // Check for spaces at the beginning of the string
            retValue = retValue.substring(1, retValue.length);
            ch = retValue.substring(0, 1);
        }
        ch = retValue.substring(retValue.length - 1, retValue.length);
        while (ch == " ") { // Check for spaces at the end of the string
            retValue = retValue.substring(0, retValue.length - 1);
            ch = retValue.substring(retValue.length - 1, retValue.length);
        }
        while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
            retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ") + 1, retValue.length); // Again, there are two spaces in each of the strings
        }
        return retValue; // Return the trimmed string back to the user
    }
    
// insertAdjacentHTML(), insertAdjacentText() and insertAdjacentElement()
// for Netscape 6/Mozilla by Thor Larholm me@jscript.dk
// Usage: include this code segment at the beginning of your document before any other Javascript contents.
if (typeof HTMLElement != "undefined" && !HTMLElement.prototype.insertAdjacentElement) {
    HTMLElement.prototype.insertAdjacentElement = function(where, parsedNode) {
        switch (where) {
            case 'beforeBegin':
                this.parentNode.insertBefore(parsedNode, this); break;
            case 'afterBegin':
                this.insertBefore(parsedNode, this.firstChild); break;
            case 'beforeEnd':
                this.appendChild(parsedNode); break;
            case 'afterEnd':
                if (this.nextSibling) this.parentNode.insertBefore(parsedNode, this.nextSibling);
                else this.parentNode.appendChild(parsedNode); break;
        }
    }

    HTMLElement.prototype.insertAdjacentHTML = function(where, htmlStr) {
        var r = this.ownerDocument.createRange();
        r.setStartBefore(this);
        var parsedHTML = r.createContextualFragment(htmlStr);
        this.insertAdjacentElement(where, parsedHTML);
    }

    HTMLElement.prototype.insertAdjacentText = function(where, txtStr) {
        var parsedText = document.createTextNode(txtStr)
        this.insertAdjacentElement(where, parsedText)
    }
}

    var ajx;
    var setHeight;
    function createAjax() // used to create ajax activeX object.
    {
        try {
            ajx = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e1) {
            try {
                ajx = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e2) {
                ajx = null;
            }
        }
        if (!ajx) {
            if (typeof XMLHttpRequest != "undefined") {
                ajx = new XMLHttpRequest();
            }
            else {
                ajx = null;
            }
        }
    }

    function request(url) // sends request to server and returns response data 
    {
        createAjax();
        url = url + "&rand=" + Math.floor(Math.random() * 100001);
        ajx.open("GET", url, false);
        ajx.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        ajx.send();
       
        return ajx.responseText;
    }

    function showTimer(){};
    
    var popupWin;

    function showPopup(obj, x, y, isCloseOnBlur) // shows any control as popup in new layer.
    {
        var layer = document.getElementById("dvOverLayer");
        layer.style.visibility = "visible";
        layer.style.display = "block";
        layer.style.height = window.screen.availHeight;
        popupWin = obj;
        var popup = document.getElementById(obj);
        popup.style.visibility = "visible";
        popup.style.display = "block";

        if (!x)
            x = (document.body.clientWidth / 2) - (popup.childNodes[0].offsetWidth / 2);
        if (!y)
            y = (document.body.clientHeight / 2) - (popup.childNodes[0].offsetHeight / 2);

        if (x + popup.offsetWidth > document.body.clientWidth)
            x = x - popup.offsetWidth;
        if (y + popup.offsetHeight > document.body.clientHeight)
            y = y - popup.offsetHeight;

        if (y < 0) {
            y = y + (popup.offsetHeight / 2)
        }


        popup.style.left = x;
        popup.style.top = y;

        if (isCloseOnBlur) {
            layer.onclick = hidePopup;
        }
        else
            layer.detachEvent("onclick", hidePopup);
    }

    function hidePopup(obj, noLayer) // hides popup control
    {
        if (!noLayer) {
            if (!obj)
                obj = popupWin;
            var layer = document.getElementById("dvOverLayer");
            layer.style.visibility = "hidden";
            layer.style.display = "none";
        }

        var popup = document.getElementById(obj);
        popup.style.visibility = "hidden";
        popup.style.display = "none";
    }

    function wait() {
        alert("Wait..");
        showPopup("dvLoading");
        //        setTimeOut("window.status='loading...';",1000);
    }

    function abortWait() {
        hidePopup("dvLoading");
    }

    function search1(sNo, grid, noMessage) //searches result by calling request function and binds result data using fillGrid function
    {
        if (!sNo) { currentPageIndex = 0, sNo = 1, lastPageIndex = 0; }
        if (!grid) grid = "searchGrid";
        grid = document.getElementById(grid);
        if (grid) {
            var hdnPage = document.getElementById('ctl00_ContentPlaceHolder1_hdnCurrentPage');
            var hdnTab = document.getElementById('ctl00_ContentPlaceHolder1_hdnCurrentTab');
            if (document.getElementById("SearchPrm"))
                var hdnprm = document.getElementById("SearchPrm").value;
            var params;
            if (hdnprm == null || hdnprm == '') {
                params = "page=" + hdnPage.value + "&schT=" + hdnTab.value + "&sNo=" + sNo;
            }
            else {
                params = "page=" + hdnPage.value + "&schT=" + hdnTab.value + "&sNo=" + sNo + "&sch=" + hdnprm;
            }


            if (grid.searchPrm)
                params += "&" + grid.searchPrm;

            if (grid.id == "searchGrid")
                grid.style.height = "";
            var rVal = fillGrid(grid, request("search.aspx?" + params), noMessage);
            if (grid.id == "searchGrid") {
                if (!rVal)
                    resetGridHeight();
                setGridHeight();
            }
            return rVal;
        }
        else
            return false;
    }

var xmlHTTP;
var randomNumber;
var customeMessage;
var IsSearchGrid;
var objGrid;
var returnValue = false;
var HideDivCommon;
var FillValue, dropDownListToFill, divCommon, SearchKeyWord;;



function CreateXMLHTTPObject()
{
 randomNumber=Math.floor(Math.random()*100001);
 try{xmlHTTP = new XMLHttpRequest();}catch(e){try{xmlHTTP = new ActiveXObject("Msxml2.XMLHTTP");}catch(e){try{xmlHTTP = new ActiveXObject("Microsoft.XMLHTTP");}catch(e){alert('Your browser does not support AJAX!');return false;}}}
 return xmlHTTP;
}

function GetXMLResponse_old(url)
{
 CreateXMLHTTPObject();
 xmlHTTP.onreadystatechange = AjaxHandleResponse;
 var fileSend=url+"&random="+randomNumber;
 if(customeMessage==true)
    xmlHTTP.open("GET",fileSend,false);
 else
    xmlHTTP.open("GET",fileSend,true);
    
 xmlHTTP.send(null);
}

function AjaxHandleResponse()
{
try
{
 if(xmlHTTP.readyState==4)
   {
    var divCommon=document.getElementById('divImageLoader');      
    var noMessage = customeMessage;
    if(xmlHTTP.status == 200)
      {
       returnValue = fillGrid(objGrid, xmlHTTP.responseText, noMessage);
       
       if(objGrid.id=="searchGrid")
       {
        if(!returnValue)
           resetGridHeight();
       }
       if(IsSearchGrid == true || IsSearchGrid == 'searchGrid' || HideDivCommon == false)
       {
          divCommon.style.display='none';
//          MainUnLoading();
       }
       }
    else
      {
       divCommon.innerHTML = 'There was a problem retrieving data from the server.';
       divCommon.style.display='block';
//       MainLoading();  
      }      
   }   
     }
     catch(e)
     {
        alert(e.massage)
     } 
}











function GetXMLResponse(url) {
    var fileSend = url + "&random=" + randomNumber;
    var $urlToSend = url + "&random=" + Math.floor(Math.random() * 100001);
    $(document).ready(function() {
        if (customeMessage == true)
            $IsRequestAsync = false;
        else
            $IsRequestAsync = true;
        $.ajax({
            type: "GET",
            url: "search.aspx",
            data: $urlToSend,
            dataType: "text/xml",
            async: $IsRequestAsync,
            success: function(data) {//xml) {
                var xml;
                try {
                    if (typeof data == 'string') {
                        xml = new ActiveXObject('Microsoft.XMLDOM');
                        xml.async = false;
                        xml.loadXML(data);
                    }
                }
                catch (e) { xml = data; }
                if (FillValue.indexOf('tblDHead') > 0) {
                    var ColumnName;
                    var i=0;
                    var html;                  
                    
                    SearchKeyWord = $(xml).find('columns').attr('rowIdColumn');
                    $(xml).find('columns').each(function() {
                        html = '<table id="tblHead" cellspacing="0" style="table-layout: auto; width:100%; height:100%;" class="tHeadMain"><tr>';
                        ColumnName = new Array(($(this).children().length)*2);
                        $(this).find('column').each(function(index) {
                             html += '<td style="width:'+$(this).attr('width')+';">' + $(this).attr('displayName') + '</td>';
                             ColumnName[i] = $(this).attr('name');i++;
                             ColumnName[i] = $(this).attr('width');i++;
                        });
                        html += '</tr></table>';
                        $('#divHead_' + FillValue).text('').append($(html));
                    });
                    html = '<table cellspacing="0" style="table-layout: auto; width:100%; height:100%;">';
                    $(xml).find('datatable').each(function(index) {
                        i=0;
                        html += '<tr class="trMain" id='+$(this).find(SearchKeyWord).text()+' onclick="searchDTA(this.id);">';
                        for (i=0; i<ColumnName.length; i+=2) {
                             html += '<td class="tdMain" style="width:'+ColumnName[i+1]+';">'+$(this).find(ColumnName[i]).text() +'</td>';
                        }
                        html += '</tr>';                                    
                    });
                    html += '</table>';
                    $('#divBody_' + FillValue).text('').append($(html));
                    ApplyTableCSS(FillValue);
                    divCommon.style.display = 'none';
                    MainUnLoading();
                }
                else if (FillValue.indexOf('tblCircular') > 0) {
                    $(xml).find('columns').each(function() {
                        var html = '<table cellspacing="0" style="table-layout: auto; width:100%;" class="tHeadMainGray"><tr>';
                        $(this).find('column').each(function(index) {
                            if (index == 0)
                                html += '<td style="width:80%;">' + $(this).attr('displayName') + '</td>';
                            else
                                html += '<td>' + $(this).attr('displayName') + '</td>';
                        });
                        html += '</tr></table>';
                        $('#divHead_' + FillValue).text('').append($(html));
                    });

                    $(xml).find('dssubjectsearch').each(function() {
                        html = '<table id="tblCircular" cellspacing="0" style="table-layout: auto; width:100%; vertical-align:top;">';
                        $(this).find('subjectsearch').each(function(index) {
                            if (index == 0)
                                $currentPageIndex = $(this).find('rowid').text();

                            html += '<tr id=tr' + index + ' onclick="SetSearchParam(this, false); return false;"><td style="width:80%;" id="' + $(this).find('notification').text() + '">' + $(this).find('notification').text() + '</td><td>' + $(this).find('circular_date').text() + '</td></tr>';

                        });
                        html += '</table>';
                        $('#divBody_' + FillValue).text('').append($(html));

                        ApplyTableCSS(FillValue);
                    });

                    var records_count = 0;
                    $(xml).find('recordsdatatable').each(function() {
                        records_count = $(this).find('records_number').text();
                    });
                    noOfRecords = parseInt(records_count, 10);

                    $('#' + FillValue + '_lblRecords').text(noOfRecords + " Records");
                    lastPageIndex = parseInt(noOfRecords / rowsInPage, 10);
                    if (noOfRecords % rowsInPage == 0)
                        lastPageIndex--;

                    $('#' + FillValue + '_txtGotoPage').attr('name', lastPageIndex + 1);
                    $currentPageIndex = parseInt($currentPageIndex / rowsInPage, 10);

                    if (noOfRecords > 0)
                        $('#' + FillValue + '_lblCurrentPage').text("[ " + parseInt($currentPageIndex + 1) + " / " + (lastPageIndex + 1) + " ] Pages");
                    else
                        $('#' + FillValue + '_lblCurrentPage').text("[ 0 / 0 ]");

                    var $btnName = FillValue.substring(0, FillValue.indexOf('tblCircular'));
                    if (noOfRecords <= 0 || lastPageIndex == 0) {
                        $('#' + $btnName + 'btnFirst').unbind("click").click(function() { return false; }).attr("src", "images/dis_first.gif");
                        $('#' + $btnName + 'btnPre').unbind("click").click(function() { return false; }).attr("src", "images/dis_pre.gif");
                        $('#' + $btnName + 'btnNext').unbind("click").click(function() { return false; }).attr("src", "images/dis_next.gif");
                        $('#' + $btnName + 'btnLast').unbind("click").click(function() { return false; }).attr("src", "images/dis_last.gif");
                    }
                    else if ($currentPageIndex == 0) {
                        $('#' + $btnName + 'btnFirst').unbind("click").click(function() { return false; }).attr("src", "images/dis_first.gif");
                        $('#' + $btnName + 'btnPre').unbind("click").click(function() { return false; }).attr("src", "images/dis_pre.gif");
                        $('#' + $btnName + 'btnNext').unbind("click").click(function() { search((parseInt($currentPageIndex + 1) * rowsInPage) + 1, "ACN_tblCircular", false); return false; }).attr("src", "images/next.gif");
                        $('#' + $btnName + 'btnLast').unbind("click").click(function() { search((lastPageIndex * rowsInPage) + 1, "ACN_tblCircular", false); return false; }).attr("src", "images/last.gif");
                    }
                    else if ($currentPageIndex == lastPageIndex) {
                        $('#' + $btnName + 'btnFirst').unbind("click").click(function() { search(0, "ACN_tblCircular", false); return false; }).attr("src", "images/first.gif");
                        $('#' + $btnName + 'btnPre').unbind("click").click(function() { search((parseInt($currentPageIndex - 1) * rowsInPage) + 1, "ACN_tblCircular", false); return false; }).attr("src", "images/pre.gif");
                        $('#' + $btnName + 'btnNext').unbind("click").click(function() { return false; }).attr("src", "images/dis_next.gif");
                        $('#' + $btnName + 'btnLast').unbind("click").click(function() { return false; }).attr("src", "images/dis_last.gif");
                    }
                    else {
                        $('#' + $btnName + 'btnFirst').unbind("click").click(function() { search(0, "ACN_tblCircular", false); return false; }).attr("src", "images/first.gif");
                        $('#' + $btnName + 'btnPre').unbind("click").click(function() { search((parseInt($currentPageIndex - 1) * rowsInPage) + 1, "ACN_tblCircular", false); return false; }).attr("src", "images/pre.gif");
                        $('#' + $btnName + 'btnNext').unbind("click").click(function() { search((parseInt($currentPageIndex + 1) * rowsInPage) + 1, "ACN_tblCircular", false); return false; }).attr("src", "images/next.gif");
                        $('#' + $btnName + 'btnLast').unbind("click").click(function() { search((lastPageIndex * rowsInPage) + 1, "ACN_tblCircular", false); return false; }).attr("src", "images/last.gif");
                    }

                    divCommon.style.display = 'none';
                    MainUnLoading();
                }
                else if (FillValue.indexOf('tblIOS') > 0) {
                    $(xml).find('columns').each(function() {
                        var html = '<table cellspacing="0" style="table-layout: auto; width:100%; height:100%;" class="tHeadMainGray"><tr>';
                        $(this).find('column').each(function() {
                            html += '<td>' + $(this).attr('displayName') + '</td>';
                        });
                        html += '</tr></table>';
                        $('#divHead_' + FillValue).text('').append($(html));
                    });

                    $(xml).find('dssubjectsearch').each(function() {
                        html = '<table id="tblIOS" cellspacing="0" style="table-layout: auto; width:100%;">';
                        $(this).find('subjectsearch').each(function(index) {
                            if (index == 0)
                                $currentPageIndex = $(this).find('rowid').text();

                            html += '<tr><td id="' + $(this).find('iosid').text() + '">' + $(this).find('iostext').text() + '</td></tr>';

                        });
                        html += '</table>';
                        $('#divBody_' + FillValue).text('').append($(html));

                        $('#tblIOS td').click(function() {
                            SetSearchParam(this, true);
                            return false;
                        });

                        ApplyTableCSS(FillValue);
                    });

                    var records_count = 0;
                    $(xml).find('recordsdatatable').each(function() {
                        records_count = $(this).find('records_number').text();
                    });
                    noOfRecords = parseInt(records_count, 10);

                    $('#' + FillValue + '_lblRecords').text(noOfRecords + " Records");
                    lastPageIndex = parseInt(noOfRecords / rowsInPage, 10);
                    if (noOfRecords % rowsInPage == 0)
                        lastPageIndex--;

                    $('#' + FillValue + '_txtGotoPage').attr('name', lastPageIndex + 1);
                    $currentPageIndex = parseInt($currentPageIndex / rowsInPage, 10);

                    if (noOfRecords > 0)
                        $('#' + FillValue + '_lblCurrentPage').text("[ " + parseInt($currentPageIndex + 1) + " / " + (lastPageIndex + 1) + " ] Pages");
                    else
                        $('#' + FillValue + '_lblCurrentPage').text("[ 0 / 0 ]");

                    var $btnName = FillValue.substring(0, FillValue.indexOf('tblIOS'));
                    if (noOfRecords <= 0 || lastPageIndex == 0) {
                        $('#' + $btnName + 'btnFirst').unbind("click").click(function() { return false; }).attr("src", "images/dis_first.gif");
                        $('#' + $btnName + 'btnPre').unbind("click").click(function() { return false; }).attr("src", "images/dis_pre.gif");
                        $('#' + $btnName + 'btnNext').unbind("click").click(function() { return false; }).attr("src", "images/dis_next.gif");
                        $('#' + $btnName + 'btnLast').unbind("click").click(function() { return false; }).attr("src", "images/dis_last.gif");
                    }
                    else if ($currentPageIndex == 0) {
                        $('#' + $btnName + 'btnFirst').unbind("click").click(function() { return false; }).attr("src", "images/dis_first.gif");
                        $('#' + $btnName + 'btnPre').unbind("click").click(function() { return false; }).attr("src", "images/dis_pre.gif");
                        $('#' + $btnName + 'btnNext').unbind("click").click(function() { search((parseInt($currentPageIndex + 1) * rowsInPage) + 1, "IOS_tblIOS", false); return false; }).attr("src", "images/next.gif");
                        $('#' + $btnName + 'btnLast').unbind("click").click(function() { search((lastPageIndex * rowsInPage) + 1, "IOS_tblIOS", false); return false; }).attr("src", "images/last.gif");
                    }
                    else if ($currentPageIndex == lastPageIndex) {
                        $('#' + $btnName + 'btnFirst').unbind("click").click(function() { search(0, "IOS_tblIOS", false); return false; }).attr("src", "images/first.gif");
                        $('#' + $btnName + 'btnPre').unbind("click").click(function() { search((parseInt($currentPageIndex - 1) * rowsInPage) + 1, "IOS_tblIOS", false); return false; }).attr("src", "images/pre.gif");
                        $('#' + $btnName + 'btnNext').unbind("click").click(function() { return false; }).attr("src", "images/dis_next.gif");
                        $('#' + $btnName + 'btnLast').unbind("click").click(function() { return false; }).attr("src", "images/dis_last.gif");
                    }
                    else {
                        $('#' + $btnName + 'btnFirst').unbind("click").click(function() { search(0, "IOS_tblIOS", false); return false; }).attr("src", "images/first.gif");
                        $('#' + $btnName + 'btnPre').unbind("click").click(function() { search((parseInt($currentPageIndex - 1) * rowsInPage) + 1, "IOS_tblIOS", false); return false; }).attr("src", "images/pre.gif");
                        $('#' + $btnName + 'btnNext').unbind("click").click(function() { search((parseInt($currentPageIndex + 1) * rowsInPage) + 1, "IOS_tblIOS", false); return false; }).attr("src", "images/next.gif");
                        $('#' + $btnName + 'btnLast').unbind("click").click(function() { search((lastPageIndex * rowsInPage) + 1, "IOS_tblIOS", false); return false; }).attr("src", "images/last.gif");
                    }

                    divCommon.style.display = 'none';
                    MainUnLoading();
                }
                else if (FillValue.indexOf('tblWords') > 0) {
                    $(xml).find('columns').each(function() {
                        var html = '<table cellspacing="0" style="table-layout: auto; width:100%; height:100%;" class="tHeadMainGray"><tr>';
                        $(this).find('column').each(function() {
                            html += '<td>' + $(this).attr('displayName') + '</td>';
                        });
                        html += '</tr></table>';
                        $('#divHead_' + FillValue).text('').append($(html));
                    });

                    $(xml).find('dssubjectsearch').each(function() {
                        html = '<table id="tblWP" cellspacing="0" style="table-layout: auto; width:100%; height:100%;">';
                        $(this).find('subjectsearch').each(function(index) {
                            if (index == 0)
                                $currentPageIndex = $(this).find('rowid').text();

                            html += '<tr><td id="' + $(this).find('wpid').text() + '">' + $(this).find('wordphrasetext').text() + '</td></tr>';

                        });
                        html += '</table>';
                        $('#divBody_' + FillValue).text('').append($(html));

                        $('#tblWP td').click(function() {
                            SetSearchParam(this, true);
                            return false;
                        });

                        ApplyTableCSS(FillValue);
                    });

                    var records_count = 0;
                    $(xml).find('recordsdatatable').each(function() {
                        records_count = $(this).find('records_number').text();
                    });
                    noOfRecords = parseInt(records_count, 10);

                    $('#' + FillValue + '_lblRecords').text(noOfRecords + " Records");
                    lastPageIndex = parseInt(noOfRecords / rowsInPage, 10);
                    if (noOfRecords % rowsInPage == 0)
                        lastPageIndex--;

                    $('#' + FillValue + '_txtGotoPage').attr('name', lastPageIndex + 1);
                    $currentPageIndex = parseInt($currentPageIndex / rowsInPage, 10);

                    if (noOfRecords > 0)
                        $('#' + FillValue + '_lblCurrentPage').text("[ " + parseInt($currentPageIndex + 1) + " / " + (lastPageIndex + 1) + " ] Pages");
                    else
                        $('#' + FillValue + '_lblCurrentPage').text("[ 0 / 0 ]");

                    var $btnName = FillValue.substring(0, FillValue.indexOf('tblWords'));
                    if (noOfRecords <= 0 || lastPageIndex == 0) {
                        $('#' + $btnName + 'btnFirst').unbind("click").click(function() { return false; }).attr("src", "images/dis_first.gif");
                        $('#' + $btnName + 'btnPre').unbind("click").click(function() { return false; }).attr("src", "images/dis_pre.gif");
                        $('#' + $btnName + 'btnNext').unbind("click").click(function() { return false; }).attr("src", "images/dis_next.gif");
                        $('#' + $btnName + 'btnLast').unbind("click").click(function() { return false; }).attr("src", "images/dis_last.gif");
                    }
                    else if ($currentPageIndex == 0) {
                        $('#' + $btnName + 'btnFirst').unbind("click").click(function() { return false; }).attr("src", "images/dis_first.gif");
                        $('#' + $btnName + 'btnPre').unbind("click").click(function() { return false; }).attr("src", "images/dis_pre.gif");
                        $('#' + $btnName + 'btnNext').unbind("click").click(function() { search((parseInt($currentPageIndex + 1) * rowsInPage) + 1, "WP_tblWords", false); return false; }).attr("src", "images/next.gif");
                        $('#' + $btnName + 'btnLast').unbind("click").click(function() { search((lastPageIndex * rowsInPage) + 1, "WP_tblWords", false); return false; }).attr("src", "images/last.gif");
                    }
                    else if ($currentPageIndex == lastPageIndex) {
                        $('#' + $btnName + 'btnFirst').unbind("click").click(function() { search(0, "WP_tblWords", false); return false; }).attr("src", "images/first.gif");
                        $('#' + $btnName + 'btnPre').unbind("click").click(function() { search((parseInt($currentPageIndex - 1) * rowsInPage) + 1, "WP_tblWords", false); return false; }).attr("src", "images/pre.gif");
                        $('#' + $btnName + 'btnNext').unbind("click").click(function() { return false; }).attr("src", "images/dis_next.gif");
                        $('#' + $btnName + 'btnLast').unbind("click").click(function() { return false; }).attr("src", "images/dis_last.gif");
                    }
                    else {
                        $('#' + $btnName + 'btnFirst').unbind("click").click(function() { search(0, "WP_tblWords", false); return false; }).attr("src", "images/first.gif");
                        $('#' + $btnName + 'btnPre').unbind("click").click(function() { search((parseInt($currentPageIndex - 1) * rowsInPage) + 1, "WP_tblWords", false); return false; }).attr("src", "images/pre.gif");
                        $('#' + $btnName + 'btnNext').unbind("click").click(function() { search((parseInt($currentPageIndex + 1) * rowsInPage) + 1, "WP_tblWords", false); return false; }).attr("src", "images/next.gif");
                        $('#' + $btnName + 'btnLast').unbind("click").click(function() { search((lastPageIndex * rowsInPage) + 1, "WP_tblWords", false); return false; }).attr("src", "images/last.gif");
                    }

                    divCommon.style.display = 'none';
                    MainUnLoading();
                }
                else if (FillValue.indexOf('tblSubjects') > 0) {
                    $(xml).find('columns').each(function() {
                        var html = '<table cellspacing="0" style="table-layout: auto; width:100%;" class="tHeadMainGray"><tr>';
                        $(this).find('column').each(function() {
                            html += '<td>' + $(this).attr('displayName') + '</td>';
                        });
                        html += '</tr></table>';
                        $('#divHead_' + FillValue).text('').append($(html));
                    });

                    $(xml).find('dssubjectsearch').each(function() {
                        html = '<table cellspacing="0" style="table-layout: auto; width:100%;">';
                        $(this).find('subjectsearch').each(function(index) {
                            if (index == 0)
                                $currentPageIndex = $(this).find('rowid').text();

                            html += '<tr><td id=' + $(this).find('subjectid').text() + ' onclick="searchAD_SW(this)">' + $(this).find('subject').text() + '</td></tr>';
                        });
                        html += '</table>';
                        $('#divBody_' + FillValue).text('').append($(html));

                        ApplyTableCSS(FillValue);
                    });

                    var records_count = 0;
                    $(xml).find('recordsdatatable').each(function() {
                        records_count = $(this).find('records_number').text();
                    });
                    noOfRecords = parseInt(records_count, 10);

                    $('#' + FillValue + '_lblRecords').text(noOfRecords + " Records");
                    lastPageIndex = parseInt(noOfRecords / rowsInPage, 10);
                    if (noOfRecords % rowsInPage == 0)
                        lastPageIndex--;

                    $('#' + FillValue + '_txtGotoPage').attr('name', lastPageIndex + 1);
                    $currentPageIndex = parseInt($currentPageIndex / rowsInPage, 10);

                    if (noOfRecords > 0)
                        $('#' + FillValue + '_lblCurrentPage').text("[ " + parseInt($currentPageIndex + 1) + " / " + (lastPageIndex + 1) + " ] Pages");
                    else
                        $('#' + FillValue + '_lblCurrentPage').text("[ 0 / 0 ]");

                    var $btnName = FillValue.substring(0, FillValue.indexOf('tblSubjects'));
                    if (noOfRecords <= 0 || lastPageIndex == 0) {
                        $('#' + $btnName + 'btnFirst').unbind("click").click(function() { return false; }).attr("src", "images/dis_first.gif");
                        $('#' + $btnName + 'btnPre').unbind("click").click(function() { return false; }).attr("src", "images/dis_pre.gif");
                        $('#' + $btnName + 'btnNext').unbind("click").click(function() { return false; }).attr("src", "images/dis_next.gif");
                        $('#' + $btnName + 'btnLast').unbind("click").click(function() { return false; }).attr("src", "images/dis_last.gif");
                    }
                    else if ($currentPageIndex == 0) {
                        $('#' + $btnName + 'btnFirst').unbind("click").click(function() { return false; }).attr("src", "images/dis_first.gif");
                        $('#' + $btnName + 'btnPre').unbind("click").click(function() { return false; }).attr("src", "images/dis_pre.gif");
                        $('#' + $btnName + 'btnNext').unbind("click").click(function() { search((parseInt($currentPageIndex + 1) * rowsInPage) + 1, 'AD_SW_tblSubjects', false); return false; }).attr("src", "images/next.gif");
                        $('#' + $btnName + 'btnLast').unbind("click").click(function() { search((lastPageIndex * rowsInPage) + 1, 'AD_SW_tblSubjects', false); return false; }).attr("src", "images/last.gif");
                    }
                    else if ($currentPageIndex == lastPageIndex) {
                        $('#' + $btnName + 'btnFirst').unbind("click").click(function() { search(0, 'AD_SW_tblSubjects', false); return false; }).attr("src", "images/first.gif");
                        $('#' + $btnName + 'btnPre').unbind("click").click(function() { search((parseInt($currentPageIndex - 1) * rowsInPage) + 1, 'AD_SW_tblSubjects', false); return false; }).attr("src", "images/pre.gif");
                        $('#' + $btnName + 'btnNext').unbind("click").click(function() { return false; }).attr("src", "images/dis_next.gif");
                        $('#' + $btnName + 'btnLast').unbind("click").click(function() { return false; }).attr("src", "images/dis_last.gif");
                    }
                    else {
                        $('#' + $btnName + 'btnFirst').unbind("click").click(function() { search(0, 'AD_SW_tblSubjects', false); return false; }).attr("src", "images/first.gif");
                        $('#' + $btnName + 'btnPre').unbind("click").click(function() { search((parseInt($currentPageIndex - 1) * rowsInPage) + 1, 'AD_SW_tblSubjects', false); return false; }).attr("src", "images/pre.gif");
                        $('#' + $btnName + 'btnNext').unbind("click").click(function() { search((parseInt($currentPageIndex + 1) * rowsInPage) + 1, 'AD_SW_tblSubjects', false); return false; }).attr("src", "images/next.gif");
                        $('#' + $btnName + 'btnLast').unbind("click").click(function() { search((lastPageIndex * rowsInPage) + 1, 'AD_SW_tblSubjects', false); return false; }).attr("src", "images/last.gif");
                    }

                    divCommon.style.display = 'none';
                    MainUnLoading();
                }
                else if (FillValue == 'searchGrid' || FillValue == "FileOpenSearchGrid" || FillValue == "ART" || FillValue.indexOf('tblDHead') > 0) {
                    var $currentPageIndex;
                    if ($(xml).find('newdataset').length < 1) {
                        html = '<table cellspacing="0" style="table-layout: auto; width:100%; height:200px;"><tr class="trMain"><td style="text-align:center; vertical-align:top; padding-top:10px;" class="tdMain">No Result Found</td></tr></table>';
                        $('#gridBody').text('').append($(html));
                        returnValue = false;
                    }
                    else {
                        $(xml).find('newdataset').each(function() {
                            if ($(this).find('datatable').length < 1) {
                                html = '<table cellspacing="0" style="table-layout: auto; width:100%; height:200px;"><tr class="trMain"><td style="text-align:center; vertical-align:top; padding-top:10px;" class="tdMain">No Result Found</td></tr></table>';
                                $('#gridBody').text('').append($(html));
                                returnValue = false;
                            }
                            else {
                                var ColumnName;
                                var i=0;
                                SearchKeyWord = $(xml).find('columns').attr('rowIdColumn');
                                $(xml).find('columns').each(function() {
                                    var html = '<table id="tblHead" cellspacing="0" style="table-layout: auto; width:100%; height:100%;" class="tHeadMain"><tr>';
                                    ColumnName = new Array();//($(this).children().length)*2);
                                    $(this).find('column').each(function(index) {
//                                        if (index == 0){
//                                            if($(this).find('column').length == 1)
//                                                html += '<td style="width:'+$(this).attr('width')+';">' + $(this).attr('displayName') + '</td>';
//                                            else
//                                                html += '<td style="width:'+$(this).attr('width')+';">' + $(this).attr('displayName') + '</td>';
//                                        }
//                                        else
                                          if($(this).attr('width') != '0%') {
                                            html += '<td style="width:'+$(this).attr('width')+';">' + $(this).attr('displayName') + '</td>';
                                            ColumnName[i] = $(this).attr('width');i++;
                                            ColumnName[i] = $(this).attr('name');i++;
                                            ColumnName[i] = $(this).attr('type');i++;
                                            if (ColumnName[i-1] == "image"){
                                                ColumnName[i] = $(this).attr('path');i++;}
                                             else {
                                                ColumnName[i] = "no";i++;}
                                          }
                                    });
                                    html += '</tr></table>';
                                    $('#gridHead').text('').append($(html));
                                });
                                html = '<table cellspacing="0" style="table-layout: auto; width:100%; height:100%;">';
                                $(this).find('datatable').each(function(index) {
                                   if (index == 0)
                                       $currentPageIndex = $(this).find('rowid').text();
                                   /*if (FillValue == "ART") {
                                       i=0;
                                       html += '<tr class="trMain" id=cit' + $(this).find(SearchKeyWord).text() + ' onclick="openFile(' + "'" + $(this).find(SearchKeyWord).text() + "'" + ', ' + "'searchGrid'" + ')">';
                                       for (i=0; i<ColumnName.length; i+=4) {
                                            html += '<td class="tdMain" style="width:'+ColumnName[i]+';">'+$(this).find(ColumnName[i+1]).text() +'</td>';
                                       }
                                       html += '</tr>';
                                   }   
                                   else {*/
                                        if($(this).find('caseid').length>0){                                    
                                            html += '<tr class="trMain"><td style="width:80px; text-align:center;" class="tdMain" onclick=DisplayCitationSummary("' + $(this).find('caseid').text() + '")><img src="images/' + $(this).find('citationimage').text() + '" alt="Summary" style="cursor:hand;" /></td><td class="tdMain" id=cit' + $(this).find('rowid').text() + ' onclick="openFile(' + "'" + $(this).find('caseid').text() + "'" + ', ' + "'searchGrid'" + ')">' + $(this).find('display_citation').text() + '</td></tr>';
                                        }   
                                        else {
                                            //html += '<tr class="trMain"><td class="tdMain" id=cit' + $(this).find('rowid').text() + ' onclick="openFile(' + "'" + $(this).find('caseid').text() + "'" + ', ' + "'searchGrid'" + ')">' + $(this).find('display_citation').text() + '</td></tr>';                                     
                                             html += '<tr class="trMain" id=cit' + $(this).find(SearchKeyWord).text() + ' onclick="openFile(' + "'" + $(this).find(SearchKeyWord).text() + "'" + ', ' + "'searchGrid'" + ')">';
                                             for (i=0; i<ColumnName.length; i+=4) {
                                                  if(ColumnName[i+2] == "image")
                                                     html += '<td class="tdMain" style="width:'+ColumnName[i]+';"><img src="'+ColumnName[i+3]+$(this).find(ColumnName[i+1]).text() +'" /></td>';
                                                  else
                                                     html += '<td class="tdMain" style="width:'+ColumnName[i]+';">'+$(this).find(ColumnName[i+1]).text() +'</td>';
                                            }
                                            html += '</tr>';
                                        }
                                   /*} */                                   
                                });
                                html += '</table>';
                                
                                $('#gridBody').text('').append($(html));
                                ApplySearchGridCSS();
                                returnValue = true;
                            }
                        });
                    }
                    var records_count = 0;
                    $(xml).find('recordsdatatable').each(function() {
                        records_count = $(this).find('records_number').text();
                    });

                    ApplyNavigationButtonsSetting(records_count, $currentPageIndex);

                    divCommon.style.display = 'none';
                    MainUnLoading();
                }
                else if (FillValue == 'dropDownList') {
                    dropDownListToFill.options.length = 0;
                    var $valueField;
                    var $TextField;
                    $(xml).find('combofields').each(function() {
                        $valueField = $(this).attr('valuefield');
                        $TextField = $(this).attr('textfield');
                    });
                   $(xml).find('newdataset').each(function() {
                        $(this).find('ddldatalist').each(function() {
                            var opt = document.createElement("option");
                            dropDownListToFill.options.add(opt);
                            opt.text = $(this).find($TextField).text();
                            opt.value = $(this).find($valueField).text();
                        });
                    });
                }
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                //alert("error: <br /> " + XMLHttpRequest.responseText);
                divCommon.style.display = 'none';
                html += '<table cellspacing="0" style="table-layout: auto; width:100%; height:100%;"><tr class="trMain"><td style="text-align:center;" class="tdMain">Invalid server response. Please try agian after some time.</td></tr></table>';
                $('#gridBody').append($(html));
            }
        });
    });
}

function SetSearchParam(tdObject, IsTD) {
    if (IsTD == true) {
        document.getElementById("searchGrid").searchPrm = "rId=" + tdObject.id;
        search(0, 'searchGrid', false);
        document.getElementById("hdnPrm").value = "\"" + $('#' + tdObject.id).text() + "\"";
    }
    else {
        document.getElementById("searchGrid").searchPrm = "rId=" + $('#' + tdObject.id).children().attr('id');
        search(0, 'searchGrid', false);
        document.getElementById("hdnPrm").value = "\"" + $('#' + tdObject.id).children().text() + "\"";
    }
}

function ApplySearchGridCSS() {
    $('#gridBody tr').hover(function(index) {
        $(this).addClass('trOver');
    }, function() {
        $(this).removeClass('trOver');
    });

    $('#gridBody tr').click(function() {
        $('#gridBody tr').each(function() {
            $(this).removeClass('trClick');
        });
        $(this).removeClass('trOver').addClass('trClick');
    });
}

function ApplyTableCSS(FValue) {    
    $('#divBody_'+FValue + ' tr').hover(function(index) {
        $(this).addClass('trOverLigthSky');
    }, function() {
        $(this).removeClass('trOverLigthSky');
    });

    $('#divBody_'+FValue + ' tr').click(function() {
        $('#divBody_'+FValue + ' tr').each(function() {
            $(this).removeClass('trClickSky');
        });
        $(this).removeClass('trOverLigthSky').removeClass('trClickSky').addClass('trClickSky');
    });
}

function ApplyNavigationButtonsSetting(records_count, $currentPageIndex) {
    noOfRecords = parseInt(records_count, 10);
    $('#searchGrid_lblRecords').text(noOfRecords + " Records");
    lastPageIndex = parseInt(noOfRecords / rowsInPage, 10);
    if (noOfRecords % rowsInPage == 0)
        lastPageIndex--;
    
    $('#txtGotoPage').attr('name', lastPageIndex + 1);
    $currentPageIndex = parseInt($currentPageIndex / rowsInPage, 10);
    if (noOfRecords > 0){
        $('#searchGrid_lblCurrentPage').text("[ " + parseInt($currentPageIndex + 1) + " / " + (lastPageIndex + 1) + " ] Pages");
        try {
           var btnPrint= document.getElementById("btnPrint");
           if (btnPrint)
           btnPrint.disabled=false;
        }catch(e){}
    }
    else
    {   
        $('#searchGrid_lblCurrentPage').text("[ 0 / 0 ]");
        try {
            var btnPrint= document.getElementById("btnPrint");
           if (btnPrint)
           btnPrint.disabled=true;
        }catch(e){}
    }
    
    if (noOfRecords <= 0 || lastPageIndex == 0) {
        $('#btnFirst').unbind("click").click(function() { return false; }).attr("src", "images/dis_first.gif");
        $('#btnPre').unbind("click").click(function() { return false; }).attr("src", "images/dis_pre.gif");
        $('#btnNext').unbind("click").click(function() { return false; }).attr("src", "images/dis_next.gif");
        $('#btnLast').unbind("click").click(function() { return false; }).attr("src", "images/dis_last.gif");
    }
    else if ($currentPageIndex == 0) {
        $('#btnFirst').unbind("click").click(function() { return false; }).attr("src", "images/dis_first.gif");
        $('#btnPre').unbind("click").click(function() { return false; }).attr("src", "images/dis_pre.gif");
        $('#btnNext').unbind("click").click(function() { search((parseInt($currentPageIndex + 1) * rowsInPage) + 1, 'searchGrid', false); return false; }).attr("src", "images/next.gif");
        $('#btnLast').unbind("click").click(function() { search((lastPageIndex * rowsInPage) + 1, 'searchGrid', false); return false; }).attr("src", "images/last.gif");
    }
    else if ($currentPageIndex == lastPageIndex) {
        $('#btnFirst').unbind("click").click(function() { search(0, 'searchGrid', false); return false; }).attr("src", "images/first.gif");
        $('#btnPre').unbind("click").click(function() {search((parseInt($currentPageIndex - 1) * rowsInPage) + 1, 'searchGrid', false); return false; }).attr("src", "images/pre.gif");
        $('#btnNext').unbind("click").click(function() { return false; }).attr("src", "images/dis_next.gif");
        $('#btnLast').unbind("click").click(function() { return false; }).attr("src", "images/dis_last.gif");
    }
    else {
        $('#btnFirst').unbind("click").click(function() { search(0, 'searchGrid', false); return false; }).attr("src", "images/first.gif");
        $('#btnPre').unbind("click").click(function() { search((parseInt($currentPageIndex - 1) * rowsInPage) + 1, 'searchGrid', false);  return false; }).attr("src", "images/pre.gif");
        $('#btnNext').unbind("click").click(function() { search((parseInt($currentPageIndex + 1) * rowsInPage) + 1, 'searchGrid', false); return false; }).attr("src", "images/next.gif");
        $('#btnLast').unbind("click").click(function() { search((lastPageIndex * rowsInPage) + 1, 'searchGrid', false); return false; }).attr("src", "images/last.gif");
    }
}

function DisplayCitationSummary(CaseID) {
    var dvSum = document.getElementById("dvSum");
    if (dvSum) {
        var params = "";
        var hdnSch = document.getElementById('ctl00_ContentPlaceHolder1_hdnCurrentPage');
        try {
          var btnPrint= document.getElementById("btnPrint");
          var sUser;
          if (btnPrint) sUser="1"; else sUser="0";
        }catch(e){}
        params = "page=" + hdnSch.value + "&schT=sum&csId=" + CaseID + "&Type="+ sUser;
        var winHeight=600, winWidth=1000;
        window.open("CitationSummary.htm?" + params, "win_summaryPopup", "width=483px,height=438px,menubar=no,toolbar=no,addressbar=no,status=no,location=no,resizable=no,scrollbars=no,left=" + ((screen.width - (winWidth/2))/2) + ",top=" + ((screen.availHeight -winHeight)));
    }
    return false;
}


function searchSync(sNo, grid, noMessage) {
    search(sNo, grid, noMessage);
    return returnValue;
}
function searchSync_Old(sNo, grid, noMessage) {
    Search_Old(sNo, grid, noMessage);
    return returnValue;
    
}
function FixHeightOnClearButton() {
    divCommon = document.getElementById('divImageLoader');
    divCommon.innerHTML = '';
    divCommon.style.height = "280px";
    divCommon.style.display = 'block';
    MainLoading();
}
function MainLoading()
{
    var MainLoading1=document.getElementById("TblLoading");
    if (MainLoading1)
            MainLoading1.style.display='block';  
}
function MainUnLoading()
{
    var MainLoading1=document.getElementById("TblLoading");
    if (MainLoading1)
           MainLoading1.style.display='none';  
}
function search(sNo, grid, noMessage) //searches result by calling request function and binds result data using fillGrid function
{
try
{
    FillValue = 'searchGrid';
    if (!grid)
        IsSearchGrid = true;
    else
        IsSearchGrid = grid;

    MainLoading();
    if (!sNo) {currentPageIndex = 0; sNo = 1, lastPageIndex = 0; }
    
    if (!grid) grid = "searchGrid";
                                   
    if (IsSearchGrid == true || IsSearchGrid == 'searchGrid') {
        document.getElementById('gridHead').innerHTML = "";
        document.getElementById('gridBody').innerHTML = "";
        $('#searchGrid_lblRecords').text('');
        $('#searchGrid_lblCurrentPage').text('');

        $('#btnFirst').unbind("click").click(function() { return false; }).attr("src", "images/dis_first.gif");
        $('#btnPre').unbind("click").click(function() { return false; }).attr("src", "images/dis_pre.gif");
        $('#btnNext').unbind("click").click(function() { return false; }).attr("src", "images/dis_next.gif");
        $('#btnLast').unbind("click").click(function() { return false; }).attr("src", "images/dis_last.gif");
        
        divCommon = document.getElementById('divImageLoader');
        divCommon.innerHTML = "Loading...<img src='images/rotating_arrow.gif' style='border:0px;' alt='' />";
        divCommon.style.display = 'block';
        MainLoading();
    }
    else {
        if (IsSearchGrid == "FileOpenSearchGrid") {
            document.getElementById('gridHead').innerHTML = "";
            document.getElementById('gridBody').innerHTML = "";
            FillValue = grid;
            divCommon = document.getElementById('divImageLoader');
            divCommon.innerHTML = "Loading...<img src='images/rotating_arrow.gif' style='border:0px;' alt='' />";
            divCommon.style.display = 'block';
            MainLoading();
        }   
        else if(IsSearchGrid.indexOf('tblDHead') > 0) {
            FillValue = grid;
            divCommon = document.getElementById('divImageLoading_' + IsSearchGrid);
            divCommon.innerHTML = "Loading...<img src='images/rotating_arrow.gif' style='border:0px;' alt='' />";
            divCommon.style.display = 'block';    
            MainLoading();    
        }
        else if (IsSearchGrid.indexOf('tblSubjects') > 0) {
            FillValue = grid;
            divCommon = document.getElementById('divImageLoading_' + IsSearchGrid.substring(0, IsSearchGrid.indexOf('tblSubjects')) + 'tblSubjects');
            divCommon.innerHTML = "Loading...<img src='images/rotating_arrow.gif' style='border:0px;' alt='' />";
            divCommon.style.display = 'block';
            MainLoading();  
        }

        else if (IsSearchGrid.indexOf('tblWords') > 0) {
            FillValue = grid;
            divCommon = document.getElementById('divImageLoading_' + IsSearchGrid);
            divCommon.innerHTML = "Loading...<img src='images/rotating_arrow.gif' style='border:0px;' alt='' />";
            divCommon.style.display = 'block';
            MainLoading();  
        }
        else if (IsSearchGrid.indexOf('tblIOS') > 0) {
            FillValue = grid;
            divCommon = document.getElementById('divImageLoading_' + IsSearchGrid);
            divCommon.innerHTML = "Loading...<img src='images/rotating_arrow.gif' style='border:0px;' alt='' />";
            divCommon.style.display = 'block';
            MainLoading();  
        }
        else if (IsSearchGrid.indexOf('tblCircular') > 0) {
            FillValue = grid;
            divCommon = document.getElementById('divImageLoading_' + IsSearchGrid);
            divCommon.innerHTML = "Loading...<img src='images/rotating_arrow.gif' style='border:0px;' alt='' />";
            divCommon.style.display = 'block';
            MainLoading();  
        }
        else if (IsSearchGrid.indexOf('subTbl') == -1) {
            divCommon = document.getElementById('divImageLoader');
            divCommon.innerHTML = "<br />";
            divCommon.style.height = "120px";
            divCommon.style.display = 'block';
            MainLoading();  
        }
    }
    
    if(IsSearchGrid == "FileOpenSearchGrid")
        grid="searchGrid";
        
    grid = document.getElementById(grid);
    objGrid = grid;
    if (IsSearchGrid == true) {
        $('#gridHead').empty();
        $('#gridBody').empty();
        ////     try
        ////     {
        ////      removeAllChildNodes(grid.getElementsByTagName("table")[0].childNodes[0]);
        ////      removeAllChildNodes(grid.getElementsByTagName("table")[1].childNodes[0]);
        ////     }
        ////     catch(e){}
        //    try
        //    {
        //     document.getElementById(grid.id+"_lblRecords").innerText='';
        //     document.getElementById(grid.id+"_lblCurrentPage").innerText='';
        //     setBtnPagingState(grid,false,false);
        //    }
        //    catch(e){}
    }
    else {
        if(IsSearchGrid == "FileOpenSearchGrid") {
            $('#gridHead').empty();
            $('#gridBody').empty();
        }
        else if (IsSearchGrid.indexOf('subTbl') == -1) {
            //     try
            //     {
            //      var RemoveGridData = document.getElementById('searchGrid');
            //      removeAllChildNodes(RemoveGridData.getElementsByTagName("table")[0].childNodes[0]);
            //      removeAllChildNodes(RemoveGridData.getElementsByTagName("table")[1].childNodes[0]);
            //     }
            //     catch(e){alert(e);}
            //     try
            //     {
            //      document.getElementById(RemoveGridData.id+"_lblRecords").innerText='';
            //      document.getElementById(RemoveGridData.id+"_lblCurrentPage").innerText='';
            //      setBtnPagingState(RemoveGridData,false,false);
            //     }
            //     catch (e) { alert(e); }
            if((IsSearchGrid.indexOf('tblDHead')>0) || (IsSearchGrid.indexOf('tblSubjects') > 0) || (IsSearchGrid.indexOf('tblWords') > 0) || (IsSearchGrid.indexOf('tblIOS') > 0) || (IsSearchGrid.indexOf('tblCircular') > 0)) {
                $('#divHead_' + IsSearchGrid).empty();
                $('#divBody_' + IsSearchGrid).empty();
            }
            /*if (IsSearchGrid.indexOf('tblSubjects') > 0) {
                $('#divHead_' + IsSearchGrid).empty();
                $('#divBody_' + IsSearchGrid).empty();
            }
            if (IsSearchGrid.indexOf('tblWords') > 0) {
                $('#divHead_' + IsSearchGrid).empty();
                $('#divBody_' + IsSearchGrid).empty();
            }
            if (IsSearchGrid.indexOf('tblIOS') > 0) {
                $('#divHead_' + IsSearchGrid).empty();
                $('#divBody_' + IsSearchGrid).empty();
            }
            if (IsSearchGrid.indexOf('tblCircular') > 0) {
                $('#divHead_' + IsSearchGrid).empty();
                $('#divBody_' + IsSearchGrid).empty();
            }*/
        }
    }
    if (grid) {
        var hdnPage = document.getElementById('ctl00_ContentPlaceHolder1_hdnCurrentPage');
        var hdnTab = document.getElementById('ctl00_ContentPlaceHolder1_hdnCurrentTab');
        if (document.getElementById("SearchPrm"))
            var hdnprm = document.getElementById("SearchPrm").value;

        var params;
        if (hdnprm == null || hdnprm == '')
            params = "page=" + hdnPage.value + "&schT=" + hdnTab.value + "&sNo=" + sNo;
        else
            params = "page=" + hdnPage.value + "&schT=" + hdnTab.value + "&sNo=" + sNo + "&sch=" + hdnprm;
        if (grid.searchPrm)
            params += "&" + grid.searchPrm;
        if (grid.id == "searchGrid")
            grid.style.height = "";
        
        if(hdnPage.value == "ART")//(hdnTab.value == "AU")
           FillValue = hdnPage.value;//'AU';
           
        customeMessage = noMessage;
        //GetXMLResponse("search.aspx?" + params);
        GetXMLResponse(params);
    }
    else 
    {
            MainUnLoading();
            divCommon.style.display = 'none';
            return false;
    }
       
    }
    catch(e)
    {
        Search_Old(sNo, grid, noMessage);
    }
}
function Search_Old(sNo, grid, noMessage)
{
if(!grid)
    IsSearchGrid = true;
 else
    IsSearchGrid = grid;
 
 if(!sNo){currentPageIndex=0,sNo=1,lastPageIndex=0;}
 if(!grid) grid="searchGrid";
 if(IsSearchGrid == true || IsSearchGrid == 'searchGrid')
   {
    var divCommon=document.getElementById('divImageLoader');
        divCommon.innerHTML="Loading...<img src='images/rotating_arrow.gif' style='border:0px;' alt='' />";
        divCommon.style.display='block';
       // MainLoading();  
   }
else
   {
    if(IsSearchGrid.indexOf('subTbl')==-1)
    {
     var divCommon=document.getElementById('divImageLoader');
         divCommon.innerHTML="<br />";
         divCommon.style.height="120px";
         divCommon.style.display='block';
        // MainLoading();  
    }
   }
alert(grid);
 grid=document.getElementById(grid);
 objGrid=grid;
 if(IsSearchGrid == true)
   {
     try
     {
      removeAllChildNodes(grid.getElementsByTagName("table")[0].childNodes[0]);
      removeAllChildNodes(grid.getElementsByTagName("table")[1].childNodes[0]);
     }
     catch(e){}
    try
    {
     document.getElementById(grid.id+"_lblRecords").innerText='';
     document.getElementById(grid.id+"_lblCurrentPage").innerText='';
     setBtnPagingState(grid,false,false);
    }
    catch(e){}
   }
 else
   {
    if(IsSearchGrid.indexOf('subTbl')==-1)
    {
     try
     {
      var RemoveGridData = document.getElementById('searchGrid');
      removeAllChildNodes(RemoveGridData.getElementsByTagName("table")[0].childNodes[0]);
      removeAllChildNodes(RemoveGridData.getElementsByTagName("table")[1].childNodes[0]);
     }
     catch(e){}
     try
     {
      document.getElementById(RemoveGridData.id+"_lblRecords").innerText='';
      document.getElementById(RemoveGridData.id+"_lblCurrentPage").innerText='';
      setBtnPagingState(RemoveGridData,false,false);
     }
     catch(e){}
    }
   }
 if(grid)
 {
  var hdnPage=document.getElementById('ctl00_ContentPlaceHolder1_hdnCurrentPage');
  var hdnTab=document.getElementById('ctl00_ContentPlaceHolder1_hdnCurrentTab');
  if(document.getElementById("SearchPrm"))
     var hdnprm=document.getElementById("SearchPrm").value;
  
  var params;
  if(hdnprm==null||hdnprm=='')
     params="page="+hdnPage.value+"&schT="+hdnTab.value+"&sNo="+sNo;
  else
     params="page="+hdnPage.value+"&schT="+hdnTab.value+"&sNo="+sNo+"&sch="+hdnprm;
  
  if(grid.searchPrm)
     params+="&"+grid.searchPrm;
                
  if(grid.id=="searchGrid")
     grid.style.height="";
     
  customeMessage = noMessage;
  GetXMLResponse_old("search.aspx?"+params);
  alert("hello");
 }
 else
 {
  divCommon.style.display='none';
  return false;
 }
}
function IsValidInteger(evt,ToCheckEnterKey,txtGotoPage,searchGrid) {
    var charCode = (evt.which) ? evt.which : evt.keyCode;
    if (charCode > 47 && charCode < 58)
        return true;
    
    if (ToCheckEnterKey == true) {
        if (charCode == 13)
            SearchDataOnPageNumber(txtGotoPage,searchGrid);
    }
       
    //var browserName = navigator.appName;
    if (browserName == "Microsoft Internet Explorer")
        event.returnValue = null;
    if (browserName == "Netscape" && charCode == 8)
        return true;

    return false;
}

function SearchDataOnPageNumber(txtPage, grid) {
    txtPage = document.getElementById(txtPage);
    grid = document.getElementById(grid);

    if (grid && txtPage) {
        //var $MaxVal = parseInt($('#txtGotoPage').attr('name'));
        var $MaxVal = parseInt($('#'+txtPage.id).attr('name'));
        var $MinVal = 1;
        if (parseInt(txtPage.value) >= 1 && parseInt(txtPage.value) <= $MaxVal) {
            //search(((txtPage.value - 1) * rowsInPage) + 1, 'searchGrid', false);
            search(((txtPage.value - 1) * rowsInPage) + 1, grid.id, false);
            //return false;
        }
        else
            alert("Search Result or Page does not exists!");
    }
    else
        txtPage.value = "";

    return false;
}

function fillComboValues(srcCombo, comboToFill, searchType) {
    if (srcCombo && srcCombo != "")
        srcCombo = document.getElementById(srcCombo);
    if (comboToFill && comboToFill != "")
        comboToFill = document.getElementById(comboToFill);
    if (srcCombo && comboToFill && srcCombo.options && srcCombo.options.length > 0 && srcCombo.selectedIndex != -1) {
        if (srcCombo.options[srcCombo.selectedIndex].value && trim(srcCombo.options[srcCombo.selectedIndex].value).toUpperCase() != "OTHER ACTS") {
            dropDownListToFill = comboToFill;
            comboToFill.options.length = 0;
            var opt = document.createElement("option");
            comboToFill.options.add(opt);
            opt.text = "Loading...";
            opt.value = "All";

            var hdnPage = document.getElementById('ctl00_ContentPlaceHolder1_hdnCurrentPage');
            var params = "page=" + hdnPage.value;
            if (searchType)
                params += "&schT=" + searchType;

            params += "&srcVal=" + srcCombo.options[srcCombo.selectedIndex].value;
            FillValue = 'dropDownList';
            GetXMLResponse(params);
        }
        else {
            alert("Please select an act from OTHER ACTS.");
            srcCombo.options[0].selected = true;
            fillComboValues(comboToFill.id, searchType);
            return false;
        }
    }
    else
        return false;
}    
    //temporary variables for pertaining css class name of tr and td while mouse is moved on grid
    var tmpTrCsName, tmpTdCsName;

    //function for preventing context menu;
    document.oncontextmenu = function(){return false;}
    
    //this function allows selection only in textbox
    document.onselectstart=function()
    {
        if((document.selection && allowSelection(document.selection)) || (window.getSelection && allowSelection(window.getSelection())) )
            return true;
        else
            return false;
    }
    
    //returns whether selection is allowed or not in selection Element
    function allowSelection(objSelection) {
        if (objSelection && objSelection.createRange && objSelection.createRange().parentElement) {
            var selectionParent = objSelection.createRange().parentElement();
            if (selectionParent.tagName == "INPUT" && selectionParent.type == "text")
                return true;
        }
        return false;
    }
    
    //prevents refresh (F5)
    //-----------document.onkeydown=function(){if(event.keyCode==116){event.keyCode=0;return false;}}
    
    // binds click event to all menu items.
    function bindMenuEvents() {
        var menu = document.getElementById("DTL_Menu");
        if (menu) {
            var pWidth = menu.parentElement.offsetWidth;
            if (pWidth < menu.offsetWidth) {
                var mTbl = document.createElement("TABLE");
                mTbl.className = menu.className;
                mTbl.id = menu.id + "_1";
                menu.insertAdjacentElement("afterEnd", mTbl);
                var mTbody = document.createElement("TBODY");
                mTbl.appendChild(mTbody);
                var mTr = document.createElement("TR");
                mTbody.appendChild(mTr);
                menu.parentNode.parentNode.style.height = (menu.parentNode.parentNode.offsetHeight * 2) - 2;
                var mItem = document.elementFromPoint(pWidth + getLeft(menu.parentElement) - 5, getTop(menu) + 3);
                if (mItem) {
                    mItem = mItem.parentNode.parentNode.parentNode.parentNode;
                    var nextItem;
                    while (mItem) {
                        nextItem = mItem.nextSibling;
                        mTr.appendChild(mItem);
                        mItem = nextItem;
                    }
                }
            }
        }

        var menuContainer = document.getElementById("menuContainer");
        if (menuContainer) {
            var mItems = menuContainer.getElementsByTagName("A");
            for (i = 0; i < mItems.length; i++) {
                mItems[i].parentNode.attachEvent("onclick", mClick);
            }
        }
    }

    function getTop(obj) {
        var top = 0;
        while (obj.offsetParent) {
            top += obj.offsetTop;
            top -= obj.scrollTop;
            obj = obj.offsetParent;
        }
        return top;
    }

    function getLeft(obj) {
        var left = 0;
        while (obj.offsetParent) {
            left += obj.offsetLeft;
            left -= obj.scrollLeft;
            obj = obj.offsetParent;
        }
        return left;
    }

    // event handler for menu item click.
    function mClick() {
        var mItem;
        if (event.srcElement.tagName == "TD")
            mItem = event.srcElement.childNodes[0];
        else if (event.srcElement.tagName == "A")
            mItem = event.srcElement;
        event.cancelBubble = true;
        if (mItem && mItem.href && mItem.href != "" && mItem.href.lastIndexOf(",") != -1) {
            var ref = mItem.href.substring(mItem.href.lastIndexOf(",") + 1);
            if (ref && ref == "'exit')")
                window.close();
            if (ref != "'')" && ref != "'\\\\')" & ref != "'\\\\\\\\')") {
                ref = ref.substring(ref.lastIndexOf("|") + 1, ref.length - 2);
                var cLoc = document.URL;
                if (cLoc.lastIndexOf("/") != -1)
                    cLoc = cLoc.substring(cLoc.lastIndexOf("/") + 1);
                if (cLoc.lastIndexOf("?") != -1)
                    cLoc = cLoc.substring(0, cLoc.lastIndexOf("?"));
                var cPage = document.getElementById('ctl00_ContentPlaceHolder1_hdnCurrentPage').value;
                var cTab = document.getElementById('ctl00_ContentPlaceHolder1_hdnCurrentTab').value;
                var wPage = ref.substring(0, ref.indexOf("?"));
                var page = ref.substring(ref.indexOf("?page=") + 6, ref.indexOf("&"));
                var tabId = "", sTabId = "";
                if (ref.indexOf("sTabId=") != -1) {
                    tabId = ref.substring(ref.indexOf("TabId=") + 6, ref.lastIndexOf("&"));
                    sTabId = ref.substring(ref.indexOf("sTabId=") + 7);
                }
                else
                    tabId = ref.substring(ref.indexOf("TabId=") + 6);

                document.location = ref;
            }
        }
        return false;
    }

   function fillComboValues1(comboToFill, searchType) {
       //alert(comboToFill);
       var srcCombo = event.srcElement;
       if (comboToFill && comboToFill != "")
           comboToFill = document.getElementById(comboToFill);
       if (srcCombo && comboToFill && srcCombo.options && srcCombo.options.length > 0 && srcCombo.selectedIndex != -1) {
           if (srcCombo.options[srcCombo.selectedIndex].value && trim(srcCombo.options[srcCombo.selectedIndex].innerText).toUpperCase() != "OTHER ACTS") {
               var hdnPage = document.getElementById('ctl00_ContentPlaceHolder1_hdnCurrentPage');
               var params = "page=" + hdnPage.value;
               if (searchType)
                   params += "&schT=" + searchType;

               params += "&srcVal=" + srcCombo.options[srcCombo.selectedIndex].value;

               var xmlVal = request("search.aspx?" + params);
               clearCombo(comboToFill.id, true);
               var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
               xmlDoc.async = false;
               xmlDoc.loadXML(xmlVal);

               columns = xmlDoc.selectSingleNode("//ComboData/ComboFields");
               if (columns) {
                   var Rows = xmlDoc.selectNodes("//ComboData/NewDataSet/Table");
                   var Row, option, txt;
                   for (i = 0; i < Rows.length; i++) {
                       if (Rows[i]) {
                           Row = Rows[i];
                           option = document.createElement("OPTION");
                           comboToFill.options.add(option);
                           if (Row.selectSingleNode(columns.getAttribute("TextField"))) {
                               txt = Row.selectSingleNode(columns.getAttribute("TextField")).text;
                               if (txt == "") txt = " ";
                               option.innerText = txt;
                           }
                           if (Row.selectSingleNode(columns.getAttribute("ValueField"))) {
                               txt = Row.selectSingleNode(columns.getAttribute("ValueField")).text;
                               if (txt == "") txt = " ";
                               option.value = txt;
                           }
                       }
                   }
               }
           }
           else {
               alert("Please select an act from OTHER ACTS.");
               srcCombo.options[0].selected = true;
               fillComboValues(comboToFill.id, searchType);
               return false;
           }
       }
       else
           return false;
   }

//    var xml, idColumn, columns, gridBody, rowsInPage=100, tr, txt, record, th, td, imgBtn, currentPageIndex=0, lastPageIndex=0, noOfRecords=0;
    
// remove previous rows and fills new rows by using setData function in specific grid from xml
var objGridValue;
var objxmlDoc;
var objNoMessage;
function fillGrid(grid, xmlVal, noMessage) {
    objGridValue = grid;
    objNoMessage = noMessage;
    if (grid) {
        if (!window.ActiveXObject) {
            parser = new DOMParser();
            objxmlDoc = parser.parseFromString(xmlVal, "text/xml");
            returnValue = ReadXmlForNonIE();
        }
        else {//alert('For IE');
            objxmlDoc = new ActiveXObject("Microsoft.XMLDOM");
            objxmlDoc.async = false;
            objxmlDoc.loadXML(xmlVal);
            ReadXmlForIE(grid, objxmlDoc, noMessage);
        }
    }
    else {
        returnValue = false;
    }

    if (!returnValue && !noMessage)
        alert("No new result found!");
    return returnValue;
}

function ReadXmlForNonIE() {
}

function ReadXmlForIE(grid, xmlDoc, noMessage) {
    if (xmlDoc.readyState == 4) {
        var err = xmlDoc.selectSingleNode("//griddata/error");
        if (!err) {
            var gridHead = grid.getElementsByTagName("table")[0].childNodes[0];
            gridBody = grid.getElementsByTagName("table")[1].childNodes[0];
            removeAllChildNodes(gridHead);
            removeAllChildNodes(gridBody);

            gridBody.parentElement.setAttribute("selectedRowId", "");

            columns = xmlDoc.selectSingleNode("//griddata/columns");
            if (columns) {
                xml = xmlDoc.selectNodes("//griddata/NewDataSet/Table");
                if (grid.allowPaging == "true") {
                    noOfRecords = parseInt(xmlDoc.selectNodes("//griddata/NewDataSet/Table1")[0].childNodes[0].text, 10);
                    document.getElementById(grid.id + "_lblRecords").innerText = noOfRecords + " Records";
                    lastPageIndex = parseInt(noOfRecords / rowsInPage, 10);
                    if (noOfRecords % rowsInPage == 0)
                        lastPageIndex--;

                    grid.noOfRecords = noOfRecords;
                    grid.currentPageIndex = currentPageIndex;
                    if (noOfRecords > 0)
                        document.getElementById(grid.id + "_lblCurrentPage").innerText = "[ " + (currentPageIndex + 1) + " / " + (lastPageIndex + 1) + " ] Pages";
                    else
                        document.getElementById(grid.id + "_lblCurrentPage").innerText = "[ 0 / 0 ]";

                    if (noOfRecords <= 0 || lastPageIndex == 0)
                        setBtnPagingState(grid, false, false);
                    else if (currentPageIndex == 0)
                        setBtnPagingState(grid, false, true);
                    else if (currentPageIndex == lastPageIndex)
                        setBtnPagingState(grid, true, false);
                    else
                        setBtnPagingState(grid, true, true);

                    if (noOfRecords > 0 && grid.id == "searchGrid" && document.getElementById("btnPrint") != null)
                        imgBtn_setEnabled(document.getElementById("btnPrint"), true);
                    else {
                        if ((grid.id != "searchGrid" || noOfRecords == 0) && document.getElementById("btnPrint") != null) document.getElementById("btnPrint").style.visible = 'hidden';
                        else imgBtn_setEnabled(document.getElementById("btnPrint"), false);
                    }
                }

                if (xml && xml.length > 0) {
                    idColumn = columns.getAttribute("rowIdColumn");
                    columns = columns.selectNodes("column");

                    tr = document.createElement("tr");
                    for (c = 0; c < columns.length; c++) {
                        th = document.createElement("th");
                        th.innerText = columns[c].getAttribute("displayName");
                        th.style.width = columns[c].getAttribute("width")
                        if (columns[c].getAttribute("hidden") && columns[c].getAttribute("hidden") == "true") {
                            th.style.visibility = "hidden";
                            th.style.display = "none";
                        }
                        tr.insertAdjacentElement("beforeEnd", th);
                    }
                    tr.className = gridHead.parentElement.HEADER_CLASS;
                    gridHead.insertAdjacentElement("beforeEnd", tr);

                    var info = xmlDoc.selectSingleNode("//griddata/EventInfo");
                    if (info && info.getAttribute("NoDblClick") && info.getAttribute("NoDblClick") == "true")
                        gridBody.parentElement.noDblClick = true;
                    else
                        gridBody.parentElement.noDblClick = false;

                    info = xmlDoc.selectSingleNode("//griddata/OtherInfo");
                    if (info && info.getAttribute("HasSubGrid") && info.getAttribute("HasSubGrid") == "true") {
                        gridBody.parentElement.hasSubGrid = true;
                        info = xmlDoc.selectSingleNode("//griddata/SubGrid");
                        if (info && info.getAttribute("SearchPrm"))
                            gridBody.parentElement.SubGrid_SearchPrm = info.getAttribute("SearchPrm");
                    }
                    else
                        gridBody.parentElement.hasSubGrid = false;
                    //if(xml.length>0)
                    //{
                    if (gridBody.parentElement.isSubGrid && xml.length > 8) {
                        gridBody.parentElement.parentElement.style.overflowY = "scroll";
                        gridBody.parentElement.parentElement.style.height = "200px";
                    }
                    setData();
                    //setGridHeight();
                    if ((document.getElementById("searchGrid").style.height != null) && (document.getElementById("searchGrid").style.height != '')) {
                        var ReHeight = document.getElementById("searchGrid").style.height;
                        ReHeight = ReHeight.substring(0, ReHeight.indexOf("px"));
                        var uheight;
                        if (setHeight == 'Decrease')
                            uheight = parseInt(ReHeight) - 100;
                        else
                            uheight = parseInt(ReHeight) + 100;

                        if (ReHeight != null && ReHeight != '')
                            document.getElementById("searchGrid").style.height = uheight + "px";
                    }
                    //}
                    returnValue = true;
                }
                else {
                    //retVal=false;
                    returnValue = false;
                }
            }
            else {
                //retVal=false;
                returnValue = false;
            }
        }
        else {
            alert(err.text);
            returnValue = false;
            return false;
        }
    }
}
    
// navigate to specific page number of specific grid which is entered in GoTo page TextBox.
function goToPage(txtPage, grid) {
    txtPage = document.getElementById(txtPage);

    grid = document.getElementById(grid);
    if (grid && txtPage) {
        noOfRecords = parseInt(grid.noOfRecords, 10);
        currentPageIndex = parseInt(grid.currentPageIndex, 10);
        lastPageIndex = parseInt(noOfRecords / rowsInPage, 10);
        if (trim(txtPage.value) != "" && noOfRecords > 0 && parseInt(trim(txtPage.value), 10) <= lastPageIndex + 1 && parseInt(trim(txtPage.value), 10) > 0) {
            var prePageIndex = currentPageIndex;
            currentPageIndex = parseInt(trim(txtPage.value), 10) - 1;
            if (prePageIndex != currentPageIndex)
                search((currentPageIndex * rowsInPage) + 1, grid.id);
        }
        else
            alert("Search Result or Page does not exists!");
    }
    txtPage.value = "";
}
    
    // set xmlNodes as rows in grid and binds rowEvents by using attachRowEvent function
    function setData() {
        for (i = 0; i < xml.length; i++) {
            if (xml[i]) {
                record = xml[i];
                tr = document.createElement("tr");
                for (c = 0; c < columns.length; c++) {
                    td = document.createElement("td");

                    if (record.selectSingleNode(columns[c].getAttribute("name"))) {
                        txt = record.selectSingleNode(columns[c].getAttribute("name")).text;
                        if (trim(txt) == "") txt = " ";

                        if (columns[c].getAttribute("type") == "text") {
                            td.innerText = txt;
                        }
                        else if (columns[c].getAttribute("type") == "image") {
                            imgBtn = document.createElement("input");
                            imgBtn.type = "image";
                            if (columns[c].getAttribute("path"))
                                txt = columns[c].getAttribute("path") + txt;
                            imgBtn.src = "images/" + txt;
                            if (columns[c].getAttribute("alt"))
                                imgBtn.alt = columns[c].getAttribute("alt");
                            if (!(columns[c].getAttribute("noClick") && columns[c].getAttribute("noClick") == "true")) {
                                imgBtn.attachEvent("onclick", smallDisplay);
                                imgBtn.className = "imgBtn";
                            }
                            td.insertAdjacentElement("beforeEnd", imgBtn);
                            td.align = "center";
                        }
                    }
                    else
                        td.innerText = " ";

                    td.style.width = columns[c].getAttribute("width");
                    if (columns[c].getAttribute("hidden") && columns[c].getAttribute("hidden") == "true") {
                        td.style.visibility = "hidden";
                        td.style.display = "none";
                    }
                    
                    td.className = gridBody.parentElement.TD_CLASS;
                    tr.insertAdjacentElement("beforeEnd", td);
                }
                if(record.selectSingleNode(idColumn))
                    tr.setAttribute("id", record.selectSingleNode(idColumn).text);

                tr.className = gridBody.parentElement.TR_CLASS;

                gridBody.insertAdjacentElement("beforeEnd", tr);
                attachRowEvents(tr);
            }
            else
                break;
        }
    }

    // binds all row events to specific row.
    function attachRowEvents(row) {
        row.onmouseover = rowMouseOver;
        row.onmouseout = rowMouseOut;
        row.onclick = rowClick;
        if (!row.parentElement.parentElement.noDblClick)
            row.ondblclick = rowDblClick;
    }
    
    // event handler for mouseOver event of row
    function rowMouseOver() {
        tmpTrCsName = this.className;
        tmpTdCsName = this.childNodes[0].className;
        this.className = this.parentElement.parentElement.TR_MOUSEOVER_CLASS;
        if (this.parentElement.parentElement.TD_MOUSEOVER_CLASS) {
            for (i = 0; i < this.childNodes.length; i++)
                this.childNodes[i].className = this.parentElement.parentElement.TD_MOUSEOVER_CLASS;
        }
    }

    // event handler for mouseOut event of row
    function rowMouseOut() {
        this.className = tmpTrCsName;
        for (i = 0; i < this.childNodes.length; i++)
            this.childNodes[i].className = tmpTdCsName;
    }
    
    // event handler for click event of row
    function rowClick() {
        var selectedRow = this.parentElement.parentElement.selectedRowId;
        if (selectedRow && (selectedRow != "")) {
            selectedRow = document.getElementById(selectedRow);
            if (selectedRow) {
                selectedRow.className = this.parentElement.parentElement.TR_CLASS;
                for (i = 0; i < selectedRow.childNodes.length; i++)
                    selectedRow.childNodes[i].className = this.parentElement.parentElement.TD_CLASS;
            }
        }
        this.parentElement.parentElement.selectedRowId = this.id;
        this.className = this.parentElement.parentElement.TR_CLICK_CLASS;
        if (this.parentElement.parentElement.TD_CLICK_CLASS) {
            for (i = 0; i < this.childNodes.length; i++)
                this.childNodes[i].className = this.parentElement.parentElement.TD_CLICK_CLASS;
        }
        tmpTrCsName = this.className;
        tmpTdCsName = this.childNodes[0].className;

        //        if(this.parentElement.parentElement.hasSubGrid)
        //            subGrid(this);
    }

    function subGrid(parentRow) {
        var sTr = document.getElementById("subTr_" + parentRow.id);
        setHeight = '';
        if (!sTr) {
            var nTr = document.createElement("TR");
            nTr.style.visibility = "hidden";
            nTr.style.display = "none";
            parentRow.insertAdjacentElement("afterEnd", nTr);
            nTr.id = "subTr_" + parentRow.id;
            var nTd = document.createElement("TD");
            nTr.insertAdjacentElement("beforeEnd", nTd);
            nTd.colSpan = "5";
            nTd.style.paddingLeft = "50px";
            nTd.style.backgroundColor = "white";
            var subTbl_id = "subTbl_" + parentRow.id;
            var innerElements = "<table id='" + subTbl_id + "' cellspacing='0' allowPaging='false' searchPrm='pId=" + parentRow.id;
            if (parentRow.parentElement.parentElement.SubGrid_SearchPrm)
                innerElements += "&" + parentRow.parentElement.parentElement.SubGrid_SearchPrm;

            if (document.getElementById('ctl00_ContentPlaceHolder1_hdnCurrentPage').value == "FINA") {
                var ts = searchFINA(true);
                if (ts && trim(ts) != "")
                    innerElements += "&" + ts;
            }

            innerElements += "'><tr><td><table id='" + subTbl_id + "_Head' cellspacing='0' style='table-layout: fixed' HEADER_CLASS='tHeadMainGray'><thead></thead></table></td></tr><tr style='height:100%'><td><div id='abc' style='height: 100%;border:solid 1px #EEEDE5'>";
            innerElements += "<table id='" + subTbl_id + "_Body' width='98.2%' cellspacing='0' style='table-layout: fixed' cellpadding='3' TR_CLASS='' TD_CLASS='' TR_MOUSEOVER_CLASS='trOverLigthSky' TD_MOUSEOVER_CLASS='tdOverLightSky' TR_CLICK_CLASS='trClickSky' TD_CLICK_CLASS='tdClickSky' isSmallGrid='true' isSubGrid='true'>";
            innerElements += "<tbody></tbody></table></div></td></tr></table>";
            nTd.insertAdjacentHTML("beforeEnd", innerElements);
            //search(null, subTbl_id, true);
            Search_Old(null, subTbl_id, true);
            if (returnValue == true)//if(search(null,subTbl_id,true))
            {
                nTr.style.visibility = "visible";
                nTr.style.display = "block";
                // --------------------------------------For increase height of Main search grid 16June2009------------------------------------------------
                //                var searchHeight=document.getElementById("searchGrid").style.height;                
                //                searchHeight=searchHeight.substring(0,searchHeight.indexOf("px"));
                //               document.getElementById("searchGrid").style.height=parseInt(document.getElementById(subTbl_id).offsetHeight)+parseInt(searchHeight)+"px";
                //-----------------------------------------------------------------------------------------------------------------------------------------

            }
            else {
                nTr.parentElement.removeChild(nTr);
                parentRow.noSubGrid = true;
                openFile(parentRow.childNodes[0].innerText);
            }
        }
        else if (sTr.style.visibility == "visible") {
            // --------------------------------------For Decrease height of Main search grid 16June2009------------------------------------------------
            //                var searchHeight=document.getElementById("searchGrid").style.height;
            //                          
            //                searchHeight=searchHeight.substring(0,searchHeight.indexOf("px"));
            //               
            //                if(parseInt(searchHeight)>parseInt(sTr.offsetHeight))
            //                document.getElementById("searchGrid").style.height=parseInt(searchHeight)-parseInt(sTr.offsetHeight)+"px";
            //-----------------------------------------------------------------------------------------------------------------------------------------

            if ((document.getElementById("searchGrid").style.height > null) && (document.getElementById("searchGrid").style.height != '')) {
                var ReHeight = document.getElementById("searchGrid").style.height;
                ReHeight = ReHeight.substring(0, ReHeight.indexOf("px"));
                var uheight;
                uheight = parseInt(ReHeight);
                if (uheight > 100) {
                    uheight = parseInt(ReHeight) - 100;
                    document.getElementById("searchGrid").style.height = uheight + "px";
                }
            }


            sTr.style.visibility = "hidden";
            sTr.style.display = "none";
        }
        else {
            sTr.style.visibility = "visible";
            sTr.style.display = "block";
        }
    }
    
    // event handler for doubleClick event of row
    function rowDblClick() {
        if (this.parentElement.parentElement.isSmallGrid && !this.parentElement.parentElement.isSubGrid) {
            var hdnPage = document.getElementById('ctl00_ContentPlaceHolder1_hdnCurrentPage');
            var hdnTab = document.getElementById('ctl00_ContentPlaceHolder1_hdnCurrentTab');
            if (hdnPage.value == "SCHC" || hdnPage.value == "ITAT" || hdnPage.value == "AAR") {
                if (hdnTab.value == "ADSW")
                    searchAD_SW(this);
                else if (hdnTab.value == "WP" || hdnTab.value == "IOS" || hdnTab.value == "ACN") {
                    document.getElementById("searchGrid").searchPrm = "rId=" + this.id;
                    if (search()) {
                        document.getElementById("hdnPrm").value = "\"" + this.childNodes[0].innerText + "\"";
                    }
                }
            }
            else if (hdnPage.value == "FINA") {
                if (hdnTab.value == "FIN")
                    searchFINA(this.id);
            }
            else if (hdnPage.value == "DSCH") {
                searchDSCH(this.id, this.childNodes[1].innerText, this.childNodes[2].innerText, this.childNodes[3].innerText, this.childNodes[4].innerText, this.childNodes[5].innerText, this.childNodes[6].innerText,this.childNodes[0].innerText);
            }
            else if (hdnPage.value == "DTA")
                searchDTA(this.id);
        }
        else if (this.parentElement.parentElement.hasSubGrid) {
           subGrid(this);
        }
        else {
            openFile(this.id);
        }
    }

    function openFile(rowId, grid) {
        if (!rowId) {
            if (this && this.id) rowId = this.id;
            else if (event.srcElement && event.srcElement.parentElement && event.srcElement.parentElement.id) rowId = event.srcElement.parentElement.id;
            else rowId = "";
        }
        if (!grid) grid = "searchGrid";
        grid = document.getElementById(grid);
        if (grid) {
            var hdnPage = document.getElementById('ctl00_ContentPlaceHolder1_hdnCurrentPage');
            var hdnTab = document.getElementById('ctl00_ContentPlaceHolder1_hdnCurrentTab');
            var page = "";

            if (hdnPage && hdnPage.value == "FOpen" && rowId != "") {
                page = addOrReplaceAttrib(document.URL, "csId", rowId);
            }
            else {
                var params = "";
                if (grid.searchPrm) page = grid.searchPrm;
                if (hdnPage.value == "DSCH") {
                    if (hdnTab.value == "DSCL")
                        params = "page=CASELAWS&schT=";
                    else
                        params = "page=" + getAttribValue(page, "pgType") + "&schT=" + getAttribValue(page, "schType");
                }
                else
                    params = "page=" + hdnPage.value + "&schT=" + hdnTab.value;

                params += "&csId=" + rowId;

                if (page != "")
                    params += "&" + page;
                    
                page = "File_opener.aspx";
                page += "?" + params;
            }

            var heading = "Taxmann - Direct Tax Laws";
            var row;
            try {
                //Added by Vikram For Title Display On File Opener
                row = document.getElementById(rowId);
                if (row.childNodes[1].innerText) {
                    heading = row.childNodes[1].innerText;
                }
            } catch (e) { }
            //---------------------------------------------//                    
            if (hdnPage.value == "SCHC" || hdnPage.value == "ITAT" || hdnPage.value == "AAR" || (hdnPage.value == "DSCH" && getAttribValue(page, "page") == "CASELAWS")) {
                var row = document.getElementById(rowId);
                if (row) {
                    if (hdnTab.value == "ADSW" || hdnTab.value == "WP" || hdnTab.value == "IOS" || hdnTab.value == "ACN") {
                        var hdPrm = document.getElementById("hdnPrm");
                        if (hdPrm)
                            page += "&sch=" + hdPrm.value;
                    }

                    if (row.childNodes[1].innerText && row.childNodes[1].innerText.indexOf("[") != -1) {
                        heading = row.childNodes[1].innerText;
                        heading = heading.substring(heading.indexOf("["));
                        if (heading.lastIndexOf(")") != -1)
                            heading = heading.substring(0, heading.lastIndexOf(")") + 1);
                    }
                }
            }

            if (document.getElementById("SearchPrm"))
                var hdnprm = document.getElementById("SearchPrm").value;
            var params;

            if (hdnprm != null || hdnprm != '') {
                if (page.indexOf("sch=") == -1) {
                    page += "&sch=" + hdnprm;
                }
            }
            page += "&title=" + heading;
            //var winFilePopup = window.open(page, "win_" + rowId.replace(/-/g, ""), 'menubar=no,toolbar=no,location=no,resizable=yes,fullscreen=yes,addressbar=no');  //, width='+winWidth+'px,height='+winHeight+'px,left='+((screen.width/2)-(winWidth/2))+',top='+((screen.availHeight/2)-(winHeight/2)));
            window.open(page, "win_"+ rowId.replace(/-/g, ""), 'menubar=no,toolbar=no,location=no,resizable=yes,addressbar=no,scrollbars=yes');
        }
        else
            return false;
    }

    function addOrReplaceAttrib(url, attrib, val) {
        if (url && attrib && val && url != "" && attrib != "") {
            var urlNew = "";
            attrib += "=";
            if (url.indexOf(attrib) != -1) {
                var sIndex = url.indexOf(attrib);
                var lIndex = url.indexOf("&", sIndex);
                urlNew = url.substring(0, sIndex) + attrib + val;
                if (lIndex != -1)
                    urlNew += url.substring(lIndex);
            }
            else
                urlNew += "&" + attrib + val;
            return urlNew;
        }
        else
            return url;
    }

    function getAttribValue(url, attrib) {
        var val = "";
        if (url && attrib && url != "" && attrib != "") {
            attrib += "=";
            if (url.indexOf(attrib) != -1) {
                var sIndex = url.indexOf(attrib) + attrib.length;
                var lIndex = url.indexOf("&", sIndex);
                if (lIndex != -1)
                    val = url.substring(sIndex, lIndex);
                else
                    val = url.substring(sIndex);
            }
        }
        return val;
    }
    
    // navigate to next, previous, first, last page of specific grid
    function goTo(num, grid) {
        if (!grid) grid = "searchGrid";
        grid = document.getElementById(grid);
        if (grid) {
            noOfRecords = parseInt(grid.noOfRecords, 10);
            currentPageIndex = parseInt(grid.currentPageIndex, 10);
            lastPageIndex = parseInt(noOfRecords / rowsInPage, 10);
            if (noOfRecords % rowsInPage == 0)
                lastPageIndex--;
            if (noOfRecords > 0) {
                var prePageIndex = currentPageIndex;
                var sNo = 1;
                if (num == 1 && currentPageIndex + 1 <= lastPageIndex) {
                    currentPageIndex++;
                    sNo = (currentPageIndex * rowsInPage) + 1;
                }
                else if (num == -1 && currentPageIndex - 1 >= 0) {
                    currentPageIndex--;
                    sNo = (currentPageIndex * rowsInPage) + 1;
                }
                else if (num == -2) {
                    currentPageIndex = lastPageIndex;
                    sNo = (lastPageIndex * rowsInPage) + 1;
                }
                else if (num == 0)
                    currentPageIndex = 0;

                if (prePageIndex != currentPageIndex)
                    search(sNo, grid.id);
                else
                    alert("No page available!");
            }
            else
                alert("No Search Result!");
        }
        else
            alert("No grid found!");
        return false;
    }
    
    // deletes selectedRow from specific body of grid
    function delSelectedRow(table) {
        if (table && (table != "")) {
            if (browserName == 'Netscape') {
                $('#' + table + ' .trClickSky').remove();

                var $htmlRow = $('#' + table + ' tr').get();
                if ($htmlRow != '')
                    return true;
                else
                    return false;
            }
            else {
                table = document.getElementById(table);
                if (table && table.selectedRowId && document.getElementById(table.selectedRowId))
                    table.childNodes[0].removeChild(document.getElementById(table.selectedRowId));
            }
        }
    }
    
    // removes all childNodes from specific node (like removes all rows from body of grid or table)
    function removeAllChildNodes(node) {
        if (node && node.hasChildNodes && node.removeChild) {
            while (node.hasChildNodes()) {
                node.removeChild(node.firstChild);
            }
        }
    }
    //This function makes copy of the searchParameters to be used with paging
    function GetSearchCriterionForPaging() {
        return document.getElementById("hdnPrm").value; //.cloneNode(true);
    }
    //
    function setSearchParameters(sParam) {
        //document.getElementById("hdnPrm").value = sParam;

        document.getElementById("searchGrid").searchPrm = sParam;
    }
    // returns previous search result from search result grid (searchGrid).
    function getSearchData() {
        if (browserName == "Netscape") {
            var schGrid = document.getElementById("searchGrid").cloneNode(true);
            var records = $('#' + schGrid.id + '_lblRecords').text();
            var page = $('#' + schGrid.id + "_lblCurrentPage").text();
        }
        else {
            var schGrid = document.getElementById("searchGrid").cloneNode(true);
            var records = document.getElementById(schGrid.id + "_lblRecords").innerText;
            var page = document.getElementById(schGrid.id + "_lblCurrentPage").innerText;
        }
        return { grid: schGrid, records: records, page: page };
    }
    
    // sets search result data to search result grid (searchGrid).
    function setSearchData(data) {
        if (data) {
            var schGrid
            if (browserName == "Netscape") {
                schGrid = document.getElementById("searchGrid");
                $('#' + schGrid.id + '_lblRecords').text(data.records);
                $('#' + schGrid.id + '_lblCurrentPage').text(data.page);
                schGrid.parentNode.replaceChild(data.grid, schGrid);

                ApplySearchGridCSS();
                ApplyNavigationButtonsSetting(data.records.substring(0, data.records.indexOf(' Records')), ((parseInt(data.page.substring(2, data.page.indexOf('/'))) - 1) * 100) + 1);
            }
            else {
                schGrid = document.getElementById("searchGrid");
                schGrid.parentNode.replaceChild(data.grid, schGrid);
                document.getElementById(schGrid.id + "_lblRecords").innerText = data.records;
                document.getElementById(schGrid.id + "_lblCurrentPage").innerText = data.page;
                var gBody = data.grid.getElementsByTagName("table")[1].childNodes[0];
                for (i = 0; i < gBody.childNodes.length; i++)
                    attachRowEvents(gBody.childNodes[i]);
                setBtnPagingState(data.grid);
            }
        }
    }
    
    // clears all search result data from search result grid (searchGrid).
    function clearSearchGrid() {
        var schGrid = document.getElementById("searchGrid");
        schGrid.currentPageIndex = "0";
        schGrid.noOfRecords = "0";
        schGrid.searchPrm = "";
        try {
            removeAllChildNodes(schGrid.getElementsByTagName("table")[0].childNodes[0]);
            //gridHead=schGrid.getElementsByTagName("table")[0].childNodes[0];
            //removeAllChildNodes(gridHead);
        } catch (e) { }
        gridBody = schGrid.getElementsByTagName("table")[1].childNodes[0];
        if (gridBody.selectedRowId)
            gridBody.selectedRowId = "";
        removeAllChildNodes(gridBody);
        document.getElementById(schGrid.id + "_lblRecords").innerText = "";
        document.getElementById(schGrid.id + "_lblCurrentPage").innerText = "[ 0 / 0 ]";
        setBtnPagingState(schGrid, false, false);
    }
    function clearSearchResult() {
        var schGrid = document.getElementById("searchGrid");
        schGrid.searchPrm = "";
        $('#gridHead').empty();
        $('#gridBody').empty().append('<div style="height:200px">&nbsp;</div>');
        currentPageIndex = 0;
        noOfRecords = 0;
        sNo = 0;
        lastPageIndex = 0;
        $('#searchGrid_lblRecords').text(0);
        $('#searchGrid_lblCurrentPage').text("[ 0 / 0 ]");
        ApplyNavigationButtonsSetting(0, 0);
    }
    //returns number of rows of search result grid
    function getSearchRowCount() {
        return document.getElementById('gridBody').childNodes[0].childNodes.length;
    }
    
    // retrieves and displays summary of specific citation in popup dialog.
    function smallDisplay() {
        var dvSum = document.getElementById("dvSum");
        if (dvSum) {
            var params = "";
            var hdnSch = document.getElementById('ctl00_ContentPlaceHolder1_hdnCurrentPage');
            var source = event.srcElement.parentElement.parentElement;
            params = "page=" + hdnSch.value + "&schT=sum&csId=" + source.id;
            var xmlText = request("./search.aspx?" + params);

            var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
            xmlDoc.async = false;
            xmlDoc.loadXML(xmlText);
            var citationHeading = "";
            var root = xmlDoc.selectSingleNode("//griddata");
            if (root.hasChildNodes()) {
                if (root.selectSingleNode("display_citation")) {
                    document.getElementById("lblCitation").innerText = root.selectSingleNode("display_citation").text;
                    citationHeading = root.selectSingleNode("display_citation").text;
                }
                else {
                    document.getElementById("lblCitation").innerText = '';
                    citationHeading = '';
                }
                if (root.selectSingleNode("benchname"))
                    document.getElementById("txtCourt").value = root.selectSingleNode("benchname").text;
                else
                    document.getElementById("txtCourt").value = '';
                if (root.selectSingleNode("orderdate"))
                    document.getElementById("txtDate").value = root.selectSingleNode("orderdate").text;
                else
                    document.getElementById("txtDate").value = '';
                if (root.selectSingleNode("casename"))
                    document.getElementById("txtCaseName").value = root.selectSingleNode("casename").text;
                else
                    document.getElementById("txtCaseName").value = '';
                if (root.selectSingleNode("caseno"))
                    document.getElementById("txtCaseNo").value = root.selectSingleNode("caseno").text;
                else
                    document.getElementById("txtCaseNo").value = '';
                if (root.selectSingleNode("judges"))
                    document.getElementById("txtJudges").value = root.selectSingleNode("judges").text;
                else
                    document.getElementById("txtJudges").value = '';
                if (root.selectSingleNode("appellant"))
                    document.getElementById("txtApp").value = root.selectSingleNode("appellant").text;
                else
                    document.getElementById("txtApp").value = '';

                if (root.selectSingleNode("respondent"))
                    document.getElementById("txtRes").value = root.selectSingleNode("respondent").text;
                else
                    document.getElementById("txtRes").value = '';
                if (root.selectSingleNode("infavour"))
                    document.getElementById("txtFav").value = root.selectSingleNode("infavour").text;
                else
                    document.getElementById("txtFav").value = '';
                if (root.selectSingleNode("cocitation")) {
                    var el = document.getElementById("txtCoCit");
                    el.value = root.selectSingleNode("cocitation").text;
                    el.parentElement.parentElement.style.visibility = "visible";
                    el.parentElement.parentElement.style.display = "block";
                }
                else {
                    var el = document.getElementById("txtCoCit");
                    el.value = "";
                    el.parentElement.parentElement.style.visibility = "visible";
                    el.parentElement.parentElement.style.display = "block";
                }

                if (root.selectSingleNode("slptext")) {
                    var el = document.getElementById("txtSlp");
                    el.value = root.selectSingleNode("slptext").text;
                    el.parentElement.parentElement.style.visibility = "visible";
                    el.parentElement.parentElement.style.display = "block";
                }
                else {
                    var el = document.getElementById("txtSlp");
                    el.value = "";
                    el.parentElement.parentElement.style.visibility = "visible";
                    el.parentElement.parentElement.style.display = "block";
                }

                if (root.selectSingleNode("affres")) {
                    var el = document.getElementById("txtAffRev");
                    el.value = root.selectSingleNode("affres").text;
                    el.parentElement.parentElement.style.visibility = "visible";
                    el.parentElement.parentElement.style.display = "block";
                }
                else {
                    var el = document.getElementById("txtAffRev");
                    el.value = "";
                    el.parentElement.parentElement.style.visibility = "visible";
                    el.parentElement.parentElement.style.display = "block";
                }
                document.getElementById("txtHeadNote").innerText = '';
                if (root.selectSingleNode("headnotes")) {
                    var headTable = document.getElementById("tblHeadNotes").childNodes[0].childNodes[0];
                    removeAllChildNodes(headTable);
                    var headNotes = root.selectSingleNode("headnotes").selectNodes("headnote");
                    if (headNotes) {
                        if (headNotes.length > 4)
                            headTable.parentNode.parentNode.parentNode.style.overflowX = "scroll";
                        else
                            headTable.parentNode.parentNode.parentNode.style.overflowX = "hidden";

                        for (i = 0; i < headNotes.length; i++) {
                            var td = document.createElement("td");
                            var btn = document.createElement("input");
                            btn.type = "button";
                            btn.className = "btn";
                            btn.value = "headnote " + (i + 1);
                            btn.setAttribute("txt", headNotes[i].text);
                            //btn.onclick=function(){document.getElementById("txtHeadNote").innerText=this.txt;};
                            btn.onclick = "document.getElementById('txtHeadNote').innerText=this.txt";
                            td.appendChild(btn);
                            headTable.appendChild(td);
                            if (i == 0)
                                document.getElementById("txtHeadNote").innerText = headNotes[i].text;
                        }
                        if ((document.getElementById("txtHeadNote").innerText == '') || (document.getElementById("txtHeadNote").innerText == null))
                            document.getElementById("txtHeadNote").innerText = '';
                    }
                    else
                        document.getElementById("txtHeadNote").innerText = '';
                }
                else
                    document.getElementById("txtHeadNote").innerText = '';
            }
            //showPopup("dvSum", getLeft(event.srcElement)+(event.srcElement.offsetWidth/2), getTop(event.srcElement)+(event.srcElement.offsetHeight/2), true);
            var winHeight = 438, winWidth = 483;
            var winSummary = window.open("", "win_summaryPopup", "width=" + winWidth + "px,height=" + winHeight + "px,menubar=no,toolbar=no,addressbar=no,status=no,location=no,resizable=no,scrollbars=no,left=" + ((screen.width / 2) - (winWidth / 2)) + ",top=" + ((screen.availHeight / 2) - (winHeight / 2)));
            //var winSummary=window.showModelessDialog("",window,"status:false;dialogWidth:500px;dialogHeight:400px;help:no;status:no;");
            var winHtml = "<html><body style='margin: 0px 0px 0px 0px'><div id='dvSum' style='BORDER-RIGHT: #9cbbe9 4px solid; BORDER-TOP: #9cbbe9 4px solid; Z-INDEX: 16000; BORDER-LEFT: #9cbbe9 4px solid; WIDTH: 475px; BORDER-BOTTOM: #9cbbe9 4px solid; BACKGROUND-COLOR: #9cbbe9'>"
            if (winSummary) {
                winSummary.document.body.innerHTML = "";
                winSummary.document.write(winHtml + dvSum.innerHTML + "</div></body></html>");
                winSummary.document.title = citationHeading;
                winSummary.focus();
                //winSummary.document.body.innerHTML = winHtml+dvSum.innerHTML+"</div></body></html>";
            }
        }
        return false;
    }
    
    function IsEnterKeyPressed(btnName) {
        /*if (event.keyCode == 13) {
            if (event.srcElement.id == 'txtGotoPage') {
                var txtId = event.srcElement.id;
                var btnId = "btnGotoPage";
                if (txtId.lastIndexOf("_") != -1)
                    btnId = txtId.substring(0, txtId.lastIndexOf("_") + 1) + btnId;
                document.getElementById(btnId).fireEvent("onclick");
            }
            else {
                var btnID = 'ctl00_ContentPlaceHolder1_' + btnName;
                document.getElementById(btnID).fireEvent("onclick");
            }
            return false;
        }*/
    }
    
    // ensures that only numbers can be inserted in any textbox
    function IsNumberInput(txtBox) {
        var field = event.srcElement;
        var key, keyChar;
        if (window.event)
            key = window.event.keyCode;
        else if (event)
            key = event.which;
        else
            return true;

        if (event.type == 'keydown' && event.keyCode == 46) return true;

        if (event.keyCode == 13) {
            if (txtBox == 'btnGotoPage')//if(event.srcElement.id=='txtGotoPage')
            {
                var txtId = event.srcElement.id;
                var btnId = "btnGotoPage";
                if (txtId.lastIndexOf("_") != -1)
                    btnId = txtId.substring(0, txtId.lastIndexOf("_") + 1) + btnId;
                document.getElementById(btnId).fireEvent("onclick");
            }
            else {
                var btnID = 'ctl00_ContentPlaceHolder1_' + txtBox;
                document.getElementById(btnID).fireEvent("onclick");
            }
            return false;
        }

        if (event.keyCode == 35 || event.keyCode == 36 || event.keyCode == 37 || event.keyCode == 39 || event.keyCode == 9 || event.keyCode == 8)
            return true;

        if (event.type == 'keydown' && key == 109 && IsMinusExist(field) == false)
            return true;

        if (event.type == 'keydown' && key == 110 && IsDotExist(field) == false)
            return true;

        if (key == 45 && IsMinusExist(field) == false)
            return true;

        if (key == 46 && IsDotExist(field) == false)
            return true;

        if (event.type == 'keydown' && (event.keyCode >= 96 && event.keyCode <= 105)) return true;

        if (event.keyCode >= 48 && event.keyCode <= 57) return true;
        // Check to see if it's a number
        keyChar = String.fromCharCode(key);

        if (/\d/.test(keyChar)) {
            window.status = "";
            return true;
        }
        else {
            window.status = "Enter only numeric data.";
            return false;
        }
    }
    
    // returns eighter (.)dot is exists or not in specific textBox
    function IsDotExist(txt) {
        var v = new String(txt.value);
        var id = v.indexOf(".", 0);
        if (id == -1 && v.length > 0)
            return false;
        else
            return true;
    }
    
    // returns eighter (-)minus sign is exists or not in specific textBox
    function IsMinusExist(txt) {
        var v = new String(txt.value);
        var id = v.indexOf("-", 0);

        if (id == -1 && v.length == 0)
            return false;
        else
            return true;
    }
    
    // inserts increased number in corresponding textbox of first textbox of assessment year
    function increaseNum(evt,incObj) {
        if (document.getElementById(incObj)) {
            //var srcObj = event.srcElement;
            var srcObj;
            if (!window.event) {
                srcObj = evt.target;
            }
            else
                srcObj = event.srcElement;
            if (srcObj.value != "" && parseInt(srcObj.value, 10).toString().length == 4) {
                var yr1 = (parseInt(srcObj.value.substring(2), 10) + 1).toString();
                if (yr1.length > 2)
                    yr1 = yr1.substring(yr1.length - 2);
                else if (yr1.length < 2)
                    yr1 = "0" + yr1;
                document.getElementById(incObj).value = yr1;
            }
            else
                document.getElementById(incObj).value = "";
        }
    }
    
    // returns eigther year entered in specific textbox is valid or not
    function isValidYear(objYear) {
        if (objYear) {
            if (objYear.value.length == 0 || objYear.value.length == 4)
                return true;
            else {
                alert("Please enter valid year!");
                objYear.select();
                return false;
            }
        }
        else
            return false;
    }

    // removes all options from specific comboBox and hides it's parent row
    function clearCombo(objCombo, noHide) {
        var objCombo = document.getElementById(objCombo);
        if (objCombo) {
            /*while (objCombo.options.length > 0)
                objCombo.options.remove(0);*/
            objCombo.options.length = 0;
        }
        if (!noHide) {
            if (browserName == "Netscape") {
                if (objCombo.parentNode.parentNode && objCombo.parentNode.parentNode.tagName == "TR") {
                    objCombo.parentNode.parentNode.style.visibility = "hidden";
                    objCombo.parentNode.parentNode.style.display = "none";
                }
            }
            else {
                if (objCombo.parentElement.parentElement && objCombo.parentElement.parentElement.tagName == "TR") {
                    objCombo.parentElement.parentElement.style.visibility = "hidden";
                    objCombo.parentElement.parentElement.style.display = "none";
                }
            }
        }
    }

    // used for add a level in combobox while using level search
    function addLevel(objCombo, searchText, searchPrm) {
        if (searchText != "" && (!isItemExists(objCombo, searchText))) {
            var opt = document.createElement("option");
            objCombo.options.add(opt);
            opt.text = searchText;
            opt.value = searchPrm;
            //objCombo.style.width = "100";
            //if ((browserName == "Netscape") ? (objCombo.parentNode.parentNode && objCombo.parentNode.parentNode.tagName == "TR") : (objCombo.parentElement.parentElement && objCombo.parentElement.parentElement.tagName == "TR")) {
            if (browserName == "Netscape" || browserName == "Opera") {
                if (objCombo.parentNode.parentNode && objCombo.parentNode.parentNode.tagName == "TR") {
                    objCombo.parentNode.parentNode.style.visibility = "visible";
                    objCombo.parentNode.parentNode.style.display = "table-row";
                }
            }
            else {
                if (objCombo.parentElement.parentElement && objCombo.parentElement.parentElement.tagName == "TR") {
                    objCombo.parentElement.parentElement.style.visibility = "visible";
                    objCombo.parentElement.parentElement.style.display = "block";
                }
            }
            objCombo.selectedIndex = objCombo.options.length - 1;
        }
    }

    // used for getting eighter an item is exists in combo or not
    function isItemExists(objCombo, item) {
        try {
            if (objCombo) {
                for (i = 0; i < objCombo.options.length; i++) {
                    if (trim(objCombo.options[i].text).toUpperCase() == trim(item).toUpperCase()) {
                        objCombo.selectedIndex = i;
                        return true;
                    }
                }
            }

            return false;
        }
        catch (e) { alert(e); }
    }

    // used for level search while changing selectedIndex of level search combobox
    function levelSearch(evt,objSearch, btnGo) {
        var cmb;
        if (!window.event)
            cmb = evt.target;
        else
            cmb = event.srcElement;
        
        if (cmb.options.length > 0 && cmb.selectedIndex != -1) {
            //document.getElementById(objSearch).value = cmb.options[cmb.selectedIndex].innerText;
            document.getElementById(objSearch).value = cmb.options[cmb.selectedIndex].text;
            document.getElementById(btnGo).click();
        }
    }

    function levelSearchForRefresh(objSearch, objSearchcmb, btnGo) {
        //       var cmbSch=document.getElementById('ctl00_ContentPlaceHolder1_DSCH_CL_cmbSchLevel');
        var cmb = document.getElementById(objSearchcmb);
        if (cmb.options.length > 0 && cmb.selectedIndex != -1) {
            //document.getElementById(objSearch).value = cmb.options[cmb.selectedIndex].innerText;
            document.getElementById(objSearch).value = cmb.options[cmb.selectedIndex].text;
            document.getElementById(btnGo).click();
        }
    }


    function imgBtn_setEnabled(iBtn, enabled) {
        if (iBtn) {
            iBtn.disabled = !enabled;
            if (iBtn.src && iBtn.src != "") {
                var src = iBtn.src;
                if (!enabled) {
                    if (src.lastIndexOf("/dis_") == -1) {
                        if (src.lastIndexOf("/") != -1)
                            src = src.substring(0, src.lastIndexOf("/") + 1) + "dis_" + src.substring(src.lastIndexOf("/") + 1);
                        else
                            src = "dis_" + src;
                    }
                }
                else {
                    if (src.lastIndexOf("/dis_") != -1) {
                        if (src.lastIndexOf("/") != -1)
                            src = src.substring(0, src.lastIndexOf("/") + 1) + src.substring(src.lastIndexOf("/") + 5);
                        else
                            src = src.substring(4);
                    }
                }
                iBtn.src = src;
            }
        }
    }

    function setBtnPagingState(grid, enableFirst_Pre, enableNext_Last) {
        if (grid) {
            if (arguments.length == 3) {
                grid.btnPgFirst_enabled = enableFirst_Pre;
                grid.btnPgLast_enabled = enableNext_Last;
            }
            imgBtn_setEnabled(document.getElementById(grid.btnFirst), grid.btnPgFirst_enabled);
            imgBtn_setEnabled(document.getElementById(grid.btnPre), grid.btnPgFirst_enabled);
            imgBtn_setEnabled(document.getElementById(grid.btnNext), grid.btnPgLast_enabled);
            imgBtn_setEnabled(document.getElementById(grid.btnLast), grid.btnPgLast_enabled);
        }
    }

    function setUrl(e) {
        var obj;
        if (!window.event) {
            obj = e.target;
        }
        else
            obj = event.srcElement;
        
        var ref = obj.href + "?page=" + document.getElementById('ctl00_ContentPlaceHolder1_hdnCurrentPage').value + "&" + obj.id//obj.navPrm;
        
        document.location = ref;
        return false;
    }

    function setGridHeight() {
        var schGrd1 = document.getElementById("searchGrid");
        if (schGrd1) {
            var schGrd1Top = getTop(schGrd1);
            //            var pFoot=document.getElementById("tbl_PageFooter");
            var tblPages = document.getElementById("tblPages");

            var aHeight = document.body.clientHeight - schGrd1Top;
            //            if(pFoot)
            //                aHeight -= pFoot.offsetHeight;
            if (tblPages)
                aHeight -= tblPages.offsetHeight;
            if (schGrd1.offsetHeight < aHeight)
                schGrd1.style.height = aHeight;
        }
    }

    function resetGridHeight() {
        var schGrd1 = document.getElementById("searchGrid");
        if (schGrd1)
            schGrd1.style.height = 280;
    }

    function setFullScreen() {
        window.moveTo(0, 0);
        window.resizeTo(window.screen.availWidth, window.screen.availHeight);
    }
    function ReqForPDF(param) {
        createAjax();
        MainLoading();
        param = param + "&rand=" + Math.floor(Math.random() * 100001);
        ajx.onreadystatechange = HandleFileOpenRes;
        ajx.open("GET", "search.aspx?CRTPram=" + param, true);
        ajx.send(null);
    }
    function HandleFileOpenRes() {
        if (ajx.readyState == 4) {
            if (ajx.status == 200) {
                var qStrToSend = ajx.responseText;
                if (qStrToSend.indexOf("<") != -1) {
                    qStrToSend = qStrToSend.substring(0, qStrToSend.indexOf("<"));
                }
                else {
                    qStrToSend = qStrToSend;
                }
                 MainUnLoading();
//                var isOpen = window.open("file_opener.aspx?page=Forms&fname=" + qStrToSend);
                var isOpen = window.open("DisplayPDF.aspx");
                if (isOpen == null) {
                    alert("Please check your pop-up blocker settings,It may be on." + '\n' + "Turn off your pop-up Blocker");
                }
                var loadimage = document.getElementById("LoadingTD");
                var imgbtn = document.getElementById("ImageButton2");
                if (loadimage != null && imgbtn != null) {
                    loadimage.style.display = "none";
                    imgbtn.disabled = false;
                }
                if (loadimage != null) {
                    loadimage.style.display = "none";
                }
            }
        }
    }
    