﻿function PubRef(title, publisher, date, ref, publisher_logo, disabled) {

  this.guessedDir = function(){
    ch = title.charAt(1); // 2nd char
    if (ch && 'אבגדהוזחטיכךלמםןנסעףפץצקרשת'.substring(ch) >= 0) return 'rtl';
    return 'ltr';
  }

  this.title = title;
  this.publisher = publisher;
  this.date = date;
  this.ref = ref;
  this.publisher_logo = (publisher_logo=='') ? publisher_logo = '../images/icon_download_pdf_reader.gif' : publisher_logo;
  this.dir = this.guessedDir();
  this.disabled = disabled;
}

function PubRefs() {

  this.set = new Array();
  var frameTag    = '<div align=center><center><div align="center"  style="margin-bottom:0;"><center><table cellSpacing="0" cellPadding="4" width="100%" border="0" style="BORDER-COLLAPSE: collapse;"><tbody>{items}</tbody></table></center></div>';
//  var itemTag     = '<tr><td align="left" height="60" width="158"><img src="{publisher_logo}" border="0"/></td><td align="center" width="50" height="60">' + 
//                    '<hr width="90%" color="#00ffff" noShade="true" SIZE="1" style="BORDER-RIGHT: 1px dotted; BORDER-TOP: 1px dotted; BORDER-LEFT: 1px dotted; BORDER-BOTTOM: 1px dotted"/>' +
//                    '</td><td align="right" height="60"><span style="FONT-SIZE: 8pt"><a href="{ref}" target="_blank">{title}</a></span><br/><font color="#808080"><span style="FONT-SIZE: 8pt">' +
//                    '({publisher} {date})</span></font></td></tr><tr>';

  var itemTag     = '<tr height=60><td><table width=90% align=center><tr dir={dir} align=right>' + 
                    '<td nowrap style="font-size:8pt;"><a href="{ref}" target="_blank">{title}</a><br><font color="#808080"><span dir=ltr>({publisher} {date})</span></font></td>' + 
                    '<td width=100%><hr align=center width="90%" color="#00ffff" noShade="true" SIZE="1" style="BORDER-RIGHT: 1px dotted; BORDER-TOP: 1px dotted; BORDER-LEFT: 1px dotted; BORDER-BOTTOM: 1px dotted"/></td>' +
                    '<td><img src="{publisher_logo}" border="0"/>' +
                    '</td></tr></table></td></tr>';

  this.add = function(title, publisher, date, ref, publisher_logo) {
    var index = this.set.length;
    this.set[index] = new PubRef(title, publisher, date, ref, publisher_logo, false);
  };

  this.innerHTML = function() {
    tag = '';
    for (i = 0; i < this.set.length; i++) {
      pubRef = this.set[i];
      tmpTag = itemTag;
      tmpTag = tmpTag.replace('{title}', pubRef.title);
      tmpTag = tmpTag.replace('{publisher}', pubRef.publisher);
      tmpTag = tmpTag.replace('{date}', pubRef.date);
      tmpTag = tmpTag.replace('{ref}', pubRef.ref);
      tmpTag = tmpTag.replace('{publisher_logo}', pubRef.publisher_logo);
      tmpTag = tmpTag.replace('{dir}', pubRef.dir);
      tag += tmpTag;
    }
    tag = frameTag.replace('{items}', tag);
    return tag;
  };

  this.pubTitle = function(title, lang){
    if ('en' == lang) {
      return ('<div dir=ltr style="background-image:url(/uploads/icon_pdf_list_en.gif);background-repeat:no-repeat;background-position:left top;padding-left:28px;color:#B0215F;font-size:12px;line-height:16px;padding-bottom:7px;"><p align=left dir=ltr style="margin-bottom:20;"><span class="CategoryTitleBlack">' + title +'</span></p></div>');
    } else {
      return ('<div class="icon_pdf"><p align=right dir=rtl style="margin-bottom:20;"><span class="CategoryTitleBlack">' + title +'</span></p></div>');
    }
  };

  this.footer = function(lang){
    if ('en' == lang) {
      return ('<div style="padding-top:24px;" dir=ltr align=center><table width=70%><tr>' +
              '  <td align=center><a href="/content.aspx?cid=780" target="_top"><img src="more_articles.gif" style="border-width:0px;" /></a>' +
              '  &nbsp;&nbsp;<a style="font-size:10pt; font-weight:bold;" href="http://www.shalva.org/content.aspx?cid=993" target="_top">More Articles</a></td>' +
              '  <td align=center><a href="http://www.adobe.com/products/acrobat/readstep2.html" target="_blank"><img src="acrobat_download.gif" style="border-width:0px;" /></a>' +
              '  &nbsp;&nbsp;<a style="font-size:10pt; font-weight:bold;" href="http://www.adobe.com/products/acrobat/readstep2.html" target="_blank">Acrobat Reader Download</a></td>' +
              '</tr></table></div>');
    } else {
      return ('<div style="padding-top:24px;" dir=rtl align=center><table width=70%><tr>' +
              '  <td align=center><a href="/content.aspx?cid=780" target="_top"><img src="more_articles.gif" style="border-width:0px;" /></a>' +
              '  &nbsp;&nbsp;<a style="font-size:10pt; font-weight:bold;" href="/content.aspx?cid=780" target="_top">לכתבות נוספות</a></td>' +
              '  <td align=center><a href="http://www.adobe.com/products/acrobat/readstep2.html" target="_blank"><img src="acrobat_download.gif" style="border-width:0px;" /></a>' +
              '  &nbsp;&nbsp;<a style="font-size:10pt; font-weight:bold;" href="http://www.adobe.com/products/acrobat/readstep2.html" target="_blank">להורדת תוכנת אקרובט</a></td>' +
              '</tr></table></div>');
    }
  };


  this.show = function(title, stand_alone, lang) {
    document.writeln(this.pubTitle(title, lang));
    document.writeln(this.innerHTML());
    if (stand_alone) document.writeln(this.footer(lang));
  };

}
