function base_url()
{
	var url = (document.location + "").split("/");
	return url[0] + "//" + url[2] + "/";
}

function segment(n)
{
	var url = (document.location + "").split("/");
	return  (n > 0) ? url[n + 2] : "error";
	
}

function removeTags(text)
{
	strInputCode = text.replace(/&(lt|gt);/g, function (strMatch, p1)
	{
		return (p1 == "lt") ? "<" : ">";
	});
    
	var strTagStrippedText = strInputCode.replace(/<\/?[^>]+(>|$)/g, "");
    return strTagStrippedText;
}


function reset()
{
	var name = "";
	$("input").each(function() {
		if($(this).attr("type") == "text" || $(this).attr("type") == "password" || $(this).attr("type") == "file" || $(this).attr("type") == "hidden")
		{
			$(this).val("");
		}
		
		if($(this).attr("type") == "checkbox")
		{
			$(this).attr("checked", false);
		}
		
		if($(this).attr("type") == "radio")
		{
			if(name == "")
			{
				name = $(this).attr("name");
				$(this).attr("checked", true);
			}
			else
			{
				if(name != $(this).attr("name"))
				{
					name = $(this).attr("name");
					$(this).attr("checked", true);
				}
			}
		}
	});
	
	$("select").val("");
	$("textarea").val("");
}

function email(first, id, second)
{
	if($("*").is("#" + id))
	{
		if($("#" + id).is("a"))
		{
			$("#" + id).attr("href", "mail" + "to:" + first + String.fromCharCode(64) + second);
		}
		$("#" + id).text(first + String.fromCharCode(64) + second);
	}
	else
	{
		alert("Помилка.\nНевірний параметр id у функції email().\nЕлемент з вказаним id відсутній на сторінці.");
	}
}

function tooltip(element_class, style)
{
	var type = ".";
	if(!$("*").is("." + element_class))
	{
		type = "#";
	}

	if($("*").is(type + element_class))
	{
		var text = "";
		var div = "<div id='tool' style='display: none; position: absolute; padding: 5px; background: #ffffff; width: auto; border: solid #000000 1px; opacity: 0.7; filter: alpha(opacity=70);'>" + text + "</div>";
			$("#tool_box").html(div);
		
		for(var key in style)
		{
			var val = style[key];
			$("#tool").css(key, val);
		}
		
		var width = $("#tool").width();
		var height = "";
	
		$(type + element_class).mouseover(function() {
			text = $(this).attr("title");
			$(this).attr("title", "");
			$("#tool").css("display", "block");
			$("#tool").html(text);
			height = $("#tool").height();
		});
			
		$(type + element_class).mousemove(function(e) {
			var c_width = document.body.clientWidth;
			var left = (c_width < e.clientX + width + 10) ? e.clientX - width - 20 : e.clientX + 10;
			var top = (window.innerHeight < e.clientY + height + 15) ? e.clientY - height - 10 + document.documentElement.scrollTop : e.clientY + 5 + document.documentElement.scrollTop;
	
			$("#tool").css("left", left + "px");
			$("#tool").css("top", top + "px");
		});
		
		$(type + element_class).mouseout(function() {
			$(this).attr("title", text);
			$("#tool").css("display", "none");
		});
	}
}

