﻿function $g(id){
	return document.getElementById(id);
}

function $n(name){
	return document.getElementsByName(name);
}

function CheckByName(form,tname,checked){
    for (var i=0;i<form.elements.length;i++){
        var e = form.elements[i];
        if(e.name == tname){
            e.checked = checked;
        }
    }
}

function CheckAll(form){
  for (var i=0;i<form.elements.length;i++){
        var e = form.elements[i];
        if (e.type=="checkbox" && e.name != 'chkall' && e.name !='deleteMode'){
           e.checked = form.chkall.checked;
        }
    }
}

function CopyRightAlert(){alert('欲浏览详细信息，请与010-62758866联系！');}

function selectall(s){   
	var obj=document.getElementsByTagName("input");   
	for(i=0;i<obj.length;i++){
		if(obj[i].id=="id"+s){
			obj[i].checked=window.event.srcElement.checked ; 
		}
	}   
}

function CheckAllByName(obj,name){
	var objs = document.getElementsByName(name);
	for(var i=0; i<objs.length; i++){
		objs[i].checked = obj.checked;
	}
}

var xmlhttp;
   
function getReturn(Url,ReturnType,RequestType,RequestData){  //提交为aspx,aspx页面路径, 返回页面的值
    if(typeof XMLHttpRequest != "undefined"){
        xmlhttp = new XMLHttpRequest();
    }
    else if(window.ActiveXObject){
        var versions = ["MSXML2.XMLHttp.5.0","MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0","MSXML2.XMLHttp","Microsoft.XMLHttp"];
        for(var i = 0 ; i < versions.length; i++){
            try{
                xmlhttp = new ActiveXObject(versions[i]);
                break;
            }
            catch(E){
            }
        }
    }
        
    try{
        xmlhttp.open(RequestType,Url,false);   
        xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded')
        xmlhttp.send(RequestData);    
        
        if((xmlhttp.readyState == 4)&&(xmlhttp.status == 200)){
			switch (ReturnType){
				case "text":
            		return xmlhttp.responseText;
					break;
				case "xml":
					return xmlhttp.responseXML;
					break;
				default:
					return xmlhttp.responseText;
					break;
			}
        }
        else{
           return null;
        }
    }
    catch (e){  
         alert("你的浏览器不支持XMLHttpRequest对象, 请升级！"); 
    }

    return null;
}
       

function isMaxLen(o){
	var nMaxLen=o.getAttribute? parseInt(o.getAttribute("maxlength")):"";
	if(o.getAttribute && o.value.length>nMaxLen){
		o.value=o.value.substring(0,nMaxLen)
	}
}


function enableCheckBox(b,form){
	for (var i=0;i<form.elements.length;i++){
		var e = form.elements[i];
		if (e.type == "checkbox"){
			e.disabled = b;
			e.checked = false;
		}
	}
} 

function isie(){
   if(navigator.userAgent.toLowerCase().indexOf('msie') != -1){
       return true;
   }
   else{
       return false;
   }
}  


//显示提示层
function showhintinfo(obj, objleftoffset,objtopoffset, title, info , objheight, showtype ,objtopfirefoxoffset){

   var p = getposition(obj);

   if((showtype==null)||(showtype =="")){
       showtype =="up";
   }
   $('hintiframe'+showtype).style.height= objheight + "px";
   $('hintinfo'+showtype).innerHTML = info;
   $('hintdiv'+showtype).style.display='block';
   
   if(objtopfirefoxoffset != null && objtopfirefoxoffset !=0 && !isie()){
        $('hintdiv'+showtype).style.top=p['y']+parseInt(objtopfirefoxoffset)+"px";
   }
   else{
        if(objtopoffset == 0){ 
			if(showtype=="up"){
				 $('hintdiv'+showtype).style.top=p['y']-$('hintinfo'+showtype).offsetHeight-40+"px";
			}
			else{
				 $('hintdiv'+showtype).style.top=p['y']+obj.offsetHeight+5+"px";
			}
        }
        else{
			$('hintdiv'+showtype).style.top=p['y']+objtopoffset+"px";
        }
   }
   $('hintdiv'+showtype).style.left=p['x']+objleftoffset+"px";
}



//隐藏提示层
function hidehintinfo(){
    $('hintdivup').style.display='none';
    $('hintdivdown').style.display='none';
}



