var xmlHttpdec;
var golbaldivname;
//定义XMLHttpRequest对象实例
var http_request = false;

function qryNewByDBID (goclid,dbid,dbval){
  if(document.getElementById(dbid)) {
   document.getElementById(dbid).value  = dbval;
   goSearch('gernalsearch','../'+goclid+'/search.html?sort=true&sortId=CONTENT_TIME&columnid=CPUB|'+dbid+'&relation=MUST|MUST',document.getElementById('classStr').value,'Region',2,2,'CPUB|'+dbid,document.getElementById('CPUB').value+'|' + document.getElementById(dbid).value,document.getElementById('curpage').value)
  }
}
//-----------------政务公开----------------------

function qryNewByMultCLID2 (multclid,clname){
  
  //表示已经选择了栏目
  //alert(clname);
  if (multclid != "-1" || multclid != -1) {
    document.getElementById('CLID').value = multclid;
    //如果已经选择了栏目，则清空输入诓里面的内容
    document.getElementById('options_value10').value = "";
    document.getElementById('CTITLE').value = "";
    document.getElementById('STARTTIME').value = "";
    document.getElementById('ENDTIME').value = "";
  }
  
  if (clname != "-1" || clname != -1) {
    document.getElementById('CLNAME').value = clname;
  }
  if (multclid == "-1" || multclid == -1) {
    //如果栏目号传过来的是－1，则表示是按钮提交的，要获取隐藏表单的数据
    multclid = document.getElementById('CLID').value; 
    //alert("2==="+document.getElementById('CLID').value);
  }
  if (clname == "-1" || clname == -1) {
    //如果栏目名称传过来的是－1，则表示是按钮提交的，要获取隐藏表单的数据
    clname = document.getElementById('CLNAME').value;
  }	
  //alert(multclid + "====" +clname);
  //先把div的栏目名称换掉
  //alert(document.getElementById('CLNAME'));
  if (document.getElementById('CLNAME')) {
    document.getElementById('CLNAME').innerHTML = clname;
  }
  //alert(qryNewByMultCLID);
  var qryidstr="CLID|OPTIONS_VALUE10|CTITLE|CTIME2";
  var relation='MUST|MUST|MUST|MUST';
  var qryvalue='';
 // if(document.getElementById('CLID')) {
   document.getElementById('CLID').value  = multclid;
   qryvalue += multclid;//栏目号
   
  //}
  qryvalue += "|"+document.getElementById('options_value10').value;//索引号
  
  qryvalue += "|"+document.getElementById('CTITLE').value;//标题
  
  var starttime;
  var endtime;
  //alert(document.getElementById('STARTTIME').value);
  if(document.getElementById('STARTTIME').value == null || document.getElementById('STARTTIME').value  == ""){
    starttime = 'null';
  }
  else {
    starttime = document.getElementById('STARTTIME').value;
  }
  
  if(document.getElementById('ENDTIME').value == null || document.getElementById('ENDTIME').value  == ""){
    endtime = 'null';
  }
  else {
    endtime = document.getElementById('ENDTIME').value;
  }
  
  //alert("ctime=="+document.getElementById('CTIME2'));
  document.getElementById('CTIME2').value = starttime + "," + endtime;
  qryvalue += "|"+starttime + "," + endtime;//开始结束时间
 

  goSearch3('gernalsearch','../CL0001/search.html?sort=true&sortId=CONTENT_TIME&columnid='+qryidstr+'&relation='+relation,document.getElementById('classStr').value,'Region',4,4,qryidstr,qryvalue,document.getElementById('curpage').value)

}


