﻿document.write('<script src="http://static.zs.cx/js/zh_cn/global.js"><\/script>');
var national={
	language:'zh_cn',
	setLang:function(module,l){
		if(l)this.language=l;
		document.write('<script src="http://static.zs.cx/js/lang/'+this.language+'/'+module+'.js"><\/script>');
	},
	getStr:function(type,child,rep){
		var o=this.getLangData(type);
		if(o&&o[child]) return o[child];
		else if(rep) return rep;
		else return '';
	},
	getLangData:function(type){
		if(typeof(o_language)!='object') o_language={};
		return o_language[type];
	},
	addLangData:function(obj,name){
		if(!obj[this.language]){
			alert('错误的语言文件');
			return;
		}
		if(typeof(o_language)!='object') o_language={};
		o_language[name]=obj[this.language];
	},
	convertStr:function(str,type){
		var src=this.getLangData(type);
		return this.reStr(str,src);
	},
	reStr:function(str,src){
		var mode=false;
		if(typeof(src)=='object'){
			this.src=src;
			mode=true;
		}
		var obj=this;
		var re=/%\{(\w+):(.*?)\}/g;
		if(mode)	str=str.replace(re,function(mstr,m1,m2){return obj.matchStr(mstr,m1,m2)});
		else str=str.replace(re,this.matchStr2);
		return str;
	},
	formatStr:function(type,params){
		var o=this.getLangData('Format');
		if(!o||!o[type]) return;
		this.src=params;
		var obj=this;
		var re=/#\{(\w+)\}/g;
		return o[type].replace(re,function(mstr,m1){return obj.matchStr3(mstr,m1)});
	},
	matchStr:function(mstr,m1,m2){
		if(this.src[m1]) return this.src[m1];
		else return m2;
	},
	matchStr2:function(mstr,m1,m2){
		return m2;
	},
	matchStr3:function(mstr,m1){
		if(this.src[m1]) return this.src[m1];
		else return '';
	},
	showMsg:function(str){
		var src=this.getLangData('Prompt');
		str=this.reStr(str,src);
		alert(str);
	}
};
