﻿$(document).ready(function(){
	
	/*
	var loadType = $('#loadType').attr("value");
	
	if (childOption=="searchCity"){
		$("#searchCity").attr("value",'CHECKED');
		alert ("111111111");
	}
	else if (childOption=="searchEmail"){
		$("#searchEmail").attr("value",'CHECKED');
		alert ("aaaaaaaaa");
	}
	*/
	
	//var friendText = $('#friendText').attr("value");
	//if (friendText) {
		loadFriend(1,5);
	//}
	
});

function loadFriend(currentPage,countPerPage){
	
	
	
	
	//
	var childOption;
	$("input[name='radiobutton']").each(function(){  
		if (this.checked){  
			
			childOption = this.value;
			
			/*
			if (!childOption)
				childOption = "searchAll";
			*/

		}  
	});
	
	if (childOption == undefined){
		childOption = "searchAll"
	}
	//alert(childOption);
	

	var friendText = $('#friendText').attr("value");
	if (!friendText) {
		//childOption = "bestUser";
		childOption = "searchAll";
	}
	
	
	var hasPhoto="no";
	if ($("#hasPhoto").attr('checked')==false){
		hasPhoto="no";
	}
	else{
		hasPhoto="yes";
	}
	//alert (hasPhoto);
	//alert (childOption);
	//alert (friendText);
	//alert (encodeURIComponent(friendText));
	
		$.ajax({
			url: 'friend_search.php?hasPhoto='+hasPhoto+'&childOption='+childOption+'&friendText='+encodeURIComponent(friendText),
			type:'GET',
			data:{currentPage:currentPage,countPerPage:countPerPage},
			dataType:'json',
			success:function(data)
			{
				var bb = data.pagination;
				$('#loadPagination').html(bb);
				
				//$('#showFriend2').html(data.message);
				
				var cc = '';
				if (data.friends.length>0)
				{
					for (i = 0; i < data.friends.length; i++)
					{
						
						cc = cc+'<div class="myroundedbox"><div class="myroundedbox-outer"><div class="myroundedbox-inner"><div class="myroundedbox-title">';
				
						cc = cc+'<h3>'+data.friends[i].lastname+data.friends[i].firstname+'</h3>';
						
						cc = cc+'<table width="600px" border="0">';
						if (data.friends[i].userimage==""){
							cc = cc+'<tr><td rowspan="2" width="100"><p><img src="./images/default-photo.jpg" width="90" height="127"/></p></td>';
						}else{
							cc = cc+'<tr><td rowspan="2"  width="100"><p><img src="'+data.friends[i].userimage+'" width="90" height="127"/></p></td>';
						}
						
						cc = cc+'<td><p><strong>使用开发语言：</strong> '+data.friends[i].uselanguage+'</p><p><strong>兴趣爱好：</strong> '+data.friends[i].specialskill+'</p><p><strong>更多自我介绍：</strong> '+data.friends[i].moreaboutme+'</p></td></tr>';
						
						/*
						cc = cc+'<tr><td align="right"><a href="popup_message_send.php?user_id='+data.friends[i].id+'&height=200&width=300&TB_iframe=true" class="thickbox" title="发送消息">发送消息</a> | <a href="popup_friend_add.php?user_id='+data.friends[i].id+'&height=200&width=300&TB_iframe=true" class="thickbox" title="发送消息">加为好友<a></td></tr>';
						*/
						
						cc = cc+'<tr><td align="right"><a href="user_view.php?user_id='+data.friends[i].id+'" target="_blank">查看详细信息</a></td></tr>';
						
						
						
						cc = cc+'</table></div></div></div></div>';
						
					}
				}
				else
				{
					cc = '<h4>没有找到相关朋友……</h4>';
				}
					
				$('#showFriend').html(cc);
				
				
				
				//重新初如化thickbox
				//tb_init('a.thickbox');
				

			}
		});
	
}

function searchFriend(childOption,friendText){
		window.location='friend_list.php?childOption='+childOption+'&friendText='+encodeURIComponent(friendText);
}


