var time  = new Date(); 
var current = time.getSeconds(); 
current = 0;  
function Second30(){ 
  
  var now = new Date(); 
  if(now.getSeconds() - current > 30){ 
    current = now.getSeconds();    
    //return true; 
  } 
  else{ 
     alert("对不起！两次查询时间间隔应大于30秒");
     return ; 
  } 
} 

function doSearch()
{       var con_item_3 = document.all.item_3.value;
	var con_topicwords = document.all.topicwords.value;
   	
        var con_cgwFlDm=document.all.cgwFlDm.options[document.all.cgwFlDm.options.selectedIndex].value;
        var con_cgwFlDm_c=document.all.cgwFlDm.options[document.all.cgwFlDm.options.selectedIndex].text;
        
        var con_cgwFlDm2=document.all.cgwFlDm2.value;
        if (con_cgwFlDm2 != "") {
            con_cgwFlDm2_c=document.all.cgwFlDm2.options[document.all.cgwFlDm2.options.selectedIndex].text;
        }       
        var con_item_15_1=document.all.item_15_1.options[document.all.item_15_1.options.selectedIndex].value;
        var con_item_15_1_c=document.all.item_15_1.options[document.all.item_15_1.options.selectedIndex].text;
     

        var con_item_15_2=document.all.item_15_2.value;
        if (con_item_15_2 != "") {
            con_item_15_2_c=document.all.item_15_2.options[document.all.item_15_2.options.selectedIndex].text;
        }  

       	var con_item_124_1=document.all.item_124_1.options[document.all.item_124_1.options.selectedIndex].value; 
        var con_item_124_1_c=document.all.item_124_1.options[document.all.item_124_1.options.selectedIndex].text;

        var con_item_12=document.all.item_12.value;
        var con_startyear=document.all.startyear.options[document.all.startyear.options.selectedIndex].value;
    	var con_endyear=document.all.endyear.options[document.all.endyear.options.selectedIndex].value;

        var con_item_2 = document.all.item_2.options[document.all.item_2.options.selectedIndex].value;
        var con_item_2_c = document.all.item_2.options[document.all.item_2.options.selectedIndex].text;

        var con_source = document.all.source.options[document.all.source.options.selectedIndex].value;
        var con_source_c = document.all.source.options[document.all.source.options.selectedIndex].text;

        var con_item_16 = document.all.item_16.options[document.all.item_16.options.selectedIndex].value;
        var con_item_16_c = document.all.item_16.options[document.all.item_16.options.selectedIndex].text;

        var con_item_9=document.all.item_9.value;
        var con_cocreator=document.all.cocreator.value;

     //   var con_item_140=document.all.item_140.options[document.all.item_140.options.selectedIndex].value;
     //   var con_item_140_c=document.all.item_140.options[document.all.item_140.options.selectedIndex].text;
        
        var con_item_126=document.all.item_126_net.options[document.all.item_126_net.options.selectedIndex].value;
        var con_item_126_c=document.all.item_126_net.options[document.all.item_126_net.options.selectedIndex].text;
              
       
        if (document.all.item_32.checked == true) {
            var con_item_32="1";
        }  
        else {
            var con_item_32="";
        } 
    
        var con_item_125=document.all.item_125.options[document.all.item_125.options.selectedIndex].value;
        var con_item_125_c=document.all.item_125.options[document.all.item_125.options.selectedIndex].text;
        
        var con_pronvince=document.all.province.options[document.all.province.options.selectedIndex].value;
        var con_pronvince_c=document.all.province.options[document.all.province.options.selectedIndex].text;
        
 
        var con_iftransfered =  document.all.iftransfered.value;       
        var con_item_21 =  document.all.item_21.value; 

      


       
       if (con_topicwords == "" &&  con_cgwFlDm == "" && con_cgwFlDm2 == "" && con_item_15_1 == "" && con_item_15_2 == "" && con_item_124_1 == "" && con_item_12 == "" && con_startyear == "" && con_endyear == "" && con_item_2 == "" && con_source == "" && con_item_16 == "" && con_item_9 == "" && con_item_32 == "" && con_item_126 == "" && con_cocreator == "" && con_item_125 == "" && con_pronvince == "" && con_iftransfered == "" && con_item_21 == "" && con_item_3 == "")
      {
        alert("请选择检索字段，谢谢！");
        return;
       }

      
      if (con_startyear == "") con_startyear="1978"; 
      if (con_endyear == "") con_endyear="2009";

      if (con_topicwords == "" &&  con_cgwFlDm == "" && con_cgwFlDm2 == "" &&  con_item_15_1 == "" && con_item_15_2 == "" && con_item_124_1 == "" && con_item_12 == ""  && (con_endyear - con_startyear > 5) && con_item_2 == "" && con_source == "" && con_item_16 == "" && con_item_9 == "" && con_item_32 == "" && con_item_126 == "" && con_cocreator == "" && con_item_125 == "" && con_pronvince == "" && con_iftransfered == "" && con_item_21 == "" && con_item_3 == "")
      {
        alert("成果年份区间请限定在五年之内，谢谢！");
        return;
       }

    if ((con_startyear == "1978")&&(con_endyear == "2009")) {
             con_endyear="";
             con_startyear="";
    }

    document.all.topicname.value = "";
    var v_condition = " 1=1 ";
    //标题
    if  (con_item_3 != "")
    {  	v_condition = v_condition + " and (Kjcg_Item_3 like '%" + con_item_3 + "%' )"  ;
        document.all.topicname.value = con_item_3;
    }

     //检索词          
    if  (con_topicwords!="")
    {  
        if (con_topicwords.indexOf(" ") != "-1") {
           var topics =new Array();
           topics = con_topicwords.split(" ");
           var i;
           var KeywordS;
           for(i=0;i<topics.length;i++) {
              if (i==0) 
                KeywordS = " KjcgID in (select KjcgID from FDAM353User.T_KjcgKey where Keyword = '"+ topics[i] +"')";
              else
                KeywordS = KeywordS + " and KjcgID in (select KjcgID from FDAM353User.T_KjcgKey where Keyword = '"+ topics[i] +"')";
           }
           v_condition = v_condition + " and " +KeywordS ;  
        }
        else {
           v_condition=v_condition+" and (KjcgID in (select KjcgID from FDAM353User.T_KjcgKey where Keyword = '"+con_topicwords+"'))"  ;
        }
    	//v_condition=v_condition+" and (TopicWords like '%"+con_topicwords+"%'" + " or  Kjcg_Item_3 like '%"+con_topicwords+"%')"  ;
       // v_condition=v_condition+" and (KjcgID in (select KjcgID from T_KjcgKey where Keyword = '"+con_topicwords+"'))"  ;
        document.all.topicname.value = con_topicwords;
     } 
    

    //国科网分类            
    if (con_cgwFlDm!="")
    {        	
    	
        if (con_cgwFlDm2 == "") {
		v_condition=v_condition + " and patindex('%" + con_cgwFlDm + "[0-9]%', CgwFlDm)>0";
               
                if (document.all.topicname.value == "") {
                        document.all.topicname.value = con_cgwFlDm_c;
                }
                else {
                        document.all.topicname.value = document.all.topicname.value + "+" + con_cgwFlDm_c;
                }
        }
	else {				
		v_condition = v_condition + " and charindex('" + con_cgwFlDm2 + "', CgwFlDm)>0 ";

                if (document.all.topicname.value == "") {
                        document.all.topicname.value = con_cgwFlDm_c + "["+con_cgwFlDm2_c+"]";
                }
                else {
                        document.all.topicname.value = document.all.topicname.value + "+" + con_cgwFlDm_c + "["+con_cgwFlDm2_c+"]";
                }
       }

    }
    
    //学科分类            
    if (con_item_15_1 != "")
    {        	
    	
        if (con_item_15_2 == "") {
		v_condition = v_condition + " and (Kjcg_Item_15 like '%" + con_item_15_1 + "%' or Kjcg_Item_15_1 like '%" + con_item_15_1 + "%')";
	        if (document.all.topicname.value == "") {
                        document.all.topicname.value = con_item_15_1_c;
                }
                else {
                        document.all.topicname.value = document.all.topicname.value + "+" +con_item_15_1_c;
                }
        }
        else {				
		v_condition = v_condition + " and (Kjcg_Item_15 like '%" + con_item_15_2 + "%' or Kjcg_Item_15_1 like '%" + con_item_15_2 + "%')";
                if (document.all.topicname.value == "") {
                        document.all.topicname.value = con_item_15_1_c + "["+con_item_15_2_c+"]";
                }
                else {
                        document.all.topicname.value = document.all.topicname.value + "+" +con_item_15_1_c + "["+con_item_15_2_c+"]";
                }     
       }
     }
    
    //高新技术
    if (con_item_124_1  != "") {
		v_condition = v_condition + " and Kjcg_Item_124_1 like '%" + con_item_124_1 + "%'";
                if (document.all.topicname.value == "") {
                        document.all.topicname.value = con_item_124_1_c;
                }
                else {
                        document.all.topicname.value = document.all.topicname.value + "+" +con_item_124_1_c;
                }     
    }
   
    //中图分类代码          
    if (con_item_12!="")
    {   if (document.all.topicname.value == "") {
                        document.all.topicname.value = con_item_12;
                }
         else {
                        document.all.topicname.value = document.all.topicname.value + "+" +con_item_12;
        }   
	con_item_12 = con_item_12.split("(")[1];
	con_item_12 = con_item_12.substring(0, con_item_12.length-1);
    	v_condition=v_condition + " and Kjcg_Item_12 like '"+con_item_12+"%'";
                
    }

    //年份
     if  (con_startyear > con_endyear && con_endyear !="") 
     { 
     	alert("年份选择有误,请重新选择!");
      	return;
     }
                
    if  (con_startyear!="")
    {
    	v_condition=v_condition+" and Kjcg_Item_Year>='"+con_startyear+"'" ;
                if (document.all.topicname.value == "") {
                        document.all.topicname.value = "自"+con_startyear+"年";
                }
                else {
                        document.all.topicname.value = document.all.topicname.value + "+" + "自"+con_startyear+"年";
                }  
    } 
  
    if (con_endyear!="")
    {
    	v_condition=v_condition+" and  Kjcg_Item_Year<='"+con_endyear+"'";
                if (document.all.topicname.value == "") {
                        document.all.topicname.value = "至"+con_endyear+"年";
                }
                else {
                        document.all.topicname.value = document.all.topicname.value +"+至"+con_endyear+"年";     
                }  
    }
 
    

    //成果水平          
    if (con_item_2!="")
    {
    	v_condition=v_condition+" and Kjcg_Item_2='"+con_item_2+"'";
        if (document.all.topicname.value == "") {
                        document.all.topicname.value = con_item_2_c;
        }
        else {
                        document.all.topicname.value = document.all.topicname.value + "+" +con_item_2_c;
        }
    }   

    //采集渠道
    if (con_source=="1")
    {
    	v_condition=v_condition+" and substring(AchiveType,1,1)='1'";
        if (document.all.topicname.value == "") {
                        document.all.topicname.value = con_source_c;
        }
        else {
                        document.all.topicname.value = document.all.topicname.value + "+" +con_source_c;
        }
    } 
   
    //是否可转让         
    if  (con_item_32 == "1")
    {
    	v_condition=v_condition+" and Kjcg_Item_33 <> '3'" ;
        if (document.all.topicname.value == "") {
                        document.all.topicname.value = "仅限可转让项目";
        }
        else {
                        document.all.topicname.value = document.all.topicname.value + "+" +"仅限可转让项目";
        }
   
    }

    //所属科技计划       
   if  (con_item_126 != "")
   {   switch(con_item_126) {
       case "1" :
           v_condition=v_condition + " and Kjcg_Item_140='1'";
           break;
       case "2" :      
           v_condition=v_condition + " and (Kjcg_Item_140='7' or Kjcg_Item_140='2') ";
           break;
       case "3" :      
           v_condition=v_condition + " and Kjcg_Item_140='3' ";
           break;
       case "4" :      
           v_condition=v_condition + " and Kjcg_Item_126='01'and (Kjcg_Item_140='9' or Kjcg_Item_140='8' or Kjcg_Item_140='4' or Kjcg_Item_140='5' or Kjcg_Item_140='6')";
           break;
       case "5" :
           v_condition=v_condition + " and Kjcg_Item_126='02'";
           break;
       case "6" :
           v_condition=v_condition + " and Kjcg_Item_126='03'";
           break;
       }
     	
        if (document.all.topicname.value == "") {
                        document.all.topicname.value = con_item_126_c;
        }
        else {
                        document.all.topicname.value = document.all.topicname.value + "+" +con_item_126_c;
        }
    }



     //所处阶段          
    if (con_item_16 != "")
    {
    	v_condition=v_condition+" and Kjcg_Item_16='"+con_item_16+"'";
        if (document.all.topicname.value == "") {
                        document.all.topicname.value = con_item_16_c;
        }
        else {
                        document.all.topicname.value = document.all.topicname.value + "+" +con_item_16_c;
        }
    }
 
      //完成单位          
    if  (con_item_9!="")
    {
    	v_condition=v_condition+" and Kjcg_Item_9 like '%"+con_item_9+"%'" ;
        if (document.all.topicname.value == "") {
                        document.all.topicname.value = con_item_9;
        }
        else {
                        document.all.topicname.value = document.all.topicname.value + "+" +con_item_9;
        }
    } 

     //完成人            
   if  (con_cocreator!="")
    {
    	v_condition=v_condition+" and CoCreator like'%"+con_cocreator+"%'" ;
        if (document.all.topicname.value == "") {
                        document.all.topicname.value = con_cocreator;
        }
        else {
                        document.all.topicname.value = document.all.topicname.value + "+" +con_cocreator;
        }
        
    } 

    //省市          
    if (con_pronvince != "")
    {
    	v_condition=v_condition+" and Kjcg_Item_dqdm='"+con_pronvince+"'";
        if (document.all.topicname.value == "") {
                        document.all.topicname.value = con_pronvince_c;
        }
        else {
                        document.all.topicname.value = document.all.topicname.value + "+" +con_pronvince_c;
        }
    }

    //行业
    if (con_item_125  != "") {
		v_condition = v_condition + " and Kjcg_Item_125 like '%" + con_item_125 + "%'";
                if (document.all.topicname.value == "") {
                        document.all.topicname.value = con_item_125_c;
                }
                else {
                        document.all.topicname.value = document.all.topicname.value + "+" +con_item_125_c;
                }     
    }

   //是否已转让
    if (con_iftransfered == "1") {
        v_condition = v_condition + " and (Kjcg_Item_45 >0  or Kjcg_Item_150 >0) ";
        if (document.all.topicname.value == "") {
                        document.all.topicname.value = "已转让";
                }
                else {
                        document.all.topicname.value = document.all.topicname.value + "+" +"已转让";
                }  
    }
   
   //是否鉴定
    if (con_item_21 == "1") {
        v_condition = v_condition + " and Kjcg_Item_21 = '1' ";
        if (document.all.topicname.value == "") {
                        document.all.topicname.value = "鉴定";
                }
                else {
                        document.all.topicname.value = document.all.topicname.value + "+" +"鉴定";
                }  
    }

    

    document.all.key.value=v_condition;

    document.getElementById("searchform").submit();
}

