var UrbianSearchWin = null;
var current_search_tab_index = 0;
var myAllFriends = null;
var urbian_search_contacts = null;
var urbian_search_contactsDetail = null;
var urbian_search_others = null;
var urbian_search_othersDetail = null;
var urbian_search_ublogs = null;
var urbian_search_places = null;
var urbian_search_groups = null;
var urbian_search_albums = null;
var urbian_search_photos = null;
var urbian_search_polls = null;
function showSearchResultWin(){
	if(UrbianSearchWin!=null){
		UrbianSearchWin.destroy();
	}
	UrbianSearchWin = new Ext.Window({
		title: 'mGuanxi Search',
		width: 650,
		height: 420,
		shadow:false,
		id:'urbianSearchWin',
		layout:'fit',
		modal:true,
		resizable:true,
		plain: true,
		html:"<div id='urbianSearchMainDiv' style='width:98%;height:320px;padding:5px;overflow:auto;'></div>"
	});
	UrbianSearchWin.show();
}

function initializeMainDiv(){
	var mainDiv = $('urbianSearchMainDiv');
	var searchDiv = _CD('searchHeaderDiv', '100%', '60px', '', '');
	searchDiv.style.paddingTop='10px';
	searchDiv.style.backgroundColor = '#e6e6e6';
	searchDiv.align='left';
	mainDiv.appendChild(searchDiv);
	
	var srch_l_div = _CD('', '25px', '25px', '', 'f-l');
	srch_l_div.style.marginLeft='10px';
	srch_l_div.style.background = "url("+STATIC_IMAGE_PATH+"urbian_search_left.png)";
	searchDiv.appendChild(srch_l_div);
	var srch_m_div = _CD('', '200px', '25px', '', 'f-l');
	srch_m_div.style.background = "url("+STATIC_IMAGE_PATH+"urbian_search_mid.png)";
	srch_m_div.innerHTML = "<input type='text' id='searchKeyword' class='inputSearch' style='margin-top:6px;width:196px;' maxLength='30' onkeyup='enterGoSearch(event);' />";
	searchDiv.appendChild(srch_m_div);
	var srch_r_div = _CD('', '22px', '25px', '', 'f-l');
	srch_r_div.style.background = "url("+STATIC_IMAGE_PATH+"urbian_search_right.png)";
	srch_r_div.onclick=function(){$('searchKeyword').value='';$('searchKeyword').focus();}
	searchDiv.appendChild(srch_r_div);
	
	var resultForDiv = _CD('resultForDiv', '', '', '', '');
	resultForDiv.style.clear = 'both';
	resultForDiv.style.marginTop='30px';
	resultForDiv.style.marginLeft='10px';
	searchDiv.appendChild(resultForDiv);
	
	var tabDiv = _CD('searchTabDiv', '100%', '21px', '', '');
	tabDiv.style.backgroundColor = '#e6e6e6';
	tabDiv.style.borderBottom = '1px solid #ccc';
	mainDiv.appendChild(tabDiv);
	
	var tab0 = addTabPanel(0, search_tab_Contacts);
	var tab1 = addTabPanel(1, search_tab_OtherUsers);
	var tab2 = addTabPanel(2, search_tab_Blogs);
	var tab3 = addTabPanel(3, search_tab_Places);
	var tab4 = addTabPanel(4, search_tab_Groups);
	var tab5 = addTabPanel(5, search_tab_Photos);
	var tab6 = addTabPanel(6, search_tab_Polls);
	
	tabDiv.appendChild(tab0);
	tabDiv.appendChild(tab1);
	tabDiv.appendChild(tab2);
	tabDiv.appendChild(tab3);
	tabDiv.appendChild(tab4);
	tabDiv.appendChild(tab5);
	tabDiv.appendChild(tab6);
	
	var resultContentDiv = _CD('resultContentDiv', '100%', '', '', '');
	resultContentDiv.align='left';
	mainDiv.appendChild(resultContentDiv);
	
	var expandResultDiv = _CD('expandResultDiv', '100%', '', '', '');
	expandResultDiv.align='left';
	expandResultDiv.style.display='none';
	mainDiv.appendChild(expandResultDiv);
	
	var timer = setTimeout(function(){
		$('searchKeyword').focus();
	}, 500);
}

function addTabPanel(index, title){
	var tab = _C('div');
	tab.id = 'search_tab_'+index;
	tab.className='urbian_search_tab';
	tab.innerHTML = title;
	tab.onclick=function(){
		setSearchTab(index);
		if(current_search_tab_index==0){
			type='contacts';
		}else if(current_search_tab_index==1){
			type='others';
		}else if(current_search_tab_index==2){
			type='ublogs';
		}else if(current_search_tab_index==3){
			type='places';
		}else if(current_search_tab_index==4){
			type='groups';
		}else if(current_search_tab_index==5){
			type='albums';
		}else if(current_search_tab_index==6){
			type='polls';
		}
		goUrbianSearch(type);
	}
	return tab;
}

function setSearchTab(index){
	if($('searchTabDiv')){
		if(index==null || index==0){
			index=0;
		}
		current_search_tab_index = index;
		for(var i=0; i<$('searchTabDiv').childNodes.length; i++){
			if(i!=index){
				$('search_tab_'+i).style.border='0px';
				$('search_tab_'+i).style.fontWeight = 'normal';
				$('search_tab_'+i).style.backgroundColor='#e6e6e6';
			}else{
				$('search_tab_'+i).style.border='1px solid #ccc';
				$('search_tab_'+i).style.borderBottom = '1px solid #fff';
				$('search_tab_'+i).style.fontWeight = 'bold';
				$('search_tab_'+i).style.backgroundColor='#fff';
			}
		}
	}
}

function enterGoSearch(e){
	e=e||event;
	if(e.keyCode==13){
		urbian_search_contacts = null;
		urbian_search_contactsDetail = null;
		urbian_search_others = null;
		urbian_search_othersDetail = null;
		urbian_search_ublogs = null;
		urbian_search_places = null;
		urbian_search_groups = null;
		urbian_search_albums = null;
		urbian_search_photos = null;
		urbian_search_polls = null;
		if(current_search_tab_index==0){
			type='contacts';
		}else if(current_search_tab_index==1){
			type='others';
		}else if(current_search_tab_index==2){
			type='ublogs';
		}else if(current_search_tab_index==3){
			type='places';
		}else if(current_search_tab_index==4){
			type='groups';
		}else if(current_search_tab_index==5){
			type='albums';
		}else if(current_search_tab_index==6){
			type='polls';
		}
		goUrbianSearch(type);
	}
}