function submenu(element_class, type, position, time)
{
	function getTop(element)
	{
		var result = element.offsetTop;
		if(element.offsetParent)
		{
			result += getTop(element.offsetParent);
		}
		return result;
	}
	
	function getLeft(element)
	{
		var result = element.offsetLeft;
		if(element.offsetParent)
		{
			result += getLeft(element.offsetParent);
		}
		return result;
	}
		
	if(type == "hover")
	{
		var class_check = 0;
		$("." + element_class).each(function(){
			class_check++;
		});
		
		if(class_check > 0)
		{
			if(position != "vertical" && position != "horizontal")
			{
				alert("Помилка.\nНевірний параметр position у функції submenu().\nДопустимі значення для параметра position:\nposition=vertical/horizontal");
			}
			else
			{
				if(time < 0 || time > 1000)
				{
					alert("Помилка.\nНевірний параметр millitime у функції submenu().\nДопустимі значення для параметра millitime:\nmillitime=[0;1000]");
				}
				else
				{
					$("." + element_class).hover(function() {
						$("." + element_class).stop();
						
						var menu_id = $(this).attr("id");
						var sub_id = "sub_" + menu_id;
						
						$("." + element_class).each(function() {
							var id = "sub_" + $(this).attr("id")
							if($("*").is("#" + id) && $("#" + id).css("display") != "none")
							{
								if(id != sub_id)
								{
									if(time == 0)
									{
										$("#" + id).hide();
									}
									else
									{
										$("#" + id).stop();
										if(position == "vertical")
										{
											$("#" + id).animate({"height": "hide"}, time);
										}
										
										if(position == "horizontal")
										{
											$("#" + id).animate({"width": "hide"}, time);
										}
									}
								}
							}
						});
			
						if($("*").is("#" + sub_id))
						{
							$("#" + sub_id).width("auto");
							$("#" + sub_id).height("auto");
							$("#" + sub_id).css("position", "absolute");
							
							var top = 0;
							var left = 0;
							
							if(position == "vertical")
							{
								top = getTop(document.getElementById(menu_id)) + $("#" + menu_id).height();
								left = getLeft(document.getElementById(menu_id));
							}
							
							if(position == "horizontal")
							{
								top = getTop(document.getElementById(menu_id));
								left = getLeft(document.getElementById(menu_id)) + $("#" + menu_id).width();
							}
							
							$("#" + sub_id).css("top", top);
							$("#" + sub_id).css("left", left);
			
							if(time == 0)
							{
								if(position == "vertical" && $("#" + sub_id).width() < $("#" + menu_id).width())
								{
									$("#" + sub_id).width($("#" + menu_id).width());
								}
								
								$("#" + sub_id).show();
							}
							else
							{
								if(position == "vertical")
								{
									if($("#" + sub_id).width() < $("#" + menu_id).width())
									{
										$("#" + sub_id).width($("#" + menu_id).width());
									}
									
									$("#" + sub_id).animate({"height": "show"}, time);
								}
								
								if(position == "horizontal")
								{
									$("#" + sub_id).animate({"width": "show"}, time);
								}
							}
						}
					}, function() {
						var menu_id = $(this).attr("id");
						var sub_id = "sub_" + menu_id;
						if($("*").is("#" + sub_id))
						{
							if(time == 0)
							{
								$("#" + sub_id).hide();
							}
							else
							{
								$("#" + sub_id).stop();
								if(position == "vertical")
								{
									$("#" + sub_id).animate({"height": "hide"}, time);
								}
								
								if(position == "horizontal")
								{
									$("#" + sub_id).animate({"width": "hide"}, time);
								}
							}
						}
					});
					
					$(".sub_" + element_class).hover(function() {
						$(this).stop();
						$(this).show();
					}, function() {
						if(time == 0)
						{
							$(this).hide();
						}
						else
						{
							if(position == "vertical")
							{
								$(this).animate({"height": "hide"}, time);
							}
							
							if(position == "horizontal")
							{
								$(this).animate({"width": "hide"}, time);
							}
						}
					});
				}
			}
		}
		else
		{
			alert("Помилка.\nНевірний параметр class у функції submenu().\nЕлемент вказаного класу відсутній у документі");
		}
	}
	
	if(type == "click")
	{
		var class_check = 0;
		$("." + element_class).each(function(){
			class_check++;
		});
		
		if(class_check > 0)
		{
			if(position != "vertical" && position != "horizontal")
			{
				alert("Помилка.\nНевірний параметр position у функції submenu().\nДопустимі значення для параметра position:\nposition=vertical/horizontal");
			}
			else
			{
				if(time < 0 || time > 1000)
				{
					alert("Помилка.\nНевірний параметр millitime у функції submenu().\nДопустимі значення для параметра millitime:\nmillitime=[0;1000]");
				}
				else
				{
					$("." + element_class).click(function() {
						$("." + element_class).stop();
						var menu_id = $(this).attr("id");
						var sub_id = "sub_" + menu_id;
						
						$("." + element_class).each(function() {
							var id = "sub_" + $(this).attr("id")
							if($("*").is("#" + id) && $("#" + id).css("display") != "none")
							{
								if(id != sub_id)
								{
									if(time == 0)
									{
										$("#" + id).hide();
									}
									else
									{
										$("#" + id).stop();
										if(position == "vertical")
										{
											$("#" + id).animate({"height": "hide"}, time);
										}
										
										if(position == "horizontal")
										{
											$("#" + id).animate({"width": "hide"}, time);
										}
									}
								}
							}
						});
			
						if($("*").is("#" + sub_id))
						{
							if($("#" + sub_id).css("display") != "none")
							{
								if(time == 0)
								{
									$("#" + sub_id).hide();
								}
								else
								{
									$("#" + sub_id).stop();
									if(position == "vertical")
									{
										$("#" + sub_id).animate({"height": "hide"}, time);
									}
									
									if(position == "horizontal")
									{
										$("#" + sub_id).animate({"width": "hide"}, time);
									}
								}
							}
							else
							{
								$(".sub_" + element_class).width("auto");
								$(".sub_" + element_class).height("auto");
								$("#" + sub_id).css("position", "absolute");
								
								if(position == "vertical")
								{
									var top = getTop(document.getElementById(menu_id)) + $("#" + menu_id).height();
									var left = getLeft(document.getElementById(menu_id));
								}
								
								if(position == "horizontal")
								{
									var top = getTop(document.getElementById(menu_id));
									var left = getLeft(document.getElementById(menu_id)) + $("#" + menu_id).width();
								}
								
								$("#" + sub_id).css("top", top);
								$("#" + sub_id).css("left", left);
				
								if(time == 0)
								{
									if(position == "vertical" && $("#" + sub_id).width() < $("#" + menu_id).width())
									{
										$("#" + sub_id).width($("#" + menu_id).width());
									}
									
									$("#" + sub_id).show();
								}
								else
								{
									if(position == "vertical")
									{
										if($("#" + sub_id).width() < $("#" + menu_id).width())
										{
											$("#" + sub_id).width($("#" + menu_id).width());
										}
										
										$("#" + sub_id).animate({"height": "show"}, time);
									}
									
									if(position == "horizontal")
									{
										$("#" + sub_id).animate({"width": "show"}, time);
									}
								}
							}
						}
					});
				}
			}
		}
		else
		{
			alert("Помилка.\nНевірний параметр class у функції submenu().\nЕлемент вказаного класу відсутній у документі");
		}
	}
	
	if(type != "click" && type != "hover")
	{
		alert("Помилка.\nНевірний параметр type у функції submenu().\nДопустимі значення для параметра type:\ntype=hover/click");
	}
}

