var common=window.common=function(args){};

common.fn=common.prototype={
//窗口大小缩放时尺寸更新
updateSize:function(){
	//解决IE6下圆角absolute 1px bug
	var W=document.body.parentNode.clientWidth;
	document.body.style.width=W<760?(760+'px'):(W%4?((W-W%4)+'px'):(W%2?(W-1)+'px':'100%'));
	
	//解决我的消息iframe尺寸更新
	var ifr=document.getElementById('inholder');
	var left=document.getElementById('left');
	var right=document.getElementById('right');
	if(ifr&&left){
		right.style.width = document.getElementById('in').offsetWidth-left.offsetWidth+'px';
	}
},

/*
	事件绑定
	如:window.onload=fn; -> bind(window,'load',fn);
*/
bind:function(o,ev,fn){
	if (document.all){
		o.attachEvent('on'+ev,fn);////////////IE绑定上但是fn里this指向window
	}
	else{
		o.addEventListener(ev,fn,false);
	}
	return o;
},

/*
	给对象添加一个class
	如:addClass(document.getElementById('id'),'classA classB');
	可以以空格分隔添加多个class
*/
addClass:function (el,cls){
	var arrCls=cls.split(/[ ]+/);
	if(el.className){
		for(var i=0;i<arrCls.length;i++){
			if(common.hasClass(el,cls)){
				cls=cls.replace(new RegExp('(^| +)'+arrCls[i]+'( +|$)'),' ');
			}
		}
		el.className=[el.className].concat(cls).join(' ');
	}
	else{
		el.className=cls;
	}
},

/*
	移除对象上的一个class
*/
removeClass:function (el,cls){
	if(common.hasClass(el,cls)){
		el.className=el.className.replace(new RegExp('(^| +)'+cls+'( +|$)','g'),' ');
	}
},

/*
	添加/移除对象上的一个class
	没有就添加，有了就移除
*/
toggleClass:function (el,cls){
	if(!common.hasClass(el,cls)){
		common.addClass(el,cls);//11-2
		return true;
	}
	else{
		common.removeClass(el,cls);//11-2
		return false;
	}
},

/*
	判断某个对象是否含有某个或多个class
*/
hasClass:function(el,cls){
	if(!el.className||!cls)
		return false;
	var cls=cls.split(/[\.| +]/);
	var re;
	for(var i=cls.length-1;i>=0;i--){
		re=new RegExp('(^| +)'+cls[i]+'( +|$)');
		if(!(re.test(el.className)||!cls[i]))
			return false;
	}
	return true;
},

/*
	显示/隐藏一个元素
	@el:Element
	@sh:Boolean true:show; false:hide; undefined:toggle.
*/
show:function(el,sh){
	var style=el.currentStyle||document.defaultView.getComputedStyle(el,null);
	var dis=style.display||'';
	if(sh==undefined){
		el.style.display=(dis!='none'?'none':'');
	}else{
		el.style.display=sh?'':'none';
	}
},

//直接取得元素在文档中的绝对坐标
getAbsPos:function(obj){
	var opos=obj.style.position;
	obj.style.position="absolute";
	var ofloat=obj.style.styleFloat;
	obj.style.styleFloat="none";
	var pos={top:obj.offsetTop,right:obj.offsetLeft+obj.offsetWidth,bottom:obj.offsetTop+obj.offsetHeight,left:obj.offsetLeft};
	obj.style.position=opos;
	obj.style.styleFloat=ofloat;
	return pos;
},

//取得元素相对于父级元素的相对坐标
getRelPos:function(obj){
	if(obj==document.body.parentNode){return {top:0,right:0,bottom:0,left:0};}
	return {top:obj.offsetTop-obj.parentNode.offsetTop,right:obj.offsetLeft-obj.parentNode.offsetLeft+obj.offsetWidth,bottom:obj.offsetTop-obj.parentNode.offsetTop+obj.offsetHeight,left:obj.offsetLeft-obj.parentNode.offsetLeft};
},

//根据相对坐标逐级计算出元素的绝对坐标
getAbsPosByRelPos:function(obj){
	var pos={top:0,right:0,bottom:0,left:0};
	for(var elem=obj;elem!=document.body;elem=elem.parentNode){
		if(this.getRelPos(elem).top>0)pos.top+=this.getRelPos(elem).top;
		if(this.getRelPos(elem).left>0)pos.left+=this.getRelPos(elem).left;
	}
	pos.right=pos.left+obj.offsetWidth;
	pos.bottom=pos.top+obj.offsetHeight;
	return pos;
},

createFlash:function(idad, swfurl, wad, had, vs){
	var str = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="' + wad + '" height="' + had + '" id="' + idad + '" align="middle">';
	str += '<param name="allowScriptAccess" value="always">';
	str += '<param name="quality" value="high">';
	str += '<param name="movie" value="' + swfurl + '">';
	str += '<param name="wmode" value="transparent">';
	str += '<param name="flashvars" value="' + vs + '">';
	str += '<embed wmode="opaque" src="' + swfurl + '" flashvars="' + vs + '" quality="high" width="' + wad + '" height="' + had + '" name="' + idad + '" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">';
	str += '</object>';
	document.write(str);
},

onClose:function(){
	window.opener = null;
	window.close();   
}

}

common.extend=common.fn.extend=function(a,b){
	for(i in b)a[i]=b[i];
	return a;
};

common.extend(common,common.fn);

(function(){
	function init(){
		var tm=document.getElementById('topswitch');
		if(tm)common.bind(tm,'click',showTopMenu);
		
		//alert(document.getElementById('output').value);
	}
	function showTopMenu(){
		//alert(1);
		common.show(document.getElementById('topmenu'));
	}
	if(window==top)common.bind(window,'load',init);
})();


function initFoot(){
	document.write('<div id="ft"><p class="links"><a href="http://union.baidu.com/newui/about.html">关于联盟</a> | <a href="http://union.baidu.com/newui/partner.html">合作伙伴</a> | <a href="http://union.baidu.com/newui/event.html">精彩活动</a> | <a href="http://union.baidu.com/newui/contact.html">联系我们</a></p><p class="copy">&copy;2008 Baidu <a href="http://www.baidu.com/duty/index.html">免责声明</a> <a href="javascript:try{window.external.addFavorite(\'http://www.baidu.com\',\'百度\');}catch(e){}">设百度为首页</a> <a href="http://utility.baidu.com/quality/quality_form.php?word=%B0%D9%B6%C8%C1%AA%C3%CB">与百度对话</a></p></div>');
}

/*
	iframe高度自适应
	@ifr:HtmlIframeElement
	@ids:[String] 一组id字符串
	由iframe dom 里的onload属性调用
*/
function adjustIframe(ifr){
	ifr.height=ifr.contentWindow.document.body.scrollHeight;
}