	var ie5=document.all&&document.getElementById;
	var ns6=document.getElementById&&!document.all;
	var left = 0;
	var top = 0;
	var firingobj;
	
	document.oncontextmenu = context_menu;
			
	function keepAlive () {
	    //nonRefreshUpdate("/common/js/keepalive.asp", "");
	    nonRefreshUpdate('/common/pages/side_box_comms_data.asp', 'type=refresh', 'V2');
	}
	
	function context_menu (e) {
		firingobj = ie5? event.srcElement : e.target;
		return false;
		//if(firingobj.id){ 
		//	return false;
		//}
	}
			
	function findPosX(obj) {
		var curLeft = 0;
		if(obj.offsetParent) {
			while(1) {
				curLeft += obj.offsetLeft;
				if(!obj.offsetParent)
					break;
				obj = obj.offsetParent;
			}
		} else if(obj.x) {
			curLeft += obj.x;
		}
		return curLeft;
	}
			
	function findPosY(obj) {
		var curTop = 0;
		if(obj.offsetParent) {
			while(1) {
				curTop += obj.offsetTop;
				if(!obj.offsetParent)
					break;
				obj = obj.offsetParent;
			}
		} else if(obj.y) {
			curTop += obj.y;
		}
		return curTop;
	}
			
	function findPosXY(obj) {
		var curLeft = 0;
		var curTop = 0;
		if(obj.offsetParent) {
			while(1) {
				curLeft += obj.offsetLeft;
				curTop += obj.offsetTop;
				if(!obj.offsetParent)
					break;
				obj = obj.offsetParent;
			}
		} else if(obj.x) {
			curLeft += obj.x;
			curTop += obj.y;
		}
		return [curLeft, curTop];
	}
	
	function findMouseX(e) {
		if(!ie5){
			left = e.pageX ;
		} else {
			left = e.clientX + document.documentElement.scrollLeft;
		}
		return left;
	}
	
	function findMouseY(e) {
		if(!ie5){
			top = e.pageY ;
		} else {
			top = e.clientY + document.documentElement.scrollTop;
		}
		return top;
	}
	
	function findMouseButton(e) {
	    if (e.which) {
	        if (e.which==2 || e.which==3) {
	            return 2;
	        } else {
	            return 1;
	        }
	    } else if (e.button) {
	        return e.button;
	    }
    }
	
	function getOffsetHeight(id) {
        h = Number.NaN;
        if (document.getElementById) {
            var ele = document.getElementById(id);
            if (ele && typeof ele.offsetHeight != 'undefined') {
                h = ele.offsetHeight;
            }
        }
        return h;
    }
	
	function getOffsetWidth(id) {
        h = Number.NaN;
        if (document.getElementById) {
            var ele = document.getElementById(id);
            if (ele && typeof ele.offsetWidth != 'undefined') {
                h = ele.offsetWidth;
            }
        }
        return h;
    }
    
    function getPageHeight() {
        if( window.innerHeight && window.scrollMaxY ) { // Firefox
            pageHeight = window.innerHeight + window.scrollMaxY;
        } else if( document.body.scrollHeight > document.body.offsetHeight ) { // all but Explorer Mac
            pageHeight = document.body.scrollHeight;
        } else {// works in Explorer 6 Strict, Mozilla (not FF) and Safari
            pageHeight = document.body.offsetHeight + document.body.offsetTop; 
        }
        return pageHeight
    }
    
    function getPageWidth() {
        if( window.innerHeight && window.scrollMaxY ) { // Firefox
            pageWidth = window.innerWidth + window.scrollMaxX;
        } else if( document.body.scrollHeight > document.body.offsetHeight ) { // all but Explorer Mac
            pageWidth = document.body.scrollWidth;
        } else {// works in Explorer 6 Strict, Mozilla (not FF) and Safari
            pageWidth = document.body.offsetWidth + document.body.offsetLeft; 
        }
        return pageWidth
    }
    
    function getPageXY() {
        if( window.innerHeight && window.scrollMaxY ) { // Firefox
            pageWidth = window.innerWidth + window.scrollMaxX;
            pageHeight = window.innerHeight + window.scrollMaxY;
        } else if( document.body.scrollHeight > document.body.offsetHeight ) { // all but Explorer Mac
            pageWidth = document.body.scrollWidth;
            pageHeight = document.body.scrollHeight;
        } else {// works in Explorer 6 Strict, Mozilla (not FF) and Safari
            pageWidth = document.body.offsetWidth + document.body.offsetLeft; 
            pageHeight = document.body.offsetHeight + document.body.offsetTop; 
        }
        return [pageWidth, pageHeight]
    }
    
    function getVisibleXY() {
        var winWidth, d=document; 
        if (typeof window.innerWidth!='undefined') { 
            winWidth = window.innerWidth; 
            winHeight = window.innerHeight; 
        } else { 
            if (d.documentElement && typeof d.documentElement.clientWidth!='undefined' && d.documentElement.clientWidth!=0) { 
                winWidth = d.documentElement.clientWidth 
                winHeight = d.documentElement.clientHeight 
            } else { 
                if (d.body && typeof d.body.clientWidth!='undefined') { 
                    winWidth = d.body.clientWidth 
                    winHeight = d.body.clientHeight 
                } 
            } 
        }
        return [winWidth, winHeight];
    }
    
    function getScrollXY() {
        var scrOfX = 0, scrOfY = 0;
        if( typeof( window.pageYOffset ) == 'number' ) {
            //Netscape compliant
            scrOfY = window.pageYOffset;
            scrOfX = window.pageXOffset;
        } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
            //DOM compliant
            scrOfY = document.body.scrollTop;
            scrOfX = document.body.scrollLeft;
        } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
            //IE6 standards compliant mode
            scrOfY = document.documentElement.scrollTop;
            scrOfX = document.documentElement.scrollLeft;
        }
        return [ scrOfX, scrOfY ];
    }
	
	function rowChange(i, nColor){
		if (!nColor) nColor = "";
		document.getElementById(i).style.backgroundColor = nColor;
		var i = 2
		for (i = 2; i < arguments.length; i++) {
		    document.getElementById(arguments[i]).style.backgroundColor = nColor;
		}
	}
	
	function colChange(nColor){
		if (!nColor) nColor = "";
		var i=1
		for (i=1; i<arguments.length; i++) {
			document.getElementById(arguments[i]).style.backgroundColor=nColor;
		}
    }

    function select_item(selected_item, status, other_border, btn) {
        if (status == 1) {
            if (!(other_border)) {
                other_border = "1px solid #004488"
            }
            selected_item.style.border = other_border;
            
            selected_item.focus();
            if (selected_item.select) {
                selected_item.select();
            }
            
            if (btn) {
                document.getElementById(btn).style.display = "";
            }
        } else {
            if (!(other_border)) {
                other_border = "none"
            }
            selected_item.style.border = other_border;
            if (btn) {
                document.getElementById(btn).style.display = "none";
            }

            selected_item.value = selected_item.value;
        }
    }
	
	function pageChange(page) {
		window.location = page;
	}
		
	function showDataContentClass(rowId, dataRowId, showstate, rowNum, itemID) {
		this.rowId = rowId;
		this.dataRowId = dataRowId;
		this.showstate = showstate;
		this.rowNum = rowNum;
		this.itemID = itemID;
	}
	
	var showDataContentStatus = new Array();
	function showDataContent(rowId, dataRowId, showstate, rowNum, itemID) {
		
	    if (showstate==0) {
			if (document.getElementById(dataRowId)) {
				document.getElementById(dataRowId).style.display = "";
				document.getElementById(rowId).showstate = 1;
				document.getElementById(rowId).setAttribute('showstate', 1);
				if(rowNum) {
					showDataContentStatus[rowNum] = new showDataContentClass(rowId, dataRowId, showstate, rowNum, itemID)
				}
			} else {
				if(rowNum) {
					showDataContentStatus[rowNum] = new showDataContentClass(0, 0, 0, rowNum, 0)
				}
			}
	    } else {
			if (document.getElementById(dataRowId)) {
				document.getElementById(dataRowId).style.display = "none";
				document.getElementById(rowId).showstate = 0;
				document.getElementById(rowId).setAttribute('showstate', 0);
				if(rowNum) {
					showDataContentStatus[rowNum] = new showDataContentClass(rowId, dataRowId, showstate, rowNum, itemID)
				}
			} else {
				if(rowNum) {
					showDataContentStatus[rowNum] = new showDataContentClass(0, 0, 0, rowNum, 0)
				}
			}
	    }
	}
	
	function findTopMostLayer() {
        var allElems = document.getElementsByTagName ? document.getElementsByTagName("*") : document.all;
        var maxZIndex = 0;
        for(var i=0; i < allElems.length; i++) {
            var elem = allElems[i];
            var cStyle = null;
            if (elem.currentStyle) {
                cStyle = elem.currentStyle;
            } else if (document.defaultView && document.defaultView.getComputedStyle) {
                cStyle = document.defaultView.getComputedStyle(elem,"");
            }
            var sNum;
            if (cStyle) {
                sNum = Number(cStyle.zIndex);
            } else {
                sNum = Number(elem.style.zIndex);
            }
            if (!isNaN(sNum)) {
                maxZIndex = Math.max(maxZIndex,sNum);
            }
        }
        return maxZIndex;
	}
    
    function checkKey(e) {
        var ctrlPressed=0;
        var altPressed=0;
        var shiftPressed=0;

        if (parseInt(navigator.appVersion)>3) {

            var evt = navigator.appName=="Netscape" ? e:event;

            if (navigator.appName=="Netscape" && parseInt(navigator.appVersion)==4) {
                // NETSCAPE 4 CODE
                var mString =(e.modifiers+32).toString(2).substring(3,6);
                shiftPressed=(mString.charAt(0)=="1");
                ctrlPressed =(mString.charAt(1)=="1");
                altPressed  =(mString.charAt(2)=="1");
            }  else {
                // NEWER BROWSERS [CROSS-PLATFORM]
                shiftPressed=evt.shiftKey;
                altPressed  =evt.altKey;
                ctrlPressed =evt.ctrlKey;
            }
        }
        return [ctrlPressed, altPressed, shiftPressed];
    }
	
	function checkEnter(e) {
		var characterCode

		if(e && e.which){ //if which property of event object is supported (NN4)
			e = e;
			characterCode = e.which; //character code is contained in NN4's which property
		} else {
			e = e;
			characterCode = e.keyCode; //character code is contained in IE's keyCode property
		}
		
		if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
			return true;
		} else {
			return false; 
		}
	}
    
    function clearSelection() {
        var sel ;
        if(document.selection && document.selection.empty){
            document.selection.empty() ;
        } else if(window.getSelection) {
            sel=window.getSelection();
            if(sel && sel.removeAllRanges)
            sel.removeAllRanges() ;
            sel.collapse();
        }
    }
    
    

    function trim(stringToTrim) {
	    return stringToTrim.replace(/^\s+|\s+$/g,"");
    }

    function ltrim(stringToTrim) {
	    return stringToTrim.replace(/^\s+/,"");
    }
    function rtrim(stringToTrim) {
	    return stringToTrim.replace(/\s+$/,"");
    }
    
    function Left(str, n){
	    if (n <= 0)
	        return "";
	    else if (n > String(str).length)
	        return str;
	    else
	        return String(str).substring(0,n);
    }
    function Right(str, n){
        if (n <= 0)
           return "";
        else if (n > String(str).length)
           return str;
        else {
           var iLen = String(str).length;
           return String(str).substring(iLen, iLen - n);
        }
    }
	
	function GetTime(time) {
		if(time == null)
		{
		   return("");
		}

		if(time > 60)
		{                                 // if time == 100
		   var seconds = time % 60;       // seconds == 40
		   var minutes = time - seconds;  // minutes == 60
		   minutes     = minutes / 60;    // minutes == 1


		   if(minutes > 60)
		   {                                     // if minutes == 100
			  var minLeft = minutes % 60;        // minLeft    == 40
			  var hours   = minutes - minLeft;   // hours      == 60
			  hours       = hours / 60;          // hours      == 1
			  if(String(hours).length==1) {
				 hours = "0" +  hours
			  }
			  if(String(minLeft).length==1) {
				 minLeft = "0" +  minLeft
			  }
			  if(String(seconds).length==1) {
				 seconds = "0" +  seconds
			  }
			  return(hours + ":" + minLeft + ":" + seconds + " ");
		   }
		   else
		   {
			  if(String(minutes).length==1) {
				 minutes = "0" +  minutes
			  }
			  if(String(seconds).length==1) {
				 seconds = "0" +  seconds
			  }
			  return("00:" + minutes + ":" + seconds);
		   }
		}
		else
		{
		   return("00:00:" + time);
		}
	 }
