function Toggle_worlds(id, focus) {
	if ($('#' + id).css("display") == "none") {
		$('.hidden-div').slideUp();
		$('#' + id).slideDown(function()
		{
			$('.' + focus).focus();
		});
	}
	else
		$('.hidden-div').slideUp();
}

function Toggle(id) {
	if ($('#' + id).css("display") == "none") {
		$('.hidden-element').hide();
		$('#' + id).show();
	}
	else
		$('.hidden-div').hide();
}

function msg_limit(obj, limit, counterId) {
	if (counterId == 'undefined' || !counterId) {
		counterId = 'count';
	}
	if (obj.value.length > limit) {
	  obj.value = obj.value.substr(0,limit);
	}
	$('#' + counterId).html(limit - obj.value.length);
}

function awardgroups(val, selection) {
	val = val || 1;
	selection = selection || false;
	request = $.ajax({
		url : "ajax/award_select.php?game_id="+val,
		complete : function() {
			if (request.readyState == 4) {
				if (request.status == 200) {
					// JSON objektiks
					var vastused = eval(request.responseText);
					// kustutan igaks juhuks kõik optionid
					var dd = document.getElementById('ag_group');
					if(val!=0) {
						try {dd.hasAttribute("disabled") ? dd.removeAttribute("disabled") : void(0);}catch(e){}
						dd.disabled = false;
					}
					else {
						try {dd.setAttribute("disabled", true);}catch(e){}
						dd.disabled = true;
					}
					for (i = 0; i < dd.length; i++) {
						dd.remove(i);
					}
					// ja täidan nad uutega
					for (r = 0; r < vastused.length; r++) {
						var opt = new Option;
						vs = vastused[r].split("|");
						opt.value = vs[0];
						opt.text = vs[1];
						if (r == 0) {
							opt.selected = true;
						}
						dd.options[r] = opt;
					}
					// WO
					if(selection) {
						var ag_group = document.getElementById('ag_group'), x = 0;

						while(x < ag_group.length) {
							if(ag_group.options[x].value == selection) {
								document.getElementById("ag_group").selectedIndex = x;
								break;
							}
							x++;
						}
					}
				}
				request = new Object();
			}
		}
	});
}

$(document).ready(function() {
	langCheck = function(e) {
		var si = e.selectedIndex;
		var sopt = e.options[si];
		var a = $(sopt).attr('multilang');
		if(a == 1)
			$('#country-container').slideDown(100);
		else
			$('#country-container').slideUp(100);

	}
});
