(function()
{
	Exf = {
		app_url: "",
		this_page: "",
		_s: {},
		_u: {},
		tmp_obj: {},
		tmp_obj2: Array(),
		tmp_obj3: Array(),

		/* Function acts as main gateway/router
		*  Expects 2 params:
		*  @action  string  Specifies the action that should be performed
		*  @params  json    Array of parameters
		*/
		Gateway: function(action, params)
		{
			switch(action)
			{
				// launch on page load
				case "init":

					Exf.app_url = params.app_url;
					Exf.this_page = params.this_page;

					$("a.confirm-link").click(function (e) {
						e.preventDefault();
					});
					$("a.del_confirm_link").click(function (e) {
						e.preventDefault();
					});

					if (params.this_page == 'page.bet')
					{
						Exf.Gateway("validate-form", { form_id: "bet_form" });
					}


					// change a division
					if (Exf.this_page == "home")
					{
						$.each($(".simpleTabs"), function() {

							var current_tabs = this.id;

							$.each($("#" + current_tabs).find("a.tab"), function() {

								elem = $("#" + this.id);

								elem.bind("click", function() {
									elem = $("#" + this.id);
									rel_div = elem.attr("rel");

									// hide all tabs
									$("#" + current_tabs + " div.theTbox").hide();
									// remove active class from all tabs
									$("#" + current_tabs + " a").removeClass("selected");

									// show correct tab
									$("#" + rel_div).show();
									elem.addClass("selected");
									return false;
								});

							});
						});

						// add "more" function
						$("#widget-standings").find("ul a.more_clubs").bind("click", function() {
							$(this).parent().prevAll("li").toggleClass("shown");
							if ($(this).html() == Exf._s.division_bar.more)
							{
								$(this).html(Exf._s.division_bar.less);
							}
							else
							{
								$(this).html(Exf._s.division_bar.more);
							}
						});
						
						// setup divisions-clubs dropdowns for bet popup
						$("#division_id").bind("change", function(e) {
							var division_id = document.getElementById("division_id").options[document.getElementById("division_id").selectedIndex].value;

							$.getJSON(Exf.app_url + "ajax.get-teams.inc.php", { division_id: division_id },
				        function(data)
								{
									var new_teams = '';
				          $.each(data.teams, function(i,item){
										new_teams += '<option class="available_teams noBold" value="'  + item.id + '">' + item.name + '</option>';
				          });
									$("#club_id option.available_teams").remove();
									$("#club_id").append(new_teams);
				        });
						});

						$("#club_id").bind("change", function(e) {
							var team_name = document.getElementById("club_id").options[document.getElementById("club_id").selectedIndex].text;
							$("#my_team_name").html(team_name);
						});
						
						/* removed for now, for some reason
						
						var the_form_id = "bet-popup-register";
						$("#" + the_form_id + " input, #" + the_form_id + " select, #" + the_form_id + " textarea").focus(function() {
							$(this).prev().find("span.default").show();
						});
						
						$.validator.addMethod("checkQDate", function() // add a method to validator to check a multiple field date
						{
							if ($('#dob_day').val() != '0' && $('#dob_month').val() != '0' && $('#dob_year').val() != '0')
							{
								return true;
							}
							else
							{
								return false;
							}
						}, ' ');//Exf._s.signup.dob_error);

						$.validator.addMethod("checkQDateAge", function() // add a method to validator to check a multiple field date has is older than 12
						{
							var min_age = 12;
							var day = parseInt($('#dob_day').val(), 10);
							var month = parseInt($('#dob_month').val(), 10) - 1;
							var year = parseInt($('#dob_year').val(), 10);
							var theirDate = new Date((year + min_age), month, day);
							var today = new Date;

							if ( (today.getTime() - theirDate.getTime()) < 0) {
								return false;
							}
							else {
								return true;
							}

						}, ' ');//Exf._s.signup.dob_age_error);

						// a new class rule to group all three methods
						$.validator.addClassRules({
							requiredQDate: {checkQDate: true},
							requiredQDateAge: {checkQDateAge: true}
						});
						*/
						
						//deactivate the selects for divisions if there is case of user type Neutral Supporters
						$("#neutral_supporter").click(function(){
							if($(this).attr('checked'))
							{
								$("#division_id").attr("disabled", "disabled");
								$("#club_id").attr("disabled", "disabled");
							}
							else
							{
								$("#division_id").removeAttr("disabled");
								if($("#club_id").val() > 0)
								{
									$("#club_id").removeAttr("disabled");
								}
							}
						});
						$("#division_id").focus(function() {
							$("#club_id").removeAttr("disabled");
						});
						
						//Exf.Gateway("validate-form", { form_id: "bet-popup-register" });
						
					}

					// contact form
					if (Exf.this_page == "contact")
					{
						Exf.Gateway("validate-form", { form_id: "contact-form" });
					}

					// Facebook Connect, first login after account import
					// nickname, email and TeamId are required
					if (Exf.this_page == "profile.view")
					{
						var the_form_id = "first_facebook_login";
						$("#" + the_form_id + " input, #" + the_form_id + " select").focus(function() {
							$(this).prev().find("span.default").show();
						});
						$("#" + the_form_id + " input, #" + the_form_id + " select").blur(function() {
							$(this).prev().find("span.default").hide();
						});

						if (!$.browser.safari)
						{
							// setup form validation
							Exf.Gateway("validate-form", { form_id: "first_facebook_login" });
						}

						//document.getElementById("nickname").focus();

						//document.getElementById("club_id").setAttribute("disabled", "disabled");

						//$("#division_id").focus(function() {
						//	$("#club_id").removeAttr("disabled");
						//});

						// setup divisions-clubs dropdowns
						$("#division_id").bind("change", function(e) {
							var division_id = document.getElementById("division_id").options[document.getElementById("division_id").selectedIndex].value;

							$.getJSON(Exf.app_url + "ajax.get-teams.inc.php", { division_id: division_id },
				        function(data)
								{
									var new_teams = '';
				          $.each(data.teams, function(i,item){
										new_teams += '<option class="available_teams noBold" value="'  + item.id + '">' + item.name + '</option>';
				          });
									$("#club_id option.available_teams").remove();
									$("#club_id").append(new_teams);
				        });
						});

						$("#club_id").bind("change", function(e) {
							var team_name = document.getElementById("club_id").options[document.getElementById("club_id").selectedIndex].text;
							$("#my_team_name").html(team_name);
						});
						
						//deactivate the selects for divisions if there is case of user type Neutral Supporters
						$("#neutral_supporter").click(function(){
							if($(this).attr('checked'))
							{
								$("#division_id").attr("disabled", "disabled");
								$("#club_id").attr("disabled", "disabled");
							}
							else
							{
								$("#division_id").removeAttr("disabled");
								if($("#club_id").val() > 0)
								{
									$("#club_id").removeAttr("disabled");
								}
							}
						});
						$("#division_id").focus(function() {
							$("#club_id").removeAttr("disabled");
						});
						
						Exf.Gateway("validate-form", { form_id: "accounts_merge_password" });
						Exf.Gateway("validate-form", { form_id: "accounts_merge_email" });
					}
					
					// sign up, step 1
					if (Exf.this_page == "signup")
					{
						var the_form_id = "signup-form";
						$("#" + the_form_id + " input, #" + the_form_id + " select, #" + the_form_id + " textarea").focus(function() {
							$(this).prev().find("span.default").show();
						});
						$("#" + the_form_id + " input, #" + the_form_id + " select, #" + the_form_id + " textarea").blur(function() {
							$(this).prev().find("span.default").hide();
						});

						$.validator.addMethod("checkMDate", function() // add a method to validator to check a multiple field date
						{
							if ($('#dob_day').val() != '0' && $('#dob_month').val() != '0' && $('#dob_year').val() != '0')
							{
								return true;
							}
							else
							{
								return false;
							}
						}, Exf._s.signup.dob_error);

						$.validator.addMethod("checkMDateAge", function() // add a method to validator to check a multiple field date has is older than 12
						{
							var min_age = 12;
							var day = parseInt($('#dob_day').val(), 10);
							var month = parseInt($('#dob_month').val(), 10) - 1;
							var year = parseInt($('#dob_year').val(), 10);
							var theirDate = new Date((year + min_age), month, day);
							var today = new Date;

							if ( (today.getTime() - theirDate.getTime()) < 0) {
								return false;
							}
							else {
								return true;
							}

						}, Exf._s.signup.dob_age_error);

						// a new class rule to group all three methods
						$.validator.addClassRules({
							requiredMDate: {checkMDate: true},
							requiredMDateAge: {checkMDateAge: true}
						});

						if (!$.browser.safari)
						{
							// setup form validation
							Exf.Gateway("validate-form", { form_id: "signup-form" });
						}

						document.getElementById("nickname").focus();

						document.getElementById("club_id").setAttribute("disabled", "disabled");
						
						//deactivate the selects for divisions if there is case of user type Neutral Supporters
						$("#neutral_supporter").click(function(){
							if($(this).attr('checked'))
							{
								$("#division_id").attr("disabled", "disabled");
								$("#club_id").attr("disabled", "disabled");
							}
							else
							{
								$("#division_id").removeAttr("disabled");
								if($("#club_id").val() > 0)
								{
									$("#club_id").removeAttr("disabled");
								}
							}
						});
						
						$("#division_id").focus(function() {
							$("#club_id").removeAttr("disabled");
						});

						// setup divisions-clubs dropdowns
						$("#division_id").bind("change", function(e) {
							var division_id = document.getElementById("division_id").options[document.getElementById("division_id").selectedIndex].value;

							$.getJSON(Exf.app_url + "ajax.get-teams.inc.php", { division_id: division_id },
				        function(data)
								{
									var new_teams = '';
				          $.each(data.teams, function(i,item){
										new_teams += '<option class="available_teams noBold" value="'  + item.id + '">' + item.name + '</option>';
				          });
									$("#club_id option.available_teams").remove();
									$("#club_id").append(new_teams);
				        });
						});

						$("#club_id").bind("change", function(e) {
							var team_name = document.getElementById("club_id").options[document.getElementById("club_id").selectedIndex].text;
							$("#my_team_name").html(team_name);
						});
					}

					// Add news page
					if (Exf.this_page == "news.add")
					{
						//document.getElementById("middle_level").setAttribute("disabled", "disabled");

						$("#top_level").change(function()
						{
							$("#middle_level").css({display: 'block'});
						});


						// setup the top level dropdown
						$("#top_level").bind("change", function(e)
						{
							var top_level_id = document.getElementById("top_level").options[document.getElementById("top_level").selectedIndex].value;

							$.getJSON(Exf.app_url + "ajax.get-folders.inc.php", { level_id: top_level_id },
								function(data)
								{

									$("#the_3rd_lvl").val(0);
									$("#low_level").css({display: 'none'});

									var new_items = '<option value="0">--' + Exf._s.dropdowns + '--</option>';
									$.each(data.children, function(i,item)
									{
										new_items += '<option value="'  + item.id + '">' + item.value + '</option>';
									});
									$("#middle_level option").remove();
									$("#middle_level").append(new_items);
								});
						});

						// fill the low  level dropdown when the middle level dropdown is changed
						$("#middle_level").bind("change", function(e)
						{
							var middle_level_id = document.getElementById("middle_level").options[document.getElementById("middle_level").selectedIndex].value;

							$.getJSON(Exf.app_url + "ajax.get-folders.inc.php", { level_id: middle_level_id },
								function(data)
								{
									if (data.has_3rd_lvl == 0)
									{
										$("#the_3rd_lvl").val(0);
										$("#low_level").css({display: 'none'});
									}
									else
									{
										$("#the_3rd_lvl").val(1);
										$("#low_level").css({display: 'block'});
									}

									var new_items = '<option value="0">--' + Exf._s.dropdowns + '--</option>';
									$.each(data.children, function(i,item)
									{
										new_items += '<option value="'  + item.id + '">' + item.value + '</option>';
									});
									$("#low_level option").remove();
									$("#low_level").append(new_items);
								});
						});

						/*$("#club_id").bind("change", function(e) {
							var team_name = document.getElementById("club_id").options[document.getElementById("club_id").selectedIndex].text;
							$("#my_team_name").html(team_name);
						});*/
					}

					if (Exf.this_page == "forum.add_thread")
					{
						$("#top_level").change(function()
						{
							$("#middle_level").css({display: 'block'});
						});


						// setup the top level dropdown
						$("#top_level").bind("change", function(e)
						{
							var top_level_id = document.getElementById("top_level").options[document.getElementById("top_level").selectedIndex].value;

							$.getJSON(Exf.app_url + "ajax.get-folders.inc.php", { level_id: top_level_id },
								function(data)
								{

									$("#the_3rd_lvl").val(0);
									$("#low_level").css({display: 'none'});

									var new_items = '<option value="0">--' + Exf._s.dropdowns + '--</option>';
									$.each(data.children, function(i,item)
									{
										new_items += '<option value="'  + item.id + '">' + item.value + '</option>';
									});
									$("#middle_level option").remove();
									$("#middle_level").append(new_items);
								});
						});

						// fill the low  level dropdown when the middle level dropdown is changed
						$("#middle_level").bind("change", function(e)
						{
							var middle_level_id = document.getElementById("middle_level").options[document.getElementById("middle_level").selectedIndex].value;

							$.getJSON(Exf.app_url + "ajax.get-folders.inc.php", { level_id: middle_level_id },
								function(data)
								{
									if (data.has_3rd_lvl == 0)
									{
										$("#the_3rd_lvl").val(0);
										$("#low_level").css({display: 'none'});
									}
									else
									{
										$("#the_3rd_lvl").val(1);
										$("#low_level").css({display: 'block'});
									}

									var new_items = '<option value="0">--' + Exf._s.dropdowns + '--</option>';
									$.each(data.children, function(i,item)
									{
										new_items += '<option value="'  + item.id + '">' + item.value + '</option>';
									});
									$("#low_level option").remove();
									$("#low_level").append(new_items);
								});
						});

						// setup form validation
						jQuery.validator.addMethod("validate_1st_level", function(value, element) {
							var validates = false;
							if (value > 0)
							{
								validates = true;
							}
						  return validates;
						}, " ");
						jQuery.validator.addMethod("validate_2nd_level", function(value, element) {
							var validates = false;
							return true;
							if (document.getElementById('middle_level').style.display == "block")
							{
								$(element).prev().show();
								if (value > 0)
								{
									validates = true;
								}
							}
							else
							{
								$(element).prev().hide();
								validates = true;
							}

						  return validates;
						}, " ");
						jQuery.validator.addMethod("validate_3rd_level", function(value, element) {
							var validates = false;
							return true;
							//if ($("#the_3rd_lvl").val() != 0)
							if (document.getElementById('low_level').style.display == "block")
							{
								$(element).prev().show();
								if (value > 0)
								{
									validates = true;
								}
							}
							else
							{
								$(element).prev().hide();
								validates = true;
							}

						  return validates;
						}, " ");

						Exf.Gateway("validate-form", { form_id: "new-thread-form" });
					}

					/* user login page */
					if (document.getElementById("is_login_page"))
					{
						// set focus on e-mail field
						document.getElementById("email").focus();
					}


					/* user profile edit page */
					if (Exf.this_page == 'profile.edit')
					{
						$("#city").autocomplete(Exf.app_url + "ajax.get-cities.inc.php", {
								mustMatch: false,
								matchContains: false,
								formatResult: function(data, val) {
									return val.split("|")[0];
								},
								formatItem: function(row, i, max, val) {
									return val.split("|")[0];
								}
							});

						// photo changing
						$("#chg-photo-link").find("a").bind("click", function(){
							$("#chg-photo-link").hide();
							$("#chg-photo-form").show();
						});
						$("#chg-photo-form").find("a").bind("click", function(){
							$("#chg-photo-form").hide();
							$("#chg-photo-link").show();
						});

						// add/delete club I like/dislike
						Exf.Gateway("handle_profile_teams", {});
						
						//add/delete players I like/dislike
						Exf.Gateway("handle_profile_players", {});
					}

					/* groups add photo (step 2) */
					if (Exf.this_page == 'groups.add.step2')
					{
						$("input#submit_photo").click(function() {
							$("#loading").show();
							$(this).attr({value: Exf._s.groups.working});
							$(this).addClass("thinking");
							//$(this).attr({disabled: "disabled"});
						});

						if (document.getElementById("full_path"))
						{
							Exf.Gateway("process_uploaded_photo", { file_path: $("#file_path").val(), full_path: $("#full_path").val() });
						}
					}

					/* groups edit logo/photo */
					if (Exf.this_page == 'groups.logo')
					{
						$("input#submit_photo").click(function() {
							$("#loading").show();
							$(this).attr({value: Exf._s.groups.working});
							$(this).addClass("thinking");
							//$(this).attr({disabled: "disabled"});
						});

						if (document.getElementById("full_path"))
						{
							Exf.Gateway("process_uploaded_photo", { file_path: $("#file_path").val(), full_path: $("#full_path").val() });
						}
					}

					/* user profile edit photo page */
					if (Exf.this_page == 'profile.edit_photo')
					{
						$("input#submit_photo").click(function() {
							$("#loading").show();
							$(this).attr({value: Exf._s.profile.working});
							$(this).addClass("thinking");
							//$(this).attr({disabled: "disabled"});
						});

						if (document.getElementById("full_path"))
						{
							Exf.Gateway("process_uploaded_photo", { file_path: $("#file_path").val(), full_path: $("#full_path").val() });
						}
					}

					// user profile / view
					if (Exf.this_page == 'profile.view')
					{
						// add "send friend request" behaviour
						Exf.Gateway("send_request", { msg: Exf._s.profile.friend_add_confirm });

						// add "remove friend" behaviour
						Exf.Gateway("setup_profile_remove_friend", {msg: Exf._s.profile.friend_remove_confirm});

						// add "tease" behaviour
						Exf.Gateway("setup_tease", {});

						if (auto_start_tease)
						{
							$('#link_tease').click();
						}
						if (auto_start_addfriend)
						{
							$('#link_add_friend').click();
						}
					}

					// user profile / bet history
					if (Exf.this_page == 'profile.bet_history')
					{
						// add "send friend request" behaviour
						Exf.Gateway("send_request", { msg: Exf._s.profile.friend_add_confirm });

						// add "remove friend" behaviour
						Exf.Gateway("setup_profile_remove_friend", {msg: Exf._s.profile.friend_remove_confirm});

						// add "tease" behaviour
						Exf.Gateway("setup_tease", {});

						if (auto_start_tease)
						{
							$('#link_tease').click();
						}
						if (auto_start_addfriend)
						{
							$('#link_add_friend').click();
						}
					}

					//user profile / bet details
					if (Exf.this_page == 'profile.bets')
					{
						// add "send friend request" behaviour
						Exf.Gateway("send_request", { msg: Exf._s.profile.friend_add_confirm });

						// add "remove friend" behaviour
						Exf.Gateway("setup_profile_remove_friend", {msg: Exf._s.profile.friend_remove_confirm});

						// add "tease" behaviour
						Exf.Gateway("setup_tease", {});

						if (auto_start_tease)
						{
							$('#link_tease').click();
						}
						if (auto_start_addfriend)
						{
							$('#link_add_friend').click();
						}
					}

					// user profile / top 11
					if (Exf.this_page == 'profile.top11')
					{
						// add "send friend request" behaviour
						Exf.Gateway("send_request", { msg: Exf._s.profile.friend_add_confirm });

						// add "remove friend" behaviour
						Exf.Gateway("setup_profile_remove_friend", {msg: Exf._s.profile.friend_remove_confirm});

						// add "tease" behaviour
						Exf.Gateway("setup_tease", {});
						
						//handle comment form submit
						Exf.Gateway("profile_top11_comment_form",{});
					}

					// top 11 - edit
					if (Exf.this_page == 'profile.top11.edit')
					{
						$('#form_id').change(function() {
							$('#post_action').val('change_formation');
							$('#form_selection').submit();
						});
						$('input.playerInput').blur(function() {
							index = this.id.substring(7);
							if ('' != $('#player_'+index).val())
							{
								$('#msg_err_'+index).hide(); $('#msg_ok_'+index).show();
							}
							else
							{
								$('#msg_ok_'+index).hide(); $('#msg_err_'+index).show();
							}
						});
						$('#form_selection').submit(function() {
							for (i = 1; i <= 11; i ++)
							{
								if (Exf._s.top11.default_first_name == $('#player_first_' + i).val())
								{
									$('#player_first_' + i).val('');
								}
								if (Exf._s.top11.default_last_name == $('#player_' + i).val())
								{
									$('#player_' + i).val('');
								}
							}
							if ($('#post_action').val() != 'save')
							{
								return true;
							}
							err = false;
							first = 0;
							for (i=1;i<=11;i++)
							{
								if ('' != $('#player_'+i).val())
								{
									$('#msg_err_'+i).hide(); $('#msg_ok_'+i).show();
								}
								else
								{
									if (first == 0)
									{
										first = i;
									}
									$('#msg_ok_'+i).hide(); $('#msg_err_'+i).show();
									err = true;
								}
							}
							$('#player_'+first).focus();
							return !err;
						});
					}

					// club supporters
					if (Exf.this_page == 'clubs.supporters' || Exf.this_page == 'bwin.supporters' || Exf.this_page == 'bwin.winners')
					{
						Exf.Gateway("setup_confirm_leave", {msg:Exf._s.clubs.leave_site_confirmation});
						Exf.Gateway("setup_confirm_leave_photo", {msg:Exf._s.clubs.leave_site_confirmation});
					}

					// club photos
					if (Exf.this_page == 'club.photos')
					{
						Exf.Gateway("setup_confirm_leave", {msg:Exf._s.clubs.leave_site_confirmation});
					}

					// photos
					if (Exf.this_page == 'photos')
					{
						Exf.Gateway("setup_confirm_leave", {msg:Exf._s.clubs.leave_site_confirmation});
					}

					// videos
					if (Exf.this_page == 'videos')
					{
						Exf.Gateway("setup_confirm_leave", {msg:Exf._s.clubs.leave_site_confirmation});
					}

					// club videos
					if (Exf.this_page == 'club.videos')
					{
						Exf.Gateway("setup_confirm_leave", {msg:Exf._s.clubs.leave_site_confirmation});
					}

					// club photo
					if (Exf.this_page == 'club.photo')
					{
						Exf.Gateway("setup_confirm_leave", {msg:Exf._s.clubs.leave_site_confirmation});
					}

					// club video
					if (Exf.this_page == 'club.video')
					{
						Exf.Gateway("setup_confirm_leave", {msg:Exf._s.clubs.leave_site_confirmation});
					}

					// all supporters
					if (Exf.this_page == 'supporters')
					{
						Exf.Gateway("setup_confirm_leave", {msg:Exf._s.clubs.leave_site_confirmation});
						Exf.Gateway("setup_confirm_leave_photo", {msg:Exf._s.clubs.leave_site_confirmation});
					}

					// friends page
					if (Exf.this_page == 'profile.friends')
					{
						Exf.Gateway("setup_accept_friend_request", {});
						Exf.Gateway("setup_reject_friend_request", {});
						//Exf.Gateway("setup_remove_friend", {});
					}


					// profile groups
					if (Exf.this_page == 'profile.groups')
					{
						Exf.Gateway("setup_accept_group_invite", {});
						Exf.Gateway("setup_ignore_group_invite", {});
						Exf.Gateway("setup_accept_group_request", {});
						Exf.Gateway("setup_ignore_group_request", {});
					}

					// group profile / view
					if (Exf.this_page == 'groups.profile')
					{
						// add "join group request" behaviour
						Exf.Gateway("setup_join_group", {});

						// add "leave group request" behaviour
						Exf.Gateway("setup_leave_group", {});

						// add "delete group request" behaviour
						Exf.Gateway("setup_delete_group", {});

						if (auto_start_join)
						{
							$('#link_join').click();
						}
					}

					// group wall
					if (Exf.this_page == 'groups.wall')
					{
						// add "join group request" behaviour
						Exf.Gateway("setup_join_group", {});

						// add "leave group request" behaviour
						Exf.Gateway("setup_leave_group", {});

						// add "delete group request" behaviour
						Exf.Gateway("setup_delete_group", {});
					}

					// group photos
					if (Exf.this_page == 'group.photos')
					{
						// add "join group request" behaviour
						Exf.Gateway("setup_join_group", {});

						// add "leave group request" behaviour
						Exf.Gateway("setup_leave_group", {});

						// add "delete group request" behaviour
						Exf.Gateway("setup_delete_group", {});
					}

					// club, add video
					if (Exf.this_page == "group.add_video")
					{
						$("#title, #description").focus(function() {
							$(this).prev().find("span.default").show();
						});
						$("#title, #description").blur(function() {
							$(this).prev().find("span.default").hide();
						});
						$('#source_label').find("span.default").show();
						$("#title").focus();

						/*$("input#submit").click(function() {
							$("#loading").show();
							$(this).attr({value: Exf._s.profile.working});
							$(this).addClass("thinking");
							$(this).attr({disabled: "disabled"});
						});*/

						Exf.Gateway("validate-form", { form_id: "group_add_video" });
					}

					// group videos
					if (Exf.this_page == 'group.videos')
					{
						// add "join group request" behaviour
						Exf.Gateway("setup_join_group", {});

						// add "leave group request" behaviour
						Exf.Gateway("setup_leave_group", {});

						// add "delete group request" behaviour
						Exf.Gateway("setup_delete_group", {});
					}

					// group supporters
					if (Exf.this_page == 'groups.supporters')
					{
						// add "approve pending join request" behaviour
						Exf.Gateway("setup_join_approve", {});

						// add "deny pending join request" behaviour
						Exf.Gateway("setup_join_deny", {});

						// add "remove member" behaviour
						Exf.Gateway("setup_remove", {});

						// add "make moderator" behaviour
						Exf.Gateway("setup_moderator", {});

						// add "unmake moderator" behaviour
						Exf.Gateway("setup_unmoderator", {});

						// add "join group request" behaviour
						Exf.Gateway("setup_join_group", {});

						// add "leave group request" behaviour
						Exf.Gateway("setup_leave_group", {});

						// add "delete group request" behaviour
						Exf.Gateway("setup_delete_group", {});
					}

					// internal messaging - new message
					if (Exf.this_page == 'profile.message.add')
					{
						$("#nickname").autocomplete(Exf.app_url + "ajax.get-users.inc.php", {
							delay: 100,
							formatResult: function(data, val) {
								return val.split("|")[0];
							},
							formatItem: function(row, i, max, val) {
								return val.split("|")[0];
							}
						});

						$('#nickname').trigger('focus');
//						document.getElementById("nickname").focus();

						// setup form validation
						Exf.Gateway("validate-form", { form_id: "new-msg-form" });
					}

					// internal messaging - list messages
					if (Exf.this_page == 'profile.message.list' || Exf.this_page == 'profile.message.sent')
					{
						Exf.Gateway("del_msg", {});
					}


					// add validation for commenting form
					if (document.getElementById("post-comment-form") && Exf.this_page != 'forum.view_thread')
					{
						Exf.Gateway("validate-form", { form_id: "post-comment-form" });
					}


					// email to friend form validation call on News page
					if (Exf.this_page == 'news.article' || Exf.this_page == 'clubs.profile.news')
					{
						// setup form validation
						options = {
							success: function(responseText) {
								$("input#submit").attr({disabled: false});
								$("input#submit").val(Exf._s.article.emailtofriend_send);
								$('#etfDiv').hide();
								$('#email_to_friend .status').html('');
								form_message = false;
								switch(responseText)
								{
									case 'ok':
										form_message = Exf._s.article.emailtofriend_successful;
										break;
									case 'internal_error':
										form_message = Exf._s.article.emailtofriend_send_internal_error;
										break;
									case 'form_error':
										form_message = Exf._s.article.emailtofriend_form_error;
										break;
								}
								Exf.Gateway("display_notification", { msg: form_message });
							},
							resetForm: true
						};

						// add "more" function
						$("#widget-standings").find("ul a.more_clubs").bind("click", function() {
							$(this).parent().prevAll("li").toggleClass("shown");
							if ($(this).html() == Exf._s.division_bar.more)
							{
								$(this).html(Exf._s.division_bar.less);
							}
							else
							{
								$(this).html(Exf._s.division_bar.more);
							}
						});

						Exf.Gateway("validate-form", { form_id: "email_to_friend", ajax: true, options: options });
						/*$("#email_to_friend").submit(function()
						{
							$(this).ajaxSubmit(options);
							return false;
						});*/
					}


					if (Exf.this_page == 'profile.forgot_password')
					{
						Exf.Gateway("validate-form", { form_id: "recover-password" });
					}

					if (Exf.this_page == 'shop.details')
					{
						Exf.Gateway("validate-form", { form_id: "shop_details" });
					}


					/* add extra behaviour for Clubs page */
					if (document.getElementById("is_club_page"))
					{
						// add "more" function
						$("div.expandbList").each(function() {
							var the_div = this;
							
							//hide all division boxes on startup
							$(the_div).find('ul').hide();
							
							// toggle division boxes
							$(the_div).find("img.down-circle").bind("click", function() {
								$(the_div).find("ul").toggle();
							});

/*
							// add "more" function
							$(the_div).find("ul a.more_clubs").bind("click", function() {
								$(this).parent().prevAll("li").toggleClass("shown");
								if ($(this).html() == Exf._s.division_bar.more)
								{
									$(this).html(Exf._s.division_bar.less);
								}
								else
								{
									$(this).html(Exf._s.division_bar.more);
								}
							});
*/							
						});
					}

					if (Exf.this_page == "clubs.profile")
					{

						// setup divisions-clubs dropdowns for bet popup
						$("#division_id").bind("change", function(e) {
							var division_id = document.getElementById("division_id").options[document.getElementById("division_id").selectedIndex].value;

							$.getJSON(Exf.app_url + "ajax.get-teams.inc.php", { division_id: division_id },
				        	function(data)
							{
								var new_teams = '';
				          		$.each(data.teams, function(i,item){
									new_teams += '<option class="available_teams noBold" value="'  + item.id + '">' + item.name + '</option>';
				          		});
								$("#club_id option.available_teams").remove();
								$("#club_id").append(new_teams);
				        	});
						});

						$("#club_id").bind("change", function(e) {
							var team_name = document.getElementById("club_id").options[document.getElementById("club_id").selectedIndex].text;
							$("#my_team_name").html(team_name);
						});
						
						/* removed for now, for some reason
						var the_form_id = "bet-popup-register";
						$("#" + the_form_id + " input, #" + the_form_id + " select, #" + the_form_id + " textarea").focus(function() {
							$(this).prev().find("span.default").show();
						});
						
						$.validator.addMethod("checkQDate", function() // add a method to validator to check a multiple field date
						{
							if ($('#dob_day').val() != '0' && $('#dob_month').val() != '0' && $('#dob_year').val() != '0')
							{
								return true;
							}
							else
							{
								return false;
							}
						}, ' ');//Exf._s.signup.dob_error);

						$.validator.addMethod("checkQDateAge", function() // add a method to validator to check a multiple field date has is older than 12
						{
							var min_age = 12;
							var day = parseInt($('#dob_day').val(), 10);
							var month = parseInt($('#dob_month').val(), 10) - 1;
							var year = parseInt($('#dob_year').val(), 10);
							var theirDate = new Date((year + min_age), month, day);
							var today = new Date;

							if ( (today.getTime() - theirDate.getTime()) < 0) {
								return false;
							}
							else {
								return true;
							}

						}, ' ');//Exf._s.signup.dob_age_error);

						// a new class rule to group all three methods
						$.validator.addClassRules({
							requiredQDate: {checkQDate: true},
							requiredQDateAge: {checkQDateAge: true}
						});
						*/
						
						//deactivate the selects for divisions if there is case of user type Neutral Supporters
						$("#neutral_supporter").click(function(){
							if($(this).attr('checked'))
							{
								$("#division_id").attr("disabled", "disabled");
								$("#club_id").attr("disabled", "disabled");
							}
							else
							{
								$("#division_id").removeAttr("disabled");
								if($("#club_id").val() > 0)
								{
									$("#club_id").removeAttr("disabled");
								}
							}
						});
						$("#division_id").focus(function() {
							$("#club_id").removeAttr("disabled");
						});
						
						//Exf.Gateway("validate-form", { form_id: "bet-popup-register" });
					}
					// add news article
					if (Exf.this_page == 'club.add_article')
					{
						var the_form_id = "new-article-form";
						$("#" + the_form_id + " input, #" + the_form_id + " select, #" + the_form_id + " textarea").focus(function() {
							$(this).prev().find("span.default").show();
						});
						$("#" + the_form_id + " input, #" + the_form_id + " select, #" + the_form_id + " textarea").blur(function() {
							$(this).prev().find("span.default").hide();
						});

						document.getElementById("title").focus();

						Exf.Gateway("validate-form", { form_id: "new-article-form" });
					}

					// club, add video
					if (Exf.this_page == "club.add_video")
					{
						$("#title, #description").focus(function() {
							$(this).prev().find("span.default").show();
						});
						$("#title, #description").blur(function() {
							$(this).prev().find("span.default").hide();
						});
						$('#source_label').find("span.default").show();
						$("#title").focus();

						/*$("input#submit").click(function() {
							$("#loading").show();
							$(this).attr({value: Exf._s.profile.working});
							$(this).addClass("thinking");
							//$(this).attr({disabled: "disabled"});
						});*/

						Exf.Gateway("validate-form", { form_id: "club_add_video" });
					}

					// club, add photo
					if (Exf.this_page == "club.add_photo")
					{
						$("#title, #description").focus(function() {
							$(this).prev().find("span.default").show();
						});
						$("#title, #description").blur(function() {
							$(this).prev().find("span.default").hide();
						});
						$("#title").focus();

						/*$("input#submit").click(function() {
							$("#loading").show();
							$(this).attr({value: Exf._s.profile.working});
							$(this).addClass("thinking");
							//$(this).attr({disabled: "disabled"});
						});*/

						Exf.Gateway("validate-form", { form_id: "add_photo" });
					}


					if (Exf.this_page == 'groups.add.step1')
					{
						Exf.Gateway("validate-form", { form_id: "groupadd_step1_form" });
					}

					/* create tabs, if any markup exist */
					if ($(".tabs-container").length > 0)
					{
						Exf.Gateway("create_tabs", { "tabs_container": "tabs-container"});
					}


					// sign up, step 4 (import contacts) OR INVITE FRIENDS
					if (Exf.this_page == "signup_step4" || Exf.this_page == "invite_contacts")
					{
						var prev_val = $("input#signup_submit").val();

						// setup form validation
						$("#loading")
							.ajaxStart(function(){
								$(this).show();
							})
							.ajaxComplete(function(){
								$(this).hide();
						});

						options = {
							dataType: 'json',
							success: function(responseText) {
								$("#loading").hide();
								$("input#signup_submit").val(prev_val);
								if (responseText.success == 1)
								{
									var contacts = responseText.contacts;
									var contacts_html = '';
									var i = 0;
									$.each(contacts, function() {
										var name = this.ContactsName;
										var email = this.ContactsEmail;
										contacts_html += '<li class="imported_contacts_element"><span class="checkBoxF">';
										contacts_html += '<input onclick=\'Exf.Gateway("select_imported_contact", { name_email: "' + name + '==' + email + '", uncheck_selectall: true  });\'';
										var j = Exf.tmp_obj2.indexOf(name + '==' + email);
										if (j != -1)
										{
											contacts_html += ' checked="checked"';
										}
										contacts_html +=' type="checkbox" name="name_emails[]" value="' + name + '==' + email + '" id="contact_' + i + '" class="all_imported_contacts" /></span>';
										contacts_html +='<label for="contact_' + i + '"><span class="nameF">' + name + '</span><span class="mailF">' + email + '</span></label></li>';
										i++;
									});
									
									if (i == 0)
									{
										Exf.Gateway("display_notification", { msg: "Server message: No contacts available" });
									}
									else
									{
										$(".notification-message").hide();

										// remove existing entries
										$("li.imported_contacts_element").remove();

										// add new entries
										//$("#inviteList").html($("#inviteList").html() + contacts_html);
										$(contacts_html).insertAfter($("#select_all_contacts"));
										$("#found_contacts_container").show();

										// show/hide next/prev links
										var nr_pages = parseInt(responseText.max_page);
										var pg_items = '';

										// add prev link
										if ($("#current_page").val() != "1")
										{
											pg_items += '<a href="javascript: void(0);" onclick="Exf.Gateway(\'contacts_prev\', { form_id: \'import_friends_form\', options: Exf.tmp_obj });">&laquo;</a>' + "\n";
										}

										// add link for each page
										for (i = 1; i <= nr_pages; i++)
										{
											pg_items += '<a ';
											if (parseInt($("#current_page").val()) == i)
											{
												pg_items += 'class="current_page" ';
											}
											pg_items += 'href="javascript: void(0);" onclick="Exf.Gateway(\'contacts_nav\', { form_id: \'import_friends_form\', new_page: ' + i + ', options: Exf.tmp_obj });">' + i + '</a>' + "\n";
										}

										// add next link
										if ($("#current_page").val() != responseText.max_page)
										{
											pg_items += '<a href="javascript: void(0);" onclick="Exf.Gateway(\'contacts_next\', { form_id: \'import_friends_form\', options: Exf.tmp_obj });">&raquo;</a>' + "\n";
										}

										// inject pagination bar
										$(".pagination").html(pg_items);
										
										var custom_message = '';
										custom_message+= '<h2 class=inviteStep><span class="zStep s3">3</span>' + Exf._s.invite_contacts.step_4_your_message + '</h2>';
										custom_message+= '<textarea name="custom_message" cols=40 rows=6 ></textarea>';
										$(".custom_mess").html(custom_message);


										$.scrollTo($('#found_contacts_container'));

										// setup "select all" function
										Exf.Gateway("invite_friends_selectall", { current_status: document.getElementById("select_all_contacts_chk").checked });
									}
									$("input#signup_submit").removeClass("thinking");
									$("input#signup_submit").removeAttr("disabled");
								}
								else
								{
									Exf.Gateway("display_notification", { msg: "There was a problem connecting to the e-mail provider. Please try again!" });
									$("input#signup_submit").removeClass("thinking");
									$("input#signup_submit").removeAttr("disabled");
								}
							},
							resetForm: false
						};
						Exf.tmp_obj = options;

						Exf.Gateway("validate-form", { form_id: "import_friends_form", ajax: true, options: Exf.tmp_obj });
					}


					//init links.main page
					if (Exf.this_page == 'links.main')
					{
						$('a.showAll').click(function(){
						
							var parent = $(this).parents('ul');
								parent.find('li.hidden').removeClass('hidden').addClass('show');

							$(this).hide();
							
							return false; //avoid event bubbling up
							
						});
					}
					
					
					//ENCYCLOPEDIA homepage
					if(Exf.this_page == 'encyclopedia_homepage')
					{
						$("#updates").bind("click",function(){
							$("#updates_block").show();
							$("#updates_li").addClass('active');
							$("#reads_block").hide();
							$("#reads_li").removeClass('active');
						});
						$("#reads").bind("click",function(){
							$("#reads_block").show();
							$("#reads_li").addClass('active');
							$("#updates_block").hide();
							$("#updates_li").removeClass('active');
						});
						$("#updates_player").bind("click",function(){
							$("#updates_player_block").show();
							$("#updates_player_li").addClass('active');
							$("#reads_player_block").hide();
							$("#reads_player_li").removeClass('active');
						});
						$("#reads_player").bind("click",function(){
							$("#reads_player_block").show();
							$("#reads_player_li").addClass('active');
							$("#updates_player_block").hide();
							$("#updates_player_li").removeClass('active');
						});
						
						// search input
						$("#encSearch").click( function() {
							if ( $(this).val() == Exf._s.profile.search_box_title)
							{ $(this).attr("value", ''); }
						});
						$("#encSearch").blur( function() {
							if ( $(this).val() == '')
							{ $(this).attr("value", Exf._s.profile.search_box_title); }
						});
					}
					
					//encyclopedia_players_homepage
					if(Exf.this_page == 'encyclopedia_players_homepage')
					{
						$("#updates").bind("click",function(){
							$("#updates_block").show();
							$("#updates_li").addClass('active');
							$("#reads_block").hide();
							$("#reads_li").removeClass('active');
						});
						$("#reads").bind("click",function(){
							$("#reads_block").show();
							$("#reads_li").addClass('active');
							$("#updates_block").hide();
							$("#updates_li").removeClass('active');
						});
						
						// search input
						$("#encSearch").click( function() {
							if ( $(this).val() == Exf._s.profile.search_box_title)
							{ $(this).attr("value", ''); }
						});
						$("#encSearch").blur( function() {
							if ( $(this).val() == '')
							{ $(this).attr("value", Exf._s.profile.search_box_title); }
						});
					}
					
					//encyclopedia_player_profile
					if(Exf.this_page == 'encyclopedia_players_profile')
					{
						$("#encSearch").click( function() {
							if ( $(this).val() == Exf._s.profile.search_box_title)
							{ $(this).attr("value", ''); }
						});
						$("#encSearch").blur( function() {
							if ( $(this).val() == '')
							{ $(this).attr("value", Exf._s.profile.search_box_title); }
						});
					}
					
					//encyclopedia_club_profile
					if(Exf.this_page == 'encyclopedia_clubs_profile')
					{
						$("#encSearch").click( function() {
							if ( $(this).val() == Exf._s.profile.search_box_title)
							{ $(this).attr("value", ''); }
						});
						$("#encSearch").blur( function() {
							if ( $(this).val() == '')
							{ $(this).attr("value", Exf._s.profile.search_box_title); }
						});
					}
					
					//encyclopedia_national_team_profile
					if(Exf.this_page == 'encyclopedia_teams_profile')
					{
						$("#encSearch").click( function() {
							if ( $(this).val() == Exf._s.profile.search_box_title)
							{ $(this).attr("value", ''); }
						});
						$("#encSearch").blur( function() {
							if ( $(this).val() == '')
							{ $(this).attr("value", Exf._s.profile.search_box_title); }
						});
					}
					
					//encyclopedia_competition_profile
					if(Exf.this_page == 'encyclopedia_competitions_profile')
					{
						$("#encSearch").click( function() {
							if ( $(this).val() == Exf._s.profile.search_box_title)
							{ $(this).attr("value", ''); }
						});
						$("#encSearch").blur( function() {
							if ( $(this).val() == '')
							{ $(this).attr("value", Exf._s.profile.search_box_title); }
						});
					}
					
					//encyclopedia_clubs_alphabet
					if(Exf.this_page == 'encyclopedia_clubs_alphabet')
					{
						$("#encSearch").click( function() {
							if ( $(this).val() == Exf._s.profile.search_box_title)
							{ $(this).attr("value", ''); }
						});
						$("#encSearch").blur( function() {
							if ( $(this).val() == '')
							{ $(this).attr("value", Exf._s.profile.search_box_title); }
						});
					}
					
					//encyclopedia_players_alphabet
					if(Exf.this_page == 'encyclopedia_players_alphabet')
					{
						$("#encSearch").click( function() {
							if ( $(this).val() == Exf._s.profile.search_box_title)
							{ $(this).attr("value", ''); }
						});
						$("#encSearch").blur( function() {
							if ( $(this).val() == '')
							{ $(this).attr("value", Exf._s.profile.search_box_title); }
						});
					}
					
					
					
					//edit player profile in multiple update sections
					//player update 1
					if (Exf.this_page == 'player_profile_update1' )
					{
						//update player's nationality
						Exf.Gateway('add_country_to_input',{'input_name':'nationality'});
						//update player's country_of_birth
						Exf.Gateway('add_country_to_input',{'input_name':'country_of_birth'});
					
						//update player's current club
						Exf.Gateway("enc_handle_player_current_club", {});
						
						$("input#update_profile").click(function() {
							$(this).attr({value: Exf._s.profile.submitting});
							$(this).addClass("thinkingWhite");
						});
						
						$("#ckeckbox_retired").bind('click', function(){
							if ($("#ckeckbox_retired").attr("checked") == true)
							{
								$("#retired").val("yes");
								$("#team_for_player_val").val("");
								$("#team_for_player_val").attr("disabled","disabled");
								$("#team_for_player_id").val("0");
							}
							else
							{
								$("#retired").val("no");
								$("#team_for_player_val").removeAttr("disabled");
							}
						});
						
						//add contrains to number format
						$("input[restricted='number']").numeric(Exf._s.profile.separators.decimal);
						
						Exf.Gateway("validate-form", { form_id: "player_form_update_1" });
						
					}
					//player update 2
					if(Exf.this_page == 'player_profile_update2')
					{
						$("input#update_profile").click(function() {
							$(this).attr({value: Exf._s.profile.submitting});
							$(this).addClass("thinkingWhite");
						});
						//add contrains to number format
						$("input[restricted='number']").numeric(Exf._s.profile.separators.decimal);
						
						//set action for remover buttons of existing players
						$("img[remover]").bind("click", function(){
							$('#'+$(this).attr("remover")).remove();

						});
						
						
						Exf.Gateway("validate-form", { form_id: "player_form_update_2" });
					}
					//player update 3
					if(Exf.this_page == 'player_profile_update3')
					{
						$("input#update_profile").click(function() {
							$(this).attr({value: Exf._s.profile.submitting});
							$(this).addClass("thinkingWhite");
						});
						//add contrains to number format
						$("input[restricted='number']").numeric(Exf._s.profile.separators.decimal);
						Exf.Gateway("format_numbers_with_separators", {});
						
						Exf.Gateway("validate-form", { form_id: "player_form_update_3" });
					}
					//player update 4
					if(Exf.this_page == 'player_profile_update4')
					{
						$("#player_history_add").bind('click', function(){
								//console.log($(this).attr('entity_id'));
								Exf.Gateway('add_item_to_player_profile',{'item_type':'player_history','box':'awards_box'});
							});
						$("div[header]").bind("click",function(){
								$("#"+$(this).attr('id')+"_box").toggle('normal');
								$("#"+$(this).attr('id')+"_h3").toggleClass('teamTitle');
								$("#"+$(this).attr('id')+"_h3").toggleClass('teamTitleWhite');
							});
						//update player's current club
						Exf.Gateway("enc_handle_team_in_team_awards", {});
						
						//set content restriction for inputs
						$("input[restricted='number']").numeric(Exf._s.profile.separators.decimal);
						
						$("input#update_profile").click(function() {
							$(this).attr({value: Exf._s.profile.submitting});
							$(this).addClass("thinkingWhite");
						});
						
						Exf.Gateway("validate-form", { form_id: "player_form_update_4" });
					}
					//player update 5
					if(Exf.this_page == 'player_profile_update5')
					{
						$("#team_award_add").bind('click', function(){
								Exf.Gateway('add_item_to_player_profile',{'item_type':'team_award','box':'awards_box','entity_id':$(this).attr('entity_id')});
							});
						$(".year_header").bind("click",function(){
								$("#"+$(this).attr('id')+"_box").toggle('normal');
								$("#"+$(this).attr('id')+"_h3").toggleClass('teamTitle');
								$("#"+$(this).attr('id')+"_h3").toggleClass('teamTitleWhite');
							});
						//update player's current club
						Exf.Gateway("enc_handle_team_in_team_awards", {});
						
						$("input#update_profile").click(function() {
							$(this).attr({value: Exf._s.profile.submitting});
							$(this).addClass("thinkingWhite");
						});
						
						Exf.Gateway("validate-form", { form_id: "player_form_update_5" });
					}
					//player update 6
					if(Exf.this_page == 'player_profile_update6')
					{
					
						$("#individual_award_add").bind('click', function(){
								Exf.Gateway('add_item_to_player_profile',{'item_type':'individual_award','box':'awards_box'});
							});
						$(".year_header").bind("click",function(){
								$("#"+$(this).attr('id')+"_box").toggle('normal');
								$("#"+$(this).attr('id')+"_h3").toggleClass('teamTitle');
							});
						
						$("input#update_profile").click(function() {
							$(this).attr({value: Exf._s.profile.submitting});
							$(this).addClass("thinkingWhite");
						});
						
						//set content restriction for inputs
						$("input[restricted='number']").numeric(Exf._s.profile.separators.decimal);
						
						Exf.Gateway("validate-form", { form_id: "player_form_update_6" });
					}
					
					//player update 7
					if(Exf.this_page == 'player_profile_update7')
					{
						$("input#update_profile").click(function() {
							$(this).attr({value: Exf._s.profile.submitting});
							$(this).addClass("thinkingWhite");
						});
						
						Exf.Gateway("validate-form", { form_id: "player_form_update_7" });
					}
					//player update 8
					if(Exf.this_page == 'player_profile_update8')
					{
						$("input#update_profile").click(function() {
							$(this).attr({value: Exf._s.profile.submitting});
							$(this).addClass("thinkingWhite");
						});
						$("#link_add").bind("click",function(){
							Exf.Gateway('add_item_to_player_profile',{'item_type':'link','box':'links_box'});
						});
						
						// search input
						$("#encSearch").click( function() {
							if ( $(this).val() == Exf._s.profile.search_box_title)
							{ $(this).attr("value", ''); }
						});
						
						Exf.Gateway("validate-form", { form_id: "player_form_update_8" });
					}
					//encyclopedia_clubs_homepage
					if(Exf.this_page == 'encyclopedia_clubs_homepage')
					{
						$("#updates").bind("click",function(){
							$("#updates_block").show();
							$("#updates_li").addClass('active');
							$("#reads_block").hide();
							$("#reads_li").removeClass('active');
						});
						$("#reads").bind("click",function(){
							$("#reads_block").show();
							$("#reads_li").addClass('active');
							$("#updates_block").hide();
							$("#updates_li").removeClass('active');
						});
						
						// search input
						$("#encSearch").click( function() {
							if ( $(this).val() == Exf._s.profile.search_box_title)
							{ $(this).attr("value", ''); }
						});
						$("#encSearch").blur( function() {
							if ( $(this).val() == '')
							{ $(this).attr("value", Exf._s.profile.search_box_title); }
						});
					}
					//form updates for CLUB
					//club update 1
					if(Exf.this_page == 'club_profile_update1')
					{
						//update country to club; also, will be triggered populating proccess with related competitions
						Exf.Gateway('add_country_to_input',{'input_name':'country'});
						
						//this was suspended: the processes will be triggered by populating 'country' input
						//Exf.Gateway('add_competition_to_input',{'input_name':'competition'});
						
						$("input#update_profile").click(function() {
							$(this).attr({value: Exf._s.profile.submitting});
							$(this).addClass("thinkingWhite");
						});
						$("#my_confirm").bind("click", function(){
							if($("#my_confirm").attr("checked") == true)
								{
									$("#my_confirm_val").val("yes");
								}
							if($("#my_confirm").attr("checked") == false)
							{
								$("#my_confirm_val").val("no");
							}
						});
						
						Exf.Gateway("validate-form", { form_id: "club_form_update_1" });
						
					}
					//club update 2
					if(Exf.this_page == 'club_profile_update2')
					{	
						//update coach nationality
						Exf.Gateway('add_country_to_input',{'input_name':'coach_nationality'});

						$("input#update_profile").click(function() {
							$(this).attr({value: Exf._s.profile.submitting});
							$(this).addClass("thinkingWhite");
						});
						
						$("#a_coaches_box_add").bind('click',function(){
							Exf.Gateway('add_item_to_club_profile',{'item_type':'assitent_coach','box':'a_coaches_box'});
						});
						
						//control the behavior of default text inside inputs;
						Exf.Gateway('default_input_behavior',{'item_id':'coach_first_name'});
						Exf.Gateway('default_input_behavior',{'item_id':'coach_last_name'});
						Exf.Gateway('default_input_behavior',{'item_id':'coach_nationality_val'});
						
						//get empty values in inputs that had default values as completition indicators (the attribute 'myattribute' is still = first)
						$("form#club_form_update_2").submit(function(){
							$.each($("input[myattribute='first']"),function(){	$(this).val(''); });
						});
						
						Exf.Gateway("validate-form", { form_id: "club_form_update_2" });
					}
					//club update 3
					if(Exf.this_page == 'club_profile_update3')
					{
						//add contrains to number format
						$("input[restricted='number']").numeric(Exf._s.profile.separators.decimal);
						Exf.Gateway("format_numbers_with_separators", {});
						
						
						//control the behavior of default text inside inputs;
						Exf.Gateway('default_input_behavior',{'item_id':'president_first_name'});
						Exf.Gateway('default_input_behavior',{'item_id':'president_last_name'});
						Exf.Gateway('default_input_behavior',{'item_id':'manager_first_name'});
						Exf.Gateway('default_input_behavior',{'item_id':'manager_last_name'});
						
						
						//submit btn behaviour
						$("input#update_profile").click(function() {
							$(this).attr({value: Exf._s.profile.submitting});
							$(this).addClass("thinkingWhite");
						});
						
						//get empty values in inputs that had default values as completition indicators (the attribute 'myattribute' is still = first)
						$("form#club_form_update_3").submit(function(){
							$.each($("input[myattribute='first']"),function(){	$(this).val(''); });
						});
						
						Exf.Gateway("validate-form", { form_id: "club_form_update_3" });
						
					}
					//club update 4
					if(Exf.this_page == 'club_profile_update4')
					{
						//add contrains to number format
						$("input[restricted='number']").numeric(Exf._s.profile.separators.decimal);
						Exf.Gateway("format_numbers_with_separators", {});
						
						//submit btn behaviour
						$("input#update_profile").click(function() {
							$(this).attr({value: Exf._s.profile.submitting});
							$(this).addClass("thinkingWhite");
						});
						
						Exf.Gateway("validate-form", { form_id: "club_form_update_4" });
						
					}
					//club update 5
					if(Exf.this_page == 'club_profile_update5')
					{
						//add contrains to number format
						$("input[restricted='number']").numeric(Exf._s.profile.separators.decimal);
						Exf.Gateway("format_numbers_with_separators", {});
						
						//submit btn behaviour
						$("input#update_profile").click(function() {
							$(this).attr({value: Exf._s.profile.submitting});
							$(this).addClass("thinkingWhite");
						});
						
						//show/hide box with details for national awards
						$(".year_header").bind("click",function(){
							$("#"+$(this).attr('id')+"_box").toggle('normal');
							$("#"+$(this).attr('id')+"_h3").toggleClass('teamTitle');
							$("#"+$(this).attr('id')+"_h3").toggleClass('teamTitleWhite');
						});
						
						//add inputs for new national award in club
						$("#team_award_add").bind('click', function(){
							Exf.Gateway('add_item_to_club_profile',{'item_type':'club_national_award','box':'awards_box'});
						});
						
						Exf.Gateway("validate-form", { form_id: "club_form_update_5" });
					}
					//club update 6
					if(Exf.this_page == 'club_profile_update6')
					{
						//add contrains to number format
						$("input[restricted='number']").numeric(Exf._s.profile.separators.decimal);
						Exf.Gateway("format_numbers_with_separators", {});
						
						//submit btn behaviour
						$("input#update_profile").click(function() {
							$(this).attr({value: Exf._s.profile.submitting});
							$(this).addClass("thinkingWhite");
						});
						
						//show/hide box with details for national awards
						$(".year_header").bind("click",function(){
							$("#"+$(this).attr('id')+"_box").toggle('normal');
							$("#"+$(this).attr('id')+"_h3").toggleClass('teamTitle');
							$("#"+$(this).attr('id')+"_h3").toggleClass('teamTitleWhite');
						});
						
						//add inputs for new national award in club
						$("#team_award_add").bind('click', function(){
							Exf.Gateway('add_item_to_club_profile',{'item_type':'club_international_award','box':'awards_box'});
						});
						
						Exf.Gateway("validate-form", { form_id: "club_form_update_6" });
					}
					//club update 7
					if(Exf.this_page == 'club_profile_update7')
					{
						//submit btn behaviour
						$("input#update_profile").click(function() {
							$(this).attr({value: Exf._s.profile.submitting});
							$(this).addClass("thinkingWhite");
						});
						Exf.Gateway("validate-form", { form_id: "club_form_update_7" });
					}
					//club update 8
					if(Exf.this_page == 'club_profile_update8')
					{
						//submit btn behaviour
						$("input#update_profile").click(function() {
							$(this).attr({value: Exf._s.profile.submitting});
							$(this).addClass("thinkingWhite");
						});
						$("#link_add").bind("click",function(){
							
							Exf.Gateway('add_item_to_player_profile',{'item_type':'link','box':'links_box'});
						});
						Exf.Gateway("validate-form", { form_id: "club_form_update_8" });
					}
				
					//encyclopedia_NATIONAL TEAMS homepage
					if(Exf.this_page == 'encyclopedia_teams_homepage')
					{
						$("#updates").bind("click",function(){
							$("#updates_block").show();
							$("#updates_li").addClass('active');
							$("#reads_block").hide();
							$("#reads_li").removeClass('active');
						});
						$("#reads").bind("click",function(){
							$("#reads_block").show();
							$("#reads_li").addClass('active');
							$("#updates_block").hide();
							$("#updates_li").removeClass('active');
						});
						
						// search input
						$("#encSearch").click( function() {
							if ( $(this).val() == Exf._s.profile.search_box_title)
							{ $(this).attr("value", ''); }
						});
						$("#encSearch").blur( function() {
							if ( $(this).val() == '')
							{ $(this).attr("value", Exf._s.profile.search_box_title); }
						});
					}
					
					//form updates for NATIONAL TEAM
					//national team update 1
					if(Exf.this_page == 'national_team_profile_update1')
					{
						//update player's current club
						Exf.Gateway('add_competition_to_input',{'input_name':'competition'});
						$("input#update_profile").click(function() {
							$(this).attr({value: Exf._s.profile.submitting});
							$(this).addClass("thinkingWhite");
						});
						//update coach nationality
						Exf.Gateway('add_country_to_input',{'input_name':'coach_nationality'});
						
						//control the behavior of default text inside inputs;
						Exf.Gateway('default_input_behavior',{'item_id':'coach_first_name'});
						Exf.Gateway('default_input_behavior',{'item_id':'coach_last_name'});
						Exf.Gateway('default_input_behavior',{'item_id':'coach_nationality_val'});
						
						//get empty values in inputs that had default values as completition indicators (the attribute 'myattribute' is still = first)
						$("form#national_team_form_update_1").submit(function(){
							$.each($("input[myattribute='first']"),function() { $(this).val(''); });
						});

						
						Exf.Gateway("validate-form", { form_id: "national_team_form_update_1" });
					}
					//national team update 2
					if(Exf.this_page == 'national_team_profile_update2')
					{
						//update player to current national team
						Exf.Gateway("enc_handle_player_to_national_team", {});
					
						//set action for remover buttons of existing players
						$("img[remover]").bind("click", function(){$('#'+$(this).attr("remover")).remove();})
						
						//add player to national team
						$("#players_box_add").bind('click',function(){
							Exf.Gateway('add_item_to_national_team_profile',{'item_type':'player', 'box':'players_box'});
						});
						
						//submit button behaviour
						
						$("input#update_profile").click(function() {
							$(this).attr({value: Exf._s.profile.submitting});
							$(this).addClass("thinkingWhite");
						});
						//update coach nationality
						Exf.Gateway('add_country_to_input',{'input_name':'coach_nationality'});
						//add new assistent coaches to list
						$("#a_coaches_box_add").bind('click',function(){
							Exf.Gateway('add_item_to_club_profile',{'item_type':'assitent_coach','box':'a_coaches_box'});
						});
						
						//control the behavior of default text inside inputs;
						Exf.Gateway('default_input_behavior',{'item_id':'coach_first_name'});
						Exf.Gateway('default_input_behavior',{'item_id':'coach_last_name'});
						Exf.Gateway('default_input_behavior',{'item_id':'coach_nationality_val'});
						
						//get empty values in inputs that had default values as completition indicators (the attribute 'myattribute' is still = first)
						$("form#national_team_form_update_2").submit(function(){
							$.each($("input[myattribute='first']"),function() { $(this).val(''); });
						});
						
						Exf.Gateway("validate-form", { form_id: "national_team_form_update_2" });
					}
					//national team update 3
					if(Exf.this_page == 'national_team_profile_update3')
					{
						//add contrains to number format
						$("input[restricted='number']").numeric(Exf._s.profile.separators.decimal);
						Exf.Gateway("format_numbers_with_separators", {});
						
						//control the behavior of default text inside inputs;
						Exf.Gateway('default_input_behavior',{'item_id':'president_first_name'});
						Exf.Gateway('default_input_behavior',{'item_id':'president_last_name'});
						
						//submit button behaviour
						$("input#update_profile").click(function() {
							$(this).attr({value: Exf._s.profile.submitting});
							$(this).addClass("thinkingWhite");
						});
						
						//get empty values in inputs that had default values as completition indicators (the attribute 'myattribute' is still = first)
						$("form#national_team_form_update_3").submit(function(){
							$.each($("input[myattribute='first']"),function(){ $(this).val(''); });
						});
						
						Exf.Gateway("validate-form", { form_id: "national_team_form_update_3" });
					}
					//national team update 4
					if(Exf.this_page == 'national_team_profile_update4')
					{
						//add contrains to number format
						$("input[restricted='number']").numeric(Exf._s.profile.separators.decimal);
						Exf.Gateway("format_numbers_with_separators", {});
						
						//submit btn behaviour
						$("input#update_profile").click(function() {
							$(this).attr({value: Exf._s.profile.submitting});
							$(this).addClass("thinkingWhite");
						});
						Exf.Gateway("validate-form", { form_id: "national_team_form_update_4" });
					}
					//national team update 5
					if(Exf.this_page == 'national_team_profile_update5')
					{
						//add contrains to number format
						$("input[restricted='number']").numeric(Exf._s.profile.separators.decimal);
						Exf.Gateway("format_numbers_with_separators", {});
						
						//submit btn behaviour
						$("input#update_profile").click(function() {
							$(this).attr({value: Exf._s.profile.submitting});
							$(this).addClass("thinkingWhite");
						});
						
						//show/hide box with details for national awards
						$(".year_header").bind("click",function(){
							$("#"+$(this).attr('id')+"_box").toggle('normal');
							$("#"+$(this).attr('id')+"_h3").toggleClass('teamTitle');
							$("#"+$(this).attr('id')+"_h3").toggleClass('teamTitleWhite');
						});
						
						//add inputs for new national award in club
						$("#team_award_add").bind('click', function(){
							Exf.Gateway('add_item_to_national_team_profile',{'item_type':'national_team_award','box':'awards_box'});
						});
						Exf.Gateway("validate-form", { form_id: "national_team_form_update_5" });
					}
					//national team update 6
					if(Exf.this_page == 'national_team_profile_update6')
					{
						//submit btn behaviour
						$("input#update_profile").click(function() {
							$(this).attr({value: Exf._s.profile.submitting});
							$(this).addClass("thinkingWhite");
						});
						Exf.Gateway("validate-form", { form_id: "national_team_form_update_6" });
					}
					//national team update 7
					if(Exf.this_page == 'national_team_profile_update7')
					{
						//submit btn behaviour
						$("input#update_profile").click(function() {
							$(this).attr({value: Exf._s.profile.submitting});
							$(this).addClass("thinkingWhite");
						});
						$("#link_add").bind("click",function(){
							
							Exf.Gateway('add_item_to_player_profile',{'item_type':'link','box':'links_box'});
						});
						Exf.Gateway("validate-form", { form_id: "national_team_form_update_7" });
					}
					
					//national competitions listing in encyclopedia
					if(Exf.this_page == 'national_competitions')
					{
						//$(".areaMainList").bind("click",function(){
						$("span[area]").bind("click",function(){
							$('#comp_'+$(this).attr('area')).toggle();
							
							//Exf.Gateway('get_nation_leagues', {'area_id':$(this).attr('area')});
						});
						
						// search input
						$("#encSearch").click( function() {
							if ( $(this).val() == Exf._s.profile.search_box_title)
							{ $(this).attr("value", ''); }
						});
						$("#encSearch").blur( function() {
							if ( $(this).val() == '')
							{ $(this).attr("value", Exf._s.profile.search_box_title); }
						});
					}
					//national competition update 1
					if(Exf.this_page == 'competition_profile_update1')
					{
						//add contrains to number format
						$("input[restricted='number']").numeric(Exf._s.profile.separators.decimal);
						Exf.Gateway("format_numbers_with_separators", {});
						
						//submit button behaviour
						$("input#update_profile").click(function() {
							$(this).attr({value: Exf._s.profile.submitting});
							$(this).addClass("thinkingWhite");
						});
						
						//control the behavior of default text inside inputs;
						Exf.Gateway('default_input_behavior',{'item_id':'president_first_name'});
						Exf.Gateway('default_input_behavior',{'item_id':'president_last_name'});
						
						//get empty values in inputs that had default values as completition indicators (the attribute 'myattribute' is still = first)
						$("form#competition_form_update_1").submit(function(){
							$.each($("input[myattribute='first']"),function(){ $(this).val(''); });
						});
						
						Exf.Gateway("validate-form", { form_id: "competition_form_update_1" });
					}
					//national competition update 2 clubs in current competition
					if(Exf.this_page == 'competition_profile_update2')
					{
						//update player to current national team
						Exf.Gateway("enc_handle_clubs_to_national_competition", {});
					
						//set action for remover buttons of existing players
						$("img[remover]").bind("click", function(){$('#'+$(this).attr("remover")).remove();})
						
						//add club to national competition
						$("#teams_box_add").bind('click',function(){
							Exf.Gateway('add_item_to_competition_profile',{'item_type':'club', 'box':'teams_box'});
						});
						
						//submit button behaviour
						$("input#update_profile").click(function() {
							$(this).attr({value: Exf._s.profile.submitting});
							$(this).addClass("thinkingWhite");
						});
						Exf.Gateway("validate-form", { form_id: "competition_form_update_2" });
					}
					//national competition update 3 award winners first place and second
					if(Exf.this_page == "competition_profile_update3")
					{
						//show/hide content of season entry
						$(".year_header").bind("click",function(){
							$("#"+$(this).attr('id')+"_box").toggle('normal');
							$("#"+$(this).attr('id')+"_h3").toggleClass('teamTitle');
							$("#"+$(this).attr('id')+"_h3").toggleClass('teamTitleWhite');
						});
						//update club to champion (first) position
						Exf.Gateway("enc_handle_clubs_to_national_competition", {});
						
						//add NEW BLOCK of palmares with clubs as winners to national competition 
						$("#clubs_award_add").bind('click',function(){
							Exf.Gateway('add_item_to_competition_profile',{'item_type':'club_winners', 'box':'clubs_box', 'competition_id':$("#entity_id").val()});
						});
						
						//submit button behaviour
						$("input#update_profile").click(function() {
							$(this).attr({value: Exf._s.profile.submitting});
							$(this).addClass("thinkingWhite");
						});
						Exf.Gateway("validate-form", { form_id: "competition_form_update_3" });
					}
					//national competition update 4 best strikers
					if(Exf.this_page == "competition_profile_update4")
					{
						//show/hide condent of season entry
						$(".year_header").bind("click",function(){
							$("#"+$(this).attr('id')+"_box").toggle('normal');
							$("#"+$(this).attr('id')+"_h3").toggleClass('teamTitle');
							$("#"+$(this).attr('id')+"_h3").toggleClass('teamTitleWhite');
						});
						//update player to current list of competition strikers
						Exf.Gateway("enc_handle_player_to_national_team", {});
						
						//update player's club where he was best striker
						Exf.Gateway("enc_handle_team_in_team_awards", {});
						
						//add clubs as winners to national competition
						$("#strikers_award_add").bind('click',function(){
							Exf.Gateway('add_item_to_competition_profile',{'item_type':'strikers', 'box':'strikers_box', 'competition_id':$("#entity_id").val()});
						});
						Exf.Gateway("validate-form", { form_id: "competition_form_update_4" });
						
					}
					//national competition update 5 //history
					if(Exf.this_page == "competition_profile_update5")
					{
						//submit button behaviour
						$("input#update_profile").click(function() {
							$(this).attr({value: Exf._s.profile.submitting});
							$(this).addClass("thinkingWhite");
						});
						Exf.Gateway("validate-form", { form_id: "competition_form_update_5" });
					}
					//national competition update 6 //add links
					if(Exf.this_page == "competition_profile_update6")
					{
						$("#link_add").bind("click",function(){
							Exf.Gateway('add_item_to_player_profile',{'item_type':'link','box':'links_box'});
						});
						//submit button behaviour
						$("input#update_profile").click(function() {
							$(this).attr({value: Exf._s.profile.submitting});
							$(this).addClass("thinkingWhite");
						});
						Exf.Gateway("validate-form", { form_id: "competition_form_update_6" });
					}
					
					
					if (Exf.this_page == 'page.bet.champ' )
					{
						//update clubs for bet page
						Exf.Gateway("enc_handle_team_in_team_awards", {});
						
						//update player to bet page
						Exf.Gateway("enc_handle_player_to_national_team", {});
						
						// setup divisions-clubs dropdowns for bet popup
						$("#division_id").bind("change", function(e) {
							var division_id = document.getElementById("division_id").options[document.getElementById("division_id").selectedIndex].value;

							$.getJSON(Exf.app_url + "ajax.get-teams.inc.php", { division_id: division_id },
				        	function(data)
							{
								var new_teams = '';
				          		$.each(data.teams, function(i,item){
								new_teams += '<option class="available_teams noBold" value="'  + item.id + '">' + item.name + '</option>';
				          		});
								$("#club_id option.available_teams").remove();
								$("#club_id").append(new_teams);
				        	});
						});

						$("#club_id").bind("change", function(e) {
							var team_name = document.getElementById("club_id").options[document.getElementById("club_id").selectedIndex].text;
							$("#my_team_name").html(team_name);
						});
						
						var the_form_id = "bet-popup-register";
						$("#" + the_form_id + " input, #" + the_form_id + " select, #" + the_form_id + " textarea").focus(function() {
							$(this).prev().find("span.default").show();
						});
						
						$.validator.addMethod("checkQDate", function() // add a method to validator to check a multiple field date
						{
							if ($('#dob_day').val() != '0' && $('#dob_month').val() != '0' && $('#dob_year').val() != '0')
							{
								return true;
							}
							else
							{
								return false;
							}
						}, ' ');//Exf._s.signup.dob_error);

						$.validator.addMethod("checkQDateAge", function() // add a method to validator to check a multiple field date has is older than 12
						{
							var min_age = 12;
							var day = parseInt($('#dob_day').val(), 10);
							var month = parseInt($('#dob_month').val(), 10) - 1;
							var year = parseInt($('#dob_year').val(), 10);
							var theirDate = new Date((year + min_age), month, day);
							var today = new Date;

							if ( (today.getTime() - theirDate.getTime()) < 0) {
								return false;
							}
							else {
								return true;
							}

						}, ' ');//Exf._s.signup.dob_age_error);

						// a new class rule to group all three methods
						$.validator.addClassRules({
							requiredQDate: {checkQDate: true},
							requiredQDateAge: {checkQDateAge: true}
						});
						
						//deactivate the selects for divisions if there is case of user type Neutral Supporters
						$("#neutral_supporter").click(function(){
							if($(this).attr('checked'))
							{
								$("#division_id").attr("disabled", "disabled");
								$("#club_id").attr("disabled", "disabled");
							}
							else
							{
								$("#division_id").removeAttr("disabled");
								if($("#club_id").val() > 0)
								{
									$("#club_id").removeAttr("disabled");
								}
							}
						});
						$("#division_id").focus(function() {
							$("#club_id").removeAttr("disabled");
						});
						
						Exf.Gateway("validate-form", { form_id: "bet-popup-register" });
					}
				break;	
				
				
				// submits the form with selected imported contacts
				case "invite_friends_submit":
					var name_emails = "";
					//console.log(Exf.tmp_obj2);
					$.each(Exf.tmp_obj2, function() {
						name_emails += this + ",";
					});
					$("#name_emailz").val(name_emails);

					// setup deleted contacts
					var del_emails = "";
					$.each(Exf.tmp_obj3, function() {
						del_emails += this + ",";
					});
					$("#del_emailz").val(del_emails);
					document.getElementById('invite_friends_list').submit();
					break;

				// build "select all" function
				case "invite_friends_selectall":
					if (params.current_status)
					{
						$("input.all_imported_contacts").each(function() {
							$(this).attr({ checked: "checked" });
							Exf.Gateway("select_imported_contact", { name_email: this.value, uncheck_selectall: false });
						});
					}

					$("#select_all_contacts_chk").click(function() {
						if (this.checked)
						{
							$("#select_all").val("1");
							$("input.all_imported_contacts").each(function() {
								$(this).attr({ checked: "checked" });
								Exf.Gateway("select_imported_contact", { name_email: this.value, uncheck_selectall: false });
							});
						}
						else
						{
							$("#select_all").val("0");
							$("input.all_imported_contacts").each(function() {
								$(this).removeAttr("checked");
								Exf.Gateway("select_imported_contact", { name_email: this.value, uncheck_selectall: false });
							});
						}
					});
					break;

				// save selected imported contacts (to email them later) in an array
				case "select_imported_contact":
					var i = Exf.tmp_obj2.indexOf(params.name_email);
					if (i == -1)
					{
						var len = Exf.tmp_obj2.length;
						Exf.tmp_obj2[len] = params.name_email;
					}
					else
					{
						delete Exf.tmp_obj2[i];
						// add deleted item to the deleted items array
						var j = Exf.tmp_obj3.indexOf(params.name_email);
						if (j == -1)
						{
							var len = Exf.tmp_obj3.length;
							Exf.tmp_obj3[len] = params.name_email;
						}
						else
						{
							delete Exf.tmp_obj3[j];
						}

						if (params.uncheck_selectall)
						{
							if (document.getElementById("select_all_contacts_chk").checked)
							{
								$("#select_all_contacts_chk").removeAttr("checked");
							}
						}
					}
					break;

				// click on imported contacts navigation page	link
				case "contacts_nav":
					$("#current_page").val(params.new_page);
					$("form#" + params.form_id).ajaxSubmit(params.options);
					// setup "select all" function
					Exf.Gateway("invite_friends_selectall", { current_status: document.getElementById("select_all_contacts_chk").checked });
					break;

				// click on imported contacts navigation prev link
				case "contacts_prev":
					$("#current_page").val(parseInt($("#current_page").val()) - 1);
					$("form#" + params.form_id).ajaxSubmit(params.options);
					// setup "select all" function
					Exf.Gateway("invite_friends_selectall", { current_status: document.getElementById("select_all_contacts_chk").checked });
					break;

				// click on imported contacts navigation next link
				case "contacts_next":
					$("#current_page").val(parseInt($("#current_page").val()) + 1);
					$("form#" + params.form_id).ajaxSubmit(params.options);
					// setup "select all" function
					Exf.Gateway("invite_friends_selectall", { current_status: document.getElementById("select_all_contacts_chk").checked });
					break;

				// switch divisions - get teams for a certain division_id
				case "switch_division":
					$.getJSON(Exf.app_url + "ajax.get-teams.inc.php", { division_id: params.division_id },
		        function(data)
						{
							var new_teams = '';
		          $.each(data.teams, function(i,item){
								new_teams += '<div class="club_item" style="width: ' + item.logo_width + 'px;">';
								new_teams += '<a class="has_hint" href="'  + Exf.app_url + Exf._u.clubs.url + '/' + Exf._u.clubs_club_profile.url + '/'+ item.slug + '/"><img src="' + Exf.app_url + 'resources/team_images/' + item.logo +'_small.gif" alt="' + item.name + '" /><span class="tName">' + item.name + '</span></a>';
								new_teams += '</div>';
		          });
							$("#equipes-logos").html(new_teams);
		       	}
					);
					break;


				// display a confirmation box, with params.msg as message
				case "confirm":
					if (confirm(params.msg))
					{
						return true;
					}
					else
					{
						return false;
					}
					break;

				case "validate-form":
					var default_validate_options = {
						onblur: true,
						onkeypress: true,
						errorElement: "span",
						errorPlacement: function(error, element) {
							already_handled = false;
							if (element[0].id == 'dob_month')
							{
								element.prev().prev().children().html(error);
								already_handled = true;
							}
							if (element[0].id == 'dob_year')
							{
								element.prev().prev().prev().children().html(error);
								already_handled = true;
							}
							if (document.getElementById("status_for_provider_select") && element[0].type == "radio")
							{
								element.parent().parent().find("li:last span").html(error);
							}
							if (element[0].type == "checkbox" || element[0].type == "radio")
							{
								element.next().find("span.status").html(error);
								//element.prev().find("span.status").html(error);
							}
							else
							{
								if (!already_handled)
								{
									element.prev().children().html(error);
								}
							}
						},
						success: function(label) {
							label.html("&nbsp;").addClass("checked");
						}
					};
					
					if ($("input#update_profile"))
					{
						$("input#update_profile").removeClass("thinkingWhite");
						$("input#update_profile").attr("value", Exf._s.profile.edit_save_button);
					}
					
					// extra infos required after Facebook Connect import
					// nickname, email, division + team
					if (params.form_id == 'first_facebook_login')
					{
						var custom_validate_options = {
							rules: {
								nickname: {
									required: true,
									rangelength: [6, 12],
									remote: Exf.app_url + "ajax.form-validation.inc.php?action=register_validate_user"
								},
								email: {
									required: true,
									email: true
									//remote: Exf.app_url + "ajax.form-validation.inc.php?action=register_validate_email"
								},
								division_id: {
									required: true,
									min: 1
								},
								club_id: {
									required: true,
									min: 1
								},
								read_terms: "required"
							},
							
							messages: {
								nickname: {
									required: Exf._s.signup.username_error,
									rangelength: jQuery.format(Exf._s.signup.username_error_length_1 + " {0} " + Exf._s.signup.username_error_length_2 + " {1} " + Exf._s.signup.username_error_length_3),
									remote: jQuery.format(Exf._s.signup.username_taken)
								},
								email: {
									required: Exf._s.signup.email_error,
									email: Exf._s.signup.email_error,
									remote: jQuery.format(Exf._s.signup.email_not_available)
								},
								division_id: {
									required: Exf._s.signup.supporter_of_division_helper,
									min: Exf._s.signup.supporter_of_division_helper
								},
								club_id: {
									required: Exf._s.signup.supporter_of_team_helper,
									min: Exf._s.signup.supporter_of_team_helper
								},
								read_terms: {
									required: " "
								}
							}
						};
					}
					
					// password form for Facebook account merge
					if (params.form_id == 'accounts_merge_password')
					{
						var custom_validate_options = {
							rules: {
								password: {
									required: true
								}
							},
							messages: {
								password: {
									required: " "
								}
							}
						};
					}
					
					// email form for Facebook account merge
					if (params.form_id == 'accounts_merge_email')
					{
						var custom_validate_options = {
							rules: {
								email: {
									required: true,
									email: true
								}
							},
							messages: {
								email: {
									required: Exf._s.signup.email_error,
									email: Exf._s.signup.email_error
								}
							}
						};
					}
					
					
					// sign-up form
					if (params.form_id == 'signup-form')
					{
						var custom_validate_options = {
							rules: {
							  firstname: "required",
								lastname: "required",
								nickname: {
									required: true,
									rangelength: [6, 12],
									remote: Exf.app_url + "ajax.form-validation.inc.php?action=register_validate_user"
								},
								password1: {
									required: true
								},
								password2: {
									required: true,
									equalTo: "#password1"
								},
								email: {
									required: true,
									email: true,
									remote: Exf.app_url + "ajax.form-validation.inc.php?action=register_validate_email"
								},
								read_terms: {
									required: true
								}
							},
							messages: {
								firstname: Exf._s.signup.first_name_error,
								lastname: Exf._s.signup.last_name_error,
								nickname: {
									required: Exf._s.signup.username_error,
									rangelength: jQuery.format(Exf._s.signup.username_error_length_1 + " {0} " + Exf._s.signup.username_error_length_2 + " {1} " + Exf._s.signup.username_error_length_3),
									remote: jQuery.format(Exf._s.signup.username_taken)
								},
								password1: {
									required: Exf._s.signup.password_error
								},
								password2: {
									required: Exf._s.signup.password_error,
									equalTo: Exf._s.signup.password_confirmation_mismatch
								},
								email: {
									required: Exf._s.signup.email_error,
									email: Exf._s.signup.email_error,
									remote: jQuery.format(Exf._s.signup.email_not_available)
								},
								read_terms: {
									required: ""
								}
							}
						};
					}

					// contact form
					else if (params.form_id == 'contact-form')
					{
						var custom_validate_options = {
							rules: {
							  firstname: "required",
								lastname: "required",
								contact_type: "required",
								message: "required",
								email: {
									required: true,
									email: true
								}
							},
							messages: {
								firstname: Exf._s.signup.first_name_error,
								lastname: Exf._s.signup.last_name_error,
								contact_type: Exf._s.signup.contacttype_error,
								message: Exf._s.signup.message_error,
								email: {
									required: Exf._s.signup.email_error,
									email: Exf._s.signup.email_error
								}
							}
						};
					}

					// club - add video
					else if (params.form_id == 'club_add_video')
					{
						var custom_validate_options = {
							rules: {
								title: {
									required: true,
									maxlength: 128
								},
								source: {
									required: true,
									remote: Exf.app_url + "ajax.form-validation.inc.php?action=check_video&team_id=" + $("#this_team_id").val()
								},
								description: {
									maxlength: 500
								},
								confirm_original: {
									required: true
								},
								confirm_amateur: {
									required: true
								}
							},
							messages: {
								title: {
									required: Exf._s.clubs.add_photo_title_error_required,
									maxlength: Exf._s.clubs.add_photo_title_helper
								},
								source: {
									required: Exf._s.clubs.add_video_source_error_required,
									remote: Exf._s.clubs.add_video_source_error_not_recognized
								},
								description: {
									maxlength: ' '
								},
								confirm_original: {
									required: " "
								},
								confirm_amateur: {
									required: " "
								}
							}
						};
					}

					// group - add video
					else if (params.form_id == 'group_add_video')
					{
						var custom_validate_options = {
							rules: {
								title: {
									required: true,
									maxlength: 128
								},
								source: {
									required: true,
									remote: Exf.app_url + "ajax.form-validation.inc.php?action=check_video_group&group_id=" + $("#this_group_id").val()
								},
								description: {
									maxlength: 500
								},
								confirm_original: {
									required: true
								},
								confirm_amateur: {
									required: true
								}
							},
							messages: {
								title: {
									required: Exf._s.clubs.add_photo_title_error_required,
									maxlength: Exf._s.clubs.add_photo_title_helper
								},
								source: {
									required: Exf._s.clubs.add_video_source_error_required,
									remote: Exf._s.clubs.add_video_source_error_not_recognized
								},
								description: {
									maxlength: ' '
								},
								confirm_original: {
									required: " "
								},
								confirm_amateur: {
									required: " "
								}
							}
						};
					}

					// add photo
					else if (params.form_id == 'add_photo')
					{
						var custom_validate_options = {
							rules: {
								title: {
									required: true,
									maxlength: 128
								},
								description: {
									required: true,
									maxlength: 500
								},
								confirm_original: {
									required: true
								},
								file: {
									required: true
								}
							},
							messages: {
								title: {
									required: Exf._s.clubs.add_photo_title_error_required,
									maxlength: Exf._s.clubs.add_photo_title_helper
								},
								description: {
									required: Exf._s.clubs.add_photo_description_helper,
									maxlength: Exf._s.clubs.add_photo_description_error
								},
								confirm_original: {
									required: ' '
								},
								file: {
									required: Exf._s.clubs.add_photo_file_helper
								}
							}
						};
					}

					// shop details
					else if (params.form_id == 'shop_details')
					{
						var custom_validate_options = {
							rules: {
								name: {
									required: true
								},
								address: {
									required: true
								},
								email: {
									required: true,
									email: true
								}
							},
							messages: {
								name: {
									required: Exf._s.shop.details_err_name_required
								},
								address: {
									required: Exf._s.shop.details_err_address_required
								},
								email: {
									required: Exf._s.shop.details_err_email_required,
									email: Exf._s.shop.details_err_email_incorrect
								}
							}
						};
					}

					// send news to a friend form
					else if (params.form_id == 'email_to_friend')
					{
						var custom_validate_options = {
							rules: {
								friend_name: {
									required: true,
									minlength: 3
								},
								friend_email: {
									required: true,
									minlength: 3,
									email: true
								},
								your_name: {
									required: true,
									minlength: 3
								},
								your_email: {
									required: true,
									minlength: 3,
									email: true
								}
							},
							messages: {
								friend_name: {
									required: Exf._s.article.email_friend_name_required,
									minlength: ' '
								},
								friend_email: {
									required: Exf._s.article.email_friend_email_required,
									minlength: ' ',
									email: ' '
								},
								your_name: {
									required: Exf._s.article.email_your_name_required,
									minlength: ' '
								},
								your_email: {
									required: Exf._s.article.email_your_email_required,
									minlength: ' ',
									email: ' '
								}
							}
						};
					}

					// new message form
					else if (params.form_id == 'new-msg-form')
					{
						var custom_validate_options = {
							rules: {
								nickname: {
									required: true,
									minlength: 3,
									remote: Exf.app_url + "ajax.form-validation.inc.php?action=new_msg_validate_user"
								},
								subject: {
									required: true,
									maxlength: 100
								},
								msg: {
									required: true
								}
							},
							messages: {
								nickname: {
									required: Exf._s.profile.error_new_msg_nickname,
									minlength: jQuery.format(Exf._s.profile.error_new_msg_username_part_1 + " {0} " + Exf._s.profile.error_new_msg_username_part_2),
									remote: Exf._s.profile.error_new_msg_nickname_inexistent
								},
								subject: {
									required: Exf._s.profile.error_new_msg_subject_required,
									maxlength: jQuery.format(Exf._s.profile.error_new_msg_subject_part1 + " {0} " + Exf._s.profile.error_new_msg_subject_part2)
								},
								msg: {
									required: Exf._s.profile.error_new_msg_message
								}
							}
						};
					}

					// add news article form
					else if (params.form_id == 'new-article-form')
					{
						var custom_validate_options = {
							rules: {
								title: {
									required: true,
									maxlength: 72
								},
								long_desc: {
									required: true
								},
								confirm_original: {
									required: true
								}
							},
							messages: {
								title: {
									required: Exf._s.article_add.title_error,
									maxlength: jQuery.format(Exf._s.article_add.title_length_error_1 + " {0} " + Exf._s.article_add.title_length_error_2)
								},
								long_desc: {
									required: Exf._s.article_add.long_desc_error,
									maxlength: jQuery.format(Exf._s.article_add.long_desc_length_error_1 + " {0} " + Exf._s.article_add.long_desc_length_error_2)
								},
								confirm_original: {
									required: " "
								}
							}
						};
					}

					// form: new group - step1
					else if (params.form_id == 'groupadd_step1_form')
					{
						var custom_validate_options = {
							rules: {
								name: {
									required: true,
									minlength: 3,
									maxlength: 128
								},
								description: {
									required: true
								},
								email: {
									email: true
								},
								website: {
									url: true
								}
							},
							messages: {
								name: {
									required: Exf._s.groups.err_group_name_required,
									minlength: Exf._s.groups.err_group_name_min_length,
									maxlength: Exf._s.groups.err_group_name_max_length
								},
								description: {
									required: Exf._s.groups.err_group_desc_required
								},
								email: {
									email: Exf._s.groups.err_email_not_valid
								},
								website: {
									url: Exf._s.groups.err_website_not_valid
								}
							}
						};
					}

					// recover password page
					else if (params.form_id == 'recover-password')
					{
						var custom_validate_options = {
							rules: {
								email: {
									required: true,
									minlength: 3,
									email: true
								}
							},
							messages: {
								email: {
									required: " ",
									minlength: " ",
									email: " "
								}
							}
						};
					}

					else if (params.form_id == 'bet_form')
					{
						var custom_validate_options = {
							rules: {
								/*email: {
									required: true,
									minlength: 3,
									email: true
								}*/
							},
							messages: {
								/*email: {
									required: " ",
									minlength: " ",
									email: " "
								}*/
							}
						};
					}

					// send news to a friend form
					else if (params.form_id == 'import_friends_form')
					{
						var custom_validate_options = {
							rules: {
								email: {
									required: true,
									email: true
								},
								password: "required"
							},
							messages: {
								email: {
									required: Exf._s.signup.email_error,
									email: Exf._s.signup.email_error
								},
								password: {
									required: Exf._s.signup.password_error
								}
							}
						};
					}

					else if (params.form_id == 'post-comment-form')
					{
						var custom_validate_options = {
							rules: {
								comment: "required"
							},
							messages: {
								comment: {
									required: " "
								}
							}
						};
					}

					else if (params.form_id == 'new-thread-form')
					{
						var custom_validate_options = {
							rules: {
								top_level: "validate_1st_level",
								middle_level: "validate_2nd_level",
								low_level: "validate_3rd_level",
								title: {
									required: true
								},
								long_desc: {
									required: true
								}
							},
							messages: {
								top_level: {
									validate_1st_level: " "
								},
								middle_level: {
									validate_2nd_level: " "
								},
								low_level: {
									validate_3rd_level: " "
								},
								title: {
									required: Exf._s.article_add.title_error
								},
								long_desc: {
									required: Exf._s.article_add.long_desc_error
								}
							}
						};
					}
					
					
					
					
					// ENCYCLOPEDIA VALIDATION FORMS
					else if (params.form_id == 'club_form_update_1')
					{
						var custom_validate_options = {
							rules: {
								my_source: {
									required: true,
									url: Exf.app_url + "ajax.encyclopedia-form-validation.inc.php?action=validate_url"
								}
							},
							messages: {
								my_source: {
									required: Exf._s.profile.update_source_error,
									url: Exf._s.profile.update_source_invalid_url
								}
							}
						};
					}
					else if (params.form_id == 'club_form_update_2')
					{
						
						var custom_validate_options = {
							rules: {
								my_source: {
									required: true,
									url: Exf.app_url + "ajax.encyclopedia-form-validation.inc.php?action=validate_url"
								}
							},
							messages: {
								my_source: {
									required: Exf._s.profile.update_source_error,
									url: Exf._s.profile.update_source_invalid_url
								}
							}
						};
						
					}
					
					else if (params.form_id == 'club_form_update_3')
					{
						var custom_validate_options = {
							rules: {
								my_source: {
									required: true,
									url: Exf.app_url + "ajax.encyclopedia-form-validation.inc.php?action=validate_url"
								}
							},
							messages: {
								my_source: {
									required: Exf._s.profile.update_source_error,
									url: Exf._s.profile.update_source_invalid_url
								}
							}
						};
					}
					
					else if (params.form_id == 'club_form_update_4')
					{
						var custom_validate_options = {
							rules: {
								my_source: {
									required: true,
									url: Exf.app_url + "ajax.encyclopedia-form-validation.inc.php?action=validate_url"
								}
							},
							messages: {
								my_source: {
									required: Exf._s.profile.update_source_error,
									url: Exf._s.profile.update_source_invalid_url
								}
							}
						};
					}
					
					else if (params.form_id == 'club_form_update_5')
					{
						var custom_validate_options = {
							rules: {
								my_source: {
									required: true,
									url: Exf.app_url + "ajax.encyclopedia-form-validation.inc.php?action=validate_url"
								}
							},
							messages: {
								my_source: {
									required: Exf._s.profile.update_source_error,
									url: Exf._s.profile.update_source_invalid_url
								}
							}
						};
					}
					
					else if (params.form_id == 'club_form_update_6')
					{
						var custom_validate_options = {
							rules: {
								my_source: {
									required: true,
									url: Exf.app_url + "ajax.encyclopedia-form-validation.inc.php?action=validate_url"
								}
							},
							messages: {
								my_source: {
									required: Exf._s.profile.update_source_error,
									url: Exf._s.profile.update_source_invalid_url
								}
							}
						};
					}
					
					else if (params.form_id == 'club_form_update_7')
					{
						var custom_validate_options = {
							rules: {
								my_source: {
									required: true,
									url: Exf.app_url + "ajax.encyclopedia-form-validation.inc.php?action=validate_url"
								}
							},
							messages: {
								my_source: {
									required: Exf._s.profile.update_source_error,
									url: Exf._s.profile.update_source_invalid_url
								}
							}
						};
					}
					else if (params.form_id == 'club_form_update_8')
					{
						var custom_validate_options = {
							rules: {
								my_source: {
									required: true,
									url: Exf.app_url + "ajax.encyclopedia-form-validation.inc.php?action=validate_url"
								}
							},
							messages: {
								my_source: {
									required: Exf._s.profile.update_source_error,
									url: Exf._s.profile.update_source_invalid_url
								}
							}
						};
					}
					
					else if (params.form_id == 'player_form_update_1')
					{
						var custom_validate_options = {
							rules: {
								my_source: {
									required: true,
									url: Exf.app_url + "ajax.encyclopedia-form-validation.inc.php?action=validate_url"
								}
							},
							messages: {
								my_source: {
									required: Exf._s.profile.update_source_error,
									url: Exf._s.profile.update_source_invalid_url
								}
							}
						};
					}
					else if (params.form_id == 'player_form_update_2')
					{
						var custom_validate_options = {
							rules: {
								my_source: {
									required: true,
									url: Exf.app_url + "ajax.encyclopedia-form-validation.inc.php?action=validate_url"
								}
							},
							messages: {
								my_source: {
									required: Exf._s.profile.update_source_error,
									url: Exf._s.profile.update_source_invalid_url
								}
							}
						};
					}
					else if (params.form_id == 'player_form_update_3')
					{
						var custom_validate_options = {
							rules: {
								my_source: {
									required: true,
									url: Exf.app_url + "ajax.encyclopedia-form-validation.inc.php?action=validate_url"
								}
							},
							messages: {
								my_source: {
									required: Exf._s.profile.update_source_error,
									url: Exf._s.profile.update_source_invalid_url
								}
							}
						};
					}
					else if (params.form_id == 'player_form_update_4')
					{
						var custom_validate_options = {
							rules: {
								my_source: {
									required: true,
									url: Exf.app_url + "ajax.encyclopedia-form-validation.inc.php?action=validate_url"
								}
							},
							messages: {
								my_source: {
									required: Exf._s.profile.update_source_error,
									url: Exf._s.profile.update_source_invalid_url
								}
							}
						};
					}
					else if (params.form_id == 'player_form_update_5')
					{
						var custom_validate_options = {
							rules: {
								my_source: {
									required: true,
									url: Exf.app_url + "ajax.encyclopedia-form-validation.inc.php?action=validate_url"
								}
							},
							messages: {
								my_source: {
									required: Exf._s.profile.update_source_error,
									url: Exf._s.profile.update_source_invalid_url
								}
							}
						};
					}
					else if (params.form_id == 'player_form_update_6')
					{
						var custom_validate_options = {
							rules: {
								my_source: {
									required: true,
									url: Exf.app_url + "ajax.encyclopedia-form-validation.inc.php?action=validate_url"
								}
							},
							messages: {
								my_source: {
									required: Exf._s.profile.update_source_error,
									url: Exf._s.profile.update_source_invalid_url
								}
							}
						};
					}
					else if (params.form_id == 'player_form_update_7')
					{
						var custom_validate_options = {
							rules: {
								my_source: {
									required: true,
									url: Exf.app_url + "ajax.encyclopedia-form-validation.inc.php?action=validate_url"
								}
							},
							messages: {
								my_source: {
									required: Exf._s.profile.update_source_error,
									url: Exf._s.profile.update_source_invalid_url
								}
							}
						};
					}
					else if (params.form_id == 'player_form_update_8')
					{
						var custom_validate_options = {
							rules: {
								my_source: {
									required: true,
									url: Exf.app_url + "ajax.encyclopedia-form-validation.inc.php?action=validate_url"
								}
							},
							messages: {
								my_source: {
									required: Exf._s.profile.update_source_error,
									url: Exf._s.profile.update_source_invalid_url
								}
							}
						};
					}

					// ENCYCLOPEDIA - national teams profile update
					else if (params.form_id == 'national_team_form_update_1')
					{
						var custom_validate_options = {
							rules: {
								my_source: {
									required: true,
									url: Exf.app_url + "ajax.encyclopedia-form-validation.inc.php?action=validate_url"
								}
							},
							messages: {
								my_source: {
									required: Exf._s.profile.update_source_error,
									url: Exf._s.profile.update_source_invalid_url
								}
							}
						};
					}
					else if (params.form_id == 'national_team_form_update_2')
					{
						var custom_validate_options = {
							rules: {
								my_source: {
									required: true,
									url: Exf.app_url + "ajax.encyclopedia-form-validation.inc.php?action=validate_url"
								}
							},
							messages: {
								my_source: {
									required: Exf._s.profile.update_source_error,
									url: Exf._s.profile.update_source_invalid_url
								}
							}
						};
					}
					else if (params.form_id == 'national_team_form_update_3')
					{
						var custom_validate_options = {
							rules: {
								my_source: {
									required: true,
									url: Exf.app_url + "ajax.encyclopedia-form-validation.inc.php?action=validate_url"
								}
							},
							messages: {
								my_source: {
									required: Exf._s.profile.update_source_error,
									url: Exf._s.profile.update_source_invalid_url
								}
							}
						};
					}
					else if (params.form_id == 'national_team_form_update_4')
					{
						var custom_validate_options = {
							rules: {
								my_source: {
									required: true,
									url: Exf.app_url + "ajax.encyclopedia-form-validation.inc.php?action=validate_url"
								}
							},
							messages: {
								my_source: {
									required: Exf._s.profile.update_source_error,
									url: Exf._s.profile.update_source_invalid_url
								}
							}
						};
					}
					else if (params.form_id == 'national_team_form_update_5')
					{
						var custom_validate_options = {
							rules: {
								my_source: {
									required: true,
									url: Exf.app_url + "ajax.encyclopedia-form-validation.inc.php?action=validate_url"
								}
							},
							messages: {
								my_source: {
									required: Exf._s.profile.update_source_error,
									url: Exf._s.profile.update_source_invalid_url
								}
							}
						};
					}
					else if (params.form_id == 'national_team_form_update_6')
					{
						var custom_validate_options = {
							rules: {
								my_source: {
									required: true,
									url: Exf.app_url + "ajax.encyclopedia-form-validation.inc.php?action=validate_url"
								}
							},
							messages: {
								my_source: {
									required: Exf._s.profile.update_source_error,
									url: Exf._s.profile.update_source_invalid_url
								}
							}
						};
					}
					else if (params.form_id == 'national_team_form_update_7')
					{
						var custom_validate_options = {
							rules: {
								my_source: {
									required: true,
									url: Exf.app_url + "ajax.encyclopedia-form-validation.inc.php?action=validate_url"
								}
							},
							messages: {
								my_source: {
									required: Exf._s.profile.update_source_error,
									url: Exf._s.profile.update_source_invalid_url
								}
							}
						};
					}
					
					// ENCYCLOPEDIA - national competitions profile update
					else if (params.form_id == 'competition_form_update_1')
					{
						var custom_validate_options = {
							rules: {
								my_source: {
									required: true,
									url: Exf.app_url + "ajax.encyclopedia-form-validation.inc.php?action=validate_url"
								}
							},
							messages: {
								my_source: {
									required: Exf._s.profile.update_source_error,
									url: Exf._s.profile.update_source_invalid_url
								}
							}
						};
					}
					else if (params.form_id == 'competition_form_update_2')
					{
						var custom_validate_options = {
							rules: {
								my_source: {
									required: true,
									url: Exf.app_url + "ajax.encyclopedia-form-validation.inc.php?action=validate_url"
								}
							},
							messages: {
								my_source: {
									required: Exf._s.profile.update_source_error,
									url: Exf._s.profile.update_source_invalid_url
								}
							}
						};
					}
					else if (params.form_id == 'competition_form_update_3')
					{
						var custom_validate_options = {
							rules: {
								my_source: {
									required: true,
									url: Exf.app_url + "ajax.encyclopedia-form-validation.inc.php?action=validate_url"
								}
							},
							messages: {
								my_source: {
									required: Exf._s.profile.update_source_error,
									url: Exf._s.profile.update_source_invalid_url
								}
							}
						};
					}
					else if (params.form_id == 'competition_form_update_4')
					{
						var custom_validate_options = {
							rules: {
								my_source: {
									required: true,
									url: Exf.app_url + "ajax.encyclopedia-form-validation.inc.php?action=validate_url"
								}
							},
							messages: {
								my_source: {
									required: Exf._s.profile.update_source_error,
									url: Exf._s.profile.update_source_invalid_url
								}
							}
						};
					}
					else if (params.form_id == 'competition_form_update_5')
					{
						var custom_validate_options = {
							rules: {
								my_source: {
									required: true,
									url: Exf.app_url + "ajax.encyclopedia-form-validation.inc.php?action=validate_url"
								}
							},
							messages: {
								my_source: {
									required: Exf._s.profile.update_source_error,
									url: Exf._s.profile.update_source_invalid_url
								}
							}
						};
					}
					else if (params.form_id == 'competition_form_update_6')
					{
						var custom_validate_options = {
							rules: {
								my_source: {
									required: true,
									url: Exf.app_url + "ajax.encyclopedia-form-validation.inc.php?action=validate_url"
								}
							},
							messages: {
								my_source: {
									required: Exf._s.profile.update_source_error,
									url: Exf._s.profile.update_source_invalid_url
								}
							}
						};
					}
					
					else if (params.form_id == 'bet-popup-register')
					{
						var custom_validate_options = {
							rules: {
								nickname: {
									required: true,
									rangelength: [6, 12],
									remote: Exf.app_url + "ajax.form-validation.inc.php?action=register_validate_user"
								},
								password1: {
									required: true
								},
								password2: {
									required: true,
									equalTo: "#password1"
								},
								email: {
									required: true,
									email: true,
									remote: Exf.app_url + "ajax.form-validation.inc.php?action=register_validate_email"
								},
								read_terms: {
									required: true
								}
							},
							messages: {
								nickname: {
									required: ' ',//Exf._s.signup.username_error,
									rangelength: ' ',//jQuery.format(Exf._s.signup.username_error_length_1 + " {0} " + Exf._s.signup.username_error_length_2 + " {1} " + Exf._s.signup.username_error_length_3),
									remote: ' '//jQuery.format(Exf._s.signup.username_taken)
								},
								password1: {
									required: ' '//Exf._s.signup.password_error
								},
								password2: {
									required: ' ',//Exf._s.signup.password_error,
									equalTo: ' '//Exf._s.signup.password_confirmation_mismatch
								},
								email: {
									required: ' ',//Exf._s.signup.email_error,
									email: ' ',//Exf._s.signup.email_error,
									remote: ' '//jQuery.format(Exf._s.signup.email_not_available)
								},
								read_terms: {
									required: " "
								}
							}
						};
					}
					
					
					
					var validator = $("form#" + params.form_id).validate($.extend({}, default_validate_options, custom_validate_options));

					$("form#" + params.form_id).submit(function() {
						
						if ($("form#" + params.form_id).valid())
						{
							if (params.form_id != "import_friends_form")
							{
								$("form#" + params.form_id + " input:submit").click(function (e) {
									e.preventDefault();
								});
							}

							if (!Exf._s.article)
							{
								$("form#" + params.form_id + " input:submit").attr("disabled", "true");
								$("form#" + params.form_id + " input:submit").attr({value: Exf._s.signup.working});
							}
							else
							{
								$("form#" + params.form_id + " input:submit").attr({value: Exf._s.article.emailtofriend_progress});
							}
							$("form#" + params.form_id + " input:submit").addClass("thinking");
							

							if (params.ajax)
							{
								$("form#" + params.form_id).ajaxSubmit(params.options);
								return false;
							}
							return true;
						}
						else
						{
							$("input#update_profile").removeClass("thinkingWhite");
							$("input#update_profile").attr({value: Exf._s.profile.edit_save_button});
							return false;
						}

					});
					break;

				// map php strings localization to JS
				case "localize_strings":
					Exf._s = params.s;
					break;

				// map php urls localization to JS
				case "localize_urls":
					Exf._u = params.u;
					break;

				// profile / edit uploaded photo
				case "process_uploaded_photo":
					if (params.file_path != '')
					{
						setTimeout(function() {
							$("#edit_uploaded_picture").show();

							$('<div id="wrap_edit_pic_preview"><img id="edit_uploaded_picture_preview" src="' + params.file_path + '" style="position: relative;" /></div>')
							    .css({
								    clear: 'both',
							      display: 'block',
							      position: 'relative',
							      overflow: 'hidden',
							      width: '170px',
							      height: '170px'
							    })
							    .insertAfter($('#img_upload_preview'));

							$('#edit_uploaded_picture_img').imgAreaSelect({
								aspectRatio: '1:1',
								x1: 1,
								y1: 1,
								x2: 170,
								y2: 170,
								onSelectEnd: function(img, selection) {
									$("#selection_coords").val(selection.x1 + "," + selection.y1 + "," + selection.width + "," + selection.height);
								},
								onSelectChange: function(img, selection) {
									var scaleX = 170 / selection.width;
								  var scaleY = 170 / selection.height;

								  $('#edit_uploaded_picture_preview').css({
								    width: Math.round(scaleX * $("#edit_uploaded_picture_img").width()) + 'px',
								    height: Math.round(scaleY * $("#edit_uploaded_picture_img").height()) + 'px',
								    marginLeft: '-' + Math.round(scaleX * selection.x1) + 'px',
								    marginTop: '-' + Math.round(scaleY * selection.y1) + 'px'
								  });
								}
							})
						}, 1100);
					}
					break;
					
				case "handle_profile_players":
				{
					//register players i like events
					$('a#add_player_i_like').click(function(){
					
						$('#player_i_like_form').show();
						$('#player_i_like_validate').show();
						$('#player_i_like_add').hide();
						
						return false; //avoid event bubbling up
					});
					
					$('a#add_player_i_like_validate').click(function(){
					
						add_player(true);
						
						return false; //avoid event bubbling up
						
					});
					
					
					//register players i dislike events
					$('a#add_player_i_dislike').click(function(){
					
						$('#player_i_dislike_form').show();
						$('#player_i_dislike_validate').show();
						$('#player_i_dislike_add').hide();
						
						return false; //avoid event bubbling up
					});
					
					$('a#add_player_i_dislike_validate').click(function(){
					
						add_player(false);
						
						return false; //avoid event bubbling up
						
					});
					
					
					function textBoxKeyDown(e,isLike)
					{
						switch (e.keyCode)
						{
							// enter/return
							case 13:
							{
								e.preventDefault();
								add_player(isLike)
							}
							default:
							{
								break;
							}
						}
					}
					
					//focus event is triggered, hides the greyed out text
					//t - this element
					function evtTextBoxFocus(t)
					{
						if (t.hasClass('greyed'))
						{
							t.removeClass('greyed');
							t.attr('rel',t.val());
							t.val('');
						}
					}
					
					//blur event is triggered
					//if nothing is entered in the textbox then restores the greyed out text
					//t - this element
					function evtTextBoxBlur(t)
					{
						if (t.val().length == 0)
						{
							t.val(t.attr('rel'));
							t.removeAttr('rel');
							t.addClass('greyed');
						}
					}
					
					//remove players from database, and from list
					function register_player_remove_event(isLike)
					{
						var dislike = '';
						if (isLike === false)
						{
							dislike = 'dis';
						}
						
						var delAnchors = $('a.del_players_i_' + dislike + 'like');
						
						delAnchors.unbind('click');
						delAnchors.bind('click',function(){
							
							//this
							var t = $(this);
							
							//get the player's id
							var player_id = t.parent().attr('id').split('_');
								player_id = player_id[1];
						
							$.ajax({
								type: 'POST',
								url: Exf.app_url + 'ajax.update-user-profile.inc.php',
								data: {action: 'del_player_i_' + dislike + 'like', id: player_id},
								dataType: 'json',
								success: function() {			
									t.parent().remove();
									$("#favourites_update").val("1");
								}
							});	
						});						
					}
					
					
					//the function handles both like and dislike players to avoid code replication
					//if isLike = false then it will switch to dislike players and handle these items.
					function add_player(isLike)
					{
						var dislike = '';
						if (isLike === false)
						{
							dislike = 'dis';
						}
						
						$('span.player_i_'+dislike+'like_indicator')
							.ajaxStart(function(){
								$(this).show();
							})
							.ajaxComplete(function(){
								$(this).hide();
							});
						
						var firstName = '';
						var lastName = '';
						
						if (! $('#player_i_'+dislike+'like_firstname').hasClass('greyed') )
						{
							firstName = $('#player_i_'+dislike+'like_firstname').val();
						}
						
						if (! $('#player_i_'+dislike+'like_lastname').hasClass('greyed') )
						{
							lastName = $('#player_i_'+dislike+'like_lastname').val();
						}
						
						//no firstname and lastname was filled, don't bother to send the request to the server
						if ( (firstName.length == 0) && (lastName.length == 0) )
						{
							return false;
						}
						
						$.ajax({
							type: 'POST',
							url: Exf.app_url + 'ajax.get-players.inc.php',
							data: {firstname: firstName, lastname: lastName},
							dataType: "json",
							success: function(response) 
							{	
								if (response.count > 0)
								{
									var players = '';
									$.each(response.players, function(){
										
										var nat = '';
										if (this.nationality.length > 0)
										{
											nat = '('+this.nationality+')';
										}
										
										//use the exf names instead
										if ( (this.exf_first_name.length > 0) || (this.exf_last_name.length > 0) )
										{
											this.first_name = this.exf_first_name;
											this.last_name = this.exf_last_name;
										}
										
										players += '<li><a class="players_i_'+dislike+'like_result" href="javascript:void(0);" name="' + this.first_name + ' ' + this.last_name + '" id="player_' + this.id + '">' + this.first_name + ' ' + this.last_name +'</a> '+nat+'</li>';								
									});
									
									$('#player_i_'+dislike+'like_form div.player_i_'+dislike+'like_results').show();
									$('#player_i_'+dislike+'like_form div.player_i_'+dislike+'like_results div.found_results').show();
									$('#player_i_'+dislike+'like_form div.player_i_'+dislike+'like_results div.not_found_results').hide();
									$('#player_i_'+dislike+'like_form div.player_i_'+dislike+'like_results b.count').html(response.count);
									$('#player_i_'+dislike+'like_form div.player_i_'+dislike+'like_results span').html(response.message);
									$('#player_i_'+dislike+'like_form div.player_i_'+dislike+'like_results ul').html(players);
									
									$('a.players_i_'+dislike+'like_result').bind('click',function() {
										//get the player id from the element's ID
										var player_id = this.id.split('_');
											player_id = player_id[1];
										//construct selected player list
										var chosen_player = '<li id="playeri'+dislike+'like_' + player_id + '">' + this.name + ' <a href="javascript: void(0);" class="del_players_i_'+dislike+'like" name="delplayer_' + player_id + '"><img src="' + Exf.app_url + 'img/ics.gif" alt="X" /></a></li>';;
										
										$('#list_players_i_'+dislike+'like').append(chosen_player);
											
										//register remove player event
										register_player_remove_event(isLike)
										
										//insert the player into the database
										$.ajax({
											type: 'POST',
											url: Exf.app_url + 'ajax.update-user-profile.inc.php',
											data: {action: 'add_player_i_'+dislike+'like', id: player_id},
											dataType: 'json',
											success: function(response) {

												$('#player_i_'+dislike+'like_form').hide();
												$('#player_i_'+dislike+'like_form .player_i_'+dislike+'like_results').hide();
												$('div#player_i_'+dislike+'like_validate').hide();
												$('#player_i_'+dislike+'like_add').show();
												
												var first = $('#player_i_'+dislike+'like_firstname');
												var last = $('#player_i_'+dislike+'like_lastname');
												
												first.val(first.attr('rel'));
												first.removeAttr('rel');
												first.addClass('greyed');
												
												last.val(last.attr('rel'));
												last.removeAttr('rel');
												last.addClass('greyed');
												
												$('#player_i_'+dislike+'like_form div.player_i_'+dislike+'like_results ul').html('');
												$("#favourites_update").val("1");
											}
										});
									});
								}
								else
								{
									
									$('#player_i_'+dislike+'like_form div.player_i_'+dislike+'like_results .found_results').hide();
									$('#player_i_'+dislike+'like_form div.player_i_'+dislike+'like_results div.not_found_results').show();
									$('#player_i_'+dislike+'like_form div.player_i_'+dislike+'like_results > ul').html('');
								}

								$('#player_i_'+dislike+'like_form div.player_i_'+dislike+'like_results').show();
							}
							
						});
					}	
						
					$("input#player_i_like_firstname").keydown(function(e){textBoxKeyDown(e,true)});
					$("input#player_i_like_lastname").keydown(function(e){textBoxKeyDown(e,true)});
					$("input#player_i_dislike_firstname").keydown(function(e){textBoxKeyDown(e,false)});
					$("input#player_i_dislike_lastname").keydown(function(e){textBoxKeyDown(e,false)});
					
					$("input#player_i_like_firstname").bind("focus",function(){ evtTextBoxFocus($(this)); });
					$("input#player_i_like_lastname").bind("focus",function(){ evtTextBoxFocus($(this)); });
					$("input#player_i_dislike_firstname").bind("focus",function(){ evtTextBoxFocus($(this)); });
					$("input#player_i_dislike_lastname").bind("focus",function(){ evtTextBoxFocus($(this)); });
					
					$("input#player_i_like_firstname").bind("blur",function(){ evtTextBoxBlur($(this)); });
					$("input#player_i_like_lastname").bind("blur",function(){ evtTextBoxBlur($(this)); });
					$("input#player_i_dislike_firstname").bind("blur",function(){ evtTextBoxBlur($(this)); });
					$("input#player_i_dislike_lastname").bind("blur",function(){ evtTextBoxBlur($(this)); });
					
					register_player_remove_event(true);
					register_player_remove_event(false);
									
					break;	
				}
				
				case "handle_profile_teams":
					$("input#team_i_like_val").keydown(function (e) {
						switch (e.keyCode)
						{
							case 13:
								e.preventDefault();
								add_team_i_like();
								break;
							default:
								break;
						}
					});

					$("input#team_i_dislike_val").keydown(function (e) {
						switch (e.keyCode)
						{
							case 13:
								e.preventDefault();
								add_team_i_dislike();
								break;
							default:
								break;
						}
					});


					// delete clubs I like
					$("a.del_teams_i_like").bind("click", function() {
						var tmp = this.name.split("_");
						$.ajax({
							 type: "POST",
						   url: Exf.app_url + "ajax.update-user-profile.inc.php",
						   data: "action=del_club_i_like&team_id=" + tmp[1],
			 				 dataType: 'json',
						   success: function(resp){
								$("li#teamilike_" + tmp[1]).remove();
								$("#favourites_update").val("1");
							 }
						});
					});

					// add clubs I like
					$("a#add_team_i_like").bind("click", function() {
						$("#team_i_like_form").show();
						document.getElementById("team_i_like_val").focus();
						$("#team_i_like_validate").show();
						$("#team_i_like_add").hide();
					});


					function add_team_i_like()
					{
						$("span.team_i_like_indicator")
							.ajaxStart(function(){
								$(this).show();
							})
							.ajaxComplete(function(){
								$(this).hide();
							});

						$.ajax({
					   type: "POST",
					   url: Exf.app_url + "ajax.get-teams-by-kw.inc.php",
					   data: "keywords=" + $("#team_i_like_val").val(),
		 				 dataType: 'json',
					   success: function(resp){
								if (resp.count > 0)
								{
									var teams = "";
									$.each(resp.teams, function() {
										teams += '<li><a class="teams_i_like_result" href="javascript: void(0);" name="' + this.name + '" id="team_' + this.id + '">' + this.name + '</a> (' + this.note + ')</li>';
									});
									$("#team_i_like_form div.team_i_like_results div.found_results").show();
									$("#team_i_like_form div.team_i_like_results div.not_found_results").hide();
									$("#team_i_like_form div.team_i_like_results b.count").html(resp.count);
									$("#team_i_like_form div.team_i_like_results span").html(resp.message);
									$("#team_i_like_form div.team_i_like_results ul").html(teams);

									$("a.teams_i_like_result").bind("click", function() {
										// add team to list
										var tmp = this.id.split("_");
										var chosen_team = '<li id="teamilike_' + tmp[1] + '">' + this.name + ' <a href="javascript: void(0);" name="delteam_' + tmp[1] + '"><img src="' + Exf.app_url + 'img/ics.gif" alt="X" /></a></li>';

										$("#list_teams_i_like").append(chosen_team);

										$("li#teamilike_" + tmp[1] + " a").bind("click", function() {
											$.ajax({
												 type: "POST",
											   url: Exf.app_url + "ajax.update-user-profile.inc.php",
											   data: "action=del_club_i_like&team_id=" + tmp[1],
								 				 dataType: 'json',
											   success: function(resp){
													$("#favourites_update").val("1");
												 }
											});
										});

										var tmp = this.id.split('_');

										// add team to database (bound to user)
										$.ajax({
											type: "POST",
										   url: Exf.app_url + "ajax.update-user-profile.inc.php",
										   data: "action=add_club_i_like&team_id=" + tmp[1],
							 				 dataType: 'json',
										   success: function(resp){
											   $("#team_i_like_form").hide();
												 $("#team_i_like_validate").hide();
												 $("#team_i_like_form .team_i_like_results").hide();
												 $("#team_i_like_add").show();
												 $("#team_i_like_val").val("");
												$("#team_i_like_form div.team_i_like_results ul").html("");
												$("#favourites_update").val("1");
											 }
										});
									});
								}
								else
								{
									$("#team_i_like_form div.team_i_like_results .found_results").hide();
									$("#team_i_like_form div.team_i_like_results div.not_found_results").show();
								}

								$("#team_i_like_form .team_i_like_results").show();
					   	}
					 	});
					}

					function add_team_i_dislike()
					{
						$("span.team_i_dislike_indicator")
							.ajaxStart(function(){
								$(this).show();
							})
							.ajaxComplete(function(){
								$(this).hide();
							});

						$.ajax({
					   type: "POST",
					   url: Exf.app_url + "ajax.get-teams-by-kw.inc.php",
					   data: "keywords=" + $("#team_i_dislike_val").val(),
		 				 dataType: 'json',
					   success: function(resp){
								if (resp.count > 0)
								{
									var teams = "";
									$.each(resp.teams, function() {
										teams += '<li><a class="teams_i_dislike_result" href="javascript: void(0);" name="' + this.name + '" id="team_' + this.id + '">' + this.name + '</a> (' + this.note + ')</li>';
									});
									$("#team_i_dislike_form div.team_i_dislike_results div.found_results").show();
									$("#team_i_dislike_form div.team_i_dislike_results div.not_found_results").hide();
									$("#team_i_dislike_form div.team_i_dislike_results b.count").html(resp.count);
									$("#team_i_dislike_form div.team_i_dislike_results span").html(resp.message);
									$("#team_i_dislike_form div.team_i_dislike_results ul").html(teams);

									$("a.teams_i_dislike_result").bind("click", function() {
										// add team to list
										var tmp = this.id.split("_");
										var chosen_team = '<li id="teamidislike_' + tmp[1] + '">' + this.name + ' <a href="javascript: void(0);" name="delteam_' + tmp[1] + '"><img src="' + Exf.app_url + 'img/ics.gif" alt="X" /></a></li>';

										$("#list_teams_i_dislike").append(chosen_team);

										$("li#teamidislike_" + tmp[1] + " a").bind("click", function() {
											$.ajax({
												 type: "POST",
											   url: Exf.app_url + "ajax.update-user-profile.inc.php",
											   data: "action=del_club_i_dislike&team_id=" + tmp[1],
								 				 dataType: 'json',
											   success: function(resp){
												   $("li#teamidislike_" + tmp[1]).remove();
												 }
											});
										});

										var tmp = this.id.split('_');

										// add team to database (bound to user)
										$.ajax({
											type: "POST",
										   url: Exf.app_url + "ajax.update-user-profile.inc.php",
										   data: "action=add_club_i_dislike&team_id=" + tmp[1],
							 				 dataType: 'json',
										   success: function(resp){
												$("#team_i_dislike_form").hide();
												$("#team_i_dislike_validate").hide();
												$("#team_i_dislike_form .team_i_dislike_results").hide();
												$("#team_i_dislike_add").show();
												$("#team_i_dislike_val").val("");
												$("#team_i_dislike_form div.team_i_dislike_results ul").html("");
												$("#favourites_update").val("1");
											 }
										});
									});
								}
								else
								{
									$("#team_i_dislike_form div.team_i_dislike_results .found_results").hide();
									$("#team_i_dislike_form div.team_i_dislike_results div.not_found_results").show();
								}

								$("#team_i_dislike_form .team_i_dislike_results").show();
					   	}
					 	});
					}

					$("a#add_team_i_like_validate").bind("click", function() {
						add_team_i_like();
					});


					// delete clubs I dislike
					$("a.del_teams_i_dislike").bind("click", function() {
						var tmp = this.name.split("_");
						$.ajax({
							 type: "POST",
						   url: Exf.app_url + "ajax.update-user-profile.inc.php",
						   data: "action=del_club_i_dislike&team_id=" + tmp[1],
			 				 dataType: 'json',
						   success: function(resp){
								$("li#teamidislike_" + tmp[1]).remove();
								$("#favourites_update").val("1");
							 }
						});
					});

					// add clubs I dislike
					$("a#add_team_i_dislike").bind("click", function() {
						$("#team_i_dislike_form").show();
						document.getElementById("team_i_dislike_val").focus();
						$("#team_i_dislike_validate").show();
						$("#team_i_dislike_add").hide();
					});

					$("a#add_team_i_dislike_validate").bind("click", function() {
						add_team_i_dislike();
					});
					break;

				// create tabs functionality
				case "create_tabs":
					$.each($("." + params.tabs_container), function() {
						var current_tabs = this.id;

						$.each($("#" + current_tabs + " ul").find("li"), function() {
							var elem = $(this).find("a");
							var rel_div = elem.attr("rel");

							elem.bind("click", function() {
								// hide all tabs
								$("#" + current_tabs + " div.is_tab").hide();
								// remove active class from all tabs
								$("#" + current_tabs + " ul li a").removeClass("active");

								// show correct tab
								$("#" + rel_div).show();
								elem.addClass("active");
							});

						});
					});

					break;

				// display a notification message
				case "display_notification":
					if (document.getElementById("master-notification"))
					{
						var new_msg = $("#master-notification").clone();
						new_msg.attr("id", "");
						new_msg.appendTo("#messages-container").show();
					}
					else
					{
						var msg_cont_div = $('<div id="messages-container"></div>').appendTo("div.t3bM2");
						var msg_tpl = '<div class="notification-message">';
						msg_tpl += '<div class="the-msg"></div>';
						msg_tpl += '<div class="close-message"><a href="javascript: void(0);" onclick="$(this).parent().parent().hide();">x</a></div></div>';
						var new_msg = $(msg_tpl).appendTo("div#messages-container");
					}
					new_msg.find("div.the-msg").html(params.msg);

					if (params.notification_type == '')
					{
						new_msg.addClass(params.notification_type);
					}
					else if (params.notification_type == 'error' || params.notification_type == 'info')
					{
						new_msg.addClass(params.notification_type);
					}
					else
					{
						new_msg.addClass("getAttention");
					}
					$("#messages-container").show();
					break;

				// send a friend request
				case "send_request":
					$("a#link_add_friend").bind("click", function(){
						
						confirm(params.msg, function() {
								$.ajax({
									 type: "POST",
								   url: Exf.app_url + "ajax.profile-friends.inc.php",
								   data: "action=send_request&friend_id=" + $("#user_id").html(),
					 				 dataType: 'json',
								   success: function(resp){
									   if (resp.status == 1)
										 {
											 Exf.Gateway("display_notification", { msg: resp.msg, notification_type: "info" });
											 $("#fr_request_sent").parent().show();
											 $("a#link_add_friend").parent().hide();
										 }
										 else
										 {
											 Exf.Gateway("display_notification", { msg: resp.msg, notification_type: "error" });
										 }
									 }
								});
							}, this);
						
/*						
						confirm(params.msg, function () {
							alert('aok');
							$.ajax({
								 type: "POST",
							   url: Exf.app_url + "ajax.profile-friends.inc.php",
							   data: "action=send_request&friend_id=" + $("#user_id").html(),
				 				 dataType: 'json',
							   success: function(resp){
								   if (resp.status == 1)
									 {
										 Exf.Gateway("display_notification", { msg: resp.msg, notification_type: "info" });
										 $("#fr_request_sent").parent().show();
										 $("a#link_add_friend").parent().hide();
									 }
									 else
									 {
										 Exf.Gateway("display_notification", { msg: resp.msg, notification_type: "error" });
									 }
								 }
							});
						}, this);
*/						
					});
					break;

				// confirm you want to leave site
				case "setup_confirm_leave":
				{
					$("a.link_leave").bind("click", function(){
						userid = this.id.substring(11);
						confirm(params.msg, function () {
							window.location.href = $("#link_out_" + userid).html();
						}, this);
					});
					break;
				}

				// confirm you want to leave site
				case "setup_confirm_leave_photo":
				{
					$("a.link_leave_photo").bind("click", function(){
						userid = this.id.substring(17);
						confirm(params.msg, function () {
							window.location.href = $("#link_out_" + userid).html();
						}, this);
					});
					break;
				}

				// remove a friend request setup
				case "setup_profile_remove_friend":
				{
					$("a#link_remove_friend").bind("click", function(){
						confirm(params.msg, function () {
							$.ajax({
								 type: "POST",
							   url: Exf.app_url + "ajax.profile-friends.inc.php",
							   data: "action=remove_friend&friend_id=" + $("#user_id").html(),
				 				 dataType: 'json',
							   success: function(resp){
								   if (resp.status == 1)
									 {
										 window.location.href = window.location;
									 }
								 }
							});
						}, this);
					});
					break;
				}

				// approve a pending request
				case "setup_join_approve":
				{
					$("a.link_approve").bind("click", function(){
						userid = this.id.substring(13);
						confirm(Exf._s.groups.members.pending_approve_question, function () {
							$.ajax({
								 	type: "POST",
								 	url: Exf.app_url + "ajax.groups.inc.php",
							   		data: "action=approve_request&group_id=" + $("#group_id").html() + "&userid=" + userid,
				 				 dataType: 'json',
							   success: function(resp){
								   if (resp.status == 1)
									 {
										window.location.href = window.location;
										// $('#member_extra_pending_'+userid).hide();
										// $('#member_extra_'+userid).show();
										//  Exf.Gateway("display_notification", { msg: Exf._s.groups.members.request_approved, notification_type: "info" });
									 }
								 }
							});
						}, this);
					});
					break;
				}

				// deny a pending request
				case "setup_join_deny":
				{
					$("a.link_deny").bind("click", function(){
						userid = this.id.substring(10);
						confirm(Exf._s.groups.members.pending_deny_question, function () {
							$.ajax({
								 	type: "POST",
								 	url: Exf.app_url + "ajax.groups.inc.php",
							   		data: "action=deny_request&group_id=" + $("#group_id").html() + "&userid=" + userid,
				 				 dataType: 'json',
							   success: function(resp){
								   if (resp.status == 1)
									 {
										window.location.href = window.location;
										// $('#group_member_'+userid).hide();
										//  Exf.Gateway("display_notification", { msg: Exf._s.groups.members.request_denied, notification_type: "info" });
									 }
								 }
							});
						}, this);
					});
					break;
				}

				// remove user from group
				case "setup_remove":
				{
					$("a.link_remove").bind("click", function(){
						userid = this.id.substring(12);
						confirm(Exf._s.groups.members.remove_question, function () {
							$.ajax({
								 	type: "POST",
								 	url: Exf.app_url + "ajax.groups.inc.php",
							   		data: "action=remove&group_id=" + $("#group_id").html() + "&userid=" + userid,
				 				 dataType: 'json',
							   success: function(resp){
								   if (resp.status == 1)
									 {
										$('#group_member_'+userid).hide();
										 Exf.Gateway("display_notification", { msg: Exf._s.groups.members.member_removed, notification_type: "info" });
									 }
								 }
							});
						}, this);
					});
					break;
				}

				// make user moderator
				case "setup_moderator":
				{
					$("a.link_moderator").bind("click", function(){
						userid = this.id.substring(15);
						confirm(Exf._s.groups.members.moderator_question, function () {
							$.ajax({
								 	type: "POST",
								 	url: Exf.app_url + "ajax.groups.inc.php",
							   		data: "action=moderator&group_id=" + $("#group_id").html() + "&userid=" + userid,
				 				 dataType: 'json',
							   success: function(resp){
								   if (resp.status == 1)
									 {
										$('#make_moderator_'+userid).hide();
										$('#make_unmoderator_'+userid).show();
										 Exf.Gateway("display_notification", { msg: Exf._s.groups.members.moderator_done, notification_type: "info" });
									 }
								 }
							});
						}, this);
					});
					break;
				}

				// unmake moderator
				case "setup_unmoderator":
				{
					$("a.link_unmoderator").bind("click", function(){
						userid = this.id.substring(17);
						confirm(Exf._s.groups.members.unmake_moderator_question, function () {
							$.ajax({
								 	type: "POST",
								 	url: Exf.app_url + "ajax.groups.inc.php",
							   		data: "action=unmoderator&group_id=" + $("#group_id").html() + "&userid=" + userid,
				 				 dataType: 'json',
							   success: function(resp){
								   if (resp.status == 1)
									 {
										$('#make_unmoderator_'+userid).hide();
										$('#make_moderator_'+userid).show();
										 Exf.Gateway("display_notification", { msg: Exf._s.groups.members.unmake_moderator_done, notification_type: "info" });
									 }
								 }
							});
						}, this);
					});
					break;
				}

				// join a group request
				case "setup_join_group":
				{
					$("a.join_group_link").bind("click", function(){
						public_status = parseInt($("#group_public").html());
						msg = (public_status) ? Exf._s.groups.actions.join_request_question_public : Exf._s.groups.actions.join_request_question_private;
						confirm(msg, function () {
							$.ajax({
								 	type: "POST",
								 	url: Exf.app_url + "ajax.groups.inc.php",
							   		data: "action=join_group&group_id=" + $("#group_id").html(),
				 				 dataType: 'json',
							   success: function(resp){
									document.location = $("#group_url").html();
									// 								   if (resp.status == 1)
									//  {
									// 	Exf.Gateway("display_notification", { msg: Exf._s.groups.actions.join_request_sent, notification_type: "info" });
									//  }
									// else
									// {
									//    if (resp.status == 2)
									// 	 {
									// 		//Exf.Gateway("display_notification", { msg: Exf._s.groups.actions.join_request_success, notification_type: "info" });
									// 	 }
									// }
								 }

							});
						}, this);
					});
					break;
				}

				// leave a group request
				case "setup_leave_group":
				{
					$("a#leave_group_link").bind("click", function(){
						confirm(Exf._s.groups.actions.leave_request_question, function () {
							document.location = $("#leave_group_url").html();
						}, this);
					});
					break;
				}

				// delete a group
				case "setup_delete_group":
				{
					$("a#delete_group_link").bind("click", function(){
						confirm(Exf._s.groups.actions.delete_question, function () {
							document.location = $("#delete_group_url").html();
						}, this);
					});
					break;
				}

				// setup accept friend request action
				case "setup_accept_friend_request":
				{
					$("a.link_accept_friend_request").bind("click", function(){
						userid = this.id.substring(27);
						//confirm("Are you sure?", function () {
							$.ajax({
								 type: "POST",
							   url: Exf.app_url + "ajax.profile-friends.inc.php",
							   data: "action=accept_request&user_id=" + userid,
				 				 dataType: 'json',
							   success: function(resp){
										window.location.href = window.location;
								 },
								error: function(msg){
									window.location.href = window.location;
								   }

							});
						//}, this);
					});
					break;
				}

				// setup reject friend request action
				case "setup_reject_friend_request":
				{
					$("a.link_reject_friend_request").bind("click", function(){
						userid = this.id.substring(27);
						//confirm("Are you sure?", function () {
							$.ajax({
								 type: "POST",
							   url: Exf.app_url + "ajax.profile-friends.inc.php",
							   data: "action=reject_request&user_id=" + userid,
				 				 dataType: 'json',
							   success: function(resp){
									if (resp.status == 1)
									{
										window.location.href = window.location;
									}
								 }
							});
						//}, this);
					});
					break;
				}

				// setup accept group invite
				case "setup_accept_group_invite":
				{
					$("a.link_accept_group_invite").bind("click", function(){
						group_id = this.id.substring(25);
						$.ajax({
							type: "POST",
							url: Exf.app_url + "ajax.groups.inc.php",
							data: "action=accept_invite&group_id=" + group_id,
							dataType: 'json',
							success: function(resp){
								window.location.href = window.location;
							}
						});
					});
					break;

				} // case "setup_accept_group_invite"

				// setup ignore group invite
				case "setup_ignore_group_invite":
				{
					$("a.link_ignore_group_invite").bind("click", function(){
						group_id = this.id.substring(25);
						$.ajax({
							type: "POST",
							url: Exf.app_url + "ajax.groups.inc.php",
							data: "action=ignore_invite&group_id=" + group_id,
							dataType: 'json',
							success: function(resp){
								window.location.href = window.location;
							}
						});
					});
					break;

				} // case "setup_ignore_group_invite"

				// setup accept group request
				case "setup_accept_group_request":
				{
					$("a.link_accept_group_request").bind("click", function(){
						str = this.id.substring(26);
						arr = str.split('_');
						group_id = arr[0];
						user_id = arr[1];
						$.ajax({
							type: "POST",
							url: Exf.app_url + "ajax.groups.inc.php",
							data: "action=approve_request&group_id=" + group_id + "&userid=" + user_id,
							dataType: 'json',
							success: function(resp){
								window.location.href = window.location;
							}
						});
					});
					break;

				} // case "setup_accept_group_request"

				// setup ignore group request
				case "setup_ignore_group_request":
				{
					$("a.link_ignore_group_request").bind("click", function(){
						str = this.id.substring(26);
						arr = str.split('_');
						group_id = arr[0];
						user_id = arr[1];
						$.ajax({
							type: "POST",
							url: Exf.app_url + "ajax.groups.inc.php",
							data: "action=deny_request&group_id=" + group_id + "&userid=" + user_id,
							dataType: 'json',
							success: function(resp){
								window.location.href = window.location;
							}
						});
					});
					break;

				} // case "setup_ignore_group_request"

				// setup remove friend action
				case "setup_remove_friend":
				{
					$("a.link_remove_friend").bind("click", function(){
						userid = this.id.substring(19);
						confirm("Are you sure?", function () {
							$.ajax({
								 type: "POST",
							   url: Exf.app_url + "ajax.profile-friends.inc.php",
							   data: "action=remove_friend&friend_id=" + userid,
				 				 dataType: 'json',
							   success: function(resp){
									if (resp.status == 1)
									{
										window.location.href = window.location;
									}
								 }
							});
						}, this);
					});
					break;
				}

				// delete a message thread
				case "del_msg":
					$(".msgItemMsg a.del_confirm_link").bind("click", function() {
						var url = $(this).attr("href");
						confirm(Exf._s.profile.message_del_alert, function() {
							window.location.href = url;
						}, this);
					});
					break;

				// popup the tease modal
				case "setup_tease":
					$("a#link_tease").bind("click", function(){
						open_modal("modal_tease", function () {
							var selected_teaserIid = $(".teasers_radios:checked").attr("id").split("_");
							$.ajax({
								 type: "GET",
							   url: Exf.app_url + "ajax.tease.inc.php",
							   data: "action=send_tease&user_id=" + $("#user_id").html() + "&tease_id=" + selected_teaserIid[1],
				 				 dataType: 'json',
							   success: function(resp){
								   if (resp.status == 1)
									 {
										 Exf.Gateway("display_notification", { msg: resp.msg, notification_type: "info" });
									 }
									 else
									 {
										 Exf.Gateway("display_notification", { msg: resp.msg, notification_type: "error" });
									 }
								 }
							});
						});
					});
					break;

				case "profile_top11_comment_form":
				{
					$('#form1 input#submit').click(function(e){
						
						var comm = $('#form1 textarea#comment');
						if (comm.val().length == 0)
						{
							e.preventDefault();
							comm.trigger('focus');
						}
						
					});
					break;
				}

				// remove warning/notification/alert message
				case "remove_warning":
				{
					// remove current warning
					var elem = params.elem;
					$(elem).parent().parent().remove();

					// if no more warnings, remove the container as well (css fix..)
					var warnings = $("#messages-container div.notification-message");
					if (warnings.length == 0)
					{
						$("#messages-container").hide();
					}

					if (params.type != "")
					{
						$.ajax({
								 type: "POST",
							   url: Exf.app_url + "ajax.remove-notifications.inc.php?type=" + params.type,
							   success: function(resp){
								 }
							});
					}
				}
				break;

				// check if confirm checkbox was ticked, then submit form. Else, display error
				case 'check_confirm_submit':
				{
					if (document.getElementById(params.confirm_id).checked)
					{
						return true;
					}
					else
					{
						$('#messages-container').show();
						return false;
					}
					break;
				}

				case 'report_abuse':
				{
					var hWnd = params.comment_wnd;
					$.ajax({
						 type: "POST",
					   url: Exf.app_url + "ajax.report_abuse.inc.php",
					   data: "link=" + params.link + "&reportee_id=" + params.reportee_id + "&message=" + $("#" + hWnd).val(),
					   success: function(resp){
							$("#" + params.comment_div).attr('style', 'display:none');
							Exf.Gateway("display_notification", { msg:  resp, notification_type: "info" });
							window.location.href = "#";
						}
					});
					break;
				}

				case 'forum_cite_reply':
				{
					$('#post-comment-form').show();
					var commented_text = ($("#comment_msg_" + params.comment_id).html() != "") ? $("#comment_msg_" + params.comment_id).html() : $("#comment_msg_" + params.comment_id).next().html();
					var comment_msg = "";
					comment_msg += "<strong>" + cite_by + " " + $("#comment_user_" + params.comment_id).html() + "</strong><br />";
					comment_msg += '<em>"' + commented_text + '"</em>';
					comment_msg += "<br />---<br />";
					tinyMCE.execCommand('mceInsertContent', false, comment_msg);
					$("#comment").val(comment_msg);
					break;
				}

				case 'validate_forum_comment_form':
				{
					tinyMCE.triggerSave();
					var comm = document.getElementById('comment').value;

					if (comm != '' && comm.length > 3)
					{
						$("form#post-comment-form input:submit").click(function (e) {
							//e.preventDefault();
						});
						//$("form#post-comment-form input:submit").attr("disabled", "true");
						$("form#post-comment-form input:submit").attr({value: Exf._s.profile.working});
						$("form#post-comment-form input:submit").addClass("thinking");
						return true;
					}
					else
					{
						return false;
					}
					break;
				}

			
				case 'get_nation_leagues':
				{
					current_box = params.box_id;
					//hide any other list open before
					$(".subList").hide('normal');

					//get the leagues for clicked nation (area_id)
					$.ajax({
						type: "POST",
						url: Exf.app_url + "ajax.manage_competitions.inc.php",
						data: 'action=get_nation_leagues&area_id='+params.area_id,
						success: function(resp){
							$("#"+current_box).html(resp);
							//$("#"+current_box).val(params.current_selected);
							$("select#"+current_box+" option[value='"+params.current_selected+"']").attr("selected", "selected");
							
							//$("#"+current_league_box).show("normal");
						}
					});
					
				}
				break;
				case 'enc_handle_player_current_club':
				{
					$("input#team_for_player_val").keyup(function (e) {
						switch (e.keyCode)
						{
							case 13:
								e.preventDefault();
							//	add_team_to_player();
								break;
							default:			
								add_team_to_player();
								break;
						}
					});
					function add_team_to_player()
					{
						var search_string = $("#team_for_player_val").val();		
						//hide results pane if there is a complete delete of input content AND reset hidden field of team id
						if(search_string.length == 0)
						{
							$('#team_for_player_id').val('');
							$("#team_for_player_form div.team_i_like_results").hide();
						}
						//limit the search to minimum 2 chars
						if(search_string.length > 1)
						{
							//start animation
							$("#team_for_player_anination").show();
							
							$.ajax({
								type: "POST",
								url: Exf.app_url + "ajax.get-clubs-by-kw.inc.php",
								data: "keywords=" + $("#team_for_player_val").val(),
								dataType: 'json',
								success: function(resp){
									//stop animation
									$("#team_for_player_anination").hide();
									if (resp.count > 0)
									{
										var teams = "";
										$.each(resp.teams, function() {
											teams += '<li><a class="team_for_player_result" href="javascript: void(0);" name="' + this.name + '" id="team_' + this.id + '">' + this.name + '</a> (' + this.note + ')</li>';
										});
										$("#team_for_player_form div.team_i_like_results div.found_results").show();
										$("#team_for_player_form div.team_i_like_results div.not_found_results").hide();
										$("#team_for_player_form div.team_i_like_results b.count").html(resp.count);
										$("#team_for_player_form div.team_i_like_results span").html(resp.message);
										$("#team_for_player_form div.team_i_like_results ul").html(teams);
	
										$("a.team_for_player_result").bind("click", function() {
											// add team to list
											var tmp = this.id.split("_");
											//populate the inputs in form with value (for visual efect) and with id (hidden input for real submit data)
											$('#team_for_player_val').val(this.name);
											$('#team_for_player_id').val(tmp[1]);
											
											//reset the result pane
											$("#team_for_player_form div.team_i_like_results").hide();
											//$("#team_i_like_add").show();
											$("#team_for_player_form div.team_i_like_results ul").html("");
										});
									}
									else
									{
										//clean the box from previous results
										$("#team_for_player_form div.team_i_like_results ul").html('');
										$("#team_for_player_form div.team_i_like_results .found_results").hide();
										$("#team_for_player_form div.team_i_like_results div.not_found_results").show();
									}
									$("#team_for_player_form .team_i_like_results").show();
									//$("#team_for_player_val").blur();
								}
							});
						}
					}	
				}
				break;
				
				case 'bets_search_team':
				{
					$("input#text_prediction_1").keyup(function (e) {
						switch (e.keyCode)
						{
							case 13:
								e.preventDefault();
							//	add_team_to_player();
								break;
							default:			
								lookup_team();
								break;
						}
					});
					function lookup_team()
					{
						var search_string = $("#text_prediction_1").val();		
						//hide results pane if there is a complete delete of input content AND reset hidden field of team id
						if(search_string.length == 0)
						{
							$('#team_for_player_id').val('');
							$("#team_for_player_form div.team_i_like_results").hide();
						}
						//limit the search to minimum 2 chars
						if(search_string.length > 1)
						{
							//start animation
							$("#team_for_player_anination").show();
							
							$.ajax({
								type: "POST",
								url: Exf.app_url + "ajax.get-clubs-by-kw.inc.php",
								data: "keywords=" + $("#team_for_player_val").val(),
								dataType: 'json',
								success: function(resp){
									//stop animation
									$("#team_for_player_anination").hide();
									if (resp.count > 0)
									{
										var teams = "";
										$.each(resp.teams, function() {
											teams += '<li><a class="team_for_player_result" href="javascript: void(0);" name="' + this.name + '" id="team_' + this.id + '">' + this.name + '</a> (' + this.note + ')</li>';
										});
										$("#team_for_player_form div.team_i_like_results div.found_results").show();
										$("#team_for_player_form div.team_i_like_results div.not_found_results").hide();
										$("#team_for_player_form div.team_i_like_results b.count").html(resp.count);
										$("#team_for_player_form div.team_i_like_results span").html(resp.message);
										$("#team_for_player_form div.team_i_like_results ul").html(teams);
	
										$("a.team_for_player_result").bind("click", function() {
											// add team to list
											var tmp = this.id.split("_");
											//populate the inputs in form with value (for visual efect) and with id (hidden input for real submit data)
											$('#team_for_player_val').val(this.name);
											$('#team_for_player_id').val(tmp[1]);
											
											//reset the result pane
											$("#team_for_player_form div.team_i_like_results").hide();
											//$("#team_i_like_add").show();
											$("#team_for_player_form div.team_i_like_results ul").html("");
										});
									}
									else
									{
										//clean the box from previous results
										$("#team_for_player_form div.team_i_like_results ul").html('');
										$("#team_for_player_form div.team_i_like_results .found_results").hide();
										$("#team_for_player_form div.team_i_like_results div.not_found_results").show();
									}
									$("#team_for_player_form .team_i_like_results").show();
									//$("#team_for_player_val").blur();
								}
							});
						}
					}
					break;	
				}
				//add team to input by autocomplete
				case 'enc_handle_team_in_team_awards':
				{
					//this var is to assign to it the ajax object that wil be created;
					var current_ajax = null;
					
					$("input[action='bring_team']").keyup(function (e) {
						
						if(current_ajax != null)
						{
							//if already exists an ajax object, abort and set null it to unblock the browser resources wating for ajax response;
							current_ajax.abort();
							current_ajax = null ;
						}
						
						switch (e.keyCode)
						{
							case 13:
								e.preventDefault();
								break;
							default:			
								add_team_to_team_award(this);
								break;
						}
					});
					function add_team_to_team_award(_this)
					{
						var input_id = $(_this).attr('id');
						var search_string = $("#"+input_id).val();
						//hide results pane if there is a complete delete of input content AND reset hidden field of team id
						if(search_string.length == 0)
						{
							$('#'+input_id).val('');
							$("#team_for_team_award_form div.team_i_like_results").hide();
						}
						//limit the search to minimum 2 chars
						if(search_string.length > 1)
						{
							//start animation
							$("#"+input_id+"_team_for_team_award").show();
							
							current_ajax = $.ajax({
								type: "POST",
								url: Exf.app_url + "ajax.get-clubs-by-kw.inc.php",
								data: "keywords=" + $('#'+input_id).val(),
								dataType: 'json',
								success: function(resp){
									//stop animation
									$("#"+input_id+"_team_for_team_award").hide();
									if (resp.count > 0)
									{
										var teams = "";
										$.each(resp.teams, function() {
											teams += '<li><a class="team_for_team_award_result" href="javascript: void(0);" name="' + this.name + '" id="team_' + this.id + '">' + this.name + '</a> (' + this.note + ')</li>';
										});
										$("#"+input_id+"_team_for_team_award_form div.team_i_like_results div.found_results").show();
										$("#"+input_id+"_team_for_team_award_form div.team_i_like_results div.not_found_results").hide();
										$("#"+input_id+"_team_for_team_award_form div.team_i_like_results b.count").html(resp.count);
										$("#"+input_id+"_team_for_team_award_form div.team_i_like_results span").html(resp.message);
										$("#"+input_id+"_team_for_team_award_form div.team_i_like_results ul").html(teams);
										
										//console.log($("div."+input_id+"_team_i_like_results"));
										$("a.team_for_team_award_result").bind("click", function() {
											// add team to list
											var tmp = this.id.split("_");
											//populate the inputs in form with value (for visual efect) and with id (hidden input for real submit data)
											$('#'+input_id).val(this.name);
											$("#"+input_id+"_new").val(tmp[1]);
											
											//reset the result pane
											$("#"+input_id+"_team_for_team_award_form div.team_i_like_results").hide();
											//$("#team_i_like_add").show();
											$("#"+input_id+"_team_for_team_award_form div.team_i_like_results ul").html("");
										});
									}
									else
									{
										//clean the box from previous results
										$("#"+input_id+"_team_for_team_award_form div.team_i_like_results ul").html('');
										$("#"+input_id+"_team_for_team_award_form div.team_i_like_results .found_results").hide();
										$("#"+input_id+"_team_for_team_award_form div.team_i_like_results div.not_found_results").show();
									}
									$("#"+input_id+"_team_for_team_award_form .team_i_like_results").show();
									//$("#team_for_player_val").blur();
								}
							});
						} 
					}
				}	
				break;

				case "add_item_to_player_profile":
				{
					var entity_param = '';	//used to send entity (most player) id to ajax
					var only_entity_id = '';	//used to send entity (most player) id to ajax in lower functions
					if(params.entity_id != undefined)
					{
						entity_param = "&entity_id="+params.entity_id;
						only_entity_id = params.entity_id;
					}
					
					//different html contructions of inputs or selects used on edit profiles (players and others)
					$.ajax({
						type: "POST",
						url: Exf.app_url + "ajax.get_player_profile_items.inc.php",
						data: 'type='+params.item_type+entity_param,
						success: function(resp){
							$("#"+params.box).append(resp);
							//console.log(params.item_type);
							//if is about team_award (palmares colectiff) form of player update, then activate trigers for just appended inputs
							if(params.item_type == 'team_award')
							{
								Exf.Gateway("enc_handle_team_in_team_awards", {});
								$("select[hiper]").bind("change",function(){
									Exf.Gateway('add_restricted_years_by_competition',{item:this, 'entity':only_entity_id});
								});
							}
							if(params.item_type == 'player_history')
							{
								//associate actions for adding team to input by autocomplete for newly added input
								Exf.Gateway("enc_handle_team_in_team_awards", {});
								//set content restriction for inputs
								$("input[restricted='number']").numeric(Exf._s.profile.separators.decimal);
							}
						}
					});
				}
				break;
				case "add_restricted_years_by_competition":
				{
					var brut_id = $(params.item).attr('brut_id');
					var item_type = $(params.item).attr('value');
					var entity_id = params.entity;
					//extract the list of
					if(item_type != '')
					{
						//console.log(entity_id);
						$.ajax({
							type: "POST",
							url: Exf.app_url + "ajax.get_filtered_years_lists.inc.php",
							data: 'type='+item_type+"&entity="+entity_id,
							success: function(resp)
							{
								
								$("#new_award_year_"+brut_id).html(resp);
							}
						});
					}
					else
					{
						$("#new_award_year_"+brut_id).html('');
					}
				}
				break;
				
				case "format_numbers_with_separators":
				{
					function NumberSeparatorsFormat(n,swap)
					{
						var ts=",", ds="."; // thousands and decimal separators
						if (swap == ",") { ts="."; ds=","; } // swap if requested
						
						var ns = String(n),ps=ns,ss=""; // numString, prefixString, suffixString
						var i = ns.indexOf(ds);
						if (i!=-1) { // if ".", then split:
						ps = ns.substring(0,i);
						ss = ds+ns.substring(i+1);
						
						}
						return ps.replace(/(\d)(?=(\d{3})+([.]|$))/g,"$1"+ts)+ss;
					}
					//set format
					//might be problems on decimals entered numbers
					$("input[restricted='number']").bind("blur",function(){
						var nr = Number($(this).val());
						if(nr)
						{
							$(this).val(NumberSeparatorsFormat(nr, Exf._s.profile.separators.decimal));
						}
					});
					
					$("input[restricted='number']").bind("focus",function(){
						
						var nr = $(this).val();
						var pattern = new RegExp("\\"+Exf._s.profile.separators.thousand +"+","g");
						
						$(this).val(nr.replace(pattern,''));
						/** /,+/g **/
					});
				}	
				break;
				
				case 'add_country_to_input':
				{
					var item_type = params.input_name;
					$("input#"+item_type+"_val").keyup(function (e) {
						if(e.keyCode == 13)
						{
							e.preventDefault();
						}
							
						var search_string = $("#"+item_type+"_val").val();		
						//hide results pane if there is a complete delete of input content AND reset hidden field of team id
						if(search_string.length == 0)
						{
							$('#'+item_type+'_id').val('');
							$("#"+item_type+"_form div.team_i_like_results").hide();
						}
						//limit the search to minimum 1 char
						if(search_string.length > 0)
						{
							//start animation
							$("#"+item_type+"_anination").show();
							
							$.ajax({
								type: "POST",
								url: Exf.app_url + "ajax.encyclopedia_get_country_names_2.inc.php",
								data: "keywords=" + $("#"+item_type+"_val").val(),
								dataType: 'json',
								success: function(resp){
									//stop animation
									$("#"+item_type+"_anination").hide();
									
									if (resp.count > 0)
									{
										var teams = "";
										$.each(resp.teams, function() {
											teams += '<li><a class="'+item_type+'_result" href="javascript: void(0);" name="' + this.alternate_name + '" id="competition__' + this.area_id + '">' + this.alternate_name + '</a></li>';
										});
										$("#"+item_type+"_form div.team_i_like_results div.found_results").show();
										$("#"+item_type+"_form div.team_i_like_results div.not_found_results").hide();
										$("#"+item_type+"_form div.team_i_like_results b.count").html(resp.count);
										$("#"+item_type+"_form div.team_i_like_results span").html(resp.message);
										$("#"+item_type+"_form div.team_i_like_results ul").html(teams);
	
										$("a."+item_type+"_result").bind("click", function() {
											// add team to list
											var tmp = this.id.split("__");
											//populate the inputs in form with value (for visual efect) and with id (hidden input for real submit data)
											$('#'+item_type+'_val').val(this.name);
											$('#'+item_type+'_id').val(tmp[1]);
											//$('#'+item_type+'country_id').val(this.id);
											
											//reset the result pane
											$("#"+item_type+"_form div.team_i_like_results").hide();
											//$("#team_i_like_add").show();
											$("#"+item_type+"_form div.team_i_like_results ul").html("");
											
											//if the input completed with county name/id has a 'league' attribute, then there must be complete an selection with related competitions
											if($('#'+item_type+'_val').attr('league') == 'yes')
											{
												var area_id = $('#'+item_type+'_id').val();
												var current_selected = $("#competition_id").val();
												
												Exf.Gateway('get_nation_leagues',{'area_id':area_id,'box_id':'competition_id','current_selected':current_selected});
											}
										});
									}
									else
									{
										//clean the box from previous results
										$("#"+item_type+"_form div.team_i_like_results ul").html('');
										$("#"+item_type+"_form div.team_i_like_results .found_results").hide();
										$("#"+item_type+"_form div.team_i_like_results div.not_found_results").show();
									}
									$("#"+item_type+"_form .team_i_like_results").show();
									//$("#team_for_player_val").blur();
								}
							});
						}
					});
				}
				break;
				case 'add_competition_to_input':
				{
					var item_type = params.input_name;
					//this var is to assign to it the ajax object that wil be created;
					var current_ajax = null;
					
					$("input#"+item_type+"_val").keyup(function (e) {
						if(e.keyCode == 13)
						{
							e.preventDefault();
						}
						if(current_ajax != null)
						{
							//if already exists an ajax object, abort and set null it to unblock the browser resources wating for ajax response;
							current_ajax.abort();
							current_ajax = null ;
						}
						var search_string = $("#"+item_type+"_val").val();		
						//hide results pane if there is a complete delete of input content AND reset hidden field of team id
						if(search_string.length == 0)
						{
							$('#'+item_type+'_id').val('');
							$("#"+item_type+"_form div.team_i_like_results").hide();
						}
						//limit the search to minimum 1 char
						if(search_string.length > 0)
						{
							//animation start
							$("#"+item_type+"_anination").show();
							
						current_ajax = $.ajax({
								type: "POST",
								url: Exf.app_url + "ajax.encyclopedia_get_competions_names.inc.php",
								data: "keywords=" + $("#"+item_type+"_val").val(),
								dataType: 'json',
								success: function(resp){
									//animation stop
									$("#"+item_type+"_anination").hide();
									
									if (resp.count > 0)
									{
										var teams = "";
										$.each(resp.teams, function() {
											teams += '<li><a class="'+item_type+'_result" href="javascript: void(0);" name="' + this.name + '" id="competition__' + this.competition_id + '">' + this.name + '</a> (' + this.country + ') </li>';
										});
										$("#"+item_type+"_form div.team_i_like_results div.found_results").show();
										$("#"+item_type+"_form div.team_i_like_results div.not_found_results").hide();
										$("#"+item_type+"_form div.team_i_like_results b.count").html(resp.count);
										$("#"+item_type+"_form div.team_i_like_results span").html(resp.message);
										$("#"+item_type+"_form div.team_i_like_results ul").html(teams);
	
										$("a."+item_type+"_result").bind("click", function() {
											// add team to list
											var tmp = this.id.split("__");
											//populate the inputs in form with value (for visual efect) and with id (hidden input for real submit data)
											$('#'+item_type+'_val').val(this.name);
											$('#'+item_type+'_id').val(tmp[1]);
											//$('#'+item_type+'country_id').val(this.id);
											
											//reset the result pane
											$("#"+item_type+"_form div.team_i_like_results").hide();
											//$("#team_i_like_add").show();
											$("#"+item_type+"_form div.team_i_like_results ul").html("");
										});
									}
									else
									{
										//clean the box from previous results
										$("#"+item_type+"_form div.team_i_like_results ul").html('');
										$("#"+item_type+"_form div.team_i_like_results .found_results").hide();
										$("#"+item_type+"_form div.team_i_like_results div.not_found_results").show();
									}
									$("#"+item_type+"_form .team_i_like_results").show();
									//$("#team_for_player_val").blur();
								}
							});
						}
					});
				}
				break;
				case "add_item_to_club_profile":
				{
					//different html contructions of inputs or selects used on edit profiles (players and others)
					$.ajax({
						type: "POST",
						url: Exf.app_url + "ajax.get_club_profile_items.inc.php",
						data: 'type='+params.item_type,
						success: function(resp){
							$("#"+params.box).append(resp);
							
							//if is about team_award (palmares colectiff) form of player update, then activate trigers for just appended inputs
							if(params.item_type == 'assitent_coach')
							{
								//remove the initial text and the attibute is used as flag; also, change the text color css
								$("input[myattribute]").focus(function(){
									if($(this).attr('myattribute') == "first")
									{
										$(this).val('');
										$(this).css('color','#333333');
										$(this).attr('myattribute','second');
									}
								});
								
								$("input[myattribute]").blur(function(){
									if($(this).val() == '')
									{
										$(this).attr('myattribute','first');
										$(this).css('color','#999999');
										$(this).val($(this).attr('default_val'));
									}
								});
							}
 						}
					});
				}
				break;
				case 'enc_handle_player_to_national_team':
				{	
					//this var is to assign to it the ajax object that wil be created;
					var current_ajax = null;
					
					$("input[action='bring_player']").keyup(function (e) {
						if(current_ajax != null)
						{
							//if already exists an ajax object, abort and set null it to unblock the browser resources wating for ajax response;
							current_ajax.abort();
							current_ajax = null ;
						}
						
						switch (e.keyCode)
						{
							case 13:
								e.preventDefault();
								break;
							default:			
								add_player_to_national_team($(this));
								break;
						}
					});
					function add_player_to_national_team(_this)
					{
						var input_id = $(_this).attr('id');
						var search_string = $("#"+input_id).val();
						
						//hide results pane if there is a complete delete of input content AND reset hidden field of team id
						if(search_string.length == 0)
						{
							$('#'+input_id).val('');
						}
						if(search_string.length < 3)
						{
							$("#"+input_id+"_form div.team_i_like_results").hide();
							//start animation
							$("#"+input_id+"_animation").hide();
						}
						//limit the search to minimum 2 chars
						if(search_string.length > 2)
						{
							//start animation
							$("#"+input_id+"_animation").show();
							
							current_ajax = $.ajax({
								type: "POST",
								url: Exf.app_url + "ajax.encyclopedia_get_players.inc.php",
								data: "keywords=" + search_string,
								dataType: 'json',
								success: function(resp){
									//stop animation
									$("#"+input_id+"_animation").hide();
									if (resp.count > 0)
									{
										var teams = "";
										$.each(resp.teams, function() {
											teams += '<li><a class="player_for_team_result" href="javascript: void(0);" name="' + this.name + '" id="player_' + this.player_id + '">' + this.name + '</a> (' + this.country + ')</li>';
										});
										$("#"+input_id+"_form div.team_i_like_results div.found_results").show();
										$("#"+input_id+"_form div.team_i_like_results div.not_found_results").hide();
										$("#"+input_id+"_form div.team_i_like_results b.count").html(resp.count);
										$("#"+input_id+"_form div.team_i_like_results span").html(resp.message);
										$("#"+input_id+"_form div.team_i_like_results ul").html(teams);
										
										//console.log($("div."+input_id+"_team_i_like_results"));
										$("a.player_for_team_result").bind("click", function() {
											// add team to list
											var tmp = this.id.split("_");
											//populate the inputs in form with value (for visual efect) and with id (hidden input for real submit data)
											$('#'+input_id).val(this.name);
											$("#"+input_id+"_new").val(tmp[1]);
											//reset the result pane
											$("#"+input_id+"_form div.team_i_like_results").hide();
											//$("#team_i_like_add").show();
											$("#"+input_id+"_form div.team_i_like_results ul").html("");
										});
									}
									else
									{
										//clean the box from previous results
										$("#"+input_id+"_form div.team_i_like_results ul").html('');
										$("#"+input_id+"_form div.team_i_like_results .found_results").hide();
										$("#"+input_id+"_form div.team_i_like_results div.not_found_results").show();
									}
									$("#"+input_id+"_form .team_i_like_results").show();
									//$("#team_for_player_val").blur();
								}
							});
						} 
					}
				}	
				break;
				case "add_item_to_national_team_profile":
				{
					//different html contructions of inputs or selects used on edit profiles (players and others)
					$.ajax({
						type: "POST",
						url: Exf.app_url + "ajax.get_national_team_profile_items.inc.php",
						data: 'type='+params.item_type,
						success: function(resp){
							$("#"+params.box).append(resp);
							
							//if is about team_award (palmares colectiff) form of player update, then activate trigers for just appended inputs
							if(params.item_type == 'player')
							{
								//update player in national team
								Exf.Gateway("enc_handle_player_to_national_team", {});
								//set action for remover buttons of existing players
								$("img[remover]").bind("click", function(){$('#'+$(this).attr("remover")).remove();})
								
								//remove the initial text and the attibute is used as flag; also, change the text color css
								$("input[myattribute]").focus(function(){
									if($(this).attr('myattribute') == "first")
									{
										$(this).val('');
										$(this).css('color','#333333');
										$(this).attr('myattribute','second');
									}
								});
								
								$("input[myattribute]").blur(function(){
									if($(this).val() == '')
									{
										$(this).attr('myattribute','first');
										$(this).css('color','#999999');
										$(this).val($(this).attr('default_val'));
									}
								});
							}
 						}
					});
				}
				break;
				case 'enc_handle_clubs_to_national_competition':
				{
					//this var is to assign to it the ajax object that wil be created;
					var current_ajax = null;
					
					$("input[action]").keyup(function (e) {
						if(current_ajax != null)
						{
							//if already exists an ajax object, abort and set null it to unblock the browser resources wating for ajax response;
							current_ajax.abort();
							current_ajax = null ;
						}
						//console.log(current_ajax+'_____________');	
						switch (e.keyCode)
						{
							case 13:
								e.preventDefault();
								break;
							default:			
								add_club_to_national_competition(this);
								break;
						}
					});
					function add_club_to_national_competition(_this)
					{
						var input_id = $(_this).attr('id');
						var search_string = $("#"+input_id).val();
						
						//hide results pane if there is a complete delete of input content AND reset hidden field of team id
						if(search_string.length == 0)
						{
							$('#'+input_id).val('');
						}
						//limit the showing the list of results if the search string is 3 chars or less
						if(search_string.length < 3)
						{
							$("#"+input_id+"_form div.team_i_like_results").hide();
						}
						//limit the search to minimum 2 chars
						if(search_string.length > 2)
						{
							//start animation
							$("#"+input_id+"_animation").show();
							
							current_ajax = $.ajax({
								type: "POST",
								url: Exf.app_url + "ajax.get-clubs-by-kw.inc.php",
								data: "keywords=" + search_string,
								dataType: 'json',
								success: function(resp){
									//stop animation
									$("#"+input_id+"_animation").hide();
									
									if (resp.count > 0)
									{
										var teams = "";
										$.each(resp.teams, function() {
											teams += '<li><a class="player_for_team_result" href="javascript: void(0);" name="' + this.name + '" id="team_' + this.id + '">' + this.name + '</a> (' + this.note + ')</li>';
										});
										$("#"+input_id+"_form div.team_i_like_results div.found_results").show();
										$("#"+input_id+"_form div.team_i_like_results div.not_found_results").hide();
										$("#"+input_id+"_form div.team_i_like_results b.count").html(resp.count);
										$("#"+input_id+"_form div.team_i_like_results span").html(resp.message);
										$("#"+input_id+"_form div.team_i_like_results ul").html(teams);
										
										//console.log($("div."+input_id+"_team_i_like_results"));
										$("a.player_for_team_result").bind("click", function() {
											// add team to list
											var tmp = this.id.split("_");
											//populate the inputs in form with value (for visual efect) and with id (hidden input for real submit data)
											$('#'+input_id).val(this.name);
											$("#"+input_id+"_new").val(tmp[1]);
											//reset the result pane
											$("#"+input_id+"_form div.team_i_like_results").hide();
											//$("#team_i_like_add").show();
											$("#"+input_id+"_form div.team_i_like_results ul").html("");
										});
									}
									else
									{
										//clean the box from previous results
										$("#"+input_id+"_form div.team_i_like_results ul").html('');
										$("#"+input_id+"_form div.team_i_like_results .found_results").hide();
										$("#"+input_id+"_form div.team_i_like_results div.not_found_results").show();
									}
									$("#"+input_id+"_form .team_i_like_results").show();
									//$("#team_for_player_val").blur();
								}
							});
						} 
					}
				}	
				break;
				case "add_item_to_competition_profile":
				{
					//different html contructions of inputs or selects used on edit profiles (players and others)
					$.ajax({
						type: "POST",
						url: Exf.app_url + "ajax.get_competition_profile_items.inc.php",
						data: {'type' : params.item_type, 'competition_id' : params.competition_id},
						success: function(resp){
							$("#"+params.box).append(resp);
							
							//if is about team_award (palmares colectiff) form of player update, then activate trigers for just appended inputs
							if(params.item_type == 'club')
							{
								//update player in national team
								Exf.Gateway("enc_handle_clubs_to_national_competition", {});
								//set action for remover buttons of existing clubs
								$("img[remover]").bind("click", function(){$('#'+$(this).attr("remover")).remove();})
							}
							
							//case of clubs for champion and second place
							if(params.item_type == 'club_winners')
							{
								//update player to current national team
								Exf.Gateway("enc_handle_clubs_to_national_competition", {});
							}
							
							//update players to national competiton's strikers list
							if(params.item_type == 'strikers')
							{
								//update player to current list of competition strikers
								Exf.Gateway("enc_handle_player_to_national_team", {});
						
								//update player's club where was/is best striker
								Exf.Gateway("enc_handle_team_in_team_awards", {});
							}
 						}
					});
				}
				break;
				case "default_input_behavior":
				{
					//control the behavior of default text inside inputs;
						$("#" + params.item_id).focus(function() {
							if($("#" + params.item_id).attr('myattribute') == 'first')
							{
								$("#" + params.item_id).attr('myattribute','second');
								$("#" + params.item_id).css('color','#333333');
								$("#" + params.item_id).val('');
							}
						});
						$("#" + params.item_id).blur(function(){
							if($("#" + params.item_id).val() == '')
							{
								$("#" + params.item_id).attr('myattribute','first');
								$("#" + params.item_id).css('color','#999999');
								$("#" + params.item_id).val($("#" + params.item_id).attr('default_val'));
							}
						});
				}
				break;
				
				case "record_vote":
				{
					$("#score").text("ASD");
					$.ajax({
						type: "POST",
						url: Exf.app_url + "ajax.register_vote.inc.php",
						data: {'vote_id' : params.vote_id, 'score' : params.score},
						success: function(resp)
						{
							$("#score").text('core');
 						}
					});
					break;
				}
				
				case "bets_verify_predictions":
				{
					var error = false;
					if ($("#i_1_new").val() == '')
					{
						error = true;
						$("#i_1").addClass("redHighlight");
					}
					if ($("#i_2_new").val() == '')
					{
						error = true;
						$("#i_2").addClass("redHighlight");
					}
					if ($("#p_3_new").val() == '')
					{
						error = true;
						$("#p_3").addClass("redHighlight");
					}
					return !error;
				}
				
				
				case "bets_cl_verify_bets":
				{
					var error = false;
					
					var bet_count = $("#match_count").val();
					
					for (var i = 0;i < bet_count;i++)
					{
						$('#bet_1_' + i).removeClass('redHighlight');
						$('#bet_X_' + i).removeClass('redHighlight');
						$('#bet_2_' + i).removeClass('redHighlight');
						$('#scoreA_' + i).removeClass('redHighlight');
						$('#scoreB_' + i).removeClass('redHighlight');
					
						var input_name = 'bet_' + i;
						if ($('input[name=' + input_name + ']:checked').val() == undefined)
						{
							error = true;
							$('#bet_1_' + i).addClass('redHighlight');
							$('#bet_X_' + i).addClass('redHighlight');
							$('#bet_2_' + i).addClass('redHighlight');
						}
						
						if ($('#scoreA_' + i).val() == '')
						{
							error = true;
							$('#scoreA_' + i).addClass('redHighlight');
						}
						
						if ($('#scoreB_' + i).val() == '')
						{
							error = true;
							$('#scoreB_' + i).addClass('redHighlight');
						}
					}
					
					return !error;
				}
				default:
				break;
			}
		}
	}
})();
