OnErrCustom = function(p) {
    if (p.msg == "Login failure") {
        ShowControl("PCBSLoginInfomation_Holder", true);
        if ($get('PCBSLoginInfomation_PopUp') != null) {
            PopUpInit('PCBSLoginInfomation');
            PopUpShow("PCBSLoginInfomation", true);
            setTimeout(function() { window.location = "Login.aspx" }, 5000);
        }
        else {
            window.location = "Login.aspx";
        }
        return false;
    }
    return true;
}

function ShowControl(id, show)
{
    var ctrl = $get(id);
    if (ctrl != null)
        ctrl.style.display = (show) ? "": "none";
}

function StudFilterKey(arg)
{
    if (window.event != null)
    {
        if (window.event.keyCode == 13)
        {
            arg();
        }
    }
}

function FormatDateTime(p)
{
    if (p == null || p.val == null || p.val == "")
    {
        return "";
    }
    var d = new Date(p.val);
    return d.format("MM/dd/yyyy HH:mm");
}

function stopRKey(evt)
{
    var evt = (evt) ? evt : ((event) ? event : null);
    var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
    if ((evt.keyCode == 13) && (node.type == "text")) { return false; }
}

function dbstrToInt(str)
{
    //  if (str == null || str == '')
    //      return 0;
    var res = parseInt(str);
    return isNaN(res) ? 0 : res;
}

function doexcol(el, cnt)
{
    var p = el;
    while (p && p.tagName != 'TR')
        p = p.parentNode;
    while (p && cnt > 0)
    {
        p = p.nextSibling;
        while (p && p.tagName != 'TR') p = p.nextSibling;
        if (!p) return;
        if (p.style.display == "")
            p.style.display = "none";
        else p.style.display = "";
        cnt--;
    }
    if (el.innerHTML == "+")
        el.innerHTML = "-";
    else el.innerHTML = "+";
}

function ValidateNumeric(v)
{
    if (v.val != null) v = v.val; // case of object (PAT validation)
    res = new RegExp("^[0-9]{1,3}([.][0-9]{0,3})?$");
    return v == "" || res.test(v);
}

function RefreshControlsToNotify(controlsToNotify)
{
    if (controlsToNotify != null && controlsToNotify != "")
    {
        var ctrl = controlsToNotify.split(",");
        if (ctrl != null)
        {
            var len = ctrl.length;
            for (var i = 0; i < len; i++)
            {
                if (ctrl[i] == null || ctrl[i] == "") continue;
                PatObj_Refresh(ctrl[i]);
            }
        }
    }
}


function ShowDetailsOnSelected(p, detailsId)
{
    var id = -1;

    if (p != null && p.curRowId != null && p.obj != null)
    {
        id = p.curRowId;
    }
    ShowControl(detailsId, id != -1);
}

function OnContactSRELoaded(p)
{
    if (p != null && p.tableRes != null && p.tableRes.rows != null && p.tableRes.rows.length > 0)
    {
        var c = p.tableRes.rows[0];
        var inactiveCtrl = $get('inactive_' + p.objName);

        if (inactiveCtrl != null)
        {
            inactiveCtrl.disabled = c.ro_inactive;
        }
    }
}

function enterBlock(e) {
    var keynum = 0;
    if (window.event) // IE
        keynum = e.keyCode;
    else if (e.which) // no IE
        keynum = e.which;
    return keynum != 13;
}

var XML = new Object();
XML.load = function(url) {
    var xmldoc = XML.newDocument();
    xmldoc.async = false;  
    xmldoc.load(url);
    return xmldoc;  
  };


XML.newDocument = function(rootTagName, namespaceURL) {
    if (!rootTagName) rootTagName = "";
    if (!namespaceURL) namespaceURL = "";

    if (document.implementation && document.implementation.createDocument) {
        // This is the W3C standard way to do it
        return document.implementation.createDocument(namespaceURL, 
                       rootTagName, null);
    }
    else { // This is the IE way to do it
        // Create an empty document as an ActiveX object
        // If there is no root element, this is all we have to do
        var doc = new ActiveXObject("MSXML2.DOMDocument");

        // If there is a root tag, initialize the document
        if (rootTagName) {
            // Look for a namespace prefix
            var prefix = "";
            var tagname = rootTagName;
            var p = rootTagName.indexOf(':');
            if (p != -1) {
                prefix = rootTagName.substring(0, p);
                tagname = rootTagName.substring(p+1);
            }

            // If we have a namespace, we must have a namespace prefix
            // If we don't have a namespace, we discard any prefix
            if (namespaceURL) {
                if (!prefix) prefix = "a0"; // What Firefox uses
            }
            else prefix = "";

            // Create the root element (with optional namespace) as a
            // string of text
            var text = "<" + (prefix?(prefix+":"):"") + tagname +
                (namespaceURL
                 ?(" xmlns:" + prefix + '="' + namespaceURL +'"')
                 :"") +
                "/>";
            // And parse that text into the empty document
            doc.loadXML(text);
        }
        return doc;
    }
}; 

XML.selectNodes = function(node, xpath){
            if(window.ActiveXObject) {// code for IE
                return node.selectNodes(xpath);
            } else {// code for Mozilla, Firefox, Opera, etc.
                var doc = node;
                if(node.ownerDocument)
                    doc = node.ownerDocument;
                var ret = new Array();
                if(doc.documentElement != null) {
                    var nsResolver = doc.createNSResolver(doc.documentElement)
                    var items = doc.evaluate(xpath, node, nsResolver, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)
                    for(var i = 0; i < items.snapshotLength; i++)
                        ret[i] =  items.snapshotItem(i);
                }
                return ret;
            }
        };
    XML.selectNodeText = function(node, xpath)
        {
            var node = this.selectSingleNode(node, xpath);
            if(node == null) return "";
            
            if(window.ActiveXObject) {// code for IE                
                return node.text;
            } else {// code for Mozilla, Firefox, Opera, etc.                
                return node.textContent;
            }
        };
    XML.selectSingleNode = function(node, xpath){
            var nodes = this.selectNodes(node, xpath);
            if(nodes.length > 0) return nodes[0];
            else return null;
        };

        function checkFileExtension(filename, extensions) 
        {
            for (ext in extensions) 
            {
                var rx = new RegExp("^.+\." + extensions[ext] + "\s*$", "ig");

                if (rx.test(filename)) return true;
            }

            return false;
        }