function clock(type, ids)
{
	if(type != "12" && type != "24")
	{
		alert("Помилка.\nНевірний параметр type у функції clock().\nДопустимі значення для параметра type:\ntype=12/24");
	}
	else
	{
		time = new Date;
		var time = zero(time.gettime());
		var minutes = zero(time.getMinutes());
		var hours = zero(time.getHours());
		var check = "ok";
		if(type == 12)
		{
			hours = (time.getHours() > 12) ? time.getHours() - 12 : time.getHours();
		}
	
		if($.trim(ids) != "")
		{
			var mas = ids.split(" ");
			var check_ids = "";
			for(i = 0; i < mas.length; i++)
			{
				if($("*").is("#" + mas[i]))
				{
					check_ids += mas[i] + "|";
				}
			}
			if(check_ids != "")
			{
				var error = check_ids.split("|");
				var error_ids = "";
				for(i = 0; i < error.length - 1; i++)
				{
					error_ids += error[i];
					if(i + 2 != error.length)
					{
						error_ids += ", ";
					}
				}
				alert("Помилка.\nНевірний параметр ids у функції clock().\nЕлементів з наступними id неіснує:\n" + error_ids);
				check = "error";
			}
			else
			{
				var ampm = "";
				if(type == 12)
				{
					if(time.getHours() > 12)
					{
						ampm = "pm";
					}
					else
					{
						ampm = "am";
					}
				}
				
				switch(mas.length)
				{
					case 1 : $("#" + mas[0]).text(hours + ":" + minutes + ":" + time + " " + ampm); break;
					case 2 : $("#" + mas[0]).text(hours + ":" + minutes + ":" + time); $("#" + mas[1]).text(ampm); break;
					case 3 : $("#" + mas[0]).text(hours); $("#" + mas[1]).text(minutes); $("#" + mas[2]).text(time); break;
					case 4 : $("#" + mas[0]).text(hours); $("#" + mas[1]).text(minutes); $("#" + mas[2]).text(time); $("#" + mas[3]).text(ampm); break;
					default : alert("Помилка.\nНевірний параметр ids у функції clock().\nВказано забагато id"); break;
				}
			}
		}
		else
		{
			alert("Помилка.\nНевірний параметр ids у функції clock().\nНевказано жодного id");
		}
		
		if(check == "ok")
		{
			setTimeout("clock('" + type + "', '" + ids +"')", 500);
		}
	}
}
/*
function date(day_visible, day_type, month_type, language, ids)
{
	date = new Date;
	var day = "";
	var number = (month_type == "num") ? zero(date.getDate()) : date.getDate();
	var month = "";
	var year = (date.getYear() < 1000) ? date.getYear() + 1900 : date.getYear();
	var er = "ok";
	
	if(language != "ua" && language != "ru" && language != "en")
	{
		alert("Помилка.\nНевірний параметр language у функції date().\nДопустимі значення для параметра language:\nlanguage=ua/ru/en");
		er = "error";
	}
	else
	{
		if(day_visible != "show" && day_visible != "hide")
		{
			alert("Помилка.\nНевірний параметр day_visible у функції date().\nДопустимі значення для параметра day_visible:\nday_visible=show/hide");
			er = "error";
		}
		else
		{
			if(day_visible == "show")
			{
				if(day_type != "short" && day_type != "long")
				{
					alert("Помилка.\nНевірний параметр day_type у функції date().\nДопустимі значення для параметра day_type:\nday_type=short/long");
					er = "error";
				}
				else
				{
					if(day_type == "short")
					{
						var num_day = date.getDay();
						if(language == "ua")
						{
							switch(num_day)
							{
								case 1 : day = "Пн"; break;
								case 2 : day = "Вт"; break;
								case 3 : day = "Ср"; break;
								case 4 : day = "Чт"; break;
								case 5 : day = "Пт"; break;
								case 6 : day = "Сб"; break;
								case 7 : day = "Нд"; break;
							}
						}
						
						if(language == "ru")
						{
							switch(num_day)
							{
								case 1 : day = "Пн"; break;
								case 2 : day = "Вт"; break;
								case 3 : day = "Ср"; break;
								case 4 : day = "Чт"; break;
								case 5 : day = "Пт"; break;
								case 6 : day = "Сб"; break;
								case 7 : day = "Вс"; break;
							}
						}
						
						if(language == "en")
						{
							switch(num_day)
							{
								case 1 : day = "Mon"; break;
								case 2 : day = "Tue"; break;
								case 3 : day = "Wed"; break;
								case 4 : day = "Thu"; break;
								case 5 : day = "Fri"; break;
								case 6 : day = "Sat"; break;
								case 7 : day = "Son"; break;
							}
						}
					}
					
					if(day_type == "long")
					{
						var num_day = date.getDay();
						if(language == "ua")
						{
							switch(num_day)
							{
								case 1 : day = "Понеділок"; break;
								case 2 : day = "Вівторок"; break;
								case 3 : day = "Середа"; break;
								case 4 : day = "Четвер"; break;
								case 5 : day = "П'ятниця"; break;
								case 6 : day = "Субота"; break;
								case 7 : day = "Неділя"; break;
							}
						}
						
						if(language == "ru")
						{
							switch(num_day)
							{
								case 1 : day = "Понедельник"; break;
								case 2 : day = "Вторник"; break;
								case 3 : day = "Среда"; break;
								case 4 : day = "Четверг"; break;
								case 5 : day = "Пятница"; break;
								case 6 : day = "Суббота"; break;
								case 7 : day = "Воскресенье"; break;
							}
						}
						
						if(language == "en")
						{
							switch(num_day)
							{
								case 1 : day = "Monday"; break;
								case 2 : day = "Tuesday"; break;
								case 3 : day = "Wednesday"; break;
								case 4 : day = "Thursday"; break;
								case 5 : day = "Friday"; break;
								case 6 : day = "Saturday"; break;
								case 7 : day = "Sonday"; break;
							}
						}
					}
				}
			}
		}
		
		if(month_type != "short" && month_type != "long" && month_type != "num")
		{
			alert("Помилка.\nНевірний параметр month_type у функції date().\nДопустимі значення для параметра month_type:\nmonth_type=num/short/long");
			er = "error";
		}
		else
		{
			if(month_type == "short")
			{
				if(language == "en")
				{
					var num_month = date.getMonth() + 1;
					if(language == "en")
					{
						switch(num_month)
						{
							case 1 : month = "Jan"; break;
							case 2 : month = "Feb"; break;
							case 3 : month = "Mar"; break;
							case 4 : month = "Apr"; break;
							case 5 : month = "May"; break;
							case 6 : month = "Jun"; break;
							case 7 : month = "Jul"; break;
							case 8 : month = "Aug"; break;
							case 9 : month = "Sep"; break;
							case 10 : month = "Oct"; break;
							case 11 : month = "Nov"; break;
							case 12 : month = "Dec"; break;
						}
					}
				}
				else
				{
					alert("Помилка.\nНевірний параметр month_type у функції date().\nЗначення 'short' для параметра month_type можливе тільки при значенні 'en' для параметра language");
					er = "error";
				}
			}
			
			if(month_type == "long")
			{
				var num_month = date.getMonth() + 1;
				if(language == "ua")
				{
					switch(num_month)
					{
						case 1 : month = "Січня"; break;
						case 2 : month = "Лютого"; break;
						case 3 : month = "Березня"; break;
						case 4 : month = "Квітня"; break;
						case 5 : month = "Травня"; break;
						case 6 : month = "Червня"; break;
						case 7 : month = "Липня"; break;
						case 8 : month = "Серпня"; break;
						case 9 : month = "Вересня"; break;
						case 10 : month = "Жовтня"; break;
						case 11 : month = "Листопада"; break;
						case 12 : month = "Грудня"; break;
					}
				}
				
				if(language == "ru")
				{
					switch(num_month)
					{
						case 1 : month = "Января"; break;
						case 2 : month = "Февраля"; break;
						case 3 : month = "Марта"; break;
						case 4 : month = "Апреля"; break;
						case 5 : month = "Мая"; break;
						case 6 : month = "Июля"; break;
						case 7 : month = "Июня"; break;
						case 8 : month = "Августа"; break;
						case 9 : month = "Сентября"; break;
						case 10 : month = "Октября"; break;
						case 11 : month = "Ноября"; break;
						case 12 : month = "Декабря"; break;
					}
				}
				
				if(language == "en")
				{
					switch(num_month)
					{
						case 1 : month = "January"; break;
						case 2 : month = "February"; break;
						case 3 : month = "March"; break;
						case 4 : month = "April"; break;
						case 5 : month = "May"; break;
						case 6 : month = "June"; break;
						case 7 : month = "July"; break;
						case 8 : month = "August"; break;
						case 9 : month = "September"; break;
						case 10 : month = "October"; break;
						case 11 : month = "November"; break;
						case 12 : month = "December"; break;
					}
				}
			}
			
			if(month_type == "num")
			{
				month = zero(date.getMonth() + 1);
			}
		}
		
		if(er == "ok")
		{
			var mas = ids.split(" ");
			var check_ids = "";
			for(i = 0; i < mas.length; i++)
			{
				if($("*").is("#" + mas[i]))
				{
					check_ids += mas[i] + "|";
				}
			}
			
			if(check_ids != "")
			{
				var error = check_ids.split("|");
				var error_ids = "";
				for(i = 0; i < error.length - 1; i++)
				{
					error_ids += error[i];
					if(i + 2 != error.length)
					{
						error_ids += ", ";
					}
				}
				alert("Помилка.\nНевірний параметр ids у функції date().\nЕлементів з наступними id неіснує:\n" + error_ids);
			}
			else
			{
				if(day != "" && mas.length == 1)
				{
					day += ", "; 
				}
				
				var y = "";
				switch(language)
				{
					case "ua" : y = " р."; break;
					case "ru" : y = " г."; break;
					default : y = ""; break;
				}
				
				var short_year = (year + "").charAt((year + "").length - 2) + (year + "").charAt((year + "").length - 1);
				
				switch(mas.length)
				{
					case 1 : if(month_type == "num")
							 {
								 $("#" + mas[0]).text(day + number + "." + month + "." + short_year);
							 }
							 else
							 {
							 	 $("#" + mas[0]).text(day + number + " " + month + ", " + year + y);
							 }
							 break;
					case 2 : if(month_type == "num")
							 {
							 	 if(day_visible == "show")
							 	 {
								 	 $("#" + mas[0]).text(day);
								 	 $("#" + mas[1]).text(number + "." + month + "." + year);
							 	 }
							 	 
							 	 if(day_visible == "hide")
							 	 {
								 	 $("#" + mas[0]).text(number);
								 	 $("#" + mas[1]).text(month + "." + year);
							 	 }
							 }
							 else
							 {
							 	 if(day_visible == "show")
							 	 {
								 	 $("#" + mas[0]).text(day);
								 	 $("#" + mas[1]).text(number + " " + month + ", " + year + y);
							 	 }
							 	 else
							 	 {
							 	 	 $("#" + mas[0]).text(number + " " + month);
								 	 $("#" + mas[1]).text(year + y);
							 	 }
							 }
							 break;
					case 3 : if(month_type == "num")
							 {
							 	 if(day_visible == "show")
							 	 {
								 	 $("#" + mas[0]).text(day);
								 	 $("#" + mas[1]).text(number);
								 	 $("#" + mas[2]).text(month + "." + year);
							 	 }
							 	 
							 	 if(day_visible == "hide")
							 	 {
								 	 $("#" + mas[0]).text(number);
								 	 $("#" + mas[1]).text(month);
								 	 $("#" + mas[2]).text(year);
							 	 }
							 }
							 else
							 {
							 	 if(day_visible == "show")
							 	 {
								 	 $("#" + mas[0]).text(day);
								 	 $("#" + mas[1]).text(number + " " + month);
								 	 $("#" + mas[2]).text(year + y);
							 	 }
							 	 else
							 	 {
							 	 	 $("#" + mas[0]).text(number);
							 	 	 $("#" + mas[1]).text(month);
								 	 $("#" + mas[2]).text(year + y);
							 	 }
							 }
							 break;
					case 4 : if(month_type == "num")
							 {
							 	 if(day_visible == "show")
							 	 {
								 	 $("#" + mas[0]).text(day);
								 	 $("#" + mas[1]).text(number);
								 	 $("#" + mas[2]).text(month);
								 	 $("#" + mas[2]).text(year);
							 	 }
							 	 
							 	 if(day_visible == "hide")
							 	 {
								 	 alert("Помилка.\nНевірний параметр ids у функції date().\nВказано забагато id");
							 	 }
							 }
							 break;
					default : alert("Помилка.\nНевірний параметр ids у функції date().\nВказано забагато id"); break;
				}
			}
		}
	}
}
*/
function zero(num)
{
	return (num < 10) ? "0" + num : num;
}

