var loading_header = '<p id="preloader" class="mid" align="center"><img src="grafika/preajax.gif" /></h2>';
var loading = '... loading ...';
var whole_country = "Whole country";
var any_city = "Any city";
var _all = "All";

// Language words.
var all_cities = '';
var in_specific_time = '';
var search_tags = '';

var mouse_x, mouse_y;
//------------------------------------------------------------------------------------------------------------

/*tan project */

//-----------------------select all deselect------------------------


function check(ch)
{
	document.getElementById('selall_1').checked =  ch.checked;

	ts = document.getElementsByName('tids[]');
	for (k = 0; k < ts.length; k++)
	{		
		if (ts[k].checked != ch.checked)
		{
			ts[k].checked = ch.checked;
			
		}
	}
	
	return true;		
}



//--------------------------------------end-------------------------



//end Tan project

// profile, Who wants similar activity (min one tag match)										Dante OK
function show_player(trackid){
	$("#mp3player").empty().append(loading_header);
	var html = $.ajax({
		type: "POST",
		url: "ajax/ajaxplayer.php",
		async: false,
		data: "trackid=" + trackid
	}).responseText;
	$("#mp3player").append(html);
	$("#preloader").remove();
	return false;
}
//------------------------------------------------------------------------------------------------------------

//--------------------------------------------add to cart-------------------------------------

function addtocart(mediaid,audioid){
	
	var result = $.ajax({
		type: "POST",
		url: "ajax/addtocart.php",
		async: false,
		data: "mediaid=" + mediaid 
	}).responseText;
	

	$("#audio_add_" + mediaid + "_" + audioid).hide();
	//$("#start_following_" + user + "_" + friend).show();
	
	$("#audio_remove_" + mediaid + "_" + audioid).show();

}

//------------------------------------------------------------

//-----------------------revove cart---------------

function removetocart(mediaid,audioid){
	
	var result = $.ajax({
		type: "POST",
		url: "ajax/removecart.php",
		async: false,
		data: "mediaid=" + mediaid 
	}).responseText;
	

	$("#audio_add_" + mediaid + "_" + audioid).show();
	//$("#start_following_" + user + "_" + friend).show();
	
	$("#audio_remove_" + mediaid + "_" + audioid).hide();

}

//------------------------------------------------------------








// counting chars
function activity_keyup(){
	var chars;
	chars = 141 - $("#activity").val().length;
	if(chars == 0 || chars < 0) $("#activity").val($("#activity").val().substr(0, 140))
	$("#chars_left").empty().append(chars);
}
//------------------------------------------------------------------------------------------------------------

// top search engine																	Dante OK
function top_search_click(user, city, when, what, gender, zip_code, within, page){
	$("#mainWindow").empty().append(loading_header);
	var html = $.ajax({
		type: "POST",
		url: "ajax/search_activities.php",
		async: false,
		data: "user=" + user + "&city=" + city + "&when=" + when + "&what=" + what + "&gender=" + gender + "&zip_code=" + zip_code + "&within=" + within + "&page=" + page
	}).responseText;
	$("#mainWindow").append(html);
	$("#preloader").remove();
}

// top search engine																	Dante OK
function top_search_click_event(user, city, who, gender, page){
	$("#mainWindow").empty().append(loading_header);
	var html = $.ajax({
		type: "POST",
		url: "ajax/search_activities_event.php",
		async: false,
		data: "lu=" + user + "&city=" + city  + "&who=" + who + "&gender=" + gender +  "&page=" + page
	}).responseText;
	$("#mainWindow").append(html);
	$("#preloader").remove();
}
/////////////////// KIL
function top_search_click_people(user, city, who, gender, page){
	$("#mainWindow").empty().append(loading_header);
	var html = $.ajax({
		type: "POST",
		url: "ajax/people.php",
		async: false,
		data: "lu=" + user + "&city=" + city  + "&who=" + who + "&gender=" + gender +  "&page=" + page
	}).responseText;
	$("#mainWindow").append(html);
	$("#preloader").remove();
}
//////////////////////// KIL
function top_search_page_click(page){
	top_search_click($("#top_se_user").val(), $("#top_se_id_city").val(), $("#top_se_when_time_a").html(), $("#top_se_activity").val(), $("#top_se_who").val(), $("#zip_code").val(), $("#within").val(), page);
}

// top search engine, City button (and other places where it exists)					Dante OK
function top_se_city_click(s){
	var loading_html='<table cellpadding="0" cellspacing="0" height="255" width="100%"><td width="100%" height="200" align="center" valign="middle">'+loading_header+'</td></table>';
	$("#top_se_city_list").empty().append(loading_html);
	$("#top_se_city_list").show();
	$.ajax({
		type: "POST",
		url: "ajax/top_se_city_list.php",
		async: true,
		data: "city=" + $("#top_se_city").attr("rel") + "&s=" + s,
		success:function(msg)
		{
			$("#top_se_city_list").empty().append(msg);
		}
	});
}

function top_se_city_click2(s){
	var loading_html='<table cellpadding="0" cellspacing="0" height="255" width="100%"><td width="100%" height="200" align="center" valign="middle">'+loading_header+'</td></table>';
	$("#top_se_city_list").empty().append(loading_html);
	$("#top_se_city_list").show();
	$.ajax({
		type: "POST",
		url: "ajax/top_se_location_loder.php",
		async: true,
		data: "city=" + $("#top_se_city").attr("rel") + "&s=" + s + "&city_name=" + $("#top_se_city").text(),
		success:function(msg)
		{
			$("#top_se_city_list").empty().append(msg);
		}
	});
}
// select a city from top search engine city list or OK button
function top_se_city_list_a_click(city, region, country, s){
	if(!city){
		city = $("#city").val();
		region = $("#state").val();
		country = $("#country").val();
		s = $("#s").val();
	}
	
	var result = $.ajax({
		type: "POST",
		url: "ajax/top_se_city_list_select.php",
		async: false,
		data: "city=" + city + "&region=" + region + "&country=" + country + "&s=" + s
	}).responseText;
	$("#top_se_id_city").val(city);
	$("#top_se_city").attr("rel", city);
	$("#top_se_city").empty().append(result);
	$("#top_se_city_list").hide().empty();
	
	if(country == 'us'){
		$("#zip_div").show();
	}
	else{
		$("#zip_div").hide();
	}
	if(s == 'eventsearch')
	{
		top_search_click_event($("#top_se_user").val(), $("#top_se_id_city").val(), $("#top_se_tabs").attr("rel"), $("#top_se_who").attr("rel"), 1);
	}
	else if(s == 'search'){
		top_search_click($("#top_se_user").val(), $("#top_se_id_city").val(), $("#top_se_when_time_a").html(), $("#top_se_activity").val(), 0, $("#zip_code").val(), $("#within").val(), 1);
	}else{
////	         if(s == 'no_search'){  ///////////////
                 		top_search_click_people($("#top_se_user").val(), $("#top_se_id_city").val(), 0,  0, 1); /// (0,0,1) ==(who,gender,page)
         	}
	
	
	var category = $.ajax({
		type: "POST",
		url: "ajax/most_popular_categories.php",
		async: false,
		data: "city=" + city
	}).responseText;
	
	$("#most_popular_category").empty().append(category);
	
	var tags = $.ajax({
		type: "POST",
		url: "ajax/most_popular_tags.php",
		async: false,
		data: "city=" + city
	}).responseText;
	$("#most_popular_tags").empty().append(tags);
	
	
	return false;
}

