var interval = 0;
var no_rrr = 0;

function LoadGames(rrr)
{
	document.getElementById('loadgames').innerHTML = interval + '%';
	document.getElementById('loadgames_gif').style.width = interval + '%';
	interval++;
	if (interval > rrr && no_rrr == 0) { document.getElementById('clickyes').innerHTML = '<font onClick="OpenGames();" style="font-size: 8pt; cursor: pointer; text-decoration: underline; color: #094da1;">Игра загружена. Кликните здесь, чтобы начать игру</font>'; no_rrr = 1; }
	if (interval > 100) { OpenGames(); };
	return;     
}

function OpenGames()
{
	$('#game_reclama').css('display', 'none');
	$('#game_reclama_upload').css('display', 'none');
	$('#swfgame_o').attr('width', 728);
	$('#swfgame_o').attr('height', 588);
	
	$('#swfgame_e').attr('width', 728);
	$('#swfgame_e').attr('height', 588);
}


/* Проверка капчи */
function CapchaVerify()
{
	var code_capcha = $('input[name=code_download]').val();
	if (code_capcha == undefined || code_capcha == '')
	{
		alert('Введите код с картинки!');
		return;
	}
	$.post('modules/verifyC.php', { zapros : code_capcha },
	function(data) 
	{
		if (data)
		{
			DownloadLink();
		}
		else
		{
			alert('Не верный код!');
			return;
		}
	});
}

/* Счетчик перед ссылкой для закачки игры */
function DownloadLink()
{
	clearInterval(time);
	code_capcha = $('input[name=code_download]').val();
	
	$('#game_reclama').css('display', 'block');
	$('#game_reclama_upload').css('display', 'none');
	$('#form_down_code').css('display', 'none');
	$('#swfgame_o').attr('width', 2);
	$('#swfgame_o').attr('height', 2);
	$('#swfgame_e').attr('width', 2);
	$('#swfgame_e').attr('height', 2);
	
	$('#game_upload_counter').css('display', 'block');

	DLtime = 15;
	$('#game_counter_time').text(DLtime);
               
	var count = setInterval (
		function()
		{
			DLtime--;
			$('#game_counter_time').text(DLtime);
			if (DLtime < 1)
			{
				clearInterval(count);
				DownloadOpenLink();
			}
		}, 1000
	);
}

/* Открытие ссылок закачки */
function DownloadOpenLink()
{
	$('#form_down_code').css('display', 'none');
	$('#game_reclama').css('display', 'none');
	$('#game_reclama_upload').css('display', 'none');
	$('#game_upload_counter').css('display', 'none');
	$('#game_upload_link').css('display', 'block');
}

/* Возвращение к игре */
function ReturnGame()
{
	$('#form_down_code').css('display', 'none');
	$('#game_reclama').css('display', 'none');
	$('#game_reclama_upload').css('display', 'none');
	$('#game_upload_counter').css('display', 'none');
	$('#game_upload_link').css('display', 'none');
	$('#swfgame_o').attr('width', wx);
	$('#swfgame_o').attr('height', hx);
	$('#swfgame_e').attr('width', wx);
	$('#swfgame_e').attr('height', hx);
}

function OpenCapcha()
{
	if (document.getElementById('form_down_code').style.display != 'block')
	{
		$('input[name=code_download]').val('');
		document.getElementById('form_down_img').src = 'image_ca.php?'+Math.random();
		$('#form_down_code').css('display', 'block');
	}
	else
	{
		$('#form_down_code').css('display', 'none');
	}
}


/* Звездочки - при наведении */
function pic(nam, but, pred)
{
	if(but)
	{
		pred1 = Math.floor(pred);
		pred2 = (pred - pred1) * 10;
		for (var i = 1; i <= pred1; i++)
		{
			document.images['b' + i].src = '/pics/sb1.gif';
		}
		pred3 = pred1;
		if (pred2 > 3 && pred2 < 9) { pred3++; document.images['b' + pred3].src = '/pics/sb2.gif'; }
		if (pred2 == 9) { pred3++; document.images['b' + pred3].src = '/pics/sb2.gif'; }
		
		for (var i = (pred3+1); i <= 5; i++)
		{
			document.images['b' + i].src = '/pics/sb3.gif';
		}
	}
	else
	{
		eee = parseInt(nam.substr(1,1));
		for (var i = 1; i <= 5; i++)
		{
			if (eee >= i) { document.images['b' + i].src = '/pics/sb1.gif'; } else { document.images['b' + i].src = '/pics/sb3.gif'; }
		}
	} 
}


