	function escapeSingleQuote(str) {
		str = str.replace(/\\/g,"\\\\");
		str = str.replace(/\'/g,"\\\'");
		return str;
	}

	function SidwViewRow(idx, name, text, onclickEvent) {
		this.idx = idx;
		this.name = name;
		this.text = text;
		this.onclickEvent = onclickEvent;
		this.renderRow = renderRow;

		this.isVisible = true;
		this.isDim = false;
	}

	function renderRow() {
		if (!this.isVisible) {
			return "";
		}

	    var str = "<tr height='19'><td id='sideViewRow_"+this.name+"'";
	    if (this.isDim) {
	        str += " class='topMLDim'>";
	    } else {
	        str += " class='topMLOff' onmouseover=this.className='topMLOn' onmouseout=this.className='topMLOff' onclick=\"hideSideView();clickAreaCheck=true;"+this.onclickEvent+";\">";
	    }
	    str += this.text + "</td></tr>";
	    return str;
	}

	function SideViewAdmin(targetObj, curObj, targetIP, targetID, is_block) {
		this.targetObj = targetObj;
		this.curObj = curObj;
		this.targetIP = targetIP;
		this.targetID = targetID;
		this.showMMLayer = showMMLayer;
		this.makeNameContextMenus = makeNameContextMenus;
		this.heads = new Array();
		this.insertHead = insertHead;
		this.tails = new Array();
		this.insertTail = insertTail;
		this.getRow = getRow;
		this.hideRow = hideRow;
		this.dimRow = dimRow;


      this.insertTail("IP Trace", "<b>IP Trace</b>", "ipTrace('"+this.targetIP+"')");
      if(is_block) this.insertTail("Block", "Block", "ipBlock('"+this.targetIP+"','"+this.targetID+"')");


	}
	function SideView(targetObj, curObj, myID, targetID, tWeb, tPix, tPM) {
		this.targetObj = targetObj;
		this.curObj = curObj;
		this.myID = myID;
		this.targetID = targetID;
		this.showMMLayer = showMMLayer;
		this.makeNameContextMenus = makeNameContextMenus;
		this.heads = new Array();
		this.insertHead = insertHead;
		this.tails = new Array();
		this.insertTail = insertTail;
		this.getRow = getRow;
		this.hideRow = hideRow;
		this.dimRow = dimRow;

	    if(tPix != '') {
        this.insertTail("Picture","<center><img name='mpic' src='"+tPix+"' width=100 vspace=2></center>","goProfile('"+this.targetID+"')");
        timerID = setTimeout("refreshImg('"+tPix+"')", 10);
      }

      this.insertTail("Profile", "<b>"+mm_profile+"</b>", "goProfile('"+this.targetID+"')");

		  if(tPM) {
		   this.insertTail("Private Message", mm_pms, "goSendWebMsg('"+this.myID+"','"+this.targetID+"')");
	     this.insertTail("Add to contacts", mm_adcontact, "add2contact('"+this.myID+"', '"+this.targetID+"')");
      }

	    this.insertTail("Send mail", mm_smail, "goSendMail('"+this.myID+"', '"+this.targetID+"')");

      if(tWeb != '') {
       this.insertTail("Website", mm_www, "goURL('"+tWeb+"')");
      }

		  if( this.targetID == this.myID ) {
	    }
	}

function refreshImg(mypic) {
	 document.images['mpic'].src = mypic;

	}


var ie5 = document.all?true:false;
function showMMLayer() {
 clickAreaCheck = true;
		var oSideViewLayer = document.getElementById(this.targetObj);
		var oBody = document.body;
	    if (oSideViewLayer == null) {
	        oSideViewLayer = document.createElement("DIV");
	        oSideViewLayer.id = this.targetObj;
	        oSideViewLayer.style.position = 'absolute';
			    oSideViewLayer.style.zIndex = '9999999';
			    oBody.appendChild(oSideViewLayer);
	    }
	    oSideViewLayer.innerHTML = this.makeNameContextMenus();

	    if(ie5) {
	      var rightedge=document.body.clientWidth-event.clientX;
        var bottomedge=document.body.clientHeight-event.clientY;

        if (getAbsoluteLeft(this.curObj) + this.curObj.offsetWidth + oSideViewLayer.scrollWidth > oBody.scrollWidth) {
            oSideViewLayer.style.left = (getAbsoluteLeft(this.curObj) - this.curObj.offsetWidth) - oSideViewLayer.scrollWidth;
        } else {
            //oSideViewLayer.style.left = getAbsoluteLeft(this.curObj) - this.curObj.offsetWidth;
           oSideViewLayer.style.left = getAbsoluteLeft(this.curObj);
        }
        if (bottomedge< oSideViewLayer.scrollHeight) {
         oSideViewLayer.style.top = getAbsoluteTop(this.curObj) + this.curObj.offsetHeight - oSideViewLayer.scrollHeight;
        } else {
            //oSideViewLayer.style.top = getAbsoluteTop(this.curObj) + this.curObj.offsetHeight;
            oSideViewLayer.style.top = getAbsoluteTop(this.curObj);
        }
      } else {

        if (getAbsoluteTop(this.curObj) + this.curObj.offsetHeight + oSideViewLayer.scrollHeight + 100 > oBody.scrollHeight) {
            oSideViewLayer.style.top = getAbsoluteTop(this.curObj) + this.curObj.offsetHeight - oSideViewLayer.scrollHeight;
        } else {
            //oSideViewLayer.style.top = getAbsoluteTop(this.curObj) + this.curObj.offsetHeight;
            oSideViewLayer.style.top = getAbsoluteTop(this.curObj);
        }
        if (getAbsoluteLeft(this.curObj) + this.curObj.offsetWidth + oSideViewLayer.scrollWidth > oBody.scrollWidth) {
            oSideViewLayer.style.left = (getAbsoluteLeft(this.curObj) - this.curObj.offsetWidth) - oSideViewLayer.scrollWidth;
        } else {
            //oSideViewLayer.style.left = getAbsoluteLeft(this.curObj) - this.curObj.offsetWidth;
           oSideViewLayer.style.left = getAbsoluteLeft(this.curObj);
        }
     }
     divDisplay(this.targetObj, 'block');

}

	function makeNameContextMenus() {
      var str = "<table border='0' cellpadding='0' cellspacing='0' width='120' style='border:#cacaca solid 1px' bgcolor='#FFFFFF'>";

	    var i=0;
	    for (i=this.heads.length - 1; i >= 0; i--) {
	    	str += this.heads[i].renderRow();
	    }

	    var j=0;
	    for (j=0; j < this.tails.length; j++) {
		    str += this.tails[j].renderRow();
	    }

	    str += "</table>";

	    return str;
	}

	function getRow(name) {
		var i = 0;
		var row = null;
		for (i=0; i<this.heads.length; ++i) {
			row = this.heads[i];
			if (row.name == name) return row;
		}
		for (i=0; i<this.tails.length; ++i) {
			row = this.tails[i];
			if (row.name == name) return row;
		}
		return row;
	}

	function hideRow(name) {
		var row = this.getRow(name);
		if (row != null) {
			row.isVisible = false;
		}
	}

	function dimRow(name) {
		var row = this.getRow(name);
		if (row != null) {
			row.isDim = true;
		}
	}

	function insertHead(name, text, evt) {
		var idx = this.heads.length;
		var row = new SidwViewRow(-idx, name, text, evt);
		this.heads[idx] = row;
		return row;
	}

	function insertTail(name, text, evt) {
		var idx = this.tails.length;
		var row = new SidwViewRow(idx, name, text, evt);
		this.tails[idx] = row;
		return row;
	}

	// global function

	function initCSS() {
		var stl = "<style type='text/css'>";
		stl += ".topMLId { color:#9A845E; font-size:10pt; font-family:tahoma,verdana; padding-top:4px; padding-left:4px; }";
		stl += ".topMLOff { background-Color:#FFFFFF; font-size:10pt; font-family:tahoma,verdana; font-weight:normal; padding-top:4px; padding-left:4px; }";
		stl += ".topMLOn { background-Color:#F3EEE2; font-size:10pt; font-family:tahoma,verdana; font-weight:bold; padding-top:4px; padding-left:4px; cursor:hand;}";
		stl += ".topMLDim { background-Color:#FFFFFF; font-size:10pt; font-family:tahoma,verdana; font-weight:normal; color:#9C9C9C; padding-top:4px; padding-left:4px; }";
		stl += ".topSLOff { background-Color:#FFFFFF; font-size:10pt; font-family:tahoma,verdana; padding-top:4px; padding-left:4px; }";
		stl += ".topSLOn { background-Color:#F3EEE2; font-size:10pt; font-family:tahoma,verdana; padding-top:4px; padding-left:4px; cursor:hand; }";
		stl += ".topSLDim { background-Color:#FFFFFF; font-size:10pt; font-family:tahoma,verdana; color:#9C9C9C; padding-top:4px; padding-left:4px; }";
		stl += "</style>";
		document.write(stl);
	}

	function getCafeUrl(url) {
		return url;
	}

	function goURL(url) {
	  window.open(url,'_blank');
	}


	function add2contact(myID, targetID) {
	var iframeObj = document.createElement('IFRAME');
     iframeObj.setAttribute('name','hiddenFrame');
     iframeObj.setAttribute('src','pop.php?langFile='+langFile+'&theme='+theme+'&mid='+mid+'&rq=add2contact&IdNo='+myID+'&targetID='+targetID);
     iframeObj.setAttribute('width','0');
     iframeObj.setAttribute('height','0');
     iframeObj.setAttribute('style','visibility:hidden');
     document.body.appendChild(iframeObj);

	}
	function goProfile(targetID) {

	    //var url = getCafeUrl('member_profile.php?userid='+targetID+'&langFile='+langFile+'&theme='+theme+'&mid='+mid);
	    //window.open(url, 'profile', 'width=470,height=540,resizable=no,scrollbars=1');
	    pop('user_profile',targetID);
	}



	function goSendMail( myID, targetID) {

		 IdNo = myID + ":" + targetID;
		 pop('send_mail', IdNo);
	}


	// SEND PM
	function goSendWebMsg(myID,targetID) {
		 IdNo = myID + ":" + targetID;
		 pop('send_pm', IdNo);

	}

 function ipTrace(IP) {
   var formObj = document.createElement('FORM');
   formObj.setAttribute('method', 'POST');
   formObj.setAttribute('action','http://www.ip-adress.com/ipaddresstolocation/?ip='+IP);
   formObj.setAttribute('target','_blank');
   formObj.setAttribute('style','visibility:hidden');
    var inputObj = document.createElement('INPUT');
    inputObj.type = 'text';
    inputObj.name = 'QRY';
    inputObj.value = IP;
    formObj.appendChild(inputObj);
    document.body.appendChild(formObj);
   formObj.submit();
  }
  function ipBlock(targetIP, targetID) {
  	var is_confirmed = confirm('Are you sure you want to block this ip?');
  	if(is_confirmed) {
  	 IdNo = targetIP + ":" + targetID;
     pop('ipBlock', IdNo);
    } else {
    	return false;
    }
  }

	function getAbsoluteTop(oNode){
		var oCurrentNode=oNode;
		var iTop=0;
		while(oCurrentNode.tagName!="BODY"){
			iTop+=oCurrentNode.offsetTop - oCurrentNode.scrollTop;
			oCurrentNode=oCurrentNode.offsetParent;
		}
		return iTop;
	}


	function getAbsoluteLeft(oNode){
		var oCurrentNode=oNode;
		var iLeft=0;
		iLeft+=oCurrentNode.offsetWidth;
		while(oCurrentNode.tagName!="BODY"){
			iLeft+=oCurrentNode.offsetLeft;
			oCurrentNode=oCurrentNode.offsetParent;
		}
		return iLeft;
	}

	function divDisplay(id, act) {
		document.getElementById(id).style.display = act;
	}

	function hideSideView() {
        if (document.getElementById("nameContextMenu")) {
            divDisplay ("nameContextMenu", 'none');
        }
        if (document.getElementById("ie5menu")) {
            document.getElementById("ie5menu").style.visibility = 'hidden';
        }

	}


	var clickAreaCheck = false;
	document.onclick = function() {
	    if (!clickAreaCheck) {
	    	hideSideView();
      } else {
			  clickAreaCheck = false;
		}
	}


