var path = "";
//********************************************加好友***********************************************************************//
//好友弹框
function showRequestForm(receiveUserId,receiveUserName,imageStatus,sex,imageUrl)
{	
	path = document.getElementById("path").value;
	showScreen("lockIfr","lockScreen","lockWaitBox",'','','');
	getScreenByStatus("jsAddScreenAddFriend","addFriend",imageStatus,sex,imageUrl,receiveUserId,receiveUserName);
	getScreenByStatus("jsAddScreenInfo","info","","","","","");
	document.getElementById("receiveUserId").value=receiveUserId;
	XMLHttp.sendReq('post', ''+path+'/ajax/relationAjax.html?operationType=checkFriend&reId='+receiveUserId, '', checkFriendAjax);
}

function checkFriendAjax(http_request)
{
	/*是否成功请求*/
    if(http_request.responseText!="")
    {
    	 var results=http_request.responseXML;
		 var roots=results.documentElement;
		 var ajaxMessage=roots.getAttribute("ajaxMessage");
		 hideScreen("lockIfr","lockScreen","lockWaitBox",'','','');
		 if(ajaxMessage=='all_sentPost')
		 {
		 	showScreen("","ScreenInForss","promptBoxInForss",null,260,20);
		 	document.getElementById("p_content").innerHTML="您的好友请求已发送给"+document.getElementById("nameSpace").innerHTML+",请等待验证！";
		 }
		 else if(ajaxMessage=='all_getPost')
		 {
		 	exitAddFriends(path);
			showScreen('ifrAddFriend','ScreenAddFriend','waitBoxAddFriendAllHave','','');
		 }
		 else if(ajaxMessage=='all_haveFriend')
		 {
		 	showScreen("","ScreenInForss","promptBoxInForss",null,260,20);
		 	document.getElementById("p_content").innerHTML="该人脉已经是您的好友！";
		 }
		 else if(ajaxMessage=="nosession")
		 {
		 	getScreenByStatus("jsAddScreenNologin","noLogin","","","","","");
		 	 showScreen("ifrNoLogins","ScreenNoLogins","waitBoxNoLogins",'','','');
		 }
		 else if (ajaxMessage == "all_toblackList")
		 {
		 	showScreen("","ScreenInForss","promptBoxInForss",null,260,20);
		 	document.getElementById("p_content").innerHTML="您已把被该人脉拉如黑名单,不能加为好友！";
		 }
		 else if (ajaxMessage == "all_fromblackList")
		 {
		 	showScreen("","ScreenInForss","promptBoxInForss",null,260,20);
		 	document.getElementById("p_content").innerHTML="您已经被该人脉拉如黑名单,不能加为好友！";
		 }
		 else if(ajaxMessage=='success')
		 {
		 	checkFriend();
		 }
	}
}
function checkFriend()
{
	document.getElementById('group').length=0;
	document.getElementById("showRequestButton").style.display="none";
	document.getElementById("sureButton").style.display="block";
	var gpselect=document.getElementById('group');
	XMLHttp.sendReq('post', ''+path+'/ajax/relationAjax.html?operationType=getFriendGroup', '', showGroups);
	showScreen('ifrAddFriend','ScreenAddFriend','waitBoxAddFriend','','');
}
function showGroups(http_request)
{
	/*是否成功请求*/
    if(http_request.responseText!="")
    {
    	 var results=http_request.responseXML;
		 var roots=results.documentElement;
		 var ajaxMessage=roots.getAttribute("ajaxMessage");
		 if(ajaxMessage=="success")
		 {
		 	var groupstr=roots.getAttribute("groups");
		 	var groups=groupstr.split(",");
		 	var gpselect=document.getElementById('group');
		 	for(var i=0;i<groups.length-1;i++)
		 	{
		 		if(groups[i].split("_")[1]!='邀请的好友')
			 	{
			 		opt=document.createElement("Option");
			 		opt.text=groups[i].split("_")[1];
	    			opt.value=groups[i].split("_")[0];
			 		
			 		if(getOs()=='MSIE')
				    {
				      gpselect.add(opt);
				    }
				    else
				   	{
				      gpselect.appendChild(opt);
				    }
			    }
		 	}
		 }
		 else if(ajaxMessage=="nosession")
		 {
		 	exitAddFriends();
		 	getScreenByStatus("jsAddScreenNologin","noLogin","","","","","");
		 	showScreen("ifrNoLogins","ScreenNoLogins","waitBoxNoLogins",'','','');
		 }
	}
}

