function setOpacity(element,level) {
  element.style.opacity = level;
  element.style.MozOpacity = level;
  element.style.KhtmlOpacity = level;
  element.style.filter = "alpha(opacity=" + (level * 100) + ");";
}

function setCookie (name, value, expires, path, domain, secure) {
      document.cookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

function getCookie(name) {
	var cookie = " " + document.cookie;
	var search = " " + name + "=";
	var setStr = null;
	var offset = 0;
	var end = 0;
	if (cookie.length > 0) {
		offset = cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			end = cookie.indexOf(";", offset)
			if (end == -1) {
				end = cookie.length;
			}
			setStr = unescape(cookie.substring(offset, end));
		}
	}
	return(setStr);
}

//EasyTooltip

(function($) {
	$.fn.easyTooltip = function(options){
		var defaults = {
			xOffset: 10,
			yOffset: -15,
			tooltipId: "easyTooltip",
			clickRemove: false,
			content: "",
			useElement: ""
		};
		var options = $.extend(defaults, options);
		var content;
		this.each(function() {
			var title = $(this).attr("title");
			$(this).hover(function(e){
				content = (options.content != "") ? options.content : title;
				content = (options.useElement != "") ? $("#" + options.useElement).html() : content;
				$(this).attr("title","");
				if (content != "" && content != undefined){
					$("body").append("<div id='"+ options.tooltipId +"'>"+ content +"</div>");
					$("#" + options.tooltipId)
						.css("position","absolute")
						.css("top",(e.pageY - options.yOffset) + "px")
						.css("left",(e.pageX + options.xOffset) + "px")
						.css("display","none")
						.fadeIn("fast")
				}
			},
			function(){
				$("#" + options.tooltipId).remove();
				$(this).attr("title",title);
			});
			$(this).mousemove(function(e){
				$("#" + options.tooltipId)
					.css("top",(e.pageY - options.yOffset) + "px")
					.css("left",(e.pageX + options.xOffset) + "px")
			});
			if(options.clickRemove){
				$(this).mousedown(function(e){
					$("#" + options.tooltipId).remove();
					$(this).attr("title",title);
				});
			}
		});
	};
})(jQuery);

//contentMenu

(function($) {
	$.fn.contentMenu = function(options){
var email;
var $item_email;
		$(this).hover(function(e){
			if (isCommDialog || isEmailDialog || isAbuseDialog) return;
			var item = $(this).attr("id").substr(1);
			var comment = getCookie("COMM"+item);
			comment = (comment) ? comment : "";
			var icons = {
						add: "<img id='add' class='contentMenu' src='images/itemadd.gif' title='Добавить в блокнот'>",
						del: "<img id='del' class='contentMenu' src='images/itemdel.gif' title='Удалить из блокнота'>",
						comm0: "<img id='comm0' class='contentMenu' src='images/itemcomm0.gif' title='Добавить примечание'>",
						comm: "<img id='comm' class='contentMenu' src='images/itemcomm.gif' title='" + comment + "'>",
						print: "<img id='print' class='contentMenu' src='images/itemprint.gif' title='Распечатать'>",
						mail: "<img id='mail' class='contentMenu' src='images/itememail.gif' title='Отправить на email'>",
						abuse: "<img id='abuse' class='contentMenu' src='images/itemabuse.gif' title='Пожаловаться на это объявление'>"
					};
			var scr = '<script type="text/javascript">$(document).ready(function(){$("img.contentMenu").contTooltip();});' +
	          '$(document).ready(function(){$("img.contentMenu").contentMenuF(' + item + ');});</script>';
			var content = icons.add + icons.del + icons.comm0 + icons.comm + icons.print + icons.mail + icons.abuse;
			$(this).append('<div id="contentMenu">' + scr + content + '</div>');
			if ( ($("#ititle"+item).css("background-color") == "rgb(255, 255, 0)") || ($("#ititle"+item).css("background-color") == "#ffff00") || ($("#ititle"+item).css("background-color") == "yellow") ) {
				$("#add").css("display","none");
			} else {
				$("#del").css("display","none");
			}
			if (comment) {
				$("#comm0").css("display","none");
			} else {
				$("#comm").css("display","none");
			}
			$item_email = $("#i"+item).find("#item_email"+item);
			email = $item_email.attr("href");
			if (email) {
				var emailtemp = [];
				for (i=0;i<email.length;i++) {
					emailtemp[i] = String.fromCharCode(6^email.charCodeAt(i));
				}
				$item_email.attr("href",'mailto:'+emailtemp.join(""));
			}
		},
		function(){
			$("#contentMenu").remove();
			$item_email.attr("href",email);
		});
	};
})(jQuery);