function goUrbianSearch(type){
	var keyword = $('searchKeyword').value.trim();
	if(keyword==''){return false;}
	if(urbian_search_contacts!=null && type=='contacts'){
		showResultsForContactsBase(urbian_search_contacts, 1, type);
	}else if(urbian_search_contactsDetail!=null && type=='contacts_detail'){
		showResultsForContactsDetail(urbian_search_contactsDetail, 1, type);
	}else if(urbian_search_others!=null && type=='others'){
		showResultsForOthersBase(urbian_search_others, 1, type);
	}else if(urbian_search_othersDetail!=null && type=='others_detail'){
		showResultsForOthersDetail(urbian_search_othersDetail, 1, type);
	}else if(urbian_search_ublogs!=null && type=='ublogs'){
		showResultsForuBlogs(urbian_search_ublogs, 1, type);
	}else if(urbian_search_places!=null && type=='places'){
		showResultsForPlaces(urbian_search_places, 1, type);
	}else if(urbian_search_groups!=null && type=='groups'){
		showResultsForGroups(urbian_search_groups, 1, type);
	}else if(urbian_search_albums!=null && type=='albums'){
		showResultsForAlbums(urbian_search_albums, 1, type);
	}else if(urbian_search_photos!=null && type=='photos'){
		showResultsForPhotos(urbian_search_photos, 1, type);
	}else if(urbian_search_polls!=null && type=='polls'){
		showResultsForPolls(urbian_search_polls, 1, type);
	}else{
		Ext.getBody().mask(searching);
		$('resultForDiv').innerHTML = searching;
		var request_friends = 0;
		if(myAllFriends==null){
			request_friends = 1;
		}
		Ext.Ajax.request({
			url:"ajax/urbian_search.php",
			method:"POST",
			params:{keyword:keyword, type:type, request_friends:request_friends},
			success:function(callBackStr,action){
				var obj = eval('['+callBackStr.responseText+']');
				if(obj[0].friends!=null){
					allMyFriends = obj[0].friends;
					myAllFriends = obj[0].friends;
				}
				Ext.getBody().unmask();
				$('resultForDiv').innerHTML = String.format(urbianSearchResultsFor, keyword);
				showSearchResult(obj[0].result, obj[0].type);
			},
			failure:function(obj,action){
				Ext.MessageBox.alert("Connection error","A network error occured during connection, please try again shortly.");
			}
		});
	}
}

function showSearchResult(results, type){
	if(type=='contacts'){
		setSearchTab(0);
		urbian_search_contacts = results['contacts'];
		showResultsForContactsBase(results['contacts'], 1, type);
	}else if(type=='contacts_detail'){
		setSearchTab(0);
		urbian_search_contactsDetail = results['contacts_detail'];
		showResultsForContactsDetail(results['contacts_detail'], 1, type, results['nocontacts']);
	}else if(type=='others'){
		setSearchTab(1);
		urbian_search_others = results['others'];
		showResultsForOthersBase(results['others'], 1, type);
	}else if(type=='others_detail'){
		setSearchTab(1);
		urbian_search_othersDetail = results['others_detail'];
		showResultsForOthersDetail(results['others_detail'], 1, type, results['noothers']);
	}else if(type=='ublogs'){
		setSearchTab(2);
		urbian_search_ublogs = results['ublogs'];
		showResultsForuBlogs(results['ublogs'], 1, type);
	}else if(type=='places'){
		setSearchTab(3);
		urbian_search_places = results['places'];
		showResultsForPlaces(results['places'], 1, type);
	}else if(type=='groups'){
		setSearchTab(4);
		urbian_search_groups = results['groups'];
		showResultsForGroups(results['groups'], 1, type);
	}else if(type=='albums'){
		setSearchTab(5);
		urbian_search_albums = results['albums'];
		showResultsForAlbums(results['albums'], 1, type);
	}else if(type=='photos'){
		setSearchTab(5);
		urbian_search_photos = results['photos'];
		showResultsForPhotos(results['photos'], 1, type, results['noalbum']);
	}else if(type=='polls'){
		setSearchTab(6);
		urbian_search_polls = results['polls'];
		showResultsForPolls(results['polls'], 1, type);
	}
}

function createTableList(id){
	var table = _CT('searchResultTable', '90%', 0, 0);
	table.style.marginTop='10px';
	table.align='center';
	$(id).appendChild(table);
	return table;
}

function getRBound(pagesize, page, length){
	var rbound = pagesize*page;
	if(rbound >= length){
		rbound = length;
	}
	return rbound;
}

function showResultsForContactsBase(contacts, page, type){
	$('resultContentDiv').innerHTML='';
	if(page==1){
		hideExpandDiv();
	}
	if(contacts!=null && contacts.length>0){
		var table = createTableList('resultContentDiv');
		var tr, td, actDiv;
		for(var i=3*(page-1); i<3*page; i++){
			tr = table.insertRow(table.rows.length);
			td = tr.insertCell(0);
			td.height=55;
			if(typeof(contacts[i])!='undefined'){
				td.width='12%';
				td.appendChild(addThumbImage('user', contacts[i]['image'], contacts[i]['name']+' '+contacts[i]['surname'], "friendDetails.php?uid="+contacts[i]['user_id']));
				td = tr.insertCell(1);
				td.width='60%';
				td.innerHTML = "<a href='userinfo.php?uid="+contacts[i]['user_id']+"'>"+contacts[i]['name']+' '+contacts[i]['surname']+"</a><br />"+contacts[i]['email'];
				td = tr.insertCell(2);
				actDiv = _CD('', '150px', '40px', '', '');
				actDiv.style.backgroundColor = '#fbffc2';
				actDiv.style.borderBottom='1px solid #8E020C';
				actDiv.innerHTML = "<div id='sendMsg_contacts_div_"+i+"' style='padding-top:5px;margin-left:20px;height:17px;'><a href='javascript:void(0);'>"+tooltip_sendMessage+"</a></div><div id='sendIntr_contacts_div_"+i+"' style='margin-left:20px;height:17px;'><a href='javascript:void(0);'>"+introduceToSomeone+"</a></div>";
				td.appendChild(actDiv);
			}else{
				td.colSpan=3;
			}
			if($('sendMsg_contacts_div_'+i)){
				$('sendMsg_contacts_div_'+i).onclick=function(){
					var index = this.id.split('_')[3];
					sendMsgTo = String.format($('sendMsgToWhom').value, contacts[index]['name']+' '+contacts[index]['surname']);
					currentFriendIdToMsg = contacts[index]['user_id'];
					typeInInvitationMessage = typeInInvitationShortMessage;
					showNormalMsgBox();
				}
			}
			if($('sendIntr_contacts_div_'+i)){
				$('sendIntr_contacts_div_'+i).onclick=function(){
					var index = this.id.split('_')[3];
					currentFriendId = contacts[index]['user_id'];
					sendEventInvite = friendIntroductionsText;
					typeInContactName = String.format($('introduceUserToText').value, contacts[index]['name']+' '+contacts[index]['surname']);
					showFriendsFilterBox();
				}
			}
		}
		addPagination(table, 3, contacts.length, 3, page, type);
		$('prelink_'+type).onclick=function(){showResultsForContactsBase(contacts, page-1, type);}
		$('nextlink_'+type).onclick=function(){showResultsForContactsBase(contacts, page+1, type);}
		var expandDiv = _C('div');
		expandDiv.align='center';
		expandDiv.style.borderBottom = '1px solid #aaa';
		expandDiv.innerHTML = "<a href='javascript:void(0);' id='expand_link_contacts' onclick='javascript:goUrbianSearch(\"contacts_detail\")'>"+expandMorePeopleResults+"</a><a href='javascript:void(0);' style='display:none;' id='close_link_contacts' onclick='javascript:hideExpandDiv(\"contacts\");'>"+closeMoreResults+"</a>";
		$('resultContentDiv').appendChild(expandDiv);
	}else{
		//$('resultContentDiv').innerHTML=String.format(noResultFor, $('searchKeyword').value.trim());
	}
}

