﻿function copyToClipboard(txt) {   

      if(window.clipboardData) { 
   
              window.clipboardData.setData("Text", txt);
              alert("复制成功！");   
       
      } else if (window.netscape) {   
           try {   
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");   
           } catch (e) {   
                alert("对不起火狐不支持此功能！");   
           }   
           var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);   
           if (!clip)   
                return;   
           var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);   
           if (!trans)   
                return;   
           trans.addDataFlavor('text/unicode');   
           var str = new Object();   
           var len = new Object();   
           var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);   
           var copytext = txt;   
           str.data = copytext;   
           trans.setTransferData("text/unicode",str,copytext.length*2);   
           var clipid = Components.interfaces.nsIClipboard;   
           if (!clip)   
                return false;   
           clip.setData(trans,null,clipid.kGlobalClipboard);   
              alert("复制成功！");   
      }   
}  
//String
String.prototype.ltrim = function(){//清除左空格
    return this.replace(/^\s*/g,""); 
}

String.prototype.rtrim = function(){//清除右空格 
    return this.replace(/\s*$/g,""); 
}

String.prototype.trim = function(){//清除空格 
    return this.ltrim().rtrim();
}

String.prototype.remove = function(str) {//移除字符串
    return this.replace(str, "");
}

String.prototype.IsEmail=function(){//Email格式
    return this.match(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) == null ? false:true;
}

String.prototype.IsMobile=function(){//手机格式
    return this.match(/^((134)|(135)|(136)|(137)|(138)|(139)|(150)|(151)|(152)|(153)|(154)|(155)|(156)|(157)|(158)|(159)|(130)|(131)|(132)|(133)|(187)|(188)|(189))\d{8}$/) == null ? false:true;
}

String.prototype.IsQQ=function(){//QQ格式  
    return this.match(/^[1-9]\d{3,12}$/) == null ? false:true;
}
String.prototype.IsCardNo=function(){//一卡通卡号格式  
    return this.match(/^[0-9]\d{11,18}$/) == null ? false:true;
}

String.prototype.IsPostCode=function(){//邮编格式
    return this.match(/^[1-9]\d{5}$/) == null ? false:true;
}

String.prototype.IsTelePhone=function(){//电话格式  
    return this.match(/^\d{3}-\d{8}|\d{4}-\d{7}$/) == null ? false:true;
}

String.prototype.IsChinese=function(){//中文格式
    return this.match(/^[\u4e00-\u9fa5]{1,}$/) == null ? false:true;
}

String.prototype.IsInteger=function(){//正整数
    return this.match(/^[1-9]\d*$/) == null ? false:true;;
}

String.prototype.GetLength=function(){//获取字符串长度，中文算两个
    var len=0;
    for(var i=0;i<this.length;i++)
    {
        len +=this.substr(i,1).IsChinese() ? 2:1;
    }
    return len;    
}

Array.prototype.contains = function ( item )
{
  for ( var i = 0; i < this.length; i++ )
  {
    
    if ( this[i] == item )
      return true;
  }
  
  return false;
}

Array.prototype.indexOf = function ( item )
{
  for ( var i = 0; i < this.length; i++ )
  {
    if ( this[i] == item )
      return i;
  }
  
  return -1;
}

Array.prototype.removeIndex = function ( index )
{
    this.splice(index,1);
}

Array.prototype.copy = function()
{
  var array = new Array( this.length );
  
  for ( var i = 0; i < this.length; i++ )
  {
    array[i] = this[i];
  }
  return array;
}

Array.prototype.copyTo = function(array)
{
  
  for ( var i = 0; i < this.length; i++ )
  {
        array.push(this[i]);
  }
}

Array.prototype.merge= function(array)
{
    for ( var i = 0; i < this.length; i++ )
  {
        if(!array.contains(this[i]))
            array.push(this[i]);
  }
}

Array.prototype.remove = function(item)
{
    var index=this.indexOf(item);
    if(index>=0)
     this.splice(index,1);
}

Array.prototype.swap = function(i, j) 
{ 
    var temp = this[i]; 
    this[i] = this[j]; 
    this[j] = temp; 
} 


Array.prototype.sortBig = function() 
{ 
    for (var i = this.length - 1; i > 0; --i) 
    { 
        for (var j = 0; j < i; ++j) 
        { 
            if (this[j] < this[j + 1]) this.swap(j, j + 1); 
        } 
    } 
}

Array.prototype.equals=function(array)
{
    if(typeof(array)!=typeof(new Array()))
        return false;
        
    if(this.length!=array.length)
        return false;
    
   var allsame=true; 
   for(var i=0;i<this.length;i++)
   {
        if(this[i]!==array[i])
        {
            allsame=false;
            break;
        }
   }  
   
   return allsame;
}

//找出元素不在另一个数组中原始集合
Array.prototype.notIn=function(arr){
    if(typeof(arr)!=typeof(new Array()))
        return this;
    var newArr=new Array();
    var flag;
    for(var i=0;i<this.length;i++)
    {
        flag=false;
        for(var j=0;j<arr.length;j++)
        {
            if(this[i]==arr[j])
            {
                flag=true;
                break;
            }
        }
        if(!flag)
            newArr.push(this[i]);
    }
    return newArr;
}

var GetEventObj=function(func) //获取触发事件的事件源
{
     if(document.all != undefined)
     {  
         return event.srcElement;   
     }
     else
     {    
         func=GetEventObj.caller;            
         while(func!=null)
         {    
             var arg0=func.arguments[0];
             if(arg0)
             {
                 if((arg0.constructor==Event || arg0.constructor ==MouseEvent) || (typeof(arg0)=="object" && arg0.preventDefault && arg0.stopPropagation))
                    {    
                        return arg0.target;
                    }
             }
             func=func.caller;
         }
         return null;
      }     
}