var isCommDialog;
var isEmailDialog;
var isAbuseDialog;
var isNote;
var totalNotes;

(function($) {
	$.fn.contentMenuF = function(options){
	var item = options;
	var $itemdiv = $("#i"+item);
		$("#add").click(function(e){
			if (totalNotes<40) {
				$("#add").css("display","none");
				var cookie = getCookie("MARKED");
				if (cookie==null)
					setCookie("MARKED", item + ",")
				else
					setCookie("MARKED", cookie + item + ",");
				if (cookie) {
					totalNotes = cookie.split(",").length;
				} else
					totalNotes = 1;
				$("#note_info").empty().append(totalNotes);
				$("#ititle" + item).css("background","yellow");
				$("#del").css("display","block");
			}
		}
		);
		$("#del").click(function(e){
			$("#del").css("display","none");
			$("#ititle" + item).css("background","none");
			$("#add").css("display","block");
			var cookie = getCookie("MARKED");
			var myregexp = new RegExp(item + ",");
			var newcookie = cookie.replace(myregexp,"");
			totalNotes = newcookie.split(",").length-1;
			setCookie("COMM"+item,"");
			$("#note_info").empty().append(totalNotes);
			setCookie("MARKED", newcookie);
			$("#comm0").css("display","block");
			$("#comm").css("display","none");
			if (isNote) {
				$itemdiv.fadeOut(1500, function(){
					$itemdiv.remove();
				$("#contTooltip").remove();
				});
			}
		}
		);
		$("#comm0").click(function(e){
			if ((totalNotes<40) || ($("#ititle"+item).css("background-color") == "rgb(255, 255, 0)") || ($("#ititle"+item).css("background-color") == "#ffff00") || ($("#ititle"+item).css("background-color") == "yellow")) {
				isCommDialog = 1;
				$itemdiv.css("background","#cae2ff");
				var scr = '<script type="text/javascript">$(document).ready(function(){$("#commdialog").commDialog(' + item + ');});</script>';
				var content = "<textarea id='comment'></textarea><br>Осталось символов: <span id='comminfo'>60</span><span id='ok'>OK</span><b id='cancel'>Отмена</b> ";
				$("body").append("<div id='commdialog'>" + scr + content + "</div>");
				var itemPosition = $itemdiv.position();
				$("#commdialog")
					.css("top",itemPosition.top-60)
					.css("left",itemPosition.left)
				$("#contentMenu").remove();
				$("#contTooltip").remove();
				$("#commdialog").fadeIn(1000);
			}
		}
		);
		$("#comm").click(function(e){
			isCommDialog = 1;
			$itemdiv.css("background","#cae2ff");
			var scr = '<script type="text/javascript">$(document).ready(function(){$("#commdialog").commDialog(' + item + ');});</script>';
			var comment = getCookie("COMM"+item);
			comment = (comment) ? comment : "";
			var content = "<textarea id='comment'>" + comment + "</textarea><br>Осталось символов: <span id='comminfo'>60</span><span id='ok'>OK</span><b id='cancel'>Отмена</b> ";
			$("body").append("<div id='commdialog'>" + scr + content + "</div>");
			var itemPosition = $itemdiv.position();
			$("#commdialog")
				.css("top",itemPosition.top-60)
				.css("left",itemPosition.left)
			$("#contentMenu").remove();
			$("#contTooltip").remove();
			$("#commdialog").fadeIn(1000);
		}
		);
		$("#print").click(function(e){
			$("body").append("<iframe id='prn_frame' name='prn_frame'></iframe>");
			var i_comm = getCookie("COMM"+item);
			var comm = (i_comm) ? "Ваш комментарий: " + i_comm : "";
			var html = "<html><body><head><title>" + document.title + " cboard.org.ua id" + item + "</title> </head>" +
							$itemdiv.find("#item_date").html() + "<br>" + $itemdiv.find("#item_place"+item).html() + "<br><b>" + $("#ititle"+item).html() + "</b><br><br>" + $itemdiv.find("#item_body"+item).html() + "<br><br>" +
							$itemdiv.find("#item_name"+item).html() + "<br>" + $itemdiv.find("#item_email"+item).attr("title") + "<br>" + $itemdiv.find("#item_tel"+item).html() + "<br>" + $itemdiv.find("#item_fax"+item).html() + "<br>" + $itemdiv.find("#item_icq"+item).html() + "<br>" + $itemdiv.find("#item_skype"+item).html() + "<br>" + $itemdiv.find("#item_site"+item).attr("title") + "<br><br>" +
							comm + "</body></html>";
			var prnFrame = window.frames["prn_frame"];
			var prnDoc = prnFrame.document;
			prnDoc.open();
			prnDoc.write(html);
			prnDoc.close();
			prnFrame.focus();
			prnFrame.onload = prnFrame.print;
		//	prnFrame.print();
			setTimeout(
			function(){
				$("#prn_frame").remove();
			},
				(60 * 1000)
			);
		}
		);
		$("#mail").click(function(e){
			isEmailDialog = 1;
			$itemdiv.css("background","#cae2ff");
			$comment = getCookie("COMM"+item);
			$comment = ($comment) ? $comment : "Ваш комментарий";
			var scr = '<script type="text/javascript">$(document).ready(function(){$("#emaildialog").emailDialog(' + item + ');});</script>';
			var content = "<form id='emailform'><input id='email' name='email' value='Адрес email'><textarea id='email_comment' name='email_comment'>"+$comment+"</textarea><input type='hidden' name='item_email_to'><input type='hidden' name='item' value=" + item + "></form>Осталось символов: <span id='email_comminfo'>60</span><span id='ok'>OK</span><b id='cancel'>Отмена</b> ";
			$("body").append("<div id='emaildialog'>" + scr + content + "</div>");
			var itemPosition = $itemdiv.position();
			$("#emaildialog")
				.css("top",itemPosition.top-85)
				.css("left",itemPosition.left)
			$("#contentMenu").remove();
			$("#contTooltip").remove();
			$("#emaildialog").fadeIn(1000);
		}
		);
		$("#abuse").click(function(e){
			isAbuseDialog = 1;
			$itemdiv.css("background","#cae2ff");
			var scr = '<script type="text/javascript">$(document).ready(function(){$("#abusedialog").abuseDialog(' + item + ');});</script>';
			var content = "<form id='abuseform' name='abuseform'><div id='abuse_type'><label for='abuse_type1'><input type='radio' checked name='abuse_type' class='abuse_type' id='abuse_type1' value='1'>Спам/мошенничество</label><br><label for='abuse_type2'><input name='abuse_type' class='abuse_type' type='radio' id='abuse_type2' value='2'>Неэтичное объявление</label><br><label for='abuse_type3'><input name='abuse_type' class='abuse_type' type='radio' id='abuse_type3' value='3'>Противозаконное объявление</label><br><label for='abuse_type4'><input name='abuse_type' class='abuse_type' type='radio' id='abuse_type4' value='4'>Неверная рубрика</label><br><label for='abuse_type5'><input name='abuse_type' class='abuse_type' type='radio' id='abuse_type5' value='5'>Другое</label></div><textarea id='abuse_comment' name='abuse_comment'>Ваш комментарий</textarea><input type='hidden' name='item_abuse'><input type='hidden' name='item' value=" + item + "></form>Осталось символов: <span id='abuse_comminfo'>60</span><span id='ok'>OK</span><b id='cancel'>Отмена</b> ";
			$("body").append("<div id='abusedialog'>" + scr + content + "</div>");
			var itemPosition = $itemdiv.position();
			$("#abusedialog")
				.css("top",itemPosition.top-140)
				.css("left",itemPosition.left)
			$("#contentMenu").remove();
			$("#contTooltip").remove();
			$("#abusedialog").fadeIn(1000);
		}
		);
	};
})(jQuery);

