var getDom = function(str){
	if(str)
		return document.getElementById(str);
}

var $a = function(obj,str){
	if(str)
		return obj.getAttribute(str);
}

var Util = function(){
	return{
		alert: function(alertStr){
			alert(alertStr);
		},

		confirm: function(confirmStr){
			return confirm(confirmStr);
		},

		mouseOver: function(obj, className, elid, btnelid){
			obj.className=className;
			if(elid){
				Ext.get(elid).setDisplayed(true);
			}
			if (btnelid) {
				Ext.get(btnelid).setDisplayed(true);
			}
		},

		mouseOut: function(obj, className, elid, btnelid){
			if(!Ext.EventObject.within(obj, true)){
				obj.className=className;
				if(elid){
					Ext.get(elid).setDisplayed(false);
				}
				if (btnelid) {
					Ext.get(btnelid).setDisplayed(false);
				}
			}
		},

		toolbarMouseOver: function(obj, className){
			obj.className=className;
		},

		toolbarMouseOut: function(obj, className){
			//if(!Ext.EventObject.within(obj, true)){
				obj.className=className;
			//}
		},

		//设置空间进度条
		setProcess:function(curspace,totalspace){
			if(totalspace == 0){
				curWidth = 0;
			}else{
				var curWidth =  ConstCommon.proceeWidth * (curspace/totalspace);
			}
			if(curWidth<1){
				curWidth = 1;
			}

			if(curWidth > 80){
				curWidth = 80;
			}

			var processdiv = $("process");

			processdiv.style.width = curWidth + "px";

		},

		//监听回车
		addKeyMap : function(el, myHandler, myObject){
            this.keyMap = new Ext.KeyMap(el, {
				key: Ext.EventObject.ENTER,
			    fn: myHandler,
			    scope: myObject
			});
	    },

		//取消监听回车
		removeKeyMap: function(el, myHandler, myObject){
			if(this.keyMap)
				this.keyMap.disable();
		},

		isIE: function(){
			return window.ActiveXObject ? true : false;
		},

		//写地址栏描点，记页数
		setAnchor: function(pos){
			//错误：会引起屏幕上移，暂注释
			//document.location.hash=pos;
		},

		getAnchor: function(){
			return document.location.hash.replace("#","");
		},

		loadscript: function(src) {
	        var headerDom = document.getElementsByTagName('head').item(0);
	        var jsDom = document.createElement('script');
	        jsDom.type = 'text/javascript';
	        jsDom.scr = src;
	        headerDom.appendChild(jsDom);
	    },

		removeEl: function(id){
			if(id){
				var el = Ext.query("#"+id);
				Ext.get(el).remove();
			}
		},

		isFirefox: function(){
			return (navigator.userAgent.indexOf("Firefox")>0)
		},

		getCharAt: function(_char, _at){
			return _char.charAt(_at)==1 ? true : false;
		},

		validEmail: function(email){
			var emailtest=/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
			return emailtest.test(email);
		},

		//复制到剪贴版
		setClipboard: function(data, value){
			if(!this.isIE()){
				Util.alert("请选中以下链接，使用鼠标右键的快捷菜单或者键盘快捷键（Ctrl+C）复制以下外链地址\n\r"+value);
			}else{
				window.clipboardData.setData("Text", value);
				Util.alert('复制成功。现在您可以粘贴（Ctrl+V）外链到Blog 或BBS中了。');
			}
			/*if (window.clipboardData) {
           		window.clipboardData.setData(data,value);
	        } else {
	            var flashcopier = 'flashcopier';
	            if(!document.getElementById(flashcopier)) {
	                var divholder = document.createElement('div');
	                divholder.id = flashcopier;
	                document.body.appendChild(divholder);
	            }
	            document.getElementById(flashcopier).innerHTML = '';
	            var divinfo = '<embed src="/js/_clipboard.swf" FlashVars="clipboard='+escape(value)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';//这里是关键
	            document.getElementById(flashcopier).innerHTML = divinfo;
	            Util.alert('复制成功');
	        }*/
		},

		//替换回车和空格
		replaceTxt: function(value){
			value = value.replace(/\n/g, "<br/>");
			value = value.replace(/ /g, "&nbsp;");
			return value;
		},

		ellipse: function(value, len){
			if(value && value.length > len){
                return value.substr(0, len-3)+"...";
            }
            return value;
		},

		contentLoad: function(callbackFun){
			var ua = navigator.userAgent.toLowerCase();
			isIE = ua.indexOf("msie") > -1 || ua.indexOf("msie 7") > -1
			if(isIE){
				document.write('<script id=____dom_content_ready__ src=javascript:void(0) defer><\/script>');
				$('____dom_content_ready__').onreadystatechange = function() {
					if (this.readyState == 'complete') {
						this.onreadystatechange = null;
							callbackFun();
					 }
				 };
			}else{
				document.addEventListener("DOMContentLoaded", callbackFun, false);
			}
		},
		
		checkValueValid:function(value){
			var valid = false;
	//		if(value.length>15){
	//			valid = true;
	//		}else{
				var str = /[\?\\\*\|\"\<\>:\/]+/;
				var chck = str.test(value);
				
				if(chck){
					valid = true;
				}
	//		}
			return valid;
		},
		
		log: function(logtext){
			//log.debug(logtext);
			//console.log(logtext);
		}

	}
}();

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();
}


