PageRenderTime 61ms CodeModel.GetById 2ms app.highlight 51ms RepoModel.GetById 1ms app.codeStats 0ms

/upload/misc/js/main.js

http://torrentpier2.googlecode.com/
JavaScript | 596 lines | 481 code | 61 blank | 54 comment | 101 complexity | 978828072348647e0ebef4fa3a79d89a MD5 | raw file
  1/**
  2 * SWFObject v1.5: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
  3 *
  4 * SWFObject is (c) 2007 Geoff Stearns and is released under the MIT License:
  5 * http://www.opensource.org/licenses/mit-license.php
  6 *
  7 */
  8if(typeof deconcept=="undefined"){var deconcept=new Object();}if(typeof deconcept.util=="undefined"){deconcept.util=new Object();}if(typeof deconcept.SWFObjectUtil=="undefined"){deconcept.SWFObjectUtil=new Object();}deconcept.SWFObject=function(_1,id,w,h,_5,c,_7,_8,_9,_a){if(!document.getElementById){return;}this.DETECT_KEY=_a?_a:"detectflash";this.skipDetect=deconcept.util.getRequestParameter(this.DETECT_KEY);this.params=new Object();this.variables=new Object();this.attributes=new Array();if(_1){this.setAttribute("swf",_1);}if(id){this.setAttribute("id",id);}if(w){this.setAttribute("width",w);}if(h){this.setAttribute("height",h);}if(_5){this.setAttribute("version",new deconcept.PlayerVersion(_5.toString().split(".")));}this.installedVer=deconcept.SWFObjectUtil.getPlayerVersion();if(!window.opera&&document.all&&this.installedVer.major>7){deconcept.SWFObject.doPrepUnload=true;}if(c){this.addParam("bgcolor",c);}var q=_7?_7:"high";this.addParam("quality",q);this.setAttribute("useExpressInstall",false);this.setAttribute("doExpressInstall",false);var _c=(_8)?_8:window.location;this.setAttribute("xiRedirectUrl",_c);this.setAttribute("redirectUrl","");if(_9){this.setAttribute("redirectUrl",_9);}};deconcept.SWFObject.prototype={useExpressInstall:function(_d){this.xiSWFPath=!_d?"expressinstall.swf":_d;this.setAttribute("useExpressInstall",true);},setAttribute:function(_e,_f){this.attributes[_e]=_f;},getAttribute:function(_10){return this.attributes[_10];},addParam:function(_11,_12){this.params[_11]=_12;},getParams:function(){return this.params;},addVariable:function(_13,_14){this.variables[_13]=_14;},getVariable:function(_15){return this.variables[_15];},getVariables:function(){return this.variables;},getVariablePairs:function(){var _16=new Array();var key;var _18=this.getVariables();for(key in _18){_16[_16.length]=key+"="+_18[key];}return _16;},getSWFHTML:function(){var _19="";if(navigator.plugins&&navigator.mimeTypes&&navigator.mimeTypes.length){if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","PlugIn");this.setAttribute("swf",this.xiSWFPath);}_19="<embed type=\"application/x-shockwave-flash\" src=\""+this.getAttribute("swf")+"\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+this.getAttribute("style")+"\"";_19+=" id=\""+this.getAttribute("id")+"\" name=\""+this.getAttribute("id")+"\" ";var _1a=this.getParams();for(var key in _1a){_19+=[key]+"=\""+_1a[key]+"\" ";}var _1c=this.getVariablePairs().join("&");if(_1c.length>0){_19+="flashvars=\""+_1c+"\"";}_19+="/>";}else{if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","ActiveX");this.setAttribute("swf",this.xiSWFPath);}_19="<object id=\""+this.getAttribute("id")+"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+this.getAttribute("style")+"\">";_19+="<param name=\"movie\" value=\""+this.getAttribute("swf")+"\" />";var _1d=this.getParams();for(var key in _1d){_19+="<param name=\""+key+"\" value=\""+_1d[key]+"\" />";}var _1f=this.getVariablePairs().join("&");if(_1f.length>0){_19+="<param name=\"flashvars\" value=\""+_1f+"\" />";}_19+="</object>";}return _19;},write:function(_20){if(this.getAttribute("useExpressInstall")){var _21=new deconcept.PlayerVersion([6,0,65]);if(this.installedVer.versionIsValid(_21)&&!this.installedVer.versionIsValid(this.getAttribute("version"))){this.setAttribute("doExpressInstall",true);this.addVariable("MMredirectURL",escape(this.getAttribute("xiRedirectUrl")));document.title=document.title.slice(0,47)+" - Flash Player Installation";this.addVariable("MMdoctitle",document.title);}}if(this.skipDetect||this.getAttribute("doExpressInstall")||this.installedVer.versionIsValid(this.getAttribute("version"))){var n=(typeof _20=="string")?document.getElementById(_20):_20;n.innerHTML=this.getSWFHTML();return true;}else{if(this.getAttribute("redirectUrl")!=""){document.location.replace(this.getAttribute("redirectUrl"));}}return false;}};deconcept.SWFObjectUtil.getPlayerVer
  9sion=function(){var _23=new deconcept.PlayerVersion([0,0,0]);if(navigator.plugins&&navigator.mimeTypes.length){var x=navigator.plugins["Shockwave Flash"];if(x&&x.description){_23=new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/,"").replace(/(\s+r|\s+b[0-9]+)/,".").split("."));}}else{if(navigator.userAgent&&navigator.userAgent.indexOf("Windows CE")>=0){var axo=1;var _26=3;while(axo){try{_26++;axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+_26);_23=new deconcept.PlayerVersion([_26,0,0]);}catch(e){axo=null;}}}else{try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");}catch(e){try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");_23=new deconcept.PlayerVersion([6,0,21]);axo.AllowScriptAccess="always";}catch(e){if(_23.major==6){return _23;}}try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");}catch(e){}}if(axo!=null){_23=new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));}}}return _23;};deconcept.PlayerVersion=function(_29){this.major=_29[0]!=null?parseInt(_29[0]):0;this.minor=_29[1]!=null?parseInt(_29[1]):0;this.rev=_29[2]!=null?parseInt(_29[2]):0;};deconcept.PlayerVersion.prototype.versionIsValid=function(fv){if(this.major<fv.major){return false;}if(this.major>fv.major){return true;}if(this.minor<fv.minor){return false;}if(this.minor>fv.minor){return true;}if(this.rev<fv.rev){return false;}return true;};deconcept.util={getRequestParameter:function(_2b){var q=document.location.search||document.location.hash;if(_2b==null){return q;}if(q){var _2d=q.substring(1).split("&");for(var i=0;i<_2d.length;i++){if(_2d[i].substring(0,_2d[i].indexOf("="))==_2b){return _2d[i].substring((_2d[i].indexOf("=")+1));}}}return "";}};deconcept.SWFObjectUtil.cleanupSWFs=function(){var _2f=document.getElementsByTagName("OBJECT");for(var i=_2f.length-1;i>=0;i--){_2f[i].style.display="none";for(var x in _2f[i]){if(typeof _2f[i][x]=="function"){_2f[i][x]=function(){};}}}};if(deconcept.SWFObject.doPrepUnload){if(!deconcept.unloadSet){deconcept.SWFObjectUtil.prepUnload=function(){__flash_unloadHandler=function(){};__flash_savedUnloadHandler=function(){};window.attachEvent("onunload",deconcept.SWFObjectUtil.cleanupSWFs);};window.attachEvent("onbeforeunload",deconcept.SWFObjectUtil.prepUnload);deconcept.unloadSet=true;}}if(!document.getElementById&&document.all){document.getElementById=function(id){return document.all[id];};}var getQueryParamValue=deconcept.util.getRequestParameter;var FlashObject=deconcept.SWFObject;var SWFObject=deconcept.SWFObject;
 10
 11// prototype $
 12function $p() {
 13  var elements = new Array();
 14
 15  for (var i = 0; i < arguments.length; i++) {
 16    var element = arguments[i];
 17    if (typeof element == 'string')
 18      element = document.getElementById(element);
 19
 20    if (arguments.length == 1)
 21      return element;
 22
 23    elements.push(element);
 24  }
 25
 26  return elements;
 27}
 28
 29// from http://www.dustindiaz.com/rock-solid-addevent/
 30function addEvent( obj, type, fn ) {
 31	if (obj.addEventListener) {
 32		obj.addEventListener( type, fn, false );
 33		EventCache.add(obj, type, fn);
 34	}
 35	else if (obj.attachEvent) {
 36		obj["e"+type+fn] = fn;
 37		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
 38		obj.attachEvent( "on"+type, obj[type+fn] );
 39		EventCache.add(obj, type, fn);
 40	}
 41	else {
 42		obj["on"+type] = obj["e"+type+fn];
 43	}
 44}
 45
 46var EventCache = function(){
 47	var listEvents = [];
 48	return {
 49		listEvents : listEvents,
 50		add : function(node, sEventName, fHandler){
 51			listEvents.push(arguments);
 52		},
 53		flush : function(){
 54			var i, item;
 55			for(i = listEvents.length - 1; i >= 0; i = i - 1){
 56				item = listEvents[i];
 57				if(item[0].removeEventListener){
 58					item[0].removeEventListener(item[1], item[2], item[3]);
 59				};
 60				if(item[1].substring(0, 2) != "on"){
 61					item[1] = "on" + item[1];
 62				};
 63				if(item[0].detachEvent){
 64					item[0].detachEvent(item[1], item[2]);
 65				};
 66				item[0][item[1]] = null;
 67			};
 68		}
 69	};
 70}();
 71if (document.all) { addEvent(window,'unload',EventCache.flush); }
 72
 73function imgFit (img, maxW)
 74{
 75	img.title  = '??????? ???????????: '+img.width+' x '+img.height;
 76	if (typeof(img.naturalHeight) == 'undefined') {
 77		img.naturalHeight = img.height;
 78		img.naturalWidth  = img.width;
 79	}
 80	if (img.width > maxW) {
 81		img.height = Math.round((maxW/img.width)*img.height);
 82		img.width  = maxW;
 83		img.title  = '??????? ?? ???????????, ????? ?????????? ??? ? ?????? ??????';
 84		img.style.cursor = 'move';
 85		return false;
 86	}
 87	else if (img.width == maxW && img.width < img.naturalWidth) {
 88		img.height = img.naturalHeight;
 89		img.width  = img.naturalWidth;
 90		img.title  = '??????? ???????????: '+img.naturalWidth+' x '+img.naturalHeight;
 91		return false;
 92	}
 93	else {
 94		return true;
 95	}
 96}
 97
 98function toggle_block (id)
 99{
100	var el = document.getElementById(id);
101	el.style.display = (el.style.display == 'none') ? '' : 'none';
102}
103
104function toggle_disabled (id, val)
105{
106	document.getElementById(id).disabled = (val) ? 0 : 1;
107}
108
109function rand (min, max)
110{
111	return min + Math.floor((max - min + 1) * Math.random());
112}
113
114//
115// Cookie functions [based on ???]
116//
117/**
118 * name       Name of the cookie
119 * value      Value of the cookie
120 * [days]     Number of days to remain active (default: end of current session)
121 * [path]     Path where the cookie is valid (default: path of calling document)
122 * [domain]   Domain where the cookie is valid
123 *            (default: domain of calling document)
124 * [secure]   Boolean value indicating if the cookie transmission requires a
125 *            secure transmission
126 */
127function setCookie (name, value, days, path, domain, secure)
128{
129	if (days != 'SESSION') {
130		var date = new Date();
131		days = days || 365;
132		date.setTime(date.getTime() + days*24*60*60*1000);
133		var expires = date.toGMTString();
134	} else {
135		var expires = '';
136	}
137
138	document.cookie =
139		name +'='+ escape(value)
140	+	((expires) ? '; expires='+ expires : '')
141	+	((path) ? '; path='+ path : ((cookiePath) ? '; path='+ cookiePath : ''))
142	+	((domain) ? '; domain='+ domain : ((cookieDomain) ? '; domain='+ cookieDomain : ''))
143	+	((secure) ? '; secure' : ((cookieSecure) ? '; secure' : ''));
144}
145
146/**
147 * Returns a string containing value of specified cookie,
148 *   or null if cookie does not exist.
149 */
150function getCookie (name)
151{
152	var c, RE = new RegExp('(^|;)\\s*'+ name +'\\s*=\\s*([^\\s;]+)', 'g');
153	return (c = RE.exec(document.cookie)) ? c[2] : null;
154}
155
156/**
157 * name      name of the cookie
158 * [path]    path of the cookie (must be same as path used to create cookie)
159 * [domain]  domain of the cookie (must be same as domain used to create cookie)
160 */
161function deleteCookie (name, path, domain)
162{
163	setCookie(name, '', -1, path, domain);
164}
165
166// Simple Javascript Browser/OS detection (based on "Harald Hope, Tapio Markula, http://techpatterns.com ver 2.0.1")
167var ua = navigator.userAgent;
168
169var os_win = ( navigator.appVersion.indexOf( 'Win' ) != -1 );
170var os_mac = ( navigator.appVersion.indexOf( 'Mac' ) != -1 );
171var os_lin = ( ua.indexOf( 'Linux' ) != -1 );
172
173var is_opera = ( ua.indexOf( 'Opera' ) != -1 );
174var is_konq  = ( ua.indexOf( 'Konqueror' ) != -1 );
175var is_saf   = ( ua.indexOf( 'Safari' ) != -1 );
176var is_moz   = ( ua.indexOf( 'Gecko' ) != -1 && !is_saf && !is_konq);
177var is_ie    = ( document.all && !is_opera );
178var is_ie4   = ( is_ie && !document.getElementById );
179
180// ie5x tests only for functionality
181// Opera will register true in this test if set to identify as IE 5
182var is_ie5x    = ( document.all && document.getElementById );
183var os_ie5mac  = ( os_mac && is_ie5x );
184var os_ie5xwin = ( os_win && is_ie5x );
185
186// Copy text to clipboard. Originally got from decompiled `php_manual_en.chm`.
187function ie_copyTextToClipboard (fromNode)
188{
189	var txt = document.body.createTextRange();
190	txt.moveToElementText(fromNode);
191	return txt.execCommand("Copy");
192}
193
194//
195// Menus
196//
197var Menu = {
198	hideSpeed          : 'fast',
199	offsetCorrection_X : -4,
200	offsetCorrection_Y : 2,
201	iframeFix          : false,
202
203	activeMenuId       : null,  //  currently opened menu (from previous click)
204	clickedMenuId      : null,  //  menu to show up
205	$root              : null,  //  root element for menu with "href = '#clickedMenuId'"
206	$menu              : null,  //  clicked menu
207	positioningType    : null,  //  reserved
208	outsideClickWatch  : false, //  prevent multiple $(document).click binding
209
210	clicked: function($root) {
211		$root.blur();
212		this.clickedMenuId = this.getMenuId($root);
213		this.$menu = $(this.clickedMenuId);
214		this.$root = $root;
215		this.toggle();
216	},
217
218	hovered: function($root) {
219		if (this.activeMenuId && this.activeMenuId !== this.getMenuId($root)) {
220			this.clicked($root);
221		}
222	},
223
224	unhovered: function($root) {
225	},
226
227	getMenuId: function($el) {
228		var href = $el.attr('href');
229		return href.substr(href.indexOf('#'));
230	},
231
232	setLocation: function() {
233		var CSS = this.$root.offset();
234		CSS.top  += this.$root.height() + this.offsetCorrection_Y;
235		var curTop = parseInt(CSS.top);
236		var tCorner = $(document).scrollTop() + $(window).height() - 20;
237		var maxVisibleTop = Math.min(curTop, Math.max(0, tCorner - this.$menu.height()));
238		if (curTop != maxVisibleTop) {
239			CSS.top = maxVisibleTop;
240		}
241		CSS.left += this.offsetCorrection_X;
242		var curLeft = parseInt(CSS.left);
243		var rCorner = $(document).scrollLeft() + $(window).width() - 6;
244		var maxVisibleLeft = Math.min(curLeft, Math.max(0, rCorner - this.$menu.width()));
245		if (curLeft != maxVisibleLeft) {
246			CSS.left = maxVisibleLeft;
247		}
248		this.$menu.css(CSS);
249		if (this.iframeFix) {
250			$('iframe.ie-fix-select-overlap', $menu).css({ width: $menu.width(), height: $menu.height() });
251		}
252	},
253
254	fixLocation: function() {
255		var $menu = this.$menu;
256		var curLeft = parseInt($menu.css('left'));
257		var rCorner = $(document).scrollLeft() + $(window).width() - 6;
258		var maxVisibleLeft = Math.min(curLeft, Math.max(0, rCorner - $menu.width()));
259		if (curLeft != maxVisibleLeft) {
260			$menu.css('left', maxVisibleLeft);
261		}
262		var curTop = parseInt($menu.css('top'));
263		var tCorner = $(document).scrollTop() + $(window).height() - 20;
264		var maxVisibleTop = Math.min(curTop, Math.max(0, tCorner - $menu.height()));
265		if (curTop != maxVisibleTop) {
266			$menu.css('top', maxVisibleTop);
267		}
268		if (this.iframeFix) {
269			$('iframe.ie-fix-select-overlap', $menu).css({ width: $menu.width(), height: $menu.height() });
270		}
271	},
272
273	toggle: function() {
274		if (this.activeMenuId && this.activeMenuId !== this.clickedMenuId) {
275			$(this.activeMenuId).hide(this.hideSpeed);
276		}
277		// toggle clicked menu
278		if (this.$menu.is(':visible')) {
279			this.$menu.hide(this.hideSpeed);
280			this.activeMenuId = null;
281		}	else {
282			this.showClickedMenu();
283			if (!this.outsideClickWatch) {
284				$(document).one('mousedown', function(e){ Menu.hideClickWatcher(e); });
285				this.outsideClickWatch = true;
286			}
287		}
288	},
289
290	showClickedMenu: function() {
291		this.setLocation();
292		this.$menu.css({display: 'block'});
293		// this.fixLocation();
294		this.activeMenuId = this.clickedMenuId;
295	},
296
297	// hide if clicked outside of menu
298	hideClickWatcher: function(e) {
299		this.outsideClickWatch = false;
300		this.hide(e);
301	},
302
303	hide: function(e) {
304		if (this.$menu) {
305			this.$menu.hide(this.hideSpeed);
306		}
307		this.activeMenuId = this.clickedMenuId = this.$menu = null;
308	}
309};
310
311$(document).ready(function(){
312	// Menus
313	$('body').append($('div.menu-sub'));
314	$('a.menu-root')
315		.click(
316			function(e){ e.preventDefault(); Menu.clicked($(this)); return false; })
317		.hover(
318			function(){ Menu.hovered($(this)); return false; },
319			function(){ Menu.unhovered($(this)); return false; }
320		)
321	;
322	$('div.menu-sub')
323		.mousedown(function(e){ e.stopPropagation(); })
324		.find('a')
325			.click(function(e){ Menu.hide(e); })
326	;
327	// Input hints
328	$('input')
329		.filter('.hint').one('focus', function(){
330			$(this).val('').removeClass('hint');
331		})
332		.end()
333		.filter('.error').one('focus', function(){
334			$(this).removeClass('error');
335		})
336	;
337});
338
339//
340// Ajax
341//
342function Ajax(handlerURL, requestType, dataType) {
343	this.url      = handlerURL;
344	this.type     = requestType;
345	this.dataType = dataType;
346	this.errors   = { };
347}
348
349Ajax.prototype = {
350	init       : {},  // init functions (run before submit, after triggering ajax event)
351	callback   : {},  // callback functions (response handlers)
352	state      : {},  // current action state
353	request    : {},  // request data
354	params     : {},  // action params, format: ajax.params[ElementID] = { param: "val" ... }
355	form_token : '',
356
357	exec: function(request) {
358		this.request[request.action] = request;
359		request['form_token'] = this.form_token;
360		$.ajax({
361			url      : this.url,
362			type     : this.type,
363			dataType : this.dataType,
364			data     : request,
365			success  : ajax.success,
366			error    : ajax.error
367		});
368	},
369
370	success: function(response) {
371		var action = response.action;
372		// raw_output normally might contain only error messages (if php.ini.display_errors == 1)
373		if (response.raw_output) {
374			$('body').prepend(response.raw_output);
375		}
376		if (response.sql_log) {
377			$('#sqlLog').prepend(response.sql_log +'<hr />');
378			fixSqlLog();
379		}
380		if (response.update_ids) {
381			for (id in response.update_ids) {
382				$('#'+id).html( response.update_ids[id] );
383			}
384		}
385		if (response.prompt_password) {
386			var user_password = prompt('??? ??????? ? ?????? ???????, ??????????, ??????? ???? ??????', '');
387			if (user_password) {
388				var req = ajax.request[action];
389				req.user_password = user_password;
390				ajax.exec(req);
391			}
392			else {
393				ajax.clearActionState(action);
394				ajax.showErrorMsg('?????? ???????? ??????');
395			}
396		}
397		else if (response.prompt_confirm) {
398			if (window.confirm(response.confirm_msg)) {
399				var req = ajax.request[action];
400				req.confirmed = 1;
401				ajax.exec(req);
402			}
403			else {
404				ajax.clearActionState(action);
405			}
406		}
407		else if (response.error_code) {
408			ajax.showErrorMsg(response.error_msg);
409			$('.loading-1').removeClass('loading-1').html('error');
410		}
411		else {
412			ajax.callback[action](response);
413			ajax.clearActionState(action);
414		}
415	},
416
417	error: function(xml, desc) {
418	},
419
420	clearActionState: function(action){
421		ajax.state[action] = ajax.request[action] = '';
422	},
423
424	showErrorMsg: function(msg){
425		alert(msg);
426	},
427
428	callInitFn: function(event) {
429		event.stopPropagation();
430		var params = ajax.params[$(this).attr('id')];
431		var action = params.action;
432		if (ajax.state[action] == 'readyToSubmit' || ajax.state[action] == 'error') {
433			return false;
434		} else {
435			ajax.state[action] = 'readyToSubmit';
436		}
437		ajax.init[action](params);
438	},
439
440	setStatusBoxPosition: function($el) {
441		var newTop = $(document).scrollTop();
442		var rCorner = $(document).scrollLeft() + $(window).width() - ($.browser.opera ? 14 : 8);
443		var newLeft = Math.max(0, rCorner - $el.width());
444		$el.css({ top: newTop, left: newLeft });
445	},
446
447	makeEditable: function(rootElementId, editableType) {
448		var $root = $('#'+rootElementId);
449		var $editable = $('.editable', $root);
450		var inputsHtml = $('#editable-tpl-'+editableType).html();
451		$editable.hide().after(inputsHtml);
452		var $inputs = $('.editable-inputs', $root);
453		if (editableType == 'input' || editableType == 'textarea') {
454			$('.editable-value', $inputs).val( $.trim($editable.text()) );
455		}
456		$('input.editable-submit', $inputs).click(function(){
457			var params = ajax.params[rootElementId];
458			var $val = $('.editable-value', '#'+rootElementId);
459			params.value = ($val.size() == 1) ? $val.val() : $val.filter(':checked').val();
460			params.submit = true;
461			ajax.init[params.action](params);
462		});
463		$('input.editable-cancel', $inputs).click(function(){
464			ajax.restoreEditable(rootElementId);
465		});
466		$inputs.show().find('.editable-value').focus();
467		$root.removeClass('editable-container');
468	},
469
470	restoreEditable: function(rootElementId, newValue) {
471		var $root = $('#'+rootElementId);
472		var $editable = $('.editable', $root);
473		$('.editable-inputs', $root).remove();
474		if (newValue) {
475			$editable.text(newValue);
476		}
477		$editable.show();
478		ajax.clearActionState( ajax.params[rootElementId].action );
479		ajax.params[rootElementId].submit = false;
480		$root.addClass('editable-container');
481	}
482};
483
484$(document).ready(function(){
485	// Setup ajax-loading box
486	$("#ajax-loading").ajaxStart(function(){
487		$("#ajax-error").hide();
488		$(this).show();
489		ajax.setStatusBoxPosition($(this));
490	});
491	$("#ajax-loading").ajaxStop(function(){ $(this).hide(); });
492
493	// Setup ajax-error box
494	$("#ajax-error").ajaxError(function(req, xml){
495		var status = xml.status;
496		var text = xml.statusText;
497		if (status == 200) {
498			status = '';
499			text = '???????? ?????? ??????';
500		}
501		$(this).html(
502			"?????? ?: <i>"+ ajax.url +"</i><br /><b>"+ status +" "+ text +"</b>"
503		).show();
504		ajax.setStatusBoxPosition($(this));
505	});
506
507	// Bind ajax events
508	$('var.ajax-params').each(function(){
509		var params = $.evalJSON( $(this).html() );
510		params.event = params.event || 'dblclick';
511		ajax.params[params.id] = params;
512		$("#"+params.id).bind(params.event, ajax.callInitFn);
513		if (params.event == 'click' || params.event == 'dblclick') {
514			$("#"+params.id).addClass('editable-container');
515		}
516	});
517});
518
519/**
520  * Autocomplete password
521  **/
522	var array_for_rand_pass = ["a", "A", "b", "B", "c", "C", "d", "D", "e", "E", "f", "F", "g", "G", "h", "H", "i", "I", "j", "J", "k", "K", "l", "L", "m", "M", "n", "N", "o", "O", "p", "P", "q", "Q", "r", "R", "s", "S", "t", "T", "u", "U", "v", "V", "w", "W", "x", "X", "y", "Y", "z", "Z", 0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
523	var array_rand = function (array) {
524		var array_length = array.length;
525		var result = Math.random() * array_length;
526		return Math.floor(result);
527
528	};
529
530	var autocomplete = function (noCenter) {
531		var string_result = ""; // Empty string
532		for (var i = 1; i <= 8; i++) {
533			string_result += array_for_rand_pass[array_rand(array_for_rand_pass)];
534		}
535
536		var _popup_left = (Math.ceil(window.screen.availWidth / 2) - 150);
537		var _popup_top = (Math.ceil(window.screen.availHeight / 2) - 50);
538
539		if (!noCenter) {
540			$("div#autocomplete_popup").css({
541				left:_popup_left + "px",
542				top:_popup_top + "px"
543			}).show(1000);
544		} else {
545			$("div#autocomplete_popup").show(1000);
546		}
547
548		$("input#pass, input#pass_confirm, div#autocomplete_popup input").each(function () {
549			$(this).val(string_result);
550		});
551	};
552	
553$(document).ready(function () {
554	$("span#autocomplete").click(function() {
555		autocomplete();
556	});
557
558	// ??????????? ????
559	var _X, _Y;
560	var _bMoveble = false;
561
562	$("div#autocomplete_popup div.title").mousedown(function (event) {
563		_bMoveble = true;
564		_X = event.clientX;
565		_Y = event.clientY;
566	});
567
568	$("div#autocomplete_popup div.title").mousemove(function (event) {
569		var jFrame = $("div#autocomplete_popup");
570		var jFLeft = parseInt(jFrame.css("left"));
571		var jFTop = parseInt(jFrame.css("top"));
572
573		if (_bMoveble) {
574			if (event.clientX < _X) {
575				jFrame.css("left", jFLeft - (_X - event.clientX) + "px");
576			} else {
577				jFrame.css("left", (jFLeft + (event.clientX - _X)) + "px");
578			}
579
580			if (event.clientY < _Y) {
581				jFrame.css("top", jFTop - (_Y - event.clientY) + "px");
582			} else {
583				jFrame.css("top", (jFTop + (event.clientY - _Y)) + "px");
584			}
585
586			_X = event.clientX;
587			_Y = event.clientY;
588		}
589	});
590
591	$("div#autocomplete_popup div.title").mouseup(function () {
592		_bMoveble = false;
593	}).mouseout(function () {
594		_bMoveble = false;
595	});
596});