function selectfl() {
    
   var fl = document.all.choosefl.value;
   
   switch(fl)
  {   
   case "1":
     document.all.cgwFlDm.style.display = ""
    
     if (cgwFlDm !="")  {
        document.all.cgwFlDm2.style.display = "";
     }
     else {
       document.all.cgwFlDm2.style.display = "none";
     }
     document.all.item_15_1.style.display = "none";
     document.all.item_15_2.style.display = "none";
     document.all.item_124_1.style.display = "none";
     document.all.item_12.style.display = "none";

     document.all.item_12.value ="";
     //document.all.item_124_1.options[document.all.item_124_1.options.selectedIndex].value ="";
     document.all.item_124_1.value ="";
     
     document.all.item_15_1.options[document.all.item_15_1.options.selectedIndex].value ="";
     if (item_15_2 !="")
       document.all.item_15_2.options[document.all.item_15_2.options.selectedIndex].value ="";
       //  document.all.item_15_2.value ="";
     
     
   break;

    case "3":
     document.all.cgwFlDm.style.display = "none";
     document.all.cgwFlDm2.style.display = "none";
     document.all.item_15_1.style.display = "";
     if (item_15_1 !="") {
       document.all.item_15_2.style.display = "";
     }
     else {

       document.all.item_15_2.style.display = "none";
     }
     document.all.item_124_1.style.display = "none";
     document.all.item_12.style.display = "none";

     document.all.cgwFlDm.options[document.all.cgwFlDm.options.selectedIndex].value ="";
     if (cgwFlDm2 !="")
         document.all.cgwFlDm2.options[document.all.cgwFlDm2.options.selectedIndex].value ="";
     document.all.item_12.value ="";
     //document.all.item_124_1.options[document.all.item_124_1.options.selectedIndex].value ="";
      document.all.item_124_1.value="";
     
     break;
    case "4":
     
     document.all.cgwFlDm.style.display = "none";
     document.all.cgwFlDm2.style.display = "none";
     document.all.item_15_1.style.display = "none";
     document.all.item_15_2.style.display = "none";
     document.all.item_124_1.style.display = "";
     document.all.item_12.style.display = "none";

       document.all.cgwFlDm.options[document.all.cgwFlDm.options.selectedIndex].value ="";
     if (cgwFlDm2 !="")
       document.all.cgwFlDm2.options[document.all.cgwFlDm2.options.selectedIndex].value ="";
     document.all.item_15_1.options[document.all.item_15_1.options.selectedIndex].value ="";
     if (item_15_2 !="")
       document.all.item_15_2.options[document.all.item_15_2.options.selectedIndex].value ="";
     document.all.item_12.value ="";

     
    break;
    case "2":
     document.all.cgwFlDm.style.display = "none";
     document.all.cgwFlDm2.style.display = "none";
     document.all.item_15_1.style.display = "none";
     document.all.item_15_2.style.display = "none";
     document.all.item_124_1.style.display = "none";
     document.all.item_12.style.display = "";

     document.all.cgwFlDm.options[document.all.cgwFlDm.options.selectedIndex].value ="";
     if (cgwFlDm2 !="")
        document.all.cgwFlDm2.options[document.all.cgwFlDm2.options.selectedIndex].value ="";
     document.all.item_15_1.options[document.all.item_15_1.options.selectedIndex].value ="";
     if (item_15_2 !="")
        document.all.item_15_2.options[document.all.item_15_2.options.selectedIndex].value ="";
     //document.all.item_124_1.options[document.all.item_124_1.options.selectedIndex].value ="";
     document.all.item_124_1.value ="";
     
   break;
     
    

  }
}

