<!-- <head>
  <script
  src="https://code.jquery.com/jquery-3.4.1.min.js"
  integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
  crossorigin="anonymous"></script>
</head> -->
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
</head>
<body>
<div class="mobileShow" id="articleSearchOptions" style="">
<div style="border:1px solid grey; padding:10px;">

  <div id="articles">
        <span style="font-weight:bold;font-style: italic;">Search by Keywords</span><input type="text" class="search" id="searchArticle"/>
        <hr class="hr-text" data-content="OR">
        <span style="font-weight:bold;font-style: italic;">Search by Author</span><input type="text" class="search" id="searchAuthor"/>
        <hr class="hr-text" data-content="OR">
        <span style="font-weight:bold;font-style: italic;">Search by Title</span><input type="text" class="search" id="searchTitle"/>
  </div>
  <div style="margin-bottom:10px;margin-top:10px;">
    Filter:
    <label class="radio-inline"><input checked name="searchFilter" id="searchFilterAll" type="radio" class="searchType" value="All">All</label>
    <label class="radio-inline"><input name="searchFilter" id="searchFilterAACT" type="radio" class="searchType" value="AACT">AACT Articles</label>
    <label class="radio-inline"><input name="searchFilter" id="searchFilterPMCA" type="radio" class="searchType" value="PMCA">PMCA Articles</label>
  </div>
  <!-- <div id="SearchOptions">
    <div id="SearchTypeDiv">
      <div style="margin-top:5px;"><input checked name="searchType" id="searchAll" type="radio" class="searchType" value="All"> Search All Articles</div>
      <div style="margin-top:5px;">Or</div>
      <div><input name="searchType" id="searchIn" type="radio" class="searchType" value="In">Search Only In
      <select name="searchMonth" id="searchMonth" onchange="">
        <option value="all">All Months</option>
        <option value="1">Jan</option>
        <option value="2">Feb</option>
        <option value="3">Mar</option>
        <option value="4">Apr</option>
        <option value="5">May</option>
        <option value="6">Jun</option>
        <option value="7">Jul</option>
        <option value="8">Aug</option>
        <option value="9">Sep</option>
        <option value="10">Oct</option>
        <option value="11">Nov</option>
        <option value="12">Dec</option>
      </select> of
      <select name="searchYear" id="searchYear">
        <option val=2026>2026</option>
<option val=2025>2025</option>
<option val=2024>2024</option>
<option val=2023>2023</option>
<option val=2022>2022</option>
<option val=2021>2021</option>
<option val=2020>2020</option>
<option val=2019>2019</option>
<option val=2018>2018</option>
<option val=2017>2017</option>
<option val=2016>2016</option>
<option val=2015>2015</option>
<option val=2014>2014</option>
<option val=2013>2013</option>
<option val=2012>2012</option>
<option val=2011>2011</option>
<option val=2010>2010</option>
<option val=2009>2009</option>
<option val=2008>2008</option>
<option val=2007>2007</option>
<option val=2006>2006</option>
<option val=2005>2005</option>
<option val=2004>2004</option>
<option val=2003>2003</option>
<option val=2002>2002</option>
<option val=2001>2001</option>
<option val=2000>2000</option>
<option val=1999>1999</option>
<option val=1998>1998</option>
<option val=1997>1997</option>
<option val=1996>1996</option>
<option val=1995>1995</option>
      </select> -->
    <!-- </div> -->
      <a class="fusion-button button-flat fusion-button-round button-small button-default button-1" href="javascript:articleSearchButton()">Search</a>
    </div>
  <!-- </div> -->
<!-- </div> -->

  <div id="articleList" style="border:1px solid grey; margin-top:20px; padding:10px;">
    <!-- PHP inserts based on Producttype selection default: Ingredients (RM)-->
    <span style="font-weight:bold;font-style: italic;">Browse by Issue</span>
  </div>
</div>


<div id="sortButtons" style="float:right;">
  sort by:
  <a class="" style="margin-right:10px; margin-left:10px; text-decoration: underline;" href="javascript:articleLinksSort('date')">Date</a>
  <a class="" style="text-decoration: underline;"href="javascript:articleLinksSort('relevance')">Relevance</a>