function sendRequest()
{
	document.getElementById("showRequestButton").style.display="block";
	document.getElementById("sureButton").style.display="none";
	var rinfo=document.getElementById("requestInfo").value;
	var groupName=document.getElementById("group").value;
	XMLHttp.sendReq('post', ''+path+'/ajax/relationAjax.html?operationType=sendMFRequest&ruid='+document.getElementById("receiveUserId").value+'&info='+encodeURI(rinfo)+'&group='+groupName, '', sentRequest);
}
function sentRequest(http_request)
{
	/*是否成功请求*/
    if(http_request.responseText!="")
    {
    	var results=http_request.responseXML;
		 var roots=results.documentElement;
		 var ajaxMessage=roots.getAttribute("ajaxMessage");
		 if(ajaxMessage=="success")
		 {
			document.getElementById("requestInfo").value = "";
			exitAddFriends();
			showScreen('ifrAddFriend','ScreenAddFriend','waitBoxAddFriendAllSent','','');
			if (document.getElementById("pageInfo") != null && document.getElementById("pageInfo").value == 'space')
			{
				 var id=roots.getAttribute("userId");
				showMessage(id);
			}
			if (document.getElementById("pageInfo") != null && document.getElementById("pageInfo").value == 'information')
			{
				 document.getElementById("friend").innerHTML = "<div style=\"float:left;width:48px;overflow:hidden;\">等待验证</div>";
			}
			if (document.getElementById("pageInfo") != null && document.getElementById("pageInfo").value == 'lockSpace')
			{
				document.getElementById("lockS").innerHTML="由于对方的隐私设置，只有好友才能查看<br/><span style='color:red'>等待对方验证</span>"
			}
		 	setTimeout("setShareMessageCloseAddFriend()",3000);
		 }
    }
}
function setShareMessageCloseAddFriend()
{
	hideScreen('ifrAddFriend','ScreenAddFriend','waitBoxAddFriendAllSent');
}
function toFriendJsp()
{
	window.open(""+path+"/s/receiveRequest.html");
	hideScreen('ifrAddFriend','ScreenAddFriend','waitBoxAddFriendAllHave')
}

//********************************************标记***********************************************************************//
//标记
function markUser(mid)
{
	path = document.getElementById("path").value;
	showScreen("lockIfr","lockScreen","lockWaitBox",'','','');
	getScreenByStatus("jsAddScreenMark","markUser","","","","","")
	XMLHttp.sendReq('post', ''+path+'/ajax/relationAjax.html?operationType=markUser&mid='+mid, '', markedUser);
}
 
