var msgr = '<img src="img/ico_01.gif" width="37" height="24" align="absbottom" /> 恭喜！操作成功！';
var msge = '<img src="img/ico_00.gif" width="24" height="24" align="absbottom" /> 抱歉！操作失败！';

/**
 * 快速登录
 * 
 * @param vBtn 登录过程中，按钮失效
 * @return
 */
function goLogin(vBtn){
//	if(vBtn) vBtn.disabled = true;
	
	$("#ina").hide();
	$("#inb").show();
	var uName = $("#inName").val();
	var uPass = $("#inPass").val();
//	
	if(Trim(uName)== '' || Trim(uPass)== ''){
		alert("用户名或密码错误");
		$("#ina").show();
		$("#inb").hide();
	}else{
		
		$.post("checkin.php",
				{sUN:uName,sPW:uPass},
				function(data){
					
					if(data == 1){
						window.location.href="profile.html";
					}else{
						alert("太粗心了吧，好好检查一下哟！");
						$("#ina").show();
						$("#inb").hide();
					}
				}
		);
		
		//window.location.reload();
	}
	
	
}

/**
 * 显示输入字数信息
 * 
 */
var maxLen = 140;   //这里可以设输入字数的最大值
function checkMaxInput()
{
	var myContents = $("#mysay").val();
	if(myContents.length > maxLen)
		$("#mysay").val(myContents.substring(0,   maxLen));
}

/**
 * 鼠标移上去时显示按钮
 * 
 * @param num
 * @return
 */
function replay(num){   
   
	var sdiv = jQuery("#btn"+num);
	var subMenu = jQuery("#tab"+num);
	
    jQuery(subMenu).hover(function(){
      jQuery(sdiv).show();
   },function(){
      jQuery(sdiv).hide();
   })
}

/**
 * 打开回复窗口
 * @return
 */
function showReplayDiv(lID,uID){
	
	$("#msgCon").val('');
	$("#toWho").html($("#listName"+lID).html());
	$(".lb_hfk_tc").show();
	$("#TB_overlay").show();
	$("#msgCon").focus();
	$("#toWhoID").val(uID);
}

/**
 * 关闭回复窗口
 * @return
 */
function closeReplay(){
	$(".lb_hfk_tc").hide();
	$("#TB_overlay").hide();
}


/**
 * 回复操作
 * @return
 */
function doReplay(){
	
	$(".lb_hfk_tc").hide();
	$("#TB_overlay").hide();
	
	var reID = $("#toWhoID").val();
	var reMsg = Trim($("#msgCon").val());
	
	if(reMsg == '' || reID < 1){
		alert("想说点什么呢？");
		return;
	}
	
	$.post("sSign.php",
			{sMsg:encodeURI(reMsg),iuID:reID},
			function(data){
//				alert(data);
				if(data == 1){
//					alert('ok');
					$("#theNotice").html(msgr);
					
				}else{
//					alert('soorry');
					$("#theNotice").html(msge);
				}
				$("#cao_zuo_cheng_gong").show().animate({top:"0px"},3000).hide("slow");//.animate({top:"0px"},1000)延迟1秒在播放后面的动画
			}
	);
	
	
	
}

/**
 * 展示大图片
 * 
 * @param lID logID
 * @return
 */
function showPic(lID){
	
	var errorinfo="<span id='loadtxt'>图片加载失败...</span>";
	var picURL = $("#pic"+lID).html();
	var loadpic = $("<img id='loadpic' src='./img/loadinfo.gif'>");	
	var loadinfo=$('<img class="photo" id="photo" src="'+picURL+'" />');
	$("#photo_cc").html(loadpic);
	jQuery("#TB_overlay").show();
	loadinfo.load(function(){
		$("#photo_cc").html(loadinfo);
		var ir = new rotationPicture('photo');
		jQuery("#photo").show();
		jQuery(function(){//鼠标按下拖动
			jQuery("#photo,canvas").easydrag();
	    });
	}).error(function(){
		$("#photo_cc").html(errorinfo);
		
	});
	
    /*
    var photo_ = "<img class='photo' id='photo' title='我可以拖动哟！' src='"+picURL+"' />";
    jQuery("#photo_cc").html(photo_);
    var ir = new rotationPicture('photo');
    jQuery("#TB_overlay").show();
    jQuery("#photo").show();
    */
   
    
    jQuery("#TB_overlay").click(function(){
		jQuery("#TB_overlay").hide();
		jQuery("#photo_cc").html("");  	
	});
  
	            

}


