﻿Object.extend=function(derivative,base){for(var property in base){derivative[property]=base[property];}return derivative;};
Object.prototype.extend=function(baseClass){return Object.extend.apply(this,[this,baseClass]);};
Object.extend(String.prototype,{
    ltrim:function(){return this.replace(/(^\s*)/g,'');},
    trim:function(){return this.replace(/(^\s*)|(\s*$)/g,'');},
    number:function(){return this.replace(/\D/g,'');},
    identifier:function(){return this.replace(/\W/g,'');}
});

var CJ={
        fn: function(){},
        isString: function(obj){return !obj ? false : this.toString.call(obj) === '[object String]';},
        isFunc: function(obj) {return !obj ? false : this.toString.call(obj) === '[object Function]';},
        isObject: function(obj){return !obj ? false : this.toString.call(obj) === '[object Object]';},
        isArray: function(obj){return !obj ? false : this.toString.call(obj) === '[object Array]';},
        isEmpty: function(obj){return (obj===null || obj===undefined || obj.toString().trim() === '') ;},
        isNumber: function(obj){return CJ.isEmpty(obj) ? false : this.toString.call(obj) === '[object Number]';},
        isBoolen: function(obj){return CJ.isEmpty(obj) ? false : this.toString.call(obj) === '[object Boolen]';},
        toInt: function(obj){ var re=parseInt(obj, 10); return isNaN(re) ? -1 : re;},
        toFloat: function(obj){return isNaN(parseFloat(obj)) ? -1 : parseFloat(obj);},
        urlAppend: function(url){if (!url) return;url = url.toString();return url.indexOf('?') === -1 ? url + '?' : url + '&';},
		parseUrl:function(url,param){
			var c,ps;
			if(!CJ.isEmpty(url) && !CJ.isEmpty(param)) {ps=param.split(';');for (var i = 0; i < ps.length; i++) { c = ps[i].split('='); CJ.urlAppend(url) += c[0] + '=' + escape(c[1]);}}
			return url+'&_tcp='+new Date().getTime();
		},
		getParam:function(param){
		    param=param.toLowerCase();
		    var value="",sURL=window.document.URL;
		    if(sURL.indexOf("?")>0){
		       var arrayParams=sURL.split("?"),arrayURLParams=arrayParams[1].split("&"),sParam;
		       for(var i=0;i<arrayURLParams.length;i++){
		           sParam=arrayURLParams[i].split("=");
		           if((sParam[0].toLowerCase()==param)&&(sParam[1]!="")){value=sParam[1];break;}
		       }
		    }
		    return value;
		}		
};

Object.extend(Array.prototype,{
    add:function(obj,index){
       if(obj==null)return this;
       if(typeof index!='number'||index>this.length)index=this.length;
       else if(index<0 )index=0;
       var a1=this.slice(0,index); a1.push(obj);
       for(var i=index;i<this.length;i++)a1.push(this[i]);
       return a1;
    },
    each:function(callback){
       for(var i=0;i<this.length;i++){
           callback.call(this[i],i);
       }
    }
});
 
function each(collection,callback){
    for(var i=0;i<collection.length;i++){        
        callback.call(collection[i],i);           
    }
}
function $(id){id=id.trim();if(CJ.isEmpty(id))return null;return document.getElementById(id);}
function $Val(id){var dom = $(id); return dom==null?'':dom.value.trim();}
/*
   判断浏览器各类和版本
*/
var Browser=(function(){
     var info=navigator.userAgent.toLowerCase(),notExist=-1;  
     return {
        Info:info,
        IE:info.indexOf('msie') !== -1,
        Firefox:info.indexOf('firefox') !== -1,
        Opera:info.indexOf('opera') !== -1, 
        Safari:info.indexOf('safari') !== -1,
        IEVersion:info.indexOf('msie')!==-1?info.substr(info.indexOf('msie')+5,1):notExist,        
        FirefoxVersion:info.indexOf('firefox') !== -1?info.substr(info.indexOf('firefox')+8,3):notExist,         
        OperaVersion:info.indexOf('opera') !== -1?info.substr(info.indexOf('opera')+6,3):notExist,        
        SafariVersion:info.indexOf('safari') !== -1?info.substr(info.indexOf('safari')+7,5):notExist
    };
})();

function getStyle(el){
    if(typeof el=='string'){el=$(el);}
    return el.currentStyle || window.getComputedStyle(el,arguments.length>1?arguments[1]:null);
}
function setStyle(el,_style){
    if(el==null||!_style||typeof _style!='object')return;
    if(typeof el=='string'){el=$(el);}
    if(el==null)return;
    if(!el.style)return;
    for(var property in _style){el.style[property]=_style[property];}
}
var Ajax={
    ajax:function(){
         var XMLHttp=null;
         if(window.ActiveXObject){
             try{XMLHttp=new ActiveXObject('Microsoft.XMLHTTP');}
             catch(e){
                 try {XMLHttp=new ActiveXObject('Msxml2.XMLHTTP');}
                 catch(e){}
             }
             finally{return XMLHttp;}
         }
         else{
             if(window.XMLHttpRequest){
                 try{XMLHttp=new XMLHttpRequest();}
                 catch(e){}
                 finally{return XMLHttp;}
                 }
             }
         },
         get:function(url,success,async,error){
             if(async==undefined || async==null)async=true;
             var XmlHttp=this.ajax();
             if(XmlHttp!=null){
                 XmlHttp.open('GET',url,async);
                 XmlHttp.onreadystatechange=finish;
                 XmlHttp.send(null);
             }
             function finish(){
                 if(XmlHttp.readyState==4){
                     if(XmlHttp.status==200){success(XmlHttp.responseText);}
                     else {error(XmlHttp.responseText);}
                 }
             }
         },
         post:function(url,success,async,error){this.get(url,success,error);}
};
function ToInt(val){return parseInt(val,10);}
/*禁用輸入法*/
function NoInput(id){
   if(CJ.isString(id)){$(id).style.imeMode='disabled';} 
   else if(CJ.isArray(id)){
       id.each(function(){
               $(this).style.imeMode='disabled';
          });
   }
}

function DisableMenu(){document.oncontextmenu=function(){return false;};}