function showResultsForContactsDetail(contacts, page, type, nocontacts){
	if(typeof(nocontacts)=='undefined'){
		$('expand_link_contacts').style.display='none';
		$('close_link_contacts').style.display='';
		var j = 0;
		if(contacts!=null && contacts.length>0){
			if(contacts.length>=3){
				j=3;
			}else{
				j = contacts.length;
			}
		}
		showExpandDiv(j*60);
	}else{ // no contacts result, show contacts detail result directly
		if(page==1){
			hideExpandDiv();
		}
		$('resultContentDiv').innerHTML='';
	}
	$('expandResultDiv').innerHTML = '';
	$('expandResultDiv').style.display='';
	if(contacts!=null && contacts.length>0){
		var table = createTableList('expandResultDiv');
		var tr, td, actDiv;
		for(var i=3*(page-1); i<getRBound(3, page, contacts.length); i++){
			tr = table.insertRow(table.rows.length);
			td = tr.insertCell(0);
			td.height=55;
			if(typeof(contacts[i])!='undefined'){
				td.width='12%';
				td.appendChild(addThumbImage('user', contacts[i]['image'], contacts[i]['name']+' '+contacts[i]['surname'], "friendDetails.php?uid="+contacts[i]['user_id']));
				td = tr.insertCell(1);
				td.width='60%';
				td.innerHTML = "<a href='userinfo.php?uid="+contacts[i]['user_id']+"'>"+contacts[i]['name']+' '+contacts[i]['surname']+"</a><div style='color:#808284;width:280px;height;35px;overflow:hidden;'>"+contacts[i]['highlight']+"</div>";
				td = tr.insertCell(2);
				actDiv = _CD('', '150px', '40px', '', '');
				actDiv.style.backgroundColor = '#fbffc2';
				actDiv.style.borderBottom='1px solid #8E020C';
				actDiv.innerHTML = "<div id='sendMsg_contactsde_div_"+i+"' style='padding-top:5px;margin-left:20px;height:17px;'><a href='javascript:void(0);'>"+tooltip_sendMessage+"</a></div><div id='sendIntr_contactsde_div_"+i+"' style='margin-left:20px;height:17px;'><a href='javascript:void(0);'>"+introduceToSomeone+"</a></div>";
				td.appendChild(actDiv);
			}else{
				td.colSpan=3;
			}
			if($('sendMsg_contactsde_div_'+i)){
				$('sendMsg_contactsde_div_'+i).onclick=function(){
					var index = this.id.split('_')[3];
					sendMsgTo = String.format($('sendMsgToWhom').value, contacts[index]['name']+' '+contacts[index]['surname']);
					currentFriendIdToMsg = contacts[index]['user_id'];
					typeInInvitationMessage = typeInInvitationShortMessage;
					showNormalMsgBox();
				}
			}
			if($('sendIntr_contactsde_div_'+i)){
				$('sendIntr_contactsde_div_'+i).onclick=function(){
					var index = this.id.split('_')[3];
					currentFriendId = contacts[index]['user_id'];
					sendEventInvite = friendIntroductionsText;
					typeInContactName = String.format($('introduceUserToText').value, contacts[index]['name']+' '+contacts[index]['surname']);
					showFriendsFilterBox();
				}
			}
		}
		addPagination(table, 3, contacts.length, 3, page, type);
		$('prelink_'+type).onclick=function(){showResultsForContactsDetail(contacts, page-1, type);}
		$('nextlink_'+type).onclick=function(){showResultsForContactsDetail(contacts, page+1, type);}
	}else{
		$('expandResultDiv').innerHTML=String.format(noResultFor, $('searchKeyword').value.trim());
	}
}

function showResultsForOthersBase(others, page, type){
	$('resultContentDiv').innerHTML='';
	hideExpandDiv();
	if(others!=null && others.length>0){
		var table = createTableList('resultContentDiv');
		var tr, td, actDiv,mutualStr;
		for(var i=3*(page-1); i<3*page; i++){
			tr = table.insertRow(table.rows.length);
			td = tr.insertCell(0);
			td.height=55;
			if(typeof(others[i])!='undefined'){
				td.width='12%';
				td.appendChild(addThumbImage('user', others[i]['image'], others[i]['name']+' '+others[i]['surname'], "userinfo.php?uid="+others[i]['user_id']));
				td = tr.insertCell(1);
				td.width='60%';
				mutualStr = '';
				if(others[i]['mutual_num']>0){
					mutualStr = "<div style='color:#808284;'>"+others[i]['mutual_num']+" mutual contacts: ";
					for(var m=0; m<others[i]['mutual_num']; m++){
						if(m<others[i]['mutual_num']-1){
							mutualStr+=others[i]['mutual'][m]['name']+'; ';
						}else{
							mutualStr+=others[i]['mutual'][m]['name'];
						}
					}
					mutualStr+='</div>';
				}
				td.innerHTML = "<a href='userinfo.php?uid="+others[i]['user_id']+"'>"+others[i]['name']+' '+others[i]['surname']+"</a><br />"+others[i]['email']+mutualStr;
				td = tr.insertCell(2);
				actDiv = _CD('', '150px', '40px', '', '');
				actDiv.style.backgroundColor = '#fbffc2';
				actDiv.style.borderBottom='1px solid #8E020C';
				actDiv.innerHTML = "<div id='add_other_div_"+i+"' style='padding-top:5px;margin-left:20px;height:17px;'><a href='javascript:void(0);'>"+addFriendsText+"</a></div><div id='sendMsg_others_div_"+i+"' style='margin-left:20px;height:17px;'><a href='javascript:void(0);'>"+tooltip_sendMessage+"</a></div>";
				td.appendChild(actDiv);
			}else{
				td.colSpan=3;
			}
			if($('add_other_div_'+i)){
				$('add_other_div_'+i).onclick=function(){
					var index = this.id.split('_')[3];
					addFriendID = others[index]['user_id'];
					typeInInvitationMessage = String.format($('addFriendMessage').value, others[index]['name']+' '+others[index]['surname']);
					createNormalBox(addFriendsText, this.id+'_box', 400, 200, addFriend, showAddFriendBoxHtml);
				}
			}
			if($('sendMsg_others_div_'+i)){
				$('sendMsg_others_div_'+i).onclick=function(){
					var index = this.id.split('_')[3];
					sendMsgTo = String.format($('sendMsgToWhom').value, others[index]['name']+' '+others[index]['surname']);
					currentFriendIdToMsg = others[index]['user_id'];
					typeInInvitationMessage = typeInInvitationShortMessage;
					showNormalMsgBox();
				}
			}
		}
		addPagination(table, 3, others.length, 3, page, type);
		$('prelink_'+type).onclick=function(){showResultsForOthersBase(others, page-1, type);}
		$('nextlink_'+type).onclick=function(){showResultsForOthersBase(others, page+1, type);}
		var expandDiv = _C('div');
		expandDiv.align='center';
		expandDiv.style.borderBottom = '1px solid #aaa';
		expandDiv.innerHTML = "<a href='javascript:void(0);' id='expand_link_others' onclick='javascript:goUrbianSearch(\"others_detail\")'>"+expandMorePeopleResults+"</a><a href='javascript:void(0);' style='display:none;' id='close_link_others' onclick='javascript:hideExpandDiv(\"others\");'>"+closeMoreResults+"</a>";
		$('resultContentDiv').appendChild(expandDiv);
	}else{
		//$('resultContentDiv').innerHTML=String.format(noResultFor, $('searchKeyword').value.trim());
	}
}