function goSearch3 (divname,mylocation,classStr,tableName,colNum,qryNum,qryidstr,qryvalue,curpage) {
//alert("");
  //if (document.getElementById(searchvalid)) {
    //查询值
    //mylocation += "&qryValue=" + document.getElementById(searchvalid).value
  //}
  //alert(mylocation);
  //mylocation = mylocation + "&classStr=" + classStr;
  mylocation = mylocation + "&tableName=" + tableName;//alert(encodeURI(tableName));
  mylocation = mylocation + "&colNum=" + colNum;
  mylocation = mylocation + "&qryNum=" + qryNum;
  //当前页
  mylocation = mylocation + "&curPage=" + curpage;
  mylocation = mylocation + "&qryidstr=" + qryidstr
  mylocation = mylocation + "&qryValue=" + qryvalue;

if (document.getElementById("record")) {
  mylocation += "&record=" + document.getElementById("record").value;}
if (document.getElementById("mytarget")) {
  mylocation += "&mytarget=" + document.getElementById("mytarget").value;}
if (document.getElementById("dateFormat")) {
  mylocation += "&dateFormat=" + document.getElementById("dateFormat").value;}
if (document.getElementById("titleLength")) {
  mylocation += "&titleLength=" + document.getElementById("titleLength").value;}
if (document.getElementById("subTitleFlag")) {
  mylocation += "&subTitleFlag=" + document.getElementById("subTitleFlag").value;}
if (document.getElementById("classStr")) {
mylocation += "&classStr=" + document.getElementById("classStr").value;}
mylocation += "&gelqryType=2";
//alert(mylocation);
mylocation = unescape(mylocation);

decAJAX("gernalsearch",mylocation);
  //decAJAX(divname,mylocation);
}
//---------------政务公开---------------

//-----------------政务公开----------------------

function qryNewByMultCLID (multclid,clname){
  
  //表示已经选择了栏目
  //alert(multclid);
  if (multclid != "-1" || multclid != -1) {
    document.getElementById('CLID').value = multclid;
    //如果已经选择了栏目，则清空输入诓里面的内容
    document.getElementById('options_value10').value = "";
    document.getElementById('CTITLE').value = "";
    document.getElementById('STARTTIME').value = "";
    document.getElementById('ENDTIME').value = "";
  }
  if (clname != "-1" || clname != -1) {
    document.getElementById('CLNAME').value = clname;
  }
  if (multclid == "-1" || multclid == -1) {
    //如果栏目号传过来的是－1，则表示是按钮提交的，要获取隐藏表单的数据
    multclid = document.getElementById('CLID').value;
    //alert("2==="+document.getElementById('CLID').value);
  }
  if (clname == "-1" || clname == -1) {
    //如果栏目名称传过来的是－1，则表示是按钮提交的，要获取隐藏表单的数据
    clname = document.getElementById('CLNAME').value;
  }	
  //alert(multclid + "====" +clname);
  //先把div的栏目名称换掉
  //alert(document.getElementById('CLNAME'));
  if (document.getElementById('CLNAME')) {
    document.getElementById('CLNAME').innerHTML = clname;
  }
  //alert(qryNewByMultCLID);
  var qryidstr="CLID|OPTIONS_VALUE10|CTITLE|CTIME2";
  var relation='MUST|MUST|MUST|MUST';
  var qryvalue='';
 // if(document.getElementById('CLID')) {
   document.getElementById('CLID').value  = multclid;
   qryvalue += multclid;//栏目号
   
  //}
  qryvalue += "|"+document.getElementById('options_value10').value;//索引号
  
  qryvalue += "|"+document.getElementById('CTITLE').value;//标题
  
  var starttime;
  var endtime;
  //alert(document.getElementById('STARTTIME').value);
  if(document.getElementById('STARTTIME').value == null || document.getElementById('STARTTIME').value  == ""){
    starttime = 'null';
  }
  else {
    starttime = document.getElementById('STARTTIME').value;
  }
  if(document.getElementById('ENDTIME').value == null || document.getElementById('ENDTIME').value  == ""){
    endtime = 'null';
  }
  else {
    endtime = document.getElementById('ENDTIME').value;
  }
  //alert("ctime=="+document.getElementById('CTIME2'));
  document.getElementById('CTIME2').value = starttime + "," + endtime;
  qryvalue += "|"+starttime + "," + endtime;//开始结束时间
//alert(qryvalue);

  goSearch2('gernalsearch','../CL0001/search.html?sort=true&sortId=CTIME&columnid='+qryidstr+'&relation='+relation,document.getElementById('classStr').value,'Region',4,4,qryidstr,qryvalue,document.getElementById('curpage').value)

}