function validate(id, symbols, empty, type)
{
	var el = id.split("_");
	var rest = "";
	for(i = 1; i < el.length; i++)
	{
		rest += el[i];
		if(i < el.length - 1)
		{
			rest += "_";
		}
	}
	el[1] = rest;
	
	if($("*").is("#" + id))
	{
		var check_empty = "error";
		if(empty)
		{
			if($.trim($("#" + id).val()) != "")
			{
				check_empty = "ok";
			}
			else
			{
				return true;
			}
		}
		else
		{
			if($.trim($("#" + id).val()) != "")
			{
				check_empty = "ok";
			}
			else
			{
				show_error(el[0] + "_empty_" + el[1]);
				return false;
			}
		}
		
		if(check_empty == "ok")
		{
			if(type == "email")
			{
				var email = $.trim($("#" + id).val());
					email = email.toLowerCase();
				var emailTest = "^[_\\.0-9a-z-]+@([0-9a-z_-]+\\.)+[a-z]{2,4}$"; 
				var regex = new RegExp(emailTest); 
				var check = "";
				if (!regex.test(email) || !(email.length > 0)) 
				{
					check = "error"; 
				}
	
				if(check == "error")
				{
					show_error(el[0] + "_symbol_" + el[1]);
					return false;
				}
				else
				{
					return true;
				}
			}
			else
			{
				if(type == "file")
				{
					var mas = symbols.split("<>");
					var part = $.trim($("#" + id).val()).split(".");
					var end = mas.length;
					for(i = 0; i < end; i++)
					{
						if(mas[i].toLowerCase() == "jpg")
						{
							mas[mas.length] = "jpeg";
							mas[mas.length] = "JPEG";
							mas[mas.length] = "Jpeg";
							mas[mas.length] = "JPG";
							mas[mas.length] = "Jpg";
						}
						
						if(mas[i].toLowerCase() == "gif")
						{
							mas[mas.length] = "GIF";
							mas[mas.length] = "Gif";
						}
						
						if(mas[i].toLowerCase() == "png")
						{
							mas[mas.length] = "PNG";
							mas[mas.length] = "Png";
						}
					}
					var check = "error";
					for(i = 0; i < mas.length; i++)
					{
						if(part[part.length - 1].toLowerCase() == mas[i].toLowerCase())
						{
							check = "ok";
						}
					}

					if(check == "error")
					{
						show_error(el[0] + "_type_" + el[1]);
						return false;
					}
					else
					{
						return true;
					}
				}
				else
				{
					if($.trim(symbols) == "")
					{
						return true;
					}
					else
					{
						var mas = symbols.split("<>");
						var str = $.trim($("#" + id).val());
						var symbols = "";
						for(i = 0; i < str.length; i++)
						{
							var code = str.charCodeAt(i);
							var error = "error";
							for(j = 0; j < mas.length; j++)
							{
								var help = mas[j].split("..");
								if(help.length == 2 && help[0] != "" && help[1] != "")
								{
									if(help[0].charCodeAt(0) == 1040)
									{
										if((code >= help[0].charCodeAt(0) && code <= help[1].charCodeAt(0)) || code == 1025 || code == 1028 || code == 1030 || code == 1031 || code == 13 || code == 10)
										{
											error = "ok";
										}
									}
									else
									{
										if(help[0].charCodeAt(0) == 1072)
										{
											if((code >= help[0].charCodeAt(0) && code <= help[1].charCodeAt(0)) || code == 1105 || code == 1108 || code == 1110 || code == 1111 || code == 13 || code == 10)
											{
												error = "ok";
											}
										}
										else
										{
											if(code >= help[0].charCodeAt(0) && code <= help[1].charCodeAt(0) || code == 13 || code == 10)
											{
												error = "ok";
											}
										}
									}
								}
								else
								{
									if(code == mas[j].charCodeAt(0) || code == 13 || code == 10)
									{
										error = "ok";
									}
								}
							}
							
							if(error == "error")
							{
								var symb_mas = symbols.split(", ");
								var symb_check = true;
								for(l = 0; l < symb_mas.length - 1; l++)
								{
									if(symb_mas[l].replace(/\'/gi, "") == str.charAt(i))
									{
										symb_check = false;
									}
								}
								
								if(symb_check)
								{
									symbols += "'" + str.charAt(i) + "', ";
								}
							}
						}
						
						if(symbols.length > 2)
						{
							var error_text = $("#" + el[0] + "_symbol_" + el[1]).text().split(":");
							//$("#" + el[0] + "_symbol_" + el[1]).text(error_text[0] + ": " + symbols.substring(0, symbols.length - 2));
							show_error(el[0] + "_symbol_" + el[1]);
							return false;
						}
						else
						{
							if(type == "pass")
							{
								if($.trim($("#" + id + "re").val()) != "")
								{
									if($.trim($("#" + id + "re").val()) == $.trim($("#" + id).val()))
									{
										show_error("ok");
										return true;
									}
									else
									{
										show_error(el[0] + "_notsame_" + el[1]);
										return false;
									}
								}
								else
								{
									show_error(el[0] + "_empty_re" + el[1]);
									return false;
								}
							}
							else
							{
								return true;
							}
						}
					}
				}
			}
		}
	}
}

function validate_date(year_id, month_id, day_id)
{
	var year_type = "normal";
	if($.trim($("#" + year_id).val()) != "")
	{
		if(parseInt($.trim($("#" + year_id).val())) % 4 == 0)
		{
			year_type = "intercalary";
		}
		
		if($.trim($("#" + month_id).val()) != "")
		{
			switch($.trim($("#" + month_id).val()))
			{
				case "4": case "6": case "9": case "11":
				{
					if($.trim($("#" + day_id).val()) != "")
					{
						if(parseInt($.trim($("#" + day_id).val())) == 31)
						{
							return "symbol";
						}
						else
						{
							return "ok";
						}
					}
					else
					{
						return "empty";
					}
				}
				
				case "2":
				{
					if($.trim($("#" + day_id).val()) != "")
					{
						if(year_type == "normal")
						{
							if(parseInt($.trim($("#" + day_id).val())) > 28)
							{
								return "symbol";
							}
							else
							{
								return "ok";
							}
						}
						else
						{
							if(parseInt($.trim($("#" + day_id).val())) > 29)
							{
								return "symbol";
							}
							else
							{
								return "ok";
							}
						}
					}
					else
					{
						return "empty";
					}
				}
				
				default: return "ok";
			}
		}
		else
		{
			return "empty";
		}
	}
	else
	{
		return "empty";
	}
}

function print_text_cell(text, id, extra_class)
{
	var lang = $.trim($("#langs_client").val()).split("[:e]");
	var result = "";
	for (k = 0; k < lang.length - 1; k++)
	{
		result += "<td class='td_prev td_changes " + ((extra_class == "") ? "show_meta" : extra_class) + "_lang_" + lang[k] + "'>"; 
		var temp = get_language_text(text, lang[k]);
		if (temp != "")
		{
			result += "<a class='tool_link' title='<p class=\"prev_text\">";
			result += get_preview(temp, 150);
			result += "</p>' >тут</a>"; 
		}
		else
		{
			result += "<span class='span_red'>нема</span>";
			
		}
		
		if (id != "")
		{
			result += "<div class='div_hidden' id='" + id + "'>" + temp + "</div>";
		}
		result += "</td>";
	}
	return result;
}

function get_language_text(text, language)
{ 
	var sep = "[:" + language + "]";
	var start = text.indexOf(sep, 0);

	if (start != -1)
	{
		var end = text.indexOf(sep, start + 1);
		return $.trim(text.substring(start + 5, end));
	}
	else
	{
		return "";
	}
}

function get_preview(text, limit)
{
	if (text != "")
	{
		if (text.length <= limit)
		{
			return text;
		}
		else
		{
			var check = false;
			do
			{
				var symbol = text.charAt(limit);
				if (symbol == "." || symbol == "," || symbol == "!" || symbol == "?" || symbol == ")")
				{
					check = true;
				}
				else
				{
					limit--;
				}
			}
			while(!check)
			return text.subString(0, limit) + "...";
		}
	}
	else
	{
		return "";
	}
}

function get_value_lang(field, is_fck)
{
	var lang = $.trim($("#langs_client").val()).split("[:e]");
	
	field.replace(/\'/gi, '&#39;');
	field.replace(/\"/gi, '&quot;');
	
	if (lang.length > 0)
	{		
		var line = "";
		for (i = 0; i < lang.length - 1; i++)
		{
			if ($("*").is("#" + field + lang[i]))
			{
				var value = "";
				if (is_fck)
				{
					value = $.trim(CKEDITOR.instances[field + lang[i]].getData())
				}
				else
				{
					value = $.trim($("#" + field + lang[i]).val());
				}
				
				if (value != "")
				{
					if(field == "pages_link")
					{
						value = convert_links(value);
					}
					line += "[:" + lang[i] + "]" + value + "[:" + lang[i] + "]";
				}
			}
		}
		return line;
	}
	else
	{
		return '';
	}
}

function convert_links(link)
{
	link = $.trim(link);
	if (link != "")
	{
		var url = (document.location + "").split("/");
		var baseurl = url[2];
		if (link.indexOf(baseurl) + 1)
		{
			var part = link.split(baseurl);
			if(part[1] == "")
			{
				return "/";
			}
			else
			{
				if(part[1].charAt(0) == "/")
				{
					return part[1];
				}
			}
		}
		
		var part = link.split("://");
		if (part.length > 1)
		{
			if (part[1] != "" && part[0] != "")
			{
				return link;
			}
			else
			{
				return "";
			}
		}
		else
		{
			if(link.charAt(0) == "/")
			{
				return link;
			}
			else
			{
				return "/" + link;
			}
		}
	}
	else
	{
		return link;
	}
}

function convert_to_array(string)
{
	var result = new Array();
	if (string != "")
	{
		var line = string.split("[:l]");
		for (i = 0; i < line.length - 1; i++)
		{
			result[i] = new Array();
			var el = line[i].split("[:e]");
			for (j = 0; j < el.length - 1; j++)
			{
				if($.trim(el[j]) != "")
				{
					var item = el[j].split("[:k]");
					result[i][item[0]] = item[1];
				}
			}
		}
	}
	
	return result;
}

function show_checked_cells()
{
	var types = $.trim($("#filter_types").val());
	var langs = $.trim($("#filter_langs").val());
	
	$("td.td_changes").hide();
	$("td.td_changes").each(function() {
		if($(this).hasClass(types + "_" + langs) || $(this).hasClass(types) || $(this).hasClass(langs))
		{
			$(this).show();
		}
	});
}

function show_error(errors_id)
{
	if (segment(1) == "panel")
	{
		$("#" + errors_id).show();
	}
	else
	{
		if ($("*").is("#error_" + errors_id))
		{
			$("#errors_here").html($.trim($("#error_" + errors_id).html()));
			$("div.error_box").animate({"opacity": "show"}, "fast", function() { $(this).show() }).delay(2000).animate({"opacity": "hide"}, "fast", function() { $(this).hide() });
		}
		else
		{
			alert("Відсутня помилка з ідентифікатором 'error_" + errors_id + "'");
		}
	}
}