function showResultsForOthersDetail(others, page, type, noothers){
	if(typeof(noothers)=='undefined'){
		$('expand_link_others').style.display='none';
		$('close_link_others').style.display='';
		var j = 0;
		if(others!=null && others.length>0){
			if(others.length>=3){
				j=3;
			}else{
				j = others.length;
			}
		}
		showExpandDiv(j*60);
	}else{ // no contacts result, show contacts detail result directly
		if(page==1){
			hideExpandDiv();
		}
		$('resultContentDiv').innerHTML='';
	}
	$('expandResultDiv').innerHTML = '';
	$('expandResultDiv').style.display='';
	if(others!=null && others.length>0){
		var table = createTableList('expandResultDiv');
		var tr, td, actDiv, mutualStr;
		for(var i=3*(page-1); i<getRBound(3, page, others.length); i++){
			tr = table.insertRow(table.rows.length);
			td = tr.insertCell(0);
			td.height=55;
			if(typeof(others[i])!='undefined'){
				td.width='12%';
				td.appendChild(addThumbImage('user', others[i]['image'], others[i]['name']+' '+others[i]['surname'], "userinfo.php?uid="+others[i]['user_id']));
				td = tr.insertCell(1);
				td.width='60%';
				td.style.vAlign='top';
				mutualStr = '';
				if(others[i]['mutual_num']>0){
					mutualStr = others[i]['mutual_num']+" mutual contacts: ";
					for(var m=0; m<others[i]['mutual_num']; m++){
						if(m<others[i]['mutual_num']-1){
							mutualStr+=others[i]['mutual'][m]['name']+'; ';
						}else{
							mutualStr+=others[i]['mutual'][m]['name'];
						}
					}
					mutualStr+='<br />';
				}
				td.innerHTML = "<a href='userinfo.php?uid="+others[i]['user_id']+"'>"+others[i]['name']+' '+others[i]['surname']+"</a><div style='color:#808284;width:280px;height:35px;overflow:hidden;'>"+mutualStr+' '+others[i]['highlight']+"</div>";
				td = tr.insertCell(2);
				actDiv = _CD('', '150px', '40px', '', '');
				actDiv.style.backgroundColor = '#fbffc2';
				actDiv.style.borderBottom='1px solid #8E020C';
				actDiv.innerHTML = "<div id='add_otherde_div_"+i+"' style='padding-top:5px;margin-left:20px;height:17px;'><a href='javascript:void(0);'>"+addFriendsText+"</a></div><div id='sendMsg_othersde_div_"+i+"' style='margin-left:20px;height:17px;'><a href='javascript:void(0);'>"+tooltip_sendMessage+"</a></div>";
				td.appendChild(actDiv);
			}else{
				td.colSpan=3;
			}
			if($('add_otherde_div_'+i)){
				$('add_otherde_div_'+i).onclick=function(){
					var index = this.id.split('_')[3];
					addFriendID = others[index]['user_id'];
					typeInInvitationMessage = String.format($('addFriendMessage').value, others[index]['name']+' '+others[index]['surname']);
					createNormalBox(addFriendsText, this.id+'_box', 400, 200, addFriend, showAddFriendBoxHtml);
				}
			}
			if($('sendMsg_othersde_div_'+i)){
				$('sendMsg_othersde_div_'+i).onclick=function(){
					var index = this.id.split('_')[3];
					sendMsgTo = String.format($('sendMsgToWhom').value, others[index]['name']+' '+others[index]['surname']);
					currentFriendIdToMsg = others[index]['user_id'];
					typeInInvitationMessage = typeInInvitationShortMessage;
					showNormalMsgBox();
				}
			}
		}
		addPagination(table, 3, others.length, 3, page, type);
		$('prelink_'+type).onclick=function(){showResultsForOthersDetail(others, page-1, type);}
		$('nextlink_'+type).onclick=function(){showResultsForOthersDetail(others, page+1, type);}
	}else{
		$('expandResultDiv').innerHTML=String.format(noResultFor, $('searchKeyword').value.trim());
	}
}

function showResultsForuBlogs(ublogs, page, type){
	$('resultContentDiv').innerHTML='';
	hideExpandDiv();
	if(ublogs!=null && ublogs.length>0){
		var table = createTableList('resultContentDiv');
		var tr, td, img, div;
		for(var i=6*(page-1); i<getRBound(6, page, ublogs.length); i++){
			if(i%2==0){
				tr = table.insertRow(table.rows.length);
				td = tr.insertCell(0);
			}else{
				td = tr.insertCell(1);
			}
			td.height=55;
			td.style.width='50%';
			img = addThumbImage('user', ublogs[i]['image'], ublogs[i]['name']+' '+ublogs[i]['surname'], "userinfo.php?uid="+ublogs[i]['user_id']);
			img.className='f-l';
			td.appendChild(img);
			div = _C('div');
			div.className='f-l';
			div.style.margin='10px';
			div.style.width='180px';
			div.style.height='40px';
			div.style.overflow='hidden';
			if(ublogs[i]['user_id']==suser_id){
				div.innerHTML = "<a href='userinfo.php?uid="+ublogs[i]['user_id']+"'>"+ublogs[i]['name']+' '+ublogs[i]['surname']+"</a>&nbsp;<span style='color:#808284;'>Mentioned in "+ublogs[i]['posts']+" posts.</span><br /><a href='board.php?key="+$('searchKeyword').value.trim()+"'>"+String.format(goToUseruBlog, ublogs[i]['name'])+"</a>";
			}else{
				div.innerHTML = "<a href='userinfo.php?uid="+ublogs[i]['user_id']+"'>"+ublogs[i]['name']+' '+ublogs[i]['surname']+"</a>&nbsp;<span style='color:#808284;'>Mentioned in "+ublogs[i]['posts']+" posts.</span><br /><a href='userinfo.php?uid="+ublogs[i]['user_id']+"&key="+$('searchKeyword').value.trim()+"#uBlogs'>"+String.format(goToUseruBlog, ublogs[i]['name'])+"</a>";
			}
			td.appendChild(div);
		}
		addPagination(table, 3, ublogs.length, 6, page, type);
		$('prelink_'+type).onclick=function(){showResultsForuBlogs(ublogs, page-1, type);}
		$('nextlink_'+type).onclick=function(){showResultsForuBlogs(ublogs, page+1, type);}
	}else{
		$('resultContentDiv').innerHTML=String.format(noResultFor, $('searchKeyword').value.trim());
	}
}

