﻿// JScript 文件

function  searchTools()
{
     this.ungineURl = "../searchUtility/search.aspx"; 
}

searchTools.prototype.hello = function()
{ 
    alert('hello') ;
}
searchTools.prototype.searchNews = function(searchString, searchType, resultDivID)
{ 
   
    
    var xmlContent = "<searchNews type=\"news\" stype=\""+searchType+"\">" ;
    xmlContent +=searchString ;
    xmlContent += "</searchNews>" ;
   
    this.runSearch(xmlContent, resultDivID , "搜索新闻中，请等待......") ;
}
searchTools.prototype.searchElement = function(stype ,target, searchString ,resultDivID )
{
    var xmlContent = "<searchElement type=\""+stype+"\" target=\""+target+"\">" ;
    xmlContent +=searchString ;
    xmlContent += "</searchElement>" ;
   
    this.runSearch(xmlContent, resultDivID , "搜索中，请等待......") ;
}
searchTools.prototype.searchElement2 = function(stype ,targets, searchString ,resultDivID )
{
    var xmlContent = "<searchElement2 type=\""+stype+"\" >" ;
    xmlContent +="<searchstring>" +  searchString + "</searchstring>" ;
    xmlContent +=targets ;
    xmlContent += "</searchElement2>" ;
   
    this.runSearch(xmlContent, resultDivID , "搜索中，请等待......") ;
}



searchTools.prototype.jumpToDirByImgURL = function(url,resultDivID)
{ 
   
    
    var xmlContent = "<jumpToDirByImgURL>" ;
    xmlContent += url;
    xmlContent += "</jumpToDirByImgURL>" ;
   
    this.runSearch(xmlContent, resultDivID, "搜索网络文件夹中，请等待......") ;
}

searchTools.prototype.searchDir = function(resultDivID)
{ 
   
    
    var xmlContent = "<searchDir>" ;
    
    xmlContent += "</searchDir>" ;
   
    this.runSearch(xmlContent, resultDivID, "搜索网络文件夹中，请等待......") ;
}
searchTools.prototype.searchAll = function(word , resultDivID)
{ 
   
   
    var xmlContent = "<searchAll>" + word ;
    
    xmlContent += "</searchAll>" ;
   
    this.runSearch(xmlContent, resultDivID, "搜索中，请等待......") ;
}

searchTools.prototype.searchDirByHeightlight = function(fname, path , resultDivID)
{ 
   
   
    var xmlContent = "<searchDirByHeightlight path=\""+path+"\">" ;
    xmlContent += fname ;
    xmlContent += "</searchDirByHeightlight>" ;
   
    this.runSearch(xmlContent, resultDivID, "搜索网络文件夹中，请等待......") ;
}
searchTools.prototype.searchElementName = function(name, type ,resultDivID)
{ 
   
  
    var xmlContent = "<searchElementName type=\""+type+"\">" ;
    xmlContent += name ;
    xmlContent += "</searchElementName>" ;
    
    this.runSearch(xmlContent, resultDivID, "搜索网络文件夹中，请等待......") ;
     
}
searchTools.prototype.searchDir2 = function(path , resultDivID)
{ 
   
   
    var xmlContent = "<searchDir path=\""+path+"\">" ;
    
    xmlContent += "</searchDir>" ;
   
    this.runSearch(xmlContent, resultDivID, "搜索网络文件夹中，请等待......") ;
}
searchTools.prototype.deleteFile = function (fname ,resultDivID )
{
    var xmlContent = "<deleteFile path=\""+fname+"\" >" ;
    
     xmlContent += "</deleteFile>" ;
     this.runSearch(xmlContent, resultDivID, "删除网络文件中，请等待......") ;
}
searchTools.prototype.createDir = function(path , dirname, resultDivID)
{
     var xmlContent = "<createDir path=\""+path+"\" dirname=\""+dirname+"\">" ;
    
     xmlContent += "</createDir>" ;
     this.runSearch(xmlContent, resultDivID, "创建网络文件夹中，请等待......") ;
}
   
