var disappear=true;var currentResultRow=-1;function chkUrbianDataKeyword(N,C){var F=[];var P=N.toLowerCase().split(" ");var G,D,L,M,R,H,Q;var E=0;var B=0;var O="";var A=0;for(var I=0;I<P.length;I++){Q=P[I].trim();if(Q!=""){A++}}for(var K=0;K<C.length;K++){if(typeof (C[K]["user_id"])!="undefined"&&typeof (C[K]["surname"])!="undefined"){G=C[K]["name"]+" "+C[K]["surname"];D=C[K]["name"].toLowerCase()+" "+C[K]["surname"].toLowerCase()}else{if(typeof (C[K]["location_id"])!="undefined"){G=C[K]["name"];D=C[K]["name"].toLowerCase()}else{if(typeof (C[K]["gid"])!="undefined"){G=C[K]["name"];D=C[K]["name"].toLowerCase()}else{if(typeof (C[K]["label_id"])!="undefined"){G=C[K]["name"];D=C[K]["name"].toLowerCase()}}}}L=G.split(" ");M=D.split(" ");O="";B=0;for(var J=0;J<M.length;J++){R=M[J].trim();if(R!=""){for(var I=0;I<P.length;I++){Q=P[I].trim();if(Q!=""&&O.indexOf(I)<0){H=Q.length;if(R.substring(0,H)==Q){O+=I+",";B++;L[J]='<span style="background-color:#ddd;"><b>'+L[J].substring(0,H)+"</b></span>"+L[J].substring(H,L[J].length);break}}}}}if(B==A){if(typeof (F[E])=="undefined"){F[E]=[]}F[E]["index"]=K;if(typeof (F[E]["username"])=="undefined"){F[E]["username"]=[]}F[E]["username"]=L.join(" ");E++}if(E>10){break}}return F}function showMatchResultList(G,A,I,B){if(G.length>0){currentResultRow=-1;if($(A).parentNode){$(A).parentNode.style.display=""}$(A).innerHTML="";var E,J,H,C,F;J=_CT("resultTable","100%",0,0);$(A).appendChild(J);for(var D=0;D<G.length;D++){H=J.insertRow(D);H.id="tr_"+A+"_"+G[D]["index"]+"_"+D;H.onmouseover=function(){var K=this.id.split("_");currentResultRow=K[3]};C=H.insertCell(0);C.width="10%";C.style.borderBottom="1px solid #ddd";C.align="right";C.style.paddingTop="4px";C.style.paddingRight="2px";E=_C("img");if(I[G[D]["index"]]["image"]==""){if(typeof (I[G[D]["index"]]["user_id"])!="undefined"&&typeof (I[G[D]["index"]]["surname"])!="undefined"){image=STATIC_IMAGE_PATH+"user_defaultsmall"}else{if(typeof (I[G[D]["index"]]["location_id"])!="undefined"){image=STATIC_IMAGE_PATH+"loc_defaulticon.png"}else{if(typeof (I[G[D]["index"]]["gid"])!="undefined"){image=STATIC_IMAGE_PATH+"group_defaultsmall"}}}}else{if(typeof (I[G[D]["index"]]["label_id"])!="undefined"){image=STATIC_IMAGE_PATH+"labelsPalette.png"}else{image=USERS_IMAGE_PATH+"/"+I[G[D]["index"]]["image"]+"small"}}E.src=image;if(typeof (I[G[D]["index"]]["label_id"])!="undefined"){}else{E.className="nowOnline_img"}C.appendChild(E);C=H.insertCell(1);C.width="90%";C.style.borderBottom="1px solid #ddd";if(typeof (I[G[D]["index"]]["user_id"])!="undefined"&&typeof (I[G[D]["index"]]["surname"])!="undefined"){if(I[G[D]["index"]]["employer"]!=""){F=I[G[D]["index"]]["employer"]+"&nbsp;"}else{if(I[G[D]["index"]]["school"]!=""){F=I[G[D]["index"]]["school"]+"&nbsp;"}else{F=contactText}}}else{if(typeof (I[G[D]["index"]]["location_id"])!="undefined"){if(I[G[D]["index"]]["address"]!=""){F=I[G[D]["index"]]["address"]+"&nbsp;"}else{F=venueText}}else{if(typeof (I[G[D]["index"]]["gid"])!="undefined"){F=groupText}else{if(typeof (I[G[D]["index"]]["label_id"])!="undefined"){F=(I[G[D]["index"]]["members"]>0?I[G[D]["index"]]["members"]:0)+withinThisLabel}}}}C.innerHTML="<div class='smallText' style='width:"+B+"px;height:13px;overflow:hidden;'>"+G[D]["username"]+"</div><div id='suggest_desc_div_"+G[D]["index"]+"' class='smallTextLight' style='width:"+B+"px;height:13px;overflow:hidden;'>"+F+"</div>";if(typeof (I[G[D]["index"]]["label_id"])!="undefined"){getLabelFriends(I[G[D]["index"]]["label_id"],G[D]["index"],F,I)}}if($("resultTable")){$("resultTable").onmouseover=function(){disappear=false;if(currentResultRow>this.rows.length-1){currentResultRow=0}else{if(currentResultRow<0){currentResultRow=-1}}for(var K=0;K<this.rows.length;K++){if(K==currentResultRow){this.rows[K].style.backgroundColor="#ddd"}else{this.rows[K].style.backgroundColor=""}}disappear=true};$("resultTable").onclick=function(){if(currentResultRow>-1){var K=this.rows[currentResultRow].id.split("_");$(A).innerHTML="";if($(A).parentNode){$(A).parentNode.style.display="none"}if(typeof (I[K[2]]["user_id"])!="undefined"&&typeof (I[K[2]]["surname"])!="undefined"){document.location.href="friendDetails.php?uid="+I[K[2]]["user_id"]}else{if(typeof (I[K[2]]["location_id"])!="undefined"){document.location.href="locations.php?lid="+I[K[2]]["location_id"]}else{if(typeof (I[K[2]]["gid"])!="undefined"){document.location.href="group_details.php?gid="+I[K[2]]["gid"]}else{if(typeof (I[K[2]]["label_id"])!="undefined"){document.location.href="friends.php?action=showLabel&lid="+I[K[2]]["label_id"]}}}}}};$("resultTable").onmouseout=function(){disappear=true}}}else{$(A).innerHTML="";if($(A).parentNode){$(A).parentNode.style.display="none"}}}function getLabelFriends(lid,index,desc,suggestData){if(typeof (suggestData[index]["friends"])=="undefined"){suggestData[index]["friends"]=[];Ext.Ajax.request({url:"ajax/get_labelusers.php?lid="+lid,success:function(obj){var friends=eval(obj.responseText);suggestData[index]["friends"]=friends;var str="";for(var i=0;i<suggestData[index]["friends"].length;i++){if(i==suggestData[index]["friends"].length-1){str+=suggestData[index]["friends"][i].name+" "+suggestData[index]["friends"][i].surname}else{str+=suggestData[index]["friends"][i].name+" "+suggestData[index]["friends"][i].surname+", "}}if(typeof (suggestData[index]["friendsStr"])=="undefined"){suggestData[index]["friendsStr"]=[];suggestData[index]["friendsStr"]=str}$("suggest_desc_div_"+index).innerHTML=desc+" ("+suggestData[index]["friendsStr"]+")"}})}else{$("suggest_desc_div_"+index).innerHTML=desc+" ("+suggestData[index]["friendsStr"]+")"}}function showFriendsFilterBox(A){var B=new Ext.Window({title:sendEventInvite,width:400,height:250,shadow:false,id:"inviteWin",layout:"fit",modal:true,resizable:false,plain:true,html:"<div id='leftDiv' style='float:left;width:180px;border-right:1px solid #aaa;height:100%;padding:5px;text-align:left;'></div><div id='rightDiv' style='float:left;width:130px;text-align:left;padding:5px;'></div>",buttons:[{text:sendText,handler:function(){sendInvitation(B)}},{text:cancelText,handler:function(){B.close()}}]});B.show();showHtmlStr(B,A)}function showNormalMsgBox(){var A=new Ext.Window({title:sendMsgTo,width:400,height:250,shadow:false,id:"inviteWin",layout:"fit",modal:true,resizable:false,plain:true,html:"<div id='leftDiv' style='width:320px;height:100%;padding:5px;text-align:left;'></div>",buttons:[{text:sendText,handler:function(){sendShortMessage(A)}},{text:cancelText,handler:function(){A.close()}}]});A.show();showHtmlMsgStr(A)}function showHtmlStr(E,F){var J=_CD("","","","","smallText");J.style.marginBottom="5px";J.innerHTML=typeInContactName;$("leftDiv").appendChild(J);var G=_C("input");G.className="inputText";G.style.width="170px";G.id="searchInviteString";$("leftDiv").appendChild(G);var C=_C("div");C.style.position="relative";C.style.top="-160px";if(Ext.isIE6||Ext.isIE7){C.style.left="-163px"}else{C.style.left="36px"}C.style.height="0px";C.style.zIndex=99999;$("inviteWin").appendChild(C);var A=_CD("resultInviteDiv","170px","","1px solid #aaa","");A.style.position="absolute";A.style.top="1px";A.style.backgroundColor="#fff";A.style.display="none";A.style.cursor="pointer";A.style.textAlign="left";C.appendChild(A);var I=_CD("","","","","smallText");I.style.marginTop="5px";I.style.marginBottom="5px";I.innerHTML=typeInInvitationMessage;$("leftDiv").appendChild(I);var H=_C("textarea");H.id="message";H.className="inputText";H.style.width="170px";H.style.height="60px";$("leftDiv").appendChild(H);var D=_CD("peopleDiv","","128px","","");D.style.overflow="auto";$("rightDiv").appendChild(D);G.onkeyup=function(N){N=N||event;if(N.keyCode==40){if($("resultTable")){currentResultRow++;$("resultTable").onmouseover()}}else{if(N.keyCode==38){if($("resultTable")){currentResultRow--;$("resultTable").onmouseover()}}else{if(N.keyCode==13){if(currentResultRow>=0&&$("resultTable")){$("resultTable").onclick()}else{if(F=="poll"){showTypeEmailBox(sendPollEmailInvitation,sendPollInvitation)}}}else{var K=this.value.trim();$("resultInviteDiv").style.display="none";if(typeof (F)!="undefined"&&F=="locations"){if(K!=""){var L=chkUrbianDataKeyword(K,myLocationsData);showMatchResultList(L,"resultInviteDiv",myLocationsData,130);$("resultInviteDiv").style.display=""}}else{if(K!=""){var L=chkUrbianDataKeyword(K,myFriendsData);showMatchResultList(L,"resultInviteDiv",myFriendsData,130);$("resultInviteDiv").style.display="";if(F=="poll"&&$("resultTable")){var M=$("resultTable").insertRow($("resultTable").rows.length);M.onmouseover=function(){currentResultRow=$("resultTable").rows.length-1;this.style.backgroundColor="#ddd"};M.onmouseout=function(){this.style.backgroundColor=""};var O=M.insertCell(0);O.colSpan=2;O.innerHTML=inviteUserByEmailText}}}if($("resultTable")){$("resultTable").onclick=function(){if(currentResultRow>-1){if(this.rows[currentResultRow].id!=""){var P=this.rows[currentResultRow].id.split("_");$("searchInviteString").value="";$("resultInviteDiv").innerHTML="";$("resultInviteDiv").style.display="none";if(typeof (F)!="undefined"&&F=="locations"){addLocation(P[2])}else{addPeople(P[2])}}else{if(F=="poll"){$("searchInviteString").value="";$("resultInviteDiv").innerHTML="";$("resultInviteDiv").style.display="none";showTypeEmailBox(sendPollEmailInvitation,sendPollInvitation)}}}}}}}}};$("searchInviteString").onblur=function(){if(disappear){if($("resultTable")){$("resultTable").onclick();$("resultInviteDiv").style.display="none"}}};$("searchInviteString").onfocus=function(){if($("resultTable")){$("resultInviteDiv").style.display=""}else{$("resultInviteDiv").style.display="none"}};var B=setTimeout(function(){$("searchInviteString").focus()},1000)}function showHtmlMsgStr(E){var D=_CD("","","","","smallText");D.style.marginBottom="5px";D.innerHTML=messageSubject;$("leftDiv").appendChild(D);var C=_C("input");C.className="inputText";C.style.width="315px";C.id="subject";$("leftDiv").appendChild(C);var B=_CD("","","","","smallText");B.style.marginTop="5px";B.style.marginBottom="5px";B.innerHTML=typeInInvitationMessage;$("leftDiv").appendChild(B);var A=_C("textarea");A.id="message";A.className="inputText";A.style.width="315px";A.style.height="60px";$("leftDiv").appendChild(A)}function addPeople(B){var E=0;var F=_GT("input");for(var C=0;C<F.length;C++){if(F[C].type=="checkbox"&&F[C].value==myFriendsData[B]["user_id"]&&F[C].id.indexOf("chkInvite_")>-1){E=1;break}}if(typeof (currentFriendId)!="undefined"&&currentFriendId!=""&&parseInt(currentFriendId)>0){if(currentFriendId==myFriendsData[B]["user_id"]){E=1}}if(E==0){var G=_C("div");$("peopleDiv").appendChild(G);var A=_C("input");A.type="checkbox";A.id="chkInvite_"+B;A.value=myFriendsData[B]["user_id"];G.appendChild(A);A.checked=true;var D=_C("span");D.innerHTML="&nbsp;&nbsp;"+myFriendsData[B]["name"]+" "+myFriendsData[B]["surname"];G.appendChild(D)}}function addLocation(B){var E=0;var F=_GT("input");for(var C=0;C<F.length;C++){if(F[C].type=="checkbox"&&F[C].value==allMyLocations[B]["location_id"]&&F[C].id.indexOf("chkInvite_")>-1){E=1;break}}if(E==0){var G=_C("div");$("peopleDiv").appendChild(G);var A=_C("input");A.type="checkbox";A.id="chkInvite_"+B;A.value=allMyLocations[B]["location_id"];G.appendChild(A);A.checked=true;var D=_C("span");D.innerHTML="&nbsp;&nbsp;"+allMyLocations[B]["name"];G.appendChild(D)}}function sendInvitation(C){var D=_GT("input");var B="";for(var A=0;A<D.length;A++){if(D[A].type=="checkbox"&&D[A].checked==true&&D[A].id.indexOf("chkInvite_")>-1){B+=D[A].value+","}}if(B!=""){if(typeof (invite_location_id)!="undefined"&&invite_location_id!=""&&parseInt(invite_location_id)>0){sendLocationInvitation(B,C)}else{if(typeof (currentFriendId)!="undefined"&&currentFriendId!=""&&parseInt(currentFriendId)>0){sendFriendsIntroduction(currentFriendId,B,C)}else{if(typeof (invite_group_id)!="undefined"&&invite_group_id!=""&&parseInt(invite_group_id)>0){sendGroupInvitation(B,C)}else{if(typeof (invite_vote_id)!="undefined"&&invite_vote_id!=""&&parseInt(invite_vote_id)>0){sendPollInvitation(B,C)}else{if(typeof (currentFriendIdToPlace)!="undefined"&&currentFriendIdToPlace!=""&&parseInt(currentFriendIdToPlace)>0){sendLocationInvitationsToUser(B,C)}}}}}}}function sendLocationInvitation(A,B){Ext.getBody().mask(sendingMessage);Ext.Ajax.request({url:"ajax/location_invitation.php",method:"POST",params:{strID:A,location_id:invite_location_id,message:$("message").value},success:function(C,D){if(C.responseText.trim()=="succ"){showAlert(sendInvitationsSucc)}Ext.getBody().unmask();B.close()},failure:function(){Ext.MessageBox.alert("Connection error","A network error occured during connection, please try again shortly.")}})}function sendLocationInvitationsToUser(A,B){Ext.getBody().mask(sendingMessage);Ext.Ajax.request({url:"ajax/location_invitations_user.php",method:"POST",params:{strID:A,friend_id:currentFriendIdToPlace,message:$("message").value},success:function(C,D){if(C.responseText.indexOf("succ")>-1){showAlert(sendInvitationsSucc)}Ext.getBody().unmask();B.close()},failure:function(){Ext.MessageBox.alert("Connection error","A network error occured during connection, please try again shortly.")}})}function sendFriendsIntroduction(C,A,B){Ext.getBody().mask(sendingMessage);Ext.Ajax.request({url:"ajax/friends_introduce.php",method:"POST",params:{strID:A,currentFriendID:C,message:$("message").value},success:function(D,E){if(D.responseText.trim()!=""){showAlert(D.responseText.trim())}Ext.getBody().unmask();B.close()},failure:function(){Ext.MessageBox.alert("Connection error","A network error occured during connection, please try again shortly.")}})}function sendGroupInvitation(A,B){Ext.getBody().mask(sendingMessage);Ext.Ajax.request({url:"ajax/group_invitation.php",method:"POST",params:{strID:A,group_id:invite_group_id,message:$("message").value},success:function(C,D){if(C.responseText.trim()=="succ"){showAlert(sendInvitationsSucc)}Ext.getBody().unmask();B.close()},failure:function(){Ext.MessageBox.alert("Connection error","A network error occured during connection, please try again shortly.")}})}function sendPollInvitation(A,B){Ext.getBody().mask(sendingMessage);Ext.Ajax.request({url:"ajax/send_poll_invitations.php",method:"POST",params:{strID:A,vote_id:invite_vote_id,message:$("message").value},success:function(C,D){if(C.responseText.trim()=="succ"){showAlert(sendInvitationsSucc)}Ext.getBody().unmask();if(typeof (B)!="undefined"){B.close()}},failure:function(){Ext.MessageBox.alert("Connection error","A network error occured during connection, please try again shortly.")}})}function sendShortMessage(B){var C=$("subject").value.trim();if(C==""){showAlert(plsTypeInSubject);return false}var A=$("message").value;if(A.trim()==""){showAlert(messageContentInput);return false}Ext.getBody().mask(sendingMessage);Ext.Ajax.request({url:"ajax/sendMessage.php",method:"POST",params:{action:"sendMsg",messageSubject:C,messageText:A,pickup:currentFriendIdToMsg},success:function(D,E){showAlert(messageSentSuccess);Ext.getBody().unmask();B.close()},failure:function(E,D){Ext.MessageBox.alert("Connection error","A network error occured during connection, please try again shortly.")}})};