var isIE = /*@cc_on!@*/!1;
function rotationPicture(img){
	if (!img) return;
	this._img = typeof img == 'string'?document.getElementById(img):img;
	this.r = 1;
	this.addBtn();
	this.bind();
}
rotationPicture.prototype.addBtn = function(){
	this._rRight = document.createElement('BUTTON');
	this._rRight.setAttribute('id','rRight');
	this._rRight.className = 'rotation';
	if (!isIE){
		var canvas = document.createElement('CANVAS');
		var ctx = canvas.getContext('2d');
		canvas.setAttribute('width',this._img.width);
		canvas.setAttribute('height',this._img.height);
		ctx.drawImage(this._img,0,0);
		this._ghost = this._img;
		this._img.parentNode.replaceChild(canvas,this._img);
		this._img = canvas;
	}
	this._img.parentNode.insertBefore(this._rRight,this._img);
};
rotationPicture.prototype.bind = function(){
	var _this = this;
	if (window.attachEvent){
		this._rRight.attachEvent('onclick',rotation);
	}else{
		this._rRight.addEventListener('click',rotation,false);
	}
	
	function rotation(){
		if (_this.r > 3) _this.r = 0;
		if(isIE){
			_this._img.style.filter = 'progid:DXImageTransform.Microsoft.BasicImage(Rotation=' + _this.r + ')';
		}else{
			var ctx = _this._img.getContext('2d');
			switch (_this.r){
				case 0:
					_this._img.setAttribute('width',_this._ghost.width);
					_this._img.setAttribute('height',_this._ghost.height);
					ctx.drawImage(_this._ghost,0,0);
					break;
				case 1:
					_this._img.setAttribute('width',_this._ghost.height);
					_this._img.setAttribute('height',_this._ghost.width);
					ctx.rotate(90*Math.PI/180);
					ctx.drawImage(_this._ghost,0,-_this._ghost.height);
					break;
				case 2:
					_this._img.setAttribute('width',_this._ghost.width);
					_this._img.setAttribute('height',_this._ghost.height);
					ctx.rotate(180*Math.PI/180);
					ctx.drawImage(_this._ghost,-_this._ghost.width,-_this._ghost.height);
					break;
				case 3:
					_this._img.setAttribute('width',_this._ghost.height);
					_this._img.setAttribute('height',_this._ghost.width);
					ctx.rotate(270*Math.PI/180);
					ctx.drawImage(_this._ghost,-_this._ghost.width,0);
					break;
			}
		}
		_this.r++;
	}
	
};

/**
 * 发布web签名
 * @return
 */
function doSay(vBtn){
	var say = Trim($("#mysay").val());
	if (say == '' || say == '我要说…'){
		alert("您要说点啥呢？");
		$("#mysay").val('');
		$("#mysay").focus();
		return;
	}
	if(vBtn) vBtn.disabled = true;
//	$("#reBtn").css("display","none");
	$.post("sMsg.php",
			{sMsg:encodeURI(say)},
			function(data){
				
				if(data == 1){
					$("#theNotice").html(msgr);
				}else{
					$("#theNotice").html(msge);
				}
				$("#mysay").val('');
				if(vBtn) vBtn.disabled = false;
				$("#cao_zuo_cheng_gong").show().animate({top:"0px"},3000).hide("slow");
			}
	);
}

/**
 * 新建好友分组
 * @return
 */
