﻿if(typeof(JavaScript)=="undefined")
{
    var JavaScript = new Object();
};
JavaScript.createNameSpace = function(NameSpace)
{
    var NameSpaceArray = NameSpace.split(".");
    for(var i=0;i<NameSpaceArray.length;i++)
    {
        var s = "";
        for(var j=0;j<=i;j++)
        {
            s = s + "."+NameSpaceArray[j];
        }
        if(s.length>0){
            s = s.substring(1,s.length);
            var js = "if(typeof("+s+")=='undefined') "+s+" = new Object();";
            eval(js);           
        }
    }
};

JavaScript.createNameSpace("JavaScript.Common");
JavaScript.Common.HttpRequest = function()
{
    this.XmlHttp = this.GetHttpObject();
    this.FormDataArray = new Array();
    this.FormData = "";
    this.Url = "";
    this.Method = "";
    this.Async = true;
    this.User = "";
    this.Password = "";
};

JavaScript.Common.HttpRequest.prototype.StrCode = function(str){if(encodeURIComponent) return encodeURIComponent(str);if(escape) return escape(str);}

JavaScript.Common.HttpRequest.prototype.addFormData = function(key,value,isencode)
{
    if(this.FormDataArray.length==0)
    {
        if(isencode)
            this.FormData = key + "=" + value;
        else
            this.FormData = key + "=" + this.StrCode(value);
    }
    else
    {
        if(isencode)
            this.FormData += "&" + key + "=" + this.StrCode(value);
        else
            this.FormData += "&" + key + "=" + value;
    }

    this.FormDataArray[this.FormDataArray.length] = new Array();

    this.FormDataArray[this.FormDataArray.length-1][0] = key;
    if(isencode)
        this.FormDataArray[this.FormDataArray.length-1][1] = this.StrCode(value);
    else
        this.FormDataArray[this.FormDataArray.length-1][1] = value;
};

JavaScript.Common.HttpRequest.prototype.removeFormData = function(key)
{
    var FormDataTemp = "";
    var FormDataArrayTemp = new Array();
    
    for(var i=0;i<this.FormDataArray.length;i++)
    {
        if(this.FormDataArray[i][0]!=key)
        {
            if(i==0)
                FormDataTemp = this.FormDataArray[i][0] + "=" +this.FormDataArray[i][1];
            else
                FormDataTemp += "&" + this.FormDataArray[i][0] + "=" +this.FormDataArray[i][1];
                
            FormDataArrayTemp[FormDataArrayTemp.length] = new Array();
            FormDataArrayTemp[FormDataArrayTemp.length-1][0] = this.FormDataArray[i][0];
            FormDataArrayTemp[FormDataArrayTemp.length-1][1] = this.FormDataArray[i][1];
        }
    }
    this.FormData = FormDataTemp;
    this.FormDataArray = FormDataArrayTemp;
};

JavaScript.Common.HttpRequest.prototype.clearFormData = function()
{
    this.FormDataArray.length = 0;
    this.FormData = "";
};

JavaScript.Common.HttpRequest.prototype.GetHttpObject = function()
{
    var xmlhttp;
     
    if (window.XMLHttpRequest)
    {
	    xmlhttp = new XMLHttpRequest();
    }
    else if (window.ActiveXObject)
    {
	    try
	    {
	    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	    }
	    catch (e1)
	    {
	        try
	        {
		        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	        }
	        catch (e2)
	        {
	        }
	    }
    }
    return xmlhttp;
};
 
JavaScript.Common.HttpRequest.prototype.DoCallBack = function()
{ 
  if( this.XmlHttp )
  {
    if( this.XmlHttp.readyState == 4 || this.XmlHttp.readyState == 0 )
    {
    try{
      var oThis = this;
      this.XmlHttp.open(oThis.Method, oThis.Url);
      this.XmlHttp.onreadystatechange = function(){ oThis.ReadyStateChange(); };
      this.XmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	  this.XmlHttp.send(this.FormData);
      }
      catch(e){
        //alert(e);
      }
    }
  }
};
 
JavaScript.Common.HttpRequest.prototype.AbortCallBack = function()
{
  if( this.XmlHttp )
    this.XmlHttp.abort();
};
 
JavaScript.Common.HttpRequest.prototype.OnLoading = function()
{
  // Loading
};
 
JavaScript.Common.HttpRequest.prototype.OnLoaded = function()
{
  // Loaded
};
 
JavaScript.Common.HttpRequest.prototype.OnInteractive = function()
{
  // Interactive
};
 
JavaScript.Common.HttpRequest.prototype.OnComplete = function(responseText, responseXml)
{
  // Complete
};
 
JavaScript.Common.HttpRequest.prototype.OnAbort = function()
{
  // Abort
};
 
JavaScript.Common.HttpRequest.prototype.OnError = function(status, statusText)
{
  // Error
};
 
