﻿

//滚动相关开始
var isIE = $.browser.msie;

function IeTrueBody(){
return $.boxModel? document.documentElement : document.body;
}

function GetScrollTop(){
 return isIE ? IeTrueBody().scrollTop : window.pageYOffset;
}

function GetScrollLeft(){
 return isIE ? IeTrueBody().scrollLeft : window.pageXOffset;
}

function SetHeight(objID,num){
	setHeight(objID,num);
	setInterval("setHeight('" + objID + "'," + num + ")",300);
}

function setHeight(objID,num){
	$("#" + objID).css("top",GetScrollTop() + num);
}

function SetLeft(objID,num){
	setLeft(objID,num);
	setInterval("setLeft('" + objID + "'," + num + ")",300);
}

function setLeft(objID,num){
	$("#" + objID).css("left",GetScrollLeft() + ($(window).width() - num)/2);
}
//滚动相关结束


//通用背景操作开始
function showCommonBg()
{
	$("select").css("display","none");
	$("#confirmInfor").attr("display","none");
	$("#CommonDivBg").css("filter","alpha(opacity=50)");
	$("#CommonDivBg").css("-moz-opacity","0.5");
	$("#CommonDivBg").css("opacity","0.5");
	$("#CommonDivBg").css("index","99");
	$("#CommonDivBg").css("display","block");
	$("#CommonDivBg").css("height",$(window).height());
	$("#CommonDivBg").css("width",$(window).width());
	//$("#CommonDivBg").SetHeight("top","0");
	setHeight("CommonDivBg",0);	
	$("#CommonDivBg").css("left",0);
}

function closeCommonBg()
{
	$("select").css("display","");
	$("#CommonDivBg").fadeOut("fast");	
}
//通用背景操作结束


//提示相关开始
function closeTipsAndConfirm()
{
	$("#tipsInfor").fadeOut("slow");
	$("#confirmInfor").fadeOut("slow");
	closeCommonBg();
}

function closeTipsAndConfirmOnly()
{
	$("#tipsInfor").fadeOut("slow");
	$("#confirmInfor").fadeOut("slow");
}

function showTipsOnly(IsErr,Msg)
{
	$("#tipsInfor em").removeClass("Open_Image_Y");
	$("#tipsInfor em").removeClass("Open_Image_N");
	$("#tipsInfor em").removeClass("Open_Image_T");
	if(IsErr == "true")
	{
		$("#tipsInfor em").addClass("Open_Image_Y");
	}
	if(IsErr == "false")
	{
		$("#tipsInfor em").addClass("Open_Image_N");
	}
	if(IsErr == "tips")
	{
		$("#tipsInfor em").addClass("Open_Image_T");
	}
	$("#tipsContent").html(Msg);
	SetLeft("tipsInfor",330);
	SetHeight("tipsInfor",180);
	$("#tipsInfor").fadeIn("slow");
	showCommonBg();
}

function showTips(IsErr,Msg)
{
	showTipsOnly(IsErr,Msg);
	setTimeout("closeTipsAndConfirm()",2000);
}

function showConfirm(Msg)
{
	$("#tipsInfor").attr("display","none");
	SetLeft("confirmInfor",330);
	SetHeight("confirmInfor",180);
	$("#confirmContent").html(Msg);
	$("#confirmInfor").fadeIn("slow");
	showCommonBg();
}

//提示相关结束

//打招呼相关操作开始
function showCommonSendShortMessage()
{
	$("#shortMessageSendSubmit").unbind("click");
	$("#shortMessageSendSubmit").click(function(){
												sendCommonShortMessage();
												});
	$("#CommonSendShortMessage").show("slow");
	$("#CommonSendShortMessage").css("top",GetScrollTop() + 140);
	$("#CommonSendShortMessage").css("left",GetScrollLeft() + (screen.width - 500)/2);
}


function sendCommonShortMessage()
{
	if($("#commonShortMessageTitle").val() =="" || $("#commonShortMessageContent").val() =="")
	{
		showTipsOnly("false","标题和内容不能为空.");
		setTimeout("closeTipsAndConfirmOnly()",1500);
		return;
	}else
	{
		if($("#commonShortMessageTitle").val().length > 50 || $("#commonShortMessageContent").val() > 200)
		{
			showTipsOnly(true,"标题不能超过50个字，内容不能超过200个字.");
			setTimeout("closeTipsAndConfirmOnly()",1500);	
			return;
		}
	}
	$("#shortMessageSendSubmit").unbind("click");
	$.ajax({
		  type : "Get",
		  url : "/Lcommon/getAjaxDate.asp",
		  async: false,
		  dataType : "html",
		  data : { "ajaxID" : escape($("#commonAjaxID").val()),
		  "Title":escape($("#commonShortMessageTitle").val()),
		  "Content":escape($("#commonShortMessageContent").val()),
		  "Action":"sendCommonShortMessage"
		  },
		  success : function(msg){
			  if(msg == 1)
			  {
				  showTipsOnly("true","短信发送成功.");
				  
			  	  setTimeout("CommonCloseDiv()",1500);
				  setTimeout("closeTipsAndConfirm()",1500);
			  }
			  else
			  {
				  showTipsOnly("false","已经超出短信发送限制，没登陆一天可以多发一条站内信.");
				  setTimeout("CommonCloseDiv()",1500);
				  setTimeout("closeTipsAndConfirm()",1500);
			}
			  },
		  error : function(msg){
			  return;
			  showTipsOnly("false","操作失败，清稍后再试.");
			  setTimeout("CommonCloseDiv()",1500);
			  setTimeout("closeTipsAndConfirm()",1500);
			  }
		  });
	//$("#commonShortMessageTitle").val("");
	//$("#commonShortMessageContent").val("");
}

