﻿//***********************************************************
// ThePort ProtoProxyUtils object  
// Author: Steve Soares
//***********************************************************
// Copyright ThePort Inc.
/////////////////////////////////////////////////////////////
// Version History.
/////////////////////////////////////////////////////////////
// Initial Version.
//***********************************************************

// This doc write is necessary for detecting the loaded state of the document in IE.
// This fire onload when it's ready to execute.  However this does not require a file on the server.
document.write('<script id="_port_start_script_" defer="true" src="//[]"></script>');
document.write('<script id="_port_bulk_script_" defer="true" src="//[]"></script>');
var ProtoProxy = {  
    // proxy the call to prototype's '$' function.
    tp_GetID: function (nodeName) { 
      var nodeResult;
        try {
            nodeResult = $tp_GetID(nodeName);
            } catch(e){
            try {
                nodeResult = $(nodeName)
                } catch(e){}
              }
        return nodeResult;
      },
      
    tp_Show: function (nodeName) {
        try {
            var node = ProtoProxy.tp_GetID(nodeName);
            node.style.display=''
        } catch(e) {}
    },
    
    tp_Hide: function (nodeName) {
        try {
            var node = ProtoProxy.tp_GetID(nodeName);
            node.style.display='none'
        } catch(e) {}
    },

 // *********************************************************
 // Added this function for detecting WHEN the onload event 
 // occurs for different browser types -SMS July 9 2008
 // *********************************************************
 tp_registerInitHandler: function (onLoadFunction) {
    // Moziller 
    if (document.addEventListener) {
        document.addEventListener("DOMContentLoaded", onLoadFunction, false);
        return;
        }

    
    // IE 
    if (document.getElementById) {
        var deferScript = document.getElementById('_port_start_script_'); //"_port_start_script_");
        if (deferScript) {
            deferScript.onreadystatechange = function() {
                if (this.readyState == "complete") {
                    onLoadFunction();
                    }
                };
            // Immediate check, right away...
            deferScript.onreadystatechange();
            // Stop IE leaks 
            deferScript = null;
            }
        return;
        }

    // Safari 
    if (/WebKit/i.test(navigator.userAgent)) { 
        var _timer = setInterval(function() {    
            if (/loaded|complete/.test(document.readyState)) {      
                clearInterval(_timer);      
                onLoadFunction(); // Doc is loaded.  Call our func
                }  
            }, 10);
        return;
        }

    // Other browsers 
    window.onload = onLoadFunction;
    },
    
 tp_registerBulkInitHandler: function (onLoadFunction) {

    // Moziller 
    if (document.addEventListener) {
        document.addEventListener("DOMContentLoaded", onLoadFunction, false);
        return;
        }

    
    // IE 
    if (document.getElementById) {
        var deferScript = document.getElementById('_port_bulk_script_'); //"_port_start_script_");
        if (deferScript) {
            deferScript.onreadystatechange = function() {
                if (this.readyState == "complete") {
                    onLoadFunction();
                    }
                };
            // Immediate check, right away...
            deferScript.onreadystatechange();
            // Stop IE leaks 
            deferScript = null;
            }
        return;
        }

    // Safari 
    if (/WebKit/i.test(navigator.userAgent)) { 
        var _timer = setInterval(function() {    
            if (/loaded|complete/.test(document.readyState)) {      
                clearInterval(_timer);      
                onLoadFunction(); // Doc is loaded.  Call our func
                }  
            }, 10);
        return;
        }

    // Other browsers 
    window.onload = onLoadFunction;
    }
    
}
