function $g(id){
	return document.getElementById(id);
}
function IsNotResulMsg()
		{
			
			if(document.getCookie("UserName"))
			{
				if(confirm('没有找到相关记录，是否转到查询提示页面！'))
				{
					window.location.href='/Lib/NotResulInfo_Post.asp';
				}
			}
			else
			{
				alert("对不起! 数据库中没有找到您所需要的记录!如需查询服务请拨打我们的服务电话.");
			}
			$("#loader").hide();
		}
function $n(name){
	return document.getElementsByName(name);
}
function LTrim(str)
{
    var whitespace = new String(" \t\n\r");
    var s = new String(str);

    if (whitespace.indexOf(s.charAt(0)) != -1)
    {
        var j=0, i = s.length;
        while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
        {
            j++;
        }
        s = s.substring(j, i);
    }
    return s;
}

function RTrim(str)
{
    var whitespace = new String(" \t\n\r");
    var s = new String(str);
 
    if (whitespace.indexOf(s.charAt(s.length-1)) != -1)
    {
        var i = s.length - 1;
        while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
        {
            i--;
        }
        s = s.substring(0, i+1);
    }
    return s;
}

function Trim(str){return RTrim(LTrim(str));}

function XMLEncode(str){
	str=Trim(str);
	str=str.replace("&","&amp;");
	str=str.replace("<","&lt;");
	str=str.replace(">","&gt;");
	str=str.replace("'","&apos;");
	str=str.replace("\"","&quot;");
	return str;
}

function cn2num(str){
	var s;
	var numeral;
	var entries;
	var tenNum;
	s=str;
	s=s.replace(/一/g,'1');
	s=s.replace(/二/g,'2');
	s=s.replace(/三/g,'3');
	s=s.replace(/四/g,'4');
	s=s.replace(/五/g,'5');
	s=s.replace(/六/g,'6');
	s=s.replace(/七/g,'7');
	s=s.replace(/八/g,'8');
	s=s.replace(/九/g,'9');
	s=s.replace(/零/g,'0');
	s=s.replace(/○/g,'0');
	if(s.indexOf('十')>=0){
	tenNum = regExpGet(s, '([0-9]*十)');
	entries= s.substr(s.indexOf('十')+1, s.length-s.indexOf('十')-1);
	if(tenNum=='十'){tenNum=10}
	else(tenNum = regExpGet(tenNum, "([1-9]+)") + '0')
	numeral = new Number(tenNum)+new Number(entries);
	}else{numeral=s}
	return(numeral);
}

function OpenWindow(Url){
	window.open(Url,'','top=0, left=0, toolbar=no, menubar=no, scrollbars=yes, resizable=yes,location=no, status=no');
}

function compareDate(strDate1,strDate2) {
	var tmp1=strDate1.split('-');
	var tmp2=strDate2.split('-');
	var date1=eval('new Date('+tmp1[0]+','+tmp1[1]+','+tmp1[2]+')');
	var date2=eval('new Date('+tmp2[0]+','+tmp2[1]+','+tmp2[2]+')');
	//if ((date2.valueOf()-date1.valueOf())>=20*24*60*60*1000)
	if ((date2.valueOf()-date1.valueOf())>=0)	{return true;}
	else{return false;}
}


/*
   Open popup widows of (mostly) predetermined types.

   windowURL -- The URL to load in the new browser window.
   type -- The (predetermined) type of window to launch.
           acceptable values for type:
           1: a help window
           2: a 400x400 window
           3: Issuezilla assignable users popup window
           ... and you can hard code others yourself inside the function.
   atts -- (optional) If the window you wish to create is unique and you do
           not want to set up a "type" for it, or if you want to pass
           additional attributes for a certain "type", you can pass its
           attributes directly to the function via this parameter.
*/
var tigrisPopupCounter = 0;
function launch(windowURL, type, atts) {
  tigrisPopupCounter += 1;

  var windowName = 'SourceCast' + type;
  if (atts) {windowName += tigrisPopupCounter;}

  var winAtts;
  if (type == 1) {winAtts = 'resizable=1,left=10,top=10,screenX=12,screenY=12,height=485,width=724,status=1,scrollbars=1,toolbar=1,menubar=1,location=1';}
  else if (type == 2) {winAtts = 'resizable=1,left=10,top=10,screenX=12,screenY=12,height=400,width=400';}
  else if (type == 3) {winAtts = 'resizable=1,left=10,top=10,screenX=12,screenY=12,height=440,width=600,scrollbars=1';}
  if (atts) {winAtts += ',' + atts;}

  var windowObj = window.open(windowURL, windowName, winAtts);

  if (windowObj) {return false;}
  else {return true;}
}

