﻿/*
select onchange
onblur：移出焦点时
onfocus：移到焦点时
onclick：
ondblclick：双击时
onpropertychange：内容改变时
onkeyup：
div
display : block开
display : none关
 */
String.prototype.DateNow=function(){ var date=new Date(); var year=date.getYear(); var month=date.getMonth()+1; var day=date.getDate(); if (parseInt(month)<10) month='0'+month;if (parseInt(day)<10) day='0'+day; return year+'-'+month+'-'+day; }
String.prototype.TimeNow=function(){ var date=new Date(); var hour=date.getHours(); var minute=date.getMinutes(); var second=date.getSeconds(); if (parseInt(hour)<10) hour='0'+hour; if(parseInt(minute)<10) minute='0'+minute; if (parseInt(second)<10) second='0'+second; return hour+':'+minute+':'+second; }
String.prototype.Trim=function(){ return this.replace(/(^\s*)|(\s*$)/g, ""); }
String.prototype.LTrim=function(){ return this.replace(/^\\s+/, ""); }
String.prototype.RTrim=function(){ return this.replace(/\\s+$/,""); }
String.prototype.Encode=function(){ return escape(this); }
String.prototype.Decode=function(){ return unescape(this); }
function IsVal(type, val)
{
   var regex = "";
   switch(type)
   {
         // 邮政编码
      case "Zip" :
         {
            regex = /^[1-9]\d{5}$/;
            break;
         }
         // 中文字符
      case "CH" :
         {
            regex = /^[^\x00-\xff]$/;
            break;
         }
         // 匹配双字节字符(包括汉字在内)
      case "" :
         {
            regex = /^[^\x00-\xff]+$/;
            break;
         }
         // 英文字符
      case "EN" :
         {
            regex = /^[A-Za-z]+$/;
            break;
         }
         // 数字
      case "Number" :
         {
            regex = /^\d+$/;
            break;
         }
         // 整数
      case "Integer" :
         {
            regex = /^[-\+]?\d+$/;
            break;
         }
         // 实数
      case "Double" :
         {
            regex = /^[-\+]?\d+(\.\d+)?$/;
            break;
         }
         // Email地址
      case "Email" :
         {            
            //regex =/^(\w+((-\w+)|(\.\w+))*)\+\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
            regex = /^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.){1,4}[a-z]{2,4}$/i;
            // = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/ ;
            break;
         }
         // 使用HTTP协议的网址
      case "Uri" :
         {
            regex = /^http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/;
            break;
         }
         // 电话号码
      case "Phone" :
         {
            // regex = /^((\(\d{2,3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}(\-\d{1,4})?$/;
            regex = /^((\(\d{2,3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}(\-\d{1,4})?|((\(\d{2,3}\))|(\d{3}\-))?13\d{9}$/;
            break;
         }
         // 货币
      case "Currency" :
         {
            regex = /^\d+(\.\d+)?$/;
            break;
         }
         // 手机号码
      case "Mobile" :
         {
            regex = /^((\(\d{2,3}\))|(\d{3}\-))?13\d{9}$/;
            // = /^13[0-9]{9}$/ ;
            break;
         }
         // 身份证号码
      case "IDCard" :
         {
            regex = /^(\d{16})|(\d{18})$/;
            break;
         }
         // QQ号码
      case "QQ" :
         {
            regex = /^[1-9]\d{4,10}$/;
            break;
         }
         // 日期
      case "Date" :
         {
            regex = /^([1-9]\d{3})([-\.])(\d{2})([-\.])(\d{2})$/;
            break;
         }
      case "UID" :
         {
            regex = /^([A-Za-z]|[^\x00-\xff]){1}([^\x00-\xff]|\w){1,20}$/;
            break;
         }
     case "PWD" :
         {
            regex = /^\w{6,20}$/;
            break;
         }
         // 是否为空
      case "Require" :
         {
            regex = /.+/;
            break;
         }
      default :
         {
            regex = /.+/;
            break;
         }
         // 判断输入值是否在(n, m)区间
         // var LenMin = 0 ;
         // var LenMax = 0 ;
   }
   if(!regex.test(val.Trim()))
   {
      return (false);
   }
   else
   {
      return (true);
   }
}
function Len(val, min, max)
{
   var val = val.Trim().replace(/[^\x00-\xff]/g, "**").length ;
   
   if ((val>=min)&&(val<=max))
   {
      return (true);
   }
   else
   {
      return (false);
   }
}

function Compare(val, val2)
{
   if (val.Trim() == val2.Trim())
   {
      return (true);
   }
   else
   {
      return (false);
   }
}
// 无提示关闭窗口
function Close()
{
   var ua = navigator.userAgent;
   var ie = navigator.appName == "Microsoft Internet Explorer" ? true : false;
   if (ie)
   {
      var IEversion = parseFloat(ua.substring(ua.indexOf("MSIE") + 5, ua.indexOf(";", ua.indexOf("MSIE")))) ;
      if(IEversion < 5.5)
      {
         var str  = '<object id = noTipClose classid = "clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11">' ;
         str += '<param name="Command" value="Close"></object>';
         document.body.insertAdjacentHTML("beforeEnd", str);
         document.all.noTipClose.Click();
      }
      else
      {
         window.self = null;
         window.opener = null;         
         window.close();
      }
   }
   else
   {
      window.close();
   }
}
// demo : Trim(string);
// Cookie.prototype.load