(function($) {
	$.fn.contTooltip = function(options){
		var defaults = {
			xOffset: 10,
			yOffset: -25,
			tooltipId: "contTooltip",
			clickRemove: false,
			content: "",
			useElement: ""
		};
		var options = $.extend(defaults, options);
		this.each(function() {
			var title = $(this).attr("title");
			$(this).hover(function(e){
				var content = (options.content != "") ? options.content : title;
				content = (options.useElement != "") ? $("#" + options.useElement).html() : content;
				$(this).attr("title","");
				if (content != "" && content != undefined){
					$("body").append("<div id='"+ options.tooltipId +"'>"+ content +"</div>");
					$("#" + options.tooltipId)
						.css("position","absolute")
						.css("top",(e.pageY - options.yOffset) + "px")
						.css("left",(e.pageX + options.xOffset) + "px")
						.css("display","none")
						.fadeIn("fast")
				}
			},
			function(){
				$("#" + options.tooltipId).remove();
				$(this).attr("title",title);
			});
			$(this).mousemove(function(e){
				$("#" + options.tooltipId)
					.css("top",(e.pageY - options.yOffset) + "px")
					.css("left",(e.pageX + options.xOffset) + "px")
			});
			if(options.clickRemove){
				$(this).mousedown(function(e){
					$("#" + options.tooltipId).remove();
					$(this).attr("title",title);
				});
			}
		});
	};
})(jQuery);

