//动态设置iframe高度
var getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1]
//extra height in px to add to iframe in FireFox 1.0+ browsers
var FFextraHeight=getFFVersion>=0.1? 16 : 0 

function dyniframesize(iframename) {
  var pTar = null;
  if (document.getElementById){
    pTar = document.getElementById(iframename);
  }
  else{
    eval('pTar = ' + iframename + ';');
  }
  if (pTar && !window.opera){
    //begin resizing iframe
    pTar.style.display="block"
    
    if (pTar.contentDocument && pTar.contentDocument.body.offsetHeight){
      //ns6 syntax
      pTar.height = pTar.contentDocument.body.offsetHeight+FFextraHeight; 
    }
    else if (pTar.Document && pTar.Document.body.scrollHeight){
      //ie5+ syntax
      pTar.height = pTar.Document.body.scrollHeight;
    }
  }
}

//调查申请验证
function isValid(form)
{
	if(form.name.value == "")
	{
		alert("请输入您的姓名！");
		form.name.focus();
		return false;
	}
	else if(form.phone.value == "")
	{
		alert("请输入您的电话！");
		form.phone.focus();
		return false;
	}
	else if(form.address.value == "")
	{
		alert("请输入您的通信地址！");
		form.address.focus();
		return false;
	}
	else if(form.title.value == "")
	{
		alert("请输入理由！");
		form.title.focus();
		return false;
	}
	else if(form.content.value == "")
	{
		alert("请输入内容！");
		form.content.focus();
		return false;
	}
	else
	{
		return true;
	}
}

//删除前后空格
function LTrim(s)
{
	for(var i=0;i<s.length;i++)
		if(s.charAt(i)!=' ')
		 return s.substring(i,s.length);
	 return "";
}
function RTrim(s)
{
	for(var i=s.length-1;i>=0;i--)
		if(s.charAt(i)!=' ')
			return s.substring(0,i+1);
		return "";
}
function Trim(s)
{
	return RTrim(LTrim(s));
}

