//全选
function checkbox_selall(form,selall,selname)
{
	for(var i = 0; i < form.elements.length; i++) {
		var e = form.elements[i];
		if(e.name.match(selname)) {
			e.checked = form.elements[selall].checked;
		}
	}
}
//全取消
function checkbox_cancel(form,selname)
{
	for(var i = 0; i < form.elements.length; i++) {
		var e = form.elements[i];
		if(e.name.match(selname)) {
			e.checked = false;
		}
	}
}
//取值
function checkbox_get_val(form,msgid)
{
	var txtval="";
	for(var i = 0; i < form.elements.length; i++) {
		var e = form.elements[i];
		if(e.name.match(msgid)) {
			if(e.checked)
			{
				if(txtval=="")
				{
					txtval=e.value;
				}else{
					txtval+=","+e.value;
				}
			}
		}
	}
	return txtval;
}

//初始化可变文本框高度
function areabox_autoheight(msgid,msgobj)
{
	var obj;
	if(msgid=="")
	{
		obj=msgobj;
	}else{
		obj=document.getElementById(msgid);
	}
	if(obj.type=="textarea")
	{
		if(obj.scrollHeight>0)
		{
			obj.style.posHeight=obj.scrollHeight+2;
		}
	}
}
function areabox_autoheight_m(form,msgname)
{
	for(var i = 0; i < form.elements.length; i++) {
		var e = form.elements[i];
		if(e.name.match(msgname)) {
			areabox_autoheight("",e)
		}
	}

}
function get_json_obj(json_cont){
	if( json_cont.substr(0,1)!="{" || json_cont.substr(json_cont.length-1,1)!="}" ){
		var obj_y={"isnull":"1"};
		return obj_y;
	}
	eval("var obj_x="+json_cont);
	return obj_x;
}
function get_number(msg_val){
	reg=/^\d{1,}$/;
	if( msg_val == '' ||  !reg.test(msg_val) ){
		return 0;
	}else{
		return msg_val;
	}
}
function table_row_insert(id){
	var obj=document.getElementById(id);
	if(!obj){
	  alert("找不到对象");
	  return;
	}
	var strRowIndex=1;//parseInt(obj.rows.length)-1;
	var objRow=obj.insertRow(obj.rows.length);
	var strid="id_"+Math.random();
	objRow.id=strid;
	var i=0,x="";
	var objCell=obj.rows[strRowIndex].cells;
	for(i=0;i<objCell.length;i++)
	{
		x=objRow.insertCell(i);
		strx=objCell[i].innerHTML.replace("THISID",strid);
		x.innerHTML=strx;
		x.className=objCell[i].className;
	}
}
function table_row_del(id,msgid){
	var obj=document.getElementById(id);
	if(!obj){
	  alert("找不到对象");
	  return;
	}
	var obj_row=document.getElementById(msgid);
	if(obj_row){
	//var strRowIndex=parseInt(obj.rows.length)-1;
		obj.deleteRow(obj_row.rowIndex);
	}
}
var dialog_z_index=0;
function div_show(msgid,msg_top,msg_left)
{
	if(dialog_z_index<0) dialog_z_index=0;
	dialog_z_index++;
	obj=document.getElementById(msgid);
	if(obj)
	{
		if(dialog_z_index==1){
			var lng_x=document.forms.length;
			for(var j=0;j<lng_x;j++){
				var form=document.forms[j];
				for(var i = 0; i < form.elements.length; i++) {
					var e = form.elements[i];
					if(e.type.match("select")) {
						e.style.visibility="hidden";
					}
				}
			}
		}
		obj.style.zIndex=dialog_z_index;
		obj.style.display='';	
		//msgObj.style.top=document.body.scrollTop+100;
		if(msg_left){
			lng_left=msg_left;
		}else{
			var w1=get_realW();
			var w2=get_realW(obj);
			lng_left=(w1-w2)/2;
		}
		if(msg_top){
			lng_top=msg_top;
		}else{
			if(document.documentElement.clientHeight>obj.offsetHeight){
				lng_top=(document.documentElement.clientHeight-obj.offsetHeight)/2;
			}else{
				lng_top=100;
			}
		}
		int_height=document.body.scrollTop;
		if(!int_height)int_height=document.documentElement.scrollTop;
		lng_top=lng_top+int_height;
		lng_top=lng_top+"px";
		lng_left=lng_left+"px";
		obj.style.top=lng_top;
		obj.style.left=lng_left;			
	}
}
function get_realW(obj){
	var w;
	if(obj){
		if(obj.scrollWidth){
			w=obj.scrollWidth;
		}else if(obj.width){
			w=obj.scrollWidth;
		}
	}else{
		w=document.body.scrollWidth;
		if(document.documentElement.scrollWidth && (!w || document.documentElement.scrollWidth>w)){
			w=document.documentElement.scrollWidth;
		}
	}
	return w;
}
function get_realH(obj){
	var h;
	if(obj){
		if(obj.scrollHeight){
			h=obj.scrollHeight;
		}else if(obj.height){
			h=obj.scrollWidth;
		}
	}else{
		h=document.body.scrollHeight;
		if(document.documentElement.scrollHeight && (!h || document.documentElement.scrollHeight>h)){
			h=document.documentElement.scrollHeight;
		}
	}
	return h;
}
function div_hide_show(msgid){
	dialog_z_index--;
	div_hide(msgid);
	if(dialog_z_index==0){
		var lng_x=document.forms.length;
		for(var j=0;j<lng_x;j++){
			var form=document.forms[j];
			for(var i = 0; i < form.elements.length; i++) {
				var e = form.elements[i];
				if(e.type.match("select")) {
					e.style.visibility="";
				}
			}
		}
	}
}
function div_hide_show_parent(msgid){
	dialog_z_index--;
	obj_x=parent.document.getElementById(msgid);
	if(obj_x) obj_x.style.display="none";
	if(dialog_z_index<=0){
		var lng_x=parent.document.forms.length;
		for(var j=0;j<lng_x;j++){
			var form=parent.document.forms[j];
			for(var i = 0; i < form.elements.length; i++) {
				var e = form.elements[i];
				if(e.type.match("select")) {
					e.style.display="";
				}
			}
		}
	}
}
function div_hide(msgid){
	obj=document.getElementById(msgid);
	if(obj)
	{
		obj.style.display='none';
	}
}
function div_show_hide(msgid){
	obj=document.getElementById(msgid);
	if(obj)
	{
		if(obj.style.display=='none'){
			obj.style.display="";
		}else{
			obj.style.display='none';
		}
	}
}
function div_display(msg_id,msg_type,msg_val){
	if(msg_id.name){
		objx=msg_id;
	}else{
		objx=document.getElementById(msg_id);
	}
	obj=objx.getElementsByTagName(msg_type);
	for(i=0;i<obj.length;i++){
		obj[i].style.display=msg_val;
	}
}
function divMove(divObj)
{
		if (!divObj) return;
		divObj.hasDraged = false;
		//this.divObj = divObj;
		// 把鼠标的形状改成移动形
		divObj.style.cursor = "move";
		// 定义鼠标按下时的操作
		divObj.onmousedown = function(event){
			if(window.event) event=window.event;
			var ofs = Offset(divObj);
			divObj.style.position = "absolute";
			divObj.style.left = ofs.l;
			divObj.style.top = ofs.t;
			divObj.X = event.clientX - ofs.l;
			divObj.Y = event.clientY - ofs.t;
			divObj.hasDraged = true;
		};

		// 定义鼠标移动时的操作
		divObj.onmousemove = function(event)
		{
			if (!divObj.hasDraged) return;
			if(window.event){
				event=window.event;
				divObj.setCapture();
			}
			var lng_x=event.clientX - divObj.X;
			var lng_y=event.clientY - divObj.Y;
			divObj.style.left = lng_x+"px";
			divObj.style.top = lng_y+"px";
		};
		// 定义鼠标提起时的操作
		divObj.onmouseup = function()
		{
			divObj.hasDraged = false;
			if(window.event){
				divObj.releaseCapture();
			}
		};
		function Offset(e)
		{
			var t = e.offsetTop;
			var l = e.offsetLeft;
			var w = e.offsetWidth;
			var h = e.offsetHeight;
			while(e=e.offsetParent)
			{
				t+=e.offsetTop;
				l+=e.offsetLeft;
			}
			return { t:t, l:l, w:w, h:h }
		};
};
function get_real_url(msgurl){
	if(msgurl.indexOf("http://")==-1){
		msgurl=cfg_web_url+msgurl;
	}
	return msgurl;
}
//添加收藏
function JSAddFavorite(url,title)
{
        if ( window.sidebar && "object" == typeof( window.sidebar ) && "function" == typeof( window.sidebar.addPanel ) )
        {
                //  firefox
                window.sidebar.addPanel(title,url,'');
        }

        else if ( document.all && "object" == typeof( window.external ) )
        {
                //  ie               
				window.external.addFavorite(url,title);
        }
}
//复制
function copy(text){
     if(window.clipboardData){//判断是否具有clipboardData对象，IE
         window.clipboardData.setData("Text",text);
		 alert('复制成功');
     }else if(window.netscape){//判断是否存在netscape对象，FF
         try{//用try来尝试使用对象
             netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
			 alert('复制成功');
         }catch(e){//如果不能使用剪贴板，提示用户出错
             alert('您的firefox安全限制限制您进行剪贴板操作。\n请打开 "about:config" 将signed.applets.codebase_principal_support "设置为true" 之后重试');
             return false;
         }
         var clip,trans,str={},clipid;
         if(!(clip=Components.classes["@mozilla.org/widget/clipboard;1"].createInstance(Components.interfaces.nsIClipboard))) return;
         if(!(trans=Components.classes["@mozilla.org/widget/transferable;1"].createInstance(Components.interfaces.nsITransferable))) return;
         trans.addDataFlavor("text/unicode");
         str=Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
         str.data=text;
         trans.setTransferData("text/unicode",str,text.length*2);
         clipid=Components.interfaces.nsIClipboard;		 
         try{			 
             clip.setData(trans,null,clipid.kGlobalClipboard);
			 alert('复制成功');
         }catch(e){return false}
     }
}
//禁止网页操作
var pubShield;
var pubIsShield=false;
function sysOpenDialog(msgObj)
{
	if(!pubIsShield)
	{
		pubShield = document.createElement("DIV");
		pubShield.id = "pubShield";
		pubShield.style.position = "absolute";
		pubShield.style.left = "0px";
		pubShield.style.top = "0px";
		pubShield.style.width = "100%";
		int_height=document.body.scrollTop;
		if(!int_height)int_height=document.documentElement.scrollTop;
		pubShield.style.height = document.body.clientHeight+50+int_height;
		pubShield.style.background = "#333";
		pubShield.style.textAlign = "center";
		pubShield.style.zIndex = "1";
		pubShield.style.filter = "alpha(opacity=20)";
		pubShield.style.opacity = 0;
		document.body.appendChild(pubShield);
		pubIsShield=true;
	}
		if(msgObj)
	{
		msgObj.style.zIndex="999";
		//msgObj.style.top=document.body.scrollTop+100;
		int_height=document.body.scrollTop;
		if(!int_height)int_height=document.documentElement.scrollTop;
		msgObj.style.top=int_height+100;
		msgObj.style.left=100;			
		msgObj.style.display='';	
	}

}
//恢复禁止
function sysCloseDialog(msgObj)
{
	if(pubIsShield)
	{
		document.body.removeChild(pubShield);
		pubIsShield=false;
	}
	//parent.document.body.removeChild(parent.pubShield);
	if(parent.pubIsShield) 
	{
		if(parent.pubShield) parent.document.body.removeChild(parent.pubShield);
		parent.pubIsShield=false;
	}
	if(msgObj)
	{
		msgObj.style.display='none';
	}
}

