﻿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{
		var callback = arguments[4];
		if (arguments[4] != "undefined" && arguments[4] != "" && arguments[4] != undefined && arguments[4] != null){
			xmlhttp.onreadystatechange = arguments[4];
		}
        xmlhttp.open(RequestType,Url,false);
        xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
        xmlhttp.send(RequestData);
        
		if (arguments[4] == "undefined" || arguments[4] == "" || arguments[4] == undefined || arguments[4] == null){
			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);
	}
	if(typeof($)=="function")
	{
		return $(content).find("#content").html();
	}
	content = content.match(/<div id=.content.[\s\S]*?>[\s\S]+?<\/div>[\s\S]+?<\/td>/);
    return content;
}
//全文下载（1）
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篇文章！");
		}
	}
 
}
//全文下载（2）
function DownLoadFullContI(inputname){

	var content = "";
	var contentNum=0;
	var inputsValue="";
	var inputNumT="";
	var inputs = $n(inputname);
	var inputsType = $n(inputname+"Type");
	var inputsChannelID = $n(inputname+"ChannelID")
	var LeaveChannelID="2010100";
	for(var i=0; i<inputs.length; i++){
		var eNum = inputs[i];
		var eNumT = inputsType[i];
		if(eNum.checked)
		{
			 contentNum=parseInt(contentNum)+1;	
			 inputNumT+=eNumT.value+",";
			    if(inputsChannelID[i].value=="2010200")
				{
				   LeaveChannelID="2010200";
				}
		}	

	}

	if(contentNum==0)
	{
		alert("请选择您需要下载的记录！");
	}
	else
	{
		if(contentNum<=6){
			
			if(LeaveChannelID!="2010200")
			{	
				for(var i=0; i<inputs.length; i++){
					var e = inputs[i];
					if(e.checked){
						inputsValue += inputs[i].value+",";
	
					}
				}
				if(window.ActiveXObject){
					window.showModalDialog('/js/DownLoadFileFrame.asp?OnCaseID='+inputsValue+'&FRID='+inputNumT+'','', 'dialogWidth:550px;dialogHeight:450px;status:0;help:no;scroll:no;');
				}
				else{
					window.open('/js/DownLoadFileFrame.asp?OnCaseID='+inputsValue+'&FRID='+inputNumT+'','','width=550,height=450,top=0,left=0,Location=no,Toolbar=no,Resizable=no;status:0;help:no;scroll:no','');
				}
			}
			else
			{
				        var today = new Date();       
						var day = today.getDate();       
						var month = today.getMonth() + 1;       
						var year = today.getYear();
						var Hours = today.getHours();
						var Seconds = today.getSeconds();
						var NowTimeDate = year.toString()+month.toString()+day.toString()+Hours.toString()+Seconds.toString();
				        DownLoadFullCont("下载媒体案例"+NowTimeDate,inputname);
			}
		}
		else
		{
			alert("为了保证网络全文下载速度，每次全文下载最多不能超过6篇文章！");
		}
	}
 
}
//列表下载
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";
	}
}

//设置每页显示条数
function SetPageSize(PageSize){
	var fromObj = $n('frmTurnsPage');
	if(fromObj.length>0){
		fromObj = fromObj[0];
		var intputpagesize = $n("PageSize");
		if(intputpagesize.length>0){
			intputpagesize[0].value = PageSize;
		}
		else{
			intputpagesize = document.createElement('input');
			intputpagesize.type = "hidden";
			intputpagesize.name = "PageSize";
			intputpagesize.value = PageSize;
			fromObj.appendChild(intputpagesize);
		}
		setTimeout(function(){fromObj.submit();},0);
	}
}