function doGroup(userID){
	var gro = Trim($("#newgroup").val());
	if(gro == ''){
		alert("分组名称错误！");
		return;
	}
	
	$("#groBtn").css("display","none");
	$("#groLoad").css("display","block");
	$.post("sGroup.php",
			{sMsg:encodeURI(gro),iUser:userID},
			function(data){
				
				if(data == 0){
					alert('新组添加失败！');
				}else if(data == 2){
					alert('抱歉，可能是有同名分组！');
				}else{
					
					$("#groupDiv").append(data);
				}
					
			}
	);
	$("#groBtn").css("display","block");
	$("#groLoad").css("display","none");
	$("#newgroup").val('');
	$(".fz_xin_jian a").show();
	$("#fz_name").hide();
}

/**
 * 保存基本设置
 * @return
 */
function dobSet(){
	
	jQuery("#btn").css("display","none");
	jQuery("#ldi").css("display","block");
	var niki = Trim(jQuery("#niki").val());
//	if(niki == ''){
//		alert("为自己选个站内昵称吧！");
//		jQuery("#btn").css("display","block");
//		jQuery("#ldi").css("display","none");
//		return;
//	}
	
	var sex = jQuery("#issex").val();
	var where = Trim(jQuery("#iwhere").val());
	if(where == ''){
		alert("说出在哪个城市吧？能认识更多身边的朋友哦！");
		jQuery("#btn").css("display","block");
		jQuery("#ldi").css("display","none");
		return;
	}
	var birthday = jQuery("#birthday").val();
	var mail = Trim(jQuery("#imail").val());
	if(mail != ''){
		if(!/^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/.test(mail)){
			alert("Email错了哦！");
			jQuery("#btn").css("display","block");
			jQuery("#ldi").css("display","none");
			return;
		}
	}
	var web = Trim(jQuery("#iweb").val());
	var intrinst = Trim(jQuery("#iintrinst").val());
	var cont = Trim(jQuery("#icont").val());
	
	
	jQuery.post("sBase.php",
			{sNiki:encodeURI(niki),
			 sSex:sex,
			 sWhe:encodeURI(where),
			 sBir:encodeURI(birthday),
			 sMai:encodeURI(mail),
			 sWeb:encodeURI(web),
			 sInt:encodeURI(intrinst),
			 sCon:encodeURI(cont)},
			function(data){
				
				if(data == 1){
					jQuery("#theNotice").html(msgr);
				}else{
					jQuery("#theNotice").html(msge);
					
				}
					
			}
	);
	
	jQuery("#btn").css("display","block");
	jQuery("#ldi").css("display","none");
	jQuery("#cao_zuo_cheng_gong").show().animate({top:"0px"},3000).hide("slow");//.animate({top:"0px"},1000)延迟1秒在播放后面的动画
}

function doSearch(vBtn){
	var seaKey = Trim($("#searchKey").val());
	if(seaKey == ''){
		alert("想搜什么内容呢？");
		return;
	}
	if(vBtn) vBtn.disabled = true;
	window.location.href = 'hot-1-'+encodeURI(seaKey)+'.html';
}


/**
 * 推广
 * 
 * */
function spread(iUserID,iMsgID,iType)
{
	$.post("saveCollect.php",
			{mU:iUserID,mM:iMsgID,mK:iType},
			function(data){
				if(data == 1){
					jQuery("#theNotice").html(msgr);
				}else{
					jQuery("#theNotice").html(msge);
				}
				jQuery("#cao_zuo_cheng_gong").show().animate({top:"0px"},3000).hide("slow");
				
	});
}


/**
 * 去空格函数
 * 
 * @param str
 * */ 
function LTrim(str){ //去掉字符串 的头空格
	var i;
	for(i=0;i< str.length;i++){
		if(str.charAt(i)!=" "&&str.charAt(i)!=" ") break;
	}
	str = str.substring(i,str.length);
	return str;
}

function RTrim(str){
	var i;
	for(i=str.length-1;i>=0;i--){
		if(str.charAt(i)!=" "&&str.charAt(i)!=" ") break;
	}
	str = str.substring(0,i+1);
	return str;
}

function Trim(str){ 
	return LTrim(RTrim(str)); 
}