﻿var System={
Cache:{},
ScriptFragment:'<s'+'cript[^>]*>([\\S\\s]*?)<\/s'+'cript>',
JSONFilter:/^\/\*-secure-([\s\S]*)\*\/\s*$/,
ThisUrl:location.href,
Reffer:document.reffer,
K:function(x){return x}
};
var Class={
create:function(parent,methods){
if(arguments.length==1&&!Object.isFunction(parent))
methods=parent,parent=null;
var method=function(){
if(!Class.extending)this.initialize.apply(this,arguments);
};
method.superclass=parent;
method.subclasses=[];
if(Object.isFunction(parent)){
Class.extending=true;
method.prototype=new parent();
parent.subclasses.push(method);
delete Class.extending;
}
if(methods)Class.extend(method,methods);
method.prototype.constructor=method;
return method;
},
extend:function(destination,source){
for(var name in source)Class.inherit(destination,source,name);
return destination;
},
inherit:function(destination,source,name){
var prototype=destination.prototype,ancestor=prototype[name],
descendant=source[name];
if(ancestor&&Object.isFunction(descendant)&&
descendant.argumentNames().first()=="$super"){
var method=descendant,descendant=ancestor.wrap(method);
Object.extend(descendant,{
valueOf:function(){return method},
toString:function(){return method.toString()}
});
}
prototype[name]=descendant;
if(destination.subclasses&&destination.subclasses.length>0){
for(var i=0,subclass;subclass=destination.subclasses[i];i++){
Class.extending=true;
Object.extend(subclass.prototype,new destination());
subclass.prototype.constructor=subclass;
delete Class.extending;
Class.inherit(subclass,destination.prototype,name);
}
}
},
mixin:function(destination,source){
return Object.extend(destination,source);
}
};
Object.extend=function(destination,source){
for(var property in source){
destination[property]=source[property];
}
return destination;
};
Object.extend(Object,{
inspect:function(object){
try{
if(object===undefined)return'undefined';
if(object===null)return'null';
return object.inspect?object.inspect():object.toString();
}catch(e){
if(e instanceof RangeError)return'...';
throw e;
}
},
toJSON:function(object){
var type=typeof object;
switch(type){
case'undefined':
case'function':
case'unknown':return;
case'boolean':return object.toString();
}
if(object===null)return'null';
if(object.toJSON)return object.toJSON();
var results=[];
for(var property in object){
var value=Object.toJSON(object[property]);
if(value!==undefined)
results.push(property.toJSON()+': '+value);
}
return'{'+results.join(', ')+'}';
},
toHTML:function(object){
return object&&object.toHTML?object.toHTML():String.interpret(object);
},
keys:function(object){
var keys=[];
for(var property in object)
keys.push(property);
return keys;
},
values:function(object){
var values=[];
for(var property in object)
values.push(object[property]);
return values;
},
clone:function(object){
return Object.extend({},object);
},
isArray:function(object){
return object&&object.constructor===Array;
},
isFunction:function(object){
return typeof object=="function";
},
isString:function(object){
return typeof object=="string";
},
isNumber:function(object){
return typeof object=="number";
},
isUndefined:function(object){
return typeof object=="undefined";
}
});
Object.extend(Function.prototype,{
argumentNames:function(){
var names=this.toString().match(/^[\s\(]*function\s*\((.*?)\)/)[1].split(",").invoke("strip");
return names.length==1&&!names[0]?[]:names;
},
bind:function(){
if(arguments.length<2&&arguments[0]===undefined)return this;
var __method=this,args=$A(arguments),object=args.shift();
return function(){
return __method.apply(object,args.concat($A(arguments)));
}
},
wrap:function(wrapper){
var __method=this;
return function(){
return wrapper.apply(this,[__method.bind(this)].concat($A(arguments)));
}
},
methodize:function(){
if(this._methodized)return this._methodized;
var __method=this;
return this._methodized=function(){
return __method.apply(null,[this].concat($A(arguments)));
};
}
});
Object.extend(Date.prototype,{
Conversion:{
w:604800000,
d:86400000,
h:3600000,
i:60000,
s:1000
},
toFormatString:function(template){
template=!template?'yyyy-mm-dd hh:ii:ss':template;
['yyyy','mm','dd','hh','ii','ss'].each(function(value,index){
template=template.replace(new RegExp(value,'g'),'$'+(++index));
});
return this.toJSON().replace(/^"(\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+)"$/g,template).replace(/\{\d+\}/,
function(index){
index=index.match(/\{(\d+)\}/)[1];
index=index.indexOf('0')==0?index.split('')[1]:index;
index=parseInt(index)-1;
return['January','February','March','April','May','June','July','August','September','October','November','December'][index];
}
);
},
getWeekDay:function(){
return'星期'+'天一二三四五六'.charAt(this.getDay());
},
add:function(interval,number){
return new Date(this.getTime()+number*this.Conversion[interval]);
},
diff:function(interval,date){
return parseInt((date.getTime()-this.getTime())/this.Conversion[interval]);
},
distance:function(){
var d=this.diff('i',new Date());
if(d>1440)return parseInt(d/1440)+'天前';
if(d>60)return parseInt(d/60)+'小时前';
return d+'分钟前';
},
toJSON:function(){
return'"'+this.getFullYear()+'-'+
(this.getMonth()+1).toPaddedString(2)+'-'+
this.getDate().toPaddedString(2)+' '+
this.getHours().toPaddedString(2)+':'+
this.getMinutes().toPaddedString(2)+':'+
this.getSeconds().toPaddedString(2)+'"';
}
});
RegExp.prototype.match=RegExp.prototype.test;
Object.extend(String,{
interpret:function(value){
return value==null?'':String(value);
},
specialChar:{
'\b':'\\b',
'\t':'\\t',
'\n':'\\n',
'\f':'\\f',
'\r':'\\r',
'\\':'\\\\'
}
});
Object.extend(String.prototype,{
size:function(){
var arr=this.split('');
var re=/[^\x00-\xff]/;
for(var i=0,k=0;k<arr.length;i++,k++){
if(re.test(arr[k]))i++;
}
return i;
},
truncate:function(length,truncation){
if(this.size()<=length)return this;
length=length||30;
truncation=truncation===undefined?'...':truncation;
var arr=this.split('');
var result='';
var re=/[^\x00-\xff]/;
for(var i=0,k=0;i<length-truncation.length&&k<arr.length;i++,k++){
result+=arr[k];
if(re.test(arr[k]))i++;
}
return i>=length-truncation.length?
result+truncation:String(this);
},
strip:function(){
return this.replace(/^\s+/,'').replace(/\s+$/,'');
},
stripTags:function(){
return this.replace(/<\/?[^>]+>/gi,'');
},
stripScripts:function(){
return this.replace(new RegExp(System.ScriptFragment,'img'),'');
},
toQueryParams:function(separator){
var match=this.strip().match(/([^?#]*)(#.*)?$/);
if(!match)return{};
return match[1].split(separator||'&').inject({},function(hash,pair){
if((pair=pair.split('='))[0]){
var key=decodeURIComponent(pair.shift());
var value=pair.length>1?pair.join('='):pair[0];
try{
if(value!=undefined)value=decodeURIComponent(value);
}catch(e){
value='';
}
if(key in hash){
if(!Object.isArray(hash[key]))hash[key]=[hash[key]];
hash[key].push(value);
}
else hash[key]=value;
}
return hash;
});
},
toArray:function(){
return this.split('');
},
succ:function(){
return this.slice(0,this.length-1)+
String.fromCharCode(this.charCodeAt(this.length-1)+1);
},
times:function(count){
var result='';
for(var i=0;i<count;i++)result+=this;
return result;
},
capitalize:function(){
return this.charAt(0).toUpperCase()+this.substring(1).toLowerCase();
},
inspect:function(useDoubleQuotes){
var escapedString=this.replace(/[\x00-\x1f\\]/,function(match){
var character=String.specialChar[match[0]];
return character;
});
if(useDoubleQuotes)return'"'+escapedString.replace(/"/g,'\\"').replace(/[\n\r]+/img,'\\n')+'"';
return"'"+escapedString.replace(/'/g,'\\\'')+"'";
},
toJSON:function(){
return this.inspect(true);
},
unfilterJSON:function(filter){
return this.sub(filter||System.JSONFilter,'#{1}');
},
isJSON:function(){
var str=this.replace(/\\./g,'@').replace(/"[^"\\\n\r]*"/g,'');
return(/^[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]*$/).test(str);
},
evalJSON:function(sanitize){
var json=this.unfilterJSON();
try{
if(!sanitize||json.isJSON())return eval('('+json+')');
}catch(e){}
throw new SyntaxError('Badly formed JSON string: '+this.inspect());
},
include:function(pattern){
return this.indexOf(pattern)>-1;
},
empty:function(){
return this=='';
},
blank:function(){
return/^\s*$/.test(this);
},
stripLabelByTagName:function(){
var result=this;
var tags={
table:'(?:table|tbody|tr|td)',
ul:'(?:ul|li)',
dl:'(?:dl|dt|dd)'
};
for(var i=0;i<arguments.length;i++){
var tagName=tags[arguments[i]]?tags[arguments[i]]:arguments[i];
result=result.replace(new RegExp('<\/?'+tagName+'[^>]*>','gi'),'');
}
return result;
},
stripContentByTagName:function(){
var result=this;
var tags={
table:'(?:table|tbody|tr|td)',
ul:'(?:ul|li)',
dl:'(?:dl|dt|dd)'
};
for(var i=0;i<arguments.length;i++){
var tagName=tags[arguments[i]]?tags[arguments[i]]:arguments[i];
result=result.replace(new RegExp('<'+tagName+'[^>]*>[\\s\\S]*?<\/'+tagName+'[^>]*>','gi'),'');
}
return result;
},
replaces:function(){
var result=this;
$A(arguments).each(function(pattern){
result=result.replace(pattern,'');
});
return result;
},
make:function(){
var result=this;
$A(arguments).each(function(value,index){
result=result.replace(new RegExp('^\\$'+(index+1),'gi'),value);
result=result.replace(new RegExp('([^\\\\])\\$'+(index+1),'gi'),'$1'+value);
});
return result;
},
format:function(){
var temp=$A(arguments);
return this.replace(/.?\{\d+\}/img,function(value){
if(value.indexOf('\\')==0)return value.replace('\\','');
var index=value.match(/{(\d+)\}/)[1];
return value.replace(/{(\d+)\}/,temp[index]);
});
},
matchs:function(pattern,reduce,before){
var result=[];
var arr;
while(arr=pattern.exec(this)){
if(reduce)arr=arr.lost(0);
if(before&&!arr[1])arr=before+arr;
result.push(arr);
}
if(result.length==0)result='';
return result;
}
});
String.prototype.parseQuery=String.prototype.toQueryParams;
function $C(value){
return''+value;
}
var $break={};
var Enumerable={
each:function(iterator,context){
var index=0;
iterator=iterator.bind(context);
try{
this._each(function(value){
iterator(value,index++);
});
}catch(e){
if(e!=$break)throw e;
}
return this;
},
collect:function(iterator,context){
iterator=iterator?iterator.bind(context):System.K;
var results=[];
this.each(function(value,index){
results.push(iterator(value,index));
});
return results;
},
detect:function(iterator,context){
iterator=iterator.bind(context);
var result;
this.each(function(value,index){
if(iterator(value,index)){
result=value;
throw $break;
}
});
return result;
},
findAll:function(iterator,context){
iterator=iterator.bind(context);
var results=[];
this.each(function(value,index){
if(iterator(value,index))
results.push(value);
});
return results;
},
grep:function(filter,iterator,context){
iterator=iterator?iterator.bind(context):System.K;
var results=[];
if(Object.isString(filter))
filter=new RegExp(filter);
this.each(function(value,index){
if(filter.match(value))
results.push(iterator(value,index));
});
return results;
},
include:function(object){
if(Object.isFunction(this.indexOf))
return this.indexOf(object)!=-1;
var found=false;
this.each(function(value){
if(value===object){
found=true;
throw $break;
}
});
return found;
},
inject:function(memo,iterator,context){
iterator=iterator.bind(context);
this.each(function(value,index){
memo=iterator(memo,value,index);
});
return memo;
},
invoke:function(method){
var args=$A(arguments).slice(1);
return this.map(function(value){
return value[method].apply(value,args);
});
},
max:function(iterator,context){
iterator=iterator?iterator.bind(context):System.K;
var result;
this.each(function(value,index){
value=iterator(value,index);
if(result==undefined||value>=result)
result=value;
});
return result;
},
min:function(iterator,context){
iterator=iterator?iterator.bind(context):System.K;
var result;
this.each(function(value,index){
value=iterator(value,index);
if(result==undefined||value<result)
result=value;
});
return result;
},
partition:function(iterator,context){
iterator=iterator?iterator.bind(context):System.K;
var trues=[],falses=[];
this.each(function(value,index){
(iterator(value,index)?
trues:falses).push(value);
});
return[trues,falses];
},
pluck:function(property){
var results=[];
this.each(function(value){
results.push(value[property]);
});
return results;
},
sortBy:function(iterator,context){
iterator=iterator.bind(context);
return this.map(function(value,index){
return{value:value,criteria:iterator(value,index)};
}).sort(function(left,right){
var a=left.criteria,b=right.criteria;
return a<b?-1:a>b?1:0;
}).pluck('value');
},
toArray:function(){
return this.map();
},
zip:function(){
var iterator=System.K,args=$A(arguments);
if(Object.isFunction(args.last()))
iterator=args.pop();
var collections=[this].concat(args).map($A);
return this.map(function(value,index){
return iterator(collections.pluck(index));
});
},
size:function(){
return this.toArray().length;
},
inspect:function(){
return'#<Enumerable:'+this.toArray().inspect()+'>';
}
};
Object.extend(Enumerable,{
map:Enumerable.collect,
find:Enumerable.detect,
select:Enumerable.findAll,
filter:Enumerable.findAll,
member:Enumerable.include,
entries:Enumerable.toArray
});
function $A(iterable){
if(!iterable)return[];
if(iterable.toArray)return iterable.toArray();
else{
var results=[];
for(var i=0,length=iterable.length;i<length;i++)
results.push(iterable[i]);
return results;
}
}
Object.extend(Array.prototype,Enumerable);
if(!Array.prototype._reverse)Array.prototype._reverse=Array.prototype.reverse;
Object.extend(Array.prototype,{
_each:function(iterator){
for(var i=0,length=this.length;i<length;i++)
iterator(this[i]);
},
clear:function(){
this.length=0;
return this;
},
first:function(){
return this[0];
},
last:function(){
return this[this.length-1];
},
compact:function(){
return this.select(function(value){
return value!=null;
});
},
flatten:function(){
return this.inject([],function(array,value){
return array.concat(Object.isArray(value)?
value.flatten():[value]);
});
},
without:function(){
var values=$A(arguments).flatten();
return this.select(function(value){
return!values.include(value);
});
},
reverse:function(inline){
return(inline!==false?this:this.toArray())._reverse();
},
reduce:function(){
return this.length>1?this:this[0];
},
uniq:function(sorted){
return this.inject([],function(array,value,index){
if(0==index||(sorted?array.last()!=value:!array.include(value)))
array.push(value);
return array;
});
},
clone:function(){
return[].concat(this);
},
lost:function(){
var losts=$A(arguments);
return this.findAll(function(value,index){
return!losts.include(index);
})
},
size:function(){
return this.length;
},
inspect:function(){
return'['+this.map(Object.inspect).join(', ')+']';
},
toJSON:function(){
var results=[];
this.each(function(object){
var value=Object.toJSON(object);
if(value!==undefined)results.push(value);
});
return'['+results.join(', ')+']';
}
});
if(!Array.prototype.indexOf)Array.prototype.indexOf=function(item,i){
i||(i=0);
var length=this.length;
if(i<0)i=length+i;
for(;i<length;i++)
if(this[i]===item)return i;
return-1;
};
Array.prototype.toArray=Array.prototype.clone;
function $w(string){
string=string.strip();
return string?string.split(/\s+/):[];
}
Object.extend(Number.prototype,{
toColorPart:function(){
return this.toPaddedString(2,16);
},
succ:function(){
return this+1;
},
times:function(iterator){
$R(0,this,true).each(iterator);
return this;
},
toPaddedString:function(length,radix){
var string=this.toString(radix||10);
return'0'.times(length-string.length)+string;
},
toFormatString:function(pointPsti,precision){
if([''].indexOf(this)>-1)return 0;
pointPsti=pointPsti||3;
precision=precision||2;
var num=this+'',numDc='',temp='';
if(num.indexOf('.')>-1){
ptPs=num.indexOf('.');
numDc=num.substr(ptPs).substr(0,precision+1);
while(numDc.length<precision+1){
numDc+='0';
}
num=num.substr(0,ptPs);
}
for(var i=num.length-1;i>=0;temp+=num.substr(i,1),i--);
var re=new RegExp('(.{'+pointPsti+'})','g');
temp=temp.replace(re,'$1,');
num='';
for(var i=temp.length-1;i>=0;num+=temp.substr(i,1),i--);
num=num.replace(/^\,|\,$/,'')+numDc;
if(precision==0)num=num.replace(/\.$/,'');
return num;
},
toJSON:function(){
return isFinite(this)?this.toString():'null';
}
});
$w('abs round ceil floor').each(function(method){
Number.prototype[method]=Math[method].methodize();
});
var Hash=function(object){
if(object instanceof Hash)this.merge(object);
else Object.extend(this,object||{});
};
Object.extend(Hash,{
toQueryString:function(obj){
var parts=[];
parts.add=arguments.callee.addPair;
this.prototype._each.call(obj,function(pair){
if(!pair.key)return;
var value=pair.value;
if(value&&typeof value=='object'){
if(Object.isArray(value))value.each(function(value){
parts.add(pair.key,value);
});
return;
}
parts.add(pair.key,value);
});
return parts.join('&');
},
toJSON:function(object){
var results=[];
this.prototype._each.call(object,function(pair){
var value=Object.toJSON(pair.value);
if(value!==undefined)results.push(pair.key.toJSON()+': '+value);
});
return'{'+results.join(', ')+'}';
}
});
Hash.toQueryString.addPair=function(key,value,prefix){
key=encodeURIComponent(key);
if(value===undefined)this.push(key);
else this.push(key+'='+(value==null?'':encodeURIComponent(value)));
};
Object.extend(Hash.prototype,Enumerable);
Object.extend(Hash.prototype,{
_each:function(iterator){
for(var key in this){
var value=this[key];
if(value&&value==Hash.prototype[key])continue;
var pair=[key,value];
pair.key=key;
pair.value=value;
iterator(pair);
}
},
keys:function(){
return this.pluck('key');
},
values:function(){
return this.pluck('value');
},
index:function(value){
var match=this.detect(function(pair){
return pair.value===value;
});
return match&&match.key;
},
merge:function(hash){
return $H(hash).inject(this,function(mergedHash,pair){
mergedHash[pair.key]=pair.value;
return mergedHash;
});
},
remove:function(){
var result;
for(var i=0,length=arguments.length;i<length;i++){
var value=this[arguments[i]];
if(value!==undefined){
if(result===undefined)result=value;
else{
if(!Object.isArray(result))result=[result];
result.push(value);
}
}
delete this[arguments[i]];
}
return result;
},
get:function(){
var result={};
var arr=$A(arguments).flatten().join(',').split(',');
for(var i=0,keys=this.keys();i<keys.length;i++){
if(arr.include(keys[i]))result[keys[i]]=this[keys[i]];
}
return $H(result);
},
lost:function(){
var result=$H();
var arr=$A(arguments).flatten();
for(var i=0,keys=this.keys();i<keys.length;i++){
if(!arr.include(keys[i]))result[keys[i]]=this[keys[i]];
}
return $H(result);
},
toQueryString:function(){
return Hash.toQueryString(this);
},
inspect:function(){
return'#<Hash:{'+this.map(function(pair){
return pair.map(Object.inspect).join(': ');
}).join(', ')+'}>';
},
toJSON:function(){
return Hash.toJSON(this);
}
});
function $H(object){
if(object instanceof Hash)return object;
return new Hash(object);
};
if(function(){
var i=0,Test=function(value){this.key=value};
Test.prototype.key='foo';
for(var property in new Test('bar'))i++;
return i>1;
}())Hash.prototype._each=function(iterator){
var cache=[];
for(var key in this){
var value=this[key];
if((value&&value==Hash.prototype[key])||cache.include(key))continue;
cache.push(key);
var pair=[key,value];
pair.key=key;
pair.value=value;
iterator(pair);
}
};
ObjectRange=Class.create();
Object.extend(ObjectRange.prototype,Enumerable);
Object.extend(ObjectRange.prototype,{
initialize:function(start,end,exclusive){
this.start=start;
this.end=end;
this.exclusive=exclusive;
},
_each:function(iterator){
var value=this.start;
while(this.include(value)){
iterator(value);
value=value.succ();
}
},
include:function(value){
if(value<this.start)
return false;
if(this.exclusive)
return value<this.end;
return value<=this.end;
}
});
var $R=function(start,end,exclusive){
return new ObjectRange(start,end,exclusive);
};
function tab(name,index,num){
for(var i=1;i<=num;i++){
$('#'+name+'-tab-'+i)[0].className='';
$('#'+name+'-data-'+i).hide();
}
$('#'+name+'-tab-'+index)[0].className='on';
$('#'+name+'-data-'+index).show();
}
function $E(id){
return document.getElementById(id);
}
function $F(name){
return $("input[name='"+name+"']").val();
}