



function setcookie (name, value, the_time) {
	var expDate = new Date();
	expDate.setTime (expDate.getTime() + (the_time * 1000));
	document.cookie = name + "=" + escape (value) + "; expires=" + expDate.toGMTString ();
}




function add_art_rating (the_id, the_value){
		var ajax = new dle_ajax();
		ajax.onShow ("");
		var varsString = "";
		ajax.setVar("id", the_id);
		ajax.setVar("value", the_value);
		ajax.requestFile = "/include/ajax/articles/add_art_rating.php";
		ajax.method = "POST";
		ajax.element = "rating_" + the_id;
		ajax.sendAJAX(varsString);
}

function add_com_rating (the_id, the_value){
		var ajax = new dle_ajax();
		ajax.onShow ("");
		var varsString = "";
		ajax.setVar("id", the_id);
		ajax.setVar("value", the_value);
		ajax.requestFile = "/include/ajax/comments_rating.php";
		ajax.method = "POST";
		ajax.element = "comm_rating_" + the_id;
		ajax.sendAJAX(varsString);
}

function addArticleToFavorite(article) {
	
		var ajax = new dle_ajax();
		ajax.onShow ("");
		var varsString = "";
		ajax.setVar("articleid", article);
		ajax.requestFile = "/include/ajax/articles/addToFavorite.php";
		ajax.method = "POST";
		ajax.element = "favorite" + article;
		ajax.sendAJAX(varsString);	
		
}


function removeArticleFromFavorite(article) {
	
		var ajax = new dle_ajax();
		ajax.onShow ("");
		var varsString = "";
		ajax.setVar("articleid", article);
		ajax.requestFile = "/include/ajax/articles/removeFromFavorite.php";
		ajax.method = "POST";
		ajax.element = "favorite" + article;
		ajax.sendAJAX(varsString);	
	
}



