var LOGIN_IF=false;


function getCookie(name)
{
	var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
	if(arr != null) return unescape(arr[2]); return null;
}

//发送消息
function sendMessage(userId)
{
	
	dojo.io.bind({
	  			url: "/web800/startChatWindow.os?friendId="+userId, // 指定将form提交到哪个页面
	  			mimetype:"text/html", // 指定用什么编码方式提交
	  			method:"POST", // 指定是post还是get,当然此处要提交,当然就要用post了
	  			encoding:"utf-8", // 指定提交内容的编码
	  			timeout:10000, // 指定超时时间
	  			load: function(type, data, evt){
					if(data=="yourSelf")
					{
						alert("您不能给自己发送消息!");
					}
					else if(data=="startClientChatWindow")
					{
						//alert("客户端窗口开始启动!");
					}
					else if(data=="startWebChatWindow")
					{
						startChatWindow(userId);
					
					}

	  			},
	  			error: function(type, error){
	  				
	  			},
	  			timeout: function(type, data, evt){
	  				
		}
   	});
}
//添加好友
function addTheFriend(userId)
{
	
	dojo.io.bind({
	  			url: "/desktop/addFriend.os?friendId="+userId+"&type=1", // 指定将form提交到哪个页面
	  			mimetype:"text/html", // 指定用什么编码方式提交
	  			method:"POST", // 指定是post还是get,当然此处要提交,当然就要用post了
	  			encoding:"utf-8", // 指定提交内容的编码
	  			timeout:10000, // 指定超时时间
	  			load: function(type, data, evt){
					
					var msg = data.split("||");
					var reason = msg[0];
					if(reason=="exist")
					{
						alert("添加失败，此好友已经存在!");
					}
					else if(reason=="self")
					{
						alert("添加失败，不能添加自己为好友!");
					}
					else if(reason=="myMaxUser")
					{
						alert("添加失败，您的好友已满，你目前的等级最大允许好友人数为"+msg[1]+"人");
					}
					else if(reason=="heMaxUser")
					{
						alert("添加失败，对方的好友已满");
					}
					else
					{
						alert("好友添加成功!");
					}

	  			},
	  			error: function(type, error){
	  				
	  			},
	  			timeout: function(type, data, evt){
	  				
		}
   	});
}

/****打开注册界面****/
function openRegWindow()
{
	createWindow("userRegWindow",530,327,"用户注册","/uReg.html",0);
}

//显示好友信息
function showUserInfo(userId)
{
	if(!LOGIN_IF)
	{
		showLoginWindow();
		return;
	}
	createWindow("userInfoWindow",520,400,"用户信息","/bbs/user/window/getUserInfo.os?userId="+userId,"",0);
}
/***赠送积分****/
function sendIntegral(userId)
{
	if(!LOGIN_IF)
	{
		showLoginWindow();
		return;
	}
	createWindow("sendIntegralWindow",360,150,"赠送积分","/bbs/user/sendIntegral.html?userId="+userId,0);
}
//查看好友共享
function userShareFile(userId)
{
	createWindow("userShareFile",560,450,"用户共享","/bbs/getUserShareFileList.os?userId="+userId,0);
}
/****显示用户文章****/
function showUserArcList(userId)
{
	createWindow("userArcList",460,370,"用户帖子","/bbs/getUserWebArcList.os?userId="+userId,0);
}
//添加为好友
function addFriend(userId,showName,ep)
{
	if(!LOGIN_IF)
	{
		showLoginWindow();
		return;
	}
	if(confirm("确认将"+showName+"("+ep+")加为好友吗？"))
	{
		addTheFriend(userId);
	}
	//createWindow("addFriend",420,250,"添加好友","/bbs/user/window/addFriend.jsp?userId="+userId+"&showName="+showName,"",0);
}
//显示登录窗口****/
function showLoginWindow()
{
	createWindow("userLoginWindow",320,200,"用户登录","/userLogin.html","",0);
}
/***发表帖子****/
function sendPost(panelId)
{
	if(!LOGIN_IF)
	{
		showLoginWindow();
		return;
	}
	window.location = "/bbs/user/sendPost.os?panelId="+panelId;
}

function startChatWindow(userId)
{
	createEPOPOSWindow("chatWindow",596,488,"/web800/webChatWindow.os?userId="+userId);
}
function setCookie(name,value)
{
	document.cookie = name + "="+ escape(value);
}
function logout()
{
	setCookie("epoposLoginMethod",null);
	setCookie("epoposUserName",null);
	setCookie("epoposPasswrod",null);
	
	dojo.io.bind({
		url: "/window/logout.os", // 指定将form提交到哪个页面
		preventCache:true,
		timeout:10000, // 指定超时时间
			load: function(type, data, evt){
				window.top.location.reload();
			}
		});

}

/****编辑帖子****/
function editRep(id)
{
	createWindow("editRepWindow",596,388,"编辑帖子","/bbs/user/initRepEdit.os?id="+id);
}