(function($) {
	$.fn.checkMarkedItems = function(options){
		var cookie = getCookie("MARKED");
		if (cookie) var cookieArray = cookie.split(",");
		totalNotes = (cookie) ? cookieArray.length-1 : "0";
		$("#note_info").empty();
		$("#note_info").append(totalNotes);
		$("<img>").attr("src", "images/itemadd.gif");
		$("<img>").attr("src", "images/itemdel.gif");
		$("<img>").attr("src", "images/itemcomm0.gif");
		$("<img>").attr("src", "images/itemcomm.gif");
		$("<img>").attr("src", "images/itemprint.gif");
		$("<img>").attr("src", "images/itememail.gif");
		$("<img>").attr("src", "images/itemabuse.gif");
		if (cookieArray) {
			for (var i in cookieArray) {
				$("#ititle" + cookieArray[i]).css("background","yellow");
			}
		}
		if ($("#notepad").css("width")) isNote = 1;
	};
})(jQuery);

(function($) {
	$.fn.notepadClear = function(options){
		$(this).click(function(e){
			if (confirm('Удалить все записи из блокнота?')) {
				$("#items_col1").fadeOut(1500, function(){
					$("#items_col1").remove();
				});
				$("#items_col2").fadeOut(1500, function(){
					$("#items_col2").remove();
				});
				$("#items_col3").fadeOut(1500, function(){
					$("#items_col3").remove();
				});
				$("#items_col4").fadeOut(1500, function(){
					$("#items_col4").remove();
				});
				totalNotes = "0";
				$("#note_info").empty().append(totalNotes);
				$("#notepad_clear").empty().replaceWith("<span>Пустой</span>");
				setCookie("MARKED","");
			};
		});
	};
})(jQuery);