function goSearch2 (divname,mylocation,classStr,tableName,colNum,qryNum,qryidstr,qryvalue,curpage) {
//alert("");
  //if (document.getElementById(searchvalid)) {
    //查询值
    //mylocation += "&qryValue=" + document.getElementById(searchvalid).value
  //}
  //alert(mylocation);
  //mylocation = mylocation + "&classStr=" + classStr;
  mylocation = mylocation + "&tableName=" + tableName;//alert(encodeURI(tableName));
  mylocation = mylocation + "&colNum=" + colNum;
  mylocation = mylocation + "&qryNum=" + qryNum;
  //当前页
  mylocation = mylocation + "&curPage=" + curpage;
  mylocation = mylocation + "&qryidstr=" + qryidstr
  mylocation = mylocation + "&qryValue=" + qryvalue;

if (document.getElementById("record")) {
  mylocation += "&record=" + document.getElementById("record").value;}
if (document.getElementById("mytarget")) {
  mylocation += "&mytarget=" + document.getElementById("mytarget").value;}
if (document.getElementById("dateFormat")) {
  mylocation += "&dateFormat=" + document.getElementById("dateFormat").value;}
if (document.getElementById("titleLength")) {
  mylocation += "&titleLength=" + document.getElementById("titleLength").value;}
if (document.getElementById("subTitleFlag")) {
  mylocation += "&subTitleFlag=" + document.getElementById("subTitleFlag").value;}
if (document.getElementById("classStr")) {
mylocation += "&classStr=" + document.getElementById("classStr").value;}
mylocation += "&gelqryType=1";
//alert(mylocation);
mylocation = unescape(mylocation);

decAJAX("gernalsearch",mylocation);
  //decAJAX(divname,mylocation);
}
//---------------政务公开---------------
function qryNewByDBIDCLID (goclid,dbid,dbval){
  if(document.getElementById(dbid)) {
   document.getElementById(dbid).value  = dbval;
   goSearch('gernalsearch','../'+goclid+'/search.html?sort=true&sortId=CTIME&columnid=CLID|'+dbid+'&relation=MUST|MUST',document.getElementById('classStr').value,'Region',2,2,'CLID|'+dbid,document.getElementById('CLID').value+'|' + document.getElementById(dbid).value,document.getElementById('curpage').value)
  }
}
function test() {
  if (http_request.readyState == 4) { // 判断对象状态
  	//alert(http_request.status);
    if (http_request.status == 200) { // 信息已经成功返回，开始处理信息
      //returnstr = http_request.responseText;
      //alert(http_request.responseText);
      var obj = document.getElementById(golbaldivname);
      if (obj) {
        obj.innerHTML = http_request.responseText;
      }
    } 
    else { //页面不正常
      alert("您所请求的页面有异常。");
    }
  }
}
function setindexname(searchfields,relation){alert("dd");
  form123.searchField.value=searchfields;
  form123.relation.value=relation;
}
function setTextInput(temp) {//alert("temp==============="+temp)
  var index = temp.indexOf("qryidstr");
  if (index != -1) {
    var qryidStr = temp.substring(index+9); 
    index = qryidStr.indexOf("&");
    qryidStr = qryidStr.substring(0,index);
    //alert("id = " + qryidStr.indexOf("CPUB"));
    var qryidAry = qryidStr.split("|");
  
    index = temp.indexOf("qryValue");
    if (index != -1) {
      var qryvalStr = temp.substring(index+9); 
      index = qryvalStr.indexOf("&");
      qryvalStr = qryvalStr.substring(0,index);
      //alert("iddd = " + qryvalStr);
      var qryvalAry = qryvalStr.split("|");
      //alert("qryvalAry="+qryvalAry.length);
      for (var i=0;i<qryidAry.length;i++) {
        var idstr = qryidAry[i];
        //alert("idstr="+idstr);
        //alert(document.getElementById("keywordwbpp").value);
        if (document.getElementById(idstr)) {
          //if(document.getElementById(idstr).type == "text"){
            document.getElementById(idstr).value = qryvalAry[i];
          //}
        }

         if (qryidStr.indexOf("CPUB") == -1 && document.getElementById("form123") &&  document.getElementById("form123").keywordwbpp) {
           //document.getElementsById("keywordwbpp").value = "dasdfasdf";//
           form123.keywordwbpp.value=qryvalAry[i];

          }
      }
    }
  }
}
function setindexname(temp2){
	 if (temp2 != null && temp2 != '' && temp2 != '-1') {
	   document.getElementById('radioval').value = temp2;
            //alert( document.getElementById('eventSubmit_doSearch').name);
            //document.getElementById('eventSubmit_doSearch').name='CONTENT';
           //alert( document.getElementById('eventSubmit_doSearch').name);
	  // return true;
	 }
	else {
        var temp = document.getElementById('radioval').value;
        
	 var temp1 = temp.split(',');
	searchfields = temp1[0];
         relation = temp1[1];
		var fields = searchfields.split('|');
		var value = form123.keywordwbpp.value;

		form123.searchField.value=searchfields;
		form123.relation.value=relation;
		
		if(fields.length==2){
		  form123.searchWord.value= value + '|' + value;
		  goSearch('gernalsearch','../CL0393/search.html?columnid='+document.getElementById('searchField').value+'&amp;relation='+relation,document.getElementById('classStr').value,'Region',2,2,form123.searchField.value,document.getElementById('searchWord').value,document.getElementById('curpage').value)
		  return true;
		}else{
		  form123.searchWord.value= value;	
		}
            //alert(fields);
            //alert(value);
            //alert(form123.searchWord.value);
            goSearch('gernalsearch','../CL0393/search.html?columnid='+document.getElementById('searchField').value+'&amp;relation='+relation,document.getElementById('classStr').value,'Region',1,1,form123.searchField.value,document.getElementById('searchWord').value,document.getElementById('curpage').value)
}}