function showResultsForPlaces(places, page, type){
	$('resultContentDiv').innerHTML='';
	hideExpandDiv();
	if(places!=null && places.length>0){
		var table = createTableList('resultContentDiv');
		var tr, td, img, div;
		for(var i=4*(page-1); i<4*page; i++){
			if(i%2==0){
				tr = table.insertRow(table.rows.length);
				td = tr.insertCell(0);
			}else{
				td = tr.insertCell(1);
			}
			td.height=90;
			td.style.width='50%';
			if(typeof(places[i])=='undefined'){
				continue;
			}
			img = addThumbImage('location', places[i]['image'], places[i]['name'], "locations.php?lid="+places[i]['location_id']);
			img.className='f-l';
			td.appendChild(img);
			div = _C('div');
			div.className='f-l';
			div.innerHTML = "<div style='width:140px;height:58px;margin-left:5px;overflow:hidden;'><div style='width:130px;height:12px;overflow:hidden;'><a href='locations.php?lid="+places[i]['location_id']+"'>"+places[i]['name']+"</a></div><div style='color:#808284;width:130px;height:45px;overflow:hidden;'>"+places[i]['description']+"</div></div>";
			td.appendChild(div);
			if(typeof(places[i]['distance'])!='undefined'){
				distance = parseInt(places[i]['distance']);
				if(distance<=1000){
					img = "Walking_2.png";
				}else if(distance>1000 && distance<=3000){
					img = "Cycling_2.png";
				}else{
					img = "Car_2.png";
				}
				div = _C('div');
				div.className='urbian_search_place_icon';
				div.style.background = "url("+STATIC_IMAGE_PATH+""+img+")";
				if(places[i]['athere']==0){
					if(distance==0){
						div.title=imnearByHere;
					}else{
						div.title=String.format(aboutDistance, distance, locationSrchOption2);
					}
				}else{
					div.title=imCurrentlyHere;
				}
				td.appendChild(div);
			}
			if(parseInt(places[i]['num'])>0){
				div = _C('div');
				div.className='urbian_search_place_num';
				div.innerHTML = "<a href='locations.php?lid="+places[i]['location_id']+"&act=1'>"+String.format(usersAreHereNow, places[i]['num'])+"</a>";
				td.appendChild(div);
			}
		}
		addPagination(table, 2, places.length, 4, page, type);
		$('prelink_'+type).onclick=function(){showResultsForPlaces(places, page-1, type);}
		$('nextlink_'+type).onclick=function(){showResultsForPlaces(places, page+1, type);}
	}else{
		$('resultContentDiv').innerHTML=String.format(noResultFor, $('searchKeyword').value.trim());
	}
}

function showResultsForGroups(groups, page, type){
	$('resultContentDiv').innerHTML='';
	hideExpandDiv();
	if(groups!=null && groups.length>0){
		var table = createTableList('resultContentDiv');
		var tr, td, actDiv;
		for(var i=3*(page-1); i<3*page; i++){
			tr = table.insertRow(table.rows.length);
			td = tr.insertCell(0);
			td.height=60;
			if(typeof(groups[i])!='undefined'){
				td.width='12%';
				td.appendChild(addThumbImage('group', groups[i]['image'], groups[i]['name'], "group_details.php?gid="+groups[i]['gid']));
				td = tr.insertCell(1);
				td.width='35%';
				td.innerHTML = "<div style='width:170px;height:60px;overflow:hidden;'><a href='group_details.php?gid="+groups[i]['gid']+"'>"+groups[i]['name']+"</a><div style='color:#808284;'>"+groups[i]['description']+"</div></div>";
				td = tr.insertCell(2);
				td.width='30%';
				td.innerHTML = groups[i]['members']+' members<br />category: '+groups[i]['category'];
				td = tr.insertCell(3);
				actDiv = _CD('', '150px', '40px', '', '');
				actDiv.style.backgroundColor = '#fbffc2';
				actDiv.style.borderBottom='1px solid #8E020C';
				if(groups[i]['ismember']>0){
					actDiv.innerHTML = "<div id='add_grpphoto_div_"+i+"' style='padding-top:5px;margin-left:10px;height:17px;'><a href='group_photoupload.php?gid="+groups[i]['gid']+"'>"+uploadPhotoToThisGroup+"</a></div><div id='add_grpinvite_div_"+i+"' style='margin-left:10px;height:17px;'><a href='javascript:void(0);'>"+inviteContactsToJoin+"</a></div>";
				}else{
					actDiv.innerHTML = "<div id='add_group_div_"+i+"' style='padding-top:10px;margin-left:10px;height:17px;'><a href='javascript:void(0);'>add this group</a></div>";
				}
				td.appendChild(actDiv);
			}else{
				td.colSpan=4;
			}
			if($('add_grpinvite_div_'+i)){
				$('add_grpinvite_div_'+i).onclick=function(){
					var index = this.id.split('_')[3];
					invite_group_id = groups[index]['gid'];
					sendEventInvite = groupInvitationsText;
					typeInInvitationMessage = tellThemWhyTheyAddGroupText;
					typeInContactName = $('introduceUserToGroupText').value;
					showFriendsFilterBox();
				}
			}
			if($('add_group_div_'+i)){
				$('add_group_div_'+i).onclick=function(){
					var index = this.id.split('_')[3];
					addGroupID = groups[index]['gid'];
					typeInInvitationMessage = String.format($('addPublicGroupMessageText').value, groups[index]['name']);
					createNormalBox('join group?', this.id+'_box', 300, 150, addGroup, showAddGroupBoxHtml);
					Ext.getCmp(this.id+'_box').buttons[0].setText('ok');
				}
			}
		}
		addPagination(table, 4, groups.length, 3, page, type);
		$('prelink_'+type).onclick=function(){showResultsForGroups(groups, page-1, type);}
		$('nextlink_'+type).onclick=function(){showResultsForGroups(groups, page+1, type);}
	}else{
		$('resultContentDiv').innerHTML=String.format(noResultFor, $('searchKeyword').value.trim());
	}
}