//显示导航
function createPageHTML(_nPageCount, _nCurrIndex, _sPageName, _sPageExt)
{
	if(_nPageCount == null || _nPageCount<=1){
		return;
	}

	var nCurrIndex = _nCurrIndex || 0;
	if(nCurrIndex == 0)
	{
		document.write("首页 | ");
		document.write("上一页 ");

		document.write("1&nbsp;");

		if(_nPageCount > 1)
		{
			for(var i=1; i<_nPageCount; i++){
			if(nCurrIndex == i)
				document.write((i+1) + "&nbsp;");
				else
				document.write("<a href=\""+_sPageName+"_" + i + "."+_sPageExt+"\">"+(i+1)+"</a>&nbsp;");
			}

			document.write("<a class=\"fy12\" href=\""+_sPageName+"_" + (nCurrIndex+1) + "."+_sPageExt+"\">下一页</a> | ");
			document.write("<a class=\"fy12\" href=\""+_sPageName+"_" + (_nPageCount-1) + "."+_sPageExt+"\">尾页</a>");
		}
		else
		{
			document.write("下一页 | ");
			document.write("尾页");
		}
	}
	else if(nCurrIndex == _nPageCount-1)
	{
		document.write("<a class=\"fy12\" href=\""+_sPageName+"."+_sPageExt+"\">首页</a> | ");
		if(nCurrIndex > 1)
		{
			document.write("<a class=\"fy12\" href=\""+_sPageName+"_" + (nCurrIndex-1) + "."+_sPageExt+"\">上一页</a> | ");
			document.write("<a href=\""+_sPageName+"."+_sPageExt+"\">1</a>&nbsp;");

		}
		else
		{
			document.write("<a class=\"fy12\" href=\""+_sPageName+"."+_sPageExt+"\">上一页</a> | ");
		}
		for(var i=1; i<_nPageCount; i++){
			if(nCurrIndex == i)
				document.write((i+1) + "&nbsp;");
				else
				document.write("<a href=\""+_sPageName+"_" + i + "."+_sPageExt+"\">"+(i+1)+"</a>&nbsp;");
			}
		document.write("下一页 | ");
		document.write("尾页");
		
	}
	else
	{
		document.write("<a class=\"fy12\" href=\""+_sPageName+"."+_sPageExt+"\">首页</a> | ");
		if(nCurrIndex == 1)
		{
			document.write("<a class=\"fy12\" href=\""+_sPageName+ "."+_sPageExt+"\">上一页</a> | ");
			document.write("<a href=\""+_sPageName+"."+_sPageExt+"\">1</a>&nbsp;");
		}
		else
		{
			document.write("<a class=\"fy12\" href=\""+_sPageName+"_" + (nCurrIndex-1) + "."+_sPageExt+"\">上一页</a> | ");
			document.write("<a href=\""+_sPageName+"."+_sPageExt+"\">1</a>&nbsp;");
		}

		for(var i=1; i<_nPageCount; i++){
			if(nCurrIndex == i)
				document.write((i+1) + "&nbsp;");
				else
				document.write("<a href=\""+_sPageName+"_" + i + "."+_sPageExt+"\">"+(i+1)+"</a>&nbsp;");
			}

		if(nCurrIndex == _nPageCount-1)
		{
			document.write("<a class=\"fy12\" href=\""+_sPageName+"_" + (_nPageCount-1) + "."+_sPageExt+"\">下一页</a> | ");
		}
		else
		{
			document.write("<a class=\"fy12\" href=\""+_sPageName+"_" + (nCurrIndex+1) + "."+_sPageExt+"\">下一页</a> | ");
		}
		document.write("<a class=\"fy12\" href=\""+_sPageName+"_" + (_nPageCount-1) + "."+_sPageExt+"\">尾页</a>");
	}
	
}

//===============goto()直接跳转函数=============================================
function goto(_nPageCount, _nCurrIndex, _sPageName, _sPageExt)
{
	var page = document.getElementById("CP").value;
	if(isNaN(page))
	{
		alert("请输入正确的页码！");
	}
	else
	{
		var pagenum = parseInt(page, 10);
		if(pagenum < 1 || pagenum > _nPageCount) 
		{
			alert("请输入正确的页码！");
		}
		else
		{
			if(pagenum == 1)
				document.location.href = _sPageName+"."+_sPageExt;
			else
				document.location.href = _sPageName+"_" + (pagenum-1) +"."+_sPageExt;
		}
	}
}

//设置页码
function setPagenum(_nCurrIndex)
{
	var nCurrIndex = _nCurrIndex || 0;
	document.getElementById("CP").value = _nCurrIndex + 1;
}

//设置颜色
function changeChnlFont(_chnlnames)
{
	var aryChnl = _chnlnames.split(";");
	for(var i=1; i<aryChnl.length; i++)
	{
		
		if(document.getElementById("T"+aryChnl[i]) != null)
		{
			document.getElementById("T"+aryChnl[i]).innerHTML = "<font color=\"#FA5505\"><strong>" + document.getElementById("T"+aryChnl[i]).innerHTML + "</strong></font>";
		}
		else if(document.getElementById(aryChnl[i]) != null)
		{
			//alert(document.getElementById(aryChnl[i]).innerHTML);
			document.getElementById(aryChnl[i]).innerHTML = "<font color=\"#ffff66\">" + document.getElementById(aryChnl[i]).innerHTML + "</font>";
		}
	}
}

//设置颜色
function changeFont(_ChannelID)
{
	document.getElementById(_ChannelID).className = "li";
}

//隐藏频道名
function hideChannel(_ChannelID)
{
	document.getElementById(_ChannelID).style.display = "none";
}