function goSearch (divname,mylocation,classStr,tableName,colNum,qryNum,qryidstr,qryvalue,curpage) {
 //alert("");
  //if (document.getElementById(searchvalid)) {
    //查询值
    //mylocation += "&qryValue=" + document.getElementById(searchvalid).value
  //}
  //alert(mylocation);
  //mylocation = mylocation + "&classStr=" + classStr;
  mylocation = mylocation + "&tableName=" + tableName;//alert(encodeURI(tableName));
  mylocation = mylocation + "&colNum=" + colNum;
  mylocation = mylocation + "&qryNum=" + qryNum;
  //当前页
  mylocation = mylocation + "&curPage=" + curpage;
  mylocation = mylocation + "&qryidstr=" + qryidstr
  mylocation = mylocation + "&qryValue=" + qryvalue;
  //alert(mylocation);
  //alert("222" + escape(mylocation));
  this.location = mylocation;
  //window.open(mylocation);
  //mylocation = escape(mylocation);
  //decAJAX(divname,mylocation);
}
//-------------------------------文章评论--------------------------------------------------
function goSearch4 (con_id,record,classStr,dateFormat,curpage) {
	 var temp = "?&con_id=" + con_id ;
     temp += "&curPage=" + curpage;
     temp += "&record=" + record;
	 temp += "&classStr=" + classStr;
	 temp += "&dateFormat=" + dateFormat;
     var URL="/wbpp/compage" + temp; 
     golbaldivname = "com_list";
     send_request("get",URL,"com_list");
}
//禁止输入空格
function  checkN()   { 
   if(event.keyCode   ==   32)  {
                 event.returnValue   =   false;   
                 alert("昵称不允许包含空格！");
				 //输入时去掉空格
        }
  } 
 //格式判断字母数字下划线
function   checkName(str)   {   
  var   newPar=/^[a-z](?!\w*\_{2,})\w{2,14}[^\W_]$/i;  
  return newPar.test(str);
  }  
//过滤<>标记
function Del(Word) {
   var a = Word.indexOf("<");
   var b = Word.indexOf(">");
   var len = Word.length;
   var c = Word.substring(0, a);
  if(b == -1){
     b = a;
    }else if(a == -1){
     c = Word.substring(0,b);
    }
     d = Word.substring((b + 1), len);
   Word = c + d;

  var tagCheckA = Word.indexOf("<");
   if(tagCheckA != -1)
     Word = Del(Word);

  var tagCheckB = Word.indexOf(">");
   if(tagCheckB != -1)
     Word = Del(Word);

return Word;
}
//新增
function   String.prototype.Trim()  
  {  
  return   this.replace(/^\s*/g,"").replace(/\s*$/g,"");  
  }
function   String.Trim(str){
  return   String.Convert(str).Trim();
  }  

