function MsnimUtils(showErrorFrameInTopWindow){
	var msnimUtils=this;
	this.lastLinkState="complete";
	this.lastClickedElement;
	this.showErrorFrameInTopWindow=showErrorFrameInTopWindow||true;
	this.onMsnimClickProxy=function (hrefObject){
		this.lastClickedElement=hrefObject;
		this.onMsnimClick(hrefObject);
		
	};
	this.onMsnimClick=function (hrefObject){
		alert("[function MsnimUtils.onMsnimClick]\r\nid = "+hrefObject.id+" ,href = "+hrefObject.href+"\r\n\r\n"+"::Overwrite this function for specific use:)");
		
	};
	MsnimUtils.requestAjax=function (url){
		if(url==null||url.length==0||url.indexOf("http://")<0)return ;
		if(!this.ajaxInited)MsnimUtils.initAjax();
		if("?"!=url.substring(url.length-1,"?"))url=url+"?";
		var msnimajaxform=document.getElementById("msnimajaxform");
		msnimajaxform.action=url;
		msnimajaxform.method="post";
		var innerHTMLBuffer="";
		for(var i=1;i<arguments.length;i=i+2){
			innerHTMLBuffer+="<input type=hidden name='"+arguments[i]+"' value='"+arguments[i+1]+"'>";
			
		}msnimajaxform.innerHTML=innerHTMLBuffer;
		msnimajaxform.submit();
		
	};
	MsnimUtils.ajaxInited=false;
	MsnimUtils.initAjax=function (){
		this.ajaxInited=true;
		div=document.createElement("DIV");
		div.innerHTML='<form id="msnimajaxform" name="msnimajaxform" target="msnimajaxiframe" method="post" action="">'+'<input type="hidden" name="info" value="">'+'</form>';
		div.style.display="none";
		document.body.appendChild(div);
		div=document.createElement("DIV");
		div.innerHTML='<iframe id="msnimajaxiframe" src="blank.htm" name="msnimajaxiframe" style="display:none" onload="msnimajaxiframe_onload()"></iframe>';
		div.style.display="none";
		document.body.appendChild(div);
		
	};
	this.noSupportedClient=function (){
		alert("[function MsnimUtils.noSupportedClient]\r\nNo Supported Live Messenger Client!!!\r\n\r\n"+"::Overwrite this function for specific use:)");
		
	};
	this.init=function (){
		var lnk=document.createElement("link");
		lnk.id="link4msnim";
		lnk.rel="stylesheet";
		document.getElementsByTagName("head")[0].appendChild(lnk);
		lnk.onreadystatechange=function (){
			if("complete"==this.readyState&&msnimUtils.lastLinkState!="loading"){
				msnimUtils.noSupportedClient(msnimUtils.lastClickedElement);
				
			}msnimUtils.lastLinkState=this.readyState;
			
		};
		
	};
	this.patch=function (){
		var trefs=document.getElementsByTagName("A");
		if(trefs==null||trefs.length==0)return ;
		for(var i=0;i<trefs.length;i++){
			var g=trefs[i].id;
			var h=trefs[i];
			if(h.href.indexOf("msnim:")!=-1){
				h.rawhref=h.href;
				h.href="#";
				h.onclick=function (){
					if(navigator.appName=="Microsoft Internet Explorer"){
						document.getElementById("link4msnim").href=this.rawhref;
						msnimUtils.onMsnimClickProxy(this);
						
					}else {
						msnimUtils.noSupportedClient(this);
					}return false;
					
				};
				
			}
		}
	};
	this.init();
	this.patch();
	
}
function msnimajaxiframe_onload(){
	var msnimajaxiframe=document.getElementById("msnimajaxiframe");
	try{
		if(msnimajaxiframe.contentWindow.location.href.indexOf("blank.htm")==-1)throw"avoid refreshing";
		
	}catch(e){
		
	}
}
function registerDocumentLoadEventCallback(loadfunc){
	if(window.attachEvent){
		window.attachEvent("onload",loadfunc);
		
	}else if(window.addEventListener){
		window.addEventListener("load",loadfunc,false);
		
	}
}
function getMsnimString(text){
	var msnimPattern=/(msnim:.+=([a-zA-Z0-9][-.\w]+@[\w-.]+))/;
	if(msnimPattern.test(text)){
		return {
			all:RegExp.$1,contact:RegExp.$2
		};
		
	}return null;
	
}
function setCookie(name,value,days,domain){
	if(days){
		var date=new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires="; expires="+date.toGMTString();
		
	}else var expires="";
	document.cookie=name+"="+value+expires+"; path=/; domain="+domain;
	
}
function getCookie(name){
	var nameEQ=name+"=";
	var ca=document.cookie.split(';');
	for(var i=0;i<ca.length;i++){
		var c=ca[i];
		while(c.charAt(0)=='')c=c.substring(1,c.length);
		if(c.indexOf(nameEQ)==0)return c.substring(nameEQ.length,c.length);
		
	}return null;
	
}
function deleteCookie(name){
	setCookie(name,"",-1);
	
}
function getUserInfo(){
	var MSNPassport="";
	var msn=new ActiveXObject("Messenger.UIAutomation");
	var oService=msn.Services;
	var oPrimserv=oService.PrimaryService;
	MSNPassport=oPrimserv.MySigninName;
	return MSNPassport;
	
}
var msnimCheckloaded=false;
var msnimUtils;
function msnimCheck(){
	if(msnimCheckloaded)return ;
	msnimCheckloaded=true;
	var isChildWindow=false;
	if(window.top!=self){
		isChildWindow=true;
		var div=top.document.createElement("DIV");
		div.id="msnimerroriframe_div";
		div.style.position="absolute";
		div.style.display="none";
		div.innerHTML='<iframe id="msnimerroriframe" name="msnimerroriframe" src="" border="0" height="180" width="330" frameBorder=0 scrolling="no"></iframe>';
		var div1=top.document.createElement("DIV");
		div1.id="grouperroriframe_div";
		div1.style.position="absolute";
		div1.style.display="none";
		div1.innerHTML='<iframe id="grouperroriframe" name="grouperroriframe" src="" border="0" height="350" width="402" frameBorder=0 scrolling="no"></iframe>';
		top.document.body.appendChild(div);
		top.document.body.appendChild(div1);
		
	}else {
		var div=document.createElement("DIV");
		div.id="msnimerroriframe_div";
		div.style.position="absolute";
		div.style.display="none";
		div.innerHTML='<iframe id="msnimerroriframe" name="msnimerroriframe" src="" border="0" height="180" width="330" frameBorder=0 scrolling="no"></iframe>';
		var div1=document.createElement("DIV");
		div1.id="grouperroriframe_div";
		div1.style.position="absolute";
		div1.style.display="none";
		div1.innerHTML='<iframe id="grouperroriframe" name="grouperroriframe" src="" border="0" height="350" width="402" frameBorder=0 scrolling="no"></iframe>';
		document.body.appendChild(div);
		document.body.appendChild(div1);
		
	}msnimUtils=new MsnimUtils();
	msnimUtils.onMsnimClick=function (hrefObject){
		var test=getCookie('from');
		var search=getCookie('search');
		var userInfo="";
		try{
			userInfo=getUserInfo();
			
		}catch(err){
			
		}if(test!=null&&test.length>0){
			if(hrefObject.rawhref){
				if(hrefObject.innerHTML.toString ().indexOf("jingpai_ljtj.gif")!=-1){
					MsnimUtils.requestAjax("http://www.xiaoi.com/util/logServlet","id",window.location,"url",hrefObject.rawhref,"from",test,"search",search,"userInfo",userInfo,"error","jingpai_ljtj.gif");
					
				}else {
					MsnimUtils.requestAjax("http://www.xiaoi.com/util/logServlet","id",window.location,"url",hrefObject.rawhref,"from",test,"search",search,"userInfo",userInfo);
					
				}
			}else if(hrefObject.parentElement&&hrefObject.parentElement.rawhref){
				MsnimUtils.requestAjax("http://www.xiaoi.com/util/logServlet","id",window.location,"url",hrefObject.parentElement.rawhref,"from",test,"search",search,"userInfo",userInfo);
				
			}
		}else {
			if(hrefObject.rawhref){
				MsnimUtils.requestAjax("http://www.xiaoi.com/util/logServlet","id",window.location,"url",hrefObject.rawhref,"search",search,"userInfo",userInfo);
				
			}else if(hrefObject.parentElement&&hrefObject.parentElement.rawhref){
				MsnimUtils.requestAjax("http://www.xiaoi.com/util/logServlet","id",window.location,"url",hrefObject.parentElement.rawhref,"search",search,"userInfo",userInfo);
				
			}
		}
	};
	msnimUtils.noSupportedClient=function (hrefObject){
		var test=getCookie('from');
		var search=getCookie('search');
		var userInfo="";
		try{
			userInfo=getUserInfo();
			
		}catch(err){
			
		}if(test!=null&&test.length>0){
			if(hrefObject.rawhref){
				MsnimUtils.requestAjax("http://www.xiaoi.com/util/logServlet","id",window.location,"url",hrefObject.rawhref,"from",test,"search",search,"userInfo",userInfo,"error","noSupported");
				
			}else if(hrefObject.parentElement&&hrefObject.parentElement.rawhref){
				MsnimUtils.requestAjax("http://www.xiaoi.com/util/logServlet","id",window.location,"url",hrefObject.parentElement.rawhref,"from",test,"search",search,"userInfo",userInfo,"error","noSupported");
				
			}
		}else {
			if(hrefObject.rawhref){
				MsnimUtils.requestAjax("http://www.xiaoi.com/util/logServlet","id",window.location,"url",hrefObject.rawhref,"search",search,"userInfo",userInfo,"error","noSupported");
				
			}else if(hrefObject.parentElement&&hrefObject.parentElement.rawhref){
				MsnimUtils.requestAjax("http://www.xiaoi.com/util/logServlet","id",window.location,"url",hrefObject.parentElement.rawhref,"search",search,"userInfo",userInfo,"error","noSupported");
				
			}
		}var x;
		if(hrefObject.rawhref){
			x=hrefObject.rawhref;
			
		}else if(hrefObject.parentElement&&hrefObject.parentElement.rawhref){
			x=hrefObject.parentElement.rawhref;
			
		}else return ;
		var y=x.indexOf('=');
		var z=x.substring(y+1);
		var badded=true;
		try{
			MsgrApp.LaunchAddContactUI(z);
			badded=false;
			
		}catch(e){
			
		}try{
			MsgrObj.AddContact(0,z);
			badded=false;
			
		}catch(e2){
			
		}if(badded){
			var msnimerroriframe_div;
			var msnimerroriframe;
			var myDocument=document;
			if(isChildWindow&&msnimUtils.showErrorFrameInTopWindow){
				myDocument=top.document;
				
			}
			if(hrefObject.id=='g'){
				msnimerroriframe_div=myDocument.getElementById("grouperroriframe_div");
				msnimerroriframe=myDocument.getElementById("grouperroriframe");
				if(!msnimerroriframe.src||msnimerroriframe.src.indexOf("grouphelp.html")==-1){
					msnimerroriframe.src="/grouphelp.html?"+z;
				}else {
					msnimerroriframe.contentWindow.refreshCopyPanel(z);
				}
				window.open('http://group.xiaoi.com/group/msnspace/index.html?p='+z);
			}
			else{
				msnimerroriframe_div=myDocument.getElementById("msnimerroriframe_div");
				msnimerroriframe=myDocument.getElementById("msnimerroriframe");
				if(!msnimerroriframe.src||msnimerroriframe.src.indexOf("msnhelp.html")==-1){
					msnimerroriframe.src="/msnhelp.html?"+z;
				}else {
					msnimerroriframe.contentWindow.refreshCopyPanel(z);
				}
			}
			msnimerroriframe_div.style.display="block";
			var mDocument;
			if(window.top!=self){
				mDocument = top.document;
			}
			else{
				mDocument = document;
			}
			var h1=mDocument.body.clientHeight;
			var h2=mDocument.documentElement.clientHeight;
			var _top=0;
			var _stop=0;
			if(navigator.appName=='Netscape'){
				var isXhtml=(h2<=h1&&h2!=0)?true:false;
				_top=isXhtml?h2/2:h1/2;
				_stop=isXhtml?mDocument.documentElement.scrollTop:mDocument.body.scrollTop;
				
			}else if(navigator.appName=='Opera'){
				_top=h1/2;
				_stop=mDocument.documentElement.scrollTop;
				
			}var top1=_top-msnimerroriframe_div.clientHeight/2+_stop;
			var left1=myDocument.body.clientWidth/2-msnimerroriframe_div.clientWidth/2;
			msnimerroriframe_div.style.top=top1+"px";
			msnimerroriframe_div.style.left=left1+"px";
			
		}
	}
}
registerDocumentLoadEventCallback(msnimCheck);