</div>
<div class="mobileHide" id="articleLinks">
  <!-- PHP inserts based on subcategory selection default: empty-->
</div>

<script>
var C_PLUGIN = '/wp-content/plugins/gomcarticles/';



  function loadarticleList(data)
  {
    //console.log(data);

    // jQuery("#articleList").empty();
    jQuery("#articleList").append(data);
    assignCollapsibleListListener();
  }
  // function loadCompanyList(data)
  // {
  //   jQuery("#searchCategory_auto").empty();
  //   jQuery("#searchCategory").val("");
  //   jQuery("#searchCompany_auto").empty();
  //   jQuery("#searchCompany").val("");
  //   jQuery("#companies").empty();
  //   jQuery("#companies").append(data);
  //   assignCollapsibleListener();
  // }
  jQuery(document).ready(function(){

    getArticles();
    assignCollapsibleListListener();
    let d = new Date();
    getArticlesByIssue(d.getFullYear(),"current");
    mobileSwitch();

    // jQuery(".categoryClick").click(function()
    // {
    //   console.log("test");
    //     jQuery("#companies").empty();
    //     jQuery.post({
    //       url: C_PLUGIN + 'ajax.php',
    //       data: {command:"printCompany",payload:{"search":this.data("id")}}
    //
    //
    //     })
    //     .done(function(result)
    //     {
    //
    //     })
    // });

  })

  function assignCollapsibleListListener()
  {
    var coll = document.querySelectorAll(".collapsible_list");
    //coll.concat(document.getElementsByClassName("collapsible_list"))
    console.log(coll);
    var i;

    for (i = 0; i < coll.length; i++) {
      coll[i].addEventListener("click", function() {
        this.classList.toggle("active");
        var content = this.nextElementSibling;
        console.log(content);
        if (content.style.display === "block") {
          content.style.display = "none";
        } else {
          content.style.display = "block";
        }
      });
    }
  }

  function assignCollapsibleListener()
  {
    var coll = document.querySelectorAll(".collapsible");
    //coll.concat(document.getElementsByClassName("collapsible_list"))
    console.log(coll);
    var i;

    for (i = 0; i < coll.length; i++) {
      coll[i].addEventListener("click", function() {
        this.classList.toggle("active");
        var content = this.nextElementSibling;
        console.log(content);
        if (content.style.display === "block") {
          content.style.display = "none";
        } else {
          content.style.display = "block";
        }
      });
    }
  }

  function getArticles()
  {
    let arr = {command: "getArticles"}
    console.log(arr);
    jQuery.post({
      url: C_PLUGIN + 'ajax.php',
      data: arr
    }).done(function(result){
      //console.log(result);
      loadarticleList(result);
      jQuery("#older").trigger("click");
      jQuery("#older").trigger("click");
    });
  }

  function getArticlesByIssue(year,issue)
  {
    let filter = jQuery("input[name=searchFilter]:checked").val()
    jQuery.post({
      url: C_PLUGIN + 'ajax.php',
      data: {command:"getArticlesByIssue","payload":{"year":year,"issue":issue,"filter":filter,"email":""}}


    }).done(function(result)
    {
      result = JSON.parse(result);
      addArticleLinks(result);
    });
  }

  function articleSearchButton()
  {
    if( jQuery("#searchArticle").val().length > 0 )
    {
      articleSearch("article",jQuery("#searchArticle").val());
    }

    else if ( jQuery("#searchAuthor").val().length > 0 )
    {
      articleSearch("author",jQuery("#searchAuthor").val());
    }

    else if ( jQuery("#searchTitle").val().length > 0 )
    {
      articleSearch("title",jQuery("#searchTitle").val());
    }
  }

  function articleDownload(name)
  {
    // download_url("/home/gomc/articles/"+name)
    // console.log(C_PLUGIN +'download.php?name=' + name)
    window.location = C_PLUGIN +'download.php?name=' + name;

    // payload = {"path":path}
    // fileName = "test.pdf"
    //
    // jQuery.post({
    //   url: C_PLUGIN + 'download.php',
    //   data: payload
    //
    // })
    // .done(function(result)
    // {
    //   window.location = C_PLUGIN +'download.php';
    // })

    // .fail(function(result)
    // {
    //   console.log("Failure!");
    //   console.log(result);
    // })
  // }
  }


  function oldarticleDownload(path)
  {

    payload = {"path":path}
    fileName = "test.pdf"

    jQuery.post({
      url: C_PLUGIN + 'ajax.php',
      data: {command:"articleDownload","payload":payload},
      responseType: "application/octetstream"

    })
    .done(function(result)
    {
      if(result)
      {
        console.log(result)
        //Convert the Byte Data to BLOB object.
        var blob = new Blob([result], { type: "application/octetstream" });

        //Check the Browser type and download the File.
        var isIE = false || !!document.documentMode;
        if (isIE) {
            window.navigator.msSaveBlob(blob, fileName);
        } else {
            var url = window.URL || window.webkitURL;
            link = url.createObjectURL(blob);
            var a = jQuery("<a />");
            a.attr("download", fileName);
            a.attr("href", link);
            jQuery("body").append(a);
            a[0].click();
            // jQuery("body").remove(a);
          }
        }
    })

    .fail(function(result)
    {
      console.log("Failure!");
      console.log(result);
    })
  // }
  }


  function articleSearch(type,val)
  {
    // var keycode = (event.keyCode ? event.keyCode : event.which);
	  // if(keycode == '13')
    // {
      console.log(val);
      // if(!jQuery("#searchArticle").val())
      // {
      //   // jQuery("#searchArticle_auto").empty();
      //   // return;
      // }
      // let cb = [];
      // jQuery.each(jQuery('.categoryType:checked'), function() {
      //   cb.push(jQuery(this).val());
      // });
      let filter = jQuery("input[name=searchFilter]:checked").val()
      //console.log(filter);
      let payload = {"search":val,"type":type,"filter":filter,"email":""};
      if( jQuery("#searchIn").prop("checked") )
      {
        payload = {"search":val,"year":jQuery("#searchYear").val(),"month":jQuery("#searchMonth").val(),"type":type,"filter":filter,"email":""};
      }
      console.log(payload)
      jQuery.post({
        url: C_PLUGIN + 'ajax.php',
        data: {command:"searchArticles","payload":payload}


      })
      .done(function(result)
      {
        if(result)
        {

          result = JSON.parse(result);
          console.log(result);
          addArticleLinks(result);
        }
      })

      .fail(function(result)
      {
        console.log("Failure!");
        console.log(result);
      })
    // }
  }


  jQuery("#searchArticle").keypress(function(event)
  {
    let keycode = (event.keyCode ? event.keyCode : event.which);
	  if(keycode == '13')
    {
	     articleSearch("article",jQuery("#searchArticle").val());
    }
  });

  jQuery("#searchAuthor").keypress(function(event)
  {
    let keycode = (event.keyCode ? event.keyCode : event.which);
	  if(keycode == '13')
    {
	     articleSearch("author",jQuery("#searchAuthor").val());
    }
  });

  jQuery("#searchTitle").keypress(function(event)
  {
    let keycode = (event.keyCode ? event.keyCode : event.which);
	  if(keycode == '13')
    {
	     articleSearch("title",jQuery("#searchTitle").val());
    }
  });
  function sort_li_date(a, b)
  {
    console.log(jQuery(a).data('date'))
    return (jQuery(b).data('date')) > (jQuery(a).data('date')) ? 1 : -1;
  }
  function sort_li(a, b)
  {
    return (jQuery(b).data('sort')) < (jQuery(a).data('sort')) ? 1 : -1;
  }
  function articleLinksSort(type)
  {
    console.log(type);
    if(type == "date")
    {
      jQuery(function()
      {
        jQuery("#articleLinks li").sort(sort_li_date).appendTo('#articleLinks ul');

      });
    }
    else
    {
      jQuery(function()
      {
        jQuery("#articleLinks li").sort(sort_li).appendTo('#articleLinks ul');

      });
    }
  }




  function addArticleLinks(result)
  {
    console.log("add Article Links")
    console.log(result)
    jQuery("#articleLinks").empty();
    document.getElementById("articleLinks").scrollIntoView();
    // jQuery("#articleLinks").append("<span></span>");
    jQuery("#articleLinks").append("<a class=\"screenHide fusion-button button-flat fusion-button-round button-small button-default button-1\" href=\"javascript:mobileSwitch()\">Back</a>");
    jQuery("#articleLinks").append("<ul>");
    let months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
    for(let i = 0; i < result.articles.length; i++)
    {
      let vol = result.articles[i].year - 1920;
      let dt = new Date(2019,result.articles[i].issue-1,1);
      let issue = result.articles[i].issue < 10 ?  "0" + result.articles[i].issue : result.articles[i].issue;
      let month = months[dt.getMonth()];
      //console.log(result.articles[i]);
      let downloadBtn = "<a style=\"margin-left:10px;margin-top: 10px;\" class=\"fusion-button button-flat fusion-button-round button-small button-default button-1\" href=\"https://gomc.com/index.php/product/"+ result.articles[i].linkTitle+"\">Buy</a>"
      if(result["free"] == 1)
      {
        downloadBtn = "<a style=\"margin-left:10px;margin-top: 10px;\" class=\"fusion-button button-flat fusion-button-round button-small button-default button-1\" href=\"javascript:articleDownload('"+result.articles[i].filename+"')\">Download</a>"
      }
      let author = result.articles[i].author != "ERROR" && result.articles[i].author != null ? " author: "+ result.articles[i].author : "";
      jQuery("#articleLinks ul").append("<li data-sort=\""+i+"\" data-date=\""+result.articles[i].year+issue+"\" style=\" margin-bottom:20px;\"><div class=\"artMobile artDesktop\"><b style=\"font-size:15px;\">"+result.articles[i].title+"</b>"+author+" ("+" Vol: "+vol+", "+month+" "+result.articles[i].year+")</div>"
      +"<div class=\"btnMobile\"><span style=\"\"><a style=\"\"class=\"fusion-button button-flat fusion-button-round button-small button-default button-1\" onClick=\"window.open('"
      + result.articles[i].firstpage_path +"','Preview','resizable,height=500,width=670'); return false;\" target=\"_blank\">Preview </a></span>"
      +downloadBtn+"<span></div></li>")
    }
    jQuery("#articleLinks").append("</ul>");
    mobileSwitch();
  }

  function addToCart(id)
  {
    console.log("addtocart: "+id)
    jQuery.post({
      url: C_PLUGIN + 'ajax.php',
      data: {command:"addToCart","payload":{"id":id}}


    }).done(function(result)
    {
      console.log(result);
    });
  }

  function mobileSwitch()
  {
    jQuery( "div .mobileHide" ).removeClass( "mobileHide" ).addClass( "mobileTemp" );
    jQuery( "div .mobileShow" ).removeClass( "mobileShow" ).addClass( "mobileHide" );
    jQuery( "div .mobileTemp" ).removeClass( "mobileTemp" ).addClass( "mobileShow" );
  }