function showResultsForAlbums(albums, page, type){
	$('resultContentDiv').innerHTML='';
	if(page==1){
		hideExpandDiv();
	}
	if(albums!=null && albums.length>0){
		var table = createTableList('resultContentDiv');
		var tr, td, pdiv, tdiv, bdiv, photoDiv, actDiv;
		for(var i=2*(page-1); i<2*page; i++){
			tr = table.insertRow(table.rows.length);
			td = tr.insertCell(0);
			td.height=85;
			if(typeof(albums[i])!='undefined'){
				td.width='14%';
				if(albums[i]['cover_path']!=''){
					photoDiv = _C('div');
					photoDiv.className = 'urbian_search_photo_div';
					photoDiv.style.marginLeft = '0px';
					if(albums[i]['owner']==suser_id){
						var link = 'album_details.php?aid='+albums[i]['album_id'];
					}else{
						var link = 'album_view.php?fid='+albums[i]['owner']+'&aid='+albums[i]['album_id'];
					}
					photoDiv.appendChild(addThumbPhoto(USERS_IMAGE_PATH+'/'+albums[i]['cover_path']+'_s', 60, link));
					td.appendChild(photoDiv);
				}else{
					td.innerHTML = "<div style='width:60px;height:60px;border:1px solid #808284;'><br />&nbsp;no covor</div>";
				}
				td = tr.insertCell(1);
				td.width='35%';
				td.style.vAlign='top';
				if(albums[i]['owner']!='' && parseInt(albums[i]['owner'])>0){
					td.innerHTML = "<div style='margin-left:2px;width:120px;height:58px;overflow:hidden;'><a href='userinfo.php?uid="+albums[i]['owner']+"'>"+albums[i]['uname']+' '+albums[i]['surname']+"</a>'s album<br />"+albums[i]['name']+"<div style='color:#808284;'>"+albums[i]['description']+"</div></div>";
				}else if(albums[i]['gid']!='' && parseInt(albums[i]['gid'])>0){
					td.innerHTML = "<div style='margin-left:2px;width:120px;height:58px;overflow:hidden;'><a href='group_details.php?gid="+albums[i]['gid']+"'>"+albums[i]['gname']+"</a>'s album<br />"+albums[i]['name']+"<div style='color:#808284;'>"+albums[i]['description']+"</div></div>";
				}
				td = tr.insertCell(2);
				td.width='35%';
				if(albums[i]['photots']!=null){
					pdiv = _C('div');
					pdiv.style.width='170px';
					pdiv.style.height='70px';
					pdiv.style.borderLeft = "1px solid #808284";
					td.appendChild(pdiv);
					tdiv = _C('div');
					bdiv = _C('div');
					tdiv.style.width='170px';
					tdiv.style.height='40px';
					bdiv.style.width='170px';
					bdiv.style.height='40px';
					pdiv.appendChild(tdiv);
					pdiv.appendChild(bdiv);
					for(var p=0; p<10; p++){
						if(typeof(albums[i]['photots'][p])!='undefined'){
							photoDiv = _C('div');
							photoDiv.className='urbian_search_photo_thumb_div';
							photoDiv.appendChild(addThumbPhoto(USERS_IMAGE_PATH+'/'+albums[i]['photots'][p]['path']+'_s', 25, 'showPhoto.php?aid='+albums[i]['photots'][p]['album_id']+'&pid='+albums[i]['photots'][p]['photo_id']+'&fid='+albums[i]['photots'][p]['owner']));
							if(p<5){
								tdiv.appendChild(photoDiv);
							}else{
								bdiv.appendChild(photoDiv);
							}
						}
					}
				}
				td = tr.insertCell(3);
				actDiv = _CD('', '150px', '40px', '', '');
				actDiv.style.backgroundColor = '#fbffc2';
				actDiv.style.borderBottom='1px solid #8E020C';
				if(albums[i]['owner']==suser_id){
					actDiv.innerHTML = "<div id='add_otherde_div_"+i+"' style='padding-top:10px;margin-left:10px;height:17px;'><a href='photo_upload.php?aid="+albums[i]['album_id']+"'>"+uploadPhotoToThisAlbum+"</a></div>";
				}else if(albums[i]['owner']!=''){
					actDiv.innerHTML = "<div id='add_otherde_div_"+i+"' style='padding-top:10px;margin-left:10px;height:17px;'><a href='album_view.php?fid="+albums[i]['owner']+"&aid="+albums[i]['album_id']+"'>"+takeToAlbum+"</a></div>";
				}else if(albums[i]['gid']!=''){
					actDiv.innerHTML = "<div id='add_otherde_div_"+i+"' style='padding-top:10px;margin-left:10px;height:17px;'><a href='album_details.php?gid="+albums[i]['gid']+"'>"+takeToAlbum+"</a></div>";
				}
				td.appendChild(actDiv);
			}else{
				td.colSpan=4;
			}
		}
		addPagination(table, 4, albums.length, 2, page, type);
		$('prelink_'+type).onclick=function(){showResultsForAlbums(albums, page-1, type);}
		$('nextlink_'+type).onclick=function(){showResultsForAlbums(albums, page+1, type);}
		var expandDiv = _C('div');
		expandDiv.align='center';
		expandDiv.style.borderBottom = '1px solid #aaa';
		expandDiv.innerHTML = "<a href='javascript:void(0);' id='expand_link_albums' onclick='javascript:goUrbianSearch(\"photos\")'>"+expandMorePhotoResults+"</a><a href='javascript:void(0);' style='display:none;' id='close_link_albums' onclick='javascript:hideExpandDiv(\"albums\");'>"+closeMoreResults+"</a>";
		$('resultContentDiv').appendChild(expandDiv);
	}else{
		//$('resultContentDiv').innerHTML=String.format(noResultFor, $('searchKeyword').value.trim());
	}
}

function showResultsForPhotos(photos, page, type, noalbum){
	//if($('expand_link_albums')){
	if(typeof(noalbum)=='undefined'){
		$('expand_link_albums').style.display='none';
		$('close_link_albums').style.display='';
		var j = 0;
		if(photos!=null && photos.length>0){
			if(Math.ceil(photos.length/4)>=2){
				j=2;
			}else{
				j = Math.ceil(photos.length/4);
			}
		}
		showExpandDiv(j*115);
	}else{ // no albums result, show photos result directly
		if(page==1){
			hideExpandDiv();
		}
		$('resultContentDiv').innerHTML='';
	}
	$('expandResultDiv').innerHTML = '';
	$('expandResultDiv').style.display='';
	if(photos!=null && photos.length>0){
		var table = createTableList('expandResultDiv');
		var tr, td, photoDiv, link, capDiv;
		for(var i=8*(page-1); i<8*page; i++){
			if(i%4==0){
				tr = table.insertRow(table.rows.length);
			}
			td = tr.insertCell(tr.cells.length);
			td.width='25%';
			if(typeof(photos[i])!='undefined'){
				td.height=90;
				photoDiv = _C('div');
				photoDiv.className = 'urbian_search_photo_div';
				link = 'showPhoto.php?aid='+photos[i]['album_id']+'&pid='+photos[i]['photo_id']+'&fid='+photos[i]['owner'];
				photoDiv.appendChild(addThumbPhoto(USERS_IMAGE_PATH+'/'+photos[i]['path']+'_s', 60, link));
				td.appendChild(photoDiv);
				capDiv = _C('div');
				capDiv.className = 'urbian_search_photocap_div';
				capDiv.align='center';
				capDiv.innerHTML = photos[i]['name']+"<div style='color:#808284;'>"+fromTheAlbum+photos[i]['album_name']+"</div>";
				td.appendChild(capDiv);
			}else{
				td.innerHTML = "&nbsp;";
			}
		}
		addPagination(table, 4, photos.length, 8, page, type);
		$('prelink_'+type).onclick=function(){showResultsForPhotos(photos, page-1, type);}
		$('nextlink_'+type).onclick=function(){showResultsForPhotos(photos, page+1, type);}
	}else{
		$('expandResultDiv').innerHTML=String.format(noResultFor, $('searchKeyword').value.trim());
	}
}

