//comm.js 公共js函数 linniao.com 蒋开建2009-3-10
function $(id){
	return document.getElementById(id);
}
function l$(id){
	return document.getElementsByName(id);
}
function v$(id){
	return document.getElementById(id).value;
}
function e$(id){
	return encodeURIComponent(document.getElementById(id).value);
}
function i$(id,str){
	document.getElementById(id).innerHTML = str;
}
function HiddenDiv(Div){//隐藏DIV
	if ($(Div)){
		$(Div).style.display="none";		
	}
}
function VisibleDiv(Div){//显示DIV
	if ($(Div)){
		$(Div).style.display="block";
	}
}
function getOffsetTop(elm) {
	var mOffsetTop = elm.offsetTop;
	var mOffsetParent = elm.offsetParent;
	while(mOffsetParent){
		mOffsetTop += mOffsetParent.offsetTop;
		mOffsetParent = mOffsetParent.offsetParent;
	}
	return mOffsetTop;
}
function getOffsetLeft(elm) {
	var mOffsetLeft = elm.offsetLeft;
	var mOffsetParent = elm.offsetParent;
	while(mOffsetParent) {
		mOffsetLeft += mOffsetParent.offsetLeft;
		mOffsetParent = mOffsetParent.offsetParent;
	}
	return mOffsetLeft;
}
function LocateDiv(DivID,BaseObjID,MoveLeft,MoveUp){//相对一个HTML对象定位
    var PaletteLeft,PaletteTop
    var Div = $(DivID)
    var BaseObj = $(BaseObjID)
	if (Div){
		PaletteLeft = getOffsetLeft(BaseObj);
		PaletteTop = (getOffsetTop(BaseObj) + BaseObj.offsetHeight);
		if (PaletteLeft+150 > parseInt(document.body.clientWidth)) PaletteLeft = parseInt(event.clientX)-260+(PaletteLeft+MoveLeft);
		if (PaletteTop > parseInt(document.body.clientHeight)) PaletteTop = parseInt(document.body.clientHeight)-165+(PaletteTop +MoveUp);
		Div.style.left = (PaletteLeft+MoveLeft) + "px";
		Div.style.top = (PaletteTop +MoveUp)+ "px";
	}
	VisibleDiv(DivID);
}
//js ajax开始
function getXMLRequester(){
	var xmlhttp_request = false;
	try{
		if( window.ActiveXObject ){
			for( var i = 5; i; i-- ){
				try{
					if( i == 2 ){
						xmlhttp_request = new ActiveXObject( "Microsoft.XMLHTTP" );
					}
					else{
						xmlhttp_request = new ActiveXObject( "Msxml2.XMLHTTP." + i + ".0" ); 
					}
					break;
				}
				catch(e){
					xmlhttp_request = false;
				}
			}
		}
		else if( window.XMLHttpRequest ){
			xmlhttp_request = new XMLHttpRequest();
			if (xmlhttp_request.overrideMimeType){
				xmlhttp_request.overrideMimeType('text/xml');
			}
		}
	}
	catch(e){
		xmlhttp_request = false;
	}
	return xmlhttp_request ;
}
function eventdeal(Method,Url,SendStr){//定义收到服务器的响应后需要执行的JavaScript函数 ;
	xmlhttp_request=getXMLRequester();//调用创建XMLHttpRequest的函数
	xmlhttp_request.onreadystatechange = doContents;//调用doContents函数
	xmlhttp_request.open(Method,Url,true);
	xmlhttp_request.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=uft-8");
	xmlhttp_request.send(SendStr);	
}
function doContents(){
	if (xmlhttp_request.readyState == 4){
		if (xmlhttp_request.status == 200){// 收到完整的服务器响应
			var result = xmlhttp_request.responseText;
			eval(result);
			//alert(result);
		}
	}
}
//Js ajax 结束
function CreateDiv(DivID,Width,Height,zindex){//JS创建动态层
	var NewDiv = document.createElement("div");
	NewDiv.id = DivID;
	NewDiv.style.display = "none";
	NewDiv.style.position = "absolute";
	NewDiv.style.width = Width;
	NewDiv.style.height = Height;
	NewDiv.style.border = "1px solid #006699";
	NewDiv.style.backgroundColor = "#FFFFFF";
	NewDiv.style.zIndex = zindex;
	document.body.appendChild(NewDiv);
}
function getRadioValue(name){//获取单选按钮的选定值
	var radios=l$(name);
	var len=radios.length;
	var selectvalue="";
	for(var i=0;i<len;i++){
		if(radios[i].checked==true){
			selectvalue=radios[i].value;
		}
    }
    return selectvalue;
}

function getCheckBoxValue(name){//获取复选按钮的选定值
	var CheckBoxs=l$(name);
	var len=CheckBoxs.length;
	var selectvalue="";
	var comma = ""
	for(var i=0;i<len;i++){
		if(CheckBoxs[i].checked==true){
			selectvalue=selectvalue+comma+CheckBoxs[i].value;
			comma = ', ';
		}
    }
    return selectvalue;
}
//ckeditro实例化
function CreateEditor(_name,_toolbar,_width,_height){
	CKEDITOR.replace(_name,{
					toolbar : _toolbar,
					width : _width,
					height :_height
	});
}
//DIV伸缩
function FixDivHeight(_div,_height){
	if ($(_div).offsetHeight>_height){
		$(_div+'height').value = $(_div).offsetHeight;
		$(_div).style.height=_height+'px';
		VisibleDiv('switch'+_div);
	}
}
//DIV伸缩高度切换 
function SwitchDivHeight(_type,_div,_height,_str){
	if (_type == 1){
		$(_div).style.height = v$(_div+'height')+'px';
		i$('switch'+_div,'<a href="javascript:;" onclick="SwitchDivHeight(0,\''+_div+'\','+_height+',\''+_str+'\');">收起'+_str+'</a>');
	} else {
		$(_div).style.height = _height+"px";
		i$('switch'+_div,'<a href="javascript:;" onclick="SwitchDivHeight(1,\''+_div+'\','+_height+',\''+_str+'\');">查看全部'+_str+'</a>');
	}
}
function ChangeVerifyQuestion(){
	eventdeal('GET','/do.php?'+ Math.random()+'&ac=ChangeVerifyQuestion',null);
}
function alertlogin(BasicOjb,Msg){
	if(!$('alertlogindiv')){
		CreateDiv('alertlogindiv','250px','','2');
	}
	LocateDiv("alertlogindiv",BasicOjb,0,0);
	i$("alertlogindiv",'<div style="padding:2px;">'+Msg+' 请先<a href="/login.php">登陆</a>或<a href="/register.php">注册</a> <a href="javascript:;" onclick="HiddenDiv(\'alertlogindiv\')">取消</a></div>');
}
var MsgBox="<div id=\"MsgBox\" style=\"display:none;\">";
MsgBox=MsgBox+"<ul id=\"MsgBoxTitle\">提示 - 林鸟网 -linniao.com</ul>";
MsgBox=MsgBox+"<ul id=\"MsgContent\"></ul>";
MsgBox=MsgBox+"<ul id=\"MsgBoxOpr\"></ul>";
MsgBox=MsgBox+"</div>";
document.write(MsgBox);