(function($) {
	$.fn.itemForm = function(options){  //options = 1 if edit
		var regexpTags = new RegExp("<[^>]*>","g");
		$("<img>").attr("src", "images/loading.gif");
//------date/time
		var currTime = new Date();
		var date = currTime.getDate();
		var month = currTime.getMonth()+1;
		var year = currTime.getFullYear();
		var hours = currTime.getHours();
		var minutes = currTime.getMinutes();
		$("#item_date").append(((date>10)?date:"0"+date)+"."+((month>10)?month:"0"+month)+"."+year+" в "+((hours>10)?hours:"0"+hours)+":"+((minutes>10)?minutes:"0"+minutes));
//------rubric
		var $i_subrubric_area = $("#i_subrubric_area");
		var $i_rubric = $("#i_rubric");
		var $disclaimer = $("#disclaimer");
		if (!options) $i_subrubric_area.hide();
		if (options) $disclaimer.hide();
		$("#i_rubric_first").attr("selected","true");
		$i_rubric.change(function(e){
			$i_subrubric_area.fadeOut(1000, function(){
				$.post('ajax.php',"rubrsel="+$i_rubric.attr("value"),function(data){
					if (data) {
						$("#i_subrubric").empty().append(data);
						$i_subrubric_area.fadeIn(1500);
					}
				});
			});

		});
//------title
		var $i_title = $("#i_title");
		title_validator = function (e)  {
			$i_title.attr("value",$i_title.attr("value").replace(regexpTags,""));
			$("#item_title").empty().append($i_title.attr("value"));
		}
		$i_title.ready(title_validator).keyup(title_validator).blur(title_validator);
//------textarea
		var $i_textarea = $("#i_textarea");
		textarea_validator = function (e) {
			$i_textarea.attr("value",$i_textarea.attr("value").replace(regexpTags,"").substr(0,200));
			$("#i_textarea_info").empty().append(200-$i_textarea.attr("value").length);
			$("#item_body").empty().append($i_textarea.attr("value"));
		}
		$i_textarea.ready(textarea_validator).keyup(textarea_validator).blur(textarea_validator);
//------name
		var $i_name = $("#i_name");
		var $i_email = $("#i_email");
		name_validator = function () {
			$i_name.attr("value",$i_name.attr("value").replace(regexpTags,""));
			if ($("#i_email").attr("value"))
				$("#item_name").empty().append('<a href="mailto:'+$i_email.attr("value").replace(regexpTags,"").replace(regexpEmail,"")+'"> '+$i_name.attr("value")+'</a>');
			else
				$("#item_name").empty().append($i_name.attr("value"));
		}
		$i_name.ready(name_validator).keyup(name_validator).blur(name_validator);
//------country
		var $i_country = $("#i_country");
		var $i_city = $("#i_city");
		country_validator = function (e) {
			$i_country.attr("value",$i_country.attr("value").replace(regexpTags,""));
			$("#item_place").empty();
			$("#item_place").append($i_city.attr("value")+" ").append($i_country.attr("value"));
		}
		$i_country.ready(country_validator).keyup(country_validator).blur(country_validator);
//------city
		city_validator = function (e) {
			$i_city.attr("value",$i_city.attr("value").replace(regexpTags,""));
			$("#item_place").empty();
			$("#item_place").append($i_city.attr("value")+" ").append($i_country.attr("value"));
		}
		$i_city.ready(city_validator).keyup(city_validator).blur(city_validator);
//------tel
		var regexpTel = new RegExp("[^0-9-,\(\)\+ ]","g");
		var $i_tel = $("#i_tel");
		tel_validator = function (e) {
			$i_tel.attr("value",$i_tel.attr("value").replace(regexpTags,"").replace(regexpTel,""));
			$("#item_tel").empty().append('<img id="telpic" alt="Тел." src="images/tel.gif">'+($i_tel.attr("value")+" "));
			if ($i_tel.attr("value"))
				$("#telpic").css("display","inline");
			else
				$("#telpic").css("display","none");
		}
		$i_tel.ready(tel_validator).keyup(tel_validator).blur(tel_validator);
//------fax
		var $i_fax = $("#i_fax");
		fax_validator = function(e){
			$i_fax.attr("value",$i_fax.attr("value").replace(regexpTags,"").replace(regexpTel,""));
			$("#item_fax").empty().append('<img id="faxpic" alt="Факс" src="images/fax.gif">'+$i_fax.attr("value")+" ");
			if ($i_fax.attr("value"))
				$("#faxpic").css("display","inline");
			else
				$("#faxpic").css("display","none");
		}
		$i_fax.ready(fax_validator).keyup(fax_validator).blur(fax_validator);
//------icq
		var regexpIcq = new RegExp("[^0-9]","g");
		var $i_icq = $("#i_icq");
		icq_validator = function(e){
			$i_icq.attr("value",$i_icq.attr("value").replace(regexpTags,"").replace(regexpIcq,""));
			$("#item_icq").empty().append('<img id="icqpic" alt="ICQ" height="12" src="http://status.icq.com/online.gif?icq='+$i_icq.attr("value")+'&img=5"> '+$i_icq.attr("value")+" ");
			if ($i_icq.attr("value"))
				$("#icqpic").css("display","inline");
			else
				$("#icqpic").css("display","none");
		}
		$i_icq.ready(icq_validator).keyup(icq_validator).blur(icq_validator);
//------skype
		var regexpSkype = new RegExp("[^0-9a-z._-]","g");
		var $i_skype = $("#i_skype");
		skype_validator = function(e){
			$i_skype.attr("value",$i_skype.attr("value").replace(regexpTags,"").replace(regexpSkype,""));
			$("#item_skype").empty().append('<img id="skypepic" alt="Skype" height="12" src="http://mystatus.skype.com/smallicon/'+$i_skype.attr("value")+'"> '+$i_skype.attr("value")+" ");
			if ($i_skype.attr("value"))
				$("#skypepic").css("display","inline");
			else
				$("#skypepic").css("display","none");
		}
		$i_skype.ready(skype_validator).keyup(skype_validator).blur(skype_validator);
//------email
		var regexpEmail = new RegExp("[^a-zA-Z0-9-_.@]","g");
		email_validator = function(e){
			$i_email.attr("value",$i_email.attr("value").replace(regexpTags,"").replace(regexpEmail,""));
			if ($i_email.attr("value"))
				$("#item_name").empty().append('<a href="mailto:'+$i_email.attr("value").replace(regexpTags,"").replace(regexpEmail,"")+'"> '+$i_name.attr("value")+'</a>');
			else
				$("#item_name").empty().append($i_name.attr("value"));
		}
		$i_email.ready(email_validator).keyup(email_validator).blur(email_validator);
//------url
		var regexpUrl = new RegExp("[^a-z0-9-_./:]","g");
		var $i_url = $("#i_url");
		url_validator = function(e){
			$i_url.attr("value",$i_url.attr("value").replace(regexpTags,"").replace(regexpUrl,""));
			if ($i_url.attr("value"))
				$("#item_url").empty().append(' <a href="'+$i_url.attr("value")+'">www</a>');
		}
		$i_url.ready(url_validator).keyup(url_validator).blur(url_validator);
//------form
		var regexpEmailValid = new RegExp("^([a-zA-Z0-9_\-]+\.)*[a-zA-Z0-9_\-]+@([a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9]\.)+[a-zA-Z]{2,4}$","i");
		var regexpUrlValid = new RegExp("^http://([a-zA-Z0-9\.\-]+)*","i");
		var regexpKey = new RegExp("(<script>)([^<]+)<\/script>","g");
		form_validator = function(options){ // options = 1 if edit
			var errorList = [];
			var errorText = {
				1 : "Не введен заголовок",
				2 : "Не введен текст объявления",
				3 : "Не введено имя автора",
				4 : "Не выбрана рубрика",
				5 : "Не введены контактные данные",
				6 : "Неверный формат email",
				7 : "Неверный формат адреса интернет-сайта",
				8 : "Неверный ответ на антиспам-вопрос",
				9 : "Вы должны согласиться с условиями публикации"
			};
			if (!$("#i_subrubric").attr("value")) errorList.push(4);
			if (!$("#i_title").attr("value").replace(regexpTags,"")) errorList.push(1);
			if (!$("#i_textarea").attr("value").replace(regexpTags,"")) errorList.push(2);
			if (!$("#i_name").attr("value").replace(regexpTags,"")) errorList.push(3);
			if (!$("#i_tel").attr("value").replace(regexpTags,"").replace(regexpTel,"") &&
				!$("#i_fax").attr("value").replace(regexpTags,"").replace(regexpTel,"") &&
				!$("#i_icq").attr("value").replace(regexpTags,"").replace(regexpIcq,"") &&
				!$("#i_skype").attr("value").replace(regexpTags,"").replace(regexpSkype,"") &&
				!$("#i_email").attr("value").replace(regexpTags,"").replace(regexpEmail,"") &&
				!$("#i_url").attr("value").replace(regexpTags,"").replace(regexpUrl,"")
				) errorList.push(5);
			if ($("#i_email").attr("value") && !regexpEmailValid.test($("#i_email").attr("value"))) errorList.push(6);
			if ($("#i_url").attr("value") && !regexpUrlValid.test($("#i_url").attr("value"))) errorList.push(7);
			if (!options && $("#spae").html().replace(regexpKey,"").length != $("#test").attr("value")) errorList.push(8);
			if (!options && !$("#user_agree").attr("checked")) errorList.push(9);
			if (errorList.length) {
				var errorMsg = "Ошибка. Введены не все необходимые данные:\n\n";
				for (i = 0; i < errorList.length; i++) {
					errorMsg += errorText[errorList[i]] + "\n";
				}
				alert(errorMsg);
				return false;
			}
			return true;
		}
		$("#additem_submit").mouseup(function(e){
			if (form_validator()) {
				$("#loading").empty().append("<img src='images/loading.gif'>");
				$.post('ajax.php',$("#item_form").serialize(),function(data){
					if (data && data!="ERR") {
						$("#add_form").fadeOut(1500).remove();
						$disclaimer.hide().empty().append(data).fadeIn(1500);
					}
					else {
						$("#loading").empty();
					}
				});
			};
		});
		$("#edititem_submit").mouseup(function(e){
			if (form_validator(1)) {
				$.post('ajax.php',$("#item_form").serialize(),function(data){
						if (data!="ERR") {
							$("#edit_form").remove();
							$disclaimer.fadeOut(1500,function(){
								$disclaimer.empty().append(data).fadeIn(1500);
							});
						}
						else
							alert("Ошибка при сохранении данных.");
				});
			};
		});

	};
})(jQuery);

