﻿// JScript 文件
//19900508 1+9+9+0+0+5+0+8=32 3+2=5 return 5
function s(str){
	var Num=0;
	for(var i=0;i<str.length;i++){
		Num+=parseInt(str.charAt(i));
	}
	return Num<10?Num.toString():s(Num.toString());
}

function $(){
    var length = arguments.length;
    if(length>1){
        if(typeof(arguments[0])=="object"){
            return arguments[0].getElementsByTagName(arguments[1]);
        }
        for(var i = 0, elements = [];i < length; i++){
            elements.push($(arguments[i]));
        }
        return elements;
    }else{
        return document.getElementById(arguments[0]);
    }
}
function $$(s){
    return document.getElementsByTagName(s);
}

String.prototype.Trim = function()
{
    return this.replace(/(^\s*)|(\s*$)/g, "");
}
// 返回字符的长度，一个中文算2个
String.prototype.ChineseLength=function()
{ 
    return this.replace(/[^\x00-\xff]/g,"**").length;
}
// 判断字符串是否以指定的字符串结束
String.prototype.EndsWith = function(str) 
{
    return this.substr(this.length - str.length) == str;
}
// 去掉字符左端的的空白字符
String.prototype.LeftTrim = function()
{
    return this.replace(/(^[\\s]*)/g, "");
}
// 去掉字符右端的空白字符
String.prototype.RightTrim = function()
{
    return this.replace(/([\\s]*$)/g, "");
}
// 判断字符串是否以指定的字符串开始
String.prototype.StartsWith = function(str) 
{
    return this.substr(0, str.length) == str;
}
// 去掉字符两端的空白字符
String.prototype.Trim = function()
{
    return this.replace(/(^\s*)|(\s*$)/g, "");
}
   //[\u4E00-\u9FA5]为汉字﹐[\uFE30-\uFFA0]为全角符号 [\uFE30-\uFFA0\u4E00-\u9FA5\s]为全角汉字和符号  

String.prototype.ChkChinese = function()  //检测是否全部为汉字 允许空格和换行
{
   return /^[\uFE30-\uFFA0\u4E00-\u9FA5\s]+$/g.test(this);   
}

String.prototype.ChkBigCode = function()   //检测是否全部为全角字符目前未成功
{   
   return /^[\uFE30-\uFFA0\u4E00-\u9FA5\s]+$/g.test(this);   
}
String.prototype.FilterImage=function(){
return this.replace(/<img.*?>/gi,"");
}

String.prototype.IsMail=function()//E-mail值检测
{ 
return /^([a-zA-Z0-9]*[-_.]?[a-zA-Z0-9]+)+@([\w-]+\.)+[a-zA-Z]{2,}$/.test(this);
}

String.prototype.IsPlusInt=function(empty)//数值检测
{
    if(empty){
        return /^[0-9]{0,}$/.test(this);  
    }else{
        return /^[0-9]{1,}$/.test(this);  
    }
}
String.prototype.IsPlusFloat = function()//检测是否为非负数
{
  
       return /^\d+(\.\d+)?$/.test(this);

}

Number.prototype.substring=function(index,lastindex)
{
	return this.toString().substring(index,lastindex)	
}
Number.prototype.substr=function(index,lastindex)
{
	return this.toString().substr(index,lastindex)	
}
Number.prototype.indexOf=function(Num)
{
	return this.toString().indexOf(Num.toString())	
}
Number.prototype.lastIndexOf=function(Num)
{
	return this.toString().lastIndexOf(Num.toString())	
}


function getXMLHttpRequest(){
  var XHR;
  
  if(window.ActiveXObject){
    try {
      XHR = new ActiveXObject("Msxml2.XMLHTTP") ;
    }
    catch(e){
      try{
        XHR = new ActiveXObject("Microsoft.XMLHTTP") ;
      }
      catch(e){
        XHR = false ;
      }
    }
  }
  else if(window.XMLHttpRequest)
    XHR = new XMLHttpRequest();

  return XHR ;
}

function ajax(url,fun){
 var xmlHttp = getXMLHttpRequest();
 
 if (!xmlHttp){
   return false;
  }
  
  xmlHttp.onreadystatechange = function() {
    if(xmlHttp.readyState == 4){
      if (xmlHttp.status == 200){
        reply = xmlHttp.responseText;
        doOK(reply,fun);
      }
      else
      {
        doError(xmlHttp.status);
      }
    }
  }
  
  xmlHttp.open("get",url,true);
xmlHttp.setRequestHeader("If-Modified-Since","0");
//以上一句 禁止IE缓存
  xmlHttp.send(null);

}

function doOK(s,fun) {
  //返回结果处理
  eval(fun);
}

function doError(error) {
  //错误处理
  alert("意外错误！")
}

