// JavaScript Document
var searchKey = '';
var contactsPerPage;
var show;
$(function(){
	$("div.msgBox").hide();	
	$("div.advancedOpt").hide();
	$("#advSearch").click(
		function() {
			if(show==0) {
				$("#advancedOpt").slideDown(400);
				$("#lblSearch").removeClass("lblmsgsError");
				$("#txtSearch").removeClass("txtmsgsError");
				$("#advSearch").html(lblHide);
				show=1;
			} else {
				$("#advancedOpt").slideUp(400);
				$("#advSearch").html(lblAdvanced);
				show=0;
				$("#country").val('')
				$("#tags").val('');
			}
		}
	);
});
function showRequestBox(userId) {
	$('#loader_pop'+userId).addClass("loading"); 
	$("div.msgBox").hide();	
	$("#msgBox"+userId).show();
	$("#msgBox"+userId).load(appUrl+'/app/modules/community/userRequest.php',
		{	
			action: "show",
			requestTo: userId
		},
		function (){
			$('#loader_pop'+userId).removeClass("loading"); 
		}
	);
}

function showSendMessageBox(userId) {
	$('#loader_pop'+userId).addClass("loading"); 
	$("div.msgBox").hide();	
	$("#msgBox"+userId).show();
	$("#msgBox"+userId).load(appUrl+'/app/modules/community/sendMessage.php',
		{	
			action: "show",
			requestTo: userId
		},
		function (){
			$('#loader_pop'+userId).removeClass("loading"); 
		}
	);
}

function sendMessage(requestId) {
	$('#loader_pop'+requestId).addClass("loading"); 
	$("#msgBox"+requestId).show();
	$("#msgBox"+requestId).load(appUrl+'/app/modules/community/sendMessage.php',
		{	
			action: "send",
			requestTo: requestId,
			message: $("#message"+requestId).val()
		},
		function (){
			$('#loader_pop'+requestId).removeClass("loading"); 
		}
	);
}



function hideRequestBox(userId) {
	$('#msgBox'+userId).slideUp(400);
}
function sendRequest(requestId) {
	$('#loader_pop'+requestId).addClass("loading"); 
	$("#msgBox"+requestId).show();
	$("#msgBox"+requestId).load(appUrl+'/app/modules/community/userRequest.php',
		{	
			action: "send",
			requestTo: requestId,
			message: $("#message"+requestId).val()
		},
		function (){
			$('#loader_pop'+requestId).removeClass("loading"); 
		}
	);
}
 function setHoverValue(val){
	//document.getElementById('tt').innerHTML = val;
	$("#tt").html(val);
 }
  function unsetHoverValue(val){
	document.getElementById('tt').innerHTML = '';
 }
 
function removeFriend(userId) {
	if(confirm(msgRemoveFriend)) {
		$('#loader_pop'+userId).addClass("loading");
		$("#removeFrnd"+userId).html(msgRemoving);
		$("#msgBox"+userId).show();
		$("#msgBox"+userId).load(appUrl+'/app/modules/community/userRequest.php',
			{	
				action: "remove",
				removeId: userId
			},
			function (data){
					$("#removeFrnd"+userId).remove();
					$('#loader_pop'+userId).removeClass("loading"); 
				
			}
		);
	}
}
function removeFromList(userId) {
	if(confirm(msgRemoveFriend)) {
		var contactsCount = $("#contactsCount").val();
		pageNo = $("#pageNo").val();
		if(contactsCount==1 && pageNo>1) {
			pageNo = pageNo-1;
		}
		$('#loader_pop'+userId).addClass("loading");
		$("#removeFrnd"+userId).html(msgRemoving);
		$("#contactList").load(appUrl+'/app/modules/community/userContacts.ajx.php',
			{	
				removeId: userId,
				searchKey:contactSearchKey,
				page: pageNo
			},
			function (){
					//$("#removeFrnd"+userId).html("<a class=\"removed\">"+msgRemoved+"</a>");
					$('#loader_pop'+userId).removeClass("loading"); 
				
			}
		);
	}
}
function validate() {
	var txt = $("#txtSearch").val();
	var type = $("#userType").val();
	var loc = $("#userCountry").val();
	if(txt || type || loc) {
		return true;	
	} else {
		$("#txtSearch").addClass("txtmsgsError");
		return false;	
	}
}