﻿var PaperList = PaperList ? PaperList : function() {
    var public =
    {
       countryName:null,
       active:null,
       index:null,
       total:null,
      call:function()
      {
       
       $('#recently_papers').empty();
       $('#recently_papers').hide();
       $('#box_recently_papers .loading').show();
        var jsonp = true;
        var service = new WindowsSerices("http://www.icgst-amc.com/icgst/ICGSTService.asmx", jsonp ? WSDataType.jsonp : WSDataType.json);
       // alert('call');
        service.call("RecentlyPapers", { }, this.callback);
      },
      call2:function(subId)
      {
       
       $('#recently_papers').empty();
       $('#recently_papers').hide();
       $('#box_recently_papers .loading').show();
        var jsonp = true;
        var service = new WindowsSerices("http://www.icgst-amc.com/icgst/ICGSTService.asmx", jsonp ? WSDataType.jsonp : WSDataType.json);
        //alert('call');
        service.call("RecentlyPapersSubject", { subId: subId }, this.callback);
      },
       call7:function(subId)
      {
       
       $('#recently_papers').empty();
       $('#recently_papers').hide();
       $('#box_recently_papers .loading').show();
        var jsonp = true;
        var service = new WindowsSerices("http://www.icgst-amc.com/icgst/ICGSTService.asmx", jsonp ? WSDataType.jsonp : WSDataType.json);
        //alert('call');
        service.call("RecentlyPapersSubject", { subId: subId }, this.callback7);
      },
      call3:function(SN)
      {
       
        //alert(SN);
         //alert('call');
         $('#authors_paper').empty();
         $('#paper_loading').show();
           $('#title').text('');          
         $('#sn').text('SN:'); 
         $('#keywords').text(''); 
         $('#abstract').text(''); 
         $('#sdate').text("Submission Date: "); 
         $('#ddate').text("DecisionDate: "); 
         $('#pdate').text("Publish Date: ");
         
        var jsonp = true;
        var service = new WindowsSerices("http://www.icgst-amc.com/icgst/ICGSTService.asmx", jsonp ? WSDataType.jsonp : WSDataType.json);
       
        service.call("LoadPaper", { sn: SN }, this.callback2);
      },
      call4:function(kw,paper_sn)
      {
       // $('#Similar_paper').empty();
       $('#S_paper').hide();
       
       //$('#box_similar_papers .loading').show();
        var jsonp = true;
        var service = new WindowsSerices("http://www.icgst-amc.com/icgst/ICGSTService.asmx", jsonp ? WSDataType.jsonp : WSDataType.json);
        // alert(kw+' '+paper_sn);
        service.call("SimilarPapers", {keywords: kw, sn: paper_sn }, PaperList.callback_similarpaper);
      },
      call5:function(id,active,index,clear)
      {
      //alert(id);
          public.active = active;
          public.index = index;
         
           if(clear)
           $('#PaperList').empty();
           
           $('#pop_loading').show();
           if(active=='false')
           {
             $('#popup_paper_title').text('Submitted Papers');
           }
           else
           {
           $('#popup_paper_title').text('Accepted papers');
           }
          var jsonp = true;
        var service = new WindowsSerices("http://www.icgst-amc.com/icgst/ICGSTService.asmx", jsonp ? WSDataType.jsonp : WSDataType.json);
        // alert(id+' '+active+' '+this.index);
        service.call("ConferencePapersLimit", {conf_id: id, active: active ,startIndex:index}, this.callbackconference);
      },
      call6:function(keywords)
      {
     //  alert('call6');
        $('#search_papers').empty();
         $('.loading').show();
     
         var jsonp = true;
         var service = new WindowsSerices("http://www.icgst-amc.com/icgst/ICGSTService.asmx", jsonp ? WSDataType.jsonp : WSDataType.json);
        //alert(kw+' '+paper_sn);
        service.call("PapersSearch", {keywords: keywords }, this.callback_papersreach);
      },
      loadpapervideos:function(sn)
      {
        var jsonp = true;
        var service = new WindowsSerices("http://www.icgst-amc.com/icgst/ICGSTService.asmx", jsonp ? WSDataType.jsonp : WSDataType.json);
       //alert(sn);       
         service.call("loadPaperVideos", { SN: sn }, this.bindpapervideos);
      }     
      ,
      callback2:function(output)
      {
         //alert('callback');
         //alert('callback');
          $('#paper_loading').hide();
         var paper = output;
         $('#title').text(paper.Title);          
         $('#sn').text("SN: "+paper.SerailNumber); 
         $('#keywords').text(paper.Keywords); 
         $('#abstract').html('<p>'+paper.Abstract+'</p>'); 
           $('#abstract p').expander({
             slicePoint:       530,  // default is 100
    
             expandText:         ' more ', // default is 'read more...'
             collapseTimer:    0, // re-collapses after 5 seconds; default is 0, so no re-collapsing
             userCollapseText: ' ^ less '  // default is '[collapse expanded text]'
           });
         
         $('#sdate').html("<p style='display:inline;font-weight:bold;'>Submission Date:</p> "+paper.SubmissionDate); 
         $('#ddate').html("<p style='display:inline;font-weight:bold;'>DecisionDate:</p> "+paper.DecisionDate); 
         $('#pdate').html("<p style='display:inline;font-weight:bold;'>Publish Date:</p> "+paper.PublichDate);
        
          //$('#pdf_link').attr('href',)
         
         $('#authores_webgates .webgates-items').show();
          $('#authores_webgates .loading').hide();
          //alert(paper.isPPT);
          if(paper.isPPT==true)
            $('#li_ppt').show();
          else
            $('#li_ppt').hide();
         //alert(paper.Bibtxt);
          $('.bibtxtbody').html(paper.Bibtxt);
          var isMemebers = false;
          $.each(paper.Authors, function(index, author) {                       
             
             isMemebers = true;
               //alert("http://www.icgst-amc.com"+author.Photo.replace('~/',''));
               var photo ='http://www.icgst-amc.com/institute/Handler1.ashx?url='+ author.Photo;
              // alert(photo);
               $('#authors_paper').append(' <li style="float:left;margin-right:10px;border-right:1px solid #ccc;width:140px;">'+
                 '<img class="smal-img" alt="" src="'+photo+'" />'+
                 '<a href="http://www.icgst-amc.com/institute/Community.aspx?InstId=3&aid='+author.Id+'" ><span class="names" style="clear:both;display:block;font-size:.8em;">'+author.Title+' '+author.FirstName+' '+author.LastName+', </span></a><div class="subtitle" >'+author.Affiliation+'</div> '+		         
		         '</li>');
		         
          }); 
          //alert(isMemebers)
          if(!isMemebers)
          {
            $('#authors_paper').append(' <li><p style="display:inline;font-weight:bold;"></p> '+paper.AuthorizedBy+'</li>');
          }
          
          $('#pdf_link').click(function(){
          //alert($.cookie('Cookie_Remember'));
           if ($.cookie('Cookie_Remember') != null) 
           {
            //alert(paper.PublichFilePath);
            //alert('')
            var p ="http://www.icgst.com/Handler1.ashx?url=/repository/"+ paper.PublichFilePath.split('/')[6]+".pdf";
            //alert(p)
            window.open(p);
             //window.open('http://www.icgst-amc.com/institute/Handler2.ashx?url='+ paper.PublichFilePath);
             }
             else
             alert("To download, please, login first or sign up if you don't have an AMC account")
          })
           $('#PPT_link').click(function(){
          //alert($.cookie('Cookie_Remember'));
           if ($.cookie('Cookie_Remember') != null) 
           {
            //alert(paper.PublichFilePath);
            //alert('')
            var p ="http://www.icgst.com/Handler1.ashx?url=/repository/PPT/"+ paper.SerailNumber+".PPT";
            //alert(p)
            window.open(p);
             //window.open('http://www.icgst-amc.com/institute/Handler2.ashx?url='+ paper.PublichFilePath);
             }
             else
             alert("To download, please, login first or sign up if you don't have an AMC account")
          })
           $('#similar_paper_link').click(function(){
             //alert(paper.Title + ' '+getParameterByName('pid'));
              $('#similar_paper_popup').show(200);   
              $('#alert_container').show(100);
             PaperList.call4(paper.Title,getParameterByName('pid'));
            })
          //PaperList.call4(paper.Title,paper.SerailNumber);
             $('#authores_webgates .webgates-items p').expander({
             slicePoint:       130,  // default is 100
    
             expandText:         '[ read more ]', // default is 'read more...'
             collapseTimer:    0, // re-collapses after 5 seconds; default is 0, so no re-collapsing
             userCollapseText: '[ ^ less ]'  // default is '[collapse expanded text]'
           });

      //}
       
       },
      callback:function(output)
      {
         //alert('callback');
         var papers = output;
          $('#recently_papers').show();
           $('#box_recently_papers .loading').hide();
         //http://www.icgst-amc.com
        $('.loading').hide();
          $.each(papers, function(index, paper) {
          
              var subid="";
              try
              {
              if(getParameterByName("subid")!=null)
                subid= '&subid='+getParameterByName("subid");
             }
             catch(err)
             {}
             var strAuthors="";
               $.each(paper.Authors, function(index, author) {                       
                    strAuthors +="<a href='http://www.icgst-amc.com/institute/Community.aspx?InstId=3&aid=" + author.Id + "' style='font-size:1em;text-decoration:none;'>" + author.FirstName + " " + author.LastName + ", </a>";		         
                }); 
          var stra="";
          if(strAuthors=="")
          {
            stra = "";
          }
          else
          {
          stra = '<span class="fleft" style="">Authors :</span><span runat=server id="paper_authors" >'+strAuthors+'</span>';
          }
      //alert(paper.Title);
             //alert((Date.parse(paper.PublichDate.replace('12:00:00 AM',''))+"").split('00:00:00')[0]);
               $('#recently_papers').append('<li class="radius-div arrow-document"  style=";display:block;">'+ 
        
    'Title: <a href="paper.aspx?pid='+paper.SerailNumber+subid+'" style="font-size:.9em;text-decoration:none;" runat="server" id="paper_link" > '+paper.Title+','+
     '<span style="display:block;color:#000">'+
    '<span>Publish Date: </span> <span >'+paper.PublichDate+',</span>'+
    '<span>Serial Number: </span><span  ID="sn_span" runat="server">'+paper.SerailNumber+'</span>'+
    ' </span>'+
  '</a>'+
  
   stra+ 
  
  
'</li>');     
		      
          
          }); 
          //alert($('#recently_papers').html());
//          $('#authores_webgates .webgates-items p').expander({
//             slicePoint:       100,  // default is 100
//    
//             expandText:         '[ read more ]', // default is 'read more...'
//             collapseTimer:    0, // re-collapses after 5 seconds; default is 0, so no re-collapsing
//             userCollapseText: '[ ^ less ]'  // default is '[collapse expanded text]'
//           });
      },
        callback7:function(output)
      {
         //alert('callback');
         var papers = output;
          $('#recently_papers').show();
           $('#box_recently_papers .loading').hide();
         //http://www.icgst-amc.com
        $('.loading').hide();
          $.each(papers, function(index, paper) {
          
              var subid="";
              try
              {
              if(getParameterByName("subid")!=null)
                subid= '&subid='+getParameterByName("subid");
             }
             catch(err)
             {}
             var strAuthors="";
               $.each(paper.Authors, function(index, author) {                       
                    strAuthors +="<a href='http://www.icgst-amc.com/institute/Community.aspx?InstId=3&aid=" + author.Id + "' style='font-size:1em;text-decoration:none;'>" + author.FirstName + " " + author.LastName + ", </a>";		         
                }); 
          var stra="";
          if(strAuthors=="")
          {
            stra = "";
          }
          else
          {
          stra = '<span class="fleft" style="">Authors :</span><span runat=server id="paper_authors" >'+strAuthors+'</span>';
          }
      //alert(paper.Title);
             //alert((Date.parse(paper.PublichDate.replace('12:00:00 AM',''))+"").split('00:00:00')[0]);
               $('#recently_papers').append('<li class="radius-div arrow-document"  style=";display:block;text-align:justify;padding-right:5px;">'+ 
        
    'Title: <a href="paper.aspx?pid='+paper.SerailNumber+subid+'" style="font-size:.9em;text-decoration:none;text-align:justify" runat="server" id="paper_link" > '+paper.Title+','+
     '<span style="display:block;color:#000">'+
    '<div style="display:block"><span>Date: </span> <span >'+paper.PublichDate+',</span></div>'+
    '<div style="display:block"><span>SN: </span><span  ID="sn_span" runat="server">'+paper.SerailNumber+'</span></div>'+
    ' </span>'+
  '</a>'+
  
   stra+ 
  
  
'</li>');     
		      
          
          }); 
          //alert($('#recently_papers').html());
//          $('#authores_webgates .webgates-items p').expander({
//             slicePoint:       100,  // default is 100
//    
//             expandText:         '[ read more ]', // default is 'read more...'
//             collapseTimer:    0, // re-collapses after 5 seconds; default is 0, so no re-collapsing
//             userCollapseText: '[ ^ less ]'  // default is '[collapse expanded text]'
//           });
      },
      callback_similarpaper:function(output){
      //alert(output);
       var papers = output;
          $('#S_paper').show();
           $('#similar_paper_popup .wrapper').hide();
           $('#S_paper').empty();
         //http://www.icgst-amc.com
        //alert('similar output');
          $.each(papers, function(index, paper) {
          
               var subid="",confid="";
              if(getParameterByName("subid"))
                 subid= '&subid='+getParameterByName("subid");
              if(getParameterByName("confid"))
                 confid ='&confid='+getParameterByName("confid"); 
             //alert(confid);
               $('#S_paper').append('<li class="arrow-document"><a href="paper.aspx?pid='+paper.SerailNumber+subid+confid+'" >'+paper.Title+',</span><span class="date" style="display:block">'+paper.SerailNumber+'</span></a></li>');
		        
          
          }); 
            
      },
      callbackconference:function(output)
      {
          //alert('test');
          $('#pop_loading').hide();
          $('#pop_header_title').show();
          if(public.total==null || public.index==0)
           public.total = 0;
           var papers = output;
           if(papers.length>0)
           {
             public.total +=papers.length;
             $.each(papers, function(index, paper) {
               //alert(paper.SerailNumber);
                var str ='<li class="arrow-document" style="border-bottom:1px solid #e7e7e7;">'+paper.Title+', <span class="date"> '+paper.SerailNumber+'</span>'
                if(public.active =="true")
                 $.each(paper.Authors, function(index, author) {   
                    str+=  '<a  href="http://www.icgst-amc.com/institute/Community.aspx?InstId=3&aid='+author.Id+'" ><span  style="clear:both;">'+author.Title+' '+author.FirstName+' '+author.LastName+', </span></a>';
                    
                  });
                str+='</li>';
               $('#PaperList').append(str);
              
            });
            
               public.index = public.index+5;
               public.call5(getParameterByName('confid'),public.active,public.index,false)
            }
            else{
                $('#not_found').show();
                if(public.index==undefined || public.index==0)
                 $('#not_found').text('Paper not found');
               else
               {
                $('#not_found').show();
                $('#not_found').text(public.total);
                 
               }
            } 
      },
      callback_papersreach:function(output)
      {
         alert('callback');
         var papers = output;
          $('#search_papers').show();
          
        
        $('.loading').hide();
          $.each(papers, function(index, paper) {
          
              var subid="";
              try
              {
              if(getParameterByName("subid")!=null)
                subid= '&subid='+getParameterByName("subid");
             }
             catch(err)
             {}
             var strAuthors="";
               $.each(paper.Authors, function(index, author) {                       
                    strAuthors +="<a href='http://www.icgst-amc.com/institute/Community.aspx?InstId=3&aid=" + author.Id + "' style='font-size:1em;text-decoration:none;'>" + author.FirstName + " " + author.LastName + ", </a>";		         
                }); 
          
         
             
               $('#search_papers').append('<div class="radius-div arrow-document" style="background-color:#eee;cursor:pointer;color:#000;margin:2px;text-decoration:none;">'+
 ' <div style="padding-top:0px;">'+
  '<a href="paper.aspx?pid='+paper.SerailNumber+subid+'" style="font-size:.9em;color:#023D80;text-decoration:none;" runat="server" id="paper_link" >'+paper.Title+','+
    '<span style="display:block;color:#000">'+
   '<span>Publish Date: </span> <span >'+paper.PublichDate+',</span>'+
   '<span>Serial Number: </span><span  ID="sn_span" runat="server">'+paper.SerailNumber+'</span>'+
   '</span>'+
  '</a>'+
  '<div style="margin-top:1px;margin-bottom:2px;padding-bottom:1px;">'+
   '<span>Authors :</span><span runat=server id="paper_authors">'+strAuthors+'</span>'+
  '</div>'+
'</div> ' +
'</div> ');     
		      
          
          }); 
      },
      bindpapervideos:function(videos){
            //alert(videos);
            if(videos==undefined || videos==null|| videos.length<1)
           {
              $('#div1').css('width','98%');
              //alert('');
           }
           $.each(videos, function(index, video) {  
            //prompt('',video.Url);
            $('#div_papers_videos').show();
                var id="";
               if(id= video.Url.split('&v=').length>0)
                 id= video.Url.split('&v=')[1];            
                $('#papers_video').append('<li id="papers_vedio_index_'+index+'"><a href="'+video.Url+'" rel="prettyPhoto" title="'+video.Title+'"><img src="http://img.youtube.com/vi/'+id+'/default.jpg" width="100" height="100" alt="" /><img class="pointer2" src="../Images/play.png" /></a></li>');
           });

            $('#papers_video li a').click(function(){
               
               $('#video_obj').hide();
               var current = $(this);
                var src = $(this).attr('href');           
               $('#alert_container').show(100);
               $('#video_popup').animate({
                  width: "10%",
                 height:"10%"           
                   
                  }, 10 ).animate({
                  width: "55%"                    
                   
                  }, 1000 ).animate({                
                 height:"400px"           
                   
                  }, 1000, function(){                                    
                           var id="",url="";
                           try{
                           if(id= src.split('&v=').length>0)
                           {
                              id= src.split('&v=')[1];
                              url ='http://www.youtube.com/v/'+id+'?version=3&feature=player_detailpage';
                           }              
                           if(id==undefined)
                               url = src1;                            
                           //$('#video_embed').attr('src',url); 
                           $('#video_obj').empty(); 
                           $('#video_obj').html('<embed id="video_embed" style="width:100%;height:100%" type="application/x-shockwave-flash" src="'+url+'" pluginspage="http://www.adobe.com/go/getflashplayer" allowfullscreen="true" allowScriptAccess="always" />');              
                           $('#video_obj').show();                                               
                           $('#video_close').show();
                             // alert($('#video_obj').html()); 
                           }
                           catch(err)
                           {
                           alert(err);
                           }
                    })

                return false;
            })
      
       },
       
    }

    return public;
} ();