JavaScript.Common.HttpRequest.prototype.ReadyStateChange = function()
{
  if( this.XmlHttp.readyState == 1 )
  {
    this.OnLoading();
  }
  else if( this.XmlHttp.readyState == 2 )
  {
   this.OnLoaded();
  }
  else if( this.XmlHttp.readyState == 3 )
  {
   this.OnInteractive();
  }
  else if( this.XmlHttp.readyState == 4 )
  {
   if( this.XmlHttp.status == 0 )
      this.OnAbort();
    else if( this.XmlHttp.status == 200 && this.XmlHttp.statusText == "OK" )
        this.OnComplete(this.XmlHttp.responseText, this.XmlHttp.responseXML);
    else
      this.OnError(this.XmlHttp.status, this.XmlHttp.statusText, this.XmlHttp.responseText);   
  }
};

/*构造分页页码的类*/
JavaScript.Common.Pager = function()
{
    this.CurrentPageIndex = 1;/*当前页码*/
    this.PageSize = 5;/*每页显示的记录数*/
    this.RecordCount = 0;/*总记录数*/
    this.HalfOfCenterButtonCount = 2;/*页码中部按钮数的半数*/
    this.InstanceNameString = null;/*当前实例对象名字符串*/
    this.PageCount = 0;/*总页数*/
    this.LeftLinkButtonVisible = true; /*是否显示最左端的按钮*/
    this.CenterLinkButtonVisible = true; /*是否显示中间的按钮*/
    this.RightLinkButtonVisible = true; /*是否显示最右端的按钮*/
    this.LinkButtonCssClass = "BlogGray"; /*链接的样式*/
};

/*构造分页页码的类-------点击页码按钮事件对应的处理函数*/
JavaScript.Common.Pager.prototype.OnPagerNumberButtonClick = function(PageIndex)
{
    
};

JavaScript.Common.Pager.prototype.clickPagerNumberButton = function(PageIndex)
{
    this.CurrentPageIndex = PageIndex;
    if(PageIndex <1)
        this.CurrentPageIndex = 1;
    if(PageIndex >this.PageCount)
        this.CurrentPageIndex = this.PageCount;

    this.OnPagerNumberButtonClick(this.CurrentPageIndex);
}

/*构造分页页码的类-------拼出当前的页码Html*/
JavaScript.Common.Pager.prototype.getPagerHtml = function()
{
    var ReturnHtml = "";
    if(this.RecordCount>0)
    {
        this.PageCount = parseInt(this.RecordCount/this.PageSize);

        if(this.RecordCount%this.PageSize!=0)
        {
            this.PageCount++;
        }
        

        ReturnHtml = '&nbsp;&nbsp;&nbsp;&nbsp;<font color = #000000>当前第<font color = #FF9219> '+this.CurrentPageIndex+'</font> 页 &nbsp; 共 <font color = #FF9219>'+this.PageCount+'</font> 页 &nbsp;</font>';
        if (this.CurrentPageIndex!=1)
        {
          /*首页*/
          ReturnHtml = ReturnHtml+ '<a href="javascript:" onclick="this.blur();'+this.InstanceNameString+'.clickPagerNumberButton('+(1)+');return false;" class="' + this.LinkButtonCssClass + '" style="padding:1px 4px 1px 4px; text-decoration:none;">首页</a>&nbsp;&nbsp;' ;
          /*上一页*/
          ReturnHtml = ReturnHtml+ '<a href="javascript:" onclick="this.blur();'+this.InstanceNameString+'.clickPagerNumberButton('+(this.CurrentPageIndex-1)+');return false;" class="' + this.LinkButtonCssClass + '" style="padding:1px 4px 1px 4px; text-decoration:none;">上一页</a>&nbsp;&nbsp;' ;
        }
        else
        {
              ReturnHtml = ReturnHtml+ '<span style="padding:1px 4px 1px 4px; text-decoration:none;color:Gray;">首页</span>&nbsp;&nbsp;' ;
              ReturnHtml = ReturnHtml+ '<span style="padding:1px 4px 1px 4px; text-decoration:none;color:Gray;">上一页</span>&nbsp;&nbsp;' ;
        }
        if (this.CurrentPageIndex!=this.PageCount)
        {  
         /*下一页*/
         ReturnHtml = ReturnHtml + '<a href="javascript:" onclick="this.blur();'+this.InstanceNameString+'.clickPagerNumberButton('+(this.CurrentPageIndex+1)+');return false;" class="' + this.LinkButtonCssClass + '" style="padding:1px 4px 1px 4px; text-decoration:none;">下一页</a>&nbsp;&nbsp;';
         /*末页*/
         ReturnHtml = ReturnHtml + '<a href="javascript:" onclick="this.blur();'+this.InstanceNameString+'.clickPagerNumberButton('+(this.PageCount)+');return false;" class="' + this.LinkButtonCssClass + '" style="padding:1px 4px 1px 4px; text-decoration:none;">末页</a> &nbsp;';
       }
        else
        {
          ReturnHtml = ReturnHtml+ '<span style="padding:1px 4px 1px 4px; text-decoration:none;;color:Gray;">下一页</span>&nbsp;&nbsp;' ;
          ReturnHtml = ReturnHtml+ '<span style="padding:1px 4px 1px 4px; text-decoration:none;;color:Gray;">末页</span>&nbsp;&nbsp;' ;
  
        }
    
        /*跳转到页*/
        ReturnHtml = ReturnHtml + '跳转到第<input id="jumpPage" type="text" style="width: 20px" onkeypress="enter(this)"/>页&nbsp;&nbsp;<a href="javascript:"  id="jumpGo"  onclick="this.blur();'+this.InstanceNameString+'.clickPagerNumberButton(document.getElementById('+"'jumpPage'"+').value);return false;" class="' + this.LinkButtonCssClass + '" style="padding:1px 4px 1px 4px; text-decoration:none;">确定</a> &nbsp;';
    } 
    if (this.PageCount==1)
    {
       ReturnHtml="<div style='display:none'> "+ReturnHtml+"</div>";
    }
    return ReturnHtml;
};

