
function documentReady() {
	var options = {
		beforeSubmit: showRequest,
		success: showResponse,
		dataType: 'json',
		timeout: 3000
	};
	$('#form_comment').submit(function() {
		$(this).ajaxSubmit(options);
		return false;
	});
}

// вызов перед передачей данных
function showRequest(formData, jqForm, options) { 
    return true; 
}

// вызов после получения ответа 
function showResponse(data, statusText) { 
	var d = new Date();
	$("#captcha_img").attr("src", '/captcha?val='+d.getTime());
	if(data) {
		if(typeof(data.err) !='undefined' && typeof(data.str) !='undefined') {
			if(data.err == true) {
				$('#block_comment_output').html(data.str);
			}
			else {
				$('#form_comment').resetForm();
				$('#block_comment_output').html(data.str);
			}
		}
	}
}

function ClearMyGames() {
	document.cookie = 'my_games=; expires=Thu, 01-Jan-70 00:00:01 GMT; path=/; domain=.igry.ru';
}

function searchClear(obj) {
	if(obj.value == obj.defaultValue) {
		obj.value = '';
		obj.style.color = '#000';
	}
}

function searchBlur(obj) {
	if(obj.value == '') {
		obj.value = obj.defaultValue;
		obj.style.color = '#888';
	}
}

function commentPage(type, id, page) {
	$("#play_comments").load("/comment/comments/"+type+"/"+id+"/"+page);
}

function rate_onlike(obj_type, obj_id, act)
{
	$.post('/rate/submit', {obj_type: obj_type, obj_id: obj_id, action: act}, function(data)
	{
		if(typeof(data.count) !='undefined' && typeof(data.rate) !='undefined')
		{
			$('#block_rating_rate').html(data.rate);
			$('#block_rating_count').html(data.count);
			$('#block_rating_form').html('Вы уже проголосовали');
		}
	}, "json");
}

function toggleLayer(layerId) {
	$(layerId).toggle();
}

function get_game_embed(div_id, game_id, checknum)
{
	$.post('/common/get_game_embed', {id: game_id, check: checknum}, function(data)
	{
		$(div_id).html(data);
	}, "html");
}