function add_answer (the_id, module, idi){
	
	var the_form = "<span style=\"color: #D0D0D0;\">Добавить комментарий:</span><br/>";
	
	the_form += "<div style=\"width: 90%;\">";
	
	the_form += "<a href=\"javascript:void(0);\" onclick=\"insert_tag('comment_"+the_id+"', ':-)');\"><img src=\"/images/smiles/girl_smile.gif\"></a>";
	the_form += "<a href=\"javascript:void(0);\" onclick=\"insert_tag('comment_"+the_id+"', ':-(');\"><img src=\"/images/smiles/girl_sad.gif\"></a>";
	the_form += "<a href=\"javascript:void(0);\" onclick=\"insert_tag('comment_"+the_id+"', ';-)');\"><img src=\"/images/smiles/girl_wink.gif\"></a>";
	the_form += "<a href=\"javascript:void(0);\" onclick=\"insert_tag('comment_"+the_id+"', ':-p');\"><img src=\"/images/smiles/girl_blum.gif\"></a>";
	the_form += "<a href=\"javascript:void(0);\" onclick=\"insert_tag('comment_"+the_id+"', '8-)');\"><img src=\"/images/smiles/girl_cool.gif\"></a>";
	the_form += "<a href=\"javascript:void(0);\" onclick=\"insert_tag('comment_"+the_id+"', ':-D');\"><img src=\"/images/smiles/ag.gif\"></a>";
	the_form += "<a href=\"javascript:void(0);\" onclick=\"insert_tag('comment_"+the_id+"', ':-[');\"><img src=\"/images/smiles/girl_blush.gif\"></a>";
	the_form += "<a href=\"javascript:void(0);\" onclick=\"insert_tag('comment_"+the_id+"', '=-O');\"><img src=\"/images/smiles/ai.gif\"></a>";
	the_form += "<a href=\"javascript:void(0);\" onclick=\"insert_tag('comment_"+the_id+"', ':-*');\"><img src=\"/images/smiles/kiss.gif\"></a>";
	the_form += "<a href=\"javascript:void(0);\" onclick=\"insert_tag('comment_"+the_id+"', ':\'(');\"><img src=\"/images/smiles/girl_cray.gif\"></a>";
	the_form += "<a href=\"javascript:void(0);\" onclick=\"insert_tag('comment_"+the_id+"', ':-|');\"><img src=\"/images/smiles/girl_hysteric.gif\"></a>";
	the_form += "<a href=\"javascript:void(0);\" onclick=\"insert_tag('comment_"+the_id+"', '@}->--');\"><img src=\"/images/smiles/give_rose.gif\"></a>";
	the_form += "<a href=\"javascript:void(0);\" onclick=\"insert_tag('comment_"+the_id+"', '*XA-XA*');\"><img src=\"/images/smiles/girl_haha.gif\"></a>";
	the_form += "<a href=\"javascript:void(0);\" onclick=\"insert_tag('comment_"+the_id+"', 'O:-)');\"><img src=\"/images/smiles/girl_angel.gif\"></a>";
	the_form += "<a href=\"javascript:void(0);\" onclick=\"insert_tag('comment_"+the_id+"', ':-!');\"><img src=\"/images/smiles/at.gif\"></a>";
	the_form += "<a href=\"javascript:void(0);\" onclick=\"insert_tag('comment_"+the_id+"', '*BRAVO*');\"><img src=\"/images/smiles/girl_claping.gif\"></a>";
	the_form += "<a href=\"javascript:void(0);\" onclick=\"insert_tag('comment_"+the_id+"', '*DANCE*');\"><img src=\"/images/smiles/girl_dance.gif\"></a>";
	the_form += "<a href=\"javascript:void(0);\" onclick=\"insert_tag('comment_"+the_id+"', '*NO*');\"><img src=\"/images/smiles/girl_nea.gif\"></a>";
	the_form += "<a href=\"javascript:void(0);\" onclick=\"insert_tag('comment_"+the_id+"', '*YES*');\"><img src=\"/images/smiles/girl_yes.gif\"></a>";
	the_form += "<a href=\"javascript:void(0);\" onclick=\"insert_tag('comment_"+the_id+"', '*HELP*');\"><img src=\"/images/smiles/girl_flag_of_truce.gif\"></a>";
	the_form += "<a href=\"javascript:void(0);\" onclick=\"insert_tag('comment_"+the_id+"', '*HEART*');\"><img src=\"/images/smiles/heart.gif\"></a>";
	the_form += "<a href=\"javascript:void(0);\" onclick=\"insert_tag('comment_"+the_id+"', '*EAT*');\"><img src=\"/images/smiles/eat.gif\"></a>";
	the_form += "<a href=\"javascript:void(0);\" onclick=\"insert_tag('comment_"+the_id+"', '*ANGRY*');\"><img src=\"/images/smiles/angry.gif\"></a>";
	the_form += "<a href=\"javascript:void(0);\" onclick=\"insert_tag('comment_"+the_id+"', '*DRINK*');\"><img src=\"/images/smiles/pivo.gif\"></a>";
	the_form += "<a href=\"javascript:void(0);\" onclick=\"insert_tag('comment_"+the_id+"', '*ICECREAM*');\"><img src=\"/images/smiles/icecream.gif\"></a>";
	the_form += "<a href=\"javascript:void(0);\" onclick=\"insert_tag('comment_"+the_id+"', '*HANDEATING*');\"><img src=\"/images/smiles/handeating.gif\"></a>";
	the_form += "</div>";
	
	the_form += "<form name='answer' id='answer_form_" + the_id + "' action='' onsubmit=\"update_comments('" + module + "', " + the_id +", " + idi + "); return false;\" method=post><input type=hidden name=parent value='" + the_id + "'><textarea id='comment_"+ the_id +"' name=com_body rows=2 style='width:90%'></textarea>"+
			 "<br><input type=submit value='добавить'></form>";
	var the_element = document.getElementById('answer_' + the_id);
	if (the_element.style.display == "none") {
		//the_element.style.display = "";
		the_element.innerHTML = the_form;
		$('#answer_'+the_id).slideDown('slow');
		document.answer.com_body.focus();
	} else {
		//the_element.style.display = "none";
		$('#answer_'+the_id).slideUp('slow');
		the_element.innerHTML = "";
	}
	
}

function add_main_answer() {
	
	var the_element = document.getElementById('new_comment');
	
	if (the_element.style.display == "none") {
		$('#new_comment').slideDown('slow'); return false;
	} else {
		$('#new_comment').slideUp('slow'); return false;
	}
}