function new_activity_city_click(){
	var html = $.ajax({
		type: "POST",
/*		url: "ajax/ne_city_list.php", */
		url: "ajax/ne_location_loder.php",
		async: false,
		data: "city=" + $("#new_activity_city").attr("rel")
	}).responseText;
	$("#top_se_city_list").empty().append(html);
	$("#top_se_city_list").show();
}
// select a city from top search engine city list or OK button
function ne_city_list_a_click(city, region, country){
	if(!city){
		city = $("#city").val();
		region = $("#state").val();
		country = $("#country").val();
	}
	
	var result = $.ajax({
		type: "POST",
		url: "ajax/ne_city_list_select.php",
		async: false,
		data: "city=" + city + "&region=" + region + "&country=" + country
	}).responseText;
	$("#top_se_id_city").val(city);
	$("#new_activity_city").attr("rel", city);
	$("#new_activity_city").empty().append(result);
	$("#top_se_city_list").hide().empty();
	
	if(country == 'us'){
		$("#zip_div").show();
	}
	else{
		$("#zip_div").hide();
	}

	return false;
}

function country_change(){
	if($("#country").val() == 'us'){
		$("#zip_div").show();
	}
	else{
		$("#zip_div").hide();
	}
	
	$("#state").empty().append('<option selected="selected">' + loading + '</option>');
	var html = $.ajax({
		type: "POST",
		url: "ajax/state_list.php",
		async: false,
		data: "country=" + $("#country").val() 
	}).responseText;
	$("#state").empty().append(html);

	if($("#state").children().size() == 0){
		$("#state").empty().append('<option value="0" selected="selected">' + whole_country + '</option>');
		$("#city").empty().append('<option selected="selected">' + loading + '</option>');
		var html = $.ajax({
			type: "POST",
			url: "ajax/city_list.php",
			async: false,
			data: "country=" + $("#country").val()
		}).responseText;
		$("#city").empty().append(html);
	}
	else{
		$("#city").empty().append('<option value="0" selected="selected">' + any_city + '</option>');
	}
}

function state_change(){
	$("#city").empty().append('<option selected="selected">' + loading + '</option>');
	var html = $.ajax({
		type: "POST",
		url: "ajax/city_list.php",
		async: false,
		data: "state=" + $("#state").val() + "&country=" + $("#country").val()
	}).responseText;
	$("#city").empty().append(html);
	
	if($("#city").children().size() == 0){
		$("#city").empty().append('<option value="0" selected="selected">' + any_city + '</option>');
	}
}

function state_blur(){
	if($("#state").children().size() == 1){
		state_change();
	}
}

function zip_code_blur(){
	if($("#zip_code").val() != ''){
		$("#city").empty().append('<option selected="selected">' + loading + '</option>');
		var html = $.ajax({
			type: "POST",
			url: "ajax/city_list.php",
			async: false,
			data: "state=" + $("#state").val() + "&country=" + $("#country").val() + "&zip_code=" + $("#zip_code").val()
		}).responseText;
		$("#city").empty().append(html);
	}
}

function zip_code_blur2(){
	if($("#zip_code").val() != ''){
		$("#state").empty().append('<option selected="selected">' + loading + '</option>');
		$("#city").empty().append('<option selected="selected">' + loading + '</option>');
		
		var states = $.ajax({
			type: "POST",
			url: "ajax/zip_states.php",
			async: false,
			data: "zip_code=" + $("#zip_code").val()
		}).responseText;
		$("#state").empty().append(states);
		
		var cities = $.ajax({
			type: "POST",
			url: "ajax/zip_cities.php",
			async: false,
			data: "zip_code=" + $("#zip_code").val()
		}).responseText;
		$("#city").empty().append(cities);
	}
}

// city list, Cancel button
function top_se_city_list_cancel_click(){
	$("#top_se_city_list").hide().empty();
}
// add tag to taglist
function add_tag(tag){
	$("#act_tags").val($("#act_tags").val() + ' ' + tag + ',');
}
//------------------------------------------------------------------------------------------------------------

// people search
function people_click(lu, city, who, gender, page){
	$("#mainWindow").empty().append(loading_header);
	var html = $.ajax({
		type: "POST",
		url: "ajax/people.php",
		async: false,
		data: "lu=" + lu + "&city=" + city + "&who=" + who + "&gender=" + gender + "&page=" + page
	}).responseText;
	$("#mainWindow").append(html);
	$("#preloader").remove();
}

function event_main_click(lu, city, who, gender, page){
	$("#mainWindow").empty().append(loading_header);
	var html = $.ajax({
		type: "POST",
		url: "ajax/search_activities_event.php",
		async: false,
		data: "lu=" + lu + "&city=" + city + "&who=" + who + "&gender=" + gender + "&page=" + page
	}).responseText;
	$("#mainWindow").append(html);
	$("#preloader").remove();
}


function eventpeople_click(lu, city, id_activity, gender, page){
	
	
	$("#mainWindow").empty().append(loading_header);
	var html = $.ajax({
		type: "POST",
		url: "ajax/eventpeople.php",
		async: false,
		data: "id_activity=" + id_activity +  "&gender=" + gender + "&page=" + page
	}).responseText;
	$("#mainWindow").append(html);
	$("#preloader").remove();
}
//------------------------------------------------------------------------------------------------------------

// add/remove friend, start/stop following, block/unblock etc
function add_friend(user, friend){
	var result = $.ajax({
		type: "POST",
		url: "ajax/user_friend_add.php",
		async: false,
		data: "user=" + user + "&friend=" + friend
	}).responseText;
	$("#add_friend_" + user + "_" + friend).hide();
	$("#waiting_for_appr_" + user + "_" + friend).show();
	//$("#start_following_" + user + "_" + friend).show();
	$("#remove_friend_" + user + "_" + friend).hide();
// right panel
	$("#action_add_as_a_friend").hide();
	$("#action_waiting_for_appr").show();
	$("#action_remove_friend").hide();
}


function remove_event(user, eventid){
	var result = $.ajax({
		type: "POST",
		url: "ajax/event_remove.php",
		async: false,
		data: "user=" + user + "&eventid=" + eventid
	}).responseText;
	
	$("#event_add_" + user + "_" + eventid).show();
	
	//$("#start_following_" + user + "_" + friend).show();
	$("#event_remove_" + user + "_" + eventid).hide();
}