//输出序号
function writeIndex(_index, _url, _pagesize)
{
	var pagenum = 0;
	if(_url.indexOf("_") > 0)
	{
		pagenum = parseInt(_url.substring(_url.indexOf("_") + 1));
	}

	_index = pagenum * _pagesize + _index;

	var sIndex = "" + _index;
	while(sIndex.length <= 4)
	{
		sIndex = "0" + sIndex;
	}

	document.write(sIndex);
}

//如果doctitle2不为空，则输出doctitle2，否则输出doctitle
function writeTitle(_url, _docpeople, _doctitle, _class, _titlecolor, _orgdocpeople, _orgdoctitle)
{
	document.write("<a href=\"" + _url + "\" target=\"_blank\"");
	//输出css
	if(_class != null && _class != "")
	{
		document.write(" class=\"" + _class + "\"");
	}
	
	//输出链接title
	if(_orgdocpeople != null && _orgdocpeople != "")
	{
		document.write(" title=\"" + _orgdocpeople + "\"");
	}
	else if(_orgdocpeople != null && _orgdocpeople != "")
	{
		document.write(" title=\"" + _orgdocpeople + "\"");
	}

	document.write(">");
	
	//输出标题颜色
	if(_titlecolor != null && _titlecolor != "")
	{
		document.write("<font color=\"" + _titlecolor + "\">");
	}

	//输出标题
	if(_docpeople != null && _docpeople != "")
	{
		document.write(_docpeople);
	}
	else
	{
		document.write(_doctitle);
	}
	//输出标题颜色
	if(_titlecolor != null && _titlecolor != "")
	{
		document.write("</font>");
	}
	document.write("</a>");
}

//检索
/*
function setSearchword(form)
{
	//检索词
	var keyword = Trim(form.keyword.value);
	if(keyword == "")
	{
		alert("请输入检索词！");
		return false;
	}
	else if(keyword.indexOf("'") >= 0)
	{
		alert("检索词中不能含有单银号“'”！");
		return false;
	}
	
	//字段
	if(form.searchfield != null)
	{
		var field = form.searchfield.value;
		if(field == "")
		{
			keyword = "DOCAUTHOR='%" + keyword + "%' OR DOCTITLE='" + keyword + "' OR DOCCONTENT='" + keyword + "'";
		}
		else if(field == "DOCAUTHOR")
		{
			keyword = field + "='%" + keyword + "%'";
		}
		else
		{
			keyword = field + "='" + keyword + "'";
		}
	}
	
	//数据库
	var aryDb = document.getElementsByName("searchdb");
	var mydb="";
	if(aryDb != null)
	{
		for(var i=0; i<aryDb.length; i++)
		{
			if(aryDb[i] != null && aryDb[i].checked)
				{ //alert(aryDb[i].value);
				  mydb=mydb+aryDb[i].value+",";
				}
			
		}
	}
  
    if( mydb.length==0)
		mydb="75007";
	else
		mydb=mydb.substring(0,mydb.length-1);
    
	//频道
	if(form.chnlname != null)
	{
		keyword = keyword + " and chnlname='" + form.chnlname.value + "'";
	}

	form.searchword.value = keyword;
	form.action="/cnss/searchcnss.jsp?channelid="+mydb;
	//alert(keyword);
	return true;
}
*/

//社科院检索,默认检索作者，标题，正文，需要别的内容可以在keyword里添加
function setSearchword(form)
{
	var keyword = Trim(form.keyword.value);
	if(keyword == "")
	{
		alert("请输入检索词！");
		return false;
	}
	else if(keyword.indexOf("'") >= 0)
	{
		alert("检索词中不能含有单银号“'”！");
		return false;
	}
	if(form.searchfield != null)
	{
		var field = form.searchfield.value;
		if(field == "")
		{
			keyword = "DOCAUTHOR='%" + keyword + "%' OR DOCTITLE='" + keyword + "' OR DOCCONTENT='" + keyword + "' OR DOCKEYWORDS='%" + keyword + "%'";
		}
		else if(field == "DOCAUTHOR")
		{
			keyword = field + "='%" + keyword + "%'";
		}
		else
		{
			keyword = field + "='" + keyword + "'";
		}
	}
	form.searchword.value = keyword;
	//alert(keyword);
	return true;
}


