﻿ // JScript File
 var focus_control = "search"; // search is the default focus control // when the login box pops up, we set it as the default focus control
 
 function alterWidth()
 {
    checkRight();
    if(Exists('RightNavVis')){
        if(document.getElementById('RightNavVis').value == ''){
            //document.getElementById('xToolbarSpace').setAttribute('ColumnSpan', '3');
            //document.getElementById('ctl00_RightNav_Control_PnlMaster').style.width = '0';
            //document.getElementById('<%=PnlBodyContent.ClientID %>' + '_PnlBodyContent').parentElement.style.width = '';
        } else {
            //document.getElementById('xToolbarSpace').setAttribute('ColumnSpan', '4');
            //document.getElementById('ctl00_RightNav_Control_PnlMaster').style.width = '160px';
            if(Exists('ConArea')){
                if(window.clientInformation.appVersion.indexOf('MSIE 5.5') != -1){
                    document.getElementById('ConArea').style.width = '540px';
                    //winWidth = 540;
                } else if(window.clientInformation.appVersion.indexOf('MSIE 6.0') != -1){
                    document.getElementById('ConArea').style.width = '595px';
                    //winWidth = 570;
                }
            };
        };
    };
    
 };

function checkRight(){
    if(Exists('RightDiv')){
        var iRight = document.getElementById('RightDiv');
        if(iRight.firstChild.innerHTML == ''){
            //document.getElementById('xToolbarSpace').setAttribute('ColumnSpan', '3');
            document.getElementById('RightDiv').style.width = '0';
            document.getElementById('RightDiv').style.display = 'none';
            document.getElementById('RightNavVis').value = '';
        } else {
            //document.getElementById('xToolbarSpace').setAttribute('ColumnSpan', '4');
            document.getElementById('RightDiv').style.width = '160px';
            document.getElementById('RightDiv').style.display = 'block';
            document.getElementById('RightNavVis').value = 'true';
        };
    };
 };
 
var ExpandStateString = "";

function checkKey(e){
    
//    if(window.clientInformation.userAgent.indexOf("MSIE") == -1)
//        /*Added by Roy on 1st July 2009 to fix 'Bug ID:420', this will only happen in non-ie browsers, and relies on the search text field named 'query0'*/
//        /*i.e., if the user is in this field and clicked Enter let it go through to the cotnrol*/        
//        var strCurrentField = e.srcElement.id;//Current field id
//        
//        if(strCurrentField.indexOf('query0')>= 0)
//        {
//            if(e.keyCode == 13){
//                return false;
//            };
//        }
//        /*Added by Roy to fix 'Bug ID:420', this will only happen in non-ie browsers, and relies on the search text field named 'query0'*/
//    };
}    
function cursor_wait() {
    document.body.style.cursor = 'wait';
}

function cursor_clear() {
    document.body.style.cursor = 'default';
}

function IsParentNode(strIdentifier)
{
    if (strIdentifier == "e" || strIdentifier == "c" || strIdentifier == "u")
        return true;
    else
        return false;
}

function GetParentByTagName(parentTagName, childElementObj)
{
    var parent = childElementObj.parentNode;
    while(parent.tagName.toLowerCase() != parentTagName.toLowerCase())
    {
        parent = parent.parentNode;
    }
    return parent;
}

function SaveBrowseTreeExpandState(treeViewId)
{
    if (treeViewId != "")
    {
        var BrowseTrees = new Array();
        var treeView = null;
        var ExpandStateString = "";
        
        BrowseTrees = treeViewId.split(';');
        
        for (var i = 0; i < BrowseTrees.length; i++)
        {
            treeView = document.getElementById(BrowseTrees[i]);
            if(treeView)
            {
                if (document.getElementById(BrowseTrees[i]+"_ExpandState"))
                {
                    ExpandStateString += document.getElementById(BrowseTrees[i]+"_ExpandState").value + "|";
                }
            }
        }
        
        document.cookie = "ExpandStateString=" + ExpandStateString + ";";
    }
 }
 
 function GetCookieValue(CookieName)
 {
    if (document.cookie.length > 0) {
        if (document.cookie.indexOf(CookieName) != -1) {
            var Cookies = document.cookie.split(';');
            for (var j = 0; j < Cookies.length; j++) {
                var Cookie = Cookies[j].split('=');
                if (Cookie[0] == CookieName) {
                    return Cookie[1];
                }
            } return "";
        } else return "";
    } else return "";
 }