function remove_friend(user, friend){
	var result = $.ajax({
		type: "POST",
		url: "ajax/user_friend_remove.php",
		async: false,
		data: "user=" + user + "&friend=" + friend
	}).responseText;
	//$("#friend_" + friend).remove();
	$("#add_friend_" + user + "_" + friend).show();
	$("#waiting_for_appr_" + user + "_" + friend).hide();
	$("#start_following_" + user + "_" + friend).hide();
	$("#remove_friend_" + user + "_" + friend).hide();
// right panel
	$("#action_waiting_for_appr").hide();
	$("#action_remove_friend").hide();
	$("#action_add_as_a_friend").show();
}

function start_following(user, followed){
	var result = $.ajax({
		type: "POST",
		url: "ajax/user_following_start.php",
		async: false,
		data: "user=" + user + "&followed=" + followed
	}).responseText;
	$("#start_following_" + user + "_" + followed).hide();
	$("#stop_following_" + user + "_" + followed).show();
	$("#action_start_following").hide();
	$("#action_stop_following").show();
}

function stop_following(user, followed){
	var result = $.ajax({
		type: "POST",
		url: "ajax/user_following_stop.php",
		async: false,
		data: "user=" + user + "&followed=" + followed
	}).responseText;
	$("#stop_following_" + user + "_" + followed).hide();
	$("#start_following_" + user + "_" + followed).show();
	$("#action_start_following").show();
	$("#action_stop_following").hide();
}

function friend_accept(user, friend){
	var result = $.ajax({
		type: "POST",
		url: "ajax/user_friend_accept.php",
		async: false,
		data: "user=" + user + "&friend=" + friend
	}).responseText;
	$("#waiting_user_" + user + "_" + friend).remove();
}

function friend_refuse(user, friend){
	var result = $.ajax({
		type: "POST",
		url: "ajax/user_friend_refuse.php",
		async: false,
		data: "user=" + user + "&friend=" + friend
	}).responseText;
	$("#waiting_user_" + user + "_" + friend).remove();
}

function block_user(user, blocked_user){
	var result = $.ajax({
		type: "POST",
		url: "ajax/user_block.php",
		async: false,
		data: "user=" + user + "&blocked_user=" + blocked_user
	}).responseText;
// right panel
	$("#action_block").hide();
	$("#action_unblock").show();
}

function unblock_user(user, blocked_user){
	var result = $.ajax({
		type: "POST",
		url: "ajax/user_unblock.php",
		async: false,
		data: "user=" + user + "&blocked_user=" + blocked_user
	}).responseText;
// right panel
	$("#action_unblock").hide();
	$("#action_block").show();
}

function nudge_user(user, nudged_user){
	var result = $.ajax({
		type: "POST",
		url: "ajax/user_nudge.php",
		async: false,
		data: "user=" + user + "&nudged_user=" + nudged_user
	}).responseText;
// right panel
	$("#action_nudge").hide();
	$("#action_after_nudge").show();
}	
//------------------------------------------------------------------------------------------------------------

// profile, I Want																				Dante OK
function prof_i_want_click(user, page){
	$("#mainWindow").empty().append(loading_header);
	var html = $.ajax({
		type: "POST",
		url: "ajax/i_want.php",
		async: false,
		data: "user=" + user + "&page=" + page 
	}).responseText;
	$("#prof_r_new_msgs_count").siblings("a.actions").removeClass("current");
	$("#prof_messages_top, #prof_r_new_msgs_count").removeClass("current");
	$("#prof_i_want, #prof_r_i_want_count").addClass("current");
	$("#mainWindow").append(html);
	$("#preloader").remove();
	return false;
}

// profile, My Messages
function prof_messages_click(user, s, d, page){
	$("#mainWindow").empty().append(loading_header);
	var html = $.ajax({
		type: "POST",
		url: "ajax/messages.php",
		async: false,
		data: "user=" + user + "&s=" + s + "&d=" + d + "&page=" + page 
	}).responseText;
	$("#prof_r_i_want_count").siblings("a.actions").removeClass("current");
	$("#prof_i_want, #prof_r_i_want_count").removeClass("current");
	$("#prof_messages_top, #prof_r_new_msgs_count").addClass("current");
	$("#mainWindow").append(html);
	$("#preloader").remove();
	return false;
}

// profile, Delete activity																		Dante OK
function delete_activity(activity, user){
	var result = $.ajax({
		type: "POST",
		url: "ajax/activity_delete.php",
		async: false,
		data: "activity=" + activity 
	}).responseText;
			
	if(result == 'OK'){
		$("#table_act_" + activity).remove();
		count_activities(user);
	}
	else{
		alert('Cannot delete the activity !!!');
	}
	return false;
}

///////////////////////////////
// profile, Delete messages
//Dante OK
function delete_message(msg, user){
	var result = $.ajax({
		type: "POST",
		url: "ajax/message_delete.php",
		async: false,
		data: "msg=" + msg
	}).responseText;
			
	if(result == 'OK'){
		$("#table_msg_" + msg).remove();
		count_msgs(user);
	}
	else{
		alert('Cannot delete the message !!!');
	}
	return false;
}
////////////////////////////
//------------------------------------------------------------------------------------------------------------

// tag search engine, all tags clicks
function tag_click(tag, city, user, page){
	$("#mainWindow").empty().append(loading_header);
	var html = $.ajax({
		type: "POST",
		url: "ajax/tag.php",
		async: false,
		data: "tag=" + tag + "&city=" + city + "&user=" + user + "&page=" + page
	}).responseText;
	$("#mainWindow").append(html);
	$("#preloader").remove();
}


/// modify by matainja:utpal


// tag search engine, all tags clicks
function category_click(tag, city, user, page){
	$("#mainWindow").empty().append(loading_header);
	var html = $.ajax({
		type: "POST",
		url: "ajax/search_category.php",
		async: false,
		data: "category=" + tag + "&city=" + city + "&user=" + user + "&page=" + page
	}).responseText;
	$("#mainWindow").append(html);
	$("#preloader").remove();
}

function tag_people_click(tag, city, user, page){
	$("#mainWindow").empty().append(loading_header);
	var html = $.ajax({
		type: "POST",
		url: "ajax/tag_people.php",
		async: false,
		data: "tag=" + tag + "&city=" + city + "&user=" + user + "&page=" + page
	}).responseText;
	$("#mainWindow").append(html);
	$("#preloader").remove();
}
//------------------------------------------------------------------------------------------------------------

// Reply tool
function reply_click(user, message){ // id_user - target, id_message
	var html = $.ajax({
		type: "POST",
		url: "ajax/reply_tool.php",
		async: false,
		data: "user=" + user + "&message=" + message
	}).responseText;
	$("#table_msg_" + message).append(html);
	return false;
}
// Reply tool Send button click
function reply_tool_send_click(user, message){ // id_user, id_message

	var result = $.ajax({
		type: "POST",
		url: "ajax/reply_send.php",
		async: false,
		data: "user=" + user + "&message=" + message + "&msg=" + $("#reply_tool_msg").val()
	}).responseText;
	$("#reply_tool_tr_" + message).remove();
	return false;
}
// Reply tool Cancel button click
function reply_tool_cancel_click(message){ // id_message
	$("#reply_tool_tr_" + message).remove();
}
//------------------------------------------------------------------------------------------------------------

