// JavaScript Document
if(!ScriptMS||typeof(ScriptMS)!=="object")
{
	 var ScriptMS={};
	     ScriptMS.Scripts=[];
		 ScriptMS.LoadScript=function(SrcList,CallBackFun)//使用Ajax对象加载Javascript文件
		 {
			
			if(typeof(CallBackFun)!=="function")
			{
				CallBackFun==""?CallBackFun=new Function("return;"):CallBackFun=new Function(CallBackFun);
				
				//CallBackFun=new Function(CallBackFun)
			}
			
			if(ScriptMS.CheckDocumentScript(SrcList)=="")
			{
				CallBackFun();
				return false;
			}
			
			for(var i in ScriptMS.Scripts)
					{
						if(ScriptMS.Scripts[i].Url==SrcList)
						{
							return false;
							
						}
					}
			
			ScriptMS.Scripts[ScriptMS.Scripts.length]={};
			ScriptMS.Scripts[ScriptMS.Scripts.length-1].Id=[];
			ScriptMS.Scripts[ScriptMS.Scripts.length-1].Url=SrcList;
			ScriptMS.Scripts[ScriptMS.Scripts.length-1].CallBackFun=CallBackFun;
			for(var S=0;S<SrcList.length;S++)
				{
						
						var AjaxObj=Ajax();
						AjaxObj.CallbackFun=ScriptMS.CallBack_LoadScript;
						ScriptMS.Scripts[ScriptMS.Scripts.length-1].Id[S]=AjaxObj.Id;
						AjaxObj.Get(Site.GetRootPath()+SrcList[S]+'?AjaxTime='+((new Date()).valueOf()));
						//alert(Site.GetRootPath()+SrcList[S]);				
				}
				
			
			return false;
		}
	
 		ScriptMS.CallBack_LoadScript=function(Response)//使用Ajax对象加载Javascript文件的回调函数
		{
			
		var DScript=document.createElement("script");
            DScript.type="text/javascript";
			DScript.text=Response.Text;
			DScript.id=Response.AjaxObjId+"";
      	var Head=document.getElementsByTagName("head")[0];
		for(S in ScriptMS.Scripts)
			{
				
				for(var i in ScriptMS.Scripts[S].Id)
					{
						if(ScriptMS.Scripts[S].Id[i]==Response.AjaxObjId)
							{
								
								DScript.Url=ScriptMS.Scripts[S].Url[i];
								ScriptMS.Scripts[S].Id.splice(i,1);
								ScriptMS.Scripts[S].Url.splice(i,1);
								Head.appendChild(DScript);
								
								if(ScriptMS.Scripts[S].Id.length==0)
									{   
										
										
										try
										{
											ScriptMS.Scripts[S].CallBackFun();
										}
										catch(e)
										{
											
											alert("脚本已经加载，但回调时发生未知错误："+e.description );
											throw (e);
										}
								
										ScriptMS.Scripts.splice(S,1);
										return true;
									}
							}
					}
			} 
			}
	
		 ScriptMS.CheckDocumentScript=function(UrlList)//检查脚本是否已经载入
		 {
		   var ScriptList=document.getElementsByTagName("script");
			for(i in UrlList)
				{
					for(Ds=0;Ds<ScriptList.length;Ds++)
						{
							if(ScriptList[Ds].Url==UrlList[i])
								{
									UrlList.splice(i,1);
								}
						}
				}
			return UrlList;
	 	}
	
		 ScriptMS.RemoveDocumentScript=function(UrlList)//移除页面动态载入的脚本
			{
			   var ScriptList=document.scripts||document.getElementsByTagName("script");
				for(i in UrlList)
					{
						for(Ds=0;Ds<ScriptList.length;Ds++)
							{
								if(ScriptList[Ds].Url==UrlList[i])
									{
										ScriptList[Ds].parentNode.removeChild(ScriptList[Ds]);
									}
							}
					}
				return true;
			}
		 }
  
   
if(!Site||typeof(Site)!=="object")
{
	var Site={};
		Site.GetRootPath=function()
		{
			return "http://"+window.location.host+"/";
		}
}

function DecodeText(Str) //解码
	{
			return (Str == null ? "" : decodeURIComponent(decodeURIComponent(Str)));
	}	
	
function EncodeText(Str) //编码
	{
			return  (Str == null ? "" :encodeURIComponent(encodeURIComponent(Str)));
	}
	
	//替换空字符
String.prototype.Trim= function() { return this.replace(/(^\s*)|(\s*$)/g, "");} 

function GetViewportInfo() //取得浏览器视区高度
    {
		var Viewport={}
        	Viewport.H = (window.innerHeight) ? window.innerHeight : (document.documentElement && document.documentElement.clientHeight) ? document.documentElement.clientHeight : document.body.offsetHeight;
			Viewport.W = (window.innerWidth) ? window.innerWidth : (document.documentElement && document.documentElement.clientWidth) ? document.documentElement.clientWidth : document.body.offsetWidth;
        return Viewport;
    }
	