function addThumbPhoto(path, scale, link){
	var img = _C('img');
	img.style.cursor = "pointer";
	img.style.display='none';
	img.onload=function(){
		var image=new Image();
		image.src=path;
		var timer = setInterval(function(){
			if(image.width>0){
				clearInterval(timer);
				if(image.width<scale && image.height<scale){
					img.style.marginTop=Math.round((scale-image.height)/2)+"px";
					img.style.marginLeft=Math.round((scale-image.width)/2)+"px";
				}else if(image.width > image.height){
					img.style.width=scale+"px";
					img.style.height=Math.round((image.height*scale)/image.width)+"px";
					img.style.marginTop=Math.round((scale-parseInt(img.style.height))/2)+"px";
				}else if(image.width <= image.height){
					img.style.height=scale+"px";
					img.style.width=Math.round((image.width*scale)/image.height)+"px";
					img.style.marginLeft=Math.round((scale-parseInt(img.style.width))/2)+"px";
				}
				img.style.display='';
				image=null;
			}
		}, 5);
	}
	img.src = path;
	if(link!=''){
		img.onclick=function(){
			document.location.href=link;
		}
	}
	return img;
}

function showResultsForPolls(polls, page, type){
	$('resultContentDiv').innerHTML='';
	hideExpandDiv();
	if(polls!=null && polls.length>0){
		var div = _C('div');
		var table = createTableList('resultContentDiv');
		table.width='100%';
		var tr,td;
		var iconDiv, nDiv, iconDivL, iconDivM, iconDivR, itemDiv, myVoteDiv;
		for(var i=3*(page-1); i<3*page; i++){
		if(typeof(polls[i])!='undefined'){
			tr = table.insertRow(table.rows.length);
			tr.className=(i%2==0)?'':'messageBodyHighlight';
			td = tr.insertCell(0);
			td.width='50%';
			td.innerHTML = "<div style='font-weight:bold;margin-top:10px;' class='mediumText'><a href='vote.php?vid="+polls[i]['vote_id']+"'>"+polls[i]['subject']+"</a></div>";
			td = tr.insertCell(1);
			td.width='50%';
			td.vAlign='bottom';
			td.style.textAlign='right';
			if(polls[i]['posts']!=null && polls[i]['posts']>0 && typeof(polls[i]['lastpost'].user_id)!='undefined'){
				td.innerHTML=lastPostByWho+" <a href='userinfo.php?uid="+polls[i]['lastpost'].user_id+"'>"+polls[i]['lastpost'].name+' '+polls[i]['lastpost'].surname+"</a>&nbsp;|&nbsp;"+polls[i]['lastpost'].vote_time;
			}
			tr = table.insertRow(table.rows.length);
			tr.className=(i%2==0)?'':'messageBodyHighlight';
			td = tr.insertCell(0);
			if(polls[i]['posts']!=null && polls[i]['posts']>0){
				td.innerHTML=String.format(voteTotalText, polls[i]['posts'], polls[i]['people'], polls[i]['comments']==''?0:polls[i]['comments']);
			}
			td = tr.insertCell(1);
			td.style.textAlign='right';
			td.innerHTML=createdBy+" <a href='userinfo.php?uid="+polls[i]['creator']+"'>"+polls[i]['name']+' '+polls[i]['surname']+"</a>&nbsp;|&nbsp;"+polls[i]['create_time'];
			
			tr = table.insertRow(table.rows.length);
			tr.className=(i%2==0)?'':'messageBodyHighlight';
			td = tr.insertCell(0);
			td.colSpan=2;
			td.style.paddingTop='5px';
			td.style.paddingBottom='5px';
			td.style.borderBottom='1px solid #aaa';
			td.align='center';
		
				iconDiv = _C('div');
				iconDiv.className='f-l';
				iconDiv.style.marginTop='5px';
				iconDiv.style.marginLeft='100px';
				iconDiv.style.width='20px';
				td.appendChild(iconDiv);
			
				nDiv = _C('div');
				nDiv.className='f-l smallText notification_div';
				nDiv.style.marginBottom = '5px';
				nDiv.style.cursor='auto';
				td.appendChild(nDiv);
				
				iconDivL = _C('div');
				iconDivL.className='icon_divL';
				nDiv.appendChild(iconDivL);
				
				iconDivM = _C('div');
				iconDivM.className = 'icon_divM';
				iconDivM.style.width='310px';
				iconDivM.style.overflow='hidden';
				iconDivM.style.fontWeight='bold';
				nDiv.appendChild(iconDivM);
				
				iconDivR = _C('div');
				iconDivR.className='icon_divR';
				nDiv.appendChild(iconDivR);
			
				itemDiv = _C('div');
				itemDiv.style.paddingTop='5px';
				var desc = "";
				if(polls[i]['posts']!=null && polls[i]['posts']>0){
					if(polls[i]['type']==1){
						iconDiv.innerHTML="<img src='"+STATIC_IMAGE_PATH+"Poll_icon_slider.png' />";
						desc = mostPoepleThink+' '+polls[i]['option'];
					}else if(polls[i]['type']==2){
						iconDiv.innerHTML="<img src='"+STATIC_IMAGE_PATH+"Poll_icon_vote.png' />";
						desc = polls[i]['percent']+' '+votedFor+' '+polls[i]['option'];
					}else if(polls[i]['type']==3){
						iconDiv.innerHTML="<img src='"+STATIC_IMAGE_PATH+"Poll_icon_rank.png' />";
						desc = mostPoeplePrefer+' '+polls[i]['option'];
					}
				}else{
					desc = noVotesForPoll;
					if(polls[i]['type']==1){
						iconDiv.innerHTML="<img src='"+STATIC_IMAGE_PATH+"Poll_icon_slider.png' />";
					}else if(polls[i]['type']==2){
						iconDiv.innerHTML="<img src='"+STATIC_IMAGE_PATH+"Poll_icon_vote.png' />";
					}else if(polls[i]['type']==3){
						iconDiv.innerHTML="<img src='"+STATIC_IMAGE_PATH+"Poll_icon_rank.png' />";
					}
				}
				itemDiv.innerHTML = desc;
				itemDiv.style.height='14px';
				itemDiv.style.overflow='hidden';
				iconDivM.appendChild(itemDiv);	
			
			
			myVoteDiv = _C('div');
			myVoteDiv.className='f-l';
			myVoteDiv.style.marginTop='10px';
			myVoteDiv.style.marginLeft='10px';
			td.appendChild(myVoteDiv);
			if(polls[i]['myvote']==0 && polls[i]['expired']==0){
				myVoteDiv.innerHTML = "<a href='vote.php?vid="+polls[i]['vote_id']+"'>"+castMyVote+"</a>";
			}else if(polls[i]['myvote']==1){
				myVoteDiv.innerHTML = "<span style='color:#aaa;'>"+IAlreadyVoted+"</span>";
			}
			
			var exDiv = _C('div');
			exDiv.className='f-l';
			exDiv.style.width='100%';
			if(polls[i]['expired']==1){
				exDiv.innerHTML = "<b>"+String.format(pollExpiredText, polls[i]['expire_time'])+"</b>";
			}
			td.appendChild(exDiv);
			}
		}
		addPagination(table, 2, polls.length, 3, page, type);
		$('prelink_'+type).onclick=function(){showResultsForPolls(polls, page-1, type);}
		$('nextlink_'+type).onclick=function(){showResultsForPolls(polls, page+1, type);}
	}else{
		$('resultContentDiv').innerHTML=String.format(noResultFor, $('searchKeyword').value.trim());
	}
}