function DisplayCgwFlDm2(xxdm1,xxdm2){
     
    document.all.cgwFlDm2.style.display = "none";
    document.all.cgwFlDm2.length=0;  
    if (xxdm1 !='' ){
   
              document.all.cgwFlDm2.style.display = "";
             
              getClass2only(xxdm1,xxdm2);

    }
    else {
             document.all.cgwFlDm2.style.display = "none";
    } 

}


function DisplaySubjectClass2(xxdm1,xxdm2){
    document.all.item_15_2.style.display = "none";
    document.all.item_15_2.length=0;  
    
    if (xxdm1 !='' ){
             document.all.item_15_2.style.display = "";
             getSubjectClassTwoLevel(xxdm1,xxdm2);
    }
    else {
             document.all.item_15_2.style.display = "none";
    } 

}

function openztfl(ctrl){
window.open('../../membercenter/kjcgmanage/systemfiles/htm/ztflunit.htm?ctrl='+ctrl,null,'height=500px width=450px top=100px left=200px  scrollbars=yes')
}


function changeOption(v_value,v_text,v_option)
{   
    document.getElementById(v_option).options[document.getElementById(v_option).selectedIndex].value=v_value;
    document.getElementById(v_option).options[document.getElementById(v_option).selectedIndex].text=v_text; 
    if (v_option == "item_15_1")  document.all.item_15_2.value="";
    if (v_option == "cgwFlDm")  document.all.cgwFlDm2.value="";
}