function showCommonAddFriend()
{
	$("#CommonAddFriend").show("slow");
	$("#CommonAddFriend").css("top",GetScrollTop() + 140);
	$("#CommonAddFriend").css("left",GetScrollLeft() + (screen.width - 500)/2);
}

function showCommonSayHello()
{
	$("#CommonSayHello").show("slow");
	$("#CommonSayHello").css("top",GetScrollTop() + 140);
	$("#CommonSayHello").css("left",GetScrollLeft() + (screen.width - 500)/2);
}

function showCommonWatch()
{
	$("#CommonWatch").show("slow");
	$("#CommonWatch").css("top",GetScrollTop() + 140);
	$("#CommonWatch").css("left",GetScrollLeft() + (screen.width - 500)/2);
}

function CommonCloseDiv()
{
	$("#CommonSendShortMessage").fadeOut("slow");
	$("#CommonAddFriend").fadeOut("slow");
	$("#CommonSayHello").fadeOut("slow");
	$("#CommonWatch").fadeOut("slow");
	closeTipsAndConfirmOnly();
	closeCommonBg();
}
//打招呼相关结束

//表单选择
function selectCommonAll(objName,obj)
{
	if($(obj).attr("checked"))
	{
		$(":checkbox[name='" + objName + "']").attr("checked",true);
	}
	else
	{
		$(":checkbox[name='" + objName + "']").attr("checked",false);	
	}
}

function selectCommonI(objName,obj)
{
	if($(obj).attr("checked"))
	{
		$(":checkbox[name='" + objName + "']").each(function(){
			if($(this).attr("checked"))
			 {
				 $(this).attr("checked",false);
			 }
			 else
			 {
				 $(this).attr("checked",true);
			 }
			 })
	}	
}

function CommonGetAddFlag()
{
	if($(":input[name='commonFriendLinkInfor']").val() == "")
	{
		$("#CommonFriendDivResultTrue").css("display","none");
		$("#CommonFriendDivResultFlase").css("display","block");
		return;
	}
	$("#CommonFriendDivResultTrue").css("display","none");
	$("#CommonFriendDivResultFlase").css("display","none");
	$("#CommonFriendDivResultSuccess").css("display","none");
	$("#CommonFriendDivResultError").css("display","none");
	var html = $.ajax({
					  type : "Get",
					  url : "/Lcommon/getAjaxDate.asp",
					  async: false,
					  dataType : "html",
					  data : { "ajaxID" : $("#commonAjaxID").val(),
					  "Action":"CommonGetAddFlag",
					  "commonFriendLinkInfor" : escape($(":input[name='commonFriendLinkInfor']").val())
					  },
					  error : function(){
						  $("#FriendDivResultTrue").css("display","none");
						  $("#FriendDivResultFlase").css("display","block");
						  }
					  }).responseText;
	if(html == "1")
	{
		$("#CommonFriendDivResultFlase").css("display","none");
		ajaxCommonAddFriend();
	}
	else
	{
		$("#CommonFriendDivResultTrue").css("display","none");
		$("#CommonFriendDivResultFlase").css("display","block");
	}
}

function ajaxCommonAddFriend()
{
	var html = $.ajax({
					  type : "Get",
					  url : "/Lcommon/getAjaxDate.asp",
					  async: false,
					  dataType : "html",
					  data : { "ajaxID" : $("#commonAjaxID").val(),
					  "Action":"CommonAddFriend",
					  "commonFriendLinkInfor" : escape($(":input[name='commonFriendLinkInfor']").val())
					  },
					  error : function(){
						  $("#FriendDivResultTrue").css("display","none");
						  $("#FriendDivResultFlase").css("display","block");
						  }
					  }).responseText;
	if(html == "out")
		showTips("false","请登录后发送好友请求.");
	else
		showTips("true","好友请求发送成功，请等待对方验证.");
	//if(html == "1")
//	{
//		$("#CommonFriendDivResultSuccess").css("display","block");
//		$("#CommonFriendDivResultError").css("display","none");
//	}
//	else
//	{
//		$("#CommonFriendDivResultSuccess").css("display","none");
//		$("#CommonFriendDivResultError").css("display","block");
//	}
}


function getStrLen(sString)
{
   var sStr,iCount,i,strTemp ;

   iCount = 0 ;
   sStr = sString.split("");
    for (i = 0 ; i < sStr.length ; i ++)
     {
         strTemp = escape(sStr[i]);
          if (strTemp.indexOf("%u",0) == -1)
          {
              iCount = iCount + 1 ;
          }
          else
          {
              iCount = iCount + 2 ;
          }
	 }
     return iCount ;
}

function onlyNum()
{
	if(!((event.keyCode>=48&&event.keyCode<=57)||(event.keyCode>=96&&event.keyCode<=105)||(event.keyCode==8)))
	{
		event.returnValue=false;
	}
}

function RemoveHTML(inStr) 
{ 
	var strText=inStr; 
	var regEx = /<[^>]*>/g; 
	return strText.replace(regEx, ""); 
}

function getCheckBoxValue(objList)
{
	tempvalue = "0";
	for(i = 0;i<objList.length;i++)
	{
		if($(objList[i]).attr("checked"))
		{
			tempvalue = tempvalue + "," + $(objList[i]).val();
		}
	}
	return tempvalue;
}

function needMyLinkInfor()
{
	showTipsOnly("false","需要完善联系方式，才能发送好友请求.");
	$("#tipsContent").append("<br /><a href='/my/infor/linkinfor.asp' target='_blank'>立即完善联系方式</a>");
	$("#tipsContent a").unbind("click");
	$("#tipsContent a").click(function(){
										closeTipsAndConfirm();
									   });
}