﻿// This code is copyright Bartram Enterprises: Web Design 2009 and beyond
// Using this code without the appropriate permission is stricly forbidden


/* new */

/* Insert adjacent element/text/html */
if(typeof HTMLElement != "undefined")
{
    var htmlElement = document.createElement("div");
    
    if(typeof htmlElement.insertAdjacentElement == "undefined")
    {
	    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;
		    }
	    }
	}

    if(typeof htmlElement.insertAdjacentHTML == "undefined")
    {
	    HTMLElement.prototype.insertAdjacentHTML = function(where,htmlStr)
	    {
		    var r = this.ownerDocument.createRange();
		    r.setStartBefore(this);
		    var parsedHTML = r.createContextualFragment(htmlStr);
		    this.insertAdjacentElement(where,parsedHTML)
	    }
    }

    if(typeof htmlElement.insertAdjacentText == "undefined")
    {
	    HTMLElement.prototype.insertAdjacentText = function(where,txtStr)
	    {
		    var parsedText = document.createTextNode(txtStr)
		    this.insertAdjacentElement(where,parsedText)
	    }
    }
    
    if (typeof htmlElement.innerText == "undefined")
    {
        HTMLElement.prototype.__defineGetter__("innerText", function()
                                                            {
                                                                retVal = '';
                                                                
                                                                if (this != null)
                                                                {
                                                                    if (typeof(this.constructor) != 'function')
                                                                    {
                                                                        var textContentType = typeof this.textContent;
                                                                        if (textContentType != 'undefined')
                                                                        {
                                                                            retVal = this.textContent;
                                                                        }
                                                                    }
                                                                }
                                                                
                                                                return retVal;
                                                            });
        HTMLElement.prototype.__defineSetter__("innerText", function(val)
                                                            {
                                                                window.$mb.setInnerText(this, val);
                                                            });
    }
    
    if (typeof htmlElement.children == "undefined")
    {
        HTMLElement.prototype.__defineGetter__("children", function()
                                                           {
                                                                var retVal = new Array();
                                                                
                                                                if (this != null)
                                                                {
                                                                    if (typeof(this.constructor) != 'function')
                                                                    {
                                                                        var TEXT_NODE = 3;
                                                                        
                                                                        if (this.childNodes)
                                                                        {
                                                                            var i = 0;
                                                                            while (i < this.childNodes.length)
                                                                            {
                                                                                var o = this.childNodes[i];
                                                                                if (o.nodeType != TEXT_NODE) // ignore text nodes
                                                                                {
                                                                                    retVal[retVal.length] = o;
                                                                                }
                                                                                i++;
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                                
                                                                return retVal;
                                                           });
    }
    
    if (typeof htmlElement.fireEvent == "undefined")
    {
        HTMLElement.prototype.fireEvent = function(eventName)
        {
            if (typeof(eventName) == 'string')
            {
                if (eventName.length > 2)
                {
                    var eventInstance = null;
                    var refinedEventName = eventName.toLowerCase();
                    
                    if (refinedEventName.substring(0, 2) == 'on')
                    {
                        refinedEventName = refinedEventName.substring(2);
                    }
                    
                    switch (refinedEventName)
                    {
                        case 'click':
                            eventInstance = window.document.createEvent("HTMLEvents"); 
                            eventInstance.initEvent(refinedEventName, isBubbleEvent(refinedEventName), true); 
                            break;
                    }
                    
                    if (eventInstance != null)
                    {
                        this.dispatchEvent(eventInstance);
                    }
                }
            }                
        }
    }

    if (typeof document.parentWindow == "undefined")
    {
        HTMLDocument.prototype.__defineGetter__("parentWindow", function()
                                                                {
                                                                    retVal = '';
                                                                
                                                                    if (this != null)
                                                                    {
                                                                        if (typeof(this.constructor) != 'function')
                                                                        {
                                                                            return this.defaultView;
                                                                        }
                                                                    }
                    
                                                                    return retVal;
                                                                });
    }    
}

/* Button */
function HTMLElementButton_ParseButtonText(sourceText)
{
    var newText = sourceText;
    
    var commonChangesMatch  = new Array("&amp;", "&lt;", "&gt;", "&#160;", "&nbsp;");
    var commonChangesReplace = new Array("&", "<", ">", " ", " ");
    
    for(var i = 0; i < commonChangesMatch.length; i++)
    {
        var lastIdx = newText.indexOf(commonChangesMatch[i]);
        while (lastIdx != -1)
        {
            newText = newText.replace(commonChangesMatch[i], commonChangesReplace[i]);
            lastIdx = newText.indexOf(commonChangesMatch[i]);
        }
    }
    return newText;
}

HTMLElementButton_SetText = function(button, text)
    {
        if (typeof HTMLButtonElement != 'undefined')
        {
            //button.textContent = text;
            $mb.setInnerText(button, HTMLElementButton_ParseButtonText(text));
        }
        else
        {
            button.value = text;
        }
    }

HTMLElementButton_GetText = function(button)
    {
        var retVal;

        if (typeof HTMLButtonElement != 'undefined') // this will be valid in IE8, but the textContent property isn't
        {
            if (typeof button.textContent != "undefined")
            {
                retVal = button.textContent;
            }
            else
            {
                retVal = button.innerText;
            }
        }
        else
        {
            retVal = button.value;
        }

        return retVal;
    }

if (!window.ActiveXObject)
{
	XMLDocument.prototype.selectNodes = function(cXPathString, xNode)
	{
		if( !xNode ) { xNode = this; } 

        try
        {
            var nsResolver = {
                                normalResolver : this.createNSResolver(this),
                                lookupNamespaceURI : function(namespacePrefix)
                                                            {
                                                                retVal = '';
                                                                switch (namespacePrefix)
                                                                {
                                                                    case 'dflt':
                                                                        retVal = this.defaultNamespaces;
                                                                        break;
                                                                    default:
                                                                        retVal = this.namespaces[namespacePrefix];
                                                                        if ((retVal == null) || (retVal == ''))
                                                                        {
                                                                            retVal = this.normalResolver.lookupNamespaceURI(namespacePrefix);
                                                                        }
                                                                        break;
                                                                }
                                                                return retVal;
                                                            },
                                namespaces : this._namespaces
                                };
		    var aItems = this.evaluate(cXPathString, xNode, nsResolver, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
		    var aResult = [];
		    for( var i = 0; i < aItems.snapshotLength; i++)
		    {
			    aResult[i] =  aItems.snapshotItem(i);
		    }
		}
		catch(ex)
		{
		    alert('selectNodes ERROR!!! \r\n ' + ex.message);
		}
		
		return aResult;
	}
	XMLDocument.prototype.selectSingleNode = function(cXPathString, xNode)
	{
		if( !xNode ) { xNode = this; } 

		var xItems = this.selectNodes(cXPathString, xNode);
		if( xItems.length > 0 )
		{
			return xItems[0];
		}
		else
		{
			return null;
		}
	}
	XMLDocument.prototype.__defineGetter__('xml', function()
	                                                        {
	                                                            var retVal = '';
	                                                            
                                                                var serialiser = new XMLSerializer();
                                                                retVal = serialiser.serializeToString(this);
                                                                
                                                                return retVal;
                                                            });	      
    XMLDocument.prototype.__defineSetter__('xml', function()
                                                            {
                                                                throw 'The property XMLDocument.xml is readonly';
                                                            });
    XMLDocument.prototype.setProperty = function(name, value)
                                                            {
                                                                if (name == 'SelectionNamespaces')
                                                                { 
                                                                    this.defaultNamespaces = value;
                                                                }
                                                            }
    XMLDocument.prototype._namespaces = new Array();
    XMLDocument.prototype.setProperty = function(name, value)
                                                            {
                                                                if (name == 'SelectionNamespaces')
                                                                { 
                                                                    this._namespaces = new Array();
                                                                    var namespaceList = value.split("xmlns:");
                                                                    for (var counter = 1 ; counter < namespaceList.length ; counter++ )
                                                                    {
                                                                        var ns = namespaceList[counter].split("=");
                                                                        this._namespaces[ns[0]] = ns[1].replace(/\"/g, "").replace(/\'/g, "");
                                                                    }
                                                                 }
                                                             }
                                                             
    Node.prototype.transformNode = function(xslDom)
    {
        var retVal = null;
    
        var xsltProcessor = new XSLTProcessor();
        xsltProcessor.importStylesheet(xslDom);

        var retDom = xsltProcessor.transformToDocument(this);
        retVal = retDom.xml;
        
        return retDom;      
    }
 
	Element.prototype.selectNodes = function(cXPathString)
	{
		if(this.ownerDocument.selectNodes)
		{
			return this.ownerDocument.selectNodes(cXPathString, this);
		}
		else{throw "For XML Elements Only";}
	}

	Element.prototype.selectSingleNode = function(cXPathString)
	{	
		if(this.ownerDocument.selectSingleNode)
		{
			return this.ownerDocument.selectSingleNode(cXPathString, this);
		}
		else{throw "For XML Elements Only";}
	}
	
    Element.prototype.__defineGetter__("text", function()
                                                        {
                                                            if (!this.textContent)
                                                            {
                                                                return "";
                                                            }
                                                            return this.textContent;
                                                        });
    Element.prototype.__defineSetter__("text", function(val)
                                                        {
                                                            if (typeof this.textContent != 'undefined')
                                                            {
                                                                window.$mb.setInnerText(this, val);
                                                            }
                                                        });
}

// core helper routines - temp location
if (!window.$mb)
{
    window.$mb = new Array();

    window.$mb.IsWindow
     = function(obj)
        {
            if (obj == window)
            {
                return true;
            }
            
            return false;
        };

    window.$mb.IsDocument
     = function(obj)
        {
            if (obj == document
             || obj == document.documentElement)
            {
                return true;
            }
            
            return false;
        };
        
    window.$mb.GetAttr
      = function(obj, name)
        {
            var result = '';
            if (obj && name && obj.attributes[name] != null)
            {
                result = obj.getAttribute(name);
            }
          
            return result;
        };

    window.$mb.SetAttr
      = function(obj, name, value)
        {
            var result = '';
            if (obj && name)
            {
                var hasAttribute = (obj.attributes[name] != null);
                if (hasAttribute == true && value == null)
                {
                    obj.removeAttribute(name);
                    return;
                }

                obj.setAttribute(name, value);
            }
        };

    // ref: http://www.quirksmode.org/dom/w3c_cssom.html        
    window.$mb.ClientLeft
      = function(obj)
        {
            return obj.clientLeft;
        };

    window.$mb.ClientTop
      = function(obj)
        {
            return obj.clientTop;
        };
        
    window.$mb.ClientWidth
      = function(obj)
        {
            return obj.clientWidth;
        };
        
    window.$mb.ClientHeight
      = function(obj)
        {
            return obj.clientHeight;
        };
        
    window.$mb.OffsetLeft
      = function(obj)
        {
            return obj.offsetLeft;
        };
        
    window.$mb.OffsetTop
      = function(obj)
        {
            return obj.offsetTop; // TODO
        };
        
    window.$mb.OffsetWidth
      = function(obj)
        {
            return obj.offsetWidth;
        };
        
    window.$mb.OffsetHeight
      = function(obj)
        {
            return obj.offsetHeight;
        };
        
    window.$mb.ScrollLeft
      = function(obj, val)
        {
            if ($mb.IsWindow(obj) == true || $mb.IsDocument(obj) == true)
            {
                if (window.pageXOffset)
                {                
                    if (val != null && window.pageXOffset != val)
                    {
                        window.pageXOffset = val;
                    }
                    
                    return window.pageXOffset;
                }
                else
                {
                    if (val != null && document.documentElement.scrollLeft != val)
                    {
                        document.documentElement.scrollLeft = val;
                    }
                    
                    return document.documentElement.scrollLeft;
                }
            }

            if (val != null && obj.scrollLeft != val)
            {
                obj.scrollLeft = val;
            }
            
            return obj.scrollLeft;
        };
        
    window.$mb.ScrollTop
      = function(obj, val)
        {
            if ($mb.IsWindow(obj) == true || $mb.IsDocument(obj) == true)
            {
                if (window.pageYOffset)
                {                
                    if (val != null && window.pageYOffset != val)
                    {
                        window.pageYOffset = val;
                    }
                    
                    return window.pageYOffset;
                }
                else
                {
                    if (val != null && document.documentElement.scrollTop != val)
                    {
                        document.documentElement.scrollTop = val;
                    }
                    
                    return document.documentElement.scrollTop;
                }
            }

            if (val != null && obj.scrollTop != val)
            {
                obj.scrollTop = val;
            }
            
            return obj.scrollTop;
        };
        
    window.$mb.ScrollWidth
      = function(obj)
        {
            return obj.scrollWidth; // TODO
        };
        
    window.$mb.ScrollHeight
      = function(obj)
        {
            return obj.scrollHeight; // TODO
        };

    window.$mb.OffsetParents
     = function(obj)
        {
            var arr = new Array();
            
            var node = obj.offsetParent;
            while (node != null)
            {
                arr[arr.length] = node;
                node = obj.offsetParent;
            }
            
            return arr;
        }
        
    window.$mb.Wrapper = function()
    {
        this.obj = null;
        
        this.clientLeft = function(){ return $mb.ClientLeft(this.obj); };
        this.clientTop = function(){ return $mb.ClientTop(this.obj); };
        this.clientWidth = function(){ return $mb.ClientWidth(this.obj); };
        this.clientHeight = function(){ return $mb.ClientHeight(this.obj); };

        this.offsetLeft = function(){ return $mb.OffsetLeft(this.obj); };
        this.offsetTop = function(){ return $mb.OffsetTop(this.obj); };
        this.offsetWidth = function(){ return $mb.OffsetWidth(this.obj); };
        this.offsetHeight = function(){ return $mb.OffsetHeight(this.obj); };

        this.scrollLeft = function(val){ return $mb.ScrollLeft(this.obj, val); };
        this.scrollTop = function(val){ return $mb.ScrollTop(this.obj, val); };
        this.scrollWidth = function(){ return $mb.ScrollWidth(this.obj); };
        this.scrollHeight = function(){ return $mb.ScrollHeight(this.obj); };

        this.offsetParents = function(){ return $mb.ParentElements(this.obj); };
        
        this.GetAttr = function(name){ return $mb.GetAttr(this.obj, name); };
        this.SetAttr = function(name, value){ return $mb.SetAttr(this.obj, name, value); };

        return this;
    };

    window.$mbx
     = function(obj)
        {
            var wrapper = new $mb.Wrapper();
            wrapper.obj = obj;
            return wrapper;
        }
        
        
    window.$mb.RemoveChildren
      = function(obj)
      {
        while (obj.hasChildNodes())
        {
            obj.removeChild(obj.firstChild);
        }
      }
      
    window.$mb.setInnerText
      = function(obj, newText)
      {
        $mb.RemoveChildren(obj);
        var xNewContent = document.createTextNode(newText);
        obj.appendChild(xNewContent);
      }

      window.$mb.IsNullOrEmpty
        = function(sourceValue)
        {
            if (typeof (sourceValue) == "undefined")
            {
                return true;
            }

            if (sourceValue == null)
            {
                return true;
            }

            if (sourceValue.replace(/^\s+|\s+$/g, "") == "")
            {
                return true;
            }
            
            return false;
        }
        
    window.$mb.ChangeChildIDs
      = function(obj, idSuffix)
    {
        if (typeof (obj.childNodes) == "undefined")
        {
            return;
        }
        
        for(var i = 0; i < obj.childNodes.length; i++)
        {
            if (obj.childNodes[i].hasChildNodes())
            {
                $mb.ChangeChildIDs(obj.childNodes[i], idSuffix);
            }

            if (!$mb.IsNullOrEmpty(obj.childNodes[i].id))
            {
                obj.childNodes[i].id = obj.childNodes[i].id + "_" + idSuffix;
            }

            if (!$mb.IsNullOrEmpty(obj.childNodes[i].name))
            {
                obj.childNodes[i].name = obj.childNodes[i].name + "_" + idSuffix;
            }
        }
      }
      
    window.$mb.ClearChildTextValues
      = function(obj)
      {
        for(var i = 0; i < obj.childNodes.length; i++)
        {
            if (obj.childNodes[i].hasChildNodes())
            {
                $mb.ClearChildTextValues(obj.childNodes[i]);
            }
            
            if (obj.childNodes[i].tagName == "INPUT")
            {
                obj.childNodes[i].value = "";
            }
        }
      }          
}

function showProperties(srcObject)
{
    var output = "";
    var iMax = 20;
    var iCount = 0;
    
    for (var prop in srcObject)
    {
        output += prop + " = " + srcObject[prop] + "\n";
        iCount += 1;
        
        if (iCount >= iMax)
        {
            alert(output);
            output = "";
            iCount = 0;
        }
    }
    
    alert(output);
}

/*
START EXTENTION METHODS
*/

/*
String Extension Methods
*/

String.prototype.isAlpha = function()
{
    return (this.match(/[A-Za-z]/g) ? true : false);
}

String.prototype.isNumeric = function()
{
    return (this.match(/^\d+$/) ? true : false);
}

String.prototype.isAlphanumeric = function()
{
    return (this.match(/[^A-Za-z0-9]/g) ? true : false);
}

String.prototype.trim = function()
{
    return this.replace(/^\s+|\s+$/g, '');
}

String.prototype.ltrim = function()
{
    return this.replace(/^\s+/, "");
}

String.prototype.rtrim = function()
{
    return this.replace(/\s+$/, "");
}

String.prototype.isEmail = function()
{
    var rx = new RegExp("\\w+([-+.\’]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*");
    var matches = rx.exec(this);
    return (matches != null && this == matches[0]);
}

String.prototype.isURL = function()
{
    var rx = new RegExp("http(s)?://([\\w-]+\\.)+[\\w-]+(/[\\w-\\+ ./?%:&=#\\[\\]]*)?");
    var matches = rx.exec(this);
    return (matches != null && this == matches[0]);
}

String.prototype.contains = function(t)
{
    return this.indexOf(t) >= 0 ? true : false;
}

String.prototype.beginsWith = function(t, caseInsensitive)
{
    if (caseInsensitive == false)
    {
        return (t == this.substring(0, t.length));
    }
    else
    {
        return (t.toLowerCase() == this.substring(0, t.length).toLowerCase());
    }
}

String.prototype.endsWith = function(t, caseInsensitive)
{
    if (caseInsensitive == false)
    {
        return (t == this.substring(this.length - t.length));
    }
    else
    {
        return (t.toLowerCase() == this.substring(this.length - t.length).toLowerCase());
    }
}

/* 
Checks a string is a valid date.  
Allowed formats are:
dd/mm/yyyy
mm/dd/yyyy
*/
String.prototype.isDate = function(dateFormat)
{
    var delimiter = dateFormat.substring(2, 3);
    var ddStart = dateFormat.substring(0, 2) == "dd" ? true : false;

    var datePartPattern = "^([0-9]{2})" + delimiter + "([0-9]{2})" + delimiter + "([0-9]{4})$";

    var ddPos = 1;
    var mmPos = 2;
    var yyPos = 3;

    if (!ddStart)
    {
        ddPos = 2;
        mmPos = 1;
    }

    var IsoDateRe = new RegExp(datePartPattern);
    var matches = IsoDateRe.exec(this);
    if (!matches) return false;

    var ddVal = matches[ddPos];
    var mmVal = matches[mmPos];
    var yyVal = matches[yyPos];

    var composedDate = new Date(yyVal, (mmVal - 1), ddVal);

    return (
        (composedDate.getMonth() == parseInt(mmVal - 1)) &&
        (composedDate.getDate() == parseInt(ddVal)) &&
        (composedDate.getFullYear() == parseInt(yyVal))
    );
}

String.prototype.isMod10 = function()
{
    var valid = "0123456789"
    var len = this.length;
    var bNum = true;
    var iCCN = this;
    var sCCN = this;
    var iCCN;
    var iTotal = 0;
    var bResult = false;
    var digit;
    var temp;
    iCCN = sCCN.replace(/^\s+|\s+$/g, '');      // strip spaces
    for (var j = 0; j < len; j++)
    {
        temp = "" + iCCN.substring(j, j + 1);
        if (valid.indexOf(temp) == "-1")
        {
            bNum = false;
        }
    }

    if (!bNum)
    {
        return false;
    }

    iCCN = parseInt(iCCN);
    if (len == 0)
    {                                           /* nothing, field is blank */
        bResult = true;
    }
    else
    {
        if (len >= 15)                           //15 or 16 for Amex or V/MC
        {
            for (var i = len; i > 0; i--)
            {
                digit = "digit" + i;
                calc = parseInt(iCCN) % 10;     //right most digit
                calc = parseInt(calc);
                iTotal += calc; 	            //parseInt(cardnum.charAt(count))i:\t" + calc.toString() + " x 2 = " + (calc *2) +" : " + calc2 + "\n";

                i--;
                digit = "digit" + i;

                iCCN = iCCN / 10; 	            // subtracts right most digit from ccNum
                calc = parseInt(iCCN) % 10; // step 1 double every other digit
                calc2 = calc * 2;

                switch (calc2)
                {
                    case 10: calc2 = 1; break; //5*2=10 & 1+0 = 1
                    case 12: calc2 = 3; break; //6*2=12 & 1+2 = 3
                    case 14: calc2 = 5; break; //7*2=14 & 1+4 = 5
                    case 16: calc2 = 7; break; //8*2=16 & 1+6 = 7
                    case 18: calc2 = 9; break; //9*2=18 & 1+8 = 9
                    default: calc2 = calc2; 	//4*2= 8 &   8 = 8  -same for all lower numbers
                }

                iCCN = iCCN / 10; 	            // subtracts right most digit from ccNum
                iTotal += calc2;
            }

            if ((iTotal % 10) == 0)
            {
                bResult = true;
            }
            else
            {
                bResult = false;
            }
        }
    }

    return bResult;
}

/*
Number Extension Methods
*/

if (!window.$pt)
{
    window.$pt = new Object();
    
    window_$pt_dispose = function(evt)
    {
        if (typeof(window.$pt) != 'undefined')
        {
            if (window.$pt != null)
            {
                if (typeof(window.$pt.events) != 'undefined')
                {
                    if (window.$pt.events != null)
                    {
                        window.$pt.events.dispose(evt);
                        window.$pt.events = null;
                    }
                }

                if (typeof(window.$pt.xml) != 'undefined')
                {
                    if (window.$pt.xml != null)
                    {
                        window.$pt.xml.dispose(evt);
                        window.$pt.xml = null;
                    }
                }

                if (typeof(window.$pt.elements) != 'undefined')
                {
                    if (window.$pt.elements != null)
                    {
                        window.$pt.elements.dispose(evt);
                        window.$pt.elements = null;
                    }
                }
            }
            window.$pt = null;
        }
    }

    registerEventListener(window, 'unload', window_$pt_dispose);
}

if (!window.$pt.events)
{
    window.$pt.events = new Object();

	$pt.events.registerEventListener = function(domObject, eventName, functionReference)
	{
		registerEventListener(domObject, eventName, functionReference)
	}

	$pt.events.unregisterEventListener = function(domObject, eventName, functionReference)
	{
		unregisterEventListener(domObject, eventName, functionReference)
	}

	$pt.events.reregisterEventListener = function(domObject, eventName, functionReference)
	{
		reregisterEventListener(domObject, eventName, functionReference)
	}   
	
	$pt.events.getSourceElement = function(evt)
	{
	    var targ;
	    if (!evt) var evt = window.event;
	    if (evt.target) targ = evt.target;
	    else if (evt.srcElement) targ = evt.srcElement;
	    if (targ.nodeType == 3) // defeat Safari bug
		    targ = targ.parentNode;	    
	    return targ;
	}
	
	$pt.events.getKeyCode = function(evt)
	{
	    var retVal;
	    
	    if (typeof(evt.which) != 'undefined')
	    {
	        retVal = evt.which;
	    }
	    else
	    {
	        retVal = evt.keyCode;
	    }
	    
	    return retVal;
	}
	
	$pt.events.setKeyCode = function(evt, keyCode)
	{
	    if (typeof(evt.which) != 'undefined')
	    {
	        try
	        {
	            evt.which = keyCode;
	        }
	        catch(ex)
	        {
	            evt.stopPropagation();
	        }
	    }
	    else
	    {
	        evt.keyCode = keyCode;
	    }
	}
	
	//TODO - Review keycodes to verify whether the macintosh, FF or SF need different codes.
	$pt.events.isNavigationKeyPressed = function(evt)
	{
	    var retVal = false;
	
	    var keyCode = $pt.events.getKeyCode(evt);

	    return $pt.events.isNavigationKeyCode(keyCode, evt.ctrlKey);
	}

    var keySystem = 0;
	var keyBackSpace = 8;
	var keyTab = 9;
	var keyShift = 16;
	var keyCtrl = 17
	var keyAlt = 18;
	var keyPause = 19;
	var keyArrowLeft = 37;
	var keyArrowUp = 38;
	var keyArrowRight = 39;
	var keyArrowDown = 40;
	var keySpace = 32;
	var key_C = 67;
	var key_V = 86;
	var key_X = 88;
	var key_c = 99;
	var key_v = 118;
	var key_x = 120;

	$pt.events.isNavigationKeyCode = function(keyCode, ctrlKey)
	{
	    if (ctrlKey == undefined || ctrlKey == null)
	    {
	        ctrlKey = false;
	    }
	    
	    var retVal = false;
	    //var navKeyCodes = [0, 8, 9, 33, 34, 35, 36, 37, 38, 39, 40, 46]; // FF Catchall, Backspace, TAB, PgUp/Dn, Home/End, Arrow Keys, Delete

	    var navKeyCodes = [keySystem, keyBackSpace, keyTab];

	    for (var i = 0; i < navKeyCodes.length; i ++)
	    {
	        if (navKeyCodes[i] == keyCode)
	        {
	            retVal = true;
	            break;
            }
	    }

	    if (!retVal)
	    {
	        if (ctrlKey == true)
	        {
	            switch (keyCode)
	            {
	                case key_C:
	                case key_V:
	                case key_X:
	                case key_c:
	                case key_v:
	                case key_x:
	                    retVal = true;
	                    break;
	            }
	        }
	    }
	    
        if (!retVal)
        {
	        var c = String.fromCharCode(keyCode);
	        if ((keyCode != keySpace) && (c.trim().length == 0))
	        {
	            retVal = true;
	        }
	    }

	    return retVal;
	}
	
	$pt.events.dispose = function(evt)
	{
	}
}

if (!window.$pt.xml)
{
    window.$pt.xml = new Object();
    
    window.$pt.xml.getHttpRequestObject = function()
        {
            var request;
            if (window.XMLHttpRequest)
            {
                request = new XMLHttpRequest();
            }
            else
            {
	            try
	            {
		            request = new ActiveXObject("Msxml2.XMLHTTP");
	            } 
	            catch (ex)
	            {
		            try
		            {
			            request = new ActiveXObject("Microsoft.XMLHTTP");
		            } 
		            catch (ex) 
		            {
		            }
	            }
	        }
	        return request;
        }

    window.$pt.xml.getDocument = function(xmlPath, properties)
        {
            var retVal = null;
            var request = getXmlHttpRequestObject();
            
            if (window.XMLHttpRequest)
            {
                if (request.overrideMimeType)
                {
                    request.overrideMimeType('text/xml');
                }
            }
        	
	        if (request != null)
	        {
                if (typeof(request.async) != "undefined")
                {
                    request.async = false;
                }
                
                try
                {
                    request.open("GET", xmlPath, false);
	            }
	            catch(ex)
	            {
	                xmlPath = xmlPath.replace(':80', '');
	                xmlPath = xmlPath.replace(':443', '');
	                request.open("GET", xmlPath, false);
	            }
                request.send(null);
        	
	            retVal = request.responseXML;
        	    
	        }

            if (typeof(properties) != 'undefined')
            {        	
                for (var counter = 0; counter < properties.length; counter ++)
                {
                    var prop = properties[counter];
                    retVal.setProperty(prop.name, prop.value);
                }
            }
                
	        return retVal;
        }

    window.$pt.xml.getDocumentFromDataIsland = function(dataIsland)
        {
            var retVal;

            if (typeof(dataIsland) == 'string')
            {
                dataIsland = document.getElementById(dataIsland);
            }
            
            if (dataIsland != null)
            {
                var xmlText = '';
                if (typeof dataIsland.xml != 'undefined')
                {
                    xmlText = '<xml>' + dataIsland.xml + '</xml>';
                }
                else if (typeof dataIsland.innerHTML != 'undefined')
                {
                    xmlText = '<xml>' + dataIsland.innerHTML + '</xml>';
                }
                else
                {
                    retVal = dataIsland;
                }
                
                if (xmlText != '')
                {
                    retVal = getXmlDocumentFromString(xmlText);
                }
            }
            
            return retVal;
        }

    window.$pt.xml.getDocumentFromString = function(sourceString, properties)
    {
        var retVal;
        
        if (window.ActiveXObject)
        {        
            retVal = new ActiveXObject('MSXML.DOMDocument');
            retVal.async = false;
            retVal.loadXML(sourceString);
        }
        else
        {
            var parser = new DOMParser();
            retVal = parser.parseFromString(sourceString, 'text/xml');
        }
        
        if (typeof(properties) != 'undefined')
        {        	
            for (var counter = 0; counter < properties.length; counter ++)
            {
                var prop = properties[counter];
                retVal.setProperty(prop.name, prop.value);
            }
        }

        return retVal;
    }

    window.$pt.xml.createDocument = function()
    {
        var retVal;
        
        if (window.ActiveXObject)
        {
            retVal = new ActiveXObject('MSXML.DOMDocument');
        }
        else
        {
            retVal = document.implementation.createDocument('', '', null);
        }
        
        return retVal;
    }

    window.$pt.xml.appendChild = function(xmlDoc, childNode)
    {
        var newNode = childNode;
        
        if (xmlDoc.importNode)
        {
            newNode = xmlDoc.importNode(newNode, true);
        }

        xmlDoc.appendChild(newNode);
    }

    window.$pt.xml.createDOM = function()
    {
	    if (typeof(ActiveXObject) != "undefined")
	    {
		    return new ActiveXObject("Microsoft.XMLDOM");
	    }
	    else if (typeof(document.implementation) != "undefined")
	    {
		    if (typeof(document.implementation.createDocument) != "undefined")
		    {
			    return document.implementation.createDocument("", "", null);
		    }
	    }
    }
    
    window.$pt.xml.dispose = function(evt)
    {
    }
}

if (!window.$pt.elements)
{
    window.$pt.elements = new Object();
    
    window.$pt.elements.setInnerText = function(element, text)
    {
        window.$mb.setInnerText(element, text);
    }
    
    window.$pt.elements.dispose = function()
    {
    }
}

/* Added to make replacement easier */
function getXmlHttpRequestObject()
{
	return window.$pt.xml.getHttpRequestObject();
}

function getXmlDocument(xmlPath, properties)
{
	return window.$pt.xml.getDocument(xmlPath, properties);
}

function getXmlDocumentFromDataIsland(dataIsland)
{
    return window.$pt.xml.getDocumentFromDataIsland(dataIsland);
}

function getXmlDocumentFromString(sourceString)
{
    return window.$pt.xml.getDocumentFromString(sourceString);
}

function createXmlDocument()
{
    return window.$pt.xml.createDocument();
}

function appendXmlChildNode(xmlDoc, childNode)
{
    window.$pt.xml.appendChild(xmlDoc, childNode);
}

function GetBlankXMLDomObject()
{
    return window.$pt.xml.createDOM();
}

function prepareXmlDataIsland(element)
{			
	element = dereferenceDomObject(element);
	
	if(element.tagName.toLowerCase() != "xml")
	{
		return;			
	}
		
	if(element.getAttribute("prepareXmlDataIsland") == "true")
	{
		return;
	}
	else
	{
		element.setAttribute("prepareXmlDataIsland", "true");
	}
				
	for(var j = 0; j < element.childNodes.length; j++)
	{
		var childNode = element.childNodes[j];				
		
		if(childNode.nodeType == 1)
		{
			var doc = childNode.ownerDocument;		
			
			if(childNode.tagName.toLowerCase() == "escaped")
			{													
				if(supportsW3CDomEvents == false)
				{									
					doc.loadXML(childNode.text);
				}
				else
				{
					doc = getXmlDocumentFromString(childNode.text);								
				}																																	     			        
			}	
			
		    if(element.id != null && element.id.length > 0)
		    {	
			    // assigns the document into a global variable of the same name as the id of the containing xml element
			    var globalElement = null;
			    
			    try
			    {
			        globalElement = eval(element.id);
			    }
			    catch(ex)
			    {
			        //Only catch those exceptions we're interested in
			        if (ex.name != 'ReferenceError')
			        {
			            throw(ex);
			        }
			    }
			    finally
			    {
                    if(globalElement == null)
			        {
			            eval('var ' + element.id + ' = doc;');
			        }
			    }
            }		
					
			break;						
		}
	}
}		

function prepareXmlDataIslands()
{			
	var xmlElements = document.getElementsByTagName("xml");

	for(var i = 0; i < xmlElements.length; i++)
	{		
		prepareXmlDataIsland(xmlElements[i], xmlElements[i].id);
	}
}

window.$pt.getTextFromHTTPRequest = function(urlToGet, transmissionMethod)
    {
            var retVal = null;
            var request = getXmlHttpRequestObject();
            
              if (request != null)
              {
                request.async = false;
                
                try
                {
                    request.open(transmissionMethod, urlToGet, false);
                  }
                  catch(ex)
                  {
                      urlToGet = urlToGet.replace(':80', '');
                      urlToGet = urlToGet.replace(':443', '');
                      request.open(transmissionMethod, urlToGet, false);
                  }
                request.send(null);
            
                  retVal = request.responseText;
                
              }
                
              return retVal;    
    }


function getElementsByAttribute(oElm, strTagName, strAttributeName, strAttributeValue)
{    
    var arrElements = oElm.getElementsByTagName(strTagName);    
    var arrReturnElements = new Array();    
    var oAttributeValue = (typeof strAttributeValue != "undefined")? new RegExp("(^|\\s)" + strAttributeValue + "(\\s|$)", "i") : null;    
    var oCurrent;    
    var oAttribute;    
    for(var i=0; i<arrElements.length; i++)
    {
        oCurrent = arrElements[i];        
        oAttribute = oCurrent.getAttribute && oCurrent.getAttribute(strAttributeName);        
        if(typeof oAttribute == "string" && oAttribute.length > 0)
        {
            if(typeof strAttributeValue == "undefined" || (oAttributeValue && oAttributeValue.test(oAttribute)))
            {
                arrReturnElements.push(oCurrent);
            }        
        }    
    }    
    return arrReturnElements;
}

///
/// SUMMARY:    Ensure that any Ahchor within a disabled element is using teh disabled CSS class as IE handles this automatically.
///
function performCrossBrowserElementDisable()
{
    // IE does this automatically, so only do this for Firefox et al.
    if (supportsW3CDomEvents)
    {
        var x = getElementsByAttribute(document, "*", "disabled", "disabled");
        for(var i = 0; i < x.length; i++)
        {
            // if the element is an anchor, go ahead
            if (x[i].tagName.toLowerCase() == "a")
            {
                setCrossBrowserElementDisable(x[i]);
            }
            else // otherwise, get all anchors within the element.
            {
                var xChildren = x[i].getElementsByTagName("a");
                for(var j = 0; j < xChildren.length; j++)
                {
                    setCrossBrowserElementDisable(xChildren[j]);
                }
            }
        }
    }
}

function setCrossBrowserElementDisable(sourceElement)
{
    sourceElement.className = "disabledElement";
}

function getFirstActualChild(sourceObject)
{
    // check to see if the source node type is text
    if (sourceObject.childNodes[0].nodeType != 3) 
    {
        // return the object
        return sourceObject.childNodes[0];
    }
    else
    {
        for(var i = 0; i < sourceObject.childNodes.length; i++)
        {
            if (sourceObject.childNodes[i].nodeType != 3)
            {
                return sourceObject.childNodes[i];
            }
        }
    }
}

function SBA_GetElementStyle(srcElement)
{
    if (window.getComputedStyle)
    {
        SBA_GetElementStyle = function(srcElement) { return window.getComputedStyle(srcElement, null); }
        return window.getComputedStyle(srcElement, null);
    }
    else
    {
        SBA_GetElementStyle = function(srcElement) { return srcElement.currentStyle; }
        return srcElement.currentStyle;
    }
}

/*********************************************************************************
Script parsing completion
*********************************************************************************/
var downloaded_coreprototype_js = new Date();