function update_comments (module, the_id, idi){
	
	
	$.post(
	   	"/include/ajax/update_comments.php",
		{
			"id": idi,
			"parent": the_id,
			"module": module,
			"com_body": $("#comment_" + the_id).attr("value")			
		},
		function(ret) { $("#comments_div").html(ret); $("#comment_" + the_id).attr("value", ""); }
	);
	
/*	
	
		var ajax = new dle_ajax();
		ajax.onShow ("");
		var varsString = "";
		ajax.setVar("id", idi);
		ajax.setVar("parent", the_id);
		ajax.setVar("module", module);
		ajax.setVar("com_body", document.getElementById("answer_form_" + the_id).com_body.value);
		ajax.requestFile = "/include/ajax/update_comments.php";
		ajax.method = "POST";
		ajax.element = "comments_div";
		ajax.sendAJAX(varsString);
*/		
		
}
function reload_captcha () {
	var rndval = new Date().getTime(); 
	document.getElementById('captcha_image').innerHTML = "<img src='/image.php?mod=bot&rnd=" + rndval + "' align='absmiddle' />";
}
function add_friend (the_id){
		var ajax = new dle_ajax();
		ajax.onShow ("");
		var varsString = "";
		ajax.setVar("id", the_id);
		ajax.requestFile = "/include/ajax/add_friend.php";
		ajax.method = "POST";
		ajax.element = "friends_list_false";
		ajax.sendAJAX(varsString);
}
function change_karma (the_id, value){
		var ajax = new dle_ajax();
		ajax.onShow ("");
		var varsString = "";
		ajax.setVar("user_id", the_id);
		ajax.setVar("value", value);
		ajax.requestFile = "/include/ajax/karma.php";
		ajax.method = "POST";
		ajax.element = "karma_value";
		ajax.sendAJAX(varsString);
}
function vote_blog_karma (value, the_id){
		setcookie ("blog_" + the_id, "1", 36000);
		var ajax = new dle_ajax();
		ajax.onShow ("");
		var varsString = "";
		ajax.setVar("blog_name", the_id);
		ajax.setVar("value", value);
		ajax.requestFile = "/include/ajax/articles/karma.php";
		ajax.method = "POST";
		ajax.element = "karma_value";
		ajax.sendAJAX(varsString);
}
function blog (the_id, type){
		var ajax = new dle_ajax();
		ajax.onShow ("");
		var varsString = "";
		ajax.setVar("blog_id", the_id);
		if (type == "join") ajax.setVar("type", "join");
		else ajax.setVar("type", "exit");
		ajax.requestFile = "/include/ajax/articles/blog.php";
		ajax.method = "POST";
		ajax.element = "blog_options";
		ajax.sendAJAX(varsString);
}


function show_reg_form () {
	document.getElementById('reg_form').style.display = "block";
	//document.getElementById('screen').style.display = "block";
}

function close_reg_form () {
	document.getElementById('reg_form').style.display = "none";
	//document.getElementById('screen').style.display = "none";
}

$(document).ready(function () {
	//$("#logo").corner("10px tl");
	$("#menu").corner("10px bl br");
	//$("#footer").corner("10px");
	$("#main_table").corner("10px");
	$("#user_karma").corner("10px");
	$(".block").corner("10px tl bl");
	//$(".blog_info").corner("10px");
	$(".site_message").corner("8px");
	$(".site_error").corner("8px");
	$("#second_navigation li").corner("8px tl tr");
	$("#second_navigation").corner("8px bl br");
	$("#block_last_user_arts").corner("10px");
	$("#block_users_top").corner("10px");
});

function close_answer (the_id) {
	$('#answer_'+the_id).slideUp('slow');
}

function delete_comments(the_id, module, idi){
		if (confirm("Вы действительно хотите удалить комментарий?") == true) {
			var ajax = new dle_ajax();
			ajax.onShow ("");
			var varsString = "";
			ajax.setVar("id", idi);
			ajax.setVar("delete", "true");
			ajax.setVar("module", module);
			ajax.setVar("comment", the_id);
			ajax.requestFile = "/include/ajax/update_comments.php";
			ajax.method = "POST";
			ajax.element =  "comments_div";
			ajax.sendAJAX(varsString);
		}
}

function edit_com(the_id){
		var ajax = new dle_ajax();
		ajax.onShow ("");
		var varsString = "";
		ajax.setVar("com_id", the_id);
		ajax.requestFile = "/include/ajax/edit_comment.php";
		ajax.method = "POST";
		ajax.element = "edit_comment_" + the_id;
		ajax.sendAJAX(varsString);
}

function save(id){
	
	$.post(
	   	"/include/ajax/edit_comment.php",
		{
			"com_id": id,
			"save": "true",
			"com_body": $("#comment_" + id).attr("value")			
		},
		function(ret) { $("#edit_comment_" + id).html(ret); $("#comment_" + id).attr("value", ""); }
	);	
	
/*		var ajax = new dle_ajax();
		ajax.onShow ("");
		var varsString = "";
		ajax.setVar("com_id", id);
		ajax.setVar("save", "true");
		ajax.setVar("com_body", document.getElementById("comment_"+id).value);
		ajax.requestFile = "/include/ajax/edit_comment.php";
		ajax.method = "POST";
		ajax.element =  "edit_comment_" + id;
		ajax.sendAJAX(varsString);
*/		
}
function exit(id){
		var ajax = new dle_ajax();
		ajax.onShow ("");
		var varsString = "";
		ajax.setVar("com_id", id);
		ajax.setVar("exit", "true");
		ajax.requestFile = "/include/ajax/edit_comment.php";
		ajax.method = "POST";
		ajax.element =  "edit_comment_" + id;
		ajax.sendAJAX(varsString);
}

function getTagActionName(form) {
	var url = '/tag/';
	var isEmpty = true;
	var tag = $('#tagname').val();
	if (tag != '') {
		url += tag + '/';
		isEmpty = false;
	}

	if (isEmpty == false) { 
		window.location.href = url; 
		return false;
	}

	return false;
} 