// profile, My Messages details                                                                       Dante OK
function messages_view_click(user, activity, which, page){ // id_user, id_activity, received | sent, page
	var html = $.ajax({
		type: "POST",
		url: "ajax/message.php",
		async: false,
		data: "user=" + user + "&activity=" + activity + "&which=" + which + "&srt=" + $("#messages_sort").val() + "&page=" + page
	}).responseText;
	$("#msg_table").hide();
	$("#cnrm_" + activity).html('0');
	$("#messages_to_act").empty().append(html).show();
	return false;
}
// My Messages details hide
function messages_hide_click(activity){
	$("#messages_to_act").hide().empty();
	$("#msg_tr_" + activity).css("background-color", "#FFFFFF");
	$("#msg_table").show();
}
//------------------------------------------------------------------------------------------------------------

// Join in tool
function join_in_click(user, activity){
	$(".join_in_tool_tr").remove();
	var html = $.ajax({
		type: "POST",
		url: "ajax/join_in_tool.php",
		async: false,
		data: "user=" + user + "&activity=" + activity 
	}).responseText;
	$("#table_act_" + activity).append(html);
	return false;
}
// Join in tool, Send button click
function join_in_tool_send_click(user, activity){
	var result = $.ajax({
		type: "POST",
		url: "ajax/join_in_send.php",
		async: false,
		data: "user=" + user + "&activity=" + activity + "&msg=" + $("#join_in_tool_msg").val()
	}).responseText;
	$("#join_in_tool_tr_" + activity).remove();
	return false;
}
// Join in tool, Cancel button click
function join_in_tool_cancel_click(activity){
	$("#join_in_tool_tr_" + activity).remove();
}
//------------------------------------------------------------------------------------------------------------

// Invite me tool (seen in others user's profile)
function invite_me_click(user, guest){
	var html = $.ajax({
		type: "POST",
		url: "ajax/invite_me_tool.php",
		async: false,
		data: "user=" + user + "&guest=" + guest
	}).responseText;
	//$("#main").append(html);
	$("#main").append(html);
	return false;
}

function invite_me_tool_send_click(user, type){
	var html = null;
	
	if($("#when_date_whenever").attr("checked")){
		html = $.ajax({
			type: "POST",
			url: "ajax/invite_me_send.php",
			async: false,
			data: "user=" + user + "&type=" + type + "&activity_r=" + $("input[@name=activity_r]:checked").val()  + "&activity=" + $("#activity").val() + "&when_date=" + "when_date_whenever" + "&when_date_date=" + $("#when_date_date").val() + "&when_time=" + $("#when_time").val() + "&priv=" + $("#priv").val() + "&top_se_id_city=" + $("#top_se_id_city").val()}).responseText;
	}
	else{

		html = $.ajax({
			type: "POST",
			url: "ajax/invite_me_send.php",
			async: false,
			data: "user=" + user + "&type=" + type + "&activity_r=" + $("input[@name=activity_r]:checked").val() + "&activity=" + $("#activity").val() + "&when_date=" + "when_date_set" + "&when_date_date=" + $("#when_date_date").val() + "&when_time=" + $("#when_time").val() + "&priv=" + $("#priv").val() + "&top_se_id_city=" + $("#top_se_id_city").val()}).responseText;
	}
	
	$("#invite_me_tool").remove();

	$("#main").append(html);
	
	return false;
}

function whenever_click(){
	$("#when_date_date, #calendar, #when_time").hide();
}

function set_time_click(){
	$("#when_date_date, #calendar, #when_time").show();
}

function invite_me_tool_cancel_click(){
	$("#invite_me_tool").remove();
}
//------------------------------------------------------------------------------------------------------------

// Send to a friend tool
function sendtofriend_click(user, activity){
	var html = $.ajax({
		type: "POST",
		url: "ajax/send_to_friend_tool.php",
		async: false,
		data: "user=" + user + "&activity=" + activity
	}).responseText;
	$("body").append(html);
	return false;
}

function sent_to_friend_tool_send_click(user, activity){
	var html = $.ajax({
		type: "POST",
		url: "ajax/send_to_friend_send.php",
		async: false,
		data: "user=" + user + "&activity=" + activity + "&emails=" + $("#emails").val() + "&add_msg=" + $("#add_msg").val()
	}).responseText;
	$("#send_to_friend_tool").remove();
}

function send_to_friend_tool_cancel_click(){
	$("#send_to_friend_tool").remove();
}
//------------------------------------------------------------------------------------------------------------

// Report abuse tool
function report_abuse_click(user, bad_user){
	var html = $.ajax({
		type: "POST",
		url: "ajax/report_abuse_tool.php",
		async: false,
		data: "user=" + user + "&bad_user=" + bad_user
	}).responseText;
	$("body").append(html);
	return false;
}

function report_abuse_tool_send_click(user, bad_user){
	var html = $.ajax({
		type: "POST",
		url: "ajax/report_abuse_send.php",
		async: false,
		data: "user=" + user + "&bad_user=" + bad_user + "&msg=" + $("#msg").val()
	}).responseText;
	$("body").append(html);
	$("#report_abuse_tool").remove();
}

function report_abuse_tool_cancel_click(){
	$("#report_abuse_tool").remove();
}

//------------------------------------------------------------------------------------------------------------

//
function messages(){
	var html = $.ajax({
		url: "ajax/messages.php",
		async: false
	}).responseText;
	$("div#messages_all").empty().append(html);
}
//------------------------------------------------------------------------------------------------------------
//																								Dante OK
function set_notify_mode(stuff){
	var result = $.ajax({
		type: "GET",
		url: "ajax/set_notify_way.php",
		data: "stuff=" + stuff,
		async: false
	}).responseText;
	$("#ncmr").empty().append(result);
}
//------------------------------------------------------------------------------------------------------------
//
function set_msg_notification(stuff){
	var result = $.ajax({
		type: "GET",
		url: "ajax/message_notification.php",
		data: "stuff=" + stuff,
		async: false
	}).responseText;
	$("#mnr").empty().append(result);
}
//------------------------------------------------------------------------------------------------------------
function eventMouseX(e, w){
	if(e.pageX){
		return xval = e.pageX;
	}
	//if(xval + w > winW) xval = winW - w - 30;
//		return xval;
}

function eventMouseY(e, h){
	if(e.pageY){
		return e.pageY;
	}
		//if(yval + h > winH) yval = winH - h - 30;
//		return yval;
}
///////////////////-----------------------------------------///////////////////////////

//Shadowbox.loadSkin('classic', './src/skin');
//Shadowbox.loadLanguage('en', './src/lang');
//Shadowbox.loadPlayer('img', './src/player');

