/*
 * Programming by Prokopchuk Vladimir IV-53
 */
$(function(){

   
    $('input[name=password], input[name=login]').keyup(function(e) {
     if(e.keyCode == 13) {
     $('form[name=enter]').submit();
    }
    });


//REGISTER
try{
$("#authors").floatdialog("avt", {backgroundcolor: '#1D5A70',speed: 'slow'});
}catch(e){}





	$("iframe").attr({'width':'440px'});
	
	

		$.datepicker.regional['ru'] = {
		clearText: 'Очистить', clearStatus: '',
		closeText: 'Закрыть', closeStatus: '',
		prevText: '&#x3c;Пред',  prevStatus: '',
		prevBigText: '&#x3c;&#x3c;', prevBigStatus: '',
		nextText: 'След&#x3e;', nextStatus: '',
		nextBigText: '&#x3e;&#x3e;', nextBigStatus: '',
		currentText: 'Сегодня', currentStatus: '',
		monthNames: ['Январь','Февраль','Март','Апрель','Май','Июнь',
		'Июль','Август','Сентябрь','Октябрь','Ноябрь','Декабрь'],
		monthNamesShort: ['Янв','Фев','Мар','Апр','Май','Июн',
		'Июл','Авг','Сен','Окт','Ноя','Дек'],
		monthStatus: '', yearStatus: '',
		weekHeader: 'Не', weekStatus: '',
		dayNames: ['воскресенье','понедельник','вторник','среда','четверг','пятница','суббота'],
		dayNamesShort: ['вск','пнд','втр','срд','чтв','птн','сбт'],
		dayNamesMin: ['Вс','Пн','Вт','Ср','Чт','Пт','Сб'],
		dayStatus: 'DD', dateStatus: 'D, M d',
		dateFormat: 'dd.mm.yy', firstDay: 1, 
		initStatus: '', isRTL: false};
	$.datepicker.setDefaults($.datepicker.regional['ru']);	
	

				$('#datepicker').datepicker({
					inline: true
					
				});
				
				
                

proxy();//Проксирующа ф-ция



//input mask
$("input[name=login]").attr({'value':'Логин'});
$("input[name=password]").attr({'value':'Пароль'});

$("input[name=login]").click(function(){
	if ($(this).attr('value')=='Логин') {
		$(this).attr({
			'value': ''
		});
	}
})
$("input[name=password]").click(function(){
	if ($(this).attr('value') == 'Пароль') {
		$(this).attr({
			'value': ''
		});
	}
})


//REGISTER
try{
$("#enter").floatdialog("aut", {backgroundcolor: '#1D5A70',speed: 'slow'});
$("#fogot").floatdialog("fog", {backgroundcolor: '#1D5A70',effect: false});
$("#theme").floatdialog("nth", {backgroundcolor: '#1D5A70',effect: 'slow'});
$("#register").floatdialog("registration", {backgroundcolor: '#1D5A70'});

}catch(e){}



$("#foggo").click(function(){
	$("#mes2").text('Обработка...');
	if ($("input[name=email]").val()) {
	$.post("http://" + top.location.host + "/mods/request.php", {
			fog: "1",
			email: $("input[name=email]").val()
		}, function(data){
			try{eval(data)}catch(e){};
			if(ans[0]=='MES'){
				$("#mes2").text(ans[1]);
			}else if(ans[0]=='ok'){
				$("#mes2").text(ans[1]);
				
			}
			
			})
	}else{
		$("#mes2").text('Введите e-mail!');
	}
})

$("#nthgo").click(function(){
	$("#mes3").text('Обработка...');
	if ($("input[name=fname]").val() && $("input[name=descr]").val()) {
		$("#mes3").text('Отправка запроса...');
	$.post("http://" + top.location.host + "/mods/request.php", {
			newtheme: "1",
			name: $("input[name=fname]").val(),
			descr: $("input[name=descr]").val(),
			uid: readCookie('user')
		}, function(data){
			try{eval(data);
			if(ans[0]=='MES'){
				$("#mes3").text(ans[1]);
			}else if(ans[0]=='ok'){
				$(".disable_masking").hide();
            	$("#floatdialog_mask_nth").fadeOut("slow").fadeTo("", 100);
       			$("#nth").hide();
				$("#last_tr").after('<tr id="last_tr"><td style="border:1px solid #BCE3E3;"><table cellpadding="0" cellspacing="0" width="100%"><tr><td width="50px"><a href="http://' + top.location.host + '/russian/forum/'+ ans[1] +'/"><img  border="0" src="http://' + top.location.host + '/images/theme.png"/></a></td><td><a href="http://' + top.location.host + '/russiann/forum/'+ ans[1] +'/"><span style="color: #1D5A70; font-size:14px;"><b>'+ans[2]+'</b></span><br/><span style="color: #1D5A70; font-size:14px;">'+ans[3]+'</span></a><br/><span style="color: #1D5A70; font-size:14px;">Создана: Сегодня,'+ ans[4]+'.</span></td></tr></table></td><td style="border:1px solid #BCE3E3;"><span style="color: #1D5A70; font-size:14px; margin:5px;">Пока еще сообщений нет</span><br/></td><td style="border:1px solid #BCE3E3;"><center><span style="color: #1D5A70; font-size:14px;">0</span></center></td></tr>');
				$("#last_tr").attr({'id':' '});
			}
			}catch(e){};
			});
	}else{
		$("#mes3").text('Введите название и описание темы!');
	}
})




$("#log").click(function(){
	$("#mes").text('Обработка...');
	if ($("input[name=login]").val() && $("input[name=password]").val()) {
		$.post("http://" + top.location.host + "/mods/request.php", {
			log: "1",
			login: $("input[name=login]").val(),
			password: $("input[name=password]").val()
		}, function(data){
			try{eval(data)}catch(e){};
			if(ans[0]=='MES'){
			$("#mes").text(ans[1]);	
			}else if(ans[0]=='OK'){
				
				createCookie('user',ans[1],30);
				
				
					
        	$(".disable_masking").hide();
            $("#floatdialog_mask_aut").fadeOut("slow").fadeTo("", 100);
       		$("#regdiv").hide();
				
				 
				 $.post("http://" + top.location.host + "/mods/request.php", {
					getlog: "1",
					uid: ans[1]
				 }, function(data){
				 $("#enter").html('<span style="cursor: default;">Вы вошли как '+data+'.</span>');
				 
				 $("#enter").after('<span id="exit" style="cursor: pointer; font-size: 13px; color:#2c657a; font-weight: bold"><img src="http://' + top.location.host + '/images/exit.gif" height="20px" style="margin:0"> Выход.</span>');
				 $("#exit").after('<span id="theme" style="cursor: pointer; font-size: 13px; color:#2c657a; font-weight: bold"><img src="http://' + top.location.host + '/images/theme.gif" height="20px" style="margin:0"> Создать тему.</span>')
				try{
$("#theme").floatdialog("nth", {backgroundcolor: '#1D5A70',effect: 'slow'});

}catch(e){}
				 
				
				 
				 	$("#exit").click(function(){
					delete_cookie('user');
	 				$("#enter").text('Вход');
	 				$("#exit").remove();
					$("#theme").remove();
					$("#regdiv").show();
					})
					
					
				 })
				 
			}else{
			$("#mes").text('Ошибка сервера');
			}
			
			
		});
	}else{
		$("#mes").text("Не введен логин или пароль!");
	}
});

	$("#exit").click(function(){
					delete_cookie('user');
					
	 				$("#enter").text('Вход');
	 				$("#exit").remove();
					$("#theme").remove();
					$("#regdiv").show();
					})

	$("#SubmitToFG").click(function(){
	 				$.post("http://"+top.location.host+"/mods/request.php", {
            			fogot: "1",
						email: $("input[name='email']").val()
      					  },function(data){
        				alert(data);
      				  });
})







$(".send").click(function(){
	if (!$("input[name=keystring]").val()) {
		$("#mesf").text("Ведите строку");
	}
	else 
		if (!FCKeditorAPI.GetInstance('datahtml_' + $(this).attr('parent')).GetHTML(true)) {
			$("#mesf").text("Нет текста для коментария");
		}
		else {
		
			$.post("http://" + top.location.host + "/mods/request.php", {
				postmes: "1",
				key: $("input[name=keystring]").val(),
				mes: FCKeditorAPI.GetInstance('datahtml_' + $(this).attr('parent')).GetHTML(true),
				parent: $(this).attr('parent'),
				uid: readCookie('user')
			}, function(data){
				alert(data);
			})
		}
})

///







$(".newmes").click(function(){
	$("#nomes").html(' ');	
	$('#nomes').rte({				
		width: 450,
		height: 200,
		controls_rte: rte_toolbar
	});
	$("#capcha_new").show();
	//alert($("#nomes").contents().find("body").html()); 
});
$(".newmes_with_posts").click(function(){
	$('#nomes').rte({				
		width: 450,
		height: 200,
		controls_rte: rte_toolbar
	});
	$("#capcha_new").show();

});
///QUOTe
$(".quot").click(function(){
	$('#nomes_'+$(this).attr("gid")).rte({				
		width: 450,
		height: 200,
		controls_rte: rte_toolbar
	});
	$("#mes_"+$(this).attr("gid")).show();

});


			});
			
function delete_cookie ( cookie_name )
{
  createCookie(cookie_name,"",-1);
}
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function closeauthors(){
	$(".disable_masking").hide();
    $("#floatdialog_mask_avt").fadeOut("slow").fadeTo("", 100);
    $("#avt").hide();
}



//Print function
  var win=null;
  function printIt(printThis)
  {
    win = window.open();
    self.focus();
    win.document.open();
    win.document.write('<'+'html'+'><'+'head'+'><'+'style'+'>');
    win.document.write('body, td { font-family: Verdana; font-size: 10pt;}');
    win.document.write('<'+'/'+'style'+'><'+'/'+'head'+'><'+'body'+'>');
    win.document.write(printThis);
    win.document.write('<'+'/'+'body'+'><'+'/'+'html'+'>');
    win.document.close();
    win.print();
    win.close();
  }