function changeFlTab(flid)
{ switch(flid)
   
 { case "1":
    
      document.all.cgwfllistsearch.style.display = "";
      document.all.xkfllistsearch.style.display = "none";
      document.all.gxjslistsearch.style.display = "none";
      document.all.ztfllistsearch.style.display = "none";
      document.all.choosefl.value = '1';
   break;
   
   case "2":
      document.all.cgwfllistsearch.style.display = "none";
      document.all.xkfllistsearch.style.display = "";
      document.all.gxjslistsearch.style.display = "none";
      document.all.ztfllistsearch.style.display = "none";
      document.all.choosefl.value = '2';
   break;

   case "3":
      document.all.cgwfllistsearch.style.display = "none";
      document.all.xkfllistsearch.style.display = "none";
      document.all.gxjslistsearch.style.display = "";
      document.all.ztfllistsearch.style.display = "none";
      document.all.choosefl.value = '3';
      
   break;

   case "4":
      document.all.cgwfllistsearch.style.display = "none";
      document.all.xkfllistsearch.style.display = "none";
      document.all.gxjslistsearch.style.display = "none";
      document.all.ztfllistsearch.style.display = "";
      document.all.choosefl.value = '4';
   break;  
  }  
   selectfl();
}
 

function OnlyChooseOnefl() {
   var flnum=0;
   if (document.all.item_15_1.value != "") flnum++; 
   if (document.all.cgwFlDm.value != "") flnum++; 
   if (document.all.item_124_1.value != "") flnum++;
   if (document.all.item_12.value != "") flnum++;
   
   if (flnum > 1) {
      alert("'国科分类'、'学科分类'、'高新技术分类'、中图分类' 只能选择一个分类");
      return;
   }
 
   if (document.all.item_15_1.value != "") document.all.choosefl.value = "3"; 
   if (document.all.cgwFlDm.value != "") document.all.choosefl.value = "1"; 
   if (document.all.item_124_1.value != "") document.all.choosefl.value = "4"; 
   if (document.all.item_12.value != "") document.all.choosefl.value = "2"; 
   
   doSearch();   
}