function js_over(msg_key,msg_id,msg_num,msg_css1,msg_css2){
	var obj_tit=document.getElementById(msg_key+msg_id);
	var obj_item;
	var obj_titx;
	if(obj_tit){
		for(i=1;i<=msg_num;i++){
			obj_item=document.getElementById(msg_key+i+"_item");
			if(i==msg_id){
				obj_item.style.display="";
			}else{
				obj_item.style.display="none";
			}
		}
		if(msg_css2){
			for(i=1;i<=msg_num;i++){
				obj_titx=document.getElementById(msg_key+i);
				obj_titx.className=msg_css2;
			}
		}
		obj_tit.className="";
	}
}
function textarea_insertstr(id, value){
	var o = document.getElementById(id);
	o.focus();
	if(document.selection)
		document.selection.createRange().text = value;
	else 
		o.value = o.value.substr(0, o.selectionStart) + value + o.value.substr(o.selectionEnd);
}

function set_agent_time(){
	var date = new Date();
	var lng_month=date.getMonth()+1;
	var str_val=date.getFullYear()+"-"+lng_month+"-"+date.getDate()+" "+date.getHours()+":"+date.getMinutes()+":"+date.getSeconds();
	set_cookie("agent_time",str_val,24,"/");
}

function set_cookie(objName,objValue,objHours,msgPath){//添加cookie
	var str = objName + "=" + escape(objValue);
	if(!objHours) objHours=24;
	var date = new Date();
	var ms = objHours*3600*1000;
	date.setTime(date.getTime() + ms);
	var strPath="";
	if(msgPath) strPath="; path=" + msgPath;
	str += "; expires=" + date.toGMTString() + strPath;
	document.cookie = str;
}
  
function get_cookie(objName){//获取指定名称的cookie的值
	var arrStr = document.cookie.split("; ");
	for(var i = 0;i < arrStr.length;i ++){
		var temp = arrStr[i].split("=");
		if(temp[0] == objName) return unescape(temp[1]);
	}
}
  
function del_cookie(name){//为了删除指定名称的cookie，可以将其过期时间设定为一个过去的时间
	var date = new Date();
	date.setTime(date.getTime() - 10000);
	document.cookie = name + "=a; expires=" + date.toGMTString();
}
function get_body_height(){
	var int_scrollheight=document.body.scrollHeight;
	if(document.documentElement.scrollHeight && (!int_scrollheight || document.documentElement.scrollHeight>int_scrollheight)){
		int_scrollheight=document.documentElement.scrollHeight;
	}
	return int_scrollheight;
}
set_agent_time();