var Cookies = function(){

	return{
		set: function(name, value){
			var argv = arguments;
			var argc = arguments.length;
			var expires = new Date();
			expires.setMonth(expires.getMonth()+12);

			var path = (argc > 2) ? argv[2] : '/';
			var domain = (argc > 3) ? argv[3] : null;
			var secure = (argc > 4) ? argv[4] : false;
			document.cookie = name + "=" + escape (value) + "; expires=" + expires.toGMTString() +
			((path == null) ? "" : ("; path=" + path)) +
			((domain == null) ? "" : ("; domain=" + domain)) +
			((secure == true) ? "; secure" : "");
		},

		get: function(name){
			var arg = name + "=";
			var alen = arg.length;
			var clen = document.cookie.length;
			var i = 0;
			var j = 0;
			while(i < clen){
				j = i + alen;
				if (document.cookie.substring(i, j) == arg)
					return this.getCookieVal(j);
				i = document.cookie.indexOf(" ", i) + 1;
				if(i == 0)
					break;
			}
			return null;
		},

		clear: function(name) {
		  if(Cookies.get(name)){
		  	//alert("haveName");
		  	var expires = new Date();
			expires.setMonth(expires.getMonth()-12);
			var path = '/';
			var domain = null;
			var secure = false;
		    document.cookie = name + "=" +
		    "; expires=" + expires.toGMTString() +
			((path == null) ? "" : ("; path=" + path)) +
			((domain == null) ? "" : ("; domain=" + domain)) +
			((secure == true) ? "; secure" : "");
		  }
		},

		getCookieVal: function(offset){
		   var endstr = document.cookie.indexOf(";", offset);
		   if(endstr == -1){
		       endstr = document.cookie.length;
		   }
		   return unescape(document.cookie.substring(offset, endstr));
		}
	}
}();


//检测是否安装 falsh插件
var CheckFlash = {
	i_flash: false,
	v_flash: false,
	checkI: function(){
		if (navigator.plugins) {
			for (var i=0; i < navigator.plugins.length; i++) {
				if (navigator.plugins[i].name.toLowerCase().indexOf("shockwave flash") >= 0) {
					i_flash = true;
					//v_flash = navigator.plugins[i].description.substring(navigator.plugins[i].description.toLowerCase().lastIndexOf("flash ") + 6, navigator.plugins[i].description.length);
				}
			}
		}else{
			var f = CreateObject("ShockwaveFlash.ShockwaveFlash");
			if (IsObject(f)){
				i_flash = true;
			}
		}
		return i_flash;
	}
};

var Regular = {
	mobileReg: function(value){
		var reg=/^1[0-9]{10}$/;
		return reg.test(value);
	},
	
	//只能是数字或英文
	validWordNum: function(value){
		var vtest=/^[a-zA-Z0-9_]+$/;
		return vtest.test(value);
	}
}