function ShowProgess(ProgressText)
{
    if(document.getElementById("divProgress") != null)
    {
        document.body.removeChild(document.getElementById("divProgress"));
    };
    
    var rDiv = document.createElement('DIV');
    rDiv.id = 'divProgress';
    rDiv.style.position = 'absolute';
    rDiv.style.left = '0px';
    rDiv.style.top = '0px';
    var iDiv = document.createElement('DIV');
    iDiv.style.position = 'absolute';
    iDiv.style.left = '0px';
    iDiv.style.top = '0px';
    iDiv.style.width = window.screen.availWidth;
    iDiv.style.height = window.screen.availHeight;
    iDiv.style.background = '#D3D3D3';
    iDiv.style.zIndex = '2000';
    iDiv.style.filter = 'progid:DXImageTransform.Microsoft.BasicImage(opacity=.3)';
    rDiv.appendChild(iDiv);
    var sDiv = document.createElement('DIV');
    sDiv.style.position = 'absolute';
    sDiv.style.left = (parseInt(window.screen.availWidth)/2)-200 + 'px';
    sDiv.style.top = (parseInt(window.screen.availHeight)/2)-100 + 'px';
    sDiv.innerHTML = "<table cellpadding='0' class='Progress' cellspacing='0' width='400px'><tr><td align='right'><img " + 
                     "src='Images/general/ajax-loader.gif' ></td><td align='left'><b>" + ProgressText + "</b></td></tr></table>";
    rDiv.appendChild(sDiv);
    document.body.appendChild(rDiv);
}

function HideProgress()
{
    if(document.getElementById("divProgress") != null)
    {
        document.body.removeChild(document.getElementById("divProgress"));
    };
}
    
function PreLoadImages(DirectoryLocation)
{
    if (document.images) {
        img1 = new Image();
        img1.src = DirectoryLocation + "Images/round-toptop.gif";
        img2 = new Image();
        img2.src = DirectoryLocation + "Images/round-topright.gif";
        img3 = new Image();
        img3.src = DirectoryLocation + "Images/round-topleft.gif";
        img4 = new Image();
        img4.src = DirectoryLocation + "Images/round-topright-hover.gif";
        img5 = new Image();
        img5.src = DirectoryLocation + "Images/round-topleft-hover.gif";
        img6 = new Image();
        img6.src = DirectoryLocation + "Images/round-toptop-hover.gif";
        img7 = new Image();
        img7.src = DirectoryLocation + "Images/round-toptop-active.gif";
        img8 = new Image();
        img8.src = DirectoryLocation + "Images/round-topright-active.gif";
        img9 = new Image();
        img9.src = DirectoryLocation + "Images/round-topleft-active.gif";
        img10 = new Image();
        img10.src = DirectoryLocation + "Images/round-topleft-active_noBottom.gif"; }
}

function removeHTMLTags(strInputCode)
{              
    return (strInputCode.replace(/<.*?>/g,''));   
}
      
function removeHTMLTags(strInputCode)
{                      
    return (strInputCode.replace(/<.*?>/g,''));    	    
}

function OnCallBackError(message, context) 
{
   HideProgress();
   alert('An error occurred:\n' + message);
}

function Trim(s)
{
    return s.replace(/^\s+|\s+$/g, '');
}

function ShowPDF(PanNumber)
{
    window.open('ShowPDF.aspx?PAN=' + PanNumber, 'Fulltext', '');
}

function submitForm(params)
{
    if (typeof(params) == 'undefined')
        params = ''
    else
        params = '?' + params;
        
    document.getElementById('aspnetForm').action = 'process_email.aspx' + params;
    document.getElementById('__VIEWSTATE').value = '';
    document.getElementById('aspnetForm').submit();
}

function submitToLyris()
{
    document.getElementById('aspnetForm').action = 'http://information.cabi.org/subscribe/subscribe.tml';
    document.getElementById('__VIEWSTATE').value = '';
    document.getElementById('aspnetForm').submit();
}

function textboxfocus() {
    if(document.getElementById(TxtUserNameClientID) != null)
        document.getElementById(TxtUserNameClientID).focus();
}   
