function copyFormHtml(button,curRecord,params){
	//alert('copyFormHtml');
	if (params === undefined) {params = {};}
	if (!('indexNum' in params)) {params['indexNum'] = 1;}
	if (!('direction' in params)) {params['direction'] = 'up';}
	if (button.hasClass('addFormDynRecord')){
		if (params['direction'] == 'up'){
			var newRecord = curRecord.clone().insertAfter(curRecord);
		} else {
			var newRecord = curRecord.clone().insertBefore(curRecord);
		}
		newRecord.find("select,textarea").each(function(index,dom){
			$(dom).attr("value",'');
			$(dom).val('');
			$(dom).attr('name',generateNextIdInName($(dom).attr('name'),params['indexNum']));
		});
		newRecord.find("input").each(function(index,dom){
			type = $(dom).attr('type');
			if ((type != 'submit')&&(type != 'button')){
				$(dom).attr("value",'');
				$(dom).val('');
				$(dom).attr('name',generateNextIdInName($(dom).attr('name'),params['indexNum']));
			}
		});
		if (button.html()!=''){button.html('x');}
		button.attr({value:'Удалить',className:'deleteFormDynRecord buttonDel'});
		curRecord.find('.dyntables_hidden').css('display','');
		newRecord.find('.remove').click();
		if (typeof reInitialize == 'function'){reInitialize(newRecord);}
	} else if (button.hasClass('deleteFormDynRecord')){		
		curRecord.remove();
	}
}
/*
*  Для заданного имени формы генерит новое имя. Используется для создания
*  динамических полей формы.
*  dynParam - какой по счету индекс увеличивать
*/
function generateNextIdInName(oldName,indexNum){
	regExps = {
		1: /(^.*?\[)([0-9]+)\]/,
		2: /(^.*?\[[0-9]+\].*?\[)([0-9]+)\]/
	}
	if (indexNum === undefined ) {indexNum = 1;}
	regExp = regExps[indexNum];
	parsedName = regExp.exec(oldName);
	if (parsedName == null){return oldName;}
	return oldName.replace(regExp,'$1'+(++parsedName[2])+']');
}
/*
 * Автозаполнение в динамических записях
 * (при очищении поля - запись удаляется)
 */
function selectedAutoComplete(obj,rpcUrl,hiddenName){	
	obj.autocomplete({
		source: function(req, add){
			$.getJSON(rpcUrl, req, function(data) {
				var suggestions = [];
				if (data != null){
					$.each(data, function(i, val){suggestions.push({label:val.label, name:val.name, id:val.id});});
					add(suggestions);
				}
			});
		},		
		select: function(e, ui) {
			var span = $("").text(ui.item.label);
			var a = $("").addClass("remove").attr({
				href: "javascript:void()",
				title: "Remove " + ui.item.label
			}).text("").appendTo(span);
			
			regExp = /(^.*\[)([^\]]+)\]/;
			oldName = $(this).attr('name');
			newName = oldName.replace(regExp,'$1'+hiddenName+']');
			hidden = $('').attr({
				type : 'hidden',
				name : newName,
				value : ui.item.id
				}).appendTo(span);
			span.insertAfter(this);
			$(this).css("display","none").attr("value",ui.item.label);
			$(this).parent().parent().find('.addFormDynRecord').click();
			if (typeof autoFillRecord == 'function'){autoFillRecord($(this).parent().parent(),ui.item.name);}
			return false;
		}
		
	});
	$(".remove").live("click", function(){
		$(this).parent().parent().find('.autoCompletedInt').val('').css("display","");   ;
		$(this).parent().remove();
		if($(this).parent().find("span").length === 0) {
			$(this).css("top", 0);
		}				
	});
	
	$(".removeRecord").live("click", function(){
		$(this).parent().parent().parent().find('.deleteFormDynRecord').click();			
	});				
}
function isInName(fullName, shortName){
	regExp = new RegExp('^.*\\['+shortName+'\\]$');
	parsedName = regExp.exec(fullName);
	if (parsedName != null) {
		return true;
	} else {
		return false;
	}
}
 