(function($) {
	$.fn.commDialog = function(options){
		var item = options;
		var $commdialog = $("#commdialog");
		var $comment = $("#comment");
		$("body").mousedown(function(e){
			var winPosition = $commdialog.position();
			var winRight = winPosition.left + $commdialog.width();
			var winBottom = winPosition.top + $commdialog.height();
			if (((e.pageX<winPosition.left) || (e.pageX>winRight)) || ((e.pageY<winPosition.top) || (e.pageY>winBottom))) {
				$commdialog.fadeOut(1000,function(){
					$commdialog.remove();
					$("#i"+item).css("background","none");
					isCommDialog = 0;
					$("body").unbind("mousedown");
				});
			}
		});
		$comment.keyup(function(e){
			var limit = 59
			var value = $comment.attr("value");
			var newvalue = value.substr(0,limit);
			$comment.attr("value",newvalue);
			$("#comminfo").empty().append(60 - value.length);
		});
		$("#cancel").mousedown(function(e){
			$commdialog.fadeOut(1000,function(){
				$commdialog.remove();
				$("#i"+item).css("background","none");
				isCommDialog = 0;
				$("body").unbind("mousedown");
			});
		});
		$("#ok").mousedown(function(e){
			if ($comment.attr("value").length) {
				$("#add").css("display","none");
				$("#ititle" + item).css("background","yellow");
				$("#del").css("display","block");
				var comment = $comment.attr("value");
				setCookie("COMM"+item,comment);
				var cookie = getCookie("MARKED");
				var myregexp = new RegExp(item + ",");
				if (!(cookie.match(myregexp))) {
					if (cookie==null)
						setCookie("MARKED", item + ",")
					else
						setCookie("MARKED", cookie + item + ",");
					var notes = cookie.split(",").length;
					$("#note_info").empty().append(notes);
				}
				$("#comm0").css("display","none");
				$("#comm").css("display","block");
			} else {
				setCookie("COMM"+item,"");
				$("#comm0").css("display","block");
				$("#comm").css("display","none");
			}
			$commdialog.fadeOut(1000,function(){
				$commdialog.remove();
				$("#i"+item).css("background","none");
				isCommDialog = 0;
				$("body").unbind("mousedown");
			});
		});
	};
})(jQuery);

