{
    "translatorID":"d5770df3-b41a-45cb-bb3a-261948c9af49",
    "translatorType":4,
    "label":"SCAR",
    "creator":"Liangxu Wang<wangliangxu@gmail.com>",
    "target":"http://www.scar.ac.cn/hhkxen/ch/reader",
    "minVersion":"1.0",
    "maxVersion":"",
    "priority":100,
    "inRepository":true,
    "lastUpdated":"2009-5-27 22:33:00"
}

function detectWeb(doc, url) {
    var articleRe = /view_abstract.aspx/;
    var s = articleRe.exec(url);

    if(s) {
        return "journalArticle";
    } else {
        return "multiple";
    }

    return false;
}

function scrape(doc) {
    var nsResolver = null;

    var itemType = "journalArticle";
    var newItem = new Zotero.Item(itemType);
    Zotero.debug(itemType);

    // 标题
    var title = doc.getElementById('EnTitle').textContent;
    Zotero.debug("Title:"+title);
    newItem.title = title;

    // 附件，网页快照
    var snapName = title + " (SCAR)";
    Zotero.debug(snapName);
    newItem.attachments.push({document:doc, title:snapName, mimeType:"text/html"});
    //Zotero.debug(doc);

    //关键词
    var keys=doc.getElementById('EnKeyWord');
    var tags=keys.getElementsByTagName('u');
    var i=0;
    for(i=0;i<tags.length;i++){
      newItem.tags.push(tags[i].textContent);
      Zotero.debug("tag:"+tags[i].textContent);
    }
    //摘要
    var abstract=doc.getElementById('EnAbstract');
    newItem.abstractNote = Zotero.Utilities.trim(abstract.textContent);
    // 出版社
    newItem.publicationTitle = 'Sciences in Cold and Arid Regions';
    newItem.ISSN='1674-3822';
    newItem.url = doc.location.href;
    //出版时间
    var ref=doc.getElementById('ReferenceText').textContent;
    if (ref.match(/,(\d+).+Sciences in Cold and Arid Regions,(\d+)\((\d+)\):(.+)\./))
    {
      newItem.volume=ref.match(/,(\d+).+Sciences in Cold and Arid Regions,(\d+)\((\d+)\):(.+)\./)[2];
      newItem.issue=ref.match(/,(\d+).+Sciences in Cold and Arid Regions,(\d+)\((\d+)\):(.+)\./)[3];
      newItem.pages=ref.match(/,(\d+).+Sciences in Cold and Arid Regions,(\d+)\((\d+)\):(.+)\./)[4];
      newItem.date=ref.match(/,(\d+).+Sciences in Cold and Arid Regions,(\d+)\((\d+)\):(.+)\./)[1];
    }
    //作者
    if (ref.match(/(.+),\d+\.+/))
    {
      authors=ref.match(/(.+),\d+\.+/)[1].split(',');
      for(i=0;i<authors.length-1;i++) {
        newItem.creators.push(Zotero.Utilities.cleanAuthor(authors[i], "author", true));
      }
      author=authors[authors.length-1].split('and');
      for(i=0;i<author.length;i++) {
        newItem.creators.push(Zotero.Utilities.cleanAuthor(author[i], "author", true));
      }
    }
    Zotero.debug("finished.");
    newItem.complete();
}

function doWeb(doc, url) {
    var namespace = doc.documentElement.namespaceURI;
    var nsResolver = null;

    if(detectWeb(doc, url) == "multiple") {
        Zotero.debug("Enter multiple~");
        // TODO: implement the multiple function.
    } else {
        var urls = [url];
    }
    Zotero.debug(urls);
    // 下面对每条url进行解析
    Zotero.Utilities.processDocuments(urls, scrape, function() { Zotero.done(); });
    Zotero.wait();
}
