
var logintimer=null;
var emailtimer=null;
var loginfocus=false;

var errorstr=new Array();

var my_ajax = new dle_ajax();

errorstr[0]='Вы ввели недопустимый символ';
errorstr[1]='Вы ввели недостаточно символов';
errorstr[2]='Вы ввели больше символов';
errorstr[3]='Вы ввели недопустимый email';
errorstr[4]='Пароль слишком короткий';
errorstr[5]='Пароли не совпадают';
errorstr[6]='Неверное число символов';
errorstr[7]='Введите не менее 4 символов';
errorstr['login']='Пользователь с таким именем уже существует';
errorstr['login2']='Пользователь с таким именем не существует';
errorstr['email']='Такой E-Mail уже зарегистрирован';
errorstr['server']='Ошибка сервера. Попробуйте позже.';



function getyScroll()
{
  yScroll = 0;

  if (window.innerHeight && window.scrollMaxY || window.innerWidth && window.scrollMaxX)
   {
    yScroll = window.innerHeight + window.scrollMaxY;
    xScroll = window.innerWidth + window.scrollMaxX;

    var deff = document.documentElement;
    var wff = (deff&&deff.clientWidth) || document.body.clientWidth || window.innerWidth || self.innerWidth;
    var hff = (deff&&deff.clientHeight) || document.body.clientHeight || window.innerHeight || self.innerHeight;

    xScroll -= (window.innerWidth - wff);
    yScroll -= (window.innerHeight - hff);
   } 
  else if (document.body.scrollHeight > document.body.offsetHeight || document.body.scrollWidth > document.body.offsetWidth)
   { // all but Explorer Mac
    yScroll = document.body.scrollHeight;
    xScroll = document.body.scrollWidth;
   } 
  else 
   { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
    yScroll = document.body.offsetHeight;
    xScroll = document.body.offsetWidth;
   }

  return yScroll;
}




function checkpost(type, id)
{
	
	function onAjaxSuccess(data)
	{
//		alert(data);
		if (data=="ok")
		{
			$("#"+type+"_error").addClass('ok');
			$("#"+type+"_error").html('V');
		} else if (data=="error") {
			$("#"+type+"_error").removeClass('ok');
			$("#"+type+"_error").html(errorstr[type]);
		} else {
			$("#"+type+"_error").removeClass('ok');
			$("#"+type+"_error").html(errorstr['server']);
		}
	}
	
	$.post(
		'/engine/ajax/checkform.php',{type: type, id: id},onAjaxSuccess
	);
	
}


function checke(field)
{

	
		$("#email_error").removeClass('ok');
		
		if(field.match(/[^a-z0-9\_\.\-\@]+/i))
		{
			
			$("#email_error").html(errorstr[0]);

		} else if (!field.match(/^[a-z0-9][a-z0-9_.-]*@[a-z0-9_.-]+\.[a-z]{2,7}$/i)) {
			
			$("#email_error").html(errorstr[3]);

		} else {
			$("#email_error").html('');
			
			clearTimeout(emailtimer);
			emailtimer = setTimeout(function(){
				checkpost("email", field);
			}, 500);
		}
		

	
	return ;
	
}



$(document).bind("ready", function() {

	$("#search-tips").click(function() {
		$("#search-query").attr("value",$(this).text());
	});
	
	
	
	$("input[name='password1']").bind("change keyup", function(){
		field=$("input[name='password1']").attr("value");
		
		if (field.length < 6) {
			
			$("#password1_error").removeClass('ok');
			$("#password1_error").html(errorstr[4]);
			
		} else {
			
			$("#password1_error").addClass('ok');
			$("#password1_error").html('V');
	
		}
	});	
	
	
	$("input[name='password2']").bind("change keyup", function(){
		field=$("input[name='password2']").attr("value");
		
		if (field.length < 6 || field!=$("input[name='password1']").attr("value")) {
			
			$("#password2_error").removeClass('ok');
			$("#password2_error").html(errorstr[5]);
			
		} else {
			
			$("#password2_error").addClass('ok');
			$("#password2_error").html('V');
	
		}
	});	
	
	
	$("input[name='story']").bind("change keyup", function(){
		field=$("input[name='story']").attr("value");
		
		if (field.length < 4 ) {
			
			$("#story_error").removeClass('ok');
			$("#story_error").html(errorstr[7]);
			
		} else {
			
			$("#story_error").addClass('ok');
			$("#story_error").html('V');
	
		}
	});	
	
	
	
	$("#close").bind("click", function(){
		
		$(".b-alert").css({"display": "none"});
		
		$.post(
			'/engine/ajax/hint.php',{type: 1},function(data) {	}
		);
		
		return false;
	});
	
	
//	$("body.screenshots table td a img").load(function()
//	{

		var screen_run=false;
		var table_width=parseInt($("div.screenshots table").width());
		var div_width=parseInt($("div.screenshots").width());
		var eshe=table_width-div_width;
		var width_scroll=150;
		var time_scroll=600;

//		alert(table_width+"-"+div_width);
		
		$("div.b-film-info-screenshots a.preview").bind("click",function() {

			if(screen_run)
				return false;

			table_width2=parseInt($("div.screenshots table").width());
			if (table_width<table_width2)
			{
				table_width=table_width2;
				div_width=parseInt($("div.screenshots").width());
				eshe=table_width-div_width;
			}

			$("div.b-film-info-screenshots a.next").removeClass( "disabled" );

			contLeft=parseInt($("div.screenshots table").css("marginLeft"));

			ostatok=eshe+contLeft;

			if (contLeft<-width_scroll)
			{
				screen_run=true;
				$("div.screenshots table").animate({"marginLeft":"+="+width_scroll+"px"},time_scroll, function(){screen_run=false;});
			}
			else if (contLeft>=-width_scroll)
			{
				screen_run=true;
				$("div.screenshots table").animate({"marginLeft":"0px"},time_scroll, function(){screen_run=false;} );
			}

			if (contLeft>=-width_scroll)
			{
				$("div.b-film-info-screenshots a.preview").addClass( "disabled" );
			}

			return false;
		});



		$("div.b-film-info-screenshots a.next").bind("click",function() {

			if(screen_run)
				return false;

			table_width2=parseInt($("div.screenshots table").width());
			if (table_width<table_width2)
			{
				table_width=table_width2;
				div_width=parseInt($("div.screenshots").width());
				eshe=table_width-div_width;
			}

			$("div.b-film-info-screenshots a.preview").removeClass( "disabled" );

			contLeft=parseInt($("div.screenshots table").css("marginLeft"));

			ostatok=eshe+contLeft;

			//		$("p.column1").html($("p.column1").html()+'<br>o-'+$("div.screenshots table").width());

			if (ostatok>=width_scroll)
			{
				screen_run=true;
				$("div.screenshots table").animate({"marginLeft":"-="+width_scroll+"px"},time_scroll, function(){screen_run=false;});
			}
			else if (ostatok>0)
			{
				screen_run=true;
				$("div.screenshots table").animate({"marginLeft":"-="+ostatok+"px"},time_scroll, function(){screen_run=false;});
			}

			if (ostatok<=width_scroll)
			{
				$("div.b-film-info-screenshots a.next").addClass( "disabled" );
			}

			return false;
		});




		//alert(parseInt($("div.screenshots").width()) +"-"+ parseInt($("div.screenshots table").width()));

//		if ( eshe > 0 )
//		{
//			$("div.b-film-info-screenshots a.next").removeClass( "disabled" );
			
//		}

//	});
	
});