(function($) {
	$.fn.emailDialog = function(options){
		var item = options;
		var $emaildialog = $("#emaildialog");
		var $email_comment = $("#email_comment");
		var $email = $("#email");
		$("body").mousedown(function(e){
			var winPosition = $emaildialog.position();
			var winRight = winPosition.left + $emaildialog.width();
			var winBottom = winPosition.top + $emaildialog.height();
			if (((e.pageX<winPosition.left) || (e.pageX>winRight)) || ((e.pageY<winPosition.top) || (e.pageY>winBottom))) {
				$emaildialog.fadeOut(1000,function(){
					$emaildialog.remove();
					$("#i"+item).css("background","none");
					isEmailDialog = 0;
					$("body").unbind("mousedown");
				});
			}
		});
		$email_comment.keyup(function(e){
			var limit = 59
			var value = $email_comment.attr("value");
			var newvalue = value.substr(0,limit);
			$email_comment.attr("value",newvalue);
			$("#email_comminfo").empty().append(60 - value.length);
		});

		$email.mousedown(function(e){
			if ($email.attr("value")=="Адрес email")
				$email.attr("value","")
		});
		$("#email_comment").mousedown(function(e){
			if ($("#email_comment").attr("value")=="Ваш комментарий")
				$("#email_comment").attr("value","")
		});
		$("#cancel").mousedown(function(e){
			$emaildialog.fadeOut(1000,function(){
				$emaildialog.remove();
				$("#i"+item).css("background","none");
				isEmailDialog = 0;
				$("body").unbind("mousedown");
			});
		});
		$("#ok").mousedown(function(e){
			if ($email.attr("value") && $email.attr("value")!="Адрес email" && (/^([a-zA-Z0-9_\-]+\.)*[a-zA-Z0-9_\-]+@([a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9]\.)+[a-zA-Z]{2,4}$/i).test($("#email").attr("value"))) {
				if (!$email_comment.attr("value")=="Ваш комментарий") $email_comment.attr("value","");
				$.post('ajax.php',$("#emailform").serialize(),function(data){
					var email = $email.attr("value");
					$emaildialog.empty();
					if (data=="OK")
						$emaildialog.append("<br><br><b>Письмо по адресу "+ email +" отправлено.</b>");
				});
				setTimeout(
				function(){
					$emaildialog.fadeOut(1000,function(){
						$emaildialog.remove();
						$("#i"+item).css("background","none");
						isEmailDialog = 0;
						$("body").unbind("mousedown");
					});
				},
					(3*1000)
				);
			} else {
				alert("Адрес не введен или введен неправилно.");
			}
		});
	};
})(jQuery);

(function($) {
	$.fn.abuseDialog = function(options){
		var item = options;
		var $abusedialog = $("#abusedialog");
		var $abuse_comment = $("#abuse_comment");
		$("body").mousedown(function(e){
			var winPosition = $abusedialog.position();
			var winRight = winPosition.left + $abusedialog.width();
			var winBottom = winPosition.top + $abusedialog.height();
			if (((e.pageX<winPosition.left) || (e.pageX>winRight)) || ((e.pageY<winPosition.top) || (e.pageY>winBottom))) {
				$abusedialog.fadeOut(1000,function(){
					$abusedialog.remove();
					$("#i"+item).css("background","none");
					isAbuseDialog = 0;
					$("body").unbind("mousedown");
				});
			}
		});
		$abuse_comment.keyup(function(e){
			var limit = 59
			var value = $abuse_comment.attr("value");
			var newvalue = value.substr(0,limit);
			$abuse_comment.attr("value",newvalue);
			$("#abuse_comminfo").empty().append(60 - value.length);
		});
		$abuse_comment.mousedown(function(e){
			if ($abuse_comment.attr("value")=="Ваш комментарий")
				$abuse_comment.attr("value","")
		});
		$("#cancel").mousedown(function(e){
			$abusedialog.fadeOut(1000,function(){
				$abusedialog.remove();
				$("#i"+item).css("background","none");
				isAbuseDialog = 0;
				$("body").unbind("mousedown");
			});
		});
		$("#ok").mousedown(function(e){
			if ($abuse_comment.attr("value")=="Ваш комментарий") $abuse_comment.attr("value","");
			$.post('ajax.php',$("#abuseform").serialize(),function(data){
					$abusedialog.empty();
					if (data=="OK")
						$abusedialog.append("<br><br><b>Ваше замечание принято и ожидает администратора.</b>");
				});
				setTimeout(
				function(){
					$abusedialog.fadeOut(1000,function(){
						$abusedialog.remove();
						$("#i"+item).css("background","none");
						isAbuseDialog = 0;
						$("body").unbind("mousedown");
					});
				},
					(3*1000)
			);
		});
	};
})(jQuery);