function print_r(theObj){
  if(theObj.constructor == Array ||
     theObj.constructor == Object){
    document.write("")
    for(var p in theObj){
      if(theObj[p].constructor == Array||
         theObj[p].constructor == Object){
document.write("- ["+p+"] => "+typeof(theObj)+"");
        document.write("
")
        print_r(theObj[p]);
        document.write("
")
      } else {
document.write("- ["+p+"] => "+theObj[p]+"");
      }
    }
    document.write("
")
  }
}
 
var dictionaryFind = 'поиск...';
jQuery(document).ready(function($){
	editingRows();
	massage();
	comment();
	jQuery(".m-nav_item-1").hover(
	  function () {
    $(this).addClass("active");
  },
  function () {
    $(this).removeClass("active");
  }
	);
	$('.find').autocomplete({
		source: function( request, response ) {
			var where = $('#where').val();
			$.getJSON( "/ajax/search.php?where="+where, request, function( data, status, xhr ) {
				response( data );
			});
		},
		minLength: 2,
		select: function(e, ui) {
			//$(this).parent().find('input').val(ui.item.id);
		}
	});
});
function editingRows() {
	jQuery('.userMassageRow').mouseover(function() {
		obj = jQuery(this).find('.editing');
		obj.removeClass('displayNone');
	});
	jQuery('.userMassageRow').mouseout(function() {
		obj = jQuery(this).find('.editing');
		obj.addClass('displayNone');
	});
}
function find(obj) {
	obj.value = '';
	$('.findValue').toggleClass('displayNone');
}
function resetAll(obj) {
	//$('.find').val(dictionaryFind);
	jQuery('.findValue').addClass('displayNone');
	jQuery('.profile').addClass('displayNone');
}
function show(obj) {
	$(obj).addClass('showLi');
}
function notshow(obj) {
	$(obj).removeClass('showLi');
}
function setWhere(obj) {
	$('.findWhere').html(obj.innerHTML);
	$('.findValue').addClass('displayNone');
	$('#where').val(obj.value);
}
function showConfigLinks() {
	$('.profile').toggleClass('displayNone');
}
function registerUser() {
	email = $('#email').val();
	password = $('#password').val();
	$('#email').removeClass('error');
	$('#password').removeClass('error');
	if(!isValidEmail(email)) {
		$('#email').addClass('error');
	}
	else if (password == ''){
		$('#password').addClass('error');
	}
	else {
		$('#register').submit();
	}
}
function  getFriend(id, obj) {
	$.post("/ajax/getfriend.php", { id: id },
	function(data) {
		$(obj).parent().html(""+data+"");
	});
}
function  remFriend(fio ,id, obj) {
	if (confirm(fio + " бутет удален из друзей?")){
		$.post("/ajax/remfriend.php", { id: id },
		function(data) {
			$(obj).parent().html(""+data+"");
		});
	}
}
function  argeeFriend(id, obj) {
	var div = $(obj).parent();
	$(obj).remove();
	$.post("/ajax/argeefriend.php", { id: id },
	function(data) {
		div.html(""+data+"");
	});
}
function rotateImgSerg( src , rotate) {
	$.post("/ajax/rotateimg.php", { src: src, rotate:rotate },
	function(data) {
		$('#TB_Image').css('background-image','url('+data+')');
	});
}
function rand( min, max ) {	// Generate a random integer
	//
	// +   original by: Leslie Hoare
	if( max ) {
		return Math.floor(Math.random() * (max - min + 1)) + min;
	} else {
		return Math.floor(Math.random() * (min + 1));
	}
}
function iWillBe(idinvite, obj){
		$(obj).hide();
		$.post("/ajax/invite/iwillbe.php", {  idinvite: idinvite },function(data) {});
} 
var tId;
function deleteMessage(obj, id, idUser) {
	var divka = $(obj).parent().parent().parent().parent().parent();
	divka.removeClass('userMassageRow');
	divka.html('');
	$.post("/ajax/deletemessage.php", { id: id, idUser: idUser },function(data) {});
}
function deleteMessages(idUser) {
	$('#massageBlock').html('');
	$.post("/ajax/deletemessages.php", { idUser: idUser },function(data) {});
}
function showMessageList(mass) {
	var massData ='';
	for(i = mass.length - 1; i>=0; i--) {
		if (mass[i].isRead == 0) read = 'read'; else read = '';
		//massData = massData + '|  |  | '+mass[i].massage+' | '+mass[i].date+'  | 
|  |  | '+mass[i].massage+' | '+mass[i].date+' | 
 ');
		$.post("/ajax/sendcomment.php", {where:where, mass:mass, userId:userId, userName:userName, idPhoto:idPhoto, idObject:idObject },
		function(data) {
			var text = '';
			$('.Comment').append(text);
			editingRows();
			$('#commentKolesiko').html('');
		});
	}
	else {
		alert('Введите сообщение');
	}
	document.getElementById('userMassageTextarea').value='';
}
function getComments(idObject) {
	var page = $('#commPage').val();
	var where = $('#where').val();
	$.post("/ajax/getcomments.php", {  idObject:idObject,where:where, page: page },function(data) {
		if (data != '') {
			$('.Comment').append(data);
			page++;
			$('#commPage').val(page);
		}
		else {
			$('.lookMore').html('');
		}
	});
}
function deleteComment(obj, idObject,idUser) {
	var where = $('#where').val();
	$.post("/ajax/deletecomment.php", {  idObject:idObject,where:where, idUser: idUser },function(data) {});
	$(obj).parent().parent().html('');
} 
function sendOnWall(id_user) {
	var mass = $('.userWallTextarea').val();
	var append = $('#userWallAppendContent').html();
	if ((mass !='' && mass != '\n') || append != '') {
		$.post("/ajax/senduseronwall.php", {  id_user: id_user, mess: mass, append: append  },
		function(data) {
			var data =jQuery.parseJSON(data);
			path = '';
			for(i=0;i"+ append;
			photo = '/files/photo'+path+'/small.jpg';
			if (data.idPhoto == '0') photo = '/images/nophotosmall.jpg';
			var str = '';
			$('#userWall').prepend(str);
			$('.userWallTextarea').val('');
			$('#userWallAppendContent').html('');
			wallListEditing();
		});
	}
	else {
		alert('Введите сообщение');
	}
}
function removeFromUserWall(obj ,id) {
	$(obj).parent().parent().parent().html('').removeClass('userListRow');
	$.post("/ajax/removefromuserwall.php", {  id: id },function(data) {});
}
function getWall(idUser) {	
	page = $('#wallPage').val();
	$.post("/ajax/getwall.php", {  idUser: idUser, page: page },function(data) {
		if (data != '') {
			$('#userWall').append(data);
			page++;
			$('#wallPage').val(page);
			wallListEditing();
		}
		else {
			$('.lookMore').html('');
		}
	});
}
function getWallPhotoes() {
	$.post("/ajax/getwallphotoes.php", {  },function(data) {
		$('#wallContent').html(data);
	});
}
function getWallReports() {
	$.post("/ajax/getwallreports.php", {  },function(data) {
		$('#wallContent').html(data);
	});
}
function getWallVideos() {
	$.post("/ajax/getwallvideos.php", {  },function(data) {
		$('#wallContent').html(data);
	});
}
function appendPhotoOnWall(src, srcBig) {
	$('#userWallAppendContent').html('
');
		$.post("/ajax/sendcomment.php", {where:where, mass:mass, userId:userId, userName:userName, idPhoto:idPhoto, idObject:idObject },
		function(data) {
			var text = '';
			$('.Comment').append(text);
			editingRows();
			$('#commentKolesiko').html('');
		});
	}
	else {
		alert('Введите сообщение');
	}
	document.getElementById('userMassageTextarea').value='';
}
function getComments(idObject) {
	var page = $('#commPage').val();
	var where = $('#where').val();
	$.post("/ajax/getcomments.php", {  idObject:idObject,where:where, page: page },function(data) {
		if (data != '') {
			$('.Comment').append(data);
			page++;
			$('#commPage').val(page);
		}
		else {
			$('.lookMore').html('');
		}
	});
}
function deleteComment(obj, idObject,idUser) {
	var where = $('#where').val();
	$.post("/ajax/deletecomment.php", {  idObject:idObject,where:where, idUser: idUser },function(data) {});
	$(obj).parent().parent().html('');
} 
function sendOnWall(id_user) {
	var mass = $('.userWallTextarea').val();
	var append = $('#userWallAppendContent').html();
	if ((mass !='' && mass != '\n') || append != '') {
		$.post("/ajax/senduseronwall.php", {  id_user: id_user, mess: mass, append: append  },
		function(data) {
			var data =jQuery.parseJSON(data);
			path = '';
			for(i=0;i"+ append;
			photo = '/files/photo'+path+'/small.jpg';
			if (data.idPhoto == '0') photo = '/images/nophotosmall.jpg';
			var str = '';
			$('#userWall').prepend(str);
			$('.userWallTextarea').val('');
			$('#userWallAppendContent').html('');
			wallListEditing();
		});
	}
	else {
		alert('Введите сообщение');
	}
}
function removeFromUserWall(obj ,id) {
	$(obj).parent().parent().parent().html('').removeClass('userListRow');
	$.post("/ajax/removefromuserwall.php", {  id: id },function(data) {});
}
function getWall(idUser) {	
	page = $('#wallPage').val();
	$.post("/ajax/getwall.php", {  idUser: idUser, page: page },function(data) {
		if (data != '') {
			$('#userWall').append(data);
			page++;
			$('#wallPage').val(page);
			wallListEditing();
		}
		else {
			$('.lookMore').html('');
		}
	});
}
function getWallPhotoes() {
	$.post("/ajax/getwallphotoes.php", {  },function(data) {
		$('#wallContent').html(data);
	});
}
function getWallReports() {
	$.post("/ajax/getwallreports.php", {  },function(data) {
		$('#wallContent').html(data);
	});
}
function getWallVideos() {
	$.post("/ajax/getwallvideos.php", {  },function(data) {
		$('#wallContent').html(data);
	});
}
function appendPhotoOnWall(src, srcBig) {
	$('#userWallAppendContent').html(' ');
	tb_remove();
}
function appendReportOnWall(src, srcBig,title) {
	$('#userWallAppendContent').html(title+'
');
	tb_remove();
}
function appendReportOnWall(src, srcBig,title) {
	$('#userWallAppendContent').html(title+'
 ');
	tb_remove();
}
function appendVideoOnWall(src, srcBig,title) {
	$('#userWallAppendContent').html(title+'
');
	tb_remove();
}
function appendVideoOnWall(src, srcBig,title) {
	$('#userWallAppendContent').html(title+'
 ');
	tb_remove();
}
function wallListEditing() {
	$('.userListRow').mouseover(function() {
		obj = $(this).find('.editing');
		obj.removeClass('displayNone');
	});
	$('.userListRow').mouseout(function() {
		obj = $(this).find('.editing');
		obj.addClass('displayNone');
	});
} 
function removeUserPhotoAlbum(obj ,idUser, idPhotoAlbum) {
	if (confirm("Вы действительно хотите удалить фотоальбом?")){
		$(obj).parent().parent().parent().parent().parent().parent().html('').removeClass('userMassageRow');
		$.post("/ajax/removeuserphotoalbum.php", {  idUser: idUser, idPhotoAlbum: idPhotoAlbum },function(data) {});
	}
}
function removeUserPhotoAlbum1(obj ,idUser, idPhotoAlbum) {
	if (confirm("Вы действительно хотите удалить фотоальбом?")){		
		$.post("/ajax/removeuserphotoalbum.php", {  idUser: idUser, idPhotoAlbum: idPhotoAlbum },function(data) {
			document.location.href='/photoalbums/id/'+idUser;			
		});
	}
}
function removeUserPhoto(obj ,idPhoto) {
	$(obj).parent().html('').removeClass('photoAlbumDiv');
	$.post("/ajax/removeuserphoto.php", {  idPhoto: idPhoto },function(data) {});
}
function setMainImg(idPhotoAlbum, idImg) {
	$.post("/ajax/setmainimg.php", {  idPhotoAlbum: idPhotoAlbum, idImg: idImg },function(data) {});
}
function setAvatarImg(idPhotoAlbum, idImg) {
	$.post("/ajax/setavatarimg.php", {  idPhotoAlbum: idPhotoAlbum, idImg: idImg },function(data) {});
}
function setAvatarImgFromWall(idPhotoAlbum, idImg, userId) {
	$.post("/ajax/setavatarimg.php", {  idPhotoAlbum: idPhotoAlbum, idImg: idImg },function(data) {});
	window.location.href='/user/id/'+userId;
}
function PhotoesAlbumLike(idVideo,like,obj) {
	jQuery(obj).removeAttr("onclick");
	var num = parseInt(jQuery(obj).find('span').text(), 10);
	if (isNaN(num)) num = 0;
	num = num + 1;
	jQuery(obj).find('span').text(num);
	jQuery.post("/ajax/photoalbumlike.php", {  idVideo: idVideo, like: like },function(data) {});
} 
function removeUserArticle(obj ,idUser, idArticle) {
	if (confirm("Вы действительно хотите удалить статью?")){
		$(obj).parent().parent().parent().parent().parent().parent().html('').removeClass('userMassageRow');
		$.post("/ajax/removeuserarticle.php", {  idUser: idUser, idArticle: idArticle },function(data) {});
	}
}
function removeUserArticle1(obj ,idUser, idArticle) {
	if (confirm("Вы действительно хотите удалить статью?")){		
		$.post("/ajax/removeuserarticle.php", {  idUser: idUser, idArticle: idArticle },function(data) {
			document.location.href='/articles/id/'+idUser;
		});
	}
}
function removeUserArticlePhoto(obj ,idPhoto) {
	$(obj).parent().parent().html('').removeClass('photoAlbumDiv');
	$.post("/ajax/removeuserarticlephoto.php", {  idPhoto: idPhoto },function(data) {});
}
function setMainImgArticle(idPhotoAlbum, idImg) {
	$.post("/ajax/setmainimgarticle.php", {  idPhotoAlbum: idPhotoAlbum, idImg: idImg },function(data) {});
} 
function removeUserVideo(obj ,idUser, idVideo) {
	if (confirm("Вы действительно хотите удалить видеозапись?")){
		$(obj).parent().parent().parent().parent().parent().parent().html('').removeClass('userMassageRow');
		$.post("/ajax/removeuservideo.php", {  idUser: idUser, idVideo: idVideo },function(data) {});
	}
}
function removeVideo(obj ,idUser, idVideo) {
	if (confirm("Вы действительно хотите удалить видеозапись?")){
		$(obj).parent().parent().parent().parent().parent().parent().html('').removeClass('userMassageRow');
		$.post("/ajax/removevideo.php", {  idUser: idUser, idVideo: idVideo },function(data) {});
	}
}
function removeUserVideo1(obj ,idUser, idVideo) {
	if (confirm("Вы действительно хотите удалить видеозапись?")){
		$.post("/ajax/removeuservideo.php", {  idUser: idUser, idVideo: idVideo },function(data) {
			document.location.href='/videos/id/'+idUser;
		});
	}
}
function removeVideo1(obj ,idUser, idVideo) {
	if (confirm("Вы действительно хотите удалить видеозапись?")){		
		$.post("/ajax/removevideo.php", {  idUser: idUser, idVideo: idVideo },function(data) {
			document.location.href='/videos';
		});
	}
}
function userAddVideo(idVideo, obj) {
	$.post("/ajax/useraddvideo.php", { idVideo: idVideo },function(data) {
		$(obj).parent().html(data);
	});
}
function VideoLike(idVideo,like,obj) {
	jQuery(obj).removeAttr("onclick");
	var num = parseInt(jQuery(obj).find('span').text(), 10);
	if (isNaN(num)) num = 0;
	num = num + 1;
	jQuery(obj).find('span').text(num);
	jQuery.post("/ajax/videolike.php", {  idVideo: idVideo, like: like },function(data) {});
} 
function dialogWindow(){
	$( "#popupWindow" ).dialog({
		height: 140,
		modal: true
	});
} 
function validateNotEmpty(data, fieldName) {
	if (data == '') return 'Поле '+fieldName+' обязательное для заполнения'; else return '';
}
function isValidEmail (email)
{
	var re = /^\w+([\.-]?\w+)*@(((([a-z0-9]{2,})|([a-z0-9][-][a-z0-9]+))[\.][a-z0-9])|([a-z0-9]+[-]?))+[a-z0-9]+\.([a-z]{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum))$/i;
	return re.test(email);
}
 
function removeUserShop(obj ,idUser, idShop) {
	if (confirm("Вы действительно хотите удалить магазин?")){
		$(obj).parent().parent().parent().parent().parent().parent().html('').removeClass('userMassageRow');
		$.post("/ajax/removeusershop.php", {  idUser: idUser, idShop: idShop },function(data) {});
	}
}
function removeUserShop1(obj ,idUser, idShop) {
	if (confirm("Вы действительно хотите удалить магазин?")){
		$.post("/ajax/removeusershop.php", {  idUser: idUser, idShop: idShop },function(data) {
			document.location.href='/shops';
		});
	}
}
function setMainImgProduct(idPhotoAlbum, idImg, userId) {
	$.post("/ajax/catalog/setmainimgproduct.php", {  idPhotoAlbum: idPhotoAlbum, idImg: idImg, id:userId },function(data) {});
}
function removeProductPhoto(obj ,idPhoto, userId) {
	$(obj).parent().parent().html('').removeClass('photoAlbumDiv');
	$.post("/ajax/catalog/removeproductphoto.php", {  idPhoto: idPhoto, id: userId },function(data) {});
}
function removeProduct(obj ,idUser, idProduct) {
	if (confirm("Вы действительно хотите удалить товар?")){
		jQuery(obj).parent().parent().parent().parent().parent().parent().html('').removeClass('userMassageRow');
		jQuery.post("/ajax/catalog/removeproduct.php", {  idUser: idUser, idProduct: idProduct },function(data) {});
	}
}
function removeProduct1(obj ,idUser, idProduct) {
	if (confirm("Вы действительно хотите удалить товар?")){
		jQuery.post("/ajax/catalog/removeproduct.php", {  idUser: idUser, idProduct: idProduct },function(data) {
			document.location.href='/shop';
		});
	}
}
function saveImgProductByLink(obj,idProduct,userId) {
	var link = $(obj).parent().find('input').val();
	if (link != '') {
		$.post("/ajax/catalog/saveimgproductbylink.php", {  link: link,idProduct: idProduct, id: userId },function(data) {
			if (data == 1) {
				location.href='/shop/catalog/productedit/idproduct/'+idProduct+/id/+userId;
			}
			else {
				alert (data);
			}
		});
	}
}
function saveTitleForProduct(idImg, obj, userId) {
	var title = $(obj).parent().find('input').val();
	jQuery.post("/ajax/catalog/savetitleforproduct.php", {  idImg: idImg, title: title, id: userId },function(data) {
		alert('Заголовок сохранен');
	});
}
function shopProductLike(idProduct,like,obj) {
	jQuery(obj).removeAttr("onclick");
	var num = parseInt(jQuery(obj).find('span').text(), 10);
	if (isNaN(num)) num = 0;
	num = num + 1;
	jQuery(obj).find('span').text(num);
	jQuery.post("/ajax/catalog/like.php", {  idProduct: idProduct, like: like },function(data) {});
}
function goToProduct(idProduct) {
	jQuery.post("/ajax/catalog/click.php", {  idProduct: idProduct },function(data) {});
}
function getShopAtrrib(title) {
	$('#listattribs').html('
');
	tb_remove();
}
function wallListEditing() {
	$('.userListRow').mouseover(function() {
		obj = $(this).find('.editing');
		obj.removeClass('displayNone');
	});
	$('.userListRow').mouseout(function() {
		obj = $(this).find('.editing');
		obj.addClass('displayNone');
	});
} 
function removeUserPhotoAlbum(obj ,idUser, idPhotoAlbum) {
	if (confirm("Вы действительно хотите удалить фотоальбом?")){
		$(obj).parent().parent().parent().parent().parent().parent().html('').removeClass('userMassageRow');
		$.post("/ajax/removeuserphotoalbum.php", {  idUser: idUser, idPhotoAlbum: idPhotoAlbum },function(data) {});
	}
}
function removeUserPhotoAlbum1(obj ,idUser, idPhotoAlbum) {
	if (confirm("Вы действительно хотите удалить фотоальбом?")){		
		$.post("/ajax/removeuserphotoalbum.php", {  idUser: idUser, idPhotoAlbum: idPhotoAlbum },function(data) {
			document.location.href='/photoalbums/id/'+idUser;			
		});
	}
}
function removeUserPhoto(obj ,idPhoto) {
	$(obj).parent().html('').removeClass('photoAlbumDiv');
	$.post("/ajax/removeuserphoto.php", {  idPhoto: idPhoto },function(data) {});
}
function setMainImg(idPhotoAlbum, idImg) {
	$.post("/ajax/setmainimg.php", {  idPhotoAlbum: idPhotoAlbum, idImg: idImg },function(data) {});
}
function setAvatarImg(idPhotoAlbum, idImg) {
	$.post("/ajax/setavatarimg.php", {  idPhotoAlbum: idPhotoAlbum, idImg: idImg },function(data) {});
}
function setAvatarImgFromWall(idPhotoAlbum, idImg, userId) {
	$.post("/ajax/setavatarimg.php", {  idPhotoAlbum: idPhotoAlbum, idImg: idImg },function(data) {});
	window.location.href='/user/id/'+userId;
}
function PhotoesAlbumLike(idVideo,like,obj) {
	jQuery(obj).removeAttr("onclick");
	var num = parseInt(jQuery(obj).find('span').text(), 10);
	if (isNaN(num)) num = 0;
	num = num + 1;
	jQuery(obj).find('span').text(num);
	jQuery.post("/ajax/photoalbumlike.php", {  idVideo: idVideo, like: like },function(data) {});
} 
function removeUserArticle(obj ,idUser, idArticle) {
	if (confirm("Вы действительно хотите удалить статью?")){
		$(obj).parent().parent().parent().parent().parent().parent().html('').removeClass('userMassageRow');
		$.post("/ajax/removeuserarticle.php", {  idUser: idUser, idArticle: idArticle },function(data) {});
	}
}
function removeUserArticle1(obj ,idUser, idArticle) {
	if (confirm("Вы действительно хотите удалить статью?")){		
		$.post("/ajax/removeuserarticle.php", {  idUser: idUser, idArticle: idArticle },function(data) {
			document.location.href='/articles/id/'+idUser;
		});
	}
}
function removeUserArticlePhoto(obj ,idPhoto) {
	$(obj).parent().parent().html('').removeClass('photoAlbumDiv');
	$.post("/ajax/removeuserarticlephoto.php", {  idPhoto: idPhoto },function(data) {});
}
function setMainImgArticle(idPhotoAlbum, idImg) {
	$.post("/ajax/setmainimgarticle.php", {  idPhotoAlbum: idPhotoAlbum, idImg: idImg },function(data) {});
} 
function removeUserVideo(obj ,idUser, idVideo) {
	if (confirm("Вы действительно хотите удалить видеозапись?")){
		$(obj).parent().parent().parent().parent().parent().parent().html('').removeClass('userMassageRow');
		$.post("/ajax/removeuservideo.php", {  idUser: idUser, idVideo: idVideo },function(data) {});
	}
}
function removeVideo(obj ,idUser, idVideo) {
	if (confirm("Вы действительно хотите удалить видеозапись?")){
		$(obj).parent().parent().parent().parent().parent().parent().html('').removeClass('userMassageRow');
		$.post("/ajax/removevideo.php", {  idUser: idUser, idVideo: idVideo },function(data) {});
	}
}
function removeUserVideo1(obj ,idUser, idVideo) {
	if (confirm("Вы действительно хотите удалить видеозапись?")){
		$.post("/ajax/removeuservideo.php", {  idUser: idUser, idVideo: idVideo },function(data) {
			document.location.href='/videos/id/'+idUser;
		});
	}
}
function removeVideo1(obj ,idUser, idVideo) {
	if (confirm("Вы действительно хотите удалить видеозапись?")){		
		$.post("/ajax/removevideo.php", {  idUser: idUser, idVideo: idVideo },function(data) {
			document.location.href='/videos';
		});
	}
}
function userAddVideo(idVideo, obj) {
	$.post("/ajax/useraddvideo.php", { idVideo: idVideo },function(data) {
		$(obj).parent().html(data);
	});
}
function VideoLike(idVideo,like,obj) {
	jQuery(obj).removeAttr("onclick");
	var num = parseInt(jQuery(obj).find('span').text(), 10);
	if (isNaN(num)) num = 0;
	num = num + 1;
	jQuery(obj).find('span').text(num);
	jQuery.post("/ajax/videolike.php", {  idVideo: idVideo, like: like },function(data) {});
} 
function dialogWindow(){
	$( "#popupWindow" ).dialog({
		height: 140,
		modal: true
	});
} 
function validateNotEmpty(data, fieldName) {
	if (data == '') return 'Поле '+fieldName+' обязательное для заполнения'; else return '';
}
function isValidEmail (email)
{
	var re = /^\w+([\.-]?\w+)*@(((([a-z0-9]{2,})|([a-z0-9][-][a-z0-9]+))[\.][a-z0-9])|([a-z0-9]+[-]?))+[a-z0-9]+\.([a-z]{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum))$/i;
	return re.test(email);
}
 
function removeUserShop(obj ,idUser, idShop) {
	if (confirm("Вы действительно хотите удалить магазин?")){
		$(obj).parent().parent().parent().parent().parent().parent().html('').removeClass('userMassageRow');
		$.post("/ajax/removeusershop.php", {  idUser: idUser, idShop: idShop },function(data) {});
	}
}
function removeUserShop1(obj ,idUser, idShop) {
	if (confirm("Вы действительно хотите удалить магазин?")){
		$.post("/ajax/removeusershop.php", {  idUser: idUser, idShop: idShop },function(data) {
			document.location.href='/shops';
		});
	}
}
function setMainImgProduct(idPhotoAlbum, idImg, userId) {
	$.post("/ajax/catalog/setmainimgproduct.php", {  idPhotoAlbum: idPhotoAlbum, idImg: idImg, id:userId },function(data) {});
}
function removeProductPhoto(obj ,idPhoto, userId) {
	$(obj).parent().parent().html('').removeClass('photoAlbumDiv');
	$.post("/ajax/catalog/removeproductphoto.php", {  idPhoto: idPhoto, id: userId },function(data) {});
}
function removeProduct(obj ,idUser, idProduct) {
	if (confirm("Вы действительно хотите удалить товар?")){
		jQuery(obj).parent().parent().parent().parent().parent().parent().html('').removeClass('userMassageRow');
		jQuery.post("/ajax/catalog/removeproduct.php", {  idUser: idUser, idProduct: idProduct },function(data) {});
	}
}
function removeProduct1(obj ,idUser, idProduct) {
	if (confirm("Вы действительно хотите удалить товар?")){
		jQuery.post("/ajax/catalog/removeproduct.php", {  idUser: idUser, idProduct: idProduct },function(data) {
			document.location.href='/shop';
		});
	}
}
function saveImgProductByLink(obj,idProduct,userId) {
	var link = $(obj).parent().find('input').val();
	if (link != '') {
		$.post("/ajax/catalog/saveimgproductbylink.php", {  link: link,idProduct: idProduct, id: userId },function(data) {
			if (data == 1) {
				location.href='/shop/catalog/productedit/idproduct/'+idProduct+/id/+userId;
			}
			else {
				alert (data);
			}
		});
	}
}
function saveTitleForProduct(idImg, obj, userId) {
	var title = $(obj).parent().find('input').val();
	jQuery.post("/ajax/catalog/savetitleforproduct.php", {  idImg: idImg, title: title, id: userId },function(data) {
		alert('Заголовок сохранен');
	});
}
function shopProductLike(idProduct,like,obj) {
	jQuery(obj).removeAttr("onclick");
	var num = parseInt(jQuery(obj).find('span').text(), 10);
	if (isNaN(num)) num = 0;
	num = num + 1;
	jQuery(obj).find('span').text(num);
	jQuery.post("/ajax/catalog/like.php", {  idProduct: idProduct, like: like },function(data) {});
}
function goToProduct(idProduct) {
	jQuery.post("/ajax/catalog/click.php", {  idProduct: idProduct },function(data) {});
}
function getShopAtrrib(title) {
	$('#listattribs').html(' ');
	jQuery.post("/ajax/catalog/getshopatrrib.php", {  title: title },function(data) {
		$('#listattribs').html(data);
	});
}
function getShopFilters(title) {
	$('#listfilters').html('
');
	jQuery.post("/ajax/catalog/getshopatrrib.php", {  title: title },function(data) {
		$('#listattribs').html(data);
	});
}
function getShopFilters(title) {
	$('#listfilters').html(' ');
	jQuery.post("/ajax/catalog/getshopfilters.php", {  title: title },function(data) {
		$('#listfilters').html(data);
	});
} 
function removeUserFishingbase(obj ,idUser, idFishingbase) {
	if (confirm("Вы действительно хотите удалить рыболовную базу?")){
		$(obj).parent().parent().parent().parent().parent().parent().html('').removeClass('userMassageRow');
		$.post("/ajax/removeuserfishingbase.php", {  idUser: idUser, idFishingbase: idFishingbase },function(data) {});
	}
}
function removeUserFishingbase1(obj ,idUser, idFishingbase) {
	if (confirm("Вы действительно хотите удалить рыболовную базу?")){
		$.post("/ajax/removeuserfishingbase.php", {  idUser: idUser, idFishingbase: idFishingbase },function(data) {
			document.location.href='/fishingbases';
		});
	}
}
function removeFishbaseDisCount(obj ,idUser, idFishingbase,idDiscount) {
	if (confirm("Вы действительно хотите удалить эту скидку?")){
		$(obj).parent().parent().html('').removeClass('userMassageRow');
		$.post("/ajax/removefishbasediscount.php", {  idUser: idUser, idFishingbase: idFishingbase,idDiscount: idDiscount },function(data) {});
	}
}
function removeUserPhotoFishingbase(obj ,idPhoto) {
	$(obj).parent().html('').removeClass('photoAlbumDiv');
	$.post("/ajax/removeuserphotofishingbase.php", {  idPhoto: idPhoto },function(data) {});
}
function activeFishbase(idfishbase,obj) {
	activefield = $(obj).find('.active').val();
	
	if (activefield == 1) {
		
		$(obj).find('.active').val(0);
		$(obj).find('img').attr("title", "Показать");
		$(obj).parent().parent().parent().parent().parent().parent().addClass('notActive');
		active = 0;
	}
	else  {
		$(obj).find('.active').val(1);
		$(obj).find('img').attr("title", "Скрыть");
		$(obj).parent().parent().parent().parent().parent().parent().removeClass('notActive');
		active = 1;
	}
	$.post("/ajax/active/activefishbase.php", {  idfishbase: idfishbase,active:active },function(data) {});
}
function attachedFishbase(idfishbase,obj) {
	activefield = $(obj).find('.attache').val();
	
	if (activefield == 1) {		
		$(obj).find('.attache').val(0);
		$(obj).find('img').attr("title", "Прикркпить");		
		attached = 0;
	}
	else  {
		$(obj).find('.attache').val(1);
		$(obj).find('img').attr("title", "Открепить");		
		attached = 1;
	}
	$.post("/ajax/active/attachefishbase.php", {  idfishbase: idfishbase,attached:attached },function(data) {});
} 
function removeUserCook(obj ,idUser, idAd) {
	if (confirm("Вы действительно хотите удалить рецепт?")){
		$(obj).parent().parent().parent().parent().parent().parent().html('').removeClass('userMassageRow');
		$.post("/ajax/removeuserad.php", {  idUser: idUser, idAd: idAd },function(data) {});
	}
}
function removeUserCook1(obj ,idUser, idCook) {
	if (confirm("Вы действительно хотите удалить рецепт?")){		
		$.post("/ajax/removeusercook.php", {  idUser: idUser, idCook: idCook },function(data) {
			document.location.href='/cooks/id/'+idUser;
		});
	}
}
');
	jQuery.post("/ajax/catalog/getshopfilters.php", {  title: title },function(data) {
		$('#listfilters').html(data);
	});
} 
function removeUserFishingbase(obj ,idUser, idFishingbase) {
	if (confirm("Вы действительно хотите удалить рыболовную базу?")){
		$(obj).parent().parent().parent().parent().parent().parent().html('').removeClass('userMassageRow');
		$.post("/ajax/removeuserfishingbase.php", {  idUser: idUser, idFishingbase: idFishingbase },function(data) {});
	}
}
function removeUserFishingbase1(obj ,idUser, idFishingbase) {
	if (confirm("Вы действительно хотите удалить рыболовную базу?")){
		$.post("/ajax/removeuserfishingbase.php", {  idUser: idUser, idFishingbase: idFishingbase },function(data) {
			document.location.href='/fishingbases';
		});
	}
}
function removeFishbaseDisCount(obj ,idUser, idFishingbase,idDiscount) {
	if (confirm("Вы действительно хотите удалить эту скидку?")){
		$(obj).parent().parent().html('').removeClass('userMassageRow');
		$.post("/ajax/removefishbasediscount.php", {  idUser: idUser, idFishingbase: idFishingbase,idDiscount: idDiscount },function(data) {});
	}
}
function removeUserPhotoFishingbase(obj ,idPhoto) {
	$(obj).parent().html('').removeClass('photoAlbumDiv');
	$.post("/ajax/removeuserphotofishingbase.php", {  idPhoto: idPhoto },function(data) {});
}
function activeFishbase(idfishbase,obj) {
	activefield = $(obj).find('.active').val();
	
	if (activefield == 1) {
		
		$(obj).find('.active').val(0);
		$(obj).find('img').attr("title", "Показать");
		$(obj).parent().parent().parent().parent().parent().parent().addClass('notActive');
		active = 0;
	}
	else  {
		$(obj).find('.active').val(1);
		$(obj).find('img').attr("title", "Скрыть");
		$(obj).parent().parent().parent().parent().parent().parent().removeClass('notActive');
		active = 1;
	}
	$.post("/ajax/active/activefishbase.php", {  idfishbase: idfishbase,active:active },function(data) {});
}
function attachedFishbase(idfishbase,obj) {
	activefield = $(obj).find('.attache').val();
	
	if (activefield == 1) {		
		$(obj).find('.attache').val(0);
		$(obj).find('img').attr("title", "Прикркпить");		
		attached = 0;
	}
	else  {
		$(obj).find('.attache').val(1);
		$(obj).find('img').attr("title", "Открепить");		
		attached = 1;
	}
	$.post("/ajax/active/attachefishbase.php", {  idfishbase: idfishbase,attached:attached },function(data) {});
} 
function removeUserCook(obj ,idUser, idAd) {
	if (confirm("Вы действительно хотите удалить рецепт?")){
		$(obj).parent().parent().parent().parent().parent().parent().html('').removeClass('userMassageRow');
		$.post("/ajax/removeuserad.php", {  idUser: idUser, idAd: idAd },function(data) {});
	}
}
function removeUserCook1(obj ,idUser, idCook) {
	if (confirm("Вы действительно хотите удалить рецепт?")){		
		$.post("/ajax/removeusercook.php", {  idUser: idUser, idCook: idCook },function(data) {
			document.location.href='/cooks/id/'+idUser;
		});
	}
}