function comment(mylocation,con_id,person,com_opinion){
	//判断格式以及长度
	if (document.getElementById("person").value.length == 0){ 
        alert("请输入您姓名!长度在4-16之间.");
        document.getElementById("person").focus();
        return false;
     }else if(!checkName(document.getElementById("person").value)){
		alert("昵称格式不符合要求.");
		document.getElementById("person").focus();
		return false;
     }else if(document.getElementById("com_opinion").value.length > 500){
       alert("不能超过500个字符！");
       document.getElementById("com_opinion").focus();
       return false;
	   
     }else if(document.getElementById("com_opinion").value.length == 0){
		alert("请输入评论内容,注意不得超过500个字!");
       document.getElementById("com_opinion").focus();
       return false;
	 }else{
	  //去掉前后空格
	  com_opinion = com_opinion.Trim();

	 //判断是否包含HTML信息,如果存在Del处理
     var as = com_opinion.indexOf("<");
     var bs = com_opinion.indexOf(">");
     if(as != -1 || bs != -1)
    com_opinion = Del(com_opinion);
	 //替换\n为<BR>,以方便保存初始化格式
    com_opinion = com_opinion.replace(/\n/g,'<BR>'); 
	mylocation = mylocation + "&con_id=" + con_id;
	mylocation = mylocation + "&person=" + person;
	mylocation = mylocation + "&com_opinion=" + com_opinion;

	var divname ="over";
	golbaldivname = divname;
    var idx = mylocation.indexOf("comment.html");
    var temp = mylocation.substring(idx+12);
    openurl = mylocation.substring(0,idx);
    var URL="/wbpp/comInsert" + temp;
    send_request("get",URL,divname);
	alert("尊敬的用户，您的评论已提交！谢谢参与!");
	document.getElementById("person").value="";
	document.getElementById("com_opinion").value="";
	}
}

//---------------------------------------------------------------------------------------------
function decAJAX(divname,mylocation){ 
   golbaldivname = divname;
  //alert("1="+mylocation);
  //mylocation =  unescape(mylocation);//alert("2="+mylocation);
  var openurl = mylocation;
  var idx = mylocation.indexOf("search.html");
  var temp = mylocation.substring(idx+11);//alert(idx);
  openurl = mylocation.substring(0,idx);
  //alert("openurl = " + openurl);
  //window.open("search.html");
  //alert("temp=" + temp);
  setTextInput(temp);
  var URL="/wbpp/generalsearch" + temp;
   //alert(URL)
  send_request("get",URL,divname);
  
}


//定义可复用的http请求发送函数
function send_request(method,URL,divname) {//初始化、指定处理函数、发送请求的函数
  http_request = null;
  //开始初始化XMLHttpRequest对象
  if(window.XMLHttpRequest) { //Mozilla 浏览器
    http_request = new XMLHttpRequest();
    if (http_request.overrideMimeType) {//设置MiME类别
      http_request.overrideMimeType("text/xml");
    }
  }
  else if (window.ActiveXObject) { // IE浏览器
    try {
      http_request = new ActiveXObject("Msxml2.XMLHTTP");
    } 
    catch (e) {
      try {
        http_request = new ActiveXObject("Microsoft.XMLHTTP");
      } 
      catch (e) {}
    }
  }
  if (!http_request) { // 异常，创建对象实例失败
    window.alert("不能创建XMLHttpRequest对象实例.");
    return false;
  }
  var obj = document.getElementById(divname);
      if (obj) {
        obj.innerHTML = "<table width='90%'><tr><td align=center><img src=../js/loading.gif><br>数据查询中</td></tr></table>";
      }

  http_request.onreadystatechange = test;
  // 确定发送请求的方式和URL以及是否异步执行下段代码
  if(method.toLowerCase()=="get") {
	var nowTime = new Date().getTime();//获取当前时间作为随机数
	 URL += "&time="+nowTime;
    http_request.open(method, URL, true);
  }
  else if(method.toLowerCase()=="post") {
    http_request.open(method, URL, true);
    //http_request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
  }
  else {
    window.alert("http请求类别参数错误。");
    return false;
  }
  http_request.send(null);
  var returnstr="";
  
  //http_request.onreadystatechange = test; 
}

// 处理返回文本格式信息的函数
function processTextResponse() {
  //alert(http_request.readyState);
  if (http_request.readyState == 4) { // 判断对象状态
  	//alert(http_request.status);
    if (http_request.status == 200) { // 信息已经成功返回，开始处理信息
      //returnstr = http_request.responseText;
      //alert(returnstr);
    } 
    else { //页面不正常
      alert("您所请求的页面有异常。");
    }
  }
  
  
}
//处理返回的XML格式文档的函数
function processXMLResponse() {
  if (http_request.readyState == 4) { // 判断对象状态
    if (http_request.status == 200) { // 信息已经成功返回，开始处理信息
      //alert(http_request.responseXML);
      alert("XML文档响应。");
    } 
    else { //页面不正常
      alert("您所请求的页面有异常。");
    }
  }
}