//设置热点关键词
function changeHotword(obj)
{
	if(obj != null && obj.value != "")
	{
		document.searchform.keyword.value = obj.value;
	}
}
//高级检索

//普通检索
function setSearchword_gj(form)
{
	var keyword = form.keyword.value;
	//普通检索
	if(keyword == "" && form.doccontent.value=="" && form.docauthor.value=="" && form.docabstract.value=="" && form.abstracten.value=="")
	{
		alert("请输入检索词！")
		return false;
	}
	//高级检索
	if(form.Relation != null)
	{
		var sRel = form.Relation.value;
		sRel="and";
		//标题
		if(keyword != "")
		{
			keyword = "DOCTITLE='" + keyword + "'";
		}
		//正文
		if(form.doccontent != null && form.doccontent.value != "")
		{
			if(keyword != "") keyword = keyword + " " + sRel + " ";
			keyword = keyword + "DOCCONTENT='" + form.doccontent.value + "'";
		}
		//作者
		if(form.docauthor != null && form.docauthor.value != "")
		{
			if(keyword != "") keyword = keyword + " " + sRel + " ";
			keyword = keyword + "DOCAUTHOR='%" + form.docauthor.value + "%'";
		}
		//时间
		if(form.docreltime != null && form.docreltime.value != "")
		{
			var a=form.docreltime.value.split(".");
			if(a[0]=="" || a[1]=="" || a[2]==""){
				alert("请选择完整时间！");
				return false;
			}
				keyword = keyword + " " + sRel + " ";
				keyword = keyword + "DOCRELTIME>='" + form.docreltime.value + "'";
		}
		if(form.docreltime1 != null && form.docreltime1.value != "")
		{
			var a=form.docreltime1.value.split(".");
			if(a[0]=="" || a[1]=="" || a[2]==""){
				alert("请选择完整时间！");
				return false;
			}
				keyword = keyword + " " + sRel + " ";
				keyword = keyword + "DOCRELTIME<='" + form.docreltime1.value + "'";

		}
		
		//中文摘要
		if(form.docabstract != null && form.docabstract.value != "")
		{
			if(keyword != "") keyword = keyword + " " + sRel + " ";
			keyword = keyword + "DOCABSTRACT='" + form.docabstract.value + "'";
		}
		//英文摘要
		if(form.abstracten != null && form.abstracten.value != "")
		{
			if(keyword != "") keyword = keyword + " " + sRel + " ";
			keyword = keyword + "ABSTRACTEN='" + form.abstracten.value + "'";
		}

		//中文摘要
		if(form.guanjianci != null && form.guanjianci.value != "")
		{
			if(keyword != "") keyword = keyword + " " + sRel + " ";
			keyword = keyword + "DOCKEYWORDS='%" + form.guanjianci.value + "%'";
		}


	}

	
	/*
	if(form.secondsearch != null)
	{
		if(form.searchword.value != "" && form.secondsearch.checked)
		{
			keyword = keyword + " and " + form.searchword.value;
		}
	}
	
	if(form.chnlname != null && form.chnlname != "")
	{
		if(keyword.indexOf("DOCTITLE"))
		keyword = "DOCTITLE='" + keyword + "' and (CHNLNAME='" + form.chnlname.value + "')";
	}
		*/
	form.searchword.value = keyword;
	//alert(keyword);
	//alert(document.getElementById('searchword').value);
	return true;
}

