/**
 * class provides simple dom selection helper methods and other useful utilities
 *
 */

// Mozilla based browsers support console logging.
try{ if (typeof(console) == 'undefined') console={log:function(){}};  }catch(e){}

var Util = (function(){
    return {
        // For IE specific functionality where object detection isnt enough
        isIE : (navigator.appName == "Microsoft Internet Explorer"),

        objExists : function(objName){
            return typeof eval("objName") != 'undefined';
        },
        
        /**
         * shortcut return element with id equal to @id
         */
        byId : function (id){
            return document.getElementById(id);
        },

        /**
         * shortcut return all elements by tag name @tag
         */
        byTag: function(tag){
            return document.getElementsByTagName(tag);
        },

        /**
         * shortcut return first element by tag name @tag
         */
        firstByTag: function(tag){
            var t = document.getElementsByTagName(tag);
            return (t && t.length > 0)?t[0]:null;
        },

        /**
         * shortcut return first element by name @name
         */
        firstByName : function(name){ try{
            return (document.getElementsByName(name) && document.getElementsByName(name).length)?document.getElementsByName(name)[0] : null;
        } catch(e){alert(e.message);} }, // finally{ console.log("firstByName("+name+")"); } },

        /*
         * Get and element by id or first element by tag name
         */
        byIdOrName : function(val){ try{
            var elem = Util.byId(val);
            if ( elem )
                return  elem;
            else
               return Util.firstByName(val);
        } catch(e){alert(e.message);}  }, // finally{ console.log("byIdOrName("+val+")"); } },

        /*
         * return collection by name
         */
        allByName : function(val){ try{
            return document.getElementsByName(val);
        } catch(e){alert(e.message);}  }, // finally{ console.log("allByName("+val+")"); } },


        byTagClass : function(tagName, className){
			var ret = new Array();
			var elems = Util.byTag(tagName);
			for ( var i = 0; i < elems.length; i++ ) {
				if( elems[i].className == className ) {
					ret.push(elems[i]);
				}
			}
			return ret;
		},

		byTagAttribute : function(tagName, attr,value){
			var ret = new Array();
			var elems = Util.byTag(tagName);
			for ( var i = 0; i < elems.length; i++ ) {
				if( elems[i].getAttribute(attr) == value ) {
					ret.push(elems[i]);
				}
			}
			return ret;
		},

        body : function() {
           return Util.firstByTag("body")
        },

        getNameOrId : function( element ) {
            return element.id || element.name || null;     
        },

        /**
         * format <tag .....> html</tag>
         */
        html : function( target, html ) {
            target = Util.getElem(target); // text id or elem object
            target.innerHTML += html;
        },

        showHide : function(elem, display){
            elem = Util.getElem(elem);
            var sty = Util.getStyle( elem, "display");
            if ( sty == "none" ) {
                Util.show(elem);   
            } else if( sty == "block" || (display && sty == display) ) {
                Util.hide(elem);
            }
        },

        hide : function( elem ) {
            elem = Util.getElem(elem);
            elem.style.display = "none";
            elem.style.visibility = "hidden";
        },

        show : function( elem, display ) {
            elem = Util.getElem(elem);
            elem.style.display = (elem.nodeName.toLowerCase() == "span")? "inline" : (display  || "block");
            elem.style.visibility = "visible";
        },

        disable : function( elem, bgcolor, color ) {
            elem = Util.getElem(elem);
            elem.disabled = true;
            elem.setAttribute("disbaled", true);

            try{
            if ( elem.style  ) {
                if ( bgcolor && elem.style ) elem.style.backgroundColor = ((bgcolor==true) ? "lightgray" : bgcolor);
                if ( color && elem.style ) elem.style.color= ((color==true) ? "gray" : color);
            }}catch(e){}
        },

        enable : function( elem, bgcolor, color ) {
            elem = Util.getElem(elem);
            elem.disabled = null;
            elem.removeAttribute( "disbaled" );

            try{
            if ( elem.style ) {
                if ( bgcolor ) elem.style.backgroundColor = ((bgcolor==true) ? "red" : color);
                if ( color ) elem.style.backgroundColor = ((color==true) ? "white" : color);
            }}catch(e){}
        },

        hideAll : function( elemArray ) {
            for ( var k in elemArray ) {
                Util.hide( elemArray[k] );
            }
        },

        showAll : function( elemArray, display ) {
            for ( var k in elemArray ) {
                Util.show( elemArray[k], display );
            }
        },

        /*
         * Get and element by id or name (usually inputs are queried by name).
         */
        getElem : function(elem){
            if ( typeof elem  == "string" ) {
                elem = Util.byIdOrName( elem );
            }
            return elem;
        },

        setSize : function(elem, w, h){
            elem = Util.getElem(elem);
            if ( w ) elem.style.width = w;
            if ( h ) elem.style.height = h;
        },

        /*
        * Grow a dom element visual size
        * @mode : v=vertical, h=horizontal, default is both
        */
        grow : function( elem, amount, mode ) {
            Util.shrinkGrowBase( 1, elem, amount, mode);
        },

        /*
        * Shrink a dom element visual size
        * @mode : v=vertical, h=horizontal, default is both
        */
        shrink : function( elem, amount, mode ) {
            Util.shrinkGrowBase( -1, elem, amount, mode);
        },

        shrinkGrowBase : function( modifier, elem, amount, mode) {
            elem = Util.getElem(elem);

            var hVal = elem.offsetWidth;
            var vVal = elem.offsetHeight;
            var hTmp = ( typeof(amount) == "string" && amount.indexOf("%") != -1 ) ? hVal * (parseFloat(amount) / 100) : parseInt(amount);
            var vTmp = ( typeof(amount) == "string" && amount.indexOf("%") != -1 ) ? vVal * (parseFloat(amount) / 100) : parseInt(amount);

            hVal = hVal + (modifier * hTmp );
            vVal = vVal + (modifier * vTmp);

            if ( mode == "v") {
                elem.style.height = vVal;
            } else  if ( mode == "h") {
                elem.style.width = hVal;
            } else {
                elem.style.width = hVal;
                elem.style.height = vVal;
            }
        },

        /**
         * return true if @strObjName evaluates to a defined object
         */
        exists: function( strObjName ) {
            if ( typeof strObjName == "string" ) {
                return ( eval("typeof(" + strObjName + ") != 'undefined'" ) && eval(strObjName + "!= null") );
            } else {
                return typeof( strObjName ) != 'undefined';
            }
        },

        /**
         * return true if the location contains @str
         */
        locHas : function(str, win){
            win = win || window;
            return (win.location && win.location.href.indexOf(str) != -1);
        },

        alertMessages : "",
        
        overrideAlert : function(msg) {
            Util.alertMessages += "["+(new Date().toGMTString() ) + "] " + msg + "\n";
        },

        /*
         * override the alert method
         */
        cloakAlert : function() {
            Util.origAlert = window.alert;
            window.alert = Util.overrideAlert;
        },

        /*
         * restore the alert method
         */
        restoreAlert : function() {
            window.alert = Util.origAlert;
            alert( Util.alertMessages );
            Util.alertMessages = "";
        },

        /*
         * Iterate over a list and execute the function @func on each
         */
        each: function(list, func){
            var cnt = 0;
            for (var i = 0; i < list.length; i++ ) {
                func(list[i]);
            }
            return list;
        },

        eachDelayed: function(list, func, delay, finalFunc) {
            //Util.tmpList = list;

            // track timers
            Util.initEachDelay();

            var cnt = 0;
            for (var i = 0; i < list.length; i++ ) {
                // add dynamic methods to Util.
                Util.dynDelayParams[i] = list[i];
                Util.dynDelayFuncs[i] = func;
                Util.activeTimers[Util.activeTimers.length] = setTimeout( "Util.dynDelayFuncs["+i+"](Util.dynDelayParams["+i+"]);", delay*i);
            }

            if ( finalFunc ) {
                Util.activeTimers[Util.activeTimers.length] = setTimeout( finalFunc, del*list.length);
                Util.activeTimers[Util.activeTimers.length] = setTimeout( Util.finalEachDelay, del*(list.length+1));
            }

            return list;
        },

        initEachDelay: function(){
            Util.activeTimers = new Array();
            Util.dynDelayParams = new Array();
            Util.dynDelayFuncs = new Array();
        },
        
        /**
         * clear array of functions
         */
        finalEachDelay : function(){
            Util.dynDelayParams = null;
            Util.dynDelayFunc = null;
        },

        eachKey: function(obj, func){
            if ( !obj ) return;
            for (var k in obj) {
                if ( obj[k] != undefined )
                    func(obj,k);
            }
            return obj;
        },

        eachMemberToString: function(obj){
            var ret = "";
            for (var k in obj) {
                var val = "" + obj[k];
                if ( obj[k] != null && obj[k] != undefined && val.indexOf('function') == -1 )
                    ret += k + "=" + obj[k]  + "\n";
            }
            return ret;
        },

        toJSONString: function(obj,bRecursiveCount){
            return Util.eachMemberToJSONString(obj, bRecursiveCount );
        },


        eachMemberToJSONString: function(obj, bRecursive){
            var ret = "{ \n";

            for (var k in obj) {

                if( typeof( obj[k] ) == 'object' && bRecursive == true) {
                    ret += "'" + k + "'  : " + Util.eachMemberToJSONString(obj[k], true)  + ", \n";
                    continue;
                } else if (typeof( obj[k]) == 'object') {
                    ret += "'" + k + "'  : '[object]', \n";
                    continue;
                }
                var val = "" + obj[k];
                if ( obj[k] != null && obj[k] != undefined && val.indexOf('function') == -1 ) {
                    if( typeof( obj[k] ) != 'number' ) {
                        ret += "'" + k + "'  : '" + obj[k].toString()  + "', \n";
                    } else {
                        ret += "'" + k + "'  : " + obj[k].toString()  + ", \n";
                    }
                }

            }

            ret = ret.substr(0, ret.lastIndexOf(", \n") );

            return ret += "\n}";
        },

        toHtmlTree: function(obj, orderedKeys){
            var ret = "";//"<ul class=\""+class+"\">";

            // get all top level keys and sort
            //var sorted = new Array();
            //for (var k in obj) {
            //    sorted.add(k);
            //}

            for (var k in obj) {
                if( typeof( ""+k != 'command' && obj[k] ) == 'object' ) {
                    var cmd = k;
                    var title;

                    if ( Util.exists(obj[k]['command'] ) ) {
                        // build commmand link
                        //    cmd = "top.messageMenuItemDisabled("+k+")";
                        //else
                        var color =  '';
                        if( k.indexOf('[DISABLED]' ) != -1 ) {
                            color = 'color:#999999';
                            k = k.replace('[DISABLED]', '');
                            cmd = "top.messageMenuItemDisabled( '"+k+"' );";
                        } else {
                            cmd = "return top.frames['mainMenu'].executeMenuFunction( '"+obj[k]['command']+"' );";
                        }
                        cmd = "<a href='javascript: void 0;' onclick=\""+cmd+"\" class='accessible' style=\""+color+"\" >"+k+"</a>";
                    }else{
                        // build parent
                        cmd = "<a href='#' class='accessible' >"+k+"&raquo;</a>";
                    }
                    ret += "<li>" + cmd + "\n<ul>" + Util.toHtmlTree(obj[k])  + "\n</ul>\n</li>\n";
                } 

            }
                     
            //ret = ret.substr(0, ret.lastIndexOf(", \n") );

            return ret;//+"</ul>";
        },


        /**
         *  Find the number of members/methods in an object
         */
        getObjectKeyCount: function(obj) {
            var cnt = 0;
            for (var k in obj) {
                if ( obj[k] != undefined )
                    cnt++;
            }
            return cnt;
        },

        convertObjectToQueryString: function(obj) {
            var str = "";
            for (var k in obj) {
                if ( obj[k] != undefined )
                    str += "&"+k+"=" + obj[k];
            }
            return str;
        },


        /**
         * return a frame whose name contains @name from a collection of frames
         */
        findFrameByName: function( frms, name ) { try {
             for(var i = 0; i < frms.length; i++ ) {
                 if ( this.locHas( name, frms[i] ) ) {
                     return frms[i];
                 } else if ( frms[i].frames && frms[i].frames.length > 0 ) {
                     // recurse
                     var res = this.findFrameByName( frms[i].frames, name );
                     if ( res ) return res;
                 }
             }

             return false;
        } catch(e) { alert("error: " + e.message); } },

        /**
         *  browser compatible add event listener to element
         */
        addEvent : function(element, name, handler) {
            if ( !Util.exists(handler) ) return;
            if ( element.attachEvent != undefined ) {
              element.attachEvent('on' + name, handler);
            } else if ( element.addEventListener != undefined ) {
              element.addEventListener(name, handler, false);
            }
        },

        stopBodyScroll : function(){
            Util.addEvent( document.body, "scroll", new function() {if (document.selection) document.selection.empty(); scrollTo(0,0); } );
        },

        getPreviousSibling : function( elem, className ) {
            var sib = elem.previousSibling;
            while ( sib && sib.noteType != 1 && (sib.className != className ) ) {
                sib = sib.previousSibling;
            }
            return sib;
        },

        getAbsPos : function(elem){
            elem = Util.getElem(elem);
            var pos = {x:0,y:0};
            var par = elem;
            while(par){
                pos.x += par.offsetLeft;
                pos.y += par.offsetTop;
                par = par.offsetParent;
            }

            return pos;
        },

        getAvailableWidth : function(){
            return ( window.innerWidth ) ? window.innerWidth : document.body.clientWidth;
        },

        getAvailableHeight : function(){
            return ( window.innerHeight) ? window.innerHeight: document.body.clientHeight;
        },

        move : function(elem, x, y) {
            elem = Util.getElem(elem);
            if(x!=null) elem.style.left = x;
            if(y!=null) elem.style.top = y;
        }, 

        center : function(elem) {
            elem = Util.getElem(elem);
            var x = Util.getAvailableWidth()/2 - elem.offsetWidth/2;
            var y = Util.getAvailableHeight()/2 - elem.offsetHeight/2;
            Util.move(elem,x,y);
        },

        center_y : function(elem,x) {
            elem = Util.getElem(elem);
            var y = Util.getAvailableHeight()/2 - elem.offsetHeight/2;
            x = (typeof x != 'undefined' ) ? x : null;
            Util.move(elem,x,y);
        },

        center_x : function(elem,y) {
            elem = Util.getElem(elem);
            var x = parseInt(Util.getAvailableWidth()/2) - parseInt(elem.offsetWidth/2);
            y = (typeof y != 'undefined' ) ? y : null;
            Util.move(elem,x,y);
        },


        create : function( tagName, id ) {
            var obj = Util.byId(id) || document.createElement( tagName );
            if ( id ) obj.id = id;
            return obj;
        },

        getStyle : function(elem,styleProp) {
            var st
            if (elem.currentStyle)
               st = elem.currentStyle[styleProp];
            else if (window.getComputedStyle)
                st = document.defaultView.getComputedStyle(elem, null).getPropertyValue(styleProp);
            return st;
        },

		getCSSRule : function(ruleName, deleteFlag) {               				// Return requested style class obejct   
		
			ruleName=ruleName.toLowerCase();                       				
			if (document.styleSheets) {                            				// If browser can play with stylesheets      
				for (var i=0; i<document.styleSheets.length; i++) { 			    
					var styleSheet=document.styleSheets[i];          			// Get the current Stylesheet         
					var ii=0;                                        			        
					var cssRule=false;                               			       
					do {                                             			           
						if (styleSheet.cssRules) {                    			             
							cssRule = styleSheet.cssRules[ii];         			// Yes --Mozilla Style            
						} else {                                      			             
							cssRule = styleSheet.rules[ii];            			// Yes IE style.             
						}                                             			          
						if (cssRule)  {                               			              
							if (cssRule.selectorText.toLowerCase()==ruleName) { //  match ruleName?                  
								if (deleteFlag=='delete') {             		// Yes.  Are we deleteing?                     
									if (styleSheet.cssRules) {           		                        
										styleSheet.deleteRule(ii);        		// Delete rule, Moz Style                     
									} 
									else {                             			               
										styleSheet.removeRule(ii);        		// Delete rule IE style.                     
									}                                    		                   
									return true;                         		// return true, class deleted.                  
								} 
								else {                                			// found and not deleting.                     
									return cssRule;                      		// return the style object.                  
								}                                       		              
							}                                          			         
				 		}                                             			       
			  			ii++;                                         		     
			  		} while (cssRule)                                		 
			  	}                                                   		
			}                                                      			
			return false;                                          				// we found NOTHING!
		},                                                         
		
		//-----------------------------------------------------------------------------------------------
		killCSSRule : function(ruleName) {                          				// Delete a CSS rule      
			return this.getCSSRule(ruleName,'delete');                  				// just call getCSSRule w/delete flag.
		},                                                         				
		//----------------------------------------------------------------------------------------
		addCSSRule : function(ruleName) {                           				// Create a new css rule 
		  
			if (document.styleSheets) {                            				
			    
				if (!getCSSRule(ruleName)) {                        			        
					if (document.styleSheets[0].addRule) {           			// Browser is IE?            
						document.styleSheets[0].addRule(ruleName, null,0);      // Yes, add IE style         
					} 
					else {                                         				// Browser is IE?            
						document.styleSheets[0].insertRule(ruleName+' { }', 0); // Yes, add Moz style.         
					}                                                			    
				}                                                   			
				  
			}                                                      				
			  
			return this.getCSSRule(ruleName);        
		} ,

        cancelBubble : function(evt){
			evt.cancelBubble = true;
			if (typeof evt.stopPropagation != 'undefined') evt.stopPropagation();
			return false;
		},

        isHeightConsumingNode : function(node){ try {
            if (node.nodeType == 1 && node.offsetHeight > 0 ) {
                    if (this.getStyle(node,'visibility') == 'hidden' ) {
                        return false;
                    } else if (this.getStyle(node,'display') == 'none' ) {
                        return false;
                    } else if (this.getStyle(node,'position') == 'absolute' ) {
                        return false;
                    }
                //Util.debug.out( node.nodeName  + " | " + node.nodeType + " | " + node.offsetHeight + " | " + node.currentStyle['visibility'] + " " + node.currentStyle['display'] + " " + node.currentStyle['position'] );
                return true;
            }

            return false;

        } catch(e){alert(e); return false;} },

        Logger : (function(){
            var debug = false;
            var showDebug = false;
            var argCharLimit = 512;

            var accum = "";

            return {
                formatFunction : function(func, args) {
                    var tmp = ""+ func; //create a string
                    var fff = "function ";
                    tmp = tmp.substring( fff.length, tmp.indexOf(")")+1 ) + "\n";

                    tmp += "arguments = [ ";
                    for ( var i = 0; i < args.length; i++ ) {
                        tmp += args[i] + ((i+1 < args.length)?", ":"");
                    }
                    tmp+= "]\n";

                    tmp = (tmp.length < argCharLimit)?tmp: tmp.substring(0,argCharLimit)+"...]\n";

                    return tmp;

                },

                error : function(args, ex, lastData) {
                    //alert(arguments.callee.caller);
                    var val = this.formatFunction(arguments.callee.caller,args) + ex.message
                    if (debug) accum += val + "\n";
                    if ( showDebug ) alert(val + ((lastData)?"\n Last="+lastData:"") );
                }
            };

        }()),

        collectionToArray : function(col) {
            var a = new Array();
            for (var i = 0; i < col.length; i++)
                a.push(col[i]);
            return a;
        },


        fireEventOnElement : function( evtName, elem ) {

        	this.fireEventOnElement( "change", rowControl,null );
        },
        
        fireEventOnElement : function( evtName, elem,excludeMethod ) {//Added overloaded method for PR 74638 

            //The name of the event (append on to the beginning of the event call)
            var elemEvent = elem.getAttribute( "on" + evtName );
            //If an event handler was found
            if(elemEvent != null){
                //Convert to string, modify the function and extract the inner function
                var sEvent = elemEvent.toString();
                var re = new RegExp ( "this" , 'gi');
                sEvent = sEvent.replace( re, "elem"  );
                var re2 = new RegExp ( "return" , 'gi');
                sEvent = sEvent.replace( re2, " "  );
                
				//PR 74638-Start							   
                if(excludeMethod != null && sEvent.indexOf(excludeMethod) > -1)
                {
                	var index = sEvent.indexOf(excludeMethod);                	
                	sEvent = sEvent.substring(0,index) + sEvent.substring(index + excludeMethod.length,sEvent.length);
                }
            	//PR 74638-End

                var handlerStart = sEvent.indexOf('{');
                if(Util.isIE){
                    sEvent = sEvent.substring(handlerStart+2,sEvent.length-2);
                }

                return eval( sEvent );
            }
        },

        setElementProperties : function ( element, configProperties ) { try{
            for ( var k in configProperties ) {
                if (k.indexOf("style_") == 0 ) {
                    var styleName = k.substr(6,k.length);
                    element.style[styleName] = configProperties[k];
                } else {
                    element[k] = configProperties[k];
                }
            }

            return element;
        } catch(e){alert(e.message);}  }, // finally{ console.log("setElementProperties("+element+","+configProperties+")"); } },

        /**
         *  return true if value found in list
         * @param: isOptions is used to check a html select object options list
         */
        isInList : function(list, value, isOptions) {
            return ( Util.findIndex(list,value,isOptions) != -1);
        },

        getEvent : function(evt) {
            return (typeof evt != 'undefined') ? evt : event;
        },

        getKey : function( evt ) {
           return (navigator.appName == "Netscape") ? evt.which : event.keyCode;
        },
            
        /**
         * Return the index in the list of the value is found.
         * Return -1 if not found.
         * @param: isOptions is used to check a html select object options list
         */
        findIndex : function( list, value, isOptions ) {

            var ret = -1;
            for ( var i = 0; i < list.length; i++ ) {
                if  (list[i] == value || (isOptions && list[i].value == value) ) {
                    ret = i;
                }
            }

            return ret;
        },

        capFirstChar : function(val) {
            var newVal = '';
            var vals = val.split(' ');
            for(var c=0; c < vals.length; c++) {
                newVal += vals[c].substring(0,1).toUpperCase() +
                vals[c].substring(1,vals[c].length) + ' ';
            }
            return newVal;
        },

        lowerFirstChar : function(val) {
            var newVal = '';
            var vals = val.split(' ');
            for(var c=0; c < vals.length; c++) {
                newVal += vals[c].substring(0,1).toLowerCase() +
                vals[c].substring(1,vals[c].length) + ' ';
            }
            return newVal;
        },

        closeDialog : function(name){try{
            top.$(top.document).trigger("dialogclose");
            top.$(".ui-dialog").remove();
            }catch(e){try{
                $(document).trigger("dialogclose");
                $(".ui-dialog").remove();
            }catch(e){}}
        },
        
        debug : {
            debugging : true,
            out : function(str){
                if ( Util.debug.debugging ) {
                    if ( !Util.byId("debug") ) {
                        var dbgElem = Util.create("div");
                        dbgElem.id = 'debug';
                        document.body.appendChild(dbgElem); 
                    }

                    Util.byId("debug").style.display = "block";
                    Util.byId("debug").innerHTML += str + "<br>";
                }
            }
        },

        dout : function(str){
            this.debug.out(str);   
        },
		
		removeAllChildren : function(elem){
		
		   	if(elem == undefined || elem == null)
		   		return;
			while (elem.hasChildNodes()) 
				elem.removeChild(elem.firstChild);
		},

        /**
            by id
            by class name
        */
        findFramesObject : function(frame, objectName){
            for(var i = 0; i < frame.frames.length; i++) {
                if( frame.frames[i].$("#"+objectName) ) {
                    return frame.frames[i].$("#"+objectName)
                } else if( frame.frames[i].$("."+objectName) ) {
                    return frame.frames[i].$("."+objectName)
                } else {
                    var object = Nav_findObjectFromOtherFrames(frame.frames[i], objectName);

                    if(object != null)  return object;
                }
            }
            return null;
        },

        getEventSource : function ( evt ) {
            if ( navigator.appName == "Netscape" ) {
                return evt.currentTarget;
            } else {
                return event.srcElement;
            }
        },
		//----------------------------------------------------------------------------------------
		//The method creates a deep copy of an object so any modification, at any level, in the copy
		//does not affect the original object
		getObjectCopy : function(obj) {
	
	        var objCopy;
			
			//The argument that was passed is an object or array ( array is also an object type)
	        if (typeof obj == 'object'){
			
				objCopy = {};
			
	            for (var k in obj){
	
					var objField = obj[k];
					//The field is an object
					if ( typeof objField == 'object'){
		                //The field is an array, copy the array
		                if ( typeof objField.length != 'undefined'){
		                    objCopy[k] = this.getArrayCopy(objField);
						}
		                //Otherwise, iterate and copy the object
		                else {
		                    objCopy[k] = this.getObjectCopy(objField);
						}
					}
	                //The field is primitive
	                else{
	                    objCopy[k] = objField;
					}
	
				}
			}
			//The argument that was passed was a primitive
			else{
				objCopy = obj;
			}
	
	        return objCopy;
	    },
		//-------------------------------------------------------------------------------
		//The method creates a deep copy of an array so any modification, at any level, in the copy
		//does not affect the original array. The array members themselves can be arrays or objects
	    getArrayCopy : function(arr) {
		
	        var arrCopy = [];
	
	        for (var i = 0; i < arr.length; i++){
				
				var arrMember = arr[i];
				//The member can be an object or another array
	            if (typeof arr[i] == 'object'){
					//It is an array
					if ( typeof arrMember.length != 'undefined'){
						arrCopy.push(this.getArrayCopy(arrMember));
					}
					//It is an object
					else{
	                	arrCopy.push(this.getObjectCopy(arrMember));
					}
				}
				//The member is a primitive
	            else{
	                arrCopy.push(arrMember);
				}
			}
	
	        return arrCopy;
	    },
		
		//-------------------------------------------------------------
		getHtmlToChars : function(){
		
			var htmlToChars = [];
			htmlToChars["&amp;"] = "&";
			htmlToChars["&lt;"] = "<";
			htmlToChars["&gt;"] = ">";
			htmlToChars["&quot;"] = "\"";
			htmlToChars["&tilde;"] = "~";
			htmlToChars["&ndash;"] = "–";
			htmlToChars["&mdash;"] = "—";
			htmlToChars["&nbsp;"] = " ";
			htmlToChars["&lsquo;"] = "‘";
			htmlToChars["&rsquo;"] = "’";
			htmlToChars["&ldquo;"] = "“";
			htmlToChars["&rdquo;"] = "”";
			htmlToChars["&dagger;"] = "†";
			htmlToChars["&Dagger;"] = "‡";
			htmlToChars["&euro;"] = "€";
			htmlToChars["&lsaquo;"] = "‹";
			htmlToChars["&rsaquo;"] = "›";
			
			return htmlToChars;
		},
		//------------------------------------------------------------------------
		getCharsToHtml : function(){
			var htmlToChars = this.getHtmlToChars();
			var charsToHtml = [];
			for( htm in htmlToChars){
				charsToHtml[htmlToChars[htm]] = htm;
			}
			return charsToHtml;
		},
		//-----------------------------------------------------------------------------
		htmlToChars : null,
		charsToHtml : null,
		//--------------------------------------------------------------------------
		decodeHtml : function(str){
			
			if(this.htmlToChars == null) this.htmlToChars = this.getHtmlToChars();
		
			for( htm in this.htmlToChars){
				var reg = new RegExp(htm, "g");
				str = str.replace(reg, this.htmlToChars[htm]);
			}
			return str
		},
		//------------------------------------------------------------------------
		 encodeHtml : function (str){
		 
		 	if(this.charsToHtml == null) this.charsToHtml = this.getCharsToHtml();
			
			for( chr in this.charsToHtml){
				var reg = new RegExp(chr, "g");
				str = str.replace(reg, this.charsToHtml[chr]);
			}
			return str
		}


    }; //return

}());


//
// Override window.open and all nav.js popup calls
//
/*
if ( top && top.showPopup ) {
    window.open2 = function(url, winName, params ){

        var name = top.showPopup( url, winName, params );

        return top.frames[name];
    }

    try{
        window.open = window.open2;
        window.opener = top;
        parent.close = Util.closeDialog;
        window.close = Util.closeDialog;
        top.close = Util.closeDialog;
        self.close = Util.closeDialog;
    }catch(e){alert('error in open and close override: ' + e.message );  }
}
*/