/*----------------------------------------------- Ajax框架 主体类 结束 2008-05-21 -----------------------------------------------*/


function enter(obj)
{
  if (event.keyCode==13)
  { 
    //window.event.keyCode=9;
    event.returnValue = false;
    document.all("jumpGo").click(); 
  }
}
//----------------------------------------------------------------------
JavaScript.createNameSpace("JavaScript.Common.Window.Document.Body");

JavaScript.Common.Window.Document.Body.onloadListeners = new Array();

JavaScript.Common.Window.Document.Body.addOnloadListener = function(listener)
{
    JavaScript.Common.Window.Document.Body.onloadListeners[JavaScript.Common.Window.Document.Body.onloadListeners.length] = listener;
};

JavaScript.Common.Window.Document.Body.onload = function()
{
    for(var i=0;i<JavaScript.Common.Window.Document.Body.onloadListeners.length;i++)
    {
        eval(JavaScript.Common.Window.Document.Body.onloadListeners[i]);
    }
};

/*页面效果命名空间*/
JavaScript.createNameSpace("JavaScript.Common.Window");



JavaScript.createNameSpace("JavaScript.Utility");

/*------------------------------------------  验证函数  -----------------------------------------*/
JavaScript.Utility.checkEmail = function(email)
{
    var myReg = /^[_a-z0-9.-]+@([_a-z0-9]+\.)+[a-z0-9]{2,3}$/;
    if(myReg.test(email)) return true;
    return false;
};

JavaScript.Utility.checkEmail2 = function(email)
{
    var myReg = /^[_a-z0-9]+@([_a-z0-9]+\.)+[a-z0-9]{2,3}$/;
    if(myReg.test(email)) return true;
    return false;
};

JavaScript.Utility.checkFileExtensionName = function(FileName,RightExtensionName)
{
    var pointLastIndex = FileName.lastIndexOf(".");
	var FileExtensionName=FileName.substring(pointLastIndex,FileName.length);
	FileExtensionName=FileExtensionName.toLowerCase();	
	var RightExtensionNameArray = RightExtensionName.toLowerCase().split("|");	
	for(var i=0;i<RightExtensionNameArray.length;i++)
	{
		if(RightExtensionNameArray[i] == FileExtensionName)
			return true;
	}
	return false;
};



/*处理cookie值的函数*/
JavaScript.Utility.Cookie = function()
{
	this.cookie=document.cookie;
	this.getCookie=function(name)
	{
		var value=null;
		var cookies=this.cookie.split(";");
		var a_cookie;
		for(var i=0;i<cookies.length;i++)
		{
			a_cookie=cookies[i].split("=");
			if(a_cookie[0].replace(" ","")==name)
			{
				value=a_cookie[1];
				break;
			}
		}
		return value;
	}
};

JavaScript.Utility.HtmlEncode = function(text){var re = {'<':'&lt;','>':'&gt;','&':'&amp;','"':'&quot;'};for (i in re) text = text.replace(new RegExp(i,'g'), re[i]);return text;};
JavaScript.Utility.HtmlDecode = function(text){var re = {'&lt;':'<','&gt;':'>','&amp;':'&','&quot;':'"'};for (i in re) text = text.replace(new RegExp(i,'g'), re[i]);return text;};


/*从inputHtml中取出文本部分*/
JavaScript.Utility.getTextFromHtml = function(inputHtml,len)
{
   var re;   
   try {              
   
   re = /<.+?>/g;   
   inputHtml = inputHtml.replace(re, "");
   inputHtml = inputHtml.replace("&nbsp;", "");
   inputHtml = inputHtml.replace("\t", "");
   inputHtml = inputHtml.replace("\r\n", "");
   inputHtml = inputHtml.replace("\t", "");
   inputHtml = inputHtml.replace(" ", ""); 
 
    var length = inputHtml.length;
    if(len<=length&&len!=0)
        inputHtml=inputHtml.substr(0,len);
    return inputHtml; 
    }
    catch(e) {
    return inputHtml;
    }
               
};