function getNewAchieve(){
     document.getElementById("startyear").options[document.getElementById("startyear").selectedIndex].value="2006";
     document.getElementById("endyear").options[document.getElementById("endyear").selectedIndex].value="2009";
     doSearch();
}

function getNewDjAchieve(){
     document.getElementById("startyear").options[document.getElementById("startyear").selectedIndex].value="2006";
     document.getElementById("endyear").options[document.getElementById("endyear").selectedIndex].value="2009";
     document.all.source.value='1';
     doSearch();
}

function getMatureTech(){
     document.all.item_16.value="3";
     document.getElementById("startyear").options[document.getElementById("startyear").selectedIndex].value="2000";
     document.getElementById("endyear").options[document.getElementById("endyear").selectedIndex].value="2009";
     document.all.source.value='1';
     doSearch();
}

function getTransferTech(){
     document.all.item_32.checked = true;
     //document.all.item_32.value = "1";
     document.getElementById("startyear").options[document.getElementById("startyear").selectedIndex].value="2000";
     document.all.source.value='1';
     doSearch();
}


function getTransferedTech(){
     document.all.item_32.checked = true;
     document.all.iftransfered.value = "1";
     document.getElementById("startyear").options[document.getElementById("startyear").selectedIndex].value="2000";
     document.all.source.value='1';
     doSearch();
}

function getAppraisedTech(){
     
     document.getElementById("startyear").options[document.getElementById("startyear").selectedIndex].value="2000";
     document.all.item_21.value='1';
     doSearch();
}