//得到字符串长度
function getLen(str){
   var totallength=0;
   
   for (var i=0;i<str.length;i++){
     var intCode=str.charCodeAt(i);   
     if (intCode>=0&&intCode<=128){
        totallength=totallength+1; //非中文单个字符长度加 1
	 }
     else{
        totallength=totallength+2; //中文字符长度则加 2
     }
   } 
   return totallength;
}


function getposition(obj){
	var r = new Array();
	r['x'] = obj.offsetLeft;
	r['y'] = obj.offsetTop;
	while(obj = obj.offsetParent){
		r['x'] += obj.offsetLeft;
		r['y'] += obj.offsetTop;
	}
	return r;
}

function isNumber(str){
    return (/^[+|-]?\d+$/.test(str));
}

//function trim(str) {
//	return (str + '').replace(/(\s+)$/g, '').replace(/^\s+/g, '');
//}

function trim(text){
  if (typeof(text) == "string"){
    return text.replace(/^\s*|\s*$/g, "");
  }
  else{
    return text;
  }
}

//设置半透明效果
function display_opacity(id, n) {
	if(!$g(id)) {
		return;
	}
	if(n >= 0) {
		n -= 10;
		$g(id).style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=' + n + ')';
		$g(id).style.opacity = n / 100;
		setTimeout('display_opacity(\'' + id + '\',' + n + ')', 50);
	} else {
		$g(id).style.display = 'none';
		$g(id).style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=100)';
		$g(id).style.opacity = 1;
	}
}


