function addtag() {
	tagval = document.getElementById('add_tag').value;
	document.getElementById('tag_form').action = '/tag/'+tagval+'/';
}

function sh(id) {
document.getElementById(id).style.display='block';
}
function hd(id) {
document.getElementById(id).style.display='none';
}

function field_is_empty(id) {
document.getElementById(id).innerHTML = 'Поле не может быть пустым!';	
}

function area_is_empty(id) {
document.getElementById(id).value = 'Поле не может быть пустым!';	
}
function block_submit() {
document.getElementById('submit').disabled = true;
}
function unblock_submit() {
document.getElementById('submit').disabled = false;
}
function clear(id) {
document.getElementById(id).innerHTML = '';	
}

function is_valid_email (email)
{
	return /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(email);
}

function do_complete() {
window.location = "/";	
}

function do_done() {
window.location.reload(true);	
}

function password_reminder() {
document.getElementById('reminder_form').style.display="inline";
return false;
}


function check_field(type,value,msg) {
	
	
if(type == 'password') {
if(value.length < 4) {
document.getElementById(msg).innerHTML = 'Слишком короткий пароль!';
}
else {
clear(msg);
return 1;
}
}

if(type == 'login') {
if(value.length < 2) {
document.getElementById(msg).innerHTML = 'Слишком короткий логин!';
}
else {
clear(msg);
return 1;
}
}

if(type == 'email') {
if(is_valid_email(value)) {
clear(msg);
return 1;
}
else {
document.getElementById(msg).innerHTML = 'Введите настоящий E-mail!';
}
}	
	
	
	
	
	
	
}






function check_login() {
login = document.getElementById('login_login').value;
password = document.getElementById('login_password').value;


if(login == '') {  field_is_empty('login_login_err'); l_s = 0; } else { l_s = check_field('login',login,'login_login_err')}
if(password == '') {  field_is_empty('login_password_err'); p_s = 0; } else { p_s = check_field('password',password,'login_password_err')}

c_sum = l_s+p_s;

if(c_sum!=2) {
return false;
}
else {
	


$.post('/ajax/login.php', {login: login, password: password, key: 'imnotaspambotpleaseletmein'}, function(msg){
if(msg == "complete"){
do_complete();
}
else if(msg == "no_user") {
document.getElementById('login_login_err').innerHTML = 'Данного логина нет в базе!';	
}
else if(msg == "no_password") {
document.getElementById('login_password_err').innerHTML = 'Неправильный пароль!';	
}
else {
document.getElementById('err').innerHTML = msg;	
}
});
	


return false;
}
}






function check_email() {
email = document.getElementById('login_email').value;

email_err = document.getElementById('login_email_err').innerHTML;


if(email == '') {  field_is_empty('login_email_err'); e_s = 0; } else { e_s = check_field('email',email,'login_email_err')}

c_sum = e_s;

if(c_sum!=1) {
return false;
}
else {
	
	

$.post('/ajax/email.php', {email: email, key: 'imnotaspambotpleaseletmein'}, function(msg){
if(msg == "complete"){
do_complete();
}
else if(msg == "no_email") {
document.getElementById('login_email_err').innerHTML = 'Данного адреса нет в базе!';	
}
else {
document.getElementById('err').innerHTML = msg;	
}
});



return false;
}
}


function show_comment_form() {
sh('comment_form');
document.getElementById('show_comment_form').onclick=function () { hide_comment_form(); return false; }
return false;
}


function hide_comment_form() {
hd('comment_form');
document.getElementById('show_comment_form').onclick=function () { show_comment_form(); return false; }
return false;
}

function add_img_out(id) {
document.getElementById('add_'+id).src = '/sw_uploader/images/0.png';	
}
function add_img_over(id) {
document.getElementById('add_'+id).src = '/sw_uploader/images/1.png';		
}
function delete_img_out(id) {
document.getElementById('delete_'+id).src = '/sw_uploader/images/00.png';	
}
function delete_img_over(id) {
document.getElementById('delete_'+id).src = '/sw_uploader/images/11.png';		
}


function add_image(id) {
document.getElementById('comment_body').value +='\n[img]'+id+'[/img]\n';
document.getElementById('comment_body').focus();
}

function delete_image(id,num) {
hd('image_thumb_'+num);

$.ajax({
type: "POST",
url: "/ajax/thumb.php",
data: "id="+id+"&key=imnotaspambotpleaseletmein&act=delete_img",
success: function(msg){
if(msg == "complete"){
alert("Изображение удалено");
}
else {
document.getElementById('err').innerHTML = msg;	
}
}
});

}



function check_comments() {
	

comment_body = document.getElementById('comment_body').value;
post = document.getElementById('post').value;



if(comment_body == '') {  field_is_empty('comment_body_err'); e_s = 0; } else { e_s = 1 }

c_sum = e_s;

if(c_sum!=1) {
return false;
}
else {
	
document.getElementById('send_button').disabled="disabled";
document.getElementById('send_button').value="Отправляется...";


$.post('/ajax/add_comment.php', {comment_body: comment_body, post: post, key: 'imnotaspambotpleaseletmein'}, function(msg){
if(msg == "complete"){
do_done();
}
else {
document.getElementById('err').innerHTML = msg;	
}
});




return false;
}

}






