/** Download Game **/

gamedo =
{
	capcha : function()
	{
		this.code = $('input[name=code_download]').val();
		if(this.code !== undefined && this.code == '')
		{
			alert('Введите код с картинки!');
			return;
		}       
		var req = { zapros : this.code };
		capcha.query('verifyC', req, this.result);
	},
     
	result : function(data)
	{
		if(data) gamedo.opentime(); else alert('Не верный код!');
	},
	
	opencapcha : function()
	{
		if (document.getElementById('form_down_code').style.display != 'block') { document.getElementById('form_down_img').src = 'image_ca.php?'+Math.random(); }
		$('#form_down_code').css('display', 'block');
	},
		  
	opentime : function()
	{
		clearInterval(time);
		this.code = $('input[name=code_download]').val();
		$('#skach_link').css('display', 'none');
		$('#form_down_code').css('display', 'none');
		$('#rrr').attr('width', 1); $('#rrr').attr('height', 1);
		$('#rrrx').attr('width', 0); $('#rrrx').attr('height', 0);
		$('#game_upl').css('display', 'none');
		$('#game_counter').css('display', 'block');
		$('#rgg').css('display', '');
		document.getElementById('form_down_img').src = 'pics/load_capcha_p.gif';
		gamedo.time = 15;
		$('#game_counter_time').text(gamedo.time);
               
		var count = setInterval (
			function()
			{
				gamedo.time = gamedo.time - 1;
				$('#game_counter_time').text(gamedo.time);
				if(gamedo.time < 1)
				{
					clearInterval(count);
					gamedo.openlink();
				}
			}, 1000
		)
	},
          
	openlink : function()
	{
		$('#rgg').css('display', 'none');
		$('#download_link').css('display', 'table');
		$('#game_counter_time').text('15');
	},
	
	returngame : function()
	{
		$('#download_link').css('display', 'none');
		$('#rrr').attr('width', this.wx); $('#rrr').attr('height', this.hx);
		$('#rrrx').attr('width', this.wx); $('#rrrx').attr('height', this.hx);
		$('#skach_link').css('display', 'table');
		$('input[name=code_download]').val('');
	},
	
	returngame2 : function()
	{
		var count2 = setInterval (
		function()
		{
			$('#download_link').css('display', 'none');
			$('#rrr').attr('width', this.wx); $('#rrr').attr('height', this.hx);
			$('#rrrx').attr('width', this.wx); $('#rrrx').attr('height', this.hx);
			$('#skach_link').css('display', 'table');
			clearInterval(count2);
		}, 7000);
		
		$('input[name=code_download]').val('');
	}
}
	 


/** Обратная связь **/
  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://www.game-game.com.ua/gamesimg/' + id + '.jpg';
	document.getElementById(divid).title = 'Игра ' + title;
	document.getElementById(divid + '_link').href = id + '/';
}

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

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