(function($) {
	$.fn.editPage = function(options){
		var $editpage = $("#editpage");
		$editpage.ready(function(e){
			$.post('ajax.php',options,function(data) {
				$editpage.fadeOut(1500, function(){
					$editpage.empty().append(data).fadeIn(1500);
				});
			});
		});
	};
})(jQuery);

(function($) {
	$.fn.loginForm = function(options){
		var $editpage = $("#editpage");
		$("#disclaimer").hide();
		$("#login_submit").mouseup(function(e){
			$.post('ajax.php',$("#login_form").serialize(),function(data){
				$editpage.fadeOut(1500,function(){
					$editpage.empty().append(data).fadeIn(1500)
				});
			});
		});
	};
})(jQuery);

(function($) {
	$.fn.prolPage = function(options){
		var $prolpage = $("#prolpage");
		$prolpage.ready(function(e){
			$.post('ajax.php',options,function(data) {
				$prolpage.fadeOut(1500, function(){
					$prolpage.empty().append(data).fadeIn(1500);
				});
			});
		});
	};
})(jQuery);

(function($) {
	$.fn.prolForm = function(options){
		var $prolpage = $("#prolpage");
		$("#prol_submit").mouseup(function(e){
			$.post('ajax.php',$("#prol_form").serialize(),function(data){
				$prolpage.fadeOut(1500,function(){
					$prolpage.empty().append(data).fadeIn(1500)
				});
			});
		});
	};
})(jQuery);

(function($) {
	$.fn.delPage = function(options){
		var $delpage = $("#delpage");
		$delpage.ready(function(e){
			$.post('ajax.php',options,function(data) {
				$delpage.fadeOut(1500, function(){
					$delpage.empty().append(data).fadeIn(1500);
				});
			});
		});
	};
})(jQuery);

(function($) {
	$.fn.delForm = function(options){
		var $delpage = $("#delpage");
		$("#del_submit").mouseup(function(e){
			$.post('ajax.php',$("#del_form").serialize(),function(data){
				$delpage.fadeOut(1500,function(){
					$delpage.empty().append(data).fadeIn(1500)
				});
			});
		});
	};
})(jQuery);

(function($) {
	$.fn.extsearchForm = function(options){
		var $i_subrubric_area = $("#i_subrubric_area");
		var $i_rubric = $("#i_rubric");
		$i_subrubric_area.hide();
		$("#i_rubric_first").attr("selected","true");
		$i_rubric.change(function(e){
			$i_subrubric_area.fadeOut(1000, function(){
				$.post('ajax.php',"rubrsel="+$i_rubric.attr("value"),function(data){
					if (data) {
						$("#i_subrubric").empty().append(data);
						$i_subrubric_area.fadeIn(1500);
					}
				});
			});
		});
	};
})(jQuery);

(function($) {
	$.fn.feedForm = function(options){
		var $i_textarea = $("#i_textarea");
		textarea_validator = function (e) {
			$i_textarea.attr("value",$i_textarea.attr("value").substr(0,1000));
			$("#i_textarea_info").empty().append(1000-$i_textarea.attr("value").length);
			$("#item_body").empty().append($i_textarea.attr("value"));
		}
		$i_textarea.ready(textarea_validator).keyup(textarea_validator).blur(textarea_validator);
		$("#feedform").submit(function(e){
			return ($("#test").attr("value")==3 && $("#uname").attr("value") && $("#i_textarea").attr("value"));
		});
	};
})(jQuery);

(function($) {
	$.fn.menuTop = function(options){
		$("li").hover(function(e){
			$(this).addClass("fHover");
		},
		function(e){
			$(this).removeClass("fHover");
		});
	};
})(jQuery);