function showExpandDiv(height){
	var div = $('urbianSearchMainDiv');
	if(UrbianSearchWin.height<=420){
		var winHeight=420;
		var timer = setInterval(function(){
			if(parseInt(div.style.height)<(320+height)){
				div.style.height = parseInt(div.style.height)+10+'px';
				winHeight+=10;
				UrbianSearchWin.setHeight(winHeight);
			}else{
				clearInterval(timer);
				UrbianSearchWin.height = winHeight;
			}
		}, 5);
	}
}

function hideExpandDiv(type){
	var div = $('urbianSearchMainDiv');
	$('expandResultDiv').style.display='none';
	if(typeof(type)!='undefined'){
		$('expand_link_'+type).style.display='';
		$('close_link_'+type).style.display='none';
	}
	if(parseInt(div.style.height)>320){
		var winHeight=UrbianSearchWin.height;
		var timer = setInterval(function(){
			if(parseInt(div.style.height)>320){
				div.style.height = parseInt(div.style.height)-10+'px';
				winHeight-=10;
				UrbianSearchWin.setHeight(winHeight);
			}else{
				clearInterval(timer);
				UrbianSearchWin.height = winHeight;
			}
		}, 5);
	}
}

function addPagination(table, colsnum, totalResults, pagesize, current_page, type){
	var tr = table.insertRow(table.rows.length);
	var td = tr.insertCell(0);
	td.colSpan=colsnum;
	td.align='center';
	var pages = Math.ceil(totalResults/pagesize);
	var pre = "<a id='prelink_"+type+"' href='javascript:void(0);' style='display:none;'>"+previousText+"</a>&nbsp;";
	var next = "&nbsp;<a id='nextlink_"+type+"' href='javascript:void(0);' style='display:none;'>"+nextText+"</a>";
	td.innerHTML = pre+current_page+"/"+pages+next+"&nbsp;"+String.format(resultsInTotal, totalResults);
	if(current_page>1){
		$('prelink_'+type).style.display='';
	}
	if(current_page<pages){
		$('nextlink_'+type).style.display='';
	}
}

	function showAddGroupBoxHtml(win){
		var textareaDiv = _CD('', '', '', '', 'smallText');
		textareaDiv.style.marginTop='5px';
		textareaDiv.style.marginBottom='5px';
		textareaDiv.innerHTML = typeInInvitationMessage;
		$('boxDiv').appendChild(textareaDiv);
	}
	
	function showAddFriendBoxHtml(win){
		var textareaDiv = _CD('', '', '', '', 'smallText');
		textareaDiv.style.marginTop='5px';
		textareaDiv.style.marginBottom='5px';
		textareaDiv.innerHTML = typeInInvitationMessage;
		$('boxDiv').appendChild(textareaDiv);
	
		var textarea = _C('textarea');
		textarea.id = 'message';
		textarea.className='inputText';
		textarea.style.width='315px';
		textarea.style.height='60px';
		$('boxDiv').appendChild(textarea);
	}
	
	function addFriend(win, id){
		Ext.getBody().mask(sendingMessage);
		Ext.Ajax.request({
			url:"ajax/send_friend_request.php",
			method:"POST",
			params:{addFriendId:addFriendID, addFriendMsg:$('message').value},
			success:function(callBackStr,action){
				var rs = callBackStr.responseText.trim();
				if(rs=='1'){
					showAlert(friendRequestSucc);
				}else if(rs=='3'){
					showAlert(friendRequestExist);
				}else if(rs=='5'){
					showAlert(friendRequestIntroduced);
				}
				$(id.substring(0, id.length-4)).innerHTML = contactRequestPending;
				$(id.substring(0, id.length-4)).id = '';
				Ext.getBody().unmask();
				win.close();
			},
			failure:function(){
				Ext.MessageBox.alert("Connection error","A network error occured during connection, please try again shortly.");
			}
		});
	}
	
	function addGroup(win, id){
		Ext.getBody().mask(sendingMessage);
		Ext.Ajax.request({
			url:"ajax/group_join.php",
			method:"POST",
			params:{addGroupId:addGroupID, addGroupMsg:''},
			success:function(callBackStr,action){
				var rs = callBackStr.responseText.trim();
				if(rs.indexOf('join succ')>-1){
					showAlert(joinGroupSucc);
					var index =id.split('_')[3];
					$(id.substring(0, id.length-4)).parentNode.innerHTML = "<div id='add_grpphoto_div_"+index+"' style='padding-top:5px;margin-left:10px;height:17px;'><a href='group_photoupload.php?gid="+addGroupID+"'>"+uploadPhotoToThisAlbum+"</a></div><div id='add_grpinvite_div_"+index+"' style='margin-left:10px;height:17px;'><a href='javascript:void(0);'>"+inviteContactsToJoin+"</a></div>";
					if($('add_grpinvite_div_'+index)){
						$('add_grpinvite_div_'+index).onclick=function(){
							invite_group_id = addGroupID;
							sendEventInvite = groupInvitationsText;
							typeInInvitationMessage = tellThemWhyTheyAddGroupText;
							typeInContactName = $('introduceUserToGroupText').value;
							showFriendsFilterBox();
						}
					}
				}else if(rs.indexOf('sent request')>-1){
					showAlert(joinGroupRequestSucc);
				}
				Ext.getBody().unmask();
				win.close();
			},
			failure:function(){
				Ext.MessageBox.alert("Connection error","A network error occured during connection, please try again shortly.");
			}
		});
	}