// 调用示例msg("错误提示",error,true,"",300,100,"20px;","#333333","#FFFFFF",60)
function AlertInfo(title,info,allowclose,clsfun,w,top){
msg(title,info,allowclose,clsfun,w,top,"10px","#333333","","#FFFFFF",100);
}
function msg(title,info,allowclose,clsfun,w,top,padding,bordercolor,Pbgcolor,bgcolor,alpha){
this.close();
		if(w==undefined)w=200;
		if(top==undefined)top=100;
		if(padding==undefined)padding="20px;";
		if(bordercolor==undefined)bordercolor="#333333";
		if(bgcolor==undefined)bgcolor="#FFFFFF";
		if(alpha==undefined)alpha=60;
		
var p=document.createElement("DIV");
	p.id="p";
	p.style.position="absolute";
	p.style.width=document.body.scrollWidth;
	p.style.height=(document.body.offsetHeight>document.body.scrollHeight)?'100%':document.body.scrollHeight;
	p.style.zIndex='998';
	p.style.top='0px';
  p.style.left='0%';
	p.style.backgroundColor=Pbgcolor;
	p.style.opacity='0.5';
	p.style.filter="alpha(opacity="+alpha+")";
	document.body.appendChild(p);
	var p1=document.createElement("DIV");
	p1.style.position="absolute";
	p1.style.width=w+"px";
	p1.id="p1";
	var left=Math.ceil(((document.body.scrollWidth)-parseInt(p1.style.width.replace('px',''))))/2
	p1.style.height="";
	p1.style.zIndex='999';	
	p1.style.top=top+document.body.scrollTop+'px';
  p1.style.left=left+'px';
	p1.style.border="0px solid "+bordercolor+"";
	var html="";
  html+="<center>"
  html+="<div class='p3' style='height:1px;overflow:hidden;background:"+bordercolor+";width:"+(Number(w)-6)+"px;border-left:1px solid "+bordercolor+";border-right:1px solid "+bordercolor+";'></div>"
  html+="<div class='p2' style='height:1px;overflow:hidden;background:"+bordercolor+";width:"+(Number(w)-4)+"px;border-left:1px solid "+bordercolor+";border-right:1px solid "+bordercolor+";'></div>"
  html+="<div class='p2' style='height:1px;overflow:hidden;background:"+bordercolor+";width:"+(Number(w)-2)+"px;border-left:1px solid "+bordercolor+";border-right:1px solid "+bordercolor+";'></div>"
  html+="<div class='p1' style='height:30px;overflow:hidden;background:"+bordercolor+";width:"+w+"px;border-left:1px solid "+bordercolor+";border-right:1px solid "+bordercolor+";color:#fff;font-size:9pt;font-weight:bold;text-align:left; padding-top:5px;'>&nbsp;&nbsp;"+title+"</div>"
  if(allowclose){
  var btm="<br><p align=center>[ <a href='javascript:this.close()'>关闭</a> ]</p>";
  }else{
  var btm="";
  }
	html+="<div id='c' style='width:"+w+"px;background-color:"+bgcolor+";border-left:1px solid "+bordercolor+";border-right:1px solid "+bordercolor+";font-size:9pt;' align='left'><div style='padding:"+padding+";'>"+info+btm+"</div></div>"
  html+="<div class='p1' style='height:1px;overflow:hidden;background:"+bgcolor+";width:"+(Number(w)-2)+"px;border-left:1px solid "+bordercolor+";border-right:1px solid "+bordercolor+";'></div>"
  html+="<div class='p2' style='height:1px;overflow:hidden;background:"+bgcolor+";width:"+(Number(w)-4)+"px;border-left:1px solid "+bordercolor+";border-right:1px solid "+bordercolor+";'></div>"
  html+="<div class='p3' style='height:1px;overflow:hidden;background:"+bordercolor+";width:"+(Number(w)-6)+"px;border-left:1px solid "+bordercolor+";border-right:1px solid "+bordercolor+"'></div>"
  html+="</center>"
	document.body.appendChild(p1);
	p1.innerHTML=html;
	if($$("select")){
	var arr=$$("select");
	var i=0;
	while(i<arr.length){
	  arr[i].style.visibility='hidden';
	  i++;
	}
	}
	if($$("iframe")[0]){
	if($$("iframe")[0].name){
	iframe=$$("iframe")[0].name
	var arr2=eval("window."+iframe+".document.getElementsByTagName('select');");
	var i=0
	while(i<arr2.length){
	  arr2[i].style.visibility='hidden';
	  i++;
	}
	}
	}
	if($$("iframe")[1]){
	if($$("iframe")[1].name){
	iframe=$$("iframe")[1].name
	var arr3=eval("window."+iframe+".document.getElementsByTagName('select');");
	var i=0
	while(i<arr3.length){
	  arr3[i].style.visibility='hidden';
	  i++;
	}
	}
	}
	this.close=function(){
	if($('p')){
		document.body.removeChild($('p'));
	}
	if($('p1')){
		document.body.removeChild($('p1'));
	}
	if($$("select")){
	var arr=$$("select");
	var i=0;
	while(i<arr.length){
	  arr[i].style.visibility='visible';
	  i++;
	}
	}
	if($$("iframe")[0]){
	if($$("iframe")[0].name){
	iframe=$$("iframe")[0].name
	var arr2=eval("window."+iframe+".document.getElementsByTagName('select');");
	var i=0
	while(i<arr2.length){
	  arr2[i].style.visibility='visible';
	  i++;
	}
	}
	}
	if($$("iframe")[1]){
	if($$("iframe")[1].name){
	iframe=$$("iframe")[1].name
	var arr3=eval("window."+iframe+".document.getElementsByTagName('select');");
	var i=0
	while(i<arr3.length){
	  arr3[i].style.visibility='visible';
	  i++;
	}
	}
	}
	eval(clsfun)
	}
}