$(document).ready(function(){
    Shadowbox.init();

	/* Retrieving the site language from cookie.	*/
	var start = document.cookie.indexOf('site_language');
	var end	= document.cookie.indexOf(';');
	var temp = document.cookie.substr(start,end);
	start = temp.indexOf('=');
	end = temp.length;
	var lang = temp.substr(start+1, end);
	
	if( lang == 'portugues'){
		all_cities = 'todas cidades';
		in_specific_time = 'em data espec&iacute;fica';
		search_tags = 'Buscar tags';
	}else{
		all_cities = 'all cities';
		in_specific_time = 'in a specific time';
		search_tags = 'Search tags';
	}

	$("#top_se_city_list").hide();
	$("#when_date_date").hide();
	$("#calendar").hide();
	$("#when_time").hide();

	$("#see_all_tags").click(
		function(){
			
			
			$("#tag_list_more").toggle();
		}
	);
//------------------------------------------------------------------------------------------------------------
// top search engine, OK button																	Dante OK
	$("#top_se_ok").click(
		function(){
			top_search_click($("#top_se_user").val(), $("#top_se_id_city").val(), $("#top_se_when_time_a").html(), $("#top_se_activity").val(), $("#top_se_who").val(), $("#zip_code").val(), $("#within").val(), 1);
		}
	);
// top search engine, Enter hit
	$("#top_se_form").submit(
		function(){
			top_search_click($("#top_se_user").val(), $("#top_se_id_city").val(), $("#top_se_when_time_a").html(), $("#top_se_activity").val(), $("#top_se_who").val(), $("#zip_code").val(), $("#within").val(), 1);
			return false;
		}
	);
// top search engine, All button																Dante OK
	$("#top_se_all").click(
		function(){
			$("#top_se_who").val('0');
			$("#top_se_all").addClass("current");
			$("#top_se_woman").removeClass("current");
			$("#top_se_man").removeClass("current");
			top_search_click($("#top_se_user").val(), $("#top_se_id_city").val(), $("#top_se_when_time_a").html(), $("#top_se_activity").val(), $("#top_se_who").val(), $("#zip_code").val(), $("#within").val(), 1);
		}
	);
// top search engine, Woman button																Dante OK
	$("#top_se_woman").click(
		function(){
			$("#top_se_who").val('1')
			$("#top_se_all").removeClass("current");
			$("#top_se_woman").addClass("current");
			$("#top_se_man").removeClass("current");
			top_search_click($("#top_se_user").val(), $("#top_se_id_city").val(), $("#top_se_when_time_a").html(), $("#top_se_activity").val(), $("#top_se_who").val(), $("#zip_code").val(), $("#within").val(), 1);
		}
	);
// top search engine, Man button																Dante OK
	$("#top_se_man").click(
		function(){
			$("#top_se_who").val('2')
			$("#top_se_all").removeClass("current");
			$("#top_se_woman").removeClass("current");
			$("#top_se_man").addClass("current");
			top_search_click($("#top_se_user").val(), $("#top_se_id_city").val(), $("#top_se_when_time_a").html(), $("#top_se_activity").val(), $("#top_se_who").val(), $("#zip_code").val(), $("#within").val(), 1);
		}
	);
	
	$("#top_se_when_time").change(
		function(){
			$("#top_se_man").removeClass("butt_current");
			$("#top_se_woman").removeClass("butt_current");
			$("#top_se_all").addClass("butt_current");
			top_search_click($("#top_se_user").val(), $("#top_se_id_city").val(), $("#top_se_when_time_a").html(), $("#top_se_activity").val(), 0, $("#zip_code").val(), $("#within").val(), 1);
		}
	);
	
	$("#top_se_activity").focus(
		function(){
			$(this).val('');
		}
	);
	
	$("#top_se_activity").blur(
		function(){
			if($(this).val().length == 0){
				$(this).val('Search');
			}
		}
	);
//------------------------------------------------------------------------------------------------------------
// people search engine
	$(".people_w").click(
		function(){
			$("#city_div").show();
			$("#top_se_who").show();
			$("#top_se_tabs").attr("rel", $(this).attr("rel"));
			$("#top_se_people_adv_search").hide();
			$(this).siblings("a").removeClass("current");
			$(this).addClass("current");
			people_click($("#lu").val(), $("#top_se_city").attr("rel"), $("#top_se_tabs").attr("rel"), $("#top_se_who").attr("rel"), 1);
		}
	);
	
	$(".eventmainpeople_w").click(
		function(){
			$("#city_div").show();
			$("#top_se_who").show();
			$("#top_se_tabs").attr("rel", $(this).attr("rel"));
			$("#top_se_people_adv_search").hide();
			$(this).siblings("a").removeClass("current");
			$(this).addClass("current");
			event_main_click($("#lu").val(), $("#top_se_city").attr("rel"), $("#top_se_tabs").attr("rel"), $("#top_se_who").attr("rel"), 1);
		}
	);
	$(".people_g").click(
		function(){
			$("#top_se_who").attr("rel", $(this).attr("rel"));
			$("#top_se_people_adv_search").hide();
			$(this).siblings("a").removeClass("current");
			$(this).addClass("current");
			people_click($("#lu").val(), $("#top_se_city").attr("rel"), $("#top_se_tabs").attr("rel"), $("#top_se_who").attr("rel"), 1);
		}
	);
	
	$(".eventpeople_g").click(
		function(){
			$("#top_se_who").attr("rel", $(this).attr("rel"));
			$("#top_se_people_adv_search").hide();
			$(this).siblings("a").removeClass("current");
			$(this).addClass("current");
			eventpeople_click($("#lu").val(), $("#top_se_city").attr("rel"), $("#top_se_id_activity").val(), $("#top_se_who").attr("rel"), 1);
		}
	);
	
	$("#top_se_people_search").click(
		function(){
			$("#city_div").hide();
			$("#top_se_who").hide();
			$("#top_se_people_adv_search").show();
			$(this).siblings("a").removeClass("current");
			$(this).addClass("current");
		}
	);
// simple people search, right panel
	$("#simple_search_text").focus(
		function(){
			$(this).val("");
		}
	);
	
	$("#simple_search_text").blur(
		function(){
			if($(this).val().length == 0){
				$(this).val("Search people");
			}
		}
	);

//------------------------------------------------------------------------------------------------------------

// profile, photo change
	$(".user_small_photo").click(
		function(){
			big = $("#user_main_photo").attr("rel");
			small = $(this).attr("rel");
			$("#user_main_photo").attr("src", "avatars150/" + small);
			$("#user_main_photo").attr("rel", small);
			$(this).attr("src", "avatars50/" + big);
			$(this).attr("rel", big);
			
			return false;
		}
	);


// profile, new activity
//
	$("#activity").focus(
		function(){
		}
	);
	
	$("#activity").blur(
		function(){
			if($(this).val().length == 0){
				$("#activity_label").css({'line-height': '150%'});
				$("#new_activity_step2").hide();
				$("#activity").css({height: '25px'});
			}
		}
	);
				
	$("#activity").keyup(
		function(){
			$("#activity").css({height: '55px'});
			$("#activity_label").css({'line-height': '350%'});
			$("#new_activity_step2").show();
		}
	);
	
	$("#new_activity_tool_cancel").click(
		function(){
			$("#new_activity_step2").hide();
			$("#activity").css({height: '25px'});
			$("#activity").val('');
			$("#act_tags").val('');
		}
	);
//																								Dante OK
	$("#when_date_whenever").click(
		function(){
			$("#when_date_date, #calendar, #when_time").hide();
		}
	);
//																								Dante OK
	$("#when_date_set").click(
		function(){
			$("#when_date_date, #calendar, #when_time").show();
		}
	);

// my profile, right panel

// who visited me
	$("#prof_who_visited_me").click(
		function(){
			$("#mainWindow").empty().append(loading_header);
			var html = $.ajax({
				type: "POST",
				url: "ajax/who_visited_me.php",
				async: false,
				data: "id_user=" + $("#prof_who_visited_me").attr("rel") 
			}).responseText;
			$(this).siblings("a.actions").removeClass("current");
			$("#prof_i_want").removeClass("current");
			$("#prof_messages_top").removeClass("current");
			$(this).addClass("current");
			$("#mainWindow").append(html);
			$("#preloader").remove();
			return false;
		}
	);

// i want = profile, I Want	

// followers
	$("#prof_r_followers_count").click(
		function(){
			$("#mainWindow").empty().append(loading_header);
			var html = $.ajax({
				type: "POST",
				url: "ajax/followers.php",
				async: false,
				data: "id_user=" + $("#prof_r_followers_count").attr("rel") 
			}).responseText;
			$(this).siblings("a.actions").removeClass("current");
			$("#prof_i_want").removeClass("current");
			$("#prof_messages_top").removeClass("current");
			$(this).addClass("current");
			$("#mainWindow").append(html);
			$("#preloader").remove();
			return false;
		}
	);
// followed
	$("#prof_r_followed_count").click(
		function(){
			$("#mainWindow").empty().append(loading_header);
			var html = $.ajax({
				type: "POST",
				url: "ajax/followed.php",
				async: false,
				data: "id_user=" + $("#prof_r_followed_count").attr("rel") 
			}).responseText;
			$(this).siblings("a.actions").removeClass("current");
			$("#prof_i_want").removeClass("current");
			$("#prof_messages_top").removeClass("current");
			$(this).addClass("current");
			$("#mainWindow").append(html);
			$("#preloader").remove();
			return false;
		}
	);
//------------------------------------------------------------------------------------------------------------

// chars counting
	$("#bio, #interests").keyup(function(){
		var chars;
		chars = 200 - $(this).val().length;
		if(chars == 0 || chars < 0) $(this).val($(this).val().substr(0, 199));
	});

//applying IE backgrounds for messages
	if($.browser.msie) {
		$(".msg").css("background-image", "url(../grafika/bubble_blue_ie.png)");
		$(".msg.yellow").css("background-image", "url(../grafika/bubble_yellow_ie.png)");
	}

	$("#note").keyup(function(){
		$("#additional_note").empty().append($(this).val());
	});

	$("#choose_photo").hide();
	$("#upload").addClass("current");

	$("#upload").click(function(){
		$("#choose_photo").hide();
		$("#upload_photo").fadeIn("slow");
		$(this).addClass("current");
		$("#photo_set").removeClass("current");
		return false;
	});

	$("#photo_set").click(function(){
		$("#upload_photo").hide();
		$("#choose_photo").fadeIn("slow");
		$(this).addClass("current");
		$("#upload").removeClass("current");
		return false;
	});

	$("img.avatar.choose").click(function(){
		$("img.avatar.choose").removeClass("chosen");
		$(this).addClass("chosen");
		$("#chosen_photo").val($(this).attr("alt"));
		return false;
	});

	

//login/register tabs switching																	Dante OK
	if($("#show_register_form").val() == 1){
		$("#login_stuff").hide();
		$("#link_register").addClass("current");
	}
	else{
		$("#register_stuff").hide();
		$("#link_login").addClass("current");
	}

	$("#link_register").click(
		function(){
			$("#login_stuff").hide();
			$("#register_stuff").fadeIn("slow");
			$(this).addClass("current");
			$("#link_login").removeClass("current");
			return false;
		}
	);
	
	$("#link_login").click(
		function(){
			$("#register_stuff").hide();
			$("#login_stuff").fadeIn("slow");
			$(this).addClass("current");
			$("#link_register").removeClass("current");
			return false;
		}
	);

//direct messages
	$("#dm_outbox").hide();
	$("#link_inbox").addClass("current");
	$("#link_inbox").click(function(){
		$("#dm_outbox").hide();
		$("#dm_inbox").fadeIn("slow");
		$(this).addClass("current");
		$("#link_outbox").removeClass("current");
		return false;
	});
	$("#link_outbox").click(function(){
		$("#dm_inbox").hide();
		$("#dm_outbox").fadeIn("slow");
		$(this).addClass("current");
		$("#link_inbox").removeClass("current");
		return false;
	});

//most popular and most recent users
	$("#most_popular_stuff").hide();
	$("#link_recent").addClass("current");
	var recent = $.ajax({
		url: "ajax/most_recent.php",
		async: false
	}).responseText;
	$("#most_recent_stuff").html(recent);

	$("#link_popular").click(function(){
		$("#most_recent_stuff").hide();
		$("#most_popular_stuff").fadeIn("slow");
		$(this).addClass("current");
		$("#link_recent").removeClass("current");
		var popular = $.ajax({
			url: "ajax/most_popular.php",
			async: false
		}).responseText;
		$("#most_popular_stuff").html(popular);
		recent_popular_enable();
		return false;
	});

	$("#link_recent").click(function(){
		$("#most_popular_stuff").hide();
		$("#most_recent_stuff").fadeIn("slow");
		$(this).addClass("current");
		$("#link_popular").removeClass("current");
		var recent = $.ajax({
			url: "ajax/most_recent.php",
			async: false
		}).responseText;
		$("#most_recent_stuff").html(recent);
		recent_popular_enable();
		return false;
	});

//latest message tooltip
	var winH = $("body").height();
	if(winH < window.innerHeight) winH = window.innerHeight;
	var winW = window.innerWidth;
	var tooltip_w, tooltip_h;

	function eventMouseX(e, w) {
		if (e.pageX){
			xval = e.pageX;
			mouse_x = e.pageX;
			return xval;
		}
	}
	
	function eventMouseY(e, h) {
		if(e.pageY){
			yval = e.pageY;
			mouse_y = e.pageY;
			return yval;
		}
	}
	
	$("body").mousemove(function(e){
		var m_x = eventMouseX(e, 200)-100;
		var m_y = eventMouseY(e, tooltip_h)+10;
		$("#last_msg_tooltip").css({
			left: m_x + 'px',
			top: m_y + 'px'
		});
		tooltip_h = $("#last_msg_tooltip").height;
	});
	$(".show_msg_tooltip").hover(function(){
		var markup = $.ajax({
			type: "POST",
			url: "ajax/user_last_message.php",
			data: "user=" + $(this).attr("alt"),
			async: false
		}).responseText;
		$("body").append(markup);
	}, function(){
		$("#last_msg_tooltip").remove();
	});
	$(".show_msg_tooltip").mouseout(function(){
		$("#last_msg_tooltip").remove();
	});

	function recent_popular_enable(){
		$(".show_msg_tooltip").hover(function(){
			var markup = $.ajax({
				type: "GET",
				url: "ajax/user_last_message.php",
				data: "user=" + $(this).attr("alt"),
				async: false
			}).responseText;
			$("body").append("<div id='last_msg_tooltip'>" + markup + "</div>");
		}, function(){
			$("#last_msg_tooltip").remove();
		});
	}
	
//favorites ajax stuff
	function enable_add(){
		$(".fav_add").click(function(){
			var result = $.ajax({
				type: "GET",
				url: "ajax/add_favorite.php",
				data: "stuff=" + $(this).attr("alt"),
				async: false
			}).responseText;
			if(result != "OK") alert("Error adding this message to favorites");
			if(result == "OK") {
				$(this).parent().append("<img src='grafika/heart_delete.png' class='fav_del' width='16' height='16' alt='"+ $(this).attr("alt") +"' title='Remove from favorites' />");
				enable_del();
				$(this).remove();
			}
		});
	}

	function enable_del(){
		$(".fav_del").click(function(){
			var result = $.ajax({
				type: "GET",
				url: "ajax/del_favorite.php",
				data: "stuff=" + $(this).attr("alt"),
				async: false
			}).responseText;
			if(result != "OK") alert("Error removing this message from favorites");
			if(result == "OK") {
				$(this).parent().append("<img src='grafika/heart_add.png' class='fav_add' width='16' height='16' alt='"+ $(this).attr("alt") +"' title='Add to favorites' />");
				enable_add();
				$(this).remove();
			}
		});
	}

	$(".fav_add").click(function(){
		var result = $.ajax({
			type: "GET",
			url: "ajax/add_favorite.php",
			data: "stuff=" + $(this).attr("alt"),
			async: false
		}).responseText;
		if(result != "OK") alert("Error adding this message to favorites");
		if(result == "OK") {
			$(this).parent().append("<img src='grafika/heart_delete.png' class='fav_del' width='16' height='16' alt='"+ $(this).attr("alt") +"' title='Remove from favorites' />");
			enable_del();
			$(this).remove();
		}
	});

	$(".fav_del").click(function(){
		var result = $.ajax({
			type: "GET",
			url: "ajax/del_favorite.php",
			data: "stuff=" + $(this).attr("alt"),
			async: false
		}).responseText;
		if(result != "OK") alert("Error removing this message from favorites");
		if(result == "OK") {
			$(this).parent().append("<img src='grafika/heart_add.png' class='fav_add' width='16' height='16' alt='"+ $(this).attr("alt") +"' title='Add to favorites' />");
			enable_add();
			$(this).remove();
		}
	});

//scripts to copy and paste
	$("#paste_code").click(function(){
		this.select();
	});
	$("#js_my_status").click(function(){
		this.select();
	});
	$("#js_my_friends").click(function(){
		this.select();
	});

//notification mode setting																		Dante OK
	$("#prof_r_notify_by_im, #prof_r_notify_by_email").click(function(){
		set_notify_mode($(this).val());
	});

//message notification
	$("#notify_direct1").click(function(){
		set_msg_notification($(this).val());
	});
	$("#notify_direct2").click(function(){
		set_msg_notification($(this).val());
	});

//autoselect of api key
	$("#api_key").click(function(){
		this.select();
	});

//autofill of the mail address in the invite page
	$("#check_user").val("@hotmail.com");
	$("#check_type").change(function(){
		$("#check_user").val("@"+ $(this).val() +".com");
	});

//password for account deletion
	$("#del_pass_form").hide();
	$("#del_pass").click(function(){
		$(this).hide();
		$("#del_pass_form").show();
	});

//color picker stuff
/*
	var current_element;
	
	$("#back_color").css("background", "#"+$("#back_color").val());
//	$("#back_color").click(function(){add_picker($(this));});

	$("#sticker_color").css("background", "#"+$("#sticker_color").val());
//	$("#sticker_color").click(function(){add_picker($(this), mouse_x, mouse_y);});

	$("#text_color").css("background", "#"+$("#text_color").val());
//	$("#text_color").click(function(){add_picker($(this));});

	$("#link_color").css("background", "#"+$("#link_color").val());
//	$("#link_color").click(function(){add_picker($(this));});

	$("#name_color").css("background", "#"+$("#name_color").val());
//	$("#name_color").click(function(){add_picker($(this));});

	$("#bubble_fill_color").css("background", "#"+$("#bubble_fill_color").val());
//	$("#bubble_fill_color").click(function(){add_picker($(this));});

	$("#bubble_text_color").css("background", "#"+$("#bubble_text_color").val());
//	$("#bubble_text_color").click(function(){add_picker($(this));});

	$("#side_border_color").css("background", "#"+$("#side_border_color").val());
//	$("#side_border_color").click(function(){add_picker($(this));});

	$("#side_fill_color").css("background", "#"+$("#side_fill_color").val());
//	$("#side_fill_color").click(function(){add_picker($(this));});

	$("#top_area_color").css("background", "#"+$("#top_area_color").val());
//	$("#top_area_color").click(function(){add_picker($(this));});


	function enable_customize(){
		$("#sticker_color").css("background", "#"+$("#sticker_color").val());
		$("#sticker_color").click(function(event){add_picker($(this));});

		$("#back_color").css("background", "#"+$("#back_color").val());
		$("#back_color").click(function(){add_picker($(this));});

		$("#text_color").css("background", "#"+$("#text_color").val());
		$("#text_color").click(function(){add_picker($(this));});

		$("#link_color").css("background", "#"+$("#link_color").val());
		$("#link_color").click(function(){add_picker($(this));});

		$("#bubble_fill_color").css("background", "#"+$("#bubble_fill_color").val());
		$("#bubble_fill_color").click(function(){add_picker($(this));});

		$("#bubble_text_color").css("background", "#"+$("#bubble_text_color").val());
		$("#bubble_text_color").click(function(){add_picker($(this));});

		$("#side_border_color").css("background", "#"+$("#side_border_color").val());
		$("#side_border_color").click(function(){add_picker($(this));});

		$("#side_fill_color").css("background", "#"+$("#side_fill_color").val());
		$("#side_fill_color").click(function(){add_picker($(this));});

		$("#top_area_color").css("background", "#"+$("#top_area_color").val());
		$("#top_area_color").click(function(){add_picker($(this));});
	}
*/

//color picker stuff
	function add_picker(current_element){
		var move_picker = true;
		current_element.parent().parent().parent().prepend("<div id='colorpicker'><div id='wheel'></div><a id='cmClose' href='#'>Apply Color</a></div>");
		$("#wheel").farbtastic(current_element);
		$("#colorpicker").show();
		current_element.parent().click(function(e){
			var mouse_x = eventMouseX(e, 200)-100;
			var mouse_y = eventMouseY(e, $("#colorpicker").height())+10;
			if(move_picker == true){
				$("#colorpicker").css({
					left: mouse_x + 'px',
					top: mouse_y + 'px'
				});
				move_picker = false;
			}
		});
		$("#cmClose").click(function(){
			if(current_element.val().substr(0, 1) == "#") current_element.val(current_element.val().substr(1));
			current_element.css("background", "#"+current_element.val());
			switch(current_element.attr("id")){
				case "back_color":
					$("body").css("background-color", "#" + current_element.val());
					break;
				case "side_fill_color":
					$(".tabs_middle, .tabs_top a.current, .tabs_top a.current:visited").css("background", "#" + current_element.val());
					$(".tabs_top a.current, .tabs_top a.current:visited").css("border-bottom", "1px solid #"+current_element.val());
					break;
				case "side_border_color":
					$(".tabs_middle").css("border", "2px solid #"+current_element.val());
					$("#main").css("border", "2px solid #"+current_element.val());
					$("#mainmenu").css("border", "2px solid #"+current_element.val());
					$(".tabs_top a, .tabs_top a.current").css("border-left", "1px solid #"+current_element.val()).css("border-right", "1px solid #"+current_element.val()).css("border-top", "1px solid #"+current_element.val());
					break;
				case "text_color":
					$("*, h1, h2, h3, h4, #footer, #copyright").not("a").css("color", "#"+current_element.val());
					break;
				case "link_color":
					$("a, a:visited, #footer a, #footer a:visited, .tabs_middle a, .tabs_middle a:visited").css("color", "#"+current_element.val());
					break;
			}
			$(this).parent().remove();
			return false;
		});
		return false;
	}

	var current_element;
	$("#colorpicker").hide();
	
	function enable_customize(){
//		bglib_enable();
		$("#sticker_color").css("background", "#"+$("#sticker_color").val());
		$("#sticker_color").click(function(){add_picker($(this));});

		$("#back_color").css("background", "#"+$("#back_color").val());
		$("#back_color").click(function(){add_picker($(this));});

		$("#text_color").css("background", "#"+$("#text_color").val());
		$("#text_color").click(function(){add_picker($(this));});

		$("#link_color").css("background", "#"+$("#link_color").val());
		$("#link_color").click(function(){add_picker($(this));});

		$("#bubble_fill_color").css("background", "#"+$("#bubble_fill_color").val());
		$("#bubble_fill_color").click(function(){add_picker($(this));});

		$("#bubble_text_color").css("background", "#"+$("#bubble_text_color").val());
		$("#bubble_text_color").click(function(){add_picker($(this));});

		$("#side_border_color").css("background", "#"+$("#side_border_color").val());
		$("#side_border_color").click(function(){add_picker($(this));});

		$("#side_fill_color").css("background", "#"+$("#side_fill_color").val());
		$("#side_fill_color").click(function(){add_picker($(this));});

		$("#top_area_color").css("background", "#"+$("#top_area_color").val());
		$("#top_area_color").click(function(){add_picker($(this));});
	}

//invitations check all and uncheck all
	$("#check_all").click(function(){
		$("table input").attr("checked", "checked");
		return false;
	});
	$("#uncheck_all").click(function(){
		$("table input").removeAttr("checked");
		return false;
	});

//blocking confirmation
	$(".block_user").click(function(){
		return confirm("Você tem certeza que você quer bloquear este usuário? Você não mais aparecerá em sua Lista de Seguidos, Suas mensagens não aparecerão em sua Página Pessoal e ele não mais poderá Seguir você.");
	});
	
	enable_customize();
});