function SetObjFocus(Obj)
	
	{
		if(typeof(Obj)!='object')
		{
			if(!$F(Obj))
				{
					return false;
				}
			Obj=$F(Obj);
		}
		try
			{
				var rtextRange =Obj.createTextRange(); 
				rtextRange.moveStart('character',Obj.value.length); 
				rtextRange.collapse(true); 
				rtextRange.select(); 
			}
			catch(e)
			{
				Obj.focus();
			}
		return true;
	}
	
function $F(ObjId)//取得对象
	{
		if(!ObjId){return false;}
		if(!document.getElementById(ObjId))
		{
			return false;
		}
		return document.getElementById(ObjId);	
	}

function JsonObject2Param(Obj)
{
	if(typeof(Obj)=="function"||typeof(Obj)=="undefined"||Obj==null){return ''}
	if(typeof(Obj)=="date"){return EncodeText(new Date(Obj).format('yyyy-MM-dd hh:mm:ss'));}
	if(typeof(Obj)!=="object"){return EncodeText(Obj);}
	var Param = [];
   	if(!Obj.sort)
	 	{
       		
       		for(var i in Obj)
	   		{
			 Param[Param.length]=i;
			 Param[Param.length]="=";
			 Param[Param.length]=JsonObject2Param(Obj[i]);
			 Param[Param.length]="&";
       		}
       		Param[Param.length-1]=""
     	}
	 	else
		{
       		
       		for(var i =0;i<Obj.length;i++)
			{
			 Param[Param.length]=JsonObject2Param(Obj[i]);
			 Param[Param.length]="&";
       		}
      		 Param[Param.length-1]=""
     	}
		return(Param.join(""));
}

function O2Json(Obj)
{
	if(typeof(Obj)=="function"||typeof(Obj)=="undefined"||Obj==null){return '"'+null+'"'}
	if(typeof(Obj)!=="object"){return '"'+Obj+'"';}
	var Json = [];
   	if(!Obj.sort)
	 	{
       		Json[0]="{"
       		for(var i in Obj)
	   		{
			 Json[Json.length]='"'+i+'"';
			 Json[Json.length]=":";
			 Json[Json.length]=O2Json(Obj[i]);
			 Json[Json.length]=",";
       		}
       		Json[Json.length-1]="}"
     	}
	 	else
		{
       		Json[0]="["
       		for(var i =0;i<Obj.length;i++)
			{
			 Json[Json.length]=O2Json(Obj[i]);
			 Json[Json.length]=",";
       		}
      		 Json[Json.length-1]="]"
     	}
	return(Json.join(""));
}

function ReplaceWithNull(V,Str)//替换空文本为新文本
{
	if(!V){return Str;}
	return(V.toString().Trim()==""?Str:V)
}

function HTMLEncode(Text)//转换HTML编码
{
	Text = Text.replace(/&/g, "&amp;") ;
	Text = Text.replace(/"/g, "&quot;");
	Text = Text.replace(/'/g, "&acute;") ;
	Text = Text.replace(/</g, "&lt;");
	Text = Text.replace(/>/g, "&gt;");
	Text = Text.replace(/\ /g,"&nbsp;");
	Text = Text.replace(/\n/g,"<br>");
	Text = Text.replace(/\t/g,"&nbsp;&nbsp;&nbsp;&nbsp;");
	return Text;
}

//时间随机数
Rnd.Seed=new Date().getTime();
function Rnd() {
　　　　Rnd.Seed = (Rnd.Seed*9301+49297) % 233280;
　　　　return Rnd.Seed/(233280.0);
};
function Rand(number) {
　　　　return Math.ceil(Rnd()*number);
};

Date.prototype.Format = function(format)//格式化时间
{   
	
	var o = 
	{   
    "M+" : this.getMonth()+1, //month   
    "d+" : this.getDate(),    //day   
    "h+" : this.getHours(),   //hour   
    "m+" : this.getMinutes(), //minute   
    "s+" : this.getSeconds(), //second   
    "q+" : Math.floor((this.getMonth()+3)/3), //quarter   
    "S" : this.getMilliseconds() //millisecond   
   }   
   if(/(y+)/.test(format)) format=format.replace(RegExp.$1,   
   (this.getFullYear()+"").substr(4 - RegExp.$1.length));   
   for(var k in o)if(new RegExp("("+ k +")").test(format))   
   format = format.replace(RegExp.$1,   
   RegExp.$1.length==1 ? o[k] :    
   ("00"+ o[k]).substr((""+ o[k]).length));   
   return format.replace(/NaN-aN-aN aN:aN:aN/ig,"");   
}  

function Left(Str,N)//取左边N个字符
{
	if(!Str){return Str}
	if(Str.length<N){return Str}
	return Str.toString().substring(0,N)+'&nbsp;…';
}