/* Звездочки - запрос на добавление */
function AddStars(id, bal)
{
	$.post('modules/bal.php', { game : id, estimation : bal },
	function(data) 
	{
		if (data)
		{
			$('#z_result_ok').html('<font style="font-size: 12pt;">Спасибо! &nbsp;</font>');
			$('#z_result').html(data);
			return;
		}
		else
		{
			return;
		}
	});
}

/** Обратная связь **/
  sndm = {
          verify : function()
		  {
               
               if(this.name() && this.email() && this.text() && this.codef())
               {
				   var qrec = { zapros : this.code };
                    capcha.query('verifyC', qrec, this.result);
               }
          
          },
          
          name : function()
		  {
               var name = $('input[name=send_name]').val();
               if(name !== undefined && name == '')
			   {
				   alert('Введите свое имя!');
                    return false;
			   }
               return true;
          },
          
          email : function()
		  {
               var email = $('input[name=send_email]').val();
               
               if(email !== undefined && email == '')
			   {
				   alert('Введите свой e-mail!');
                    return false;
			   }
                    
               if(!email.match(/^[A-Za-z0-9\.\_]{1,32}\@[A-Za-z0-9\.\_]{1,32}\.[a-zA-Z]{2,6}$/))
			   {
				   alert('Неверный e-mail!');
                    return false;
			   }
               
               return true;
          },
          
          text : function()
		  {
               var text = $('textarea[name=send_text]').val();
               
               if(text !== undefined && text == '')
			   {
				   alert('Введите текст письма!');
                    return false;
			   }
                    
               return true;
          },
          
          codef : function()
		  {
               this.code = $('input[name=send_code]').val();
               
               if(this.code !== undefined && this.code == '')
			   {
				   alert('Введите код с картинки!');
                    return false;
			   }
               
               return true;
          },
          
          result : function(data)
		  {
               if(data) document.forms.formsend.submit(); else alert('Неверный защитный код!');
          
          }
     }

     capcha = {
          query : function(uri, req, func_ret)
          {
               $.post(
                    'modules/' + uri + '.php',
                 	req ,
                    function(data)
                    {
						
                         if(data)
                             func_ret(data);
                              else
                                   func_ret(false);
                         
                    }          
               )
          }
     }
	 
function perecl(id)
{
	if (id == 1)	
	{
		$('#podobn_l').attr('class', 'pod_posl_nl');
		$('#posl_sgam_l').attr('class', 'pod_posl_l');
		$('#podobn').css('display', 'block');
		$('#posl_sgam').css('display', 'none');
	}
	else
	{
		$('#podobn_l').attr('class', 'pod_posl_l');
		$('#posl_sgam_l').attr('class', 'pod_posl_nl');
		$('#podobn').css('display', 'none');
		$('#posl_sgam').css('display', 'block');
	}
}

function bookmarksite(title,url)
{
	if (navigator.appName === "Microsoft Internet Explorer")
		window.external.AddFavorite(url, title);
	else
		if(window.opera && window.print)
		{
			// Opera Browser
			var elem = document.createElement('a');
			elem.setAttribute('href',url);
			elem.setAttribute('title',title);
			elem.setAttribute('rel','sidebar');
			elem.click();
		}
		else
		{ // Other Browsers
			window.sidebar.addPanel(title, url, "");
		}
}

function preload(images)
{
	if (typeof document.body == "undefined") return;  
	try {  
			var div = document.createElement("div");  
			var s = div.style;  
			s.position = "absolute";  
			s.top = s.left = 0;  
			s.visibility = "hidden";  
			document.body.appendChild(div);
			div.innerHTML = "<img src=\"" + images.join("\" /><img src=\"") + "\" />";
			var lastImg = div.lastChild;  
			lastImg.onload = function() { document.body.removeChild(document.body.lastChild); };  
		}  
		catch(e) {  
	}
} 
	
function top_view_img(id, title, divid)
{
	document.getElementById(divid).src = 'http://i.0game.ru/gamesimg/' + id + '.jpg';
	document.getElementById(divid).title = 'Игра ' + title;
	document.getElementById(divid + '_link').href = 'game/' + id + '/';
}

function iban(ident, id)
{
	$.post( 'statistics.php', { 'ident' : ident, 'idbanner' : id } )
}

function dwg(id)
{
	$.post( 'downgame.php', { 'id' : id } )
}