// displays a number of mesg and meets in realtime
function count_msgs_meets_rt(user){
	var msgs = $.ajax({
		type: "POST",
		url: "ajax/count_msgs.php",
		async: false,
		data: "user=" + user
	}).responseText;
	$("#cnrm").html(msgs);
	$("#cnrm_r").html(msgs);
	
	
	var meets = $.ajax({
		type: "POST",
		url: "ajax/count_meets.php",
		async: false,
		data: "user=" + user
	}).responseText;
	$("#cm").html(meets);
	$("#cm_r").html(meets);
}

function count_activities(user){
	var act = $.ajax({
		type: "POST",
		url: "ajax/count_activities.php",
		async: false,
		data: "user=" + user
	}).responseText;
	$("#ca").html(act);
}

function reset_search(city, region, country){
	var zip = 0;
// city
	if(city > 0){
		var result = $.ajax({
			type: "POST",
			url: "ajax/top_se_city_list_select.php",
			async: false,
			data: "city=" + city + "&region=" + region + "&country=" + country
		}).responseText;
		$("#top_se_id_city").val(city);
		$("#top_se_city").attr("rel", city);
		$("#top_se_city").empty().append(result);
	}
	else{
		var result = $.ajax({
			type: "POST",
			url: "ajax/top_se_city_list_select.php",
			async: false,
			data: "city=" + city + "&region=" + region + "&country=" + country
		}).responseText;
/* ***		
		$("#top_se_id_city").val(city);
		$("#top_se_city").attr("rel", city);
		$("#top_se_city").empty().append(result);
**** */

		$("#top_se_city").attr('rel', '0');
		$("#top_se_id_city").val('0')
		$("#top_se_city").html(all_cities);
	}
// ZIP code
	if(country == 'us'){
		$("#zip_div").show();
		$("#zip_code").val(zip);
	}
	else{
		$("#zip_div").hide();
		$("#zip_code").val('');
	}
// time
	$("#top_se_when_time_a").html(in_specific_time);
	$("#top_se_when_time").val('');
// what
	$("#top_se_activity").val(search_tags);
// who
	$("#top_se_who").val('0');
	$("#top_se_all").addClass("current");
	$("#top_se_woman").removeClass("current");
	$("#top_se_man").removeClass("current");
// tags
	var tags = $.ajax({
		type: "POST",
		url: "ajax/most_popular_tags.php",
		async: false,
		data: "city=" + city
	}).responseText;
	$("#most_popular_tags").empty().append(tags);
// research
	top_search_click($("#top_se_user").val(), $("#top_se_id_city").val(), $("#top_se_when_time_a").html(), $("#top_se_activity").val(), $("#top_se_who").val(), $("#zip_code").val(), $("#within").val(), 1);
}

function clean_field(f){
	$(f).val('');
}


function hideT(v)
{
var z=document.act_event_form.www.value;
if(v==z)
document.act_event_form.www.value='';
}
function mover(v)
{
	document.getElementById(v).style.textDecoration='underline';

}
function mout(v)
{
document.getElementById(v).style.textDecoration='none';
}