function $(id){
	return document.getElementById(id);
}

function display_div(id){
	if($(id).style.display=='block'){
		$(id).style.display='none';
	}else{
		$(id).style.display='block';
	}
}

var DragObj;
var x, y;

/* 鼠标拖动div  */
function ye(obj,id){
	//alert(id);
	x = event.clientX - $(id).offsetLeft;
	y = event.clientY - $(id).offsetTop;
	DragObj = obj;
	document.onmousemove = function(){
		$(id).style.left = event.clientX - x;
		$(id).style.top = event.clientY - y;
	}
	document.onmouseup = function(){
		document.onmousemove = null;
		DragObj.style.cursor="default";
	}
	DragObj.style.cursor = "move";
}


//鼠标变成移动样式
function cursor_move(DragObj){
	DragObj.style.cursor = "move";
}
//鼠标指针变成小手
function cursor_pointer(DragObj){
	DragObj.style.cursor = "pointer";
}

function mouseCoords(ev)
{
	if(ev.pageX || ev.pageY){
		return {x:ev.pageX, y:ev.pageY};
	}
	return {
		x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
		y:ev.clientY + document.body.scrollTop  - document.body.clientTop
	}
}

//得到鼠标绝对位置
function div_position(divID,client_y,client_x){

	var ev;
	ev= ev || window.event;
	var mousePos = mouseCoords(ev);
	$(divID).style.top=mousePos.y+parseInt(client_y,'10');
	$(divID).style.left=mousePos.x-parseInt(client_x,'10');
}


/**关闭浏览器**/
function CloseWin()
{
	var ua=navigator.userAgent
	var ie=navigator.appName=="Microsoft Internet Explorer"?true:false
	if(ie){
		var IEversion=parseFloat(ua.substring(ua.indexOf("MSIE ")+5,ua.indexOf(";",ua.indexOf("MSIE "))))
		if(IEversion< 5.5){
			var str  = '<object id=noTipClose classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11">'
			str += '<param name="Command" value="Close"></object>';
			document.body.insertAdjacentHTML("beforeEnd", str);
			document.all.noTipClose.Click();
		}
		else{
			window.opener =null;
			window.close();
		}
	}
	else{
		window.close()
	}
}

/**打开一个浏览器，屏蔽工具栏**/
function popUp(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=720,height=600,left = 200,top = 100');");
}



function addfavorite()
{
	switch(getOs())
	{
		case 1:window.external.addFavorite('http://www.zhihuiban.com/','智慧班');break;
		case 2:window.sidebar.addPanel('智慧班', 'http://www.zhihuiban.com/', "");break;
	}
}
function getOs()
{
	if(navigator.userAgent.indexOf("MSIE")>0)return 1;
	if(isFirefox=navigator.userAgent.indexOf("Firefox")>0)return 2;
	if(isSafari=navigator.userAgent.indexOf("Safari")>0)return 3;
	if(isCamino=navigator.userAgent.indexOf("Camino")>0)return 4;
	if(isMozilla=navigator.userAgent.indexOf("Gecko/")>0)return 5;

}


//参数为已经经过转义的字符
function URLencode(sStr)
{
	return sStr.replace(/\+/g, '%2B').replace(/\"/g, '%22').replace(/\'/g, '%27').replace(/\//g, '%2F').replace(/\#/g, '%23').replace(/\&/g, '%26');
	//return escape(sStr).replace(/\+/g, '%2B').replace(/\"/g, '%22').replace(/\'/g, '%27').replace(/\//g, '%2F').replace(/\#/g, '%23');
}

//参数为原始字符串，没有经过任何转义
function URLencode2(sStr)
{
	return escape(sStr).replace(/\+/g, '%2B').replace(/\"/g, '%22').replace(/\'/g, '%27').replace(/\//g, '%2F').replace(/\#/g, '%23').replace(/\&/g, '%26');
}

function getServerURL(){
	var pageUrl="";
	pageUrl = window.location;
	pageUrl = pageUrl.toString()
	return site_url=pageUrl.substring(0,pageUrl.indexOf('/index.php')); //javascript获得服务器请求地址
}

function trim(str){ //删除左右两端的空格
	return str.replace(/(^\s*)|(\s*$)/g, "");
}
function ltrim(str){ //删除左边的空格
	return str.replace(/(^\s*)/g,"");
}
function rtrim(str){ //删除右边的空格
	return str.replace(/(\s*$)/g,"");
}

function binObjClick(obj){
	obj.disabled=true;
}

//转义特殊字符
function repspe(str){
	return URLencode(encodeURI(str));
}

//解析服务器的返回值
function de_opt_msg(string_json){
	
	var arr=eval(string_json); //接收的xmlHttp.responseText只是一个字符串，要用eval函数转化成json对象
	if(arr[0]['flag']){
		
	}
	alert(arr[0]['param_type']);
	obj=arr[0]['param'];
	alert(obj);
}



function openWin(url,obj){
	obj.href = url;
}

//获得单选框的值
function getRadioValueByName(name){
	var va;
	var   e=document.getElementsByName(name);
	for(var i=0;i<e.length;i++)
	{
		
		if (e[i].type== "radio"){
			if(document.getElementsByName(name)[i].checked==true){
				va=document.getElementsByName(name)[i].value;
			}
		}
	}
	return va;
}

function getCheckboxValueByName(name){
	var arr = new Array();
	var   e=document.getElementsByName( name);
	for(var  i=0;i <e.length;i++)
	{
		if (e[i].type== "checkbox" || e[i].type== "radio"){
			if(document.getElementsByName( name)[i].checked==true){
				arr.push(document.getElementsByName( name)[i].value); //把选中的复选框的value提取组成一个新数组
			}
		}
	}
	return arr;
}