//替换空格为空,去除空格
String.prototype.trim = function(){return this.replace(/(^[ |　]*)|([ |　]*$)/g, "");}

//取得ID，用法如：$('aa') 就等于 document.getElementById('aa')
function $(s){return document.getElementById(s);}

//取得目标框架ID,用法：$$('aa')
function $$(s){return document.frames?document.frames[s]:$(s).contentWindow;}

//取得formID,用法：$f('aa')
function $f(s){return document.forms?document.forms[s]:$(s).contentWindow;}

//取得表单中的元素name值,用法：$c('aa')
function $c(s){return document.createElement(s);}

//getElementsByTagName是返回指定名称的元素集合。如：var aa = document.getElementsByTagName("input");就是input共有几个 
function $n(name){return document.getElementsByTagName(name || "*");}

//输出目标
function dw(s){document.write(s);}

//隐藏/显示目标
function hide(s){$(s).style.display=$(s).style.display=="none"?"":"none";}

//判断是否为空
function isNull(_sVal){return (_sVal == "" || _sVal == null || _sVal == "undefined");}

//隐藏目标
function removeNode(s){if(exist(s)){$(s).innerHTML = '';$(s).removeNode?$(s).removeNode():$(s).parentNode.removeChild($(s));}}

//在新窗口打开网址
function newopen(_sUrl){window.open(_sUrl, "_blank");}

//在本窗口打开地址
function wopen(_sUrl){location.href=_sUrl;}

//收藏本页
function setAddHome(){try{window.external.AddFavorite(window.document.location,window.document.title)}catch(e){};}

//设为首页
function setHome(homeurl){document.body.style.behavior='url(#default#homepage)';document.body.setHomePage(homeurl); return false;}

//删除目标
//如：onclick=\"oDel('dlgID')\"
window.oDel=function(obj){if($(obj)!=null){$(obj).parentNode.removeChild($(obj))}}

//隐藏/显示列表 
function hideList(_sId,_sStr,_iBegin,_iEnd,_sShow){for(var i = _iBegin; i <= _iEnd; i++)if(exist(_sId + i)){$(_sId + i).style.display = _sStr;_sStr == 'none' ? $(_sShow + i).className = 'down' : $(_sShow + i).className = 'up'}}


//调用dialog窗体，要结合dialog.js一起用。页面中加载此库时，同时加载<SCRIPT language="javascript" src="dialog.js"></SCRIPT>
function openWindow(_sUrl, _sWidth, _sHeight, _sTitle, _sScroll){
	var oEdit = new dialog();
	oEdit.init();
	oEdit.set('title', _sTitle ? _sTitle : "系统提示信息" );
	oEdit.set('width', _sWidth);
	oEdit.set('height', _sHeight);
	oEdit.open(_sUrl, _sScroll ? 'no' : 'yes');
	}
	
//调用flash文件，能去除flash的虚边
//在网页中加载调用如下：
// <SCRIPT language=javascript>
// <!--
// LoadFlash('/menu.swf','transparent','753','141','Wish114_Menu','Wish114_Menu')
// //-->
// </script>
function LoadFlash(s_url,s_wmode,s_width,s_Height,s_name,s_id){
	document.write("<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='"+s_width+"' height='"+s_Height+"' id='"+s_id+"'>");
	document.write("<param name='movie' value='"+s_url+"'>");
	document.write("<param name='quality' value='high'>");
	document.write("<param name=\"menu\" value=\"false\">");
	document.write("<PARAM name=wmode value='"+s_wmode+"'>");	
	document.write("<embed src='"+s_url+"' wmode='"+s_wmode+"' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='"+s_width+"' height='"+s_Height+"' name='"+s_name+"' swLiveConnect='true'></embed>");
	document.write("</object>");
}

//将图片按比例缩放
//使用onload=DrawImage(this,长,宽);
function DrawImage(ImgD,w,h){
	var image=new Image();
	image.src=ImgD.src;
	if(image.width>0 && image.height>0){
		flag=true;
		if(image.width/image.height>= w/h){
			if(image.width>w){
				ImgD.width=w;
				ImgD.height=(image.height*w)/image.width;
			}
			else{
				ImgD.width=image.width;
				ImgD.height=image.height;
			}
			//ImgD.alt=image.width+"×"+image.height;
		}
		else{
			if(image.height>h){
				ImgD.height=h;
				ImgD.width=(image.width*h)/image.height;
			}else{
				ImgD.width=image.width;
				ImgD.height=image.height;
			}
			//ImgD.alt=image.width+"×"+image.height;
		}
	}
}

//CTRL+鼠标滚轮放大或缩小图片
//用法：onmousewheel="return imgzoom(this);"
function imgzoom(o) {
	if(event.ctrlKey) {
		var zoom = parseInt(o.style.zoom, 10) || 100;
		zoom -= event.wheelDelta / 12;
		if(zoom > 0) {
			o.style.zoom = zoom + '%';
		}
		return false;
	} else {
		return true;
	}
}

//取得以“;”分隔的cookie值
//记录cookie时为：document.cookie = 'discuz_collapse=' + escape(collapsed) + '; expires=' + expires.toGMTString() + '; path=/';
function getcookie(name) {
	var cookie_start = document.cookie.indexOf(name);
	var cookie_end = document.cookie.indexOf(";", cookie_start);
	return cookie_start == -1 ? '' : unescape(document.cookie.substring(cookie_start + name.length + 1, (cookie_end > cookie_start ? cookie_end : document.cookie.length)));
}

//复制拷贝目标代码
function copycode(obj) {
	var rng = document.body.createTextRange();
	rng.moveToElementText(obj);
	rng.scrollIntoView();
	rng.select();
	rng.execCommand("Copy");
	rng.collapse(false);
}

//运行代码
function runCode(obj) {
        var winname = window.open('', "_blank", '');
        winname.document.open('text/html', 'replace');
		winname.opener = null // 防止代码对论谈页面修改
        winname.document.write(obj.value);
        winname.document.close();
}

//保存代码
function saveCode(obj) {
        var winname = window.open('', '_blank', 'top=10000');
        winname.document.open('text/html', 'replace');
        winname.document.write(obj.value);
        winname.document.execCommand('saveas','','code.htm');
        winname.close();
}

function pageWidth() {return window.innerWidth != null? window.innerWidth: document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth:document.body != null? document.body.clientWidth:null;}
function pageHeight() {return window.innerHeight != null? window.innerHeight: document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight:document.body != null? document.body.clientHeight:null;}
function posLeft() {return typeof window.pageXOffset != 'undefined' ? window.pageXOffset:document.documentElement && document.documentElement.scrollLeft? document.documentElement.scrollLeft:document.body.scrollLeft? document.body.scrollLeft:0;}
function posTop() {return typeof window.pageYOffset != 'undefined' ? window.pageYOffset:document.documentElement && document.documentElement.scrollTop? document.documentElement.scrollTop: document.body.scrollTop?document.body.scrollTop:0;}
function posRight() {return posLeft()+pageWidth();}
function posBottom() {return posTop()+pageHeight();}