/*----------------------------------------------------------------------------*/
/**
 * 转换阿拉伯数字为汉字数码
 * @author fpeez
 * @author fpeez@163.com
 * @version 1.0
 * 主体函数, 实现转换
 * @param inString    (String)输入的阿拉伯数字字符串(如: "13800138000")
 * @param isUpcase    (boolean)输出汉字数码大小写指示(如: false)
 * @param times       (String)阶数(如: "个万亿兆...")
 * @param errorCode   (String)错误时(溢出,空值,...)归零显示(如: "E")
 * @return ~errorCode
 * @return ~OUT       (String)转换后的汉字数码(如: "一百三十八亿〇一十三万八千")
 * eg. changeDigitToHZ("13800138000",false,"个万亿兆","E")
*/
function changeDigitToHZ(inString, isUpcase, times, errorCode) {
	/** 输入字符串预处理, 亦可放到函数外执行 **/
	inString=formatedDigit(inString);
	/** 变量定义 **/
	var base,digit;                           // times: 阶数("个万亿兆...")
	if(isUpcase) {
		base="个拾佰仟";                      // base: 位数
		digit="零壹贰叁肆伍陆柒捌玖";         // digit: 汉字数码串(大写)
	} else {
		base="个十百千";
		digit="〇一二三四五六七八九";
	}

	var sLen,b,t,bLen;
	sLen=inString.length;                     // 输入字符串的长度
	bLen=base.length;                         // 位数的长度
	if(sLen>bLen*times.length || sLen<1) return errorCode;      // 溢出归零
	b=(sLen-1)%bLen;                          // 当前数码在base中的位置
	t=Math.floor((sLen-1)/bLen);              // 当前数码在times中的位置
	var i,at,zero;
	i=0;                                      // at某个位上的数码, i循环计数
	zero="";                                  // 保存数字中的0值
	var OUT="";                                   // 输出汉字数码

	/** 开始 **/
	at=inString.charCodeAt(i)-48;             // 处理"一十二"为"十二", 此时i=0
	if(at==1 && b==1){
		OUT+=base.charAt(b--);
		i+=1;                                 // 此时, i=1
	}
	while(i<sLen) {
		at=inString.charCodeAt(i++)-48;
		if(b!=0) {
			if(at!=0) {
				OUT+=zero;
				zero="";
				OUT+=digit.charAt(at);
				OUT+=base.charAt(b);
			} else zero=digit.charAt(0);         // 此时, zero="零"或"〇"
			b--;
		} else {
			if(at!=0) {
				OUT+=zero;
				OUT+=digit.charAt(at);
			}
			zero="";
			if(t!=0) OUT+=times.charAt(t--);
			b=bLen-1;
		}
	}

  return OUT;  
}
function CheckAllByName(obj,name){
	var objs = document.getElementsByName(name);
	for(var i=0; i<objs.length; i++){
		objs[i].checked = obj.checked;
	}
}

//ajax
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.1.0','MICROSOFT.XMLHTTP.1','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 unescape(xmlhttp.responseText);
					break;
				case "xml":
					return xmlhttp.responseXML;
					break;
				default:
					return xmlhttp.responseText;
					break;
			}
        }
        else{
           return null;
        }
    }
    catch (e){  
         alert("你的浏览器不支持XMLHttpRequest对象, 请升级！"); 
    }

    return null;
}

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;
}

//全文下载（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){
	if(!document.getCookie("UserName")){
		alert("请登录后下载");
		return false;
	}
	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";
	}
}  
document.setCookie=function(c_name,value,expiredays)
{
var exdate=new Date()
exdate.setDate(exdate.getDate()+expiredays)
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString())
}
document.getCookie=function(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=")
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1 
    c_end=document.cookie.indexOf(";",c_start)
    if (c_end==-1) c_end=document.cookie.length
    return unescape(document.cookie.substring(c_start,c_end))
    } 
  }
return ""
}
function getLeft(e){
	var offset=e.offsetLeft;
	if(e.offsetParent!=null)
		offset+=getLeft(e.offsetParent);
	return offset;
}
function getTop(e){
	var offset=e.offsetTop;
	if(e.offsetParent!=null)
		offset+=getTop(e.offsetParent);
	return offset;
}
