document.write("<script src='/js/jquery/jquery.js'></script>");
function friendadd(fid,fname,flogo,uid){
		addpost(fid,fname,0,flogo);
}
function showHtml(fid,fname,flogo){
	var html=friendgetHtml(fid,fname,flogo);
	$("body").append(html);
	$("#Temp").height(getHeight());
	$("#Temp1").css("top",document.documentElement.scrollTop+180);
	if (window.navigator.userAgent.indexOf("MSIE")>=1)
	$("#Temp1").css("left",document.body.clientWidth/2-200);
}
function friendgetHtml(fid,fname,flogo){
    var html='';
	html+='<div id="htmldiv"><style>';
	html+='#Temp{width:100%;cursor:wait;filter:alpha(opacity=30); opacity: 0.3;background-color:#000000; position:absolute;left:0px;top:0px;right:0px;bottom: 0px;}'
	html+='#Temp1{width:415px; line-height:21px; margin:20px auto; background:#fff; border:5px solid #efefef; text-align:left;position:absolute;left:80px;right:0px;}'
	html+='#Tempconten{line-height:25px; padding:0 8px; background:#dc0000; color:#fff;}'
	html+='</style>';
	html+='<div id="Temp" onclick="closehtml()"></div><div  id="Temp1">';
	html+='<div id="Tempconten"><a href="javascript:closehtml()" style="float:right; color:#fff;">X</a><b>请求'+fname+'加为好友</b></div>';
	html+='<table cellspacing="0" cellpadding="0" border="0" style="margin:20px"><tr>';
	html+='<td width="80" valign="top"><img src="'+flogo+'" /><br/>'+fname+'</td>';
	html+='<td width="295">附加信息：<br /><textarea style="width:280px" id="htmltext"></textarea></td></tr>';
	html+='<tr><td colspan="2" height="20"></td></tr><tr><td colspan="2" height="1" bgcolor="#cccccc"></td></tr><tr><td colspan="2" height="20"></td></tr><tr><td></td>';
	html+='<td align="right"><input type="image" src="/images/passport/btn_enter.gif" onclick="addpost('+fid+',\''+fname+'\',1)"/> &nbsp;';
	html+='<input type="image" src="/images/passport/cancel.gif" onclick="closehtml()" /></td></tr></table></div></div>';
	return html;
}
function addpost(fid,fname,ischeck,flogo){
	$.get("/passport/friend.php",{act:"callfriend",ischeck:ischeck,fid:fid,text:$("#htmltext").val()},function ( data ){
		if(data==2){
			alert(fname+"已经是您的好友!");
		}else if(data==1){
			alert("已经发送过好友请求了!");
		}else if(data==3){
			alert("不能添加自己为好友!");
		}else if(data==4){
			alert("对方已经给您发送过请求了!");
		}else if(data==6){
			alert("请先登陆!");
		}else if(data==8){
			alert("发送成功!");
		}
		if(ischeck==0 && data==0){//判断是否显示加为好友的html
		   showHtml(fid,fname,flogo)
		}
	});
	if(ischeck==1){
	   closehtml();
	}
}
function closehtml(){
	$("#htmldiv").empty();
	$("#htmldiv").remove();
}

function getHeight(){

    var yScroll;

    if (window.innerHeight && window.scrollMaxY) {
        yScroll = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
        yScroll = document.body.scrollHeight;
    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
        yScroll = document.body.offsetHeight;
    }
    var windowHeight;
    if (self.innerHeight) { // all except Explorer
        windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) {
    // Explorer 6 Strict Mode
       windowHeight = document.documentElement.clientHeight;
    } else if (document.body) { // other Explorers
       windowHeight = document.body.clientHeight;
    }

    // for small pages with total height less then height of the viewport
    if(yScroll < windowHeight){
        pageHeight = windowHeight;
    } else {
        pageHeight = yScroll;
    }
      return pageHeight;
}