function DownLoadActList(subject,inputname){
	var objid = $n(inputname);
	var id = "";
	var j = 0;
	for (var i=0; i<objid.length; i++){
		if(objid[i].type == "checkbox" && objid[i].checked){
			if (id == ""){
				id = objid[i].value;
			}
			else{
				id += "," + objid[i].value;
			}
			j = j + 1;
		}
	}
	if (j >10){
		alert("对不起，最多只能下载10个！");
		return false;
	}
	if (id != ""){
		var url = "/Act/DownLoadActList.asp?filename="+subject+"&id="+id+"&r="+Math.random();
		if(window.ActiveXObject){
			window.showModalDialog(url,'', 'dialogWidth:900px;status:0;help:no;');
		}
		else{
			//window.showModalDialog(url,'', 'dialogWidth:900px;status:0;help:no;scroll:no;');
			window.open(url,'','width=900,top=0,left=0,Location=no,Toolbar=no,Resizable=no;status:0;help:no;modal=yes','');
		}
	}
	else{
		alert("请选择需要下载的内容！");
	}
}

function DownLoadAct(subject,inputname){
	var objid = $n(inputname);
	var id = "";
	var j = 0;
	for (var i=0; i<objid.length; i++){
		if(objid[i].type == "checkbox" && objid[i].checked){
			if (id == ""){
				id = objid[i].value;
			}
			else{
				id += "," + objid[i].value;
			}
			j = j + 1;
		}
	}
	if (j >4){
		alert("对不起，最多只能下载4个！");
		return false;
	}
	
	if (id != ""){	
		var body = document.body;
		var formid = 'DownloadForm';
		var url = '/Act/DownLoadAct.asp';
		var node = $g(formid);
		if (node != null) {
			node.parentNode.removeChild(node);
		}
		var theForm = document.createElement('form');
		theForm.id = formid;
		theForm.action = url;
		theForm.method = 'post';
		theForm.target = "_blank";
	
		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 = 'RID';
		node.value = id;
		theForm.appendChild(node);
	
		body.appendChild(theForm);
		theForm.submit();
	}
	else{
		alert("请选择需要下载的内容！");
	}
}



/*
* 描述：自定义通用的javascript字典类。
* 属性：
*     count 字典中的条目数。
* 方法：
*     add(key,value) 增加字典的条目(返回值：无返回值)。参数：key 唯一的键值，value 与键值对应的值。
*     remove(key)    根据指定的键值删除字典中的条目(返回值：无返回值)。参数：key 要删除的字典条目的键值。
*     removeAll()    删除字典中的所有的条目(返回值：无返回值)。
*     exists(key)    检测指定的键值在字典中是否存在(返回值：true 存在，false 不存在)。参数：key 要检测的键值。
*     item(key)      根据指定键值获取与该键值对应的值(返回值：实际类型的值)。参数：key 要查找的键值。
*     keys()         获取字典中所有的键值(返回值：键值数组)。
*     values()       获取字典中所有的值(返回值：值数组)。
* 示例：
*     var dic = new Dictionary();
*     dic.add("key1","value1");
*     dic.add("key2","value2");
*     dic.add("key3","value3");
*     alert(dic.count);
*/
function Dictionary(){
	this._obj = {};
	this.count = 0;
}
Dictionary.prototype.Add = function(key,value){
	if(typeof(this._obj[key]) != "undefined"){
	   throw new Error("关键字[" + key + "]已存在！");
	}
	this._obj[key] = value
	this.count += 1;
};
Dictionary.prototype.Remove = function(key){
	if(typeof(this._obj[key]) == "undefined"){
	   throw new Error("关键字[" + key + "]不存在！");
	}
	delete this._obj[key];
	this.count -= 1;
};
Dictionary.prototype.RemoveAll = function(){
	this._obj = {};
	this.count = 0;
};
Dictionary.prototype.Exists = function(key){
	if(typeof(this._obj[key]) == "undefined"){
	   return false;
	}
	return true;
};
Dictionary.prototype.Item = function(key){
	if(typeof(this._obj[key]) == "undefined"){
	   throw new Error("关键字[" + key + "]不存在！");
	}
	return this._obj[key];
};
Dictionary.prototype.Keys = function(){
	var keys = [];
	for(var p in this._obj){
	   keys[keys.length] = p;
	}
	return keys;
};
Dictionary.prototype.Values = function(){
	var values = [];
	for(var p in this._obj){
	   values[values.length] = this._obj[p];
	}
	return values;
};