function markedUser(http_request)
{
	/*是否成功请求*/
    if(http_request.responseText!="")
    {
    	 var results=http_request.responseXML;
		 var roots=results.documentElement;
		 var ajaxMessage=roots.getAttribute("ajaxMessage");
		  hideScreen("lockIfr","lockScreen","lockWaitBox",'','','');
		 if(ajaxMessage=="success")
		 {
		 	showScreen('ifrMarkUser','ScreenMarkUser','waitBoxMarkUser','','');
		 	if (document.getElementById("pageInfo") != null && document.getElementById("pageInfo").value == 'space')
			{
				var id = roots.getAttribute("sentUserId");
				showMessage(id);
			}
			if (document.getElementById("pageInfo") != null && document.getElementById("pageInfo").value == 'information')
			{
				document.getElementById("mark").innerHTML="<div style=\"float:left;width:38px;overflow:hidden;\">已标记</div>";
			}
		 }
		 else if(ajaxMessage=="exist")
		 {
		 	showScreen('ifrMarkUser','ScreenMarkUser','waitBoxMarkUser','','');
		 }
		 else if(ajaxMessage=="nosession")
		 {
		 	getScreenByStatus("jsAddScreenNologin","noLogin","","","","","");
		 	 showScreen("ifrNoLogins","ScreenNoLogins","waitBoxNoLogins",'','','');
		 }
    }
}
function toUserJsp()
{
	window.open(""+path+"/s/markedList.html");
	hideScreen('ifrMarkUser','ScreenMarkUser','waitBoxMarkUser');
}
function exitAddFriends()
{
	hideScreen('ifrAddFriend','ScreenAddFriend','waitBoxAddFriend');
	document.getElementById("requestInfo").value = "";
}
//********************************************举报***********************************************************************//
function showScreenReport(reportType,reportId)
{
	path = document.getElementById("path").value;
	getScreenByStatus("jsAddScreenReport","report",reportType,"","",reportId,"")
	XMLHttp.sendReq('post', ''+path+'/ajax/reportAjax.html?operationType=checkReportUser','', reportResultAjax);
}

function reportResultAjax(http_request)
{
	var results=http_request.responseXML;
	var roots=results.documentElement;
	var ajaxMessage=roots.getAttribute("ajaxMessage");
	
	if(ajaxMessage=="ok")
	{
		startObjMessage('waitBoxReport');
		showScreen('ifrReport','ScreenReport','waitBoxReport','','');
	}
	else if(ajaxMessage=="nosession")
	{
		 getScreenByStatus("jsAddScreenNologin","noLogin","","","","","");
		 showScreen("ifrNoLogins","ScreenNoLogins","waitBoxNoLogins",'','','');
	}
}


function hideScreenReport()
{
	hideScreen('ifrReport','ScreenReport','waitBoxReport');
    document.getElementById("reportInfo").value="";
}

function saveReport(reportType,reportId)
{
	var reportDetail = document.getElementById("reportInfo").value;
	if(reportDetail=="")
	{
		document.getElementById("reportMessage").innerHTML = '<font style="color:red;">举报内容不能为空</font>';
		return false;
	}
	else
	{
		XMLHttp.sendReq('post', ''+path+'/ajax/reportAjax.html?operationType=insertReport&reportType='+reportType+'&reportDetail='+encodeURI(jsTrim(reportDetail))+'&reportId='+jsTrim(reportId), '', reportResult);
		document.getElementById("reportMessage").innerHTML="<img src='"+path+"/common/images/ajax/waitting_1.gif'/>&nbsp;正在保存,请稍等... ...";
		return true;
	}
}
function reportResult(http_request)
{
	/*是否成功请求*/
	   if(http_request.responseText!="")
	   {
			var results=http_request.responseXML;
			var roots=results.documentElement;
			var ajaxMessage=roots.getAttribute("ajaxMessage");
			
			if(ajaxMessage == "nosession")
			{
				 getScreenByStatus("jsAddScreenNologin","noLogin","","","","","");
				 showScreen("ifrNoLogins","ScreenNoLogins","waitBoxNoLogins",'','','');
			}
			else if(ajaxMessage == "existReport")
			{
				document.getElementById("reportInfoDiv").style.display="none";
				document.getElementById("reportButtonDiv").innerHTML="<input type='button' onclick='hideScreen2()' value='确定' class='button1'/>";
				document.getElementById("reportMessageDiv").innerHTML = "<font style='font-size:12px;'>您已举报过该人虚假信息,请耐心等待管理员审核!</font>";
			}
			else
			{
				
				document.getElementById("reportInfoDiv").style.display="none";
				document.getElementById("reportButtonDiv").style.display="none";
				document.getElementById("reportMessageDiv").innerHTML = "<font style='font-size:12px;'>举报该人虚假信息成功,请耐心等待管理员审核!</font>";
				if (document.getElementById("pageInfo") != null && document.getElementById("pageInfo").value == 'space')
				{
					var id=roots.getAttribute("userId");
					showMessage(id);
				}
				if (document.getElementById("pageInfo") != null && document.getElementById("pageInfo").value == 'lockSpace')
				{
					 document.getElementById("isReport").innerHTML="<span style='margin-left:35px;'>您已经举报过</span>";
				}
				if (document.getElementById("pageInfo") != null && document.getElementById("pageInfo").value == 'activity')
				{
					document.getElementById("isreport").innerHTML="<span style='margin-left:35px;'>您已经举报过</span>";
				}
				if (document.getElementById("pageInfo") != null && document.getElementById("pageInfo").value == 'information')
				{
					document.getElementById("isreport").innerHTML="<span style='margin-left:35px;'>您已经举报过</span>";
				}
				setTimeout("setShareMessageCloseReport()",2000);
			}
		}
}
function setShareMessageCloseReport()
{
	document.getElementById("reportInfoDiv").style.display="block";
	document.getElementById("reportButtonDiv").style.display="block";
	document.getElementById("reportMessageDiv").innerHTML = "<ul><li class='addFriendL'>&nbsp;</li><li><span id='reportMessage' name='reportMessage'></span></li></ul>";
	hideScreenReport();
}


