/***********************************************************
* (C) 2008-2010 jentian.com                                *
* This is Not a freeware.                                  *
* version     : 2.1.0.                                     *
* author      : jentian.com (zshejxing@163.com).           *
* date        : 2010/8/20                                 * 
***********************************************************/
window.undefined = window.undefined;
var Jt = {
	version : 1.0
};
Jt.apply = function(o, c, defaults){
    // no "this" reference for friendly out of scope calls
    if(defaults){
        Jt.apply(o, defaults);
    }
    if(o && c && typeof c == 'object'){
        for(var p in c){
            o[p] = c[p];
        }
    }
    return o;
};
(function(){
    var idSeed = 0,Doc = document,Dde = Doc.documentElement,
        toString = Object.prototype.toString,
        isStrict = document.compatMode == "CSS1Compat",
		ua = navigator.userAgent.toLowerCase(),
		Explorer = function(){
			var s = null,e = {};
			(s = ua.match(/msie ([\d.]+)/))?e.ie = s[1] : (s = ua.match(/firefox\/([\d.]+)/)) ? e.firefox = s[1] : (s = ua.match(/chrome\/([\d.]+)/)) ? e.chrome = s[1] : (s = ua.match(/opera.([\d.]+)/)) ? e.opera = s[1] : (s = ua.match(/version\/([\d.]+).*safari/)) ? e.safari = s[1] : 0;
			e.type = e.ie?'ie':e.firefox?'firefox':e.chrome?'chrome':e.opera?'opera':e.safari?'safari':'unknow';
			e.ver = e.ie?e.ie:e.firefox?e.firefox:e.chrome?e.chrome:e.opera?e.opera:e.safari?e.safari:'unknow';
			return e;
		}(),
		Client = function(){
			var s = null,c = {};
			(s = ua.match(/(windows nt|win32) ([\d.]+)/))?c.windows = s[2] : (s = ua.match(/linux ([\d.]+)/ ))?c.linux = s[1] : (s = ua.match(/(macintosh|mac os x) ([\d.]+)/ ))?c.mac = s[2] : (s = ua.match(/adobeair ([\d.]+)/ ))?c.adobeair = s[1] : 0;
			c.type = c.windows?'windows':c.linux?'linux':c.mac?'mac':c.adobeair?'adobeair':'unknow';
			c.ver = c.windows?c.windows:c.linux?c.linux:c.mac?c.mac:c.adobeair?c.adobeair:'unknow';
			return c;
		}(),
        isSecure = /^https/i.test(window.location.protocol);
		if(Client.ie && Client.ver == 6){
			try{
				DOC.execCommand("BackgroundImageCache", false, true);
			}catch(e){}
		}
		var Cookie = {
			set : function(name,value,hour){
				var exp  = new Date();
				exp.setTime(exp.getTime() + hour*60*60*1000);
				Doc.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
			},
			get : function(name){
				var arr = Doc.cookie.match(new RegExp(name+"=([^;]*)"));
				if(arr != null)return unescape(arr[1]);
				return '';
			},
			del : function(name){
				var exp = new Date();
				exp.setTime(exp.getTime() - 1);
				var cval = this.get(name);
				if(cval!=null)Doc.cookie = name + "="+cval+";expires="+exp.toGMTString();
			}
		}
    Jt.apply(Jt, {
		explorer : Explorer,
		client : Client,
		cookie : Cookie,
        SSL_SECURE_URL : isSecure && isIE ? 'javascript:""' : 'about:blank',
        isStrict : isStrict,
        isSecure : isSecure,
        isReady : false,
        enableGarbageCollector : true,
        enableListenerCollection : false,
        enableNestedListenerRemoval : false,
        USE_NATIVE_JSON : false,
        applyIf : function(o, c){
            if(o){
                for(var p in c){
                    if(!Jt.isDefined(o[p])){
                        o[p] = c[p];
                    }
                }
            }
            return o;
        },
		doc : Doc,
		dde : Dde,
		$ : function(basis,doc,t){
			doc = doc || Doc;
			var o = null,docs = [];
			(function getFooter(dp){
				if(dp.length){
					for(var i = 0, l = dp.length;i < l;i++){
						dp[i].length?getFooter(dp[i]) : docs.push(dp[i]);
					}
				}
			})(doc);
			if(docs.length){
				o = [];
				for(var i = 0, l = docs.length;i < l;i++){
					o.push(Jt.$(basis,docs[i],t));
				}
			}else{
				switch(t){
					case 1 :
						o = doc.getElementsByTagName(basis);
					break;
					case 2 :
						o = doc.getElementsByName(basis);
					break;
					default :
						o = doc.getElementById(basis);
					break;
				}
			}
			return o;
		},
		disabled : function(o){},
		$$ : function(tagName){
			return Doc.getElementsByTagName(tagName);
		},
		create : function(tagName){
			return Doc.createElement(tagName);
		},
		getScroll : function(){
			return new Array(Dde.scrollTop,Dde.scrollLeft);
		},
		getClickXY : function(evnt){
			var top = 0, left = 0;
			if(Jt.arrMyAlertSave && Jt.arrMyAlertSave.length >= 1){
				var eleRoot = Jt.noInTheContent(evnt.target?evnt.target : evnt.srcElement, Doc);
				if(eleRoot){
					var parentInfoBox = Jt.arrMyAlertSave[Global.arrMyAlertSave.length-1];
					var arrIframe = parentInfoBox.msgBoxContent.getElementsByTagName('IFRAME');
					for(var i = 0;i<arrIframe.length;i++){
						if(eleRoot == arrIframe[i].contentWindow.document){
							var posIframe = Jt.getObjPosition(arrIframe[i]);
							top = posIframe.top;left = posIframe.left;
							break;
						}
					}
				}
			}
			var arrScroll = Jt.getScroll();
			top += evnt.clientY + arrScroll[0] - 2;
			left += evnt.clientX + arrScroll[1] - 2;
			return new Array(top,left);
		},
		noInTheContent : function(ele,content){
			while(ele != content && ele.parentNode)ele = ele.parentNode;
			return ele == content?false : ele;
		},
        getBody : function(){
            return (Doc.body || Doc.documentElement);
        },
        isEmpty : function(v, allowBlank){
            return v === null || v === undefined || ((Jt.isArray(v) && !v.length)) || (!allowBlank ? v === '' : false);
        },
        isArray : function(v){
            return toString.apply(v) === '[object Array]';
        },
        isDate : function(v){
            return toString.apply(v) === '[object Date]';
        },
        isObject : function(v){
            return !!v && Object.prototype.toString.apply(v) === '[object Object]';
        },
        isPrimitive : function(v){
            return Jt.isString(v) || Jt.isNumber(v) || Jt.isBoolean(v);
        },
        isFunction : function(v){
            return toString.apply(v) === '[object Function]';
        },
        isNumber : function(v){
            return typeof v === 'number' && isFinite(v);
        },
        isString : function(v){
            return typeof v === 'string';
        },
        isBoolean : function(v){
            return typeof v === 'boolean';
        },
        isElement : function(v) {
            return v ? !!v.tagName : false;
        },
        isDefined : function(v){
            return typeof v !== 'undefined';
        },
		code : function(str){
			return new Function('return ('+str+')')();
		}
    });
})();
Jt.apply(Jt,{
	url : {
		parse : function(name,url){
			url = url?url : location.href;
			var arrSpHref = url.split("?");
			var arrResult = new Array();
			if(arrSpHref[1]){
				var re = new RegExp(name+"=([^&^#]*)", "g");
				var arr = new Array();
				if(arr = re.exec(arrSpHref[1]))return decodeURI(arr[1]);
			}
			return "";
		},
		getQueryString : function(url){
			if(!Jt.isDefined(url))url = location.href;
			var arrSplit = url.split("?");
			return arrSplit.length >= 2?arrSplit[1]:'';
		},
		set : function(url,msg){
			if(!url)return false;
			if(!msg || confirm(msg))window.location.href = url;
		},
		reBack : function(){
			window.location.href = parent.Global.parentPageUrl;
		},
		getJsParameter : function(jsFileName){
			var scripts = Jt.$$("script");
			for(var i=0;i<scripts.length;i++){
				var theSrc = scripts[i].src.toString();
				if(theSrc.toString().indexOf(jsFileName)!= -1){
					var arrParam = new Array();
					var arrSpHref = theSrc.split('?');
					arrParam['path'] = arrSpHref[0].replace(jsFileName,'');
					if(arrSpHref[1]){
						var re = new RegExp("([^&^#]*)=([^&^#]*)", "g");
						var arr = new Array();
						while(arr = re.exec(arrSpHref[1]))arrParam[arr[1]] = arr[2];
					}
					return arrParam;
				}
			}
			return '';
		},
		addFavorite : function(url,title){
			if(!url)url = location.href;
			if(!title)title = Jt.doc.title;
			if(Jt.explorer.ie){
				window.external.AddFavorite(url,title);
			}else if(window.sidebar){
				window.sidebar.addPanel(title,url,'');
			}
		},
		setHome : function(url,o){
			try{
				o.style.behavior='url(#default#homepage)';o.setHomePage(url);
       		}catch(e){
                if(window.netscape){
					try{
						netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
					}catch(e){
                        alert("请手动设置^_^");
                    }
                   	var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
                   	prefs.setCharPref('browser.startup.homepage',url);
                 }
        	}
		}
	},
	on : function(o,et,ob,ua,scope){
		var newOb = function(){ob.apply(scope?scope:o,arguments);};
		if(o.addEventListener){
			o.addEventListener(et,newOb,ua || false);
		}else if(o.attachEvent){
			o.attachEvent('on'+et,newOb);
		}
		return newOb;
	},
	un : function(o,et,ob,ua){
		if(o.removeEventListener){
			o.removeEventListener(et,ob,ua || false);
		}else if(o.detachEvent){
			o.detachEvent('on'+et,ob);
		}
	},
	onLoad : function(fn,scope){
		Jt.on(window,'load',fn,false,scope);
	},
	getTarget : function(evnt){
		return evnt.srcElement?evnt.srcElement:evnt.target;
	},
	loader : {
		css : function(file,obj){
			var o = obj?obj:Jt.doc;
			var head = o.getElementsByTagName('HEAD')[0];
			var css = o.createElement('LINK');
			css.rel = 'stylesheet';
			css.type = 'text/css';
			css.href = file;
			head.insertBefore(css,head.childNodes[head.childNodes.length?head.childNodes.length-1:0]);
		},
		js : function(file,obj){//加上回调查函数
			var o = obj?obj:Jt.doc;
			var head = o.getElementsByTagName('HEAD')[0];
			var js = o.createElement('SCRIPT');
			js.src = file;
			js.language = 'javascript';
			js.type = 'text/javascript';
			head.insertBefore(js,head.childNodes[head.childNodes.length?head.childNodes.length-1:0]);
		}	
	},
	screen : {
		height : window.screen.height,
		width : window.screen.width,
		availHeight : window.screen.availHeight,
		availWidth : window.screen.availWidth
	},
	className : {
		remove : function(o,c){
			var reg = new RegExp("[\s]*"+c);
			o.className = o.className.replace(reg,'');
		},
		add : function(o,c){
			Jt.className.remove(o,c);
			o.className += ' '+c;
		}	
	},
	dom : {
		remove : function(o){
			o.parentNode.removeChild(o);
			return o;
		},
		add : function(o,parent){
			parent = parent?parent : Jt.doc.body;
			parent.appendChild(o);
			return o;
		},
		getPosition : function(o,allPage){
			var arrScroll = new Array(0,0);
			if(allPage)arrScroll = Jt.getScroll();
			var arrPosition = o.getBoundingClientRect();
			var arrReturn = new Array();
			arrReturn['top'] = arrPosition.top + arrScroll[0];
			arrReturn['right'] = arrPosition.right + arrScroll[1];
			arrReturn['bottom'] = arrPosition.bottom + arrScroll[0];
			arrReturn['left'] = arrPosition.left + arrScroll[1];
			return arrReturn;
		}
	},
	number : {
		formatFloat : function(v,l){
			l = l?l:2;
			var sv = (v + 1/Math.pow(10,l+1)).toString();
			var p = sv.indexOf('.');
			return sv.substring(0,p+l+1);
		}
	},
	user : Jt.code(Jt.cookie.get("userLogin") || "{}")
});
Jt.apply(Array.prototype,{
	remove : function(el,index){
		if(index){
			var ele = this[el];
			this.splice(el,1);
			return ele;
		}
		for(var i=0;i<this.length;i++){
			if(this[i] == el){
				this.splice(i,1);
				return i;
			}
		}
	},
	isInArray : function(needle, haystack){
		if(typeof(needle) == 'string' || typeof(needle) == 'number'){
			for(var i in haystack){
				if(haystack[i] == needle)return true;
			}
		}
		return false;
	}
});
Jt.apply(String.prototype,{
	trim : function(){
		return this.replace(/(^\s*)|(\s*$)/g, "");
	},
	cnLength : function(){
		return this.length+(this.match(/[^\x00-\xff]/ig)==null?0:arr.length);
	},
	maxLength : function(len,dot){
		if(this.lenght <= len)return this;
		var str = this.substr(0,len);
		if(dot)str += '...';
		return str;
	}
});
Jt.apply(Jt,{
	form : {
		check : {
			english : function(str){
				str = Jt.form.fullTohalf(fullTohalf);
				var strSource =" 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ~`!@#$%^&*()_-+=|\{[}]\"':;?/>.<,\r\n";
				var ch, i, temp;
				for (i=0;i<=(str.length-1);i++){ 
					ch = str.charAt(i); 
					temp = strSource.indexOf(ch); 
					if(temp == -1){ 
						return false; 
					}
				}
				return true;
			},
			email : function(emailaddress){
				var reg = /^.+@(?:[\w-]+\.)*(?:[\w-]{2,}\.)+(?:[a-zA-Z]{2,4}){1}$/;
				return reg.test(emailaddress);
			},
			postCode : function(strPostCode){
				var reg = /^[0-9]{6,6}$/;
				return reg.test(strPostCode);
			},
			phoneNo : function(strPhoneNo){
				var reg = /^[0-9\-]{7,15}$/;
				return reg.test(strPhoneNo);
			},
			mobile : function(strMobileNo){
				var reg = /^1[0-9]{10}$/;
				return reg.test(strMobileNo);
			}
		},
		fullTohalf : function(tempstr){
			var fullstr = "～·！@#￥％……—×（）——－＋＝|、｛〔｝〕“”’：；？、》。《，１２３４５６７８９０";
			var halfstr = "~`!@#$%^^&*()_-+=|\{[}]\"\",:;?/>.<,1234567890"
			for(var i=0;i<=10;i++){
				var re = new RegExp(fullstr.charAt(i),"g");
				tempstr = tempstr.replace(re,halfstr.charAt(i));	
			}
			return tempstr;
		}
	}
});