function sendRecommend(form) 
{
	var str0,str1,str2,str3,str4,str;


	if (!validEmail(form.friendEmail.value))
	{
		alert(' 朋友的Email可能打错了或为空的！');
		return false;
	}

	var sInfo = "◆◆◆中国社会保障网新闻◆◆◆\n";
	sInfo += "您好!\n";
	sInfo += "您的朋友向您推荐中国社会保障网新闻:\n";
	sInfo += "“" + form.title.value + "”\n";
	sInfo += "链接网址是：\n" + this.location;
	form.Subject.value = "推荐新闻";
	form.Context.value = sInfo;
	form.action="mailto:" + form.friendEmail.value;
	
	return true;
}

function validEmail(_email) 
{

  if (_email == "" || (_email.indexOf ('@') == -1) || (_email.indexOf ('.') == -1))
      return false;
  return true;
}

function setAppendix() 
{
	if(document.getElementById("idappendix") != null && document.getElementById("idappendix").innerHTML != "")
	{
		document.getElementById("idappendixdesc").style.display = "block";
		document.getElementById("idappendixlist").style.display = "block";
	}
}

//时间联动菜单(20080805 by darksx)
function DateSelector(selYear, selMonth, selDay)
{
    this.selYear = selYear;
    this.selMonth = selMonth;
    this.selDay = selDay;
    this.selYear.Group = this;
    this.selMonth.Group = this;
	this.selDay.Group = this;
    // 给年份、月份下拉菜单添加处理onchange事件的函数
    if(window.document.all != null) // IE
    {
        this.selYear.attachEvent("onchange", DateSelector.Onchange);
        this.selMonth.attachEvent("onchange", DateSelector.Onchange);	
		this.selDay.attachEvent("onchange", DateSelector.Onchange1);	
    }
    else // Firefox
    {
        this.selYear.addEventListener("change", DateSelector.Onchange, false);
        this.selMonth.addEventListener("change", DateSelector.Onchange, false);
    }

    if(arguments.length == 4) // 如果传入参数个数为4，最后一个参数必须为Date对象
        this.InitSelector(arguments[3].getFullYear(), arguments[3].getMonth() + 1, arguments[3].getDate());
    else if(arguments.length == 6) // 如果传入参数个数为6，最后三个参数必须为初始的年月日数值
        this.InitSelector(arguments[3], arguments[4], arguments[5]);
    else // 默认使用当前日期
    {
        var dt = new Date();
        this.InitSelector(dt.getFullYear(), dt.getMonth() + 1, dt.getDate());
    }
}
// 增加一个最大年份的属性
DateSelector.prototype.MinYear = 1970;

// 增加一个最大年份的属性
DateSelector.prototype.MaxYear = (new Date()).getFullYear();

// 初始化年份
DateSelector.prototype.InitYearSelect = function()
{
	//创建option元素，默认为空
	var op = window.document.createElement("OPTION");
	op.value="";
	op.innerHTML="";
	this.selYear.appendChild(op);
    // 循环添加OPION元素到年份select对象中
    for(var i = this.MaxYear; i >= this.MinYear; i--)
    {
        // 新建一个OPTION对象
        op = window.document.createElement("OPTION");
        
        // 设置OPTION对象的值
        op.value = i;
        
        // 设置OPTION对象的内容
        op.innerHTML = i;
        
        // 添加到年份select对象
        this.selYear.appendChild(op);
    }
}

// 初始化月份
DateSelector.prototype.InitMonthSelect = function()
{
	var op = window.document.createElement("OPTION");
	op.value="";
	op.innerHTML="";
	this.selMonth.appendChild(op);
    // 循环添加OPION元素到月份select对象中
    for(var i = 1; i < 13; i++)
    {
        // 新建一个OPTION对象
        op = window.document.createElement("OPTION");
        
        // 设置OPTION对象的值
        op.value = i;
        
        // 设置OPTION对象的内容
        op.innerHTML = i;
        
        // 添加到月份select对象
        this.selMonth.appendChild(op);
    }
}

