;jQuery.xc = {
	debug:0,profileNewWin:1,self:this,L:{},D:null,emo:null,uid:0,vip:0,rollusr:null,pag:null,havePhoto:null,

	loader: function(obj,t){
		if (typeof t == 'undefined') {t='big';}
		var l = {big:'loader-large.gif',mid:'loader-middle.gif',small:'loader-small.gif',none:'x.gif'};
		return $(obj).busyBox({spinner:'<img src="/bin/img/'+l[t]+'" alt="Loading..." />'})
	},
	save: function(obj, a, callback, s) {
		if (obj.running) {
			return false;
		}
		obj.running = 1;
		if (typeof a == 'undefined'){a=1};
		var loading = $(obj).busyBox({spinner:'<img src="/bin/protoload/bigWaiting.gif" alt="Loading..." />'});
		var f = $('form', $(obj).dialog('widget'));
		$.ajax({type:$(f).attr('method'), url:$(f).attr('action'), data:$(f).serialize(), success:function(msg){
			loading.busyBox('close');
			obj.running = 0;
			if (msg.OK && a) {
				$(obj).dialog('destroy');
				if (msg.OK != 1){ $().alert(msg.OK); }
				if (callback && typeof callback != 'undefined') {callback(msg);}
			} else if (msg.ERR && a) {
				if ($('div.err', f).length) {
					$('.err', f).html(msg.ERR);
				} else {
					$().alert(msg.ERR, msg.T ? {title:msg.T}:{});
				}
			} else if (a) {
				//alert('Something went wrong. Please try again.');
			}
		}});
		return false;
	},
	saveForm: function(f, callback) {
		var l = this.loader(f);
		$.ajax({type:$(f).attr('method'), url:$(f).attr('action'), data:$(f).serialize(), success:function(msg){
			l.busyBox('close');
			if (msg.OK) {
				if (typeof callback != 'undefined') {
					callback(msg);
				} else {
					$().alert(msg.OK);
				}
			} else if (msg.ERR) {
				if ($('div.err', f).lenght) {
					$('.err', f).html(msg.ERR);
				} else {
					$().alert(msg.ERR, msg.T ? {title:msg.T}:{});
				}
			} else {
				alert('Something went wrong. Please try again.');
			}
			return false;
		}});
		return false;
	},
	cityList: function(obj, to) {
		if ($(obj).val() == '' || $(obj).val() == '0'){
			$('#' + to).attr('selectedIndex', 0);
			$('#' + to).attr('disabled',true);return false;
		}
		var l = $(obj).busyBox({spinner:'<img src="/Applications/Page/Views/Images/bussy.gif" alt="Loading..." />'});
		$('#' + to).attr('disabled',true);
		$('#' + to).load('/User/DataEX/GetCities/?countryISO=' + $(obj).val(), function(){l.busyBox('close');$('#' + to).attr('disabled',false);});
	},
	getLocation: function(city, country) {
		var cityID = '#' + city.replace('Name', 'ID');
		$("#" + city).autocomplete({
			source: function(request, response) {
				$.getJSON("/User/DataEX/searchCity/?country=" + $('#' + country).val() +'&term=' + request.term, null, response)
			},
			minLength: 2,
			select: function(event, ui) {
				$(cityID).val(ui.item.id);
			},
			change: function(event, ui) {
				if (!ui.item) { $(cityID).val(''); }
			}
		});
		$('#' + country).change(function(){
			$(cityID).val('');
			$("#" + city).val('');
		});
		$('#' + city).change(function(){
			if ($(this).val() == ''){
				$(cityID).val('');
			}
		});
		$('#' + city).keypress(function(e){
			if (e.keyCode && e.keyCode == 13) {
				$('#' + city).blur();
				return false;
			}
		});
	},

	// -------------- comments ----------------
	comment: function(recID,node){
		var f = $('<div class="popup" title="'+$.xc.L.Message+'"><form method="get" action="#" class="simple popup"><div><input type="hidden" name="node" value="'+node+'" /><input type="hidden" name="userID" value="'+recID+'" /><label>'+$.xc.L.Message+'</label><textarea rows="10" cols="30" name="message"></textarea></div></form></div>');
		var btSave = {buttons:{}}
		btSave.buttons[$.xc.L.Send] = function(){var loading = $.xc.loader(f);$.ajax({url:'/Comments/Data/AddComment/', data:$('form', f).serialize(), success:function(msg){loading.busyBox('close');$(f).dialog('destroy');if ($(msg.OK)) {$('#totalComm'+recID).html(msg.total);$().alert(msg.OK);}}});};
		$(f).prompt(btSave);
	},
	addComment: function(f,addTo){
		var l = this.loader($(f),'small');
		$.ajax({url:$(f).attr('action'), type:$(f).attr('method'), data:$(f).serialize(),success:function(h){
			l.busyBox('close');
			if (h) {
				$(addTo).prepend(h);
				if ($('#profileCommCnt')){$('#profileCommCnt').html(parseInt($('#profileCommCnt').html())+1);}
			}
			$(f).find('textarea').val('');
		}});
		return false;
	},
	deleteComment: function(id){
		$(this).confirm($.xc.L.delComm, function(){$.ajax({url:'/Comments/Data/RMComment/?commentID='+id,success:function(){
			$('#com'+id).remove();
			if ($('#profileCommCnt')){$('#profileCommCnt').html(parseInt($('#profileCommCnt').html())-1);}
			if (parseInt($('#profileCommCnt').html())<=0){$('#profileCommCnt').up(2).hide()}
		}});});
		return false;
	},

	// -------------- events ----------------
	joinEvent: function(o,eid) {
		$.ajax({url:'/Event/Data/joinEvent/?eventID='+eid,success:function(msg){if(msg.OK){$().alert(msg.OK);$(o).hide();$('#participants'+eid).innerHTML=msg.total;}}});
	},
	unJoinEvent: function(o,eid) {
		$.ajax({url:'/Event/Data/unJoinEvent/?eventID='+eid,success:function(msg){if(msg.OK){$().alert(msg.OK);$('#MyJoinedEvent'+eid).remove();}}});
	},
	deleteEvent: function(msg,eid){
		$(this).confirm(msg, function(){$.ajax({url:'/Event/Data/DeleteEvent/?eventID='+eid,success:function(){ $('#MyJoinedEvent'+eid).remove();$('#MyEvent'+eid).remove(); }})});return false;
	},

	// -------------- msg ----------------
	delConv: function(o, cID, type, archive){
		var msg = (cID ? $.xc.L.delConv : (archive ? $.xc.L.convArch : $.xc.L.delConvs));
		$(this).confirm(msg, function(){
			if (cID) {
				$.ajax({url:'/Conversations/Data/RemoveGroup/?groupID='+cID+'&type='+type, success:function(){
					$(o).closest('table').remove();
					if ($('#convContainer input[type=checkbox]').length == 0){
						$('#convContainer').load('/Conversations/');
					}
				}});
			} else {
				var ids = new Array();
				$('.conv input[type=checkbox]').each(function(){ if (this.checked){ids.push($(this).val());} });
				if (ids.length > 0) {
					$.ajax({url:'/Conversations/Data/'+(typeof(archive)=="undefined" ? 'Remove' : 'Archive')+'Groups/?ids=' +ids.join(',')+'&type='+type, success:function(){
						$(ids).each(function(k,v){
							$('#Group'+v).remove();
						});
						if ($('#convContainer input[type=checkbox]').length == 0){
							$('#convContainer').load('/Conversations/');
						}
					}});
				}
			}
		});
	},
	delTip: function(o, tipID){
		$(this).confirm($.xc.L.delConv, function(){
			$.ajax({url:'/Conversations/Data/RemoveTip/?tipID=' + tipID, success:function(){
				$(o).closest('table').remove();
			}});
		});
	},
	convSpam: function(cID) {
		$(this).confirm($.xc.L.convSpam, function(){
			$.ajax({url:'/Conversations/Data/ReportSpam/?messageID='+cID, success:function(){
				$().alert($.xc.L.Done);
			}});
		});
	},
	delMsg: function(o, mID, type){
		$(this).confirm($.xc.L.delMsg, function(){
			$.ajax({url:'/Conversations/Data/RemoveMessage/?messageID='+mID+'&type='+type, success:function(){
				$(o).closest('table').remove();
				if ($('#content-full table.message').length == 0) {
					var u = $.getUrlVars();
					$('#content-full').load('/Conversations/ReadGroup/?conversationID=' + u['conversationID'] + '&type=' + u['type']);
				}
			}});
		});
	},
	convAsRead: function(){
		$(this).confirm($.xc.L.convAsRead, function(){
			var ids = new Array();
			$('.conv input[type=checkbox]').each(function(){ if (this.checked){ids.push($(this).val());} });
			if (ids.length > 0) {
				$.ajax({url:'/Conversations/Data/markAsRead/?ids=' +ids.join(','), success:function(){
					$(ids).each(function(k,v){
						$('#Group'+v).removeClass("message-unread");
					});
				}});
			}
		});
	},
	voteTip: function(o,tid){
		$.ajax({url:'/Conversations/Data/VoteTip/?tid='+tid+'&val='+$(o).val(), success:function(m){
			$(o).closest('div').html(m.OK);
		}});
	},
	stayinconv: function(o) {
		if (!$(o).attr('checked')) {
			$('#convlink').attr('href', '/?Q=44852c73');
		} else {
			$('#convlink').attr('href', '/?Q=dddd27f9&53315650&type=1&conversationID=' + $(o).val());
		}
		$.ajax({url:'/Conversations/Data/StayInConv/?cid='+$(o).val()+'&ac='+$(o).attr('checked'), success:function(m){

		}});
	},
	quickReply: function(o) {
		$(o).attr('disabled', true);
		var f = $(o).parent();
		$.ajax({url:'/Conversations/Data/quickReply/', type:'POST', data:$(f).serialize(), success:function(m) {
			$(o).closest('table').removeClass('message-unread');
			$(o).up(4).html(m.M);
		}});
	},

	// -------------- friends ----------------
	friendToggle: function(o,relID){
		$.ajax({url:'/User/DataEX/showHideRelationship/?relationshipID='+relID, success:function(msg){
			o.innerHTML = parseInt(msg.Hidden) ? $.xc.L.Show : $.xc.L.Hide;
			var p = $(o).parent().parent();
			parseInt(msg.Hidden) ? p.addClass('inactive') : p.removeClass('inactive');
			if (parseInt(msg.Hidden)){$().alert($.xc.L.friendHidded)}
		}});
	},
	friendRem: function(o,uID){
		$(this).confirm($.xc.L.remFriend, function(){
			var l = $.xc.loader($('#content div:first-child').get(0));
			$.ajax({url:'/User/DataEX/RemoveRelationship/?withUserID='+uID, success:function(){
				l.busyBox('close');
				$(o).closest('td').remove();
			}});
		});
	},
	remBlocked: function(o,uID){
		$(this).confirm($.xc.L.remBlocked, function(){
			var l = $.xc.loader($('#content-left'));
			$.ajax({url:'/User/Data/RemoveRelationship/?withUserID='+uID+'&type=ignore', success:function(){
				l.busyBox('close');
				$(o).closest('td').remove();
			}});
		});
	},

	// -------------- profile ----------------
	profile: function(){
		$('#previews img').each(function(){
			if ($(this).attr('longdesc')){
				$(this).click(function(){
					if ($(this).attr('longdesc') == 'invisible') {
						$("#invInfo").pop();
					} else if ($(this).attr('longdesc') == 'locked') {

					} else {
						$.xc.loader($('#main-img'), 'none');
						$('#bigPreview').attr('src', $(this).attr('longdesc'));
					}
				});
			}
		});
		$('#bigPreview').load(function(){
			$('#main-img').busyBox('close');
		});
	},
	viewPhoto: function(o){
		if ($.xc.vip) {
			window.open(o.src.replace(/\/F\/[^\/]+\//, '/F/'));
		} else {
			$(o).pop('/Popups/Vip/');
		}
		return false;
	},
	sendGift: function(o,gID,toID,toName,free){
		if (!free) {
			$(this).confirm($.xc.L.giftConfirm.replace('%s', toName), function(){
				$.xc.sg(o,gID,toID,toName,free);
			});
		} else {
			this.sg(o,gID,toID,toName,free);
		}
	},
	sg: function(o,gID,toID,toName,free){
		var l = this.loader($('#gifts'));
		$.ajax({url:'/User/DataEX/sendGift/?id='+gID+'&toUser='+toID,success:function(msg){
			if (msg.OK) {
				l.busyBox('close');
				$('#gifts').parent().dialog('destroy');
				if ($('#main-img a[class*=usr]').length >= 10) {
					$('#main-img a[class*=usr]:last').remove();
				}
				var	cNr = 2;
				$('#main-img a[class*=usr] img').each(function(){
					$(this).attr('className', 'gift gift'+(cNr++));
				});
				$('<a href="/?Q=b56becc7&userID='+$.xc.uid+'" class="usr_'+$.xc.uid+'"><img alt="" class="gift gift1" src="/themes/default/Views/Images/gifts/g'+gID+'.png?1"></a>').prependTo('#main-img');
				$.xc.rolldown($('#main-img'));
			} else {
				l.busyBox('close');
				$().alert(msg.ERR);
			}
		}});
	},
	//  -------------- vip & x ----------------
	buyVip: function(o,days) {
		var l = this.loader($('#buyVIP'));
		$.ajax({url:'/Wallet/DataEX/buyVIPMembership/?days='+days, success:function(msg){
			l.busyBox('close');
			if (msg.OK) {
				$('#buyVIP').parent().dialog('destroy');
				$.xc.vip=1;
				if ($('#xAmount').length){
					$('#xAmount span:first-child').html($('#xAmount span:first-child').html() - msg.CR);
				}
				if ($('#vipexp').length) {
					$('#vipexp').html(msg.VT);
				}
				$().alert(msg.OK);
			} else {
				$().alert(msg.ERR);
			}
		}});
	},
	check900: function(o,code){
		var l = this.loader($(o).parent().parent());
		$.ajax({url:'/Wallet/Data/check900Code/?code='+$(code).val(), success:function(msg){
			l.busyBox('close');
			if (msg.OKMSG) {
				$(o).parent().parent().dialog('destroy');
				$.xc.vip=1;
				$().alert(msg.OKMSG);
			} else {
				$().alert(msg.ERR);
			}
		}});
	},

	// -------------- rolldown ----------------
	sendMsg: function(o,u) {
		var usr = u || $.xc.rollusr;
		if ($('#msgSendPop'+usr[0]).length > 0) {
			f = $('#msgSendPop'+usr[0])
		} else {
			var f = $('<div class="popup" title="'+$.xc.L.writeTo+': '+usr[1]+'" id="msgSendPop'+usr[0]+'"><form method="get" action="#" class="simple popup"><div><input type="hidden" name="userID" value="'+usr[0]+'" /><label style="width:70px !important"><img src="'+usr[2]+'" alt="'+$.xc.L.Message+'" /></label><textarea rows="10" cols="30" name="message" id="quickMsg'+usr[0]+'"></textarea></div><a href="javascript:void(0)" style="position:absolute;right:11px;bottom;0" onclick="$(this).emo(\'#quickMsg'+usr[0]+'\',\'#emolist'+usr[0]+'\');"><img src="/themes/default/Views/Images/emoticons/smile.gif" alt="" /></a></form>'+this.emoList('emolist'+usr[0])+'</div>');
		}
		$(f).find('textarea').val('');
		var btSave = {buttons:{}}
		btSave.buttons[$.xc.L.Send] = function(){
			var self = this;
			if (self.r) {
				return false;
			}
			if (!self.r) {
				self.r = 1;
			}
			var l = $.xc.loader(f);
			$.ajax({url:'/Conversations/Data/SendMessage/', data:$('form', f).serialize(), success:function(msg){
				self.r = 0;
				l.busyBox('close');
				$(f).dialog('destroy');
				if ($(typeof(msg.OK) == 'object' && msg.OK)) { $().alert(msg.OK); }
			}})
		};
		$(f).prompt(btSave, {dialogClass:'ui-default ui-sendmsg'});
	},
	mainPics: function(o,u){
		var usr = u || $.xc.rollusr;
		$(this).pop('/File/DataEX/GetFilesInFolder/?userID='+usr[0]+'&folderID=0&type=image');
	},
	getAlbums: function(o,u){
		var usr = u || $.xc.rollusr;
		$(this).pop('/File/DataEX/GetFolders/?userID='+usr[0]);
	},
	getVideo: function(o,u){
		var usr = u || $.xc.rollusr;
		$(this).pop('/File/DataEX/GetFilesInFolder/?userID='+usr[0]+'&folderID=0&type=video');
	},
	addFriend: function(o,u){
		var usr = u || $.xc.rollusr;
		var f = $('<div class="popup" title="'+$.xc.L.inviteFriend+': '+usr[1]+'"><form method="get" action="#" class="simple popup"><div><label style="width:70px !important"><img src="'+usr[2]+'" alt="'+$.xc.L.Message+'" /></label><input type="hidden" name="withUserID" value="'+usr[0]+'" /><textarea rows="10" cols="30" name="message" onkeypress="return $.xc.maxLen(this,250)"></textarea></div></form></div>');
		var btSave = {buttons:{}}
		btSave.buttons[$.xc.L.Send] = function(){
			var l = $.xc.loader(f);
			$.ajax({url:'/User/Data/CreateRelationship/', data:$('form', f).serialize(), success:function(msg){
				l.busyBox('close');
				$(f).dialog('destroy');
				if ($(msg.OK)) {$().alert(msg.OK);}
			}})
		};
		$(f).prompt(btSave);
	},
	addToBlackList: function(o,u){
		var usr = u || $.xc.rollusr;
		var l = $.xc.loader(o,'small');
		$.ajax({url:'/User/Data/CreateRelationship/?withUserID='+usr[0]+'&type=ignore', success:function(msg){
			l.busyBox('close');
			if ($(msg.OK)) {$().alert(msg.OK);}
		}});
	},
	markAsFake: function(o,u){
		var usr = u || $.xc.rollusr;
		$(o).confirm($(o).attr('title'), function(){
			var l = $.xc.loader(o,'small');
			$.ajax({url:'/User/DataEX/markAsFake/?userID='+usr[0], success:function(msg){
				l.busyBox('close');
				if ($(msg.OK)) {$().alert(msg.OK);}
			}});
		});
	},
	permRequest: function(o,u,t,nid,p){
		nid=nid||0; p=p||4;
		var usr = u || $.xc.rollusr;
		var f = $('<div class="popup" title="'+$.xc.L.unlockReason+'"><form method="get" action="#" class="simple popup"><div><label style="width:auto !important">'+$.xc.L.Message+'</label>'
				+ '<input type="hidden" name="userID" value="'+usr[0]+'" />'
				+ '<input type="hidden" name="type" value="'+t+'" />'
				+ '<input type="hidden" name="nodeID" value="'+nid+'" />'
				+ '<input type="hidden" name="perm" value="'+p+'" />'
				+ '<textarea rows="10" cols="30" name="message" onkeypress="return $.xc.maxLen(this,250)"></textarea></div></form></div>');
		var btSave = {buttons:{}}
		btSave.buttons[$.xc.L.Send] = function(){
			var l = $.xc.loader(f);
			$.ajax({url:'/User/Data/SendPermRequest/', data:$('form', f).serialize(), success:function(msg){
				l.busyBox('close');
				$(f).dialog('destroy');
				if ($(msg.OK)) {$().alert(msg.OK);}
			}})
		};
		$(f).prompt(btSave);
	},

	// -------------- permissions ----------------
	acceptRequest: function(o,rID){
		var l = this.loader($('#content-left'));
		$.ajax({url:'/User/Data/AceptRequest/?requestID='+rID,success:function(msg){
			$('#content-left').html(msg);
			l.busyBox('close');
		}});
	},
	rejectRequest: function(o,rID){
		$.ajax({url:'/User/Data/RejectRequest/?requestID='+rID, success:function(){
			if ($('table tr', $(o).closest('div')).length == 1) {
				$(o).closest('div').remove();
			} else {
				$(o).closest('tr').remove();
			}
		}});
	},
	removeFromGroup: function(o,uid,gid){
		$(this).confirm($.xc.L.remPerm, function(){
			var l = $.xc.loader($(o).closest('table'));
			$.ajax({url:'/User/DataEX/RemoveUserFromGroup/?userID='+uid+'&groupID='+gid, success:function(){
				l.busyBox('close');
				if ($('td', $(o).up(5)).length == 1) {
					$(o).up(6).remove();
				} else {
					$(o).closest('td').remove();
				}
			}});
		});
	},

	// -------------- settings ----------------
	chUsername: function() {
		settings = {buttons:{}};
		settings.buttons[$.xc.L.Save] = function(){$.xc.save($('#chLogin'),1, function(m){$('#userName').html(m.U)});};
		$('#chLogin').prompt(settings);
	},
	confirmNumber: function(m) {
		$('#profilePercents').html(m.P<100 ? ' ['+m.P+'%]' : '');
		if (m.ConfirmNumber) {
			settings = {buttons:{},width:350};
			settings.buttons[$.xc.L.Save] = function(){ $.xc.save($('#cNumber'),1, function(m){
				$('#userPhoneNumber').val(m.number);
				$('#confirmNumberLink').hide();
				$('#confirmNumberLink2').hide();
			})};
			$('#cNumber').prompt(settings);
		} else if (m.OK) {
			$().alert(m.OK);
		}
	},
	rmFile: function(o,fid){
		var l = this.loader($(o).closest('div.list'));
		$.ajax({url:'/File/Data/rmFile/?fileID='+fid+'&getlist',success:function(msg){
			l.busyBox('close');
			$(o).closest('div.list').html(msg+'<p class="clear"></p>');
			$(o).closest('div.list').find('a[class*=blank]').attr('target', '_blank');
		}});
	},
	makeMain: function(o,fid){
		var l = this.loader($(o).closest('div.list'));
		$.ajax({url:'/File/Data/setMain/?fileID='+fid,success:function(msg){
			$(o).closest('div.list').html(msg+'<p class="clear"></p>');
			l.busyBox('close');
			$(o).closest('div.list').find('a[class*=blank]').attr('target', '_blank');
		}});
	},
	chOrder: function(o,fid){
		var l = this.loader($(o).closest('div.list'));
		$.ajax({url:'/File/Data/chOrder/?fileID='+fid+'&ord=' +$(o).val(),success:function(msg){
			$(o).closest('div.list').html(msg+'<p class="clear"></p>');
			l.busyBox('close');
			$(o).closest('div.list').find('a[class*=blank]').attr('target', '_blank');
		}});
	},
	chPerms: function(o,fid){
		var l = this.loader($(o).up(), 'small');
		$('input', $(o).up(3)).attr('disabled',false);
		$.ajax({url:'/File/Data/setFilePermissions/?fileID='+fid+'&permissions=' +$(o).val(),success:function(msg){
			l.busyBox('close');
		}});
		return true;
	},
	newFolder: function(o) {
		f = $(o);
		var btSave = {buttons:{}}
		btSave.buttons[$.xc.L.Save] = function(){
			var l = $.xc.loader(f);
			$.ajax({url:'/File/DataEX/makeFolder/', data:$('form', f).serialize(), success:function(msg){
				l.busyBox('close');
				$(f).dialog('destroy');
				if (msg.ERR) {
					$().alert(msg.ERR,{hideAfter:100});
				} else {
					if ($('#stabs-3').length) {
						$('#stabs-3').html(msg);
					} else {
						$('#ui-tabs-3').html(msg);
					}
				}
			}});
		};
		$(o).prompt(btSave);
	},
	rmFolder: function(o,fid){
		$(this).confirm($.xc.L.remAlbum, function(){
			var l = $.xc.loader($(o).up(2));
			$.ajax({url:'/File/DataEX/RMFolder/?id='+fid,success:function(msg){
				l.busyBox('close');
				if (msg.OK) {
					$(o).up(2).remove();
				}
			}});
		});
	},
	getList: function(fid,type,rand){
		var l = this.loader($('#uploadList'+rand));
		$.ajax({url:'/File/Data/getList/?folderID='+fid+'&type=' +type,success:function(msg){
			$('#uploadList'+rand).html(msg+'<p class="clear"></p>');
			l.busyBox('close');
			$('#uploadList'+rand).find('a[class*=blank]').attr('target', '_blank');
		}});
	},
	loadFolder: function(o,fid) {
		var p = $(o).closest('div');
		var l = this.loader(p);
		$.ajax({url:'/File/SettingsImages/?folderID='+fid+'&type=image',success:function(msg){
			$(p).html(msg);
			l.busyBox('close');
			$(o).closest('div.list').find('a[class*=blank]').attr('target', '_blank');
		}});
		return false;
	},
	getFolders: function(o){
		var p = $(o).up(3);
		var l = this.loader(p);
		$.ajax({url:'/File/SettingsFolders/',success:function(msg){
			$(p).html(msg);
			l.busyBox('close');
		}});
		return false;
	},

	// -------------- common ----------------
	emoList: function(id) {
		id = id || 'emolist';
		return '<table id="'+id+'" class="none"><tr><td><img src="/themes/default/Views/Images/emoticons/acute.gif" alt="acute" /></td><td><img src="/themes/default/Views/Images/emoticons/aggressive.gif" alt="aggressive" /></td><td><img src="/themes/default/Views/Images/emoticons/agree.gif" alt="agree" /></td><td><img src="/themes/default/Views/Images/emoticons/air_kiss.gif" alt="air_kiss" /></td><td><img src="/themes/default/Views/Images/emoticons/angrybang.gif" alt="angrybang" /></td><td><img src="/themes/default/Views/Images/emoticons/backbang.gif" alt="backbang" /></td><td><img src="/themes/default/Views/Images/emoticons/bad.gif" alt="bad" /></td><td><img src="/themes/default/Views/Images/emoticons/bananabang.gif" alt="bananabang" /></td><td><img src="/themes/default/Views/Images/emoticons/bananadogy.gif" alt="bananadogy" /></td><td><img src="/themes/default/Views/Images/emoticons/bedbang.gif" alt="bedbang" /></td></tr><tr><td><img src="/themes/default/Views/Images/emoticons/bedbang2.gif" alt="bedbang2" /></td><td><img src="/themes/default/Views/Images/emoticons/beee.gif" alt="beee" /></td><td><img src="/themes/default/Views/Images/emoticons/black_eye.gif" alt="black_eye" /></td><td><img src="/themes/default/Views/Images/emoticons/blum.gif" alt="blum" /></td><td><img src="/themes/default/Views/Images/emoticons/blum2.gif" alt="blum2" /></td><td><img src="/themes/default/Views/Images/emoticons/blush.gif" alt="blush" /></td><td><img src="/themes/default/Views/Images/emoticons/blush2.gif" alt="blush2" /></td><td><img src="/themes/default/Views/Images/emoticons/boast.gif" alt="boast" /></td><td><img src="/themes/default/Views/Images/emoticons/bobiiespin.gif" alt="bobiiespin" /></td><td><img src="/themes/default/Views/Images/emoticons/boobies.gif" alt="boobies" /></td></tr><tr><td><img src="/themes/default/Views/Images/emoticons/boredom.gif" alt="boredom" /></td><td><img src="/themes/default/Views/Images/emoticons/censored.gif" alt="censored" /></td><td><img src="/themes/default/Views/Images/emoticons/clapping.gif" alt="clapping" /></td><td><img src="/themes/default/Views/Images/emoticons/cray.gif" alt="cray" /></td><td><img src="/themes/default/Views/Images/emoticons/cray2.gif" alt="cray2" /></td><td><img src="/themes/default/Views/Images/emoticons/d.gif" alt="d" /></td><td><img src="/themes/default/Views/Images/emoticons/dance.gif" alt="dance" /></td><td><img src="/themes/default/Views/Images/emoticons/dance2.gif" alt="dance2" /></td><td><img src="/themes/default/Views/Images/emoticons/dance3.gif" alt="dance3" /></td><td><img src="/themes/default/Views/Images/emoticons/dance4.gif" alt="dance4" /></td></tr><tr><td><img src="/themes/default/Views/Images/emoticons/declare.gif" alt="declare" /></td><td><img src="/themes/default/Views/Images/emoticons/derisive.gif" alt="derisive" /></td><td><img src="/themes/default/Views/Images/emoticons/dirol.gif" alt="dirol" /></td><td><img src="/themes/default/Views/Images/emoticons/dntknw.gif" alt="dntknw" /></td><td><img src="/themes/default/Views/Images/emoticons/doggy.gif" alt="doggy" /></td><td><img src="/themes/default/Views/Images/emoticons/don-t_mention.gif" alt="don-t_mention" /></td><td><img src="/themes/default/Views/Images/emoticons/download.gif" alt="download" /></td><td><img src="/themes/default/Views/Images/emoticons/dream.gif" alt="dream" /></td><td><img src="/themes/default/Views/Images/emoticons/drinks.gif" alt="drinks" /></td><td><img src="/themes/default/Views/Images/emoticons/evildoggy.gif" alt="evildoggy" /></td></tr><tr><td><img src="/themes/default/Views/Images/emoticons/f.gif" alt="f" /></td><td><img src="/themes/default/Views/Images/emoticons/first_move.gif" alt="first_move" /></td><td><img src="/themes/default/Views/Images/emoticons/flashing.gif" alt="flashing" /></td><td><img src="/themes/default/Views/Images/emoticons/flashme.gif" alt="flashme" /></td><td><img src="/themes/default/Views/Images/emoticons/fool.gif" alt="fool" /></td><td><img src="/themes/default/Views/Images/emoticons/friends.gif" alt="friends" /></td><td><img src="/themes/default/Views/Images/emoticons/girl_blum2.gif" alt="girl_blum2" /></td><td><img src="/themes/default/Views/Images/emoticons/girl_cray2.gif" alt="girl_cray2" /></td><td><img src="/themes/default/Views/Images/emoticons/girl_dance.gif" alt="girl_dance" /></td><td><img src="/themes/default/Views/Images/emoticons/girl_devil.gif" alt="girl_devil" /></td></tr><tr><td><img src="/themes/default/Views/Images/emoticons/girl_drink1.gif" alt="girl_drink1" /></td><td><img src="/themes/default/Views/Images/emoticons/girl_drink4.gif" alt="girl_drink4" /></td><td><img src="/themes/default/Views/Images/emoticons/girl_hide.gif" alt="girl_hide" /></td><td><img src="/themes/default/Views/Images/emoticons/girl_in_love.gif" alt="girl_in_love" /></td><td><img src="/themes/default/Views/Images/emoticons/girl_pinkglassesf.gif" alt="girl_pinkglassesf" /></td><td><img src="/themes/default/Views/Images/emoticons/girl_prepare_fish.gif" alt="girl_prepare_fish" /></td><td><img src="/themes/default/Views/Images/emoticons/girl_witch.gif" alt="girl_witch" /></td><td><img src="/themes/default/Views/Images/emoticons/good.gif" alt="good" /></td><td><img src="/themes/default/Views/Images/emoticons/good2.gif" alt="good2" /></td><td><img src="/themes/default/Views/Images/emoticons/good3.gif" alt="good3" /></td></tr><tr><td><img src="/themes/default/Views/Images/emoticons/grannyflash.gif" alt="grannyflash" /></td><td><img src="/themes/default/Views/Images/emoticons/grin.gif" alt="grin" /></td><td><img src="/themes/default/Views/Images/emoticons/handcufs.gif" alt="handcufs" /></td><td><img src="/themes/default/Views/Images/emoticons/happybang.gif" alt="happybang" /></td><td><img src="/themes/default/Views/Images/emoticons/hardbang.gif" alt="hardbang" /></td><td><img src="/themes/default/Views/Images/emoticons/heat.gif" alt="heat" /></td><td><img src="/themes/default/Views/Images/emoticons/help.gif" alt="help" /></td><td><img src="/themes/default/Views/Images/emoticons/hysteric.gif" alt="hysteric" /></td><td><img src="/themes/default/Views/Images/emoticons/i-m_so_happy.gif" alt="i-m_so_happy" /></td><td><img src="/themes/default/Views/Images/emoticons/ireful1.gif" alt="ireful1" /></td></tr><tr><td><img src="/themes/default/Views/Images/emoticons/ireful2.gif" alt="ireful2" /></td><td><img src="/themes/default/Views/Images/emoticons/ireful3.gif" alt="ireful3" /></td><td><img src="/themes/default/Views/Images/emoticons/kiss3.gif" alt="kiss3" /></td><td><img src="/themes/default/Views/Images/emoticons/kissass.gif" alt="kissass" /></td><td><img src="/themes/default/Views/Images/emoticons/laugh2.gif" alt="laugh2" /></td><td><img src="/themes/default/Views/Images/emoticons/laugh3.gif" alt="laugh3" /></td><td><img src="/themes/default/Views/Images/emoticons/lazy.gif" alt="lazy" /></td><td><img src="/themes/default/Views/Images/emoticons/lazy2.gif" alt="lazy2" /></td><td><img src="/themes/default/Views/Images/emoticons/lazy3.gif" alt="lazy3" /></td><td><img src="/themes/default/Views/Images/emoticons/love.gif" alt="love" /></td></tr><tr><td><img src="/themes/default/Views/Images/emoticons/mda.gif" alt="mda" /></td><td><img src="/themes/default/Views/Images/emoticons/meeting.gif" alt="meeting" /></td><td><img src="/themes/default/Views/Images/emoticons/mosking.gif" alt="mosking" /></td><td><img src="/themes/default/Views/Images/emoticons/nea.gif" alt="nea" /></td><td><img src="/themes/default/Views/Images/emoticons/negative.gif" alt="negative" /></td><td><img src="/themes/default/Views/Images/emoticons/no2.gif" alt="no2" /></td><td><img src="/themes/default/Views/Images/emoticons/nobang.gif" alt="nobang" /></td><td><img src="/themes/default/Views/Images/emoticons/noti.gif" alt="noti" /></td><td><img src="/themes/default/Views/Images/emoticons/offtopic.gif" alt="offtopic" /></td><td><img src="/themes/default/Views/Images/emoticons/ok.gif" alt="ok" /></td></tr><tr><td><img src="/themes/default/Views/Images/emoticons/pardon.gif" alt="pardon" /></td><td><img src="/themes/default/Views/Images/emoticons/pleasantry.gif" alt="pleasantry" /></td><td><img src="/themes/default/Views/Images/emoticons/polling.gif" alt="polling" /></td><td><img src="/themes/default/Views/Images/emoticons/popcorm1.gif" alt="popcorm1" /></td><td><img src="/themes/default/Views/Images/emoticons/popcorm2.gif" alt="popcorm2" /></td><td><img src="/themes/default/Views/Images/emoticons/punish.gif" alt="punish" /></td><td><img src="/themes/default/Views/Images/emoticons/punish2.gif" alt="punish2" /></td><td><img src="/themes/default/Views/Images/emoticons/read.gif" alt="read" /></td><td><img src="/themes/default/Views/Images/emoticons/resent.gif" alt="resent" /></td><td><img src="/themes/default/Views/Images/emoticons/rofl.gif" alt="rofl" /></td></tr><tr><td><img src="/themes/default/Views/Images/emoticons/sad.gif" alt="sad" /></td><td><img src="/themes/default/Views/Images/emoticons/scare.gif" alt="scare" /></td><td><img src="/themes/default/Views/Images/emoticons/scare2.gif" alt="scare2" /></td><td><img src="/themes/default/Views/Images/emoticons/sclerosis.gif" alt="sclerosis" /></td><td><img src="/themes/default/Views/Images/emoticons/scratch.gif" alt="scratch" /></td><td><img src="/themes/default/Views/Images/emoticons/search.gif" alt="search" /></td><td><img src="/themes/default/Views/Images/emoticons/secret.gif" alt="secret" /></td><td><img src="/themes/default/Views/Images/emoticons/shab1.gif" alt="shab1" /></td><td><img src="/themes/default/Views/Images/emoticons/shab2.gif" alt="shab2" /></td><td><img src="/themes/default/Views/Images/emoticons/shab3.gif" alt="shab3" /></td></tr><tr><td><img src="/themes/default/Views/Images/emoticons/shout.gif" alt="shout" /></td><td><img src="/themes/default/Views/Images/emoticons/showerbang.gif" alt="showerbang" /></td><td><img src="/themes/default/Views/Images/emoticons/smile.gif" alt="smile" /></td><td><img src="/themes/default/Views/Images/emoticons/smoke.gif" alt="smoke" /></td><td><img src="/themes/default/Views/Images/emoticons/snooks.gif" alt="snooks" /></td><td><img src="/themes/default/Views/Images/emoticons/sorry.gif" alt="sorry" /></td><td><img src="/themes/default/Views/Images/emoticons/sorry2.gif" alt="sorry2" /></td><td><img src="/themes/default/Views/Images/emoticons/stink.gif" alt="stink" /></td><td><img src="/themes/default/Views/Images/emoticons/stop.gif" alt="stop" /></td><td><img src="/themes/default/Views/Images/emoticons/superstition.gif" alt="superstition" /></td></tr><tr><td><img src="/themes/default/Views/Images/emoticons/swoon.gif" alt="swoon" /></td><td><img src="/themes/default/Views/Images/emoticons/swoon2.gif" alt="swoon2" /></td><td><img src="/themes/default/Views/Images/emoticons/taunt.gif" alt="taunt" /></td><td><img src="/themes/default/Views/Images/emoticons/thank_you.gif" alt="thank_you" /></td><td><img src="/themes/default/Views/Images/emoticons/thank_you2.gif" alt="thank_you2" /></td><td><img src="/themes/default/Views/Images/emoticons/this.gif" alt="this" /></td><td><img src="/themes/default/Views/Images/emoticons/threaten.gif" alt="threaten" /></td><td><img src="/themes/default/Views/Images/emoticons/to_clue.gif" alt="to_clue" /></td><td><img src="/themes/default/Views/Images/emoticons/to_take_umbrage.gif" alt="to_take_umbrage" /></td><td><img src="/themes/default/Views/Images/emoticons/tongue.gif" alt="tongue" /></td></tr><tr><td><img src="/themes/default/Views/Images/emoticons/tripleass.gif" alt="tripleass" /></td><td><img src="/themes/default/Views/Images/emoticons/triplebang.gif" alt="triplebang" /></td><td><img src="/themes/default/Views/Images/emoticons/umnik.gif" alt="umnik" /></td><td><img src="/themes/default/Views/Images/emoticons/umnik2.gif" alt="umnik2" /></td><td><img src="/themes/default/Views/Images/emoticons/victory.gif" alt="victory" /></td><td><img src="/themes/default/Views/Images/emoticons/whistle.gif" alt="whistle" /></td><td><img src="/themes/default/Views/Images/emoticons/whistle2.gif" alt="whistle2" /></td><td><img src="/themes/default/Views/Images/emoticons/whistle3.gif" alt="whistle3" /></td><td><img src="/themes/default/Views/Images/emoticons/wiener.gif" alt="wiener" /></td><td><img src="/themes/default/Views/Images/emoticons/wink3.gif" alt="wink3" /></td></tr><tr><td><img src="/themes/default/Views/Images/emoticons/wipme.gif" alt="wipme" /></td><td><img src="/themes/default/Views/Images/emoticons/yahoo.gif" alt="yahoo" /></td><td><img src="/themes/default/Views/Images/emoticons/yes.gif" alt="yes" /></td><td><img src="/themes/default/Views/Images/emoticons/yes2.gif" alt="yes2" /></td><td><img src="/themes/default/Views/Images/emoticons/yes3.gif" alt="yes3" /></td><td><img src="/themes/default/Views/Images/emoticons/yes4.gif" alt="yes4" /></td><td><img src="/themes/default/Views/Images/emoticons/yu.gif" alt="yu" /></td><td></td><td></td><td></td></tr></table>';
	},
	selAll: function(selector) {
		$(selector + ' input[type=checkbox]').each(function(){$(this).attr('checked', !this.checked);});
	},
	growl: function(msg, options){
		options = options||{};$.jGrowl.defaults.position=options.position||'top-right';$.jGrowl.defaults.closer=options.closer||'';$.jGrowl.defaults.closeTemplate=options.closeTemplate||'';options.open=function(e,m,o){$.xc.rolldown(e)};$.jGrowl(msg,options);
	},
	maxLen:function(o,MaxLen){return(o.value.length<=MaxLen)},
	changeWalletCountry: function(o,b) {
		$('#tabs div.prices').hide();
		if ($('#tabs .'+ $(o).val()).length > 0) {
			$('#tabs .'+ $(o).val()).show();
		}
		if (b == 'x' && $(o).val() != 'LT') { $('#l900').hide(); $("#tabs").tabs('select', 0); } else { $('#l900').show(); }
		if (b == 'vip' && $(o).val() != 'LT' && $(o).val() != 'LV' && $(o).val() != 'RU') { $('#bsms').hide(); $("#tabs").tabs('select', 1); } else { $('#bsms').show(); }
	},
	matchDontLike: function(o,id) {
		$.ajax({url:'/User/DataEX/matchDontLike/?id='+id,success:function(msg){
			$(o).up(3).find('div.close').click();
		}});
	},
	showProfile: function(o){
		var userID = /usr_(\d+)/.exec($(o).attr('className'));
		var win = window.open('/profile.html?Q=13eddd0' +'&userID='+userID[1], "Profile_"+userID[1], "status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=1,scrollbars=1,height=700,width=810");
		if (win){win.focus();}
		return false;
	},
	afterBid: function(m) {
		$('#xAmount').html(m.X);
		$('form.showup input').val('');
		$('form.showup .err').html('');
		window.location.reload();
	},
	sendActivationCode: function(o) {
		$.ajax({url:'/User/DataEX/sendActivationCode/',success:function(msg){
			if (msg.OK) {
				settings = {buttons:{},width:350};
				settings.buttons[$.xc.L.Save] = function(){ $.xc.save($('#cNumber'),1, function(m){
					$('#userPhoneNumber').val(m.number);
					$('#confirmNumberLink').hide();
					$('#confirmNumberLink2').hide();
					$('#profilePercents').html(m.P<100 ? ' ['+m.P+'%]' : '');
				})};
				$('#cNumber').prompt(settings);
			}
		}});
	},
	rolldown: function(o,h) {
		var x = 1;
		$('a[class*=usr]', o).each(function(){
			if ($.xc.profileNewWin){
				/*if (typeof console == 'object') {
					console.log(x, '. ', $(this).attr('className'), this);
					x++;
				}/**/
				$(this).click(function(){
					var userID = /usr_(\d+)/.exec($(this).attr('className'));
					var win = window.open( '/profile.html?Q=13eddd0' +'&userID='+userID[1], "Profile_"+userID[1], "status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=1,scrollbars=1,height=700,width=810");
					if (win){win.focus();}
					return false;
				});
			};
			if ($('img:last-child', this).length == 1 && $('img:last-child', this).attr('longdesc')/**/) {
				if (!this.user) {
					this.user = $('img:last-child', this).attr('longdesc').split('|');
					html = $('<div class="roll-down">' + $('#RollDown').html() + '</div>');
					if ($.xc.uid == this.user[0]) {
						$('ul li:nth-child(1),ul li:nth-child(5)', $(html)).hide();
					}

					$(this).qtip({
						content:html,
						position:'bottomRight',
						position:{adjust:{x:-20,y:-20}},
						show:{delay:100,solo:true,effect:{length:0,type:'show'}},
						hide:{when:'mouseout',fixed:true,delay:150,effect:'hide'},
						style: {
							border:{width:1,color:'#474747'},background:'#1d1d1d',padding:0
						},
						api: {
							beforeShow: function(e){
								var trg = (e.target.user ? e.target :  $(e.target).parent()[0]);
								$.xc.rollusr = trg.user;
								$.xc.rollusr[2] = $('img:first-child', $(trg)).attr('src');
							}
						}
					});
				}
			}
		});
	},
	toggleMenu: function(o) {
		var el = $(o).parent().next();
		if ($(el).is(":hidden")){
			$(el).slideDown("fast");
		} else {
			$(el).slideUp("fast");
		}
	},
	markNoteAsRead: function(o,nid) {
		$.ajax({url:'/User/DataEX/markNotificationAsRead/?nid='+nid,success:function(msg){
			$(o).parent().fadeOut(300, function(){ $(this).remove(); });
		}});
	},
	win: function(object, settings) {
		settings = jQuery.extend({dialogClass:'ui-default',title:'',minHeight:50}, settings);

		if (typeof object == 'object' && $(object).attr('title') && settings.title == '') {
			settings.title = $(object).attr('title');
		}

		if (typeof object == 'object' && $(object).attr('href') && $(object).attr('href') != '#') {
			this.D = this.D || $('<div/>');
			this.D.html('<div class="ui-loader">&nbsp;</div>');
			var d = this._dialog(this.D, settings);

			$.ajax({url: $(object).attr('href'), success: function(data){
				$(d).html(data);
				$(d).dialog('option','position','center');
			}});
			return d;
		} else {
			return this._dialog(object, settings);
		}
	},
	_dialog: function(object, settings) {
		var w = settings.maxWidth || 'auto';
		settings = jQuery.extend({closeText:'',draggable:false,resizable:false,autoOpen:false,modal:true,minHeight:130,width:w},settings);

		$(object).dialog(settings);
		if ($('.ui-dialog-buttonpane button', $(object).dialog('widget')).length > 1) {
			$('.ui-dialog-buttonpane button:first', $(object).dialog('widget')).addClass('submit');
		}
		$('.ui-dialog-buttonpane button:last', $(object).dialog('widget')).addClass('reset');
		object.dialog('open');
		return object;
	}
};
// -------------------------------------------------------------------------------------------------------------------------------------------------
var aw = null
jQuery.fn.alert = function(msg, settings){
	var self = this;
	settings = settings || {};settings.hideAfter = settings.hideAfter || 1;settings.buttons = settings.buttons || {};
	settings = jQuery.extend({title:$.xc.L.Info,dialogClass:'ui-default ui-alert',minHeight:80}, settings);
	settings.buttons[$.xc.L.Ok] = function() { $(this).dialog('close'); $(this).dialog('destroy'); };
	aw = $.xc.win($('<div>'+(msg || this.selector)+'</div>'), settings);
	if (settings.hideAfter) {
		setTimeout("$(aw).dialog('close');", settings.hideAfter * 1000);
	}
};
jQuery.fn.confirm = function(msg, settings, texts){
	settings = settings || {};settings.buttons = settings.buttons || {};
	var OK = (texts && texts.OK) || $.xc.L.Yes;
	if (typeof settings == 'function') {var s=settings;settings={buttons:{},maxWidth:400};settings.buttons[OK]=function(){s();$(this).dialog('close');};}
	settings.dialogClass = settings.dialogClass || 'ui-default c';
	settings.title = settings.title || $.xc.L.Confirm;
	settings.buttons[$.xc.L.Cancel] = function(){$(this).busyBox('close');$(this).dialog('close');$(this).dialog('destroy');};
	$.xc.win($('<div>'+msg+'</div>'), settings);
};
jQuery.fn.prompt = function(settings, ext){
	settings = settings || {}; ext = ext || {}; settings.callBack = settings.callBack || null;
	if (typeof settings == 'string') {
		$(this).attr('href', settings);
		settings = {};
	}
	settings.dialogClass = settings.dialogClass || 'ui-default';

	if (!settings.buttons) {
		settings.buttons = {};
		var btSave = settings.btSave || $.xc.L.Save;
		settings.buttons[btSave] = function(){ $.xc.save(this, 1, settings.callBack); };
	}
	var self = this;
	if (!$('form', $(this).dialog('widget')).attr('bindedSubmit')) {
		$('form', $(this).dialog('widget')).attr('bindedSubmit', 1);
		$('form', $(this).dialog('widget')).submit(function(){ $.xc.save(self, 1, settings.callBack); return false;});
	}

	settings.buttons[$.xc.L.Cancel] = function(){ $(this).busyBox('close'); $(this).dialog('close'); $(this).dialog('destroy'); };
	settings = jQuery.extend(settings, ext);

	$.xc.win(this, settings);
	return false;
};
jQuery.fn.pop = function(settings){
	settings = settings || {};
	if (typeof settings == 'string') {
		$(this).attr('href', settings);
		settings = {};
	}
	settings.dialogClass = settings.dialogClass || 'ui-info';
	settings.buttons = {};
	$.xc.win(this, settings);
	return false;
};
// -------------------------------------------------------------------------------------------------------------------------------------------------

function fbOnLogin(){window.location.href = '/FbConnect/Login/';};
jQuery.fn.up = function(n){var o=this;if(typeof n == 'undefined'){n=1};for(i=0;i<n;i++){o=$(o).parent()}return(o)};
jQuery.fn.langbox = function(){$(this).click(function(){$('#' + this.id + ' + ul').toggle()})};
jQuery.fn.paginate = function(s){s=s||{};s.parent=s.parent||$(this.parent());$('a', this).click(function(e){var l = $(s.parent).busyBox({spinner:'<img src="/bin/protoload/bigWaiting.gif" alt="Loading..." />'});$.xc.pag = 1;$.ajax({url:$(this).attr('href'),success:function(data){$(s.parent).html(data);l.busyBox('close');$.xc.rolldown($(s.parent));return false;}});return false;});};
jQuery.fn.defaultText = function(){$(this).focus(function(){if ($(this).val() == $(this).attr('title')){$(this).removeClass("defaultTextActive").val("")}});$(this).blur(function(){if ($(this).val() == ""){$(this).addClass("defaultTextActive").val($(this)[0].title);}});$(this).blur();};
jQuery.fn.emo = function(t,emoid){
	emoid = emoid || '#emolist';
	var emo = $(emoid), self = this; self.txtArea = t;
	$(emoid).bind('dialogbeforeclose', function() { $('img',this).each(function(){ $(this).unbind('click'); }); });
	$.xc.win($(emoid),{dialogClass:'ui-notitle'});

	$('img', $(emoid)).each(function(){
		$(this).bind('click', function(){
			$($(emoid)).dialog('close');
			t = self.txtArea || $(self).prev().prev();
			$(t).focus();
			$(t).val($(t).val()+'('+$(this).attr('alt')+')');
		});
	});

	return false;
};
jQuery.fn.feed = function(url) {
	if (!$.xc.pag) {
		$.ajax({url:url,success:function(msg){
			$('#pages').parent().html(msg);
			$.xc.rolldown($('#pages').parent());
		}});
	}

};
jQuery.fn.listFilter = function(url,dst){
	var self = this, dst = dst || $(this).next();
	$(this).find('input').click(function(){
		load(this,self,url,dst);
	});
	$(this).find('select').change(function(){
		load(this,self,url,dst);
	});
	load = function(o,f,url,dst) {
		var d = $(f).serialize(), l = $.xc.loader(dst);
		$(f).find('input, select').attr('disabled', true);
		$.ajax({url:url, type:$(f).attr('method'), data:d, success:function(data){
			$(dst).html(data);
			$.xc.rolldown($(dst));
			$(f).find('input, select').attr('disabled', false);
			l.busyBox('close');
		}});
	}
};
jQuery.fn.simpleGallery = function(o) {
	var self = this;
	o = o || {};
	var running = false;
	$('#thumbs', this).jCarouselLite(o);
	$('ul img', this).each(function(){
		$(this).click(function(){

			$('ul img', self).removeClass('active');
			$(this).addClass('active');
			var longdesc = $(this).attr('longdesc');

			if (longdesc.substring(0,1) == '$') {
				eval(longdesc);
				return false;
			}

			if (!running && o.gtype == 'image') {
				$('#galBigPrevDiv', self).busyBox({spinner:'<img src="/bin/img/loader-large.gif" alt="Loading..." />'})
				running = true;
			}

			if (o.gtype == 'video') {
				$('#VideoRollDownPreview')[0].sendEvent("LOAD", longdesc);
				$('#VideoRollDownPreview')[0].sendEvent("PLAY", "true");
			} else {
				$('#galBigPrev', self).attr('src', longdesc);
			}
		})
	});

	if (o.gtype == 'image') {
		$('#galBigPrev', self).load(function(){
			if (running) {
				$('#galBigPrevDiv', self).busyBox('close');
				running = false;
			}
		});
	}
};
jQuery.fn.resetForm = function(o) {
	$(this).find("select").val('');
	$(this).find("input:text").val('');
	$(this).find("input:checked").attr('checked', false);
}

var wall = new function () {
	this.loader = function(obj) {
		return $(obj).busyBox({spinner:'<img src="/Applications/Page/Views/Images/bussy.gif" alt="Loading..." />'});
	}
	this.postW = function(f) {
		if ($('textarea', f).attr('disabled') || $('textarea', f).val() == '' || $('textarea', f).val() == $('textarea', f).attr('title')) {
			return false;
		}
		var data = $(f).serialize();
		$('textarea', f).attr('disabled',true);
		$.ajax({type:$(f).attr('method'), url:$(f).attr('action'), data:data, success:function(msg){
			$('#wallMain').prepend(msg);
			$('textarea', f).attr('disabled',false).val('');
			$.xc.rolldown($('#wallMain :first-child'));
		}});
		return false;
	};
	this.rmP = function(o,msg) {
		self = this;
		$(this).confirm(msg, function(){
			var l = self.loader($(o));
			$.ajax({url:'/Wall/Delete/?WallID='+$(o).attr('rel'),
				success:function(){
					l.busyBox('close');
					$('#wall' + $(o).attr('rel')).remove();
				}
			})
		});
		return false;
	};
	this.postC = function(f) {
		if ($('textarea', f).attr('disabled') || $('textarea', f).val() == '') {
			return false;
		}
		var data = $(f).serialize();
		$('textarea', f).attr('disabled',true);
		$.ajax({type:$(f).attr('method'), url:$(f).attr('action'), data:data, success:function(msg){
			var id = $(':first-child', $(f).parent().parent()).attr('id');
			$('#' + id).append(msg);
			$('textarea', f).attr('disabled',false).val('');

			var c = $('tr:first-child .msg .allcom a', $(f).closest('table'));
			if (c.html()) {
				$(c).html(c.html().replace(/(\d+)/g, function(m){return (parseInt(m)+1);}));
			}
			$.xc.rolldown($('#' + id));
		}});
		return false;
	};
	this.rmC = function(o,msg) {
		self = this;
		$(this).confirm(msg, function(){
			var l = self.loader($(o));
			$.ajax({url:'/Wall/Delete/?CommentID='+$(o).attr('rel'),
				success:function(msg){
					l.busyBox('close');
					var p = $(o).closest('table').parent().closest('table');
					var c = $('tr:first-child .msg .allcom a', p);
					if (c.html()) {
						if (parseInt(msg.CLEFT) == 0) {
							c.remove();
						} else {
							$(c).html(c.html().replace(/(\d+)/g, function(m){return (parseInt(m)-1);}));

						}
					}
					$('#wc' + $(o).attr('rel')).remove();
				}
			})
		});
		return false;
	};
	this.allComments = function(obj, wallID, prepend) {
		var l = this.loader($(obj));
		$.ajax({url:$(obj).attr('href'), success:function(msg){
			l.busyBox('close');
			if (prepend == 1) {
				$('#wa' + wallID).prepend(msg);
			} else {
				$('#wa' + wallID).html(msg);
				if ($('#wa' + wallID + ' table').length >= 5) {
					$(obj).parent().next().find('a').click();
				}
			}
			$(obj).parent().remove();
			$.xc.rolldown($('#wa' + wallID));
		}});
		return false;
	};
	this.commForm = function(o,id) {
		$('#cf' + id).toggle();
		$(o).hide();
		$('#cf' + id + ' textarea').focus();
	};
	this.more = function(a) {
		var l = this.loader($(a));
		$.ajax({url:'/Wall/' + $(a).attr('href').substring($(a).attr('href').indexOf('?')), success:function(msg){
			l.busyBox('close');
			$(a).closest('table').remove();
			$('#wallMain').append(msg);
			$.xc.rolldown($('#wallMain'));
		}});
		return false;
	};
	this.play = function(o,u){
		var v = new SWFObject(u, "ply", "480", "288", "9");
		v.addParam("allowfullscreen", "true");
		v.addParam("allowscriptaccess", "always");
		v.addParam("wmode", "transparent");
		v.addParam("flashvars", u);
		v.write(o);
	}
};
$.extend({
	getUrlVars: function(){
		var vars = [], hash;
		var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
		for (var i = 0; i < hashes.length; i++){
			hash = hashes[i].split('=');
			vars.push(hash[0]);
			vars[hash[0]] = hash[1];
		}
		return vars;
	},
	getUrlVar: function(name){
		return $.getUrlVars()[name];
	}
});
function regChGender(o){$(o).val()=='C'?$('#regForm .partnerFileds').show():$('#regForm .partnerFileds').hide()}
function updateDom(){
	if (!$.xc.uid){return false}
	$.ajax({url:'/Page/Data/DOMUpdates/', success:function(m){
		var data = m.updateDOM || {};
	    for (var key in data) {
	    	if (key == 'growl') {
	    		for (var g=0; g < data.growl.length; g++) {
					if (data.growl[g]) {
						$.xc.growl(data.growl[g], {life:15*1000,position:'bottom-right'});
					}
	    		}
	    	} else if (key == 'notifications' && $('#notification').html() == '') {
				$('#notification').hide().html(data[key]).fadeIn('slow');
	    	} else {
	    		$('#' + key).html(data[key] ? '('+data[key]+')' : '');
			}
	    }
		window.setTimeout('updateDom();', 60*1000);
	}});
}
function numbersonly(e) {
	var unicode = e.charCode? e.charCode : e.keyCode;
	if (unicode!=8) {
		if (unicode < 48 || unicode > 57) {
			return false;
		}
	}
	return true;
}
$(document).ready(function(){
	$(document).bind('contextmenu', function(){return($.xc.debug == 1)});
	$('#langBox').langbox();
	window.setTimeout('updateDom();', 60*1000);
});