function check_post() {
block_submit();

post_title = document.getElementById('post_title').value;
post_text = document.getElementById('comment_body').value;
post_tags = document.getElementById('post_tags').value;
blog = document.getElementById('blog').value;



if(post_title == '') {  field_is_empty('post_title_err'); tt_s = 0; } else { tt_s = 1 }
if(post_text == '') {  field_is_empty('post_text_err'); te_s = 0; } else { te_s = 1 }
if(post_tags == '') {  field_is_empty('post_tags_err'); tg_s = 0; } else { tg_s = 1 }

c_sum = tt_s+te_s+tg_s;

if(c_sum!=3) {
unblock_submit();
return false;
}
else {
	
	

$.post('/ajax/add_post.php', {post_text: post_text, post_title: post_title, post_tags: post_tags, blog: blog, key: 'imnotaspambotpleaseletmein'}, function(msg){
if(msg == "complete"){
do_complete();
}
else {
document.getElementById('err').innerHTML = msg;	
}
});





return false;
}

}



function check_edit_post() {
block_submit();

post_title = document.getElementById('post_title').value;
post_text = document.getElementById('comment_body').value;
post_tags = document.getElementById('post_tags').value;
blog = document.getElementById('blog').value;



if(post_title == '') {  field_is_empty('post_title_err'); tt_s = 0; } else { tt_s = 1 }
if(post_text == '') {  field_is_empty('post_text_err'); te_s = 0; } else { te_s = 1 }
if(post_tags == '') {  field_is_empty('post_tags_err'); tg_s = 0; } else { tg_s = 1 }

c_sum = tt_s+te_s+tg_s;

if(c_sum!=3) {
unblock_submit();
return false;
}
else {
	
	

$.post('/ajax/edit_post.php', {post_text: post_text, post_title: post_title, post_tags: post_tags, blog: blog, key: 'imnotaspambotpleaseletmein'}, function(msg){
if(msg == "complete"){
do_complete();
}
else {
document.getElementById('err').innerHTML = msg;	
}
});





return false;
}

}










function answer_comment(id) {
sh('comment_form');
document.getElementById('show_comment_form').onclick=function () { hide_comment_form(); return false; }
document.getElementById('comment_body').value +='[quote]'+id+'[/quote]\n';
document.getElementById('comment_body').focus();
}

function bbtag_(tag) {
var msg;
var param;
if(tag == 'Video') {
msg = 'Ссылка на видео на YouTube, RuTube, Vimeo или GameTrailers'; 
param = '';
}
if(tag == 'a') {
msg = 'Заголовок ссылки'; 
param = ' href=http://адрес_сайта.ру ';
}
if(tag == 'Spoiler') {
msg = 'Текст который надо скрыть'; 
param = '';
}
if(tag == 'i') {
msg = ''; 
param = '';
}
if(tag == 'b') {
msg = ''; 
param = '';
}

document.getElementById('comment_body').value +='['+tag+''+param+']'+msg+'[/'+tag+']\n';
document.getElementById('comment_body').focus();
}

function text_cut() {
document.getElementById('comment_body').value +='[text_cut]\n';
document.getElementById('comment_body').focus();	
}

function spoiler(key) {
document.getElementById('sp_b_'+key).style.display="none";	
document.getElementById('sp_c_'+key).style.display="inline";	
}

function delete_topic(id) {
	
$.ajax({
type: "POST",
url: "/ajax/delete_topic.php",
data: "id="+id+"&key=imnotaspambotpleaseletmein",
success: function(msg){
if(msg == "complete"){
do_complete();
}
else {
document.getElementById('err').innerHTML = msg;	
}
}
});
	
}


function profile_complete(name) {
window.location = "/people/"+name+"/";	
}

function check_profile_comment(accname) {
comment = document.getElementById('comment').value;
comment.replace('[[amp]]','&');

$.post('/ajax/edit_profile.php', {accname: accname, comment: comment, key: 'imnotaspambotpleaseletmein'}, function(msg){
if(msg == "complete"){
profile_complete(accname);
}
else {
document.getElementById('err').innerHTML = msg;	
}
});



return false;
}

function check_profile_contacts(accname) {
icq = document.getElementById('icq').value;
skype = document.getElementById('skype').value;
lj = document.getElementById('lj').value;
hz = document.getElementById('hz').value;




$.post('/ajax/edit_profile.php', {accname: accname, icq: icq, skype: skype, lg: lj, hz: hz, key: 'imnotaspambotpleaseletmein'}, function(msg){
if(msg == "complete"){
profile_complete(accname);
}
else {
document.getElementById('err').innerHTML = msg;	
}
});



return false;
}


function check_profile_osebe(accname) {
name = document.getElementById('name').value;
s_name = document.getElementById('s_name').value;
gender = document.getElementById('gender').value;
day = document.getElementById('day').value;
month = document.getElementById('month').value;
year = document.getElementById('year').value;
country = document.getElementById('country').value;
city = document.getElementById('city').value;




$.post('/ajax/edit_profile.php', {accname: accname, name: name, s_name: s_name, gender: gender, day: day, month: month, year: year, country: country, city: city, key: 'imnotaspambotpleaseletmein'}, function(msg){
if(msg == "complete"){
profile_complete(accname);
}
else {
document.getElementById('err').innerHTML = msg;	
}
});


return false;
}

function vote_pm(id,type,val) {


$.ajax({
type: "POST",
url: "/ajax/vote.php",
data: "id="+id+"&type="+type+"&val="+val+"&key=imnotaspambotpleaseletmein",
success: function(msg){
if(msg == 'avt'){
alert('Вы уже голосовали тут');
}
else {
document.getElementById('v_c_'+id).innerHTML = msg;	
}
}
});



}