/*------------------分享-------------------*/
// 锁屏
function showShareScreen(sessionUser,shareType,objId,objUserId,objTitle)
{
	path = document.getElementById("path").value;
	if( sessionUser != null && sessionUser != "")
	{
		getScreenByStatus("jsAddScreenShare","share",shareType,"",objTitle,objId,objUserId);
		startObjMessage('waitBoxShare');
		showScreen('ifrShare','ScreenShare','waitBoxShare','','');
    }
    else
    {
    	getScreenByStatus("jsAddScreenNologin","noLogin","","","","","");
    	showScreen("ifrNoLogins","ScreenNoLogins","waitBoxNoLogins",'','','');
    }
}
//解屏
function hideActivityScreen()
{
	hideScreen('ifrShare','ScreenShare','waitBoxShare');
    document.getElementById("shareDetail").value="";
    document.getElementById("shareMessage").innerHTML="";
}

function saveShare(shareType,shareUserId,shareId)
{
	var shareIntro = "";
	var shareDetail = document.getElementById("shareDetail").value;
	var receiveUserId = "0";
	XMLHttp.sendReq('post', ''+path+'/ajax/shareAjax.html?operationType=insertShare&shareType='+shareType+'&shareIntro='+encodeURI(jsTrim(shareIntro))+'&shareDetail='+encodeURI(jsTrim(shareDetail))+'&shareUserId='+jsTrim(shareUserId)+'&receiveUserId='+jsTrim(receiveUserId)+'&shareId='+jsTrim(shareId), '', shareResult);
	document.getElementById("shareMessage").innerHTML="<img src='"+path+"/common/images/ajax/waitting_1.gif'/>&nbsp;正在保存,请稍等... ...";
}