function CuteEditor_Decode(str) {

        if (!str) {
            return str;
    }

    str = str.replace(/#1/g, "<");
    str = str.replace(/#2/g, ">");
    str = str.replace(/#3/g, "&");
    str = str.replace(/#4/g, "*");
    str = str.replace(/#5/g, "o");
    str = str.replace(/#6/g, "O");
    str = str.replace(/#7/g, "s");
    str = str.replace(/#8/g, "S");
    str = str.replace(/#9/g, "e");
    str = str.replace(/#a/g, "E");
    str = str.replace(/#0/g, "#");
    return str;
}


　 /*
　 *　方法:Array.remove(dx)
　 *　功能:删除数组元素.
　 *　参数:dx删除元素的下标.
　 *　返回:在原数组上修改数组
　 */
　　
　//经常用的是通过遍历,重构数组.
　Array.prototype.Remove=function(dx){
　　if(isNaN(dx)||dx>this.length){return false;}
　　for(var i=0,n=0;i<this.length;i++){
　　　　if(this[i]!=this[dx]){
　　　　　　this[n++]=this[i];
　　　　}
　　}
　　this.length-=1;
　}
　　
　/*
　 *　方法:Array.baoremove(dx)
　 *　功能:删除数组元素.
　 *　参数:dx删除元素的下标.
　 *　返回:在原数组上修改数组.
　 */
　　
　//我们也可以用splice来实现.
　　
　Array.prototype.Delete = function(dx){
　　if(isNaN(dx)||dx>this.length){return false;}
　　this.splice(dx,1);
　}


//添加到收藏夹
function AddToFavorite(){
    if (document.all){
       window.external.addFavorite(document.URL,document.title);
    }else if (window.sidebar){
       window.sidebar.addPanel(document.title, document.URL, "");
    }
}

//设为首页
function setHomepage(){
	if (document.all){
    document.body.style.behavior='url(#default#homepage)';
    document.body.setHomePage(document.URL);
  }else if (window.sidebar){
		if(window.netscape){
       try{ 
          netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); 
       }catch (e){ 
 					alert( "该操作被浏览器拒绝，如果想启用该功能，请在地址栏内输入 about:config,然后将项 signed.applets.codebase_principal_support 值该为true" ); 
       }
		} 
    var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components. interfaces.nsIPrefBranch);
    prefs.setCharPref('browser.startup.homepage',document.URL);
	}
}

function OpenDialog(url, obj, wid, hig){
	window.showModalDialog(url, obj, 'dialogWidth:'+wid+'px;dialogHeight:'+hig+'px;status:0;help:no;scroll;no;scroll=no');
}

function getPageContent(url){
	var content;
	if(url.indexOf('Case_Data.asp')>-1)
	{
		var content1;
		content1 = getReturn(url+"&a="+Math.random(),"text","get",null);
		content1 = content1.match(/<a\b("[^"]*"|'[^']*'|[^'">])* target="_blank">点击浏览案例内容/)[1];
		content1=content1.replace("'","");
		content1=content1.replace("\"","");
		content = getReturn(content1+"&a="+Math.random(),"text","get",null);
	}
	else
	{
		content = getReturn(url+"&a="+Math.random(),"text","get",null);
	}
	content = content.match(/<div id=.content.[\s\S]*?>[\s\S]+?<\/div>[\s\S]+?<\/td>/);
    return content;
}

function DownLoadFullCont(subject,inputname){

	var content = "";
	var contentNum=0;
	var inputs = $n(inputname);
	for(var i=0; i<inputs.length; i++){
	var eNum = inputs[i];
	if(eNum.checked){
		 contentNum=parseInt(contentNum)+1;
    	}
	}
	if(contentNum==0)
	{
		alert("请选择您需要下载的记录！");
	}
	else
	{
		if(contentNum<=10){
			for(var i=0; i<inputs.length; i++){
				var e = inputs[i];
				if(e.checked){
					if(getPageContent(document.getElementById("Href"+e.value).value)!=null)
					{
						content += "<span style='color:#F00'>第"+parseInt(i+1)+"篇</span>"+getPageContent(document.getElementById("Href"+e.value).value)+"<p>&nbsp;</p>";
					}
					else
					{
						alert("对不起！您选择下载的第"+parseInt(i+1)+"篇记录没有全文页。");
						return;
					}
				}
			}
			content = content.replace(/\<img.*?\>/ig, '');
			content = content.replace(/\<input.*?\>/ig, '');
			content = "<table>"+content+"</table>"
			var body = document.body;
			var formid = 'DownloadForm';
			var url = '/public/DownloadToDoc.asp';
			var node = document.getElementById(formid);
			if (node != null) {
				node.parentNode.removeChild(node);
			}
			var theForm = document.createElement('form');
			theForm.id = formid;
			theForm.action = url;
			theForm.method = 'post';
		
			node = document.createElement('input');
			node.type = 'hidden';
			node.name = 'File_Name';
			node.value = subject;
			theForm.appendChild(node);
		
			node = document.createElement('input');
			node.type = 'hidden';
			node.name = 'strItemContent';
			node.value = content;
			theForm.appendChild(node);
		
			body.appendChild(theForm);
			theForm.submit();
		}
		else
		{
			alert("为了保证网络全文下载速度，每次全文下载最多不能超过10篇文章！");
		}
	}
 
}


function DownLoadList(subject,inputname){
	var content = "";
	var inputs = $n(inputname);
	var contentNum=0;
	for(var i=0; i<inputs.length; i++){
		var e = inputs[i];
		if(e.checked){
			content += $g("list"+e.value).innerHTML;
			contentNum=parseInt(contentNum)+1;
		}
	}
	if(contentNum==0)
	{
		alert("请选择您需要下载的记录！");
	}
	else
	{	
		content = content.replace(/\<img.*?\>/ig, '');
		content = content.replace(/\<input.*?\>/ig, '');
		content = "<table>"+content+"</table>"
		var body = document.body;
		var formid = 'DownloadForm';
		var url = '/public/DownloadToDoc.asp';
		var node = document.getElementById(formid);
		if (node != null) {
			node.parentNode.removeChild(node);
		}
		var theForm = document.createElement('form');
		theForm.id = formid;
		theForm.action = url;
		theForm.method = 'post';
	
		node = document.createElement('input');
		node.type = 'hidden';
		node.name = 'File_Name';
		node.value = subject;
		theForm.appendChild(node);
	
		node = document.createElement('input');
		node.type = 'hidden';
		node.name = 'strItemContent';
		node.value = content;
		theForm.appendChild(node);
	
		body.appendChild(theForm);
		theForm.submit();
	}
}

function CaseOclick(str)
{
	if(str!="caseli")
	{
		document.getElementById("caseli").className="data_tab_li1";
		document.getElementById("casehotli").className="data_tab_li2";
	}
	else
	{
		document.getElementById("caseli").className="data_tab_li2";
		document.getElementById("casehotli").className="data_tab_li1";
	}
}