searchTools.prototype.deleteDir = function(path , resultDivID)
{
     var xmlContent = "<deleteDir path=\""+path+"\">" ;
    
     xmlContent += "</deleteDir>" ;
     this.runSearch(xmlContent, resultDivID, "删除网络文件夹中，请等待......") ;
}
searchTools.prototype.runSearch = function (xmlContent , resultDivID , message)
{
     var xmlHttp = null ;
    
     var viewDiv = document.getElementById(resultDivID) ;
    
    if(viewDiv == null)
        return ;
    
    viewDiv.innerHTML = message ;
    
    if(window.ActiveXObject)
           xmlHttp=new ActiveXObject("Microsoft.XMLHTTP") ;
    else if(window.XMLHttpRequest)
         xmlHttp = new XMLHttpRequest() ;   
    if(xmlHttp == null)
    {
      alert("unable to create connect") ;
      return ;
    }
    
   // var search = new searchTools();  
    
    xmlHttp.open("post" , this.ungineURl) ;
    
    xmlHttp.setRequestHeader("Content-Type", "text/xml");
    xmlHttp.onreadystatechange=function(){searchCallbak(xmlHttp ,viewDiv)}   ;//loadAllProjInfoListCallbak;
   
    xmlHttp.send(xmlContent) ;  
    
    serch = null ;
   
}
function searchCallbak (xmlhttpObj,viewDiv)
{     
     
          if(xmlhttpObj.readyState == 4)
          {        
            if(xmlhttpObj.status==200)
            {   
                if(xmlhttpObj.responseText.indexOf('会话已关闭，无法操作，请登录') >=0)
                {
                   alert('会话已关闭，无法操作，请登录') ;
                    xmlhttpObj = null ;
                  CollectGarbage();
                  return ;
                }
                
                if(xmlhttpObj.responseText.indexOf('staffFind') >=0 )
                {
                  showRepeatAlert() ;
                   xmlhttpObj = null ;
                  CollectGarbage();
                  return ;
                  
                }
                  if(xmlhttpObj.responseText.indexOf('staffNotFind')>=0) 
                {
                
                  document.getElementById('form1').action= "staffRegister.aspx?insert=true" ;
                
                   createElement2() ;
                     xmlhttpObj = null ;
                  CollectGarbage();
                  return ;
                }
                  if(xmlhttpObj.responseText.indexOf('projectFind') >=0 ) 
                {
                  xmlhttpObj = null ;
                  CollectGarbage();
                  return ;
                }
                  if(xmlhttpObj.responseText.indexOf('projectNotFind')>=0) 
                {
                   createElement() ;
                     xmlhttpObj = null ;
                  CollectGarbage();
                  return ;
                }
                   viewDiv.innerHTML =xmlhttpObj.responseText ;   
            }
            else
              viewDiv.innerHTML ="搜索失败，请检查网络链接" ;
         }
           
         xmlhttpObj = null ;
         CollectGarbage();
}

function removeImg(div , inputid)
{
      if(confirm("是否删除当前图片？") == false)
         return ;
     if(div!=null)
        div.innerHTML = "" ;
    document.getElementById(inputid).value="" ;
}
function searchElement2(stype, selectionPop , searchString)
{
    
    var s = new searchTools() ;
    var type = getSearchType2(selectionPop) ;
    alert(type) ;
      if(stype == 'project_info')
       s.searchElement2(stype ,type, document.getElementById(searchString).value ,'mainDivView');
}
function searchElementByType(target, type , searchString)
{
    var s = new searchTools() ;
   
      s.searchElement(target ,type, searchString ,'mainDivView');
      
}
function searchElement(stype , searchString)
{
    var s = new searchTools() ;
    var type = getSearchType() ;
    if(stype == 'project_info')
       s.searchElement(stype ,'[proj-name]', document.getElementById(searchString).value ,'mainDivView');
    else    s.searchElement(stype ,type, document.getElementById(searchString).value ,'mainDivView');
}
function getSearchType2(selectionPop)
   {
       var xml = "<targets>" ;
       var table = document.getElementById(selectionPop) ;
       if(table == null)
          return "" ;
          
       var radios =table.getElementsByTagName('input') ;  
       if(radios.lenght <= 0 )
          radios =table.getElementsByTagName('INPUT') ;  
       if(radios.lenght <= 0 )
          radios =table.getElementsByTagName('Input') ;  
      
       for( i = 0 ; i <radios.length ; i ++ )
       {
        
         if(radios[i].checked == true)
         {
             
             xml += "<target value=\""+radios[i].getAttribute("value")+"\"  />" ;
          }
    
       }
       xml += "</targets>" ;
       return xml ;
       
   }
   
function getSearchType()
   {
       var table = document.getElementById("searchTable") ;
       if(table == null)
          return "" ;
          
       var radios =table.getElementsByTagName('input') ;  
       if(radios.lenght <= 0 )
          radios =table.getElementsByTagName('INPUT') ;  
       if(radios.lenght <= 0 )
          radios =table.getElementsByTagName('Input') ;  
      
       for( i = 0 ; i <radios.length ; i ++ )
       {
        
         if(radios[i].checked == true)
         {
             return radios[i].value ;
          }
    
       }
       return '' ;
       
   }
   
function selectPop(val , evtObj)
    {
       
      document.getElementById("word").innerHTML = val ;
      showPopup ('wordPop' , evtObj) ;
    }