/*---------------------方法回调-----------------------*/
function shareResult(http_request){
	/*是否成功请求*/
   if(http_request.responseText!="")
   {
		var results=http_request.responseXML;
		var roots=results.documentElement;
		var ajaxMessage=roots.getAttribute("ajaxMessage");
		var type=roots.getAttribute("type");
		if(type == '5' || type == '14' )
		{
			type='topic';
		}
		else if (type == '22')
		{
			type = '9';
		}
		if(ajaxMessage == "nosession")
		{
			getScreenByStatus("jsAddScreenNologin","noLogin","","","","","");
			showScreen("ifrNoLogins","ScreenNoLogins","waitBoxNoLogins",'','','');
		}
		else
		{
			document.getElementById("shareContentDiv").style.display="none";
			document.getElementById("shareTitleDiv").style.display="none";
			document.getElementById("shareButtonDiv").style.display="none";
			document.getElementById("shareMessageDiv").innerHTML = "<font style='font-size:12px;'>分享成功，<a href='"+path+"/s/myShare.html?shareType="+type+"'>去看看</a></font>";
			setTimeout("setShareMessageClose()",2000);
		}
	}
}
function setShareMessageClose()
{
	setMessageClose("waitBoxShare");
	document.getElementById("shareContentDiv").style.display="block";
	document.getElementById("shareTitleDiv").style.display="block";
	document.getElementById("shareButtonDiv").style.display="block";
	document.getElementById("shareMessageDiv").innerHTML = "<ul><li class='addFriendL'>&nbsp;</li><li><span id='shareMessage' name='shareMessage'></span></li></ul>";
	hideActivityScreen();
}

function showDiaryScreen(sessionUser,type,id,binzhi_user_id,title,diaryType)
{
	if(sessionUser != null && sessionUser != "")
	{
		if(diaryType != "2")
		{
		    showShareScreen(sessionUser,type,id,binzhi_user_id,title);
	    }
	    else
	    {
	    	getScreenByStatus("jsAddScreenInfo","info","","","","","");
	    	showScreen("","ScreenInForss","promptBoxInForss",null,260,20);
		 	document.getElementById("p_content").innerHTML="私密日志不能被分享！";
	    }
    }
    else
    {
    	getScreenByStatus("jsAddScreenNologin","noLogin","","","","","");
    	showScreen("ifrNoLogins","ScreenNoLogins","waitBoxNoLogins",'','','');
    }
}
function addBlackList(userId,e,myUserId)
{
	if (myUserId == null || myUserId == '')
	{
		getScreenByStatus("jsAddScreenNologin","noLogin","","","","","");
    	showScreen("ifrNoLogins","ScreenNoLogins","waitBoxNoLogins",'','','');
	}
	else
	{
		document.getElementById("blackUserId").value = userId;
		showScreen("","","addBlackListBox",e);
	}
	
}
function sureBlackList()
{
	showScreen("lockIfr","lockScreen","lockWaitBox",'','','');
	var id = document.getElementById("blackUserId").value;
	XMLHttp.sendReq('post', ''+path+'/ajax/businessSpaceAjax.html?operationType=addBlackList&bzuid='+id, '', showBlackListAjax);
}
function showBlackListAjax(http_request){
	/*是否成功请求*/
   if(http_request.responseText!="")
   {
		var results=http_request.responseXML;
		var roots=results.documentElement;
		var ajaxMessage=roots.getAttribute("ajaxMessage");
		hideScreen("lockIfr","lockScreen","lockWaitBox",'','','');
	 	if (ajaxMessage == 'nosession')
	 	{
	 		getScreenByStatus("jsAddScreenNologin","noLogin","","","","","");
    		showScreen("ifrNoLogins","ScreenNoLogins","waitBoxNoLogins",'','','');
	 	}
	 	else
	 	{
	 		hideScreen("","","addBlackListBox");
	 		getScreenByStatus("jsAddScreenInfo","info","","","","","");
	    	showScreen("","ScreenInForss","promptBoxInForss",null,260,20);
		 	document.getElementById("p_content").innerHTML="您已成功将该人脉加入黑名单，如若需要移除，您可到<a href='/s/blackList.html'>此处移除您的黑名单人脉</a>！";
		 	if (document.getElementById("pageInfo") != null && document.getElementById("pageInfo").value == 'space')
			{
				var id=roots.getAttribute("userId");
				showMessage(id);
			}
	 	}
	}
}