// 根据年份与月份获取当月的天数
DateSelector.DaysInMonth = function(year, month)
{
    var date = new Date(year, month, 0);
    return date.getDate();
}

// 初始化天数
DateSelector.prototype.InitDaySelect = function()
{
    // 使用parseInt函数获取当前的年份和月份
    var year = parseInt(this.selYear.value);
    var month = parseInt(this.selMonth.value);
    
    // 获取当月的天数
    var daysInMonth = DateSelector.DaysInMonth(year, month);
    
    // 清空原有的选项
    this.selDay.options.length = 0;
	var op = window.document.createElement("OPTION");
	op.value="";
	op.innerHTML="";
	this.selDay.appendChild(op);
    // 循环添加OPION元素到天数select对象中
    for(var i = 1; i <= daysInMonth ; i++)
    {
        // 新建一个OPTION对象
        op = window.document.createElement("OPTION");
        
        // 设置OPTION对象的值
        op.value = i;
        
        // 设置OPTION对象的内容
        op.innerHTML = i;
        
        // 添加到天数select对象
        this.selDay.appendChild(op);
    }
}

// 处理年份和月份onchange事件的方法，它获取事件来源对象（即selYear或selMonth）
// 并调用它的Group对象（即DateSelector实例，请见构造函数）提供的InitDaySelect方法重新初始化天数
// 参数e为event对象
DateSelector.Onchange = function(e)
{
    var selector = window.document.all != null ? e.srcElement : e.target;
    selector.Group.InitDaySelect();
	var year=document.getElementById("selYear").value;
	var month=document.getElementById("selMonth").value;
	var day=document.getElementById("selDay").value;
	var d=year+"."+month+"."+day;
	document.getElementById("docreltime").value=d;
	var year1=document.getElementById("selYear1").value;
	var month1=document.getElementById("selMonth1").value;
	var day1=document.getElementById("selDay1").value;
	var d1=year1+"."+month1+"."+day1;
	document.getElementById("docreltime1").value=d1;
	//alert(d);
	//alert(d1);
	//alert(document.getElementById('docreltime').value);
	///alert(document.getElementById('selYear').value);
	//alert(document.getElementById('selMonth').value);
	//alert(document.getElementById('selDay').value);
}

//处理只选择日期，未选择年月的情况
DateSelector.Onchange1 = function(e)
{
	var year=document.getElementById("selYear").value;
	var month=document.getElementById("selMonth").value;
	var day=document.getElementById("selDay").value;
	var d=year+"."+month+"."+day;
	document.getElementById("docreltime").value=d;
	var year1=document.getElementById("selYear1").value;
	var month1=document.getElementById("selMonth1").value;
	var day1=document.getElementById("selDay1").value;
	var d1=year1+"."+month1+"."+day1;
	document.getElementById("docreltime1").value=d1;
	//alert(d);
	//alert(d1);
	//alert(document.getElementById('docreltime').value);
	///alert(document.getElementById('selYear').value);
	//alert(document.getElementById('selMonth').value);
	//alert(document.getElementById('selDay').value);
}

// 根据参数初始化下拉菜单选项
DateSelector.prototype.InitSelector = function(year, month, day)
{
    // 由于外部是可以调用这个方法，因此我们在这里也要将selYear和selMonth的选项清空掉
    // 另外因为InitDaySelect方法已经有清空天数下拉菜单，因此这里就不用重复工作了
    this.selYear.options.length = 0;
    this.selMonth.options.length = 0;
    
    // 初始化年、月
    this.InitYearSelect();
    this.InitMonthSelect();
    
    // 设置年、月初始值
    this.selYear.selectedIndex =0;//this.MaxYear - year;
    this.selMonth.selectedIndex =0;// month - 1;
    
    // 初始化天数
    this.InitDaySelect();
    
    // 设置天数初始值
    this.selDay.selectedIndex = 0;//day - 1;
}

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