</script>
</body>
{"id":17351,"date":"2019-08-22T03:41:11","date_gmt":"2019-08-22T03:41:11","guid":{"rendered":"http:\/\/gomc.mcservices.com\/?page_id=17351"},"modified":"2019-11-14T15:51:45","modified_gmt":"2019-11-14T15:51:45","slug":"articles","status":"publish","type":"page","link":"https:\/\/gomc.com\/index.php\/articles\/","title":{"rendered":"Articles"},"content":{"rendered":"\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":2,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":[],"_links":{"self":[{"href":"https:\/\/gomc.com\/index.php\/wp-json\/wp\/v2\/pages\/17351"}],"collection":[{"href":"https:\/\/gomc.com\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/gomc.com\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/gomc.com\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/gomc.com\/index.php\/wp-json\/wp\/v2\/comments?post=17351"}],"version-history":[{"count":2,"href":"https:\/\/gomc.com\/index.php\/wp-json\/wp\/v2\/pages\/17351\/revisions"}],"predecessor-version":[{"id":38673,"href":"https:\/\/gomc.com\/index.php\/wp-json\/wp\/v2\/pages\/17351\/revisions\/38673"}],"wp:attachment":[{"href":"https:\/\/gomc.com\/index.php\/wp-json\/wp\/v2\/media?parent=17351"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}