﻿function DeserializeResponse(response)   //反序列化返回的字符串为JS对象。
{
    return Sys.Serialization.JavaScriptSerializer.deserialize(response);
}

function getSelectPatentIds()   //获取被选中的专利的ID
{
    var returnStr = '';
    var objs = document.getElementsByTagName('input');
    for(var i=0;i < objs.length; i++) 
    {
        if(objs[i].type.toLowerCase() == "checkbox" && objs[i].checked && objs[i].id.indexOf('viewCheck_') != -1)
        {
            var array = objs[i].id.split('_');
            returnStr += array[1] + ',';
        }
    }
    if(returnStr.indexOf(',') != -1)
    {
        returnStr = returnStr.substring(0,returnStr.length - 1);
    }
    return returnStr;
}

function getSelectPatentIdsExt()   //获取被选中的专利的ID(建库专用)
{
    var returnStr = '';
    var objs = document.getElementsByTagName('input');
    for (var i = 0; i < objs.length; i++) {
        if (objs[i].type.toLowerCase() == "checkbox" && objs[i].checked && objs[i].id.indexOf('viewCheck|') != -1) {
            var array = objs[i].id.split('|');
            returnStr += array[1] + ',' + array[2] + '|';
        }
    }
    if (returnStr.indexOf(',') != -1) {
        returnStr = returnStr.substring(0, returnStr.length - 1);
    }
    return returnStr;
}

function collect(typeId)  //添加收藏到数据库（搜索结果页面）
{
    var patentId = getSelectPatentIds();
    if(patentId != '')
    {
        var CollectionFileDDLObj=document.getElementById("ctl00_ctl00_MainContent_ChildContent1_CollectionFileDDL");
        var catalogId=CollectionFileDDLObj.options[CollectionFileDDLObj.selectedIndex].value;
        CollectService.AddCollections(patentId,typeId,catalogId,ReceiveCollectResult);
    }
    else
    {
        alert('您没有选中任何专利!');
    }
}

function ReceiveCollectResult(result)  //处理webservice返回的数据
{
    if(result == 'notLogin')
    {
        alert("对不起,您还没有登录!");
    }
    else if(result == 'true')
    {
        alert("添加成功!");
    }
    else
    {
        alert("添加失败!");
    }
}

function loadCatalogName()  //获取收藏目录
{
    CollectService.CatalogNameService(ReceiveCatalogResult);
}

function ReceiveCatalogResult(result)  //把获取的收藏目录添加到dropdownlist中
{
    if(result != 'notLogin')
    {
        document.getElementById("NotCollectDiv").style.display='none';
        document.getElementById("ctl00_ctl00_MainContent_ChildContent1_panel3").style.display='block';
        var catalog=DeserializeResponse(result);
        var CollectionFileDDLObj=document.getElementById("ctl00_ctl00_MainContent_ChildContent1_CollectionFileDDL");
        if(CollectionFileDDLObj.options.length ==0)
        {
            for(var j=0;j<catalog.length;j++)
            {
                CollectionFileDDLObj.options.add(new Option(catalog[j].CatalogName,catalog[j].CatalogID));
            }
        }
    }
    else
    {
        document.getElementById("ctl00_ctl00_MainContent_ChildContent1_panel3").style.display='none';
        document.getElementById("NotCollectDiv").style.display='block';
    }
}

function collectEn()  //添加收藏到数据库（企业库页面）
{
    var patentId = getSelectPatentIds();
    var typeId=document.getElementById("ctl00_ctl00_MainContent_ChildContent1_TxtSearchTypeId").value;
    if(patentId != '')
    {
        var CollectionFileDDLObj=document.getElementById("ctl00_ctl00_MainContent_ChildContent1_CollectionFileDDL");
        var catalogId=CollectionFileDDLObj.options[CollectionFileDDLObj.selectedIndex].value;
        CollectService.AddCollections(patentId,typeId,catalogId,ReceiveCollectResult);
    }
    else
    {
        alert('您没有选